Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2 | /* |
| 3 | * This is the new netlink-based wireless configuration interface. |
| 4 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2020 Intel Corporation |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/if.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15 | #include <linux/list.h> |
| 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/ieee80211.h> |
| 18 | #include <linux/nl80211.h> |
| 19 | #include <linux/rtnetlink.h> |
| 20 | #include <linux/netlink.h> |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 21 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Johannes Berg | e3ae39e | 2020-02-24 09:38:15 +0100 | [diff] [blame] | 23 | #include <linux/if_vlan.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include <net/genetlink.h> |
| 26 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 27 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 28 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | #include "core.h" |
| 30 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 31 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 32 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 33 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 34 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 35 | struct genl_info *info, |
| 36 | struct cfg80211_crypto_settings *settings, |
| 37 | int cipher_limit); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 40 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 42 | /* multicast groups */ |
| 43 | enum nl80211_multicast_groups { |
| 44 | NL80211_MCGRP_CONFIG, |
| 45 | NL80211_MCGRP_SCAN, |
| 46 | NL80211_MCGRP_REGULATORY, |
| 47 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 48 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 49 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 51 | }; |
| 52 | |
| 53 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 54 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 55 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 56 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 57 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 58 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 59 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 60 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 61 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 62 | #endif |
| 63 | }; |
| 64 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | /* returns ERR_PTR values */ |
| 66 | static struct wireless_dev * |
| 67 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 69 | struct cfg80211_registered_device *rdev; |
| 70 | struct wireless_dev *result = NULL; |
| 71 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 72 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 73 | u64 wdev_id; |
| 74 | int wiphy_idx = -1; |
| 75 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 77 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 78 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 79 | if (!have_ifidx && !have_wdev_id) |
| 80 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 81 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 82 | if (have_ifidx) |
| 83 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 84 | if (have_wdev_id) { |
| 85 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 86 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 90 | struct wireless_dev *wdev; |
| 91 | |
| 92 | if (wiphy_net(&rdev->wiphy) != netns) |
| 93 | continue; |
| 94 | |
| 95 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 96 | continue; |
| 97 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 98 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 99 | if (have_ifidx && wdev->netdev && |
| 100 | wdev->netdev->ifindex == ifidx) { |
| 101 | result = wdev; |
| 102 | break; |
| 103 | } |
| 104 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 105 | result = wdev; |
| 106 | break; |
| 107 | } |
| 108 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 109 | |
| 110 | if (result) |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (result) |
| 115 | return result; |
| 116 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 119 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 122 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 123 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 124 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 125 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 128 | !attrs[NL80211_ATTR_IFINDEX] && |
| 129 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 130 | return ERR_PTR(-EINVAL); |
| 131 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 132 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 133 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 135 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 136 | if (attrs[NL80211_ATTR_WDEV]) { |
| 137 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 138 | struct wireless_dev *wdev; |
| 139 | bool found = false; |
| 140 | |
| 141 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 142 | if (tmp) { |
| 143 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 144 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 145 | if (wdev->identifier != (u32)wdev_id) |
| 146 | continue; |
| 147 | found = true; |
| 148 | break; |
| 149 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | |
| 151 | if (!found) |
| 152 | tmp = NULL; |
| 153 | |
| 154 | if (rdev && tmp != rdev) |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | rdev = tmp; |
| 157 | } |
| 158 | } |
| 159 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 160 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 161 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 162 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 163 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 164 | if (netdev) { |
| 165 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 166 | tmp = wiphy_to_rdev( |
| 167 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 168 | else |
| 169 | tmp = NULL; |
| 170 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 171 | /* not wireless device -- return error */ |
| 172 | if (!tmp) |
| 173 | return ERR_PTR(-EINVAL); |
| 174 | |
| 175 | /* mismatch -- return error */ |
| 176 | if (rdev && tmp != rdev) |
| 177 | return ERR_PTR(-EINVAL); |
| 178 | |
| 179 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 183 | if (!rdev) |
| 184 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | if (netns != wiphy_net(&rdev->wiphy)) |
| 187 | return ERR_PTR(-ENODEV); |
| 188 | |
| 189 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * This function returns a pointer to the driver |
| 194 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | * |
| 196 | * The result of this can be a PTR_ERR and hence must |
| 197 | * be checked with IS_ERR() for errors. |
| 198 | */ |
| 199 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 200 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 202 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 205 | static int validate_beacon_head(const struct nlattr *attr, |
| 206 | struct netlink_ext_ack *extack) |
| 207 | { |
| 208 | const u8 *data = nla_data(attr); |
| 209 | unsigned int len = nla_len(attr); |
| 210 | const struct element *elem; |
| 211 | const struct ieee80211_mgmt *mgmt = (void *)data; |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 212 | bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); |
| 213 | unsigned int fixedlen, hdrlen; |
| 214 | |
| 215 | if (s1g_bcn) { |
| 216 | fixedlen = offsetof(struct ieee80211_ext, |
| 217 | u.s1g_beacon.variable); |
| 218 | hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); |
| 219 | } else { |
| 220 | fixedlen = offsetof(struct ieee80211_mgmt, |
| 221 | u.beacon.variable); |
| 222 | hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); |
| 223 | } |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 224 | |
| 225 | if (len < fixedlen) |
| 226 | goto err; |
| 227 | |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 228 | if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 229 | goto err; |
| 230 | |
| 231 | data += fixedlen; |
| 232 | len -= fixedlen; |
| 233 | |
| 234 | for_each_element(elem, data, len) { |
| 235 | /* nothing */ |
| 236 | } |
| 237 | |
| 238 | if (for_each_element_completed(elem, data, len)) |
| 239 | return 0; |
| 240 | |
| 241 | err: |
| 242 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 246 | static int validate_ie_attr(const struct nlattr *attr, |
| 247 | struct netlink_ext_ack *extack) |
| 248 | { |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 249 | const u8 *data = nla_data(attr); |
| 250 | unsigned int len = nla_len(attr); |
Jouni Malinen | 7388afe | 2019-02-11 16:29:04 +0200 | [diff] [blame] | 251 | const struct element *elem; |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 252 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 253 | for_each_element(elem, data, len) { |
| 254 | /* nothing */ |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 257 | if (for_each_element_completed(elem, data, len)) |
| 258 | return 0; |
| 259 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 260 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 264 | /* policy for the attributes */ |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 265 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
| 266 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 267 | static const struct nla_policy |
| 268 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 269 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 270 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 271 | .len = U8_MAX }, |
| 272 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 273 | .len = U8_MAX }, |
| 274 | }; |
| 275 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 276 | static const struct nla_policy |
| 277 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 278 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 279 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 280 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 281 | NLA_POLICY_MAX(NLA_U8, 15), |
| 282 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 283 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 284 | NLA_POLICY_MAX(NLA_U8, 15), |
| 285 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
Aviya Erenfeld | ea18709 | 2019-02-06 13:17:08 +0200 | [diff] [blame] | 286 | NLA_POLICY_MAX(NLA_U8, 31), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 287 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 288 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 289 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 290 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| 291 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | static const struct nla_policy |
| 295 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 296 | [NL80211_PMSR_TYPE_FTM] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 297 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static const struct nla_policy |
| 301 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 302 | [NL80211_PMSR_REQ_ATTR_DATA] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 303 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 304 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 305 | }; |
| 306 | |
| 307 | static const struct nla_policy |
| 308 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 309 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 310 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 311 | [NL80211_PMSR_PEER_ATTR_REQ] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 312 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 313 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 314 | }; |
| 315 | |
| 316 | static const struct nla_policy |
| 317 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 318 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 319 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 320 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 321 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 322 | [NL80211_PMSR_ATTR_PEERS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 323 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 324 | }; |
| 325 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 326 | static const struct nla_policy |
| 327 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 328 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 329 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 330 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 331 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 332 | }; |
| 333 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 334 | static const struct nla_policy |
| 335 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 336 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 337 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 338 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 339 | }; |
| 340 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 341 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 342 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 343 | .len = NL80211_MAX_SUPP_RATES }, |
| 344 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 345 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 346 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), |
| 347 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 348 | [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), |
| 349 | [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, |
| 350 | NL80211_RATE_INFO_HE_GI_0_8, |
| 351 | NL80211_RATE_INFO_HE_GI_3_2), |
| 352 | [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, |
| 353 | NL80211_RATE_INFO_HE_1XLTF, |
| 354 | NL80211_RATE_INFO_HE_4XLTF), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 355 | }; |
| 356 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 357 | static const struct nla_policy |
| 358 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 359 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 360 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 361 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 362 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 363 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 364 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 365 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 366 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 367 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
| 368 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 369 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
| 370 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 371 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
| 372 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 373 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
| 374 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), |
| 375 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = |
| 376 | NLA_POLICY_NESTED(nl80211_txattr_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 377 | }; |
| 378 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame^] | 379 | static const struct nla_policy |
| 380 | nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { |
| 381 | [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 382 | [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 383 | NLA_POLICY_RANGE(NLA_BINARY, |
| 384 | NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, |
| 385 | IEEE80211_MAX_DATA_LEN), |
| 386 | }; |
| 387 | |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 388 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 6d4dd4e | 2019-07-31 10:58:20 +0200 | [diff] [blame] | 389 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 390 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 391 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 392 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 394 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 395 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 396 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 398 | NL80211_EDMG_CHANNELS_MIN, |
| 399 | NL80211_EDMG_CHANNELS_MAX), |
| 400 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 401 | NL80211_EDMG_BW_CONFIG_MIN, |
| 402 | NL80211_EDMG_BW_CONFIG_MAX), |
| 403 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 404 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 405 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 406 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 407 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 408 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 409 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 410 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 411 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 412 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 413 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 414 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 415 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 416 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 417 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 418 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 419 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 420 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| 421 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 422 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 423 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 424 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 425 | .len = WLAN_MAX_KEY_LEN }, |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 426 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 427 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 428 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 429 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 430 | [NL80211_ATTR_KEY_TYPE] = |
| 431 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 432 | |
| 433 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 434 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 435 | [NL80211_ATTR_BEACON_HEAD] = |
| 436 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 437 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 438 | [NL80211_ATTR_BEACON_TAIL] = |
| 439 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 440 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 441 | [NL80211_ATTR_STA_AID] = |
| 442 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 443 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 444 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 445 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 446 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 447 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 448 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 449 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 450 | NLA_POLICY_RANGE(NLA_U8, |
| 451 | NL80211_TX_POWER_AUTOMATIC, |
| 452 | NL80211_TX_POWER_FIXED), |
| 453 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 454 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 455 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 456 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 457 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Markus Theil | 1fab1b8 | 2019-10-29 10:30:03 +0100 | [diff] [blame] | 458 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 459 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 460 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 461 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 462 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 463 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 464 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 465 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 466 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 467 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 468 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 469 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 470 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 471 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 472 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 473 | [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 474 | |
| 475 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 476 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 477 | validate_ie_attr, |
| 478 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 479 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 480 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 481 | |
| 482 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 483 | .len = IEEE80211_MAX_SSID_LEN }, |
| 484 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 485 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 486 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 487 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 488 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 489 | NL80211_MFP_NO, |
| 490 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 491 | [NL80211_ATTR_STA_FLAGS2] = { |
| 492 | .len = sizeof(struct nl80211_sta_flag_update), |
| 493 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 494 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 495 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 496 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 497 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 498 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
Sergey Matyukevich | ea75080 | 2020-02-13 13:16:16 +0000 | [diff] [blame] | 499 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 500 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 501 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 502 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 503 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 504 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 505 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 506 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 507 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 508 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 509 | .len = IEEE80211_MAX_DATA_LEN }, |
| 510 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 511 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 512 | NL80211_PS_DISABLED, |
| 513 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 514 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 515 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 516 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 517 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 518 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 519 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 520 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 521 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 522 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 523 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 524 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 525 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 526 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 527 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
Jakub Kicinski | 056e937 | 2020-03-02 21:10:57 -0800 | [diff] [blame] | 528 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
| 529 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 530 | [NL80211_ATTR_MESH_PEER_AID] = |
| 531 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 532 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 533 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 534 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 535 | [NL80211_ATTR_HIDDEN_SSID] = |
| 536 | NLA_POLICY_RANGE(NLA_U32, |
| 537 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 538 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 539 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 540 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 541 | IEEE80211_MAX_DATA_LEN), |
| 542 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 543 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 544 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 545 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 546 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 547 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 548 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 549 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 550 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 551 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 552 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 553 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 554 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 555 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 556 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 557 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 558 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 559 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 560 | .len = NL80211_HT_CAPABILITY_LEN |
| 561 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 562 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 563 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 564 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 565 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 566 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 567 | |
| 568 | /* need to include at least Auth Transaction and Status Code */ |
| 569 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), |
| 570 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 571 | [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 572 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 573 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 574 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 575 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 576 | NLA_POLICY_RANGE(NLA_U32, |
| 577 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 578 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 579 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 580 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 581 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 582 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 583 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 584 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 585 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 586 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 587 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 588 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 589 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 590 | .len = IEEE80211_MAX_DATA_LEN }, |
Jakub Kicinski | 0e1a1d8 | 2020-03-02 21:10:56 -0800 | [diff] [blame] | 591 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 592 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
| 593 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 594 | [NL80211_ATTR_PEER_AID] = |
| 595 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 596 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 597 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 598 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 599 | [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, |
| 600 | [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 601 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 602 | /* |
| 603 | * The value of the Length field of the Supported Operating |
| 604 | * Classes element is between 2 and 253. |
| 605 | */ |
| 606 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = |
| 607 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 608 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 609 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 610 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 611 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 612 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 613 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
| 614 | IEEE80211_QOS_MAP_LEN_MIN, |
| 615 | IEEE80211_QOS_MAP_LEN_MAX), |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 616 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 617 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 618 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 619 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 620 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 621 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 622 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 623 | [NL80211_ATTR_USER_PRIO] = |
| 624 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 625 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 626 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Jakub Kicinski | 5cde05c | 2020-03-02 21:10:58 -0800 | [diff] [blame] | 627 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 628 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 629 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 630 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 631 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 632 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 633 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 634 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 635 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 636 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 637 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 638 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 639 | }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 640 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 641 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 642 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 643 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 644 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 645 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 646 | [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 647 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 648 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 649 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 650 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 651 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 652 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 653 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 654 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 655 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 656 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 657 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 658 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 659 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 660 | .len = FILS_ERP_MAX_RRK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 661 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 662 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 663 | [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 664 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 665 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 666 | |
| 667 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 668 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 669 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 670 | [NL80211_ATTR_HE_CAPABILITY] = |
| 671 | NLA_POLICY_RANGE(NLA_BINARY, |
| 672 | NL80211_HE_MIN_CAPABILITY_LEN, |
| 673 | NL80211_HE_MAX_CAPABILITY_LEN), |
Johannes Berg | 0e012b4 | 2020-04-12 00:40:30 +0200 | [diff] [blame] | 674 | [NL80211_ATTR_FTM_RESPONDER] = |
| 675 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 676 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 677 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 678 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 679 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 680 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 681 | .len = SAE_PASSWORD_MAX_LEN }, |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 682 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 683 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 684 | [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 685 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 686 | [NL80211_ATTR_TID_CONFIG] = |
| 687 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
Markus Theil | 5631d96 | 2020-03-12 10:10:53 +0100 | [diff] [blame] | 688 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 689 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
| 690 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 691 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 692 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 693 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
Johannes Berg | 8140860 | 2020-08-18 10:17:31 +0200 | [diff] [blame] | 694 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
| 695 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame^] | 696 | [NL80211_ATTR_FILS_DISCOVERY] = |
| 697 | NLA_POLICY_NESTED(nl80211_fils_discovery_policy), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 698 | }; |
| 699 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 700 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 701 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 702 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 703 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 704 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 705 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 706 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 707 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 708 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 709 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 710 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 711 | }; |
| 712 | |
| 713 | /* policy for the key default flags */ |
| 714 | static const struct nla_policy |
| 715 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 716 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 717 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 718 | }; |
| 719 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 720 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 721 | /* policy for WoWLAN attributes */ |
| 722 | static const struct nla_policy |
| 723 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 724 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 725 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 726 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 727 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 728 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 729 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 730 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 731 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 732 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 733 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | static const struct nla_policy |
| 737 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 738 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 739 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 740 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 741 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 742 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 743 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 744 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 745 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 746 | }, |
| 747 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 748 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 749 | }, |
| 750 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 751 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| 752 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 753 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 754 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 755 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 756 | /* policy for coalesce rule attributes */ |
| 757 | static const struct nla_policy |
| 758 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 759 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 760 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 761 | NLA_POLICY_RANGE(NLA_U32, |
| 762 | NL80211_COALESCE_CONDITION_MATCH, |
| 763 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 764 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 765 | }; |
| 766 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 767 | /* policy for GTK rekey offload attributes */ |
| 768 | static const struct nla_policy |
| 769 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 770 | [NL80211_REKEY_DATA_KEK] = { |
| 771 | .type = NLA_BINARY, |
| 772 | .len = NL80211_KEK_EXT_LEN |
| 773 | }, |
| 774 | [NL80211_REKEY_DATA_KCK] = { |
| 775 | .type = NLA_BINARY, |
| 776 | .len = NL80211_KCK_EXT_LEN |
| 777 | }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 778 | [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 779 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 780 | }; |
| 781 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 782 | static const struct nla_policy |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 783 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 784 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 785 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
Arend van Spriel | e548a1c | 2019-08-02 13:31:02 +0200 | [diff] [blame] | 786 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 787 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
| 788 | }; |
| 789 | |
| 790 | static const struct nla_policy |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 791 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 792 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 793 | .len = IEEE80211_MAX_SSID_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 794 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 795 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 796 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 797 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 798 | }; |
| 799 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 800 | static const struct nla_policy |
| 801 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 802 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 803 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 804 | }; |
| 805 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 806 | static const struct nla_policy |
| 807 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 808 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 809 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 810 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 811 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 812 | }, |
| 813 | }; |
| 814 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 815 | /* policy for NAN function attributes */ |
| 816 | static const struct nla_policy |
| 817 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 818 | [NL80211_NAN_FUNC_TYPE] = |
| 819 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 820 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 821 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 822 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 823 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 824 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 825 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 826 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 827 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 828 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 829 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 830 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 831 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 832 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 833 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 834 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 835 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 836 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 837 | }; |
| 838 | |
| 839 | /* policy for Service Response Filter attributes */ |
| 840 | static const struct nla_policy |
| 841 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 842 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 843 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 844 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 845 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 846 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 847 | }; |
| 848 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 849 | /* policy for packet pattern attributes */ |
| 850 | static const struct nla_policy |
| 851 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 852 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 853 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 854 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 855 | }; |
| 856 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 857 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 858 | struct cfg80211_registered_device **rdev, |
| 859 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 860 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 861 | int err; |
| 862 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 863 | if (!cb->args[0]) { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 864 | struct nlattr **attrbuf; |
| 865 | |
| 866 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 867 | GFP_KERNEL); |
| 868 | if (!attrbuf) |
| 869 | return -ENOMEM; |
| 870 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 871 | err = nlmsg_parse_deprecated(cb->nlh, |
| 872 | GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 873 | attrbuf, nl80211_fam.maxattr, |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 874 | nl80211_policy, NULL); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 875 | if (err) { |
| 876 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 877 | return err; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 878 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 879 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 880 | *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), |
| 881 | attrbuf); |
| 882 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 883 | if (IS_ERR(*wdev)) |
| 884 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 885 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 886 | /* 0 is the first index - add 1 to parse only once */ |
| 887 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 888 | cb->args[1] = (*wdev)->identifier; |
| 889 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 890 | /* subtract the 1 again here */ |
| 891 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 892 | struct wireless_dev *tmp; |
| 893 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 894 | if (!wiphy) |
| 895 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 896 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 897 | *wdev = NULL; |
| 898 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 899 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 900 | if (tmp->identifier == cb->args[1]) { |
| 901 | *wdev = tmp; |
| 902 | break; |
| 903 | } |
| 904 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 905 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 906 | if (!*wdev) |
| 907 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 910 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 911 | } |
| 912 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 913 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 914 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 915 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 916 | { |
| 917 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 918 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 919 | } |
| 920 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 921 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 922 | const struct ieee80211_reg_rule *rule) |
| 923 | { |
| 924 | int j; |
| 925 | struct nlattr *nl_wmm_rules = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 926 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 927 | |
| 928 | if (!nl_wmm_rules) |
| 929 | goto nla_put_failure; |
| 930 | |
| 931 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 932 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 933 | |
| 934 | if (!nl_wmm_rule) |
| 935 | goto nla_put_failure; |
| 936 | |
| 937 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 938 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 939 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 940 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 941 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 942 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 943 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 944 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 945 | goto nla_put_failure; |
| 946 | |
| 947 | nla_nest_end(msg, nl_wmm_rule); |
| 948 | } |
| 949 | nla_nest_end(msg, nl_wmm_rules); |
| 950 | |
| 951 | return 0; |
| 952 | |
| 953 | nla_put_failure: |
| 954 | return -ENOBUFS; |
| 955 | } |
| 956 | |
| 957 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 958 | struct ieee80211_channel *chan, |
| 959 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 960 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 961 | /* Some channels must be completely excluded from the |
| 962 | * list to protect old user-space tools from breaking |
| 963 | */ |
| 964 | if (!large && chan->flags & |
| 965 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 966 | return 0; |
| 967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 968 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 969 | chan->center_freq)) |
| 970 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 971 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 972 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
| 973 | goto nla_put_failure; |
| 974 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 975 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 976 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 977 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 978 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 979 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 980 | goto nla_put_failure; |
| 981 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 982 | goto nla_put_failure; |
| 983 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 984 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 985 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 986 | goto nla_put_failure; |
| 987 | if (large) { |
| 988 | u32 time; |
| 989 | |
| 990 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 991 | |
| 992 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 993 | chan->dfs_state)) |
| 994 | goto nla_put_failure; |
| 995 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 996 | time)) |
| 997 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 998 | if (nla_put_u32(msg, |
| 999 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 1000 | chan->dfs_cac_ms)) |
| 1001 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1002 | } |
| 1003 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1004 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1005 | if (large) { |
| 1006 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 1007 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 1008 | goto nla_put_failure; |
| 1009 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 1010 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 1011 | goto nla_put_failure; |
| 1012 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 1013 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 1014 | goto nla_put_failure; |
| 1015 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 1016 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 1017 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1018 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 1019 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 1020 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1021 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 1022 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1023 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1024 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 1025 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 1026 | goto nla_put_failure; |
| 1027 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 1028 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 1029 | goto nla_put_failure; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 1030 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 1031 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 1032 | goto nla_put_failure; |
Thomas Pedersen | d65a977 | 2020-09-08 12:03:03 -0700 | [diff] [blame] | 1033 | if ((chan->flags & IEEE80211_CHAN_1MHZ) && |
| 1034 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) |
| 1035 | goto nla_put_failure; |
| 1036 | if ((chan->flags & IEEE80211_CHAN_2MHZ) && |
| 1037 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) |
| 1038 | goto nla_put_failure; |
| 1039 | if ((chan->flags & IEEE80211_CHAN_4MHZ) && |
| 1040 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) |
| 1041 | goto nla_put_failure; |
| 1042 | if ((chan->flags & IEEE80211_CHAN_8MHZ) && |
| 1043 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) |
| 1044 | goto nla_put_failure; |
| 1045 | if ((chan->flags & IEEE80211_CHAN_16MHZ) && |
| 1046 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) |
| 1047 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1050 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 1051 | DBM_TO_MBM(chan->max_power))) |
| 1052 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1053 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1054 | if (large) { |
| 1055 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 1056 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1057 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1058 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1059 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1060 | goto nla_put_failure; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1064 | return 0; |
| 1065 | |
| 1066 | nla_put_failure: |
| 1067 | return -ENOBUFS; |
| 1068 | } |
| 1069 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1070 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1071 | struct cfg80211_txq_stats *txqstats, |
| 1072 | int attrtype) |
| 1073 | { |
| 1074 | struct nlattr *txqattr; |
| 1075 | |
| 1076 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1077 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1078 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1079 | return false; \ |
| 1080 | } while (0) |
| 1081 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1082 | txqattr = nla_nest_start_noflag(msg, attrtype); |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1083 | if (!txqattr) |
| 1084 | return false; |
| 1085 | |
| 1086 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1087 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1088 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1089 | PUT_TXQVAL_U32(DROPS, drops); |
| 1090 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1091 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1092 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1093 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1094 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1095 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1096 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1097 | nla_nest_end(msg, txqattr); |
| 1098 | |
| 1099 | #undef PUT_TXQVAL_U32 |
| 1100 | return true; |
| 1101 | } |
| 1102 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1103 | /* netlink command implementations */ |
| 1104 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1105 | struct key_parse { |
| 1106 | struct key_params p; |
| 1107 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1108 | int type; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1109 | bool def, defmgmt, defbeacon; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1110 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1111 | }; |
| 1112 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1113 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1114 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1115 | { |
| 1116 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1117 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1118 | nl80211_key_policy, |
| 1119 | info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1120 | if (err) |
| 1121 | return err; |
| 1122 | |
| 1123 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1124 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1125 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1126 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1127 | if (k->def) { |
| 1128 | k->def_uni = true; |
| 1129 | k->def_multi = true; |
| 1130 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1131 | if (k->defmgmt || k->defbeacon) |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1132 | k->def_multi = true; |
| 1133 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1134 | if (tb[NL80211_KEY_IDX]) |
| 1135 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1136 | |
| 1137 | if (tb[NL80211_KEY_DATA]) { |
| 1138 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1139 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1140 | } |
| 1141 | |
| 1142 | if (tb[NL80211_KEY_SEQ]) { |
| 1143 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1144 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1145 | } |
| 1146 | |
| 1147 | if (tb[NL80211_KEY_CIPHER]) |
| 1148 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1149 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1150 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1151 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1152 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1153 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1154 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1155 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1156 | err = nla_parse_nested_deprecated(kdt, |
| 1157 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1158 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1159 | nl80211_key_default_policy, |
| 1160 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1161 | if (err) |
| 1162 | return err; |
| 1163 | |
| 1164 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1165 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1166 | } |
| 1167 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 1168 | if (tb[NL80211_KEY_MODE]) |
| 1169 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1170 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1175 | { |
| 1176 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1177 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1178 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1179 | } |
| 1180 | |
| 1181 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1182 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1183 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1184 | } |
| 1185 | |
| 1186 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1187 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1188 | |
| 1189 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1190 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1191 | |
| 1192 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1193 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1194 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1195 | if (k->def) { |
| 1196 | k->def_uni = true; |
| 1197 | k->def_multi = true; |
| 1198 | } |
| 1199 | if (k->defmgmt) |
| 1200 | k->def_multi = true; |
| 1201 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1202 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1203 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1204 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1205 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1206 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1207 | int err = nla_parse_nested_deprecated(kdt, |
| 1208 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1209 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1210 | nl80211_key_default_policy, |
| 1211 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1212 | if (err) |
| 1213 | return err; |
| 1214 | |
| 1215 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1216 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1217 | } |
| 1218 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1223 | { |
| 1224 | int err; |
| 1225 | |
| 1226 | memset(k, 0, sizeof(*k)); |
| 1227 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1228 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1229 | |
| 1230 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1231 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1232 | else |
| 1233 | err = nl80211_parse_key_old(info, k); |
| 1234 | |
| 1235 | if (err) |
| 1236 | return err; |
| 1237 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1238 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1239 | (k->defbeacon ? 1 : 0) > 1) { |
| 1240 | GENL_SET_ERR_MSG(info, |
| 1241 | "key with multiple default flags is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1242 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1243 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1244 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1245 | if (k->defmgmt || k->defbeacon) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1246 | if (k->def_uni || !k->def_multi) { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1247 | GENL_SET_ERR_MSG(info, |
| 1248 | "defmgmt/defbeacon key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1249 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1250 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1251 | } |
| 1252 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1253 | if (k->idx != -1) { |
| 1254 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1255 | if (k->idx < 4 || k->idx > 5) { |
| 1256 | GENL_SET_ERR_MSG(info, |
| 1257 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1258 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1259 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1260 | } else if (k->defbeacon) { |
| 1261 | if (k->idx < 6 || k->idx > 7) { |
| 1262 | GENL_SET_ERR_MSG(info, |
| 1263 | "defbeacon key idx not 6 or 7"); |
| 1264 | return -EINVAL; |
| 1265 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1266 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1267 | if (k->idx < 0 || k->idx > 3) { |
| 1268 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1269 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1270 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1271 | } else { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1272 | if (k->idx < 0 || k->idx > 7) { |
| 1273 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1274 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1275 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1282 | static struct cfg80211_cached_keys * |
| 1283 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1284 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1285 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1286 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1287 | struct key_parse parse; |
| 1288 | struct nlattr *key; |
| 1289 | struct cfg80211_cached_keys *result; |
| 1290 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1291 | bool have_key = false; |
| 1292 | |
| 1293 | nla_for_each_nested(key, keys, rem) { |
| 1294 | have_key = true; |
| 1295 | break; |
| 1296 | } |
| 1297 | |
| 1298 | if (!have_key) |
| 1299 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1300 | |
| 1301 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1302 | if (!result) |
| 1303 | return ERR_PTR(-ENOMEM); |
| 1304 | |
| 1305 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1306 | |
| 1307 | nla_for_each_nested(key, keys, rem) { |
| 1308 | memset(&parse, 0, sizeof(parse)); |
| 1309 | parse.idx = -1; |
| 1310 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1311 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1312 | if (err) |
| 1313 | goto error; |
| 1314 | err = -EINVAL; |
| 1315 | if (!parse.p.key) |
| 1316 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1317 | if (parse.idx < 0 || parse.idx > 3) { |
| 1318 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1319 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1320 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1321 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1322 | if (def) { |
| 1323 | GENL_SET_ERR_MSG(info, |
| 1324 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1325 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1326 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1327 | def = 1; |
| 1328 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1329 | if (!parse.def_uni || !parse.def_multi) |
| 1330 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1331 | } else if (parse.defmgmt) |
| 1332 | goto error; |
| 1333 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1334 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1335 | if (err) |
| 1336 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1337 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1338 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1339 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1340 | err = -EINVAL; |
| 1341 | goto error; |
| 1342 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1343 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1344 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1345 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1346 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1347 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1348 | /* must be WEP key if we got here */ |
| 1349 | if (no_ht) |
| 1350 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1351 | } |
| 1352 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1353 | if (result->def < 0) { |
| 1354 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1355 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1356 | goto error; |
| 1357 | } |
| 1358 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1359 | return result; |
| 1360 | error: |
| 1361 | kfree(result); |
| 1362 | return ERR_PTR(err); |
| 1363 | } |
| 1364 | |
| 1365 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1366 | { |
| 1367 | ASSERT_WDEV_LOCK(wdev); |
| 1368 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1369 | switch (wdev->iftype) { |
| 1370 | case NL80211_IFTYPE_AP: |
| 1371 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1372 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1373 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1374 | break; |
| 1375 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1376 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1377 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1378 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1379 | return -ENOLINK; |
| 1380 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1381 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1382 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1383 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1384 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1385 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1386 | case NL80211_IFTYPE_WDS: |
| 1387 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1388 | return -EINVAL; |
| 1389 | } |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1394 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1395 | u32 freq) |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1396 | { |
| 1397 | struct ieee80211_channel *chan; |
| 1398 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1399 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1400 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1401 | return NULL; |
| 1402 | return chan; |
| 1403 | } |
| 1404 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1405 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1406 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1407 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1408 | int i; |
| 1409 | |
| 1410 | if (!nl_modes) |
| 1411 | goto nla_put_failure; |
| 1412 | |
| 1413 | i = 0; |
| 1414 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1415 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1416 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1417 | ifmodes >>= 1; |
| 1418 | i++; |
| 1419 | } |
| 1420 | |
| 1421 | nla_nest_end(msg, nl_modes); |
| 1422 | return 0; |
| 1423 | |
| 1424 | nla_put_failure: |
| 1425 | return -ENOBUFS; |
| 1426 | } |
| 1427 | |
| 1428 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1429 | struct sk_buff *msg, |
| 1430 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1431 | { |
| 1432 | struct nlattr *nl_combis; |
| 1433 | int i, j; |
| 1434 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1435 | nl_combis = nla_nest_start_noflag(msg, |
| 1436 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1437 | if (!nl_combis) |
| 1438 | goto nla_put_failure; |
| 1439 | |
| 1440 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1441 | const struct ieee80211_iface_combination *c; |
| 1442 | struct nlattr *nl_combi, *nl_limits; |
| 1443 | |
| 1444 | c = &wiphy->iface_combinations[i]; |
| 1445 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1446 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1447 | if (!nl_combi) |
| 1448 | goto nla_put_failure; |
| 1449 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1450 | nl_limits = nla_nest_start_noflag(msg, |
| 1451 | NL80211_IFACE_COMB_LIMITS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1452 | if (!nl_limits) |
| 1453 | goto nla_put_failure; |
| 1454 | |
| 1455 | for (j = 0; j < c->n_limits; j++) { |
| 1456 | struct nlattr *nl_limit; |
| 1457 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1458 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1459 | if (!nl_limit) |
| 1460 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1461 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1462 | c->limits[j].max)) |
| 1463 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1464 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1465 | c->limits[j].types)) |
| 1466 | goto nla_put_failure; |
| 1467 | nla_nest_end(msg, nl_limit); |
| 1468 | } |
| 1469 | |
| 1470 | nla_nest_end(msg, nl_limits); |
| 1471 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1472 | if (c->beacon_int_infra_match && |
| 1473 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1474 | goto nla_put_failure; |
| 1475 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1476 | c->num_different_channels) || |
| 1477 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1478 | c->max_interfaces)) |
| 1479 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1480 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1481 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1482 | c->radar_detect_widths) || |
| 1483 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1484 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1485 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1486 | if (c->beacon_int_min_gcd && |
| 1487 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1488 | c->beacon_int_min_gcd)) |
| 1489 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1490 | |
| 1491 | nla_nest_end(msg, nl_combi); |
| 1492 | } |
| 1493 | |
| 1494 | nla_nest_end(msg, nl_combis); |
| 1495 | |
| 1496 | return 0; |
| 1497 | nla_put_failure: |
| 1498 | return -ENOBUFS; |
| 1499 | } |
| 1500 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1502 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1503 | struct sk_buff *msg) |
| 1504 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1505 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1506 | struct nlattr *nl_tcp; |
| 1507 | |
| 1508 | if (!tcp) |
| 1509 | return 0; |
| 1510 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1511 | nl_tcp = nla_nest_start_noflag(msg, |
| 1512 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1513 | if (!nl_tcp) |
| 1514 | return -ENOBUFS; |
| 1515 | |
| 1516 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1517 | tcp->data_payload_max)) |
| 1518 | return -ENOBUFS; |
| 1519 | |
| 1520 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1521 | tcp->data_payload_max)) |
| 1522 | return -ENOBUFS; |
| 1523 | |
| 1524 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1525 | return -ENOBUFS; |
| 1526 | |
| 1527 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1528 | sizeof(*tcp->tok), tcp->tok)) |
| 1529 | return -ENOBUFS; |
| 1530 | |
| 1531 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1532 | tcp->data_interval_max)) |
| 1533 | return -ENOBUFS; |
| 1534 | |
| 1535 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1536 | tcp->wake_payload_max)) |
| 1537 | return -ENOBUFS; |
| 1538 | |
| 1539 | nla_nest_end(msg, nl_tcp); |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1543 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1544 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1545 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | { |
| 1547 | struct nlattr *nl_wowlan; |
| 1548 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1549 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | return 0; |
| 1551 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1552 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1553 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | if (!nl_wowlan) |
| 1555 | return -ENOBUFS; |
| 1556 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1557 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1558 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1559 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1561 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1563 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1567 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1569 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1570 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1571 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1573 | return -ENOBUFS; |
| 1574 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1575 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1576 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1577 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1578 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1579 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1580 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1581 | }; |
| 1582 | |
| 1583 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1584 | sizeof(pat), &pat)) |
| 1585 | return -ENOBUFS; |
| 1586 | } |
| 1587 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1588 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1589 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1590 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1591 | return -ENOBUFS; |
| 1592 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1594 | return -ENOBUFS; |
| 1595 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | nla_nest_end(msg, nl_wowlan); |
| 1597 | |
| 1598 | return 0; |
| 1599 | } |
| 1600 | #endif |
| 1601 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1602 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1603 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1604 | { |
| 1605 | struct nl80211_coalesce_rule_support rule; |
| 1606 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1608 | return 0; |
| 1609 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1610 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1611 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1612 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1613 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1614 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1615 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1616 | |
| 1617 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1618 | return -ENOBUFS; |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1623 | static int |
| 1624 | nl80211_send_iftype_data(struct sk_buff *msg, |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1625 | const struct ieee80211_supported_band *sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1626 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1627 | { |
| 1628 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1629 | |
| 1630 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1631 | iftdata->types_mask)) |
| 1632 | return -ENOBUFS; |
| 1633 | |
| 1634 | if (he_cap->has_he) { |
| 1635 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1636 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1637 | he_cap->he_cap_elem.mac_cap_info) || |
| 1638 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1639 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1640 | he_cap->he_cap_elem.phy_cap_info) || |
| 1641 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1642 | sizeof(he_cap->he_mcs_nss_supp), |
| 1643 | &he_cap->he_mcs_nss_supp) || |
| 1644 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1645 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1646 | return -ENOBUFS; |
| 1647 | } |
| 1648 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1649 | if (sband->band == NL80211_BAND_6GHZ && |
| 1650 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, |
| 1651 | sizeof(iftdata->he_6ghz_capa), |
| 1652 | &iftdata->he_6ghz_capa)) |
| 1653 | return -ENOBUFS; |
| 1654 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
| 1657 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1658 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1659 | struct ieee80211_supported_band *sband) |
| 1660 | { |
| 1661 | struct nlattr *nl_rates, *nl_rate; |
| 1662 | struct ieee80211_rate *rate; |
| 1663 | int i; |
| 1664 | |
| 1665 | /* add HT info */ |
| 1666 | if (sband->ht_cap.ht_supported && |
| 1667 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1668 | sizeof(sband->ht_cap.mcs), |
| 1669 | &sband->ht_cap.mcs) || |
| 1670 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1671 | sband->ht_cap.cap) || |
| 1672 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1673 | sband->ht_cap.ampdu_factor) || |
| 1674 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1675 | sband->ht_cap.ampdu_density))) |
| 1676 | return -ENOBUFS; |
| 1677 | |
| 1678 | /* add VHT info */ |
| 1679 | if (sband->vht_cap.vht_supported && |
| 1680 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1681 | sizeof(sband->vht_cap.vht_mcs), |
| 1682 | &sband->vht_cap.vht_mcs) || |
| 1683 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1684 | sband->vht_cap.cap))) |
| 1685 | return -ENOBUFS; |
| 1686 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1687 | if (sband->n_iftype_data) { |
| 1688 | struct nlattr *nl_iftype_data = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1689 | nla_nest_start_noflag(msg, |
| 1690 | NL80211_BAND_ATTR_IFTYPE_DATA); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1691 | int err; |
| 1692 | |
| 1693 | if (!nl_iftype_data) |
| 1694 | return -ENOBUFS; |
| 1695 | |
| 1696 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1697 | struct nlattr *iftdata; |
| 1698 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1699 | iftdata = nla_nest_start_noflag(msg, i + 1); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1700 | if (!iftdata) |
| 1701 | return -ENOBUFS; |
| 1702 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1703 | err = nl80211_send_iftype_data(msg, sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1704 | &sband->iftype_data[i]); |
| 1705 | if (err) |
| 1706 | return err; |
| 1707 | |
| 1708 | nla_nest_end(msg, iftdata); |
| 1709 | } |
| 1710 | |
| 1711 | nla_nest_end(msg, nl_iftype_data); |
| 1712 | } |
| 1713 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1714 | /* add EDMG info */ |
| 1715 | if (sband->edmg_cap.channels && |
| 1716 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1717 | sband->edmg_cap.channels) || |
| 1718 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1719 | sband->edmg_cap.bw_config))) |
| 1720 | |
| 1721 | return -ENOBUFS; |
| 1722 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1723 | /* add bitrates */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1724 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1725 | if (!nl_rates) |
| 1726 | return -ENOBUFS; |
| 1727 | |
| 1728 | for (i = 0; i < sband->n_bitrates; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1729 | nl_rate = nla_nest_start_noflag(msg, i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1730 | if (!nl_rate) |
| 1731 | return -ENOBUFS; |
| 1732 | |
| 1733 | rate = &sband->bitrates[i]; |
| 1734 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1735 | rate->bitrate)) |
| 1736 | return -ENOBUFS; |
| 1737 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1738 | nla_put_flag(msg, |
| 1739 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1740 | return -ENOBUFS; |
| 1741 | |
| 1742 | nla_nest_end(msg, nl_rate); |
| 1743 | } |
| 1744 | |
| 1745 | nla_nest_end(msg, nl_rates); |
| 1746 | |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
| 1750 | static int |
| 1751 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1752 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1753 | { |
| 1754 | u16 stypes; |
| 1755 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1756 | enum nl80211_iftype ift; |
| 1757 | int i; |
| 1758 | |
| 1759 | if (!mgmt_stypes) |
| 1760 | return 0; |
| 1761 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1762 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1763 | if (!nl_ifs) |
| 1764 | return -ENOBUFS; |
| 1765 | |
| 1766 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1767 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1768 | if (!nl_ftypes) |
| 1769 | return -ENOBUFS; |
| 1770 | i = 0; |
| 1771 | stypes = mgmt_stypes[ift].tx; |
| 1772 | while (stypes) { |
| 1773 | if ((stypes & 1) && |
| 1774 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1775 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1776 | return -ENOBUFS; |
| 1777 | stypes >>= 1; |
| 1778 | i++; |
| 1779 | } |
| 1780 | nla_nest_end(msg, nl_ftypes); |
| 1781 | } |
| 1782 | |
| 1783 | nla_nest_end(msg, nl_ifs); |
| 1784 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1785 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1786 | if (!nl_ifs) |
| 1787 | return -ENOBUFS; |
| 1788 | |
| 1789 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1790 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1791 | if (!nl_ftypes) |
| 1792 | return -ENOBUFS; |
| 1793 | i = 0; |
| 1794 | stypes = mgmt_stypes[ift].rx; |
| 1795 | while (stypes) { |
| 1796 | if ((stypes & 1) && |
| 1797 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1798 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1799 | return -ENOBUFS; |
| 1800 | stypes >>= 1; |
| 1801 | i++; |
| 1802 | } |
| 1803 | nla_nest_end(msg, nl_ftypes); |
| 1804 | } |
| 1805 | nla_nest_end(msg, nl_ifs); |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1810 | #define CMD(op, n) \ |
| 1811 | do { \ |
| 1812 | if (rdev->ops->op) { \ |
| 1813 | i++; \ |
| 1814 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1815 | goto nla_put_failure; \ |
| 1816 | } \ |
| 1817 | } while (0) |
| 1818 | |
| 1819 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1820 | struct sk_buff *msg) |
| 1821 | { |
| 1822 | int i = 0; |
| 1823 | |
| 1824 | /* |
| 1825 | * do *NOT* add anything into this function, new things need to be |
| 1826 | * advertised only to new versions of userspace that can deal with |
| 1827 | * the split (and they can't possibly care about new features... |
| 1828 | */ |
| 1829 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1830 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1831 | CMD(add_key, NEW_KEY); |
| 1832 | CMD(start_ap, START_AP); |
| 1833 | CMD(add_station, NEW_STATION); |
| 1834 | CMD(add_mpath, NEW_MPATH); |
| 1835 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1836 | CMD(change_bss, SET_BSS); |
| 1837 | CMD(auth, AUTHENTICATE); |
| 1838 | CMD(assoc, ASSOCIATE); |
| 1839 | CMD(deauth, DEAUTHENTICATE); |
| 1840 | CMD(disassoc, DISASSOCIATE); |
| 1841 | CMD(join_ibss, JOIN_IBSS); |
| 1842 | CMD(join_mesh, JOIN_MESH); |
| 1843 | CMD(set_pmksa, SET_PMKSA); |
| 1844 | CMD(del_pmksa, DEL_PMKSA); |
| 1845 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1846 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1847 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1848 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1849 | CMD(mgmt_tx, FRAME); |
| 1850 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1851 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1852 | i++; |
| 1853 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1854 | goto nla_put_failure; |
| 1855 | } |
| 1856 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1857 | rdev->ops->join_mesh) { |
| 1858 | i++; |
| 1859 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1860 | goto nla_put_failure; |
| 1861 | } |
| 1862 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1863 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1864 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1865 | CMD(tdls_oper, TDLS_OPER); |
| 1866 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1867 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1868 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1869 | CMD(probe_client, PROBE_CLIENT); |
| 1870 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1871 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1872 | i++; |
| 1873 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1874 | goto nla_put_failure; |
| 1875 | } |
| 1876 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1877 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1878 | #ifdef CONFIG_NL80211_TESTMODE |
| 1879 | CMD(testmode_cmd, TESTMODE); |
| 1880 | #endif |
| 1881 | |
| 1882 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1883 | i++; |
| 1884 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1885 | goto nla_put_failure; |
| 1886 | } |
| 1887 | |
| 1888 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1889 | i++; |
| 1890 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1891 | goto nla_put_failure; |
| 1892 | } |
| 1893 | |
| 1894 | return i; |
| 1895 | nla_put_failure: |
| 1896 | return -ENOBUFS; |
| 1897 | } |
| 1898 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1899 | static int |
| 1900 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1901 | struct sk_buff *msg) |
| 1902 | { |
| 1903 | struct nlattr *ftm; |
| 1904 | |
| 1905 | if (!cap->ftm.supported) |
| 1906 | return 0; |
| 1907 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1908 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1909 | if (!ftm) |
| 1910 | return -ENOBUFS; |
| 1911 | |
| 1912 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1913 | return -ENOBUFS; |
| 1914 | if (cap->ftm.non_asap && |
| 1915 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1916 | return -ENOBUFS; |
| 1917 | if (cap->ftm.request_lci && |
| 1918 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1919 | return -ENOBUFS; |
| 1920 | if (cap->ftm.request_civicloc && |
| 1921 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1922 | return -ENOBUFS; |
| 1923 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1924 | cap->ftm.preambles)) |
| 1925 | return -ENOBUFS; |
| 1926 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1927 | cap->ftm.bandwidths)) |
| 1928 | return -ENOBUFS; |
| 1929 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1930 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1931 | cap->ftm.max_bursts_exponent)) |
| 1932 | return -ENOBUFS; |
| 1933 | if (cap->ftm.max_ftms_per_burst && |
| 1934 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1935 | cap->ftm.max_ftms_per_burst)) |
| 1936 | return -ENOBUFS; |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 1937 | if (cap->ftm.trigger_based && |
| 1938 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) |
| 1939 | return -ENOBUFS; |
| 1940 | if (cap->ftm.non_trigger_based && |
| 1941 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) |
| 1942 | return -ENOBUFS; |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1943 | |
| 1944 | nla_nest_end(msg, ftm); |
| 1945 | return 0; |
| 1946 | } |
| 1947 | |
| 1948 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1949 | struct sk_buff *msg) |
| 1950 | { |
| 1951 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1952 | struct nlattr *pmsr, *caps; |
| 1953 | |
| 1954 | if (!cap) |
| 1955 | return 0; |
| 1956 | |
| 1957 | /* |
| 1958 | * we don't need to clean up anything here since the caller |
| 1959 | * will genlmsg_cancel() if we fail |
| 1960 | */ |
| 1961 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1962 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1963 | if (!pmsr) |
| 1964 | return -ENOBUFS; |
| 1965 | |
| 1966 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1967 | return -ENOBUFS; |
| 1968 | |
| 1969 | if (cap->report_ap_tsf && |
| 1970 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1971 | return -ENOBUFS; |
| 1972 | |
| 1973 | if (cap->randomize_mac_addr && |
| 1974 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 1975 | return -ENOBUFS; |
| 1976 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1977 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1978 | if (!caps) |
| 1979 | return -ENOBUFS; |
| 1980 | |
| 1981 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 1982 | return -ENOBUFS; |
| 1983 | |
| 1984 | nla_nest_end(msg, caps); |
| 1985 | nla_nest_end(msg, pmsr); |
| 1986 | |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 1990 | static int |
| 1991 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 1992 | struct sk_buff *msg) |
| 1993 | { |
| 1994 | int i; |
| 1995 | struct nlattr *nested, *nested_akms; |
| 1996 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 1997 | |
| 1998 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 1999 | !rdev->wiphy.iftype_akm_suites) |
| 2000 | return 0; |
| 2001 | |
| 2002 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 2003 | if (!nested) |
| 2004 | return -ENOBUFS; |
| 2005 | |
| 2006 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 2007 | nested_akms = nla_nest_start(msg, i + 1); |
| 2008 | if (!nested_akms) |
| 2009 | return -ENOBUFS; |
| 2010 | |
| 2011 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 2012 | |
| 2013 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 2014 | iftype_akms->iftypes_mask)) |
| 2015 | return -ENOBUFS; |
| 2016 | |
| 2017 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 2018 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 2019 | iftype_akms->akm_suites)) { |
| 2020 | return -ENOBUFS; |
| 2021 | } |
| 2022 | nla_nest_end(msg, nested_akms); |
| 2023 | } |
| 2024 | |
| 2025 | nla_nest_end(msg, nested); |
| 2026 | |
| 2027 | return 0; |
| 2028 | } |
| 2029 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2030 | static int |
| 2031 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 2032 | struct sk_buff *msg) |
| 2033 | { |
| 2034 | struct nlattr *supp; |
| 2035 | |
| 2036 | if (!rdev->wiphy.tid_config_support.vif && |
| 2037 | !rdev->wiphy.tid_config_support.peer) |
| 2038 | return 0; |
| 2039 | |
| 2040 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 2041 | if (!supp) |
| 2042 | return -ENOSPC; |
| 2043 | |
| 2044 | if (rdev->wiphy.tid_config_support.vif && |
| 2045 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 2046 | rdev->wiphy.tid_config_support.vif, |
| 2047 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2048 | goto fail; |
| 2049 | |
| 2050 | if (rdev->wiphy.tid_config_support.peer && |
| 2051 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 2052 | rdev->wiphy.tid_config_support.peer, |
| 2053 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2054 | goto fail; |
| 2055 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 2056 | /* for now we just use the same value ... makes more sense */ |
| 2057 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, |
| 2058 | rdev->wiphy.tid_config_support.max_retry)) |
| 2059 | goto fail; |
| 2060 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, |
| 2061 | rdev->wiphy.tid_config_support.max_retry)) |
| 2062 | goto fail; |
| 2063 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2064 | nla_nest_end(msg, supp); |
| 2065 | |
| 2066 | return 0; |
| 2067 | fail: |
| 2068 | nla_nest_cancel(msg, supp); |
| 2069 | return -ENOBUFS; |
| 2070 | } |
| 2071 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2072 | struct nl80211_dump_wiphy_state { |
| 2073 | s64 filter_wiphy; |
| 2074 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2075 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2076 | bool split; |
| 2077 | }; |
| 2078 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2079 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2080 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2081 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2082 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2083 | { |
| 2084 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2085 | struct nlattr *nl_bands, *nl_band; |
| 2086 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2087 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2088 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2089 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2090 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2091 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2092 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2093 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2094 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2095 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2096 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2097 | return -ENOBUFS; |
| 2098 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2099 | if (WARN_ON(!state)) |
| 2100 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2101 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2102 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2103 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2104 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2105 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2106 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2107 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2108 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2109 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2110 | goto finish; |
| 2111 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2112 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2113 | case 0: |
| 2114 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2115 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2116 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2117 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2118 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2119 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2120 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2121 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2122 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2123 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2124 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2125 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2126 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2127 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2128 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2129 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2130 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2131 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2132 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 2133 | rdev->wiphy.max_match_sets) || |
| 2134 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2135 | rdev->wiphy.max_sched_scan_plans) || |
| 2136 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2137 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2138 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2139 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2140 | goto nla_put_failure; |
| 2141 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2142 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2143 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2144 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2145 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2146 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2147 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2148 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2149 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2150 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2151 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2152 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2153 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2154 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2155 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2156 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2157 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2158 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2159 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2160 | state->split_start++; |
| 2161 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2162 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2163 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2164 | case 1: |
| 2165 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2166 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2167 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 2168 | goto nla_put_failure; |
| 2169 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2170 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2171 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2172 | goto nla_put_failure; |
| 2173 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2174 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2175 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2176 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2177 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2179 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2180 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2181 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2182 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2183 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2184 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2185 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2186 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2187 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 2188 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2189 | if ((rdev->wiphy.available_antennas_tx || |
| 2190 | rdev->wiphy.available_antennas_rx) && |
| 2191 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2192 | u32 tx_ant = 0, rx_ant = 0; |
| 2193 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2194 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2195 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2196 | if (!res) { |
| 2197 | if (nla_put_u32(msg, |
| 2198 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2199 | tx_ant) || |
| 2200 | nla_put_u32(msg, |
| 2201 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2202 | rx_ant)) |
| 2203 | goto nla_put_failure; |
| 2204 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2205 | } |
| 2206 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2207 | state->split_start++; |
| 2208 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2209 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2210 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2211 | case 2: |
| 2212 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2213 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2214 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2215 | state->split_start++; |
| 2216 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2217 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2218 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2219 | case 3: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2220 | nl_bands = nla_nest_start_noflag(msg, |
| 2221 | NL80211_ATTR_WIPHY_BANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2222 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2223 | goto nla_put_failure; |
| 2224 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2225 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2226 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2227 | struct ieee80211_supported_band *sband; |
| 2228 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2229 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2230 | |
| 2231 | if (!sband) |
| 2232 | continue; |
| 2233 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2234 | nl_band = nla_nest_start_noflag(msg, band); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2235 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2236 | goto nla_put_failure; |
| 2237 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2238 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2239 | case 0: |
| 2240 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 2241 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2242 | state->chan_start++; |
| 2243 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2244 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2245 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2246 | default: |
| 2247 | /* add frequencies */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2248 | nl_freqs = nla_nest_start_noflag(msg, |
| 2249 | NL80211_BAND_ATTR_FREQS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2250 | if (!nl_freqs) |
| 2251 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2252 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2253 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2254 | i < sband->n_channels; |
| 2255 | i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2256 | nl_freq = nla_nest_start_noflag(msg, |
| 2257 | i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2258 | if (!nl_freq) |
| 2259 | goto nla_put_failure; |
| 2260 | |
| 2261 | chan = &sband->channels[i]; |
| 2262 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2263 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 2264 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2265 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2266 | goto nla_put_failure; |
| 2267 | |
| 2268 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2269 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2270 | break; |
| 2271 | } |
| 2272 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2273 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2274 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2275 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2276 | nla_nest_end(msg, nl_freqs); |
| 2277 | } |
| 2278 | |
| 2279 | nla_nest_end(msg, nl_band); |
| 2280 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2281 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2282 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2283 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2284 | band--; |
| 2285 | break; |
| 2286 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2287 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2288 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2289 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2290 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2291 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2292 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2293 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2294 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2295 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2296 | if (state->band_start == 0 && state->chan_start == 0) |
| 2297 | state->split_start++; |
| 2298 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2299 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2300 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2301 | case 4: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2302 | nl_cmds = nla_nest_start_noflag(msg, |
| 2303 | NL80211_ATTR_SUPPORTED_COMMANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2304 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2305 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2306 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 2307 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2308 | if (i < 0) |
| 2309 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2310 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2311 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2312 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2313 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2314 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2315 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2316 | if (rdev->wiphy.features & |
| 2317 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2318 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2319 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2320 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Matthew Wang | 7010998 | 2019-08-22 10:48:06 -0700 | [diff] [blame] | 2321 | CMD(update_ft_ies, UPDATE_FT_IES); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2322 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2323 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2324 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2325 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2326 | state->split_start++; |
| 2327 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2328 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2329 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2330 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2331 | if (rdev->ops->remain_on_channel && |
| 2332 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2333 | nla_put_u32(msg, |
| 2334 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2335 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2336 | goto nla_put_failure; |
| 2337 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2338 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2339 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2340 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2341 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2342 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2343 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2344 | state->split_start++; |
| 2345 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2346 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2347 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2348 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2349 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2350 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2351 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2352 | state->split_start++; |
| 2353 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2354 | break; |
| 2355 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2356 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2357 | #endif |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2358 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2359 | case 7: |
| 2360 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2361 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2362 | goto nla_put_failure; |
| 2363 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2364 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2365 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2366 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2367 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2368 | state->split_start++; |
| 2369 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2370 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2371 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2372 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2373 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2374 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2375 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2376 | goto nla_put_failure; |
| 2377 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2378 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2379 | /* |
| 2380 | * We can only add the per-channel limit information if the |
| 2381 | * dump is split, otherwise it makes it too big. Therefore |
| 2382 | * only advertise it in that case. |
| 2383 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2384 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2385 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2386 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2387 | goto nla_put_failure; |
| 2388 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2389 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2390 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2391 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2392 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2393 | goto nla_put_failure; |
| 2394 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2395 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2396 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2397 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2398 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2399 | goto nla_put_failure; |
| 2400 | |
| 2401 | /* |
| 2402 | * Any information below this point is only available to |
| 2403 | * applications that can deal with it being split. This |
| 2404 | * helps ensure that newly added capabilities don't break |
| 2405 | * older tools by overrunning their buffers. |
| 2406 | * |
| 2407 | * We still increment split_start so that in the split |
| 2408 | * case we'll continue with more data in the next round, |
| 2409 | * but break unconditionally so unsplit data stops here. |
| 2410 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2411 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2412 | break; |
| 2413 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2414 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2415 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2416 | rdev->wiphy.extended_capabilities_len, |
| 2417 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2418 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2419 | rdev->wiphy.extended_capabilities_len, |
| 2420 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2421 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2422 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2423 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2424 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2425 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2426 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2427 | goto nla_put_failure; |
| 2428 | |
Denis Kenzior | ae6fa4d | 2019-07-22 06:33:12 -0500 | [diff] [blame] | 2429 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2430 | rdev->wiphy.perm_addr)) |
| 2431 | goto nla_put_failure; |
| 2432 | |
| 2433 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2434 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2435 | rdev->wiphy.addr_mask)) |
| 2436 | goto nla_put_failure; |
| 2437 | |
| 2438 | if (rdev->wiphy.n_addresses > 1) { |
| 2439 | void *attr; |
| 2440 | |
| 2441 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2442 | if (!attr) |
| 2443 | goto nla_put_failure; |
| 2444 | |
| 2445 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2446 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2447 | rdev->wiphy.addresses[i].addr)) |
| 2448 | goto nla_put_failure; |
| 2449 | |
| 2450 | nla_nest_end(msg, attr); |
| 2451 | } |
| 2452 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2453 | state->split_start++; |
| 2454 | break; |
| 2455 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2456 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2457 | goto nla_put_failure; |
| 2458 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2459 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2460 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2461 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2462 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2463 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2464 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2465 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2466 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2467 | goto nla_put_failure; |
| 2468 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2469 | state->split_start++; |
| 2470 | break; |
| 2471 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2472 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2473 | const struct nl80211_vendor_cmd_info *info; |
| 2474 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2475 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2476 | nested = nla_nest_start_noflag(msg, |
| 2477 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2478 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2479 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2480 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2481 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2482 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2483 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2484 | goto nla_put_failure; |
| 2485 | } |
| 2486 | nla_nest_end(msg, nested); |
| 2487 | } |
| 2488 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2489 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2490 | const struct nl80211_vendor_cmd_info *info; |
| 2491 | struct nlattr *nested; |
| 2492 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2493 | nested = nla_nest_start_noflag(msg, |
| 2494 | NL80211_ATTR_VENDOR_EVENTS); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2495 | if (!nested) |
| 2496 | goto nla_put_failure; |
| 2497 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2498 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2499 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2500 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2501 | goto nla_put_failure; |
| 2502 | } |
| 2503 | nla_nest_end(msg, nested); |
| 2504 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2505 | state->split_start++; |
| 2506 | break; |
| 2507 | case 12: |
| 2508 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2509 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2510 | rdev->wiphy.max_num_csa_counters)) |
| 2511 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2512 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2513 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2514 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2515 | goto nla_put_failure; |
| 2516 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2517 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2518 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2519 | rdev->wiphy.max_sched_scan_reqs)) |
| 2520 | goto nla_put_failure; |
| 2521 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2522 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2523 | sizeof(rdev->wiphy.ext_features), |
| 2524 | rdev->wiphy.ext_features)) |
| 2525 | goto nla_put_failure; |
| 2526 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2527 | if (rdev->wiphy.bss_select_support) { |
| 2528 | struct nlattr *nested; |
| 2529 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2530 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2531 | nested = nla_nest_start_noflag(msg, |
| 2532 | NL80211_ATTR_BSS_SELECT); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2533 | if (!nested) |
| 2534 | goto nla_put_failure; |
| 2535 | |
| 2536 | i = 0; |
| 2537 | while (bss_select_support) { |
| 2538 | if ((bss_select_support & 1) && |
| 2539 | nla_put_flag(msg, i)) |
| 2540 | goto nla_put_failure; |
| 2541 | i++; |
| 2542 | bss_select_support >>= 1; |
| 2543 | } |
| 2544 | nla_nest_end(msg, nested); |
| 2545 | } |
| 2546 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2547 | state->split_start++; |
| 2548 | break; |
| 2549 | case 13: |
| 2550 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2551 | rdev->wiphy.iftype_ext_capab) { |
| 2552 | struct nlattr *nested_ext_capab, *nested; |
| 2553 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2554 | nested = nla_nest_start_noflag(msg, |
| 2555 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2556 | if (!nested) |
| 2557 | goto nla_put_failure; |
| 2558 | |
| 2559 | for (i = state->capa_start; |
| 2560 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2561 | const struct wiphy_iftype_ext_capab *capab; |
| 2562 | |
| 2563 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2564 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2565 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2566 | i); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2567 | if (!nested_ext_capab || |
| 2568 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2569 | capab->iftype) || |
| 2570 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2571 | capab->extended_capabilities_len, |
| 2572 | capab->extended_capabilities) || |
| 2573 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2574 | capab->extended_capabilities_len, |
| 2575 | capab->extended_capabilities_mask)) |
| 2576 | goto nla_put_failure; |
| 2577 | |
| 2578 | nla_nest_end(msg, nested_ext_capab); |
| 2579 | if (state->split) |
| 2580 | break; |
| 2581 | } |
| 2582 | nla_nest_end(msg, nested); |
| 2583 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2584 | state->capa_start = i + 1; |
| 2585 | break; |
| 2586 | } |
| 2587 | } |
| 2588 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2589 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2590 | rdev->wiphy.nan_supported_bands)) |
| 2591 | goto nla_put_failure; |
| 2592 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2593 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2594 | NL80211_EXT_FEATURE_TXQS)) { |
| 2595 | struct cfg80211_txq_stats txqstats = {}; |
| 2596 | int res; |
| 2597 | |
| 2598 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2599 | if (!res && |
| 2600 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2601 | NL80211_ATTR_TXQ_STATS)) |
| 2602 | goto nla_put_failure; |
| 2603 | |
| 2604 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2605 | rdev->wiphy.txq_limit)) |
| 2606 | goto nla_put_failure; |
| 2607 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2608 | rdev->wiphy.txq_memory_limit)) |
| 2609 | goto nla_put_failure; |
| 2610 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2611 | rdev->wiphy.txq_quantum)) |
| 2612 | goto nla_put_failure; |
| 2613 | } |
| 2614 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2615 | state->split_start++; |
| 2616 | break; |
| 2617 | case 14: |
| 2618 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2619 | goto nla_put_failure; |
| 2620 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2621 | state->split_start++; |
| 2622 | break; |
| 2623 | case 15: |
| 2624 | if (rdev->wiphy.akm_suites && |
| 2625 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2626 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2627 | rdev->wiphy.akm_suites)) |
| 2628 | goto nla_put_failure; |
| 2629 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2630 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2631 | goto nla_put_failure; |
| 2632 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2633 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2634 | goto nla_put_failure; |
| 2635 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2636 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2637 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2638 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2639 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2640 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2641 | genlmsg_end(msg, hdr); |
| 2642 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2643 | |
| 2644 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2645 | genlmsg_cancel(msg, hdr); |
| 2646 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2647 | } |
| 2648 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2649 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2650 | struct netlink_callback *cb, |
| 2651 | struct nl80211_dump_wiphy_state *state) |
| 2652 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2653 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2654 | int ret; |
| 2655 | |
| 2656 | if (!tb) |
| 2657 | return -ENOMEM; |
| 2658 | |
| 2659 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2660 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2661 | tb, nl80211_fam.maxattr, |
| 2662 | nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2663 | /* ignore parse errors for backward compatibility */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2664 | if (ret) { |
| 2665 | ret = 0; |
| 2666 | goto out; |
| 2667 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2668 | |
| 2669 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2670 | if (tb[NL80211_ATTR_WIPHY]) |
| 2671 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2672 | if (tb[NL80211_ATTR_WDEV]) |
| 2673 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2674 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2675 | struct net_device *netdev; |
| 2676 | struct cfg80211_registered_device *rdev; |
| 2677 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2678 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2679 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2680 | if (!netdev) { |
| 2681 | ret = -ENODEV; |
| 2682 | goto out; |
| 2683 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2684 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2685 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2686 | netdev->ieee80211_ptr->wiphy); |
| 2687 | state->filter_wiphy = rdev->wiphy_idx; |
| 2688 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2689 | } |
| 2690 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2691 | ret = 0; |
| 2692 | out: |
| 2693 | kfree(tb); |
| 2694 | return ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2695 | } |
| 2696 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2697 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2698 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2699 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2700 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2701 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2702 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2703 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2704 | if (!state) { |
| 2705 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2706 | if (!state) { |
| 2707 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2708 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2709 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2710 | state->filter_wiphy = -1; |
| 2711 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2712 | if (ret) { |
| 2713 | kfree(state); |
| 2714 | rtnl_unlock(); |
| 2715 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2716 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2717 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2718 | } |
| 2719 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2720 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2721 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2722 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2723 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2724 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2725 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2726 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2727 | continue; |
| 2728 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2729 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2730 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2731 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2732 | NETLINK_CB(cb->skb).portid, |
| 2733 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2734 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2735 | if (ret < 0) { |
| 2736 | /* |
| 2737 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2738 | * or EMSGSIZE returned), this SKB is still |
| 2739 | * empty (so it's not too big because another |
| 2740 | * wiphy dataset is already in the skb) and |
| 2741 | * we've not tried to adjust the dump allocation |
| 2742 | * yet ... then adjust the alloc size to be |
| 2743 | * bigger, and return 1 but with the empty skb. |
| 2744 | * This results in an empty message being RX'ed |
| 2745 | * in userspace, but that is ignored. |
| 2746 | * |
| 2747 | * We can then retry with the larger buffer. |
| 2748 | */ |
| 2749 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2750 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2751 | cb->min_dump_alloc < 4096) { |
| 2752 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2753 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2754 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2755 | return 1; |
| 2756 | } |
| 2757 | idx--; |
| 2758 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2759 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2760 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2761 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2762 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2763 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2764 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2765 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2766 | |
| 2767 | return skb->len; |
| 2768 | } |
| 2769 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2770 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2771 | { |
| 2772 | kfree((void *)cb->args[0]); |
| 2773 | return 0; |
| 2774 | } |
| 2775 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2776 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2777 | { |
| 2778 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2779 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2780 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2781 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2782 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2783 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2784 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2785 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2786 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2787 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2788 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2789 | nlmsg_free(msg); |
| 2790 | return -ENOBUFS; |
| 2791 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2792 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2793 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2796 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2797 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2798 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2799 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2800 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2801 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2802 | }; |
| 2803 | |
| 2804 | static int parse_txq_params(struct nlattr *tb[], |
| 2805 | struct ieee80211_txq_params *txq_params) |
| 2806 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2807 | u8 ac; |
| 2808 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2809 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2810 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2811 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2812 | return -EINVAL; |
| 2813 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2814 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2815 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2816 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2817 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2818 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2819 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2820 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2821 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2822 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2823 | return 0; |
| 2824 | } |
| 2825 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2826 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2827 | { |
| 2828 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2829 | * You can only set the channel explicitly for WDS interfaces, |
| 2830 | * all others have their channel managed via their respective |
| 2831 | * "establish a connection" command (connect, join, ...) |
| 2832 | * |
| 2833 | * For AP/GO and mesh mode, the channel can be set with the |
| 2834 | * channel userspace API, but is only stored and passed to the |
| 2835 | * low-level driver when the AP starts or the mesh is joined. |
| 2836 | * This is for backward compatibility, userspace can also give |
| 2837 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2838 | * |
| 2839 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2840 | * whatever else is going on, so they have their own special |
| 2841 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2842 | */ |
| 2843 | return !wdev || |
| 2844 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2845 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2846 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2847 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2848 | } |
| 2849 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2850 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2851 | struct genl_info *info, |
| 2852 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2853 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2854 | struct netlink_ext_ack *extack = info->extack; |
| 2855 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2856 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2857 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2858 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2859 | return -EINVAL; |
| 2860 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2861 | control_freq = MHZ_TO_KHZ( |
| 2862 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2863 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 2864 | control_freq += |
| 2865 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 2867 | memset(chandef, 0, sizeof(*chandef)); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2868 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2869 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2870 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
| 2871 | chandef->freq1_offset = control_freq % 1000; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2872 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2873 | |
| 2874 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2875 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2876 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2877 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2878 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2879 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2880 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2881 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2882 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2883 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2884 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2885 | |
| 2886 | switch (chantype) { |
| 2887 | case NL80211_CHAN_NO_HT: |
| 2888 | case NL80211_CHAN_HT20: |
| 2889 | case NL80211_CHAN_HT40PLUS: |
| 2890 | case NL80211_CHAN_HT40MINUS: |
| 2891 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2892 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2893 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2894 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2895 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2896 | NL_SET_ERR_MSG_ATTR(extack, |
| 2897 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2898 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2899 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2900 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2901 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2902 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2903 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2904 | NL_SET_ERR_MSG_ATTR(extack, |
| 2905 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2906 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2907 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2908 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2909 | break; |
| 2910 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2911 | NL_SET_ERR_MSG_ATTR(extack, |
| 2912 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2913 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2914 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2915 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2916 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2917 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2918 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2919 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2920 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2921 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2922 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
| 2923 | chandef->freq1_offset = nla_get_u32( |
| 2924 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); |
| 2925 | else |
| 2926 | chandef->freq1_offset = 0; |
| 2927 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2928 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2929 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2930 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2931 | } |
| 2932 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 2933 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 2934 | chandef->edmg.channels = |
| 2935 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 2936 | |
| 2937 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 2938 | chandef->edmg.bw_config = |
| 2939 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 2940 | } else { |
| 2941 | chandef->edmg.bw_config = 0; |
| 2942 | chandef->edmg.channels = 0; |
| 2943 | } |
| 2944 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2945 | if (!cfg80211_chandef_valid(chandef)) { |
| 2946 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2947 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2948 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2949 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2950 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2951 | IEEE80211_CHAN_DISABLED)) { |
| 2952 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2953 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2954 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2955 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2956 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2957 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2958 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2959 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2960 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2961 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2962 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2963 | return 0; |
| 2964 | } |
| 2965 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2966 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2967 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2968 | struct genl_info *info) |
| 2969 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2970 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2971 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2972 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2973 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2974 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2975 | if (dev) |
| 2976 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2977 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2978 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2979 | if (wdev) |
| 2980 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2981 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2982 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2983 | if (result) |
| 2984 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2985 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2986 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2987 | case NL80211_IFTYPE_AP: |
| 2988 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2989 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2990 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2991 | result = -EINVAL; |
| 2992 | break; |
| 2993 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2994 | if (wdev->beacon_interval) { |
| 2995 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2996 | !(rdev->wiphy.features & |
| 2997 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2998 | result = -EBUSY; |
| 2999 | break; |
| 3000 | } |
| 3001 | |
| 3002 | /* Only allow dynamic channel width changes */ |
| 3003 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 3004 | result = -EBUSY; |
| 3005 | break; |
| 3006 | } |
| 3007 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 3008 | if (result) |
| 3009 | break; |
| 3010 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3011 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3012 | result = 0; |
| 3013 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3014 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3015 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3016 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3017 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3018 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3019 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3020 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3021 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3022 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3023 | |
| 3024 | return result; |
| 3025 | } |
| 3026 | |
| 3027 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 3028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3030 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3031 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3032 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3033 | } |
| 3034 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3035 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 3036 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3038 | struct net_device *dev = info->user_ptr[1]; |
| 3039 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 3040 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3041 | |
| 3042 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3043 | return -EINVAL; |
| 3044 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3045 | if (netif_running(dev)) |
| 3046 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3047 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3048 | if (!rdev->ops->set_wds_peer) |
| 3049 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3050 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3051 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 3052 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3053 | |
| 3054 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3055 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3056 | } |
| 3057 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3058 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 3059 | { |
| 3060 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3061 | struct net_device *netdev = NULL; |
| 3062 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 3063 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3064 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3065 | u32 changed; |
| 3066 | u8 retry_short = 0, retry_long = 0; |
| 3067 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3068 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3069 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3070 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3071 | ASSERT_RTNL(); |
| 3072 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3073 | /* |
| 3074 | * Try to find the wiphy and netdev. Normally this |
| 3075 | * function shouldn't need the netdev, but this is |
| 3076 | * done for backward compatibility -- previously |
| 3077 | * setting the channel was done per wiphy, but now |
| 3078 | * it is per netdev. Previous userland like hostapd |
| 3079 | * also passed a netdev to set_wiphy, so that it is |
| 3080 | * possible to let that go to the right netdev! |
| 3081 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3082 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3083 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 3084 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 3085 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3086 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3087 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 3088 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3089 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3090 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3091 | } |
| 3092 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3093 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 3094 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3095 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3096 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3097 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3098 | wdev = NULL; |
| 3099 | netdev = NULL; |
| 3100 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 3101 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3102 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3103 | |
| 3104 | /* |
| 3105 | * end workaround code, by now the rdev is available |
| 3106 | * and locked, and wdev may or may not be NULL. |
| 3107 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3108 | |
| 3109 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3110 | result = cfg80211_dev_rename( |
| 3111 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3112 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3113 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3114 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3115 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3116 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3117 | struct ieee80211_txq_params txq_params; |
| 3118 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3119 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3120 | if (!rdev->ops->set_txq_params) |
| 3121 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3122 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3123 | if (!netdev) |
| 3124 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 3125 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3126 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3127 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3128 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3129 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3130 | if (!netif_running(netdev)) |
| 3131 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 3132 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3133 | nla_for_each_nested(nl_txq_params, |
| 3134 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3135 | rem_txq_params) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3136 | result = nla_parse_nested_deprecated(tb, |
| 3137 | NL80211_TXQ_ATTR_MAX, |
| 3138 | nl_txq_params, |
| 3139 | txq_params_policy, |
| 3140 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 3141 | if (result) |
| 3142 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3143 | result = parse_txq_params(tb, &txq_params); |
| 3144 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3145 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3146 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3147 | result = rdev_set_txq_params(rdev, netdev, |
| 3148 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3149 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3150 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3151 | } |
| 3152 | } |
| 3153 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3154 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3155 | result = __nl80211_set_channel( |
| 3156 | rdev, |
| 3157 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3158 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3159 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3160 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3161 | } |
| 3162 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3163 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3164 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3165 | enum nl80211_tx_power_setting type; |
| 3166 | int idx, mbm = 0; |
| 3167 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3168 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3169 | txp_wdev = NULL; |
| 3170 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3171 | if (!rdev->ops->set_tx_power) |
| 3172 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3173 | |
| 3174 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3175 | type = nla_get_u32(info->attrs[idx]); |
| 3176 | |
| 3177 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3178 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 3179 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3180 | |
| 3181 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3182 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3183 | mbm = nla_get_u32(info->attrs[idx]); |
| 3184 | } |
| 3185 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3186 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3187 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3188 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3189 | } |
| 3190 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3191 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3192 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3193 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3194 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3195 | if ((!rdev->wiphy.available_antennas_tx && |
| 3196 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3197 | !rdev->ops->set_antenna) |
| 3198 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3199 | |
| 3200 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3201 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3202 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3203 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3204 | * available antenna masks, except for the "all" mask */ |
| 3205 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3206 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 3207 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3208 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3209 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3210 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3211 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3212 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3213 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3214 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3215 | } |
| 3216 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3217 | changed = 0; |
| 3218 | |
| 3219 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3220 | retry_short = nla_get_u8( |
| 3221 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3222 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3223 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3224 | } |
| 3225 | |
| 3226 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3227 | retry_long = nla_get_u8( |
| 3228 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3229 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3230 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3231 | } |
| 3232 | |
| 3233 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3234 | frag_threshold = nla_get_u32( |
| 3235 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3236 | if (frag_threshold < 256) |
| 3237 | return -EINVAL; |
| 3238 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3239 | if (frag_threshold != (u32) -1) { |
| 3240 | /* |
| 3241 | * Fragments (apart from the last one) are required to |
| 3242 | * have even length. Make the fragmentation code |
| 3243 | * simpler by stripping LSB should someone try to use |
| 3244 | * odd threshold value. |
| 3245 | */ |
| 3246 | frag_threshold &= ~0x1; |
| 3247 | } |
| 3248 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3249 | } |
| 3250 | |
| 3251 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3252 | rts_threshold = nla_get_u32( |
| 3253 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3254 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3255 | } |
| 3256 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3257 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3258 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 3259 | return -EINVAL; |
| 3260 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3261 | coverage_class = nla_get_u8( |
| 3262 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3263 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3264 | } |
| 3265 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3266 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3267 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 3268 | return -EOPNOTSUPP; |
| 3269 | |
| 3270 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3271 | } |
| 3272 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3273 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3274 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3275 | NL80211_EXT_FEATURE_TXQS)) |
| 3276 | return -EOPNOTSUPP; |
| 3277 | txq_limit = nla_get_u32( |
| 3278 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3279 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3280 | } |
| 3281 | |
| 3282 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3283 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3284 | NL80211_EXT_FEATURE_TXQS)) |
| 3285 | return -EOPNOTSUPP; |
| 3286 | txq_memory_limit = nla_get_u32( |
| 3287 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3288 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3289 | } |
| 3290 | |
| 3291 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3292 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3293 | NL80211_EXT_FEATURE_TXQS)) |
| 3294 | return -EOPNOTSUPP; |
| 3295 | txq_quantum = nla_get_u32( |
| 3296 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3297 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3298 | } |
| 3299 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3300 | if (changed) { |
| 3301 | u8 old_retry_short, old_retry_long; |
| 3302 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3303 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3304 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3305 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3306 | if (!rdev->ops->set_wiphy_params) |
| 3307 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3308 | |
| 3309 | old_retry_short = rdev->wiphy.retry_short; |
| 3310 | old_retry_long = rdev->wiphy.retry_long; |
| 3311 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3312 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3313 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3314 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3315 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3316 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3317 | |
| 3318 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3319 | rdev->wiphy.retry_short = retry_short; |
| 3320 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3321 | rdev->wiphy.retry_long = retry_long; |
| 3322 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3323 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3324 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3325 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3326 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3327 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3328 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3329 | rdev->wiphy.txq_limit = txq_limit; |
| 3330 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3331 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3332 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3333 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3334 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3335 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3336 | if (result) { |
| 3337 | rdev->wiphy.retry_short = old_retry_short; |
| 3338 | rdev->wiphy.retry_long = old_retry_long; |
| 3339 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3340 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3341 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3342 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3343 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3344 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 3345 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3346 | } |
| 3347 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3348 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3349 | } |
| 3350 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3351 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 3352 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3353 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 3354 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3355 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3356 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3357 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3358 | chandef->chan->center_freq)) |
| 3359 | return -ENOBUFS; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3360 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 3361 | chandef->chan->freq_offset)) |
| 3362 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3363 | switch (chandef->width) { |
| 3364 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3365 | case NL80211_CHAN_WIDTH_20: |
| 3366 | case NL80211_CHAN_WIDTH_40: |
| 3367 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3368 | cfg80211_get_chandef_type(chandef))) |
| 3369 | return -ENOBUFS; |
| 3370 | break; |
| 3371 | default: |
| 3372 | break; |
| 3373 | } |
| 3374 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3375 | return -ENOBUFS; |
| 3376 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3377 | return -ENOBUFS; |
| 3378 | if (chandef->center_freq2 && |
| 3379 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3380 | return -ENOBUFS; |
| 3381 | return 0; |
| 3382 | } |
| 3383 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3384 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 3385 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3386 | struct wireless_dev *wdev, |
| 3387 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3388 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3389 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3390 | void *hdr; |
| 3391 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3392 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3393 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3394 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3395 | |
| 3396 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3397 | if (!hdr) |
| 3398 | return -1; |
| 3399 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3400 | if (dev && |
| 3401 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3402 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3403 | goto nla_put_failure; |
| 3404 | |
| 3405 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3406 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3407 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3408 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3409 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3410 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3411 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3412 | (cfg80211_rdev_list_generation << 2)) || |
| 3413 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3414 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3415 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3416 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3417 | int ret; |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3418 | struct cfg80211_chan_def chandef = {}; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3419 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3420 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3421 | if (ret == 0) { |
| 3422 | if (nl80211_send_chandef(msg, &chandef)) |
| 3423 | goto nla_put_failure; |
| 3424 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3425 | } |
| 3426 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3427 | if (rdev->ops->get_tx_power) { |
| 3428 | int dbm, ret; |
| 3429 | |
| 3430 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3431 | if (ret == 0 && |
| 3432 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3433 | DBM_TO_MBM(dbm))) |
| 3434 | goto nla_put_failure; |
| 3435 | } |
| 3436 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3437 | wdev_lock(wdev); |
| 3438 | switch (wdev->iftype) { |
| 3439 | case NL80211_IFTYPE_AP: |
| 3440 | if (wdev->ssid_len && |
| 3441 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3442 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3443 | break; |
| 3444 | case NL80211_IFTYPE_STATION: |
| 3445 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3446 | case NL80211_IFTYPE_ADHOC: { |
| 3447 | const u8 *ssid_ie; |
| 3448 | if (!wdev->current_bss) |
| 3449 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3450 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3451 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3452 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3453 | if (ssid_ie && |
| 3454 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3455 | goto nla_put_failure_rcu_locked; |
| 3456 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3457 | break; |
| 3458 | } |
| 3459 | default: |
| 3460 | /* nothing */ |
| 3461 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3462 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3463 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3464 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3465 | if (rdev->ops->get_txq_stats) { |
| 3466 | struct cfg80211_txq_stats txqstats = {}; |
| 3467 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3468 | |
| 3469 | if (ret == 0 && |
| 3470 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3471 | NL80211_ATTR_TXQ_STATS)) |
| 3472 | goto nla_put_failure; |
| 3473 | } |
| 3474 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3475 | genlmsg_end(msg, hdr); |
| 3476 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3477 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3478 | nla_put_failure_rcu_locked: |
| 3479 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3480 | nla_put_failure_locked: |
| 3481 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3482 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3483 | genlmsg_cancel(msg, hdr); |
| 3484 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3488 | { |
| 3489 | int wp_idx = 0; |
| 3490 | int if_idx = 0; |
| 3491 | int wp_start = cb->args[0]; |
| 3492 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3493 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3494 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3495 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3496 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3497 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3498 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3499 | if (!cb->args[2]) { |
| 3500 | struct nl80211_dump_wiphy_state state = { |
| 3501 | .filter_wiphy = -1, |
| 3502 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3503 | |
| 3504 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3505 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3506 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3507 | |
| 3508 | filter_wiphy = state.filter_wiphy; |
| 3509 | |
| 3510 | /* |
| 3511 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3512 | * value needed to determine that parsing is necessary. |
| 3513 | */ |
| 3514 | if (filter_wiphy >= 0) |
| 3515 | cb->args[2] = filter_wiphy + 1; |
| 3516 | else |
| 3517 | cb->args[2] = -1; |
| 3518 | } else if (cb->args[2] > 0) { |
| 3519 | filter_wiphy = cb->args[2] - 1; |
| 3520 | } |
| 3521 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3522 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3523 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3524 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3525 | if (wp_idx < wp_start) { |
| 3526 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3527 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3528 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3529 | |
| 3530 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3531 | continue; |
| 3532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3533 | if_idx = 0; |
| 3534 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3535 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3536 | if (if_idx < if_start) { |
| 3537 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3538 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3539 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3540 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3541 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3542 | rdev, wdev, |
| 3543 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3544 | goto out; |
| 3545 | } |
| 3546 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3547 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3548 | |
| 3549 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3550 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3551 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3552 | cb->args[0] = wp_idx; |
| 3553 | cb->args[1] = if_idx; |
| 3554 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3555 | ret = skb->len; |
| 3556 | out_unlock: |
| 3557 | rtnl_unlock(); |
| 3558 | |
| 3559 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3563 | { |
| 3564 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3566 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3567 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3568 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3569 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3570 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3571 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3572 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3573 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3574 | nlmsg_free(msg); |
| 3575 | return -ENOBUFS; |
| 3576 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3577 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3578 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3579 | } |
| 3580 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3581 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3582 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3583 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3584 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3585 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3586 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3587 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3588 | }; |
| 3589 | |
| 3590 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3591 | { |
| 3592 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3593 | int flag; |
| 3594 | |
| 3595 | *mntrflags = 0; |
| 3596 | |
| 3597 | if (!nla) |
| 3598 | return -EINVAL; |
| 3599 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3600 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3601 | return -EINVAL; |
| 3602 | |
| 3603 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3604 | if (flags[flag]) |
| 3605 | *mntrflags |= (1<<flag); |
| 3606 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3607 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3608 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3609 | return 0; |
| 3610 | } |
| 3611 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3612 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3613 | enum nl80211_iftype type, |
| 3614 | struct genl_info *info, |
| 3615 | struct vif_params *params) |
| 3616 | { |
| 3617 | bool change = false; |
| 3618 | int err; |
| 3619 | |
| 3620 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3621 | if (type != NL80211_IFTYPE_MONITOR) |
| 3622 | return -EINVAL; |
| 3623 | |
| 3624 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3625 | ¶ms->flags); |
| 3626 | if (err) |
| 3627 | return err; |
| 3628 | |
| 3629 | change = true; |
| 3630 | } |
| 3631 | |
| 3632 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3633 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3634 | return -EOPNOTSUPP; |
| 3635 | |
| 3636 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3637 | const u8 *mumimo_groups; |
| 3638 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3639 | |
| 3640 | if (type != NL80211_IFTYPE_MONITOR) |
| 3641 | return -EINVAL; |
| 3642 | |
| 3643 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3644 | return -EOPNOTSUPP; |
| 3645 | |
| 3646 | mumimo_groups = |
| 3647 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3648 | |
| 3649 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3650 | if ((mumimo_groups[0] & BIT(0)) || |
| 3651 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3652 | return -EINVAL; |
| 3653 | |
| 3654 | params->vht_mumimo_groups = mumimo_groups; |
| 3655 | change = true; |
| 3656 | } |
| 3657 | |
| 3658 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3659 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3660 | |
| 3661 | if (type != NL80211_IFTYPE_MONITOR) |
| 3662 | return -EINVAL; |
| 3663 | |
| 3664 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3665 | return -EOPNOTSUPP; |
| 3666 | |
| 3667 | params->vht_mumimo_follow_addr = |
| 3668 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3669 | change = true; |
| 3670 | } |
| 3671 | |
| 3672 | return change ? 1 : 0; |
| 3673 | } |
| 3674 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3675 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3676 | struct net_device *netdev, u8 use_4addr, |
| 3677 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3678 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3679 | if (!use_4addr) { |
Julian Wiedmann | 2e92a2d | 2020-02-20 09:00:07 +0100 | [diff] [blame] | 3680 | if (netdev && netif_is_bridge_port(netdev)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3681 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3682 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3683 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3684 | |
| 3685 | switch (iftype) { |
| 3686 | case NL80211_IFTYPE_AP_VLAN: |
| 3687 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3688 | return 0; |
| 3689 | break; |
| 3690 | case NL80211_IFTYPE_STATION: |
| 3691 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3692 | return 0; |
| 3693 | break; |
| 3694 | default: |
| 3695 | break; |
| 3696 | } |
| 3697 | |
| 3698 | return -EOPNOTSUPP; |
| 3699 | } |
| 3700 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3701 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3702 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3704 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3705 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3706 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3707 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3708 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3709 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3710 | memset(¶ms, 0, sizeof(params)); |
| 3711 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3712 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3713 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3714 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3715 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3716 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3717 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3718 | } |
| 3719 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3720 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3721 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3722 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3723 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3724 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3725 | if (netif_running(dev)) |
| 3726 | return -EBUSY; |
| 3727 | |
| 3728 | wdev_lock(wdev); |
| 3729 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3730 | IEEE80211_MAX_MESH_ID_LEN); |
| 3731 | wdev->mesh_id_up_len = |
| 3732 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3733 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3734 | wdev->mesh_id_up_len); |
| 3735 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3736 | } |
| 3737 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3738 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3739 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3740 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3741 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3742 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3743 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3744 | } else { |
| 3745 | params.use_4addr = -1; |
| 3746 | } |
| 3747 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3748 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3749 | if (err < 0) |
| 3750 | return err; |
| 3751 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3752 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3753 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3754 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3755 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3756 | else |
| 3757 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3758 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3759 | if (!err && params.use_4addr != -1) |
| 3760 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3761 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3762 | if (change && !err) { |
| 3763 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3764 | |
| 3765 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3766 | } |
| 3767 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3768 | return err; |
| 3769 | } |
| 3770 | |
| 3771 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3772 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3774 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3775 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3776 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3777 | int err; |
| 3778 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3779 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3780 | /* to avoid failing a new interface creation due to pending removal */ |
| 3781 | cfg80211_destroy_ifaces(rdev); |
| 3782 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3783 | memset(¶ms, 0, sizeof(params)); |
| 3784 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3785 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3786 | return -EINVAL; |
| 3787 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 3788 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3789 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3790 | |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3791 | if (!rdev->ops->add_virtual_intf) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3792 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3793 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3794 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3795 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3796 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3797 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3798 | ETH_ALEN); |
| 3799 | if (!is_valid_ether_addr(params.macaddr)) |
| 3800 | return -EADDRNOTAVAIL; |
| 3801 | } |
| 3802 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3803 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3804 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3805 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3806 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3807 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3808 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3809 | |
Manikanta Pubbisetty | e6f4051 | 2019-07-22 12:44:50 +0530 | [diff] [blame] | 3810 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3811 | return -EOPNOTSUPP; |
| 3812 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3813 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3814 | if (err < 0) |
| 3815 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3816 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3817 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3818 | if (!msg) |
| 3819 | return -ENOMEM; |
| 3820 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3821 | wdev = rdev_add_virtual_intf(rdev, |
| 3822 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3823 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3824 | if (WARN_ON(!wdev)) { |
| 3825 | nlmsg_free(msg); |
| 3826 | return -EPROTO; |
| 3827 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3828 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3829 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3830 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3831 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3832 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3833 | wdev->owner_nlportid = info->snd_portid; |
| 3834 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3835 | switch (type) { |
| 3836 | case NL80211_IFTYPE_MESH_POINT: |
| 3837 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3838 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3839 | wdev_lock(wdev); |
| 3840 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3841 | IEEE80211_MAX_MESH_ID_LEN); |
| 3842 | wdev->mesh_id_up_len = |
| 3843 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3844 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3845 | wdev->mesh_id_up_len); |
| 3846 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3847 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3848 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3849 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3850 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3851 | * P2P Device and NAN do not have a netdev, so don't go |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3852 | * through the netdev notifier and must be added here |
| 3853 | */ |
Johannes Berg | e4d4216 | 2018-09-13 14:12:03 +0200 | [diff] [blame] | 3854 | cfg80211_init_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3855 | break; |
| 3856 | default: |
| 3857 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3858 | } |
| 3859 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3860 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3861 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3862 | nlmsg_free(msg); |
| 3863 | return -ENOBUFS; |
| 3864 | } |
| 3865 | |
| 3866 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3870 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3872 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3873 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3874 | if (!rdev->ops->del_virtual_intf) |
| 3875 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3876 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3877 | /* |
| 3878 | * If we remove a wireless device without a netdev then clear |
| 3879 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3880 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3881 | * since the wdev has been freed, unlike with a netdev where |
| 3882 | * we need the dev_put() for the netdev to really be freed. |
| 3883 | */ |
| 3884 | if (!wdev->netdev) |
| 3885 | info->user_ptr[1] = NULL; |
| 3886 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3887 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3888 | } |
| 3889 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3890 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3891 | { |
| 3892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3893 | struct net_device *dev = info->user_ptr[1]; |
| 3894 | u16 noack_map; |
| 3895 | |
| 3896 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3897 | return -EINVAL; |
| 3898 | |
| 3899 | if (!rdev->ops->set_noack_map) |
| 3900 | return -EOPNOTSUPP; |
| 3901 | |
| 3902 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3903 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3904 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3905 | } |
| 3906 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3907 | struct get_key_cookie { |
| 3908 | struct sk_buff *msg; |
| 3909 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3910 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3911 | }; |
| 3912 | |
| 3913 | static void get_key_callback(void *c, struct key_params *params) |
| 3914 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3915 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3916 | struct get_key_cookie *cookie = c; |
| 3917 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3918 | if ((params->key && |
| 3919 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3920 | params->key_len, params->key)) || |
| 3921 | (params->seq && |
| 3922 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3923 | params->seq_len, params->seq)) || |
| 3924 | (params->cipher && |
| 3925 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3926 | params->cipher))) |
| 3927 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3928 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 3929 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3930 | if (!key) |
| 3931 | goto nla_put_failure; |
| 3932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3933 | if ((params->key && |
| 3934 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3935 | params->key_len, params->key)) || |
| 3936 | (params->seq && |
| 3937 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3938 | params->seq_len, params->seq)) || |
| 3939 | (params->cipher && |
| 3940 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3941 | params->cipher))) |
| 3942 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3943 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 3944 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3945 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3946 | |
| 3947 | nla_nest_end(cookie->msg, key); |
| 3948 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3949 | return; |
| 3950 | nla_put_failure: |
| 3951 | cookie->error = 1; |
| 3952 | } |
| 3953 | |
| 3954 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3955 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3957 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3958 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3959 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3960 | const u8 *mac_addr = NULL; |
| 3961 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3962 | struct get_key_cookie cookie = { |
| 3963 | .error = 0, |
| 3964 | }; |
| 3965 | void *hdr; |
| 3966 | struct sk_buff *msg; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3967 | bool bigtk_support = false; |
| 3968 | |
| 3969 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 3970 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 3971 | bigtk_support = true; |
| 3972 | |
| 3973 | if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || |
| 3974 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| 3975 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 3976 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
| 3977 | bigtk_support = true; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3978 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3979 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3980 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3981 | |
| 3982 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { |
| 3983 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3984 | return -EINVAL; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3985 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3986 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3987 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3989 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3990 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3991 | pairwise = !!mac_addr; |
| 3992 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3993 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3994 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3995 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3996 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3997 | return -EINVAL; |
| 3998 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3999 | } |
| 4000 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4001 | if (!rdev->ops->get_key) |
| 4002 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4003 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4004 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4005 | return -ENOENT; |
| 4006 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4007 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4008 | if (!msg) |
| 4009 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4010 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4011 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4012 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 4013 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 4014 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4015 | |
| 4016 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4017 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4019 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4020 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 4021 | goto nla_put_failure; |
| 4022 | if (mac_addr && |
| 4023 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 4024 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4026 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 4027 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4028 | |
| 4029 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4030 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4031 | |
| 4032 | if (cookie.error) |
| 4033 | goto nla_put_failure; |
| 4034 | |
| 4035 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4036 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4037 | |
| 4038 | nla_put_failure: |
| 4039 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4040 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4041 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4042 | return err; |
| 4043 | } |
| 4044 | |
| 4045 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 4046 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4048 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4049 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4050 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4051 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4052 | err = nl80211_parse_key(info, &key); |
| 4053 | if (err) |
| 4054 | return err; |
| 4055 | |
| 4056 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4057 | return -EINVAL; |
| 4058 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4059 | /* Only support setting default key and |
| 4060 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 4061 | */ |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4062 | if (!key.def && !key.defmgmt && !key.defbeacon && |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4063 | !(key.p.mode == NL80211_KEY_SET_TX)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4064 | return -EINVAL; |
| 4065 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4066 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4067 | |
| 4068 | if (key.def) { |
| 4069 | if (!rdev->ops->set_default_key) { |
| 4070 | err = -EOPNOTSUPP; |
| 4071 | goto out; |
| 4072 | } |
| 4073 | |
| 4074 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4075 | if (err) |
| 4076 | goto out; |
| 4077 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4078 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4079 | key.def_uni, key.def_multi); |
| 4080 | |
| 4081 | if (err) |
| 4082 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4083 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4084 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4085 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4086 | #endif |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4087 | } else if (key.defmgmt) { |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4088 | if (key.def_uni || !key.def_multi) { |
| 4089 | err = -EINVAL; |
| 4090 | goto out; |
| 4091 | } |
| 4092 | |
| 4093 | if (!rdev->ops->set_default_mgmt_key) { |
| 4094 | err = -EOPNOTSUPP; |
| 4095 | goto out; |
| 4096 | } |
| 4097 | |
| 4098 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4099 | if (err) |
| 4100 | goto out; |
| 4101 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4102 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4103 | if (err) |
| 4104 | goto out; |
| 4105 | |
| 4106 | #ifdef CONFIG_CFG80211_WEXT |
| 4107 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4108 | #endif |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4109 | } else if (key.defbeacon) { |
| 4110 | if (key.def_uni || !key.def_multi) { |
| 4111 | err = -EINVAL; |
| 4112 | goto out; |
| 4113 | } |
| 4114 | |
| 4115 | if (!rdev->ops->set_default_beacon_key) { |
| 4116 | err = -EOPNOTSUPP; |
| 4117 | goto out; |
| 4118 | } |
| 4119 | |
| 4120 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4121 | if (err) |
| 4122 | goto out; |
| 4123 | |
| 4124 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4125 | if (err) |
| 4126 | goto out; |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4127 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4128 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4129 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4130 | u8 *mac_addr = NULL; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4131 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4132 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4133 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4134 | |
| 4135 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4136 | err = -EINVAL; |
| 4137 | goto out; |
| 4138 | } |
| 4139 | |
| 4140 | err = rdev_add_key(rdev, dev, key.idx, |
| 4141 | NL80211_KEYTYPE_PAIRWISE, |
| 4142 | mac_addr, &key.p); |
| 4143 | } else { |
| 4144 | err = -EINVAL; |
| 4145 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4146 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4147 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4148 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4149 | return err; |
| 4150 | } |
| 4151 | |
| 4152 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4155 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4156 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4157 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4158 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4159 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4160 | err = nl80211_parse_key(info, &key); |
| 4161 | if (err) |
| 4162 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4163 | |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4164 | if (!key.p.key) { |
| 4165 | GENL_SET_ERR_MSG(info, "no key"); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4166 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4167 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4168 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4169 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4170 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4171 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4172 | if (key.type == -1) { |
| 4173 | if (mac_addr) |
| 4174 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4175 | else |
| 4176 | key.type = NL80211_KEYTYPE_GROUP; |
| 4177 | } |
| 4178 | |
| 4179 | /* for now */ |
| 4180 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4181 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4182 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4183 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4184 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4185 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 4186 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4187 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4188 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 4189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4190 | if (!rdev->ops->add_key) |
| 4191 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4192 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4193 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4194 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4195 | mac_addr)) { |
| 4196 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4197 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4198 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4199 | |
| 4200 | wdev_lock(dev->ieee80211_ptr); |
| 4201 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4202 | if (err) |
| 4203 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4204 | if (!err) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4205 | err = rdev_add_key(rdev, dev, key.idx, |
| 4206 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4207 | mac_addr, &key.p); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4208 | if (err) |
| 4209 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4210 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4211 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4212 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4213 | return err; |
| 4214 | } |
| 4215 | |
| 4216 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4217 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4219 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4220 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4221 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4222 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4223 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4224 | err = nl80211_parse_key(info, &key); |
| 4225 | if (err) |
| 4226 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4227 | |
| 4228 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4229 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4230 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4231 | if (key.type == -1) { |
| 4232 | if (mac_addr) |
| 4233 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4234 | else |
| 4235 | key.type = NL80211_KEYTYPE_GROUP; |
| 4236 | } |
| 4237 | |
| 4238 | /* for now */ |
| 4239 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4240 | key.type != NL80211_KEYTYPE_GROUP) |
| 4241 | return -EINVAL; |
| 4242 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | if (!rdev->ops->del_key) |
| 4244 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4245 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4246 | wdev_lock(dev->ieee80211_ptr); |
| 4247 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4248 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4249 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4250 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4251 | err = -ENOENT; |
| 4252 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4253 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4254 | err = rdev_del_key(rdev, dev, key.idx, |
| 4255 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4256 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4257 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4258 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4259 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4260 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4261 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4262 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4263 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4264 | } |
| 4265 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4266 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4267 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4268 | return err; |
| 4269 | } |
| 4270 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4271 | /* This function returns an error or the number of nested attributes */ |
| 4272 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4273 | { |
| 4274 | struct nlattr *attr; |
| 4275 | int n_entries = 0, tmp; |
| 4276 | |
| 4277 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4278 | if (nla_len(attr) != ETH_ALEN) |
| 4279 | return -EINVAL; |
| 4280 | |
| 4281 | n_entries++; |
| 4282 | } |
| 4283 | |
| 4284 | return n_entries; |
| 4285 | } |
| 4286 | |
| 4287 | /* |
| 4288 | * This function parses ACL information and allocates memory for ACL data. |
| 4289 | * On successful return, the calling function is responsible to free the |
| 4290 | * ACL buffer returned by this function. |
| 4291 | */ |
| 4292 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4293 | struct genl_info *info) |
| 4294 | { |
| 4295 | enum nl80211_acl_policy acl_policy; |
| 4296 | struct nlattr *attr; |
| 4297 | struct cfg80211_acl_data *acl; |
| 4298 | int i = 0, n_entries, tmp; |
| 4299 | |
| 4300 | if (!wiphy->max_acl_mac_addrs) |
| 4301 | return ERR_PTR(-EOPNOTSUPP); |
| 4302 | |
| 4303 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4304 | return ERR_PTR(-EINVAL); |
| 4305 | |
| 4306 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4307 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4308 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4309 | return ERR_PTR(-EINVAL); |
| 4310 | |
| 4311 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4312 | return ERR_PTR(-EINVAL); |
| 4313 | |
| 4314 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4315 | if (n_entries < 0) |
| 4316 | return ERR_PTR(n_entries); |
| 4317 | |
| 4318 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4319 | return ERR_PTR(-ENOTSUPP); |
| 4320 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 4321 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4322 | if (!acl) |
| 4323 | return ERR_PTR(-ENOMEM); |
| 4324 | |
| 4325 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4326 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4327 | i++; |
| 4328 | } |
| 4329 | |
| 4330 | acl->n_acl_entries = n_entries; |
| 4331 | acl->acl_policy = acl_policy; |
| 4332 | |
| 4333 | return acl; |
| 4334 | } |
| 4335 | |
| 4336 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4337 | { |
| 4338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4339 | struct net_device *dev = info->user_ptr[1]; |
| 4340 | struct cfg80211_acl_data *acl; |
| 4341 | int err; |
| 4342 | |
| 4343 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4345 | return -EOPNOTSUPP; |
| 4346 | |
| 4347 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4348 | return -EINVAL; |
| 4349 | |
| 4350 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4351 | if (IS_ERR(acl)) |
| 4352 | return PTR_ERR(acl); |
| 4353 | |
| 4354 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4355 | |
| 4356 | kfree(acl); |
| 4357 | |
| 4358 | return err; |
| 4359 | } |
| 4360 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4361 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4362 | u8 *rates, u8 rates_len) |
| 4363 | { |
| 4364 | u8 i; |
| 4365 | u32 mask = 0; |
| 4366 | |
| 4367 | for (i = 0; i < rates_len; i++) { |
| 4368 | int rate = (rates[i] & 0x7f) * 5; |
| 4369 | int ridx; |
| 4370 | |
| 4371 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4372 | struct ieee80211_rate *srate = |
| 4373 | &sband->bitrates[ridx]; |
| 4374 | if (rate == srate->bitrate) { |
| 4375 | mask |= 1 << ridx; |
| 4376 | break; |
| 4377 | } |
| 4378 | } |
| 4379 | if (ridx == sband->n_bitrates) |
| 4380 | return 0; /* rate not found */ |
| 4381 | } |
| 4382 | |
| 4383 | return mask; |
| 4384 | } |
| 4385 | |
| 4386 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4387 | u8 *rates, u8 rates_len, |
| 4388 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4389 | { |
| 4390 | u8 i; |
| 4391 | |
| 4392 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4393 | |
| 4394 | for (i = 0; i < rates_len; i++) { |
| 4395 | int ridx, rbit; |
| 4396 | |
| 4397 | ridx = rates[i] / 8; |
| 4398 | rbit = BIT(rates[i] % 8); |
| 4399 | |
| 4400 | /* check validity */ |
| 4401 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4402 | return false; |
| 4403 | |
| 4404 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 4405 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4406 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4407 | mcs[ridx] |= rbit; |
| 4408 | else |
| 4409 | return false; |
| 4410 | } |
| 4411 | |
| 4412 | return true; |
| 4413 | } |
| 4414 | |
| 4415 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4416 | { |
| 4417 | u16 mcs_mask = 0; |
| 4418 | |
| 4419 | switch (vht_mcs_map) { |
| 4420 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4421 | break; |
| 4422 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4423 | mcs_mask = 0x00FF; |
| 4424 | break; |
| 4425 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4426 | mcs_mask = 0x01FF; |
| 4427 | break; |
| 4428 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4429 | mcs_mask = 0x03FF; |
| 4430 | break; |
| 4431 | default: |
| 4432 | break; |
| 4433 | } |
| 4434 | |
| 4435 | return mcs_mask; |
| 4436 | } |
| 4437 | |
| 4438 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4439 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4440 | { |
| 4441 | u8 nss; |
| 4442 | |
| 4443 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4444 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4445 | vht_mcs_map >>= 2; |
| 4446 | } |
| 4447 | } |
| 4448 | |
| 4449 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4450 | struct nl80211_txrate_vht *txrate, |
| 4451 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4452 | { |
| 4453 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4454 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4455 | u8 i; |
| 4456 | |
| 4457 | if (!sband->vht_cap.vht_supported) |
| 4458 | return false; |
| 4459 | |
| 4460 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4461 | |
| 4462 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4463 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4464 | |
| 4465 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4466 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4467 | mcs[i] = txrate->mcs[i]; |
| 4468 | else |
| 4469 | return false; |
| 4470 | } |
| 4471 | |
| 4472 | return true; |
| 4473 | } |
| 4474 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4475 | static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) |
| 4476 | { |
| 4477 | switch (he_mcs_map) { |
| 4478 | case IEEE80211_HE_MCS_NOT_SUPPORTED: |
| 4479 | return 0; |
| 4480 | case IEEE80211_HE_MCS_SUPPORT_0_7: |
| 4481 | return 0x00FF; |
| 4482 | case IEEE80211_HE_MCS_SUPPORT_0_9: |
| 4483 | return 0x03FF; |
| 4484 | case IEEE80211_HE_MCS_SUPPORT_0_11: |
| 4485 | return 0xFFF; |
| 4486 | default: |
| 4487 | break; |
| 4488 | } |
| 4489 | return 0; |
| 4490 | } |
| 4491 | |
| 4492 | static void he_build_mcs_mask(u16 he_mcs_map, |
| 4493 | u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 4494 | { |
| 4495 | u8 nss; |
| 4496 | |
| 4497 | for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { |
| 4498 | he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); |
| 4499 | he_mcs_map >>= 2; |
| 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | static u16 he_get_txmcsmap(struct genl_info *info, |
| 4504 | const struct ieee80211_sta_he_cap *he_cap) |
| 4505 | { |
| 4506 | struct net_device *dev = info->user_ptr[1]; |
| 4507 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4508 | __le16 tx_mcs; |
| 4509 | |
| 4510 | switch (wdev->chandef.width) { |
| 4511 | case NL80211_CHAN_WIDTH_80P80: |
| 4512 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 4513 | break; |
| 4514 | case NL80211_CHAN_WIDTH_160: |
| 4515 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; |
| 4516 | break; |
| 4517 | default: |
| 4518 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; |
| 4519 | break; |
| 4520 | } |
| 4521 | return le16_to_cpu(tx_mcs); |
| 4522 | } |
| 4523 | |
| 4524 | static bool he_set_mcs_mask(struct genl_info *info, |
| 4525 | struct wireless_dev *wdev, |
| 4526 | struct ieee80211_supported_band *sband, |
| 4527 | struct nl80211_txrate_he *txrate, |
| 4528 | u16 mcs[NL80211_HE_NSS_MAX]) |
| 4529 | { |
| 4530 | const struct ieee80211_sta_he_cap *he_cap; |
| 4531 | u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; |
| 4532 | u16 tx_mcs_map = 0; |
| 4533 | u8 i; |
| 4534 | |
| 4535 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4536 | if (!he_cap) |
| 4537 | return false; |
| 4538 | |
| 4539 | memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); |
| 4540 | |
| 4541 | tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4542 | |
| 4543 | /* Build he_mcs_mask from HE capabilities */ |
| 4544 | he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4545 | |
| 4546 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 4547 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4548 | mcs[i] = txrate->mcs[i]; |
| 4549 | else |
| 4550 | return false; |
| 4551 | } |
| 4552 | |
| 4553 | return true; |
| 4554 | } |
| 4555 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4556 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4557 | struct nlattr *attrs[], |
| 4558 | enum nl80211_attrs attr, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4559 | struct cfg80211_bitrate_mask *mask, |
| 4560 | struct net_device *dev) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4561 | { |
| 4562 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4565 | int rem, i; |
| 4566 | struct nlattr *tx_rates; |
| 4567 | struct ieee80211_supported_band *sband; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4568 | u16 vht_tx_mcs_map, he_tx_mcs_map; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4569 | |
| 4570 | memset(mask, 0, sizeof(*mask)); |
| 4571 | /* Default to all rates enabled */ |
| 4572 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4573 | const struct ieee80211_sta_he_cap *he_cap; |
| 4574 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4575 | sband = rdev->wiphy.bands[i]; |
| 4576 | |
| 4577 | if (!sband) |
| 4578 | continue; |
| 4579 | |
| 4580 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4581 | memcpy(mask->control[i].ht_mcs, |
| 4582 | sband->ht_cap.mcs.rx_mask, |
| 4583 | sizeof(mask->control[i].ht_mcs)); |
| 4584 | |
| 4585 | if (!sband->vht_cap.vht_supported) |
| 4586 | continue; |
| 4587 | |
| 4588 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4589 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4590 | |
| 4591 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4592 | if (!he_cap) |
| 4593 | continue; |
| 4594 | |
| 4595 | he_tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4596 | he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); |
| 4597 | |
| 4598 | mask->control[i].he_gi = 0xFF; |
| 4599 | mask->control[i].he_ltf = 0xFF; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | /* if no rates are given set it back to the defaults */ |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4603 | if (!attrs[attr]) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4604 | goto out; |
| 4605 | |
| 4606 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4607 | * directly to the enum nl80211_band values used in cfg80211. |
| 4608 | */ |
| 4609 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4610 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4611 | enum nl80211_band band = nla_type(tx_rates); |
| 4612 | int err; |
| 4613 | |
| 4614 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4615 | return -EINVAL; |
| 4616 | sband = rdev->wiphy.bands[band]; |
| 4617 | if (sband == NULL) |
| 4618 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4619 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4620 | tx_rates, |
| 4621 | nl80211_txattr_policy, |
| 4622 | info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4623 | if (err) |
| 4624 | return err; |
| 4625 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4626 | mask->control[band].legacy = rateset_to_mask( |
| 4627 | sband, |
| 4628 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4629 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4630 | if ((mask->control[band].legacy == 0) && |
| 4631 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4632 | return -EINVAL; |
| 4633 | } |
| 4634 | if (tb[NL80211_TXRATE_HT]) { |
| 4635 | if (!ht_rateset_to_mask( |
| 4636 | sband, |
| 4637 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4638 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4639 | mask->control[band].ht_mcs)) |
| 4640 | return -EINVAL; |
| 4641 | } |
| 4642 | if (tb[NL80211_TXRATE_VHT]) { |
| 4643 | if (!vht_set_mcs_mask( |
| 4644 | sband, |
| 4645 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4646 | mask->control[band].vht_mcs)) |
| 4647 | return -EINVAL; |
| 4648 | } |
| 4649 | if (tb[NL80211_TXRATE_GI]) { |
| 4650 | mask->control[band].gi = |
| 4651 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4652 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4653 | return -EINVAL; |
| 4654 | } |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4655 | if (tb[NL80211_TXRATE_HE] && |
| 4656 | !he_set_mcs_mask(info, wdev, sband, |
| 4657 | nla_data(tb[NL80211_TXRATE_HE]), |
| 4658 | mask->control[band].he_mcs)) |
| 4659 | return -EINVAL; |
| 4660 | if (tb[NL80211_TXRATE_HE_GI]) |
| 4661 | mask->control[band].he_gi = |
| 4662 | nla_get_u8(tb[NL80211_TXRATE_HE_GI]); |
| 4663 | if (tb[NL80211_TXRATE_HE_LTF]) |
| 4664 | mask->control[band].he_ltf = |
| 4665 | nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4666 | |
| 4667 | if (mask->control[band].legacy == 0) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4668 | /* don't allow empty legacy rates if HT, VHT or HE |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4669 | * are not even supported. |
| 4670 | */ |
| 4671 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4672 | rdev->wiphy.bands[band]->vht_cap.vht_supported || |
| 4673 | ieee80211_get_he_iftype_cap(sband, wdev->iftype))) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4674 | return -EINVAL; |
| 4675 | |
| 4676 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4677 | if (mask->control[band].ht_mcs[i]) |
| 4678 | goto out; |
| 4679 | |
| 4680 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4681 | if (mask->control[band].vht_mcs[i]) |
| 4682 | goto out; |
| 4683 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4684 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) |
| 4685 | if (mask->control[band].he_mcs[i]) |
| 4686 | goto out; |
| 4687 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4688 | /* legacy and mcs rates may not be both empty */ |
| 4689 | return -EINVAL; |
| 4690 | } |
| 4691 | } |
| 4692 | |
| 4693 | out: |
| 4694 | return 0; |
| 4695 | } |
| 4696 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4697 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4698 | enum nl80211_band band, |
| 4699 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4700 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4701 | u32 count_ht, count_vht, i; |
| 4702 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4703 | |
| 4704 | /* Allow only one rate */ |
| 4705 | if (hweight32(rate) > 1) |
| 4706 | return -EINVAL; |
| 4707 | |
| 4708 | count_ht = 0; |
| 4709 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4710 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4711 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4712 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4713 | count_ht++; |
| 4714 | if (count_ht > 1) |
| 4715 | return -EINVAL; |
| 4716 | } |
| 4717 | if (count_ht && rate) |
| 4718 | return -EINVAL; |
| 4719 | } |
| 4720 | |
| 4721 | count_vht = 0; |
| 4722 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4723 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4724 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4725 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4726 | count_vht++; |
| 4727 | if (count_vht > 1) |
| 4728 | return -EINVAL; |
| 4729 | } |
| 4730 | if (count_vht && rate) |
| 4731 | return -EINVAL; |
| 4732 | } |
| 4733 | |
| 4734 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4735 | return -EINVAL; |
| 4736 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4737 | if (rate && |
| 4738 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4739 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4740 | return -EINVAL; |
| 4741 | if (count_ht && |
| 4742 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4743 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4744 | return -EINVAL; |
| 4745 | if (count_vht && |
| 4746 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4747 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4748 | return -EINVAL; |
| 4749 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4750 | return 0; |
| 4751 | } |
| 4752 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4753 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4754 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4755 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4756 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4757 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4758 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4759 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4760 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4761 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4762 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4763 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4764 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4765 | if (!bcn->head_len) |
| 4766 | return -EINVAL; |
| 4767 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4770 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4771 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4772 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4773 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4774 | } |
| 4775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4776 | if (!haveinfo) |
| 4777 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4778 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4779 | if (attrs[NL80211_ATTR_IE]) { |
| 4780 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4781 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4782 | } |
| 4783 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4784 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4785 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4786 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4787 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4788 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4789 | } |
| 4790 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4791 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4792 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4793 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4794 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4795 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4796 | } |
| 4797 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4798 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4799 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4800 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4801 | } |
| 4802 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4803 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4804 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4805 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4806 | err = nla_parse_nested_deprecated(tb, |
| 4807 | NL80211_FTM_RESP_ATTR_MAX, |
| 4808 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4809 | NULL, NULL); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4810 | if (err) |
| 4811 | return err; |
| 4812 | |
| 4813 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4814 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4815 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4816 | bcn->ftm_responder = 1; |
| 4817 | else |
| 4818 | return -EOPNOTSUPP; |
| 4819 | |
| 4820 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4821 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4822 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4823 | } |
| 4824 | |
| 4825 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4826 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4827 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4828 | } |
| 4829 | } else { |
| 4830 | bcn->ftm_responder = -1; |
| 4831 | } |
| 4832 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4833 | return 0; |
| 4834 | } |
| 4835 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4836 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 4837 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 4838 | { |
| 4839 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 4840 | int err; |
| 4841 | |
| 4842 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 4843 | he_obss_pd_policy, NULL); |
| 4844 | if (err) |
| 4845 | return err; |
| 4846 | |
| 4847 | if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] || |
| 4848 | !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 4849 | return -EINVAL; |
| 4850 | |
| 4851 | he_obss_pd->min_offset = |
| 4852 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 4853 | he_obss_pd->max_offset = |
| 4854 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
| 4855 | |
| 4856 | if (he_obss_pd->min_offset >= he_obss_pd->max_offset) |
| 4857 | return -EINVAL; |
| 4858 | |
| 4859 | he_obss_pd->enable = true; |
| 4860 | |
| 4861 | return 0; |
| 4862 | } |
| 4863 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4864 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 4865 | struct cfg80211_he_bss_color *he_bss_color) |
| 4866 | { |
| 4867 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 4868 | int err; |
| 4869 | |
| 4870 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 4871 | he_bss_color_policy, NULL); |
| 4872 | if (err) |
| 4873 | return err; |
| 4874 | |
| 4875 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 4876 | return -EINVAL; |
| 4877 | |
| 4878 | he_bss_color->color = |
| 4879 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 4880 | he_bss_color->enabled = |
| 4881 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4882 | he_bss_color->partial = |
| 4883 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 4884 | |
| 4885 | return 0; |
| 4886 | } |
| 4887 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame^] | 4888 | static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, |
| 4889 | struct nlattr *attrs, |
| 4890 | struct cfg80211_ap_settings *params) |
| 4891 | { |
| 4892 | struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; |
| 4893 | int ret; |
| 4894 | struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; |
| 4895 | |
| 4896 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4897 | NL80211_EXT_FEATURE_FILS_DISCOVERY)) |
| 4898 | return -EINVAL; |
| 4899 | |
| 4900 | ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, |
| 4901 | NULL, NULL); |
| 4902 | if (ret) |
| 4903 | return ret; |
| 4904 | |
| 4905 | if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || |
| 4906 | !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || |
| 4907 | !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) |
| 4908 | return -EINVAL; |
| 4909 | |
| 4910 | fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4911 | fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4912 | fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); |
| 4913 | fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); |
| 4914 | |
| 4915 | return 0; |
| 4916 | } |
| 4917 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4918 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 4919 | const u8 *rates) |
| 4920 | { |
| 4921 | int i; |
| 4922 | |
| 4923 | if (!rates) |
| 4924 | return; |
| 4925 | |
| 4926 | for (i = 0; i < rates[1]; i++) { |
| 4927 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 4928 | params->ht_required = true; |
| 4929 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 4930 | params->vht_required = true; |
Ilan Peer | 2a39259 | 2020-03-26 15:09:35 +0200 | [diff] [blame] | 4931 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
| 4932 | params->he_required = true; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | /* |
| 4937 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 4938 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 4939 | * benefit of drivers that rebuild IEs in the firmware. |
| 4940 | */ |
| 4941 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 4942 | { |
| 4943 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 4944 | size_t ies_len = bcn->tail_len; |
| 4945 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4946 | const u8 *rates; |
| 4947 | const u8 *cap; |
| 4948 | |
| 4949 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 4950 | nl80211_check_ap_rate_selectors(params, rates); |
| 4951 | |
| 4952 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 4953 | nl80211_check_ap_rate_selectors(params, rates); |
| 4954 | |
| 4955 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 4956 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 4957 | params->ht_cap = (void *)(cap + 2); |
| 4958 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 4959 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 4960 | params->vht_cap = (void *)(cap + 2); |
Shaul Triebitz | 244eb9a | 2018-08-31 11:31:14 +0300 | [diff] [blame] | 4961 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 4962 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 4963 | params->he_cap = (void *)(cap + 3); |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 4964 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); |
| 4965 | if (cap && cap[1] >= sizeof(*params->he_oper) + 1) |
| 4966 | params->he_oper = (void *)(cap + 3); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4967 | } |
| 4968 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4969 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 4970 | struct cfg80211_ap_settings *params) |
| 4971 | { |
| 4972 | struct wireless_dev *wdev; |
| 4973 | bool ret = false; |
| 4974 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 4975 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4976 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 4977 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 4978 | continue; |
| 4979 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4980 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4981 | continue; |
| 4982 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4983 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4984 | ret = true; |
| 4985 | break; |
| 4986 | } |
| 4987 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4988 | return ret; |
| 4989 | } |
| 4990 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4991 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 4992 | enum nl80211_auth_type auth_type, |
| 4993 | enum nl80211_commands cmd) |
| 4994 | { |
| 4995 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 4996 | return false; |
| 4997 | |
| 4998 | switch (cmd) { |
| 4999 | case NL80211_CMD_AUTHENTICATE: |
| 5000 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 5001 | auth_type == NL80211_AUTHTYPE_SAE) |
| 5002 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5003 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5004 | NL80211_EXT_FEATURE_FILS_STA) && |
| 5005 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5006 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5007 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 5008 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5009 | return true; |
| 5010 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5011 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 5012 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5013 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5014 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5015 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5016 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5017 | /* FILS with SK PFS or PK not supported yet */ |
| 5018 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5019 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5020 | return false; |
| 5021 | if (!wiphy_ext_feature_isset( |
| 5022 | &rdev->wiphy, |
| 5023 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 5024 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 5025 | return false; |
| 5026 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5027 | case NL80211_CMD_START_AP: |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 5028 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5029 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && |
| 5030 | auth_type == NL80211_AUTHTYPE_SAE) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5031 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5032 | /* FILS not supported yet */ |
| 5033 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5034 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5035 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5036 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5037 | return true; |
| 5038 | default: |
| 5039 | return false; |
| 5040 | } |
| 5041 | } |
| 5042 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5043 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 5044 | { |
| 5045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5046 | struct net_device *dev = info->user_ptr[1]; |
| 5047 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5048 | struct cfg80211_ap_settings params; |
| 5049 | int err; |
| 5050 | |
| 5051 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5052 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5053 | return -EOPNOTSUPP; |
| 5054 | |
| 5055 | if (!rdev->ops->start_ap) |
| 5056 | return -EOPNOTSUPP; |
| 5057 | |
| 5058 | if (wdev->beacon_interval) |
| 5059 | return -EALREADY; |
| 5060 | |
| 5061 | memset(¶ms, 0, sizeof(params)); |
| 5062 | |
| 5063 | /* these are required for START_AP */ |
| 5064 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 5065 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 5066 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 5067 | return -EINVAL; |
| 5068 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5069 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5070 | if (err) |
| 5071 | return err; |
| 5072 | |
| 5073 | params.beacon_interval = |
| 5074 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5075 | params.dtim_period = |
| 5076 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 5077 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 5078 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 5079 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5080 | if (err) |
| 5081 | return err; |
| 5082 | |
| 5083 | /* |
| 5084 | * In theory, some of these attributes should be required here |
| 5085 | * but since they were not used when the command was originally |
| 5086 | * added, keep them optional for old user space programs to let |
| 5087 | * them continue to work with drivers that do not need the |
| 5088 | * additional information -- drivers must check! |
| 5089 | */ |
| 5090 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 5091 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5092 | params.ssid_len = |
| 5093 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 5094 | if (params.ssid_len == 0) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5095 | return -EINVAL; |
| 5096 | } |
| 5097 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5098 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5099 | params.hidden_ssid = nla_get_u32( |
| 5100 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5101 | |
| 5102 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 5103 | |
| 5104 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5105 | params.auth_type = nla_get_u32( |
| 5106 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5107 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 5108 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5109 | return -EINVAL; |
| 5110 | } else |
| 5111 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5112 | |
| 5113 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 5114 | NL80211_MAX_NR_CIPHER_SUITES); |
| 5115 | if (err) |
| 5116 | return err; |
| 5117 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 5118 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 5119 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 5120 | return -EOPNOTSUPP; |
| 5121 | params.inactivity_timeout = nla_get_u16( |
| 5122 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 5123 | } |
| 5124 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5125 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5126 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5127 | return -EINVAL; |
| 5128 | params.p2p_ctwindow = |
| 5129 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5130 | if (params.p2p_ctwindow != 0 && |
| 5131 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5132 | return -EINVAL; |
| 5133 | } |
| 5134 | |
| 5135 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5136 | u8 tmp; |
| 5137 | |
| 5138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5139 | return -EINVAL; |
| 5140 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5141 | params.p2p_opp_ps = tmp; |
| 5142 | if (params.p2p_opp_ps != 0 && |
| 5143 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5144 | return -EINVAL; |
| 5145 | } |
| 5146 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5147 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5148 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5149 | if (err) |
| 5150 | return err; |
| 5151 | } else if (wdev->preset_chandef.chan) { |
| 5152 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5153 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5154 | return -EINVAL; |
| 5155 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 5156 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 5157 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5158 | return -EINVAL; |
| 5159 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5160 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 5161 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 5162 | NL80211_ATTR_TX_RATES, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 5163 | ¶ms.beacon_rate, |
| 5164 | dev); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5165 | if (err) |
| 5166 | return err; |
| 5167 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 5168 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 5169 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5170 | if (err) |
| 5171 | return err; |
| 5172 | } |
| 5173 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5174 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 5175 | params.smps_mode = |
| 5176 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 5177 | switch (params.smps_mode) { |
| 5178 | case NL80211_SMPS_OFF: |
| 5179 | break; |
| 5180 | case NL80211_SMPS_STATIC: |
| 5181 | if (!(rdev->wiphy.features & |
| 5182 | NL80211_FEATURE_STATIC_SMPS)) |
| 5183 | return -EINVAL; |
| 5184 | break; |
| 5185 | case NL80211_SMPS_DYNAMIC: |
| 5186 | if (!(rdev->wiphy.features & |
| 5187 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 5188 | return -EINVAL; |
| 5189 | break; |
| 5190 | default: |
| 5191 | return -EINVAL; |
| 5192 | } |
| 5193 | } else { |
| 5194 | params.smps_mode = NL80211_SMPS_OFF; |
| 5195 | } |
| 5196 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 5197 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 5198 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 5199 | return -EOPNOTSUPP; |
| 5200 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 5201 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 5202 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 5203 | if (IS_ERR(params.acl)) |
| 5204 | return PTR_ERR(params.acl); |
| 5205 | } |
| 5206 | |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 5207 | params.twt_responder = |
| 5208 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 5209 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5210 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 5211 | err = nl80211_parse_he_obss_pd( |
| 5212 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
| 5213 | ¶ms.he_obss_pd); |
Luca Coelho | bc7a39b | 2020-06-26 12:49:39 +0300 | [diff] [blame] | 5214 | if (err) |
| 5215 | goto out; |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5216 | } |
| 5217 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5218 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 5219 | err = nl80211_parse_he_bss_color( |
| 5220 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
| 5221 | ¶ms.he_bss_color); |
| 5222 | if (err) |
Luca Coelho | 60a0121 | 2020-06-26 12:49:40 +0300 | [diff] [blame] | 5223 | goto out; |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5224 | } |
| 5225 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame^] | 5226 | if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { |
| 5227 | err = nl80211_parse_fils_discovery(rdev, |
| 5228 | info->attrs[NL80211_ATTR_FILS_DISCOVERY], |
| 5229 | ¶ms); |
| 5230 | if (err) |
| 5231 | goto out; |
| 5232 | } |
| 5233 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5234 | nl80211_calculate_ap_params(¶ms); |
| 5235 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 5236 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 5237 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 5238 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5239 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5240 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5241 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5242 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5243 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5244 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 5245 | wdev->ssid_len = params.ssid_len; |
| 5246 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 5247 | |
| 5248 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5249 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5250 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5251 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5252 | |
Johannes Berg | 9951ebf | 2020-02-21 10:41:43 +0100 | [diff] [blame] | 5253 | out: |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5254 | kfree(params.acl); |
| 5255 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 5256 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5257 | } |
| 5258 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5259 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5260 | { |
| 5261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5262 | struct net_device *dev = info->user_ptr[1]; |
| 5263 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5264 | struct cfg80211_beacon_data params; |
| 5265 | int err; |
| 5266 | |
| 5267 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5268 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5269 | return -EOPNOTSUPP; |
| 5270 | |
| 5271 | if (!rdev->ops->change_beacon) |
| 5272 | return -EOPNOTSUPP; |
| 5273 | |
| 5274 | if (!wdev->beacon_interval) |
| 5275 | return -EINVAL; |
| 5276 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5277 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5278 | if (err) |
| 5279 | return err; |
| 5280 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5281 | wdev_lock(wdev); |
| 5282 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5283 | wdev_unlock(wdev); |
| 5284 | |
| 5285 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5291 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5292 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 5293 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5294 | } |
| 5295 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5296 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5297 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5298 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5299 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 5300 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 5301 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 5302 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5303 | }; |
| 5304 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5305 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5306 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5307 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5308 | { |
| 5309 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5310 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5311 | int flag; |
| 5312 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5313 | /* |
| 5314 | * Try parsing the new attribute first so userspace |
| 5315 | * can specify both for older kernels. |
| 5316 | */ |
| 5317 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5318 | if (nla) { |
| 5319 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5320 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5321 | sta_flags = nla_data(nla); |
| 5322 | params->sta_flags_mask = sta_flags->mask; |
| 5323 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5324 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5325 | if ((params->sta_flags_mask | |
| 5326 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5327 | return -EINVAL; |
| 5328 | return 0; |
| 5329 | } |
| 5330 | |
| 5331 | /* if present, parse the old attribute */ |
| 5332 | |
| 5333 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5334 | if (!nla) |
| 5335 | return 0; |
| 5336 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5337 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5338 | return -EINVAL; |
| 5339 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5340 | /* |
| 5341 | * Only allow certain flags for interface types so that |
| 5342 | * other attributes are silently ignored. Remember that |
| 5343 | * this is backward compatibility code with old userspace |
| 5344 | * and shouldn't be hit in other cases anyway. |
| 5345 | */ |
| 5346 | switch (iftype) { |
| 5347 | case NL80211_IFTYPE_AP: |
| 5348 | case NL80211_IFTYPE_AP_VLAN: |
| 5349 | case NL80211_IFTYPE_P2P_GO: |
| 5350 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5351 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5352 | BIT(NL80211_STA_FLAG_WME) | |
| 5353 | BIT(NL80211_STA_FLAG_MFP); |
| 5354 | break; |
| 5355 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5356 | case NL80211_IFTYPE_STATION: |
| 5357 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5358 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5359 | break; |
| 5360 | case NL80211_IFTYPE_MESH_POINT: |
| 5361 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5362 | BIT(NL80211_STA_FLAG_MFP) | |
| 5363 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 5364 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5365 | default: |
| 5366 | return -EINVAL; |
| 5367 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5368 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5369 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5370 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5371 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5372 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5373 | /* no longer support new API additions in old API */ |
| 5374 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5375 | return -EINVAL; |
| 5376 | } |
| 5377 | } |
| 5378 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5379 | return 0; |
| 5380 | } |
| 5381 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 5382 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5383 | { |
| 5384 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5385 | u32 bitrate; |
| 5386 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 5387 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5388 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5389 | rate = nla_nest_start_noflag(msg, attr); |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5390 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5391 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5392 | |
| 5393 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5394 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5395 | /* report 16-bit bitrate only if we can */ |
| 5396 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5397 | if (bitrate > 0 && |
| 5398 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5399 | return false; |
| 5400 | if (bitrate_compat > 0 && |
| 5401 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5402 | return false; |
| 5403 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5404 | switch (info->bw) { |
| 5405 | case RATE_INFO_BW_5: |
| 5406 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5407 | break; |
| 5408 | case RATE_INFO_BW_10: |
| 5409 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5410 | break; |
| 5411 | default: |
| 5412 | WARN_ON(1); |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 5413 | fallthrough; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5414 | case RATE_INFO_BW_20: |
| 5415 | rate_flg = 0; |
| 5416 | break; |
| 5417 | case RATE_INFO_BW_40: |
| 5418 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5419 | break; |
| 5420 | case RATE_INFO_BW_80: |
| 5421 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5422 | break; |
| 5423 | case RATE_INFO_BW_160: |
| 5424 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5425 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5426 | case RATE_INFO_BW_HE_RU: |
| 5427 | rate_flg = 0; |
| 5428 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5432 | return false; |
| 5433 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5434 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5435 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5436 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5437 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5438 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5439 | return false; |
| 5440 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5441 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5442 | return false; |
| 5443 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5444 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5445 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5446 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5447 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5448 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5449 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5450 | return false; |
| 5451 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5452 | return false; |
| 5453 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5454 | return false; |
| 5455 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5456 | return false; |
| 5457 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5458 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5459 | info->he_ru_alloc)) |
| 5460 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5461 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5462 | |
| 5463 | nla_nest_end(msg, rate); |
| 5464 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5465 | } |
| 5466 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5467 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5468 | int id) |
| 5469 | { |
| 5470 | void *attr; |
| 5471 | int i = 0; |
| 5472 | |
| 5473 | if (!mask) |
| 5474 | return true; |
| 5475 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5476 | attr = nla_nest_start_noflag(msg, id); |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5477 | if (!attr) |
| 5478 | return false; |
| 5479 | |
| 5480 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5481 | if (!(mask & BIT(i))) |
| 5482 | continue; |
| 5483 | |
| 5484 | if (nla_put_u8(msg, i, signal[i])) |
| 5485 | return false; |
| 5486 | } |
| 5487 | |
| 5488 | nla_nest_end(msg, attr); |
| 5489 | |
| 5490 | return true; |
| 5491 | } |
| 5492 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5493 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5494 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5495 | struct cfg80211_registered_device *rdev, |
| 5496 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5497 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5498 | { |
| 5499 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5500 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5501 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5502 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5503 | if (!hdr) { |
| 5504 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5505 | return -1; |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5506 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5507 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5508 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5509 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5510 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5511 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5512 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5513 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5514 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5515 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5516 | |
| 5517 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5518 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5519 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5520 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 5521 | sinfo->memb)) \ |
| 5522 | goto nla_put_failure; \ |
| 5523 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5524 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5525 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5526 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 5527 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 5528 | goto nla_put_failure; \ |
| 5529 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5530 | |
| 5531 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 5532 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
Ben Greear | 6c7a003 | 2019-08-09 11:00:00 -0700 | [diff] [blame] | 5533 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5534 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5535 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 5536 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5537 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5538 | (u32)sinfo->rx_bytes)) |
| 5539 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5540 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5541 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 5542 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5543 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 5544 | (u32)sinfo->tx_bytes)) |
| 5545 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5546 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5547 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 5548 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5549 | PUT_SINFO(LLID, llid, u16); |
| 5550 | PUT_SINFO(PLID, plid, u16); |
| 5551 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5552 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5553 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 5554 | |
| 5555 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 5556 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5557 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5558 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5559 | switch (rdev->wiphy.signal_type) { |
| 5560 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5561 | PUT_SINFO(SIGNAL, signal, u8); |
| 5562 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5563 | break; |
| 5564 | default: |
| 5565 | break; |
| 5566 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5567 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5568 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5569 | sinfo->chain_signal, |
| 5570 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 5571 | goto nla_put_failure; |
| 5572 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5573 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5574 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5575 | sinfo->chain_signal_avg, |
| 5576 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 5577 | goto nla_put_failure; |
| 5578 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5579 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5580 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 5581 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5582 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5583 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5584 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5585 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 5586 | NL80211_STA_INFO_RX_BITRATE)) |
| 5587 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5588 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5589 | |
| 5590 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 5591 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 5592 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 5593 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 5594 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
Narayanraddi Masti | ab60633 | 2019-02-07 12:16:05 -0800 | [diff] [blame] | 5595 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5596 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 5597 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 5598 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 5599 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 5600 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Markus Theil | 1303a51 | 2020-06-11 16:02:38 +0200 | [diff] [blame] | 5601 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5602 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5603 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5604 | bss_param = nla_nest_start_noflag(msg, |
| 5605 | NL80211_STA_INFO_BSS_PARAM); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5606 | if (!bss_param) |
| 5607 | goto nla_put_failure; |
| 5608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5609 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 5610 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 5611 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 5612 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 5613 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 5614 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 5615 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 5616 | sinfo->bss_param.dtim_period) || |
| 5617 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 5618 | sinfo->bss_param.beacon_interval)) |
| 5619 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5620 | |
| 5621 | nla_nest_end(msg, bss_param); |
| 5622 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5623 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5624 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 5625 | sizeof(struct nl80211_sta_flag_update), |
| 5626 | &sinfo->sta_flags)) |
| 5627 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5628 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5629 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 5630 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 5631 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 5632 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 5633 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 5634 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 5635 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 5636 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 5637 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 5638 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 5639 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5640 | |
| 5641 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5642 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5643 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 5644 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5645 | struct nlattr *tidsattr; |
| 5646 | int tid; |
| 5647 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5648 | tidsattr = nla_nest_start_noflag(msg, |
| 5649 | NL80211_STA_INFO_TID_STATS); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5650 | if (!tidsattr) |
| 5651 | goto nla_put_failure; |
| 5652 | |
| 5653 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 5654 | struct cfg80211_tid_stats *tidstats; |
| 5655 | struct nlattr *tidattr; |
| 5656 | |
| 5657 | tidstats = &sinfo->pertid[tid]; |
| 5658 | |
| 5659 | if (!tidstats->filled) |
| 5660 | continue; |
| 5661 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5662 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5663 | if (!tidattr) |
| 5664 | goto nla_put_failure; |
| 5665 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5666 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5667 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5668 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 5669 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5670 | goto nla_put_failure; \ |
| 5671 | } while (0) |
| 5672 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5673 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 5674 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 5675 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 5676 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5677 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5678 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 5679 | if ((tidstats->filled & |
| 5680 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 5681 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 5682 | NL80211_TID_STATS_TXQ_STATS)) |
| 5683 | goto nla_put_failure; |
| 5684 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5685 | nla_nest_end(msg, tidattr); |
| 5686 | } |
| 5687 | |
| 5688 | nla_nest_end(msg, tidsattr); |
| 5689 | } |
| 5690 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5691 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5692 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5693 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5694 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5695 | sinfo->assoc_req_ies)) |
| 5696 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 5697 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5698 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5699 | genlmsg_end(msg, hdr); |
| 5700 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5701 | |
| 5702 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5703 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5704 | genlmsg_cancel(msg, hdr); |
| 5705 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5706 | } |
| 5707 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5708 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5709 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5710 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5711 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5712 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5713 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5714 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5715 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5716 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5717 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5718 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5719 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5720 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5721 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5722 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5723 | if (!wdev->netdev) { |
| 5724 | err = -EINVAL; |
| 5725 | goto out_err; |
| 5726 | } |
| 5727 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5728 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5729 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5730 | goto out_err; |
| 5731 | } |
| 5732 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5733 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5734 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5735 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5736 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5737 | if (err == -ENOENT) |
| 5738 | break; |
| 5739 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5740 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5741 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5742 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5743 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5744 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5745 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5746 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5747 | goto out; |
| 5748 | |
| 5749 | sta_idx++; |
| 5750 | } |
| 5751 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5752 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5753 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5754 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5755 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5756 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5757 | |
| 5758 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5759 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5760 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5761 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5762 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5764 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5765 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5766 | struct sk_buff *msg; |
| 5767 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5768 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5769 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5770 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5771 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5772 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5773 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5774 | |
| 5775 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5776 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5777 | if (!rdev->ops->get_station) |
| 5778 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5779 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5780 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5781 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5782 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5783 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5784 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5785 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 5786 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5787 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5788 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5789 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5790 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5791 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5792 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5793 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5794 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5795 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5796 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5797 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5798 | } |
| 5799 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5800 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5801 | struct station_parameters *params, |
| 5802 | enum cfg80211_station_type statype) |
| 5803 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5804 | if (params->listen_interval != -1 && |
| 5805 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5806 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5807 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5808 | if (params->support_p2p_ps != -1 && |
| 5809 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5810 | return -EINVAL; |
| 5811 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 5812 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5813 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5814 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5815 | return -EINVAL; |
| 5816 | |
| 5817 | /* When you run into this, adjust the code below for the new flag */ |
| 5818 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5819 | |
| 5820 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5821 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5822 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5823 | /* |
| 5824 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5825 | * code doesn't have the bug of including TDLS in the |
| 5826 | * mask everywhere. |
| 5827 | */ |
| 5828 | if (params->sta_flags_mask & |
| 5829 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5830 | BIT(NL80211_STA_FLAG_MFP) | |
| 5831 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5832 | return -EINVAL; |
| 5833 | break; |
| 5834 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5835 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5836 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5837 | return -EINVAL; |
| 5838 | /* ignore since it can't change */ |
| 5839 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5840 | break; |
| 5841 | default: |
| 5842 | /* disallow mesh-specific things */ |
| 5843 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5844 | return -EINVAL; |
| 5845 | if (params->local_pm) |
| 5846 | return -EINVAL; |
| 5847 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5848 | return -EINVAL; |
| 5849 | } |
| 5850 | |
| 5851 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5852 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5853 | /* TDLS can't be set, ... */ |
| 5854 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5855 | return -EINVAL; |
| 5856 | /* |
| 5857 | * ... but don't bother the driver with it. This works around |
| 5858 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5859 | * TLDS_PEER flag in the mask even for AP mode. |
| 5860 | */ |
| 5861 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5862 | } |
| 5863 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5864 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5865 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5866 | /* reject other things that can't change */ |
| 5867 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5868 | return -EINVAL; |
| 5869 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5870 | return -EINVAL; |
| 5871 | if (params->supported_rates) |
| 5872 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5873 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5874 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5875 | return -EINVAL; |
| 5876 | } |
| 5877 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5878 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5879 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5880 | if (params->vlan) |
| 5881 | return -EINVAL; |
| 5882 | } |
| 5883 | |
| 5884 | switch (statype) { |
| 5885 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5886 | /* Use this only for authorizing/unauthorizing a station */ |
| 5887 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5888 | return -EOPNOTSUPP; |
| 5889 | break; |
| 5890 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5891 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5892 | /* accept only the listed bits */ |
| 5893 | if (params->sta_flags_mask & |
| 5894 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5895 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5896 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5897 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5898 | BIT(NL80211_STA_FLAG_WME) | |
| 5899 | BIT(NL80211_STA_FLAG_MFP))) |
| 5900 | return -EINVAL; |
| 5901 | |
| 5902 | /* but authenticated/associated only if driver handles it */ |
| 5903 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5904 | params->sta_flags_mask & |
| 5905 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5906 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 5907 | return -EINVAL; |
| 5908 | break; |
| 5909 | case CFG80211_STA_IBSS: |
| 5910 | case CFG80211_STA_AP_STA: |
| 5911 | /* reject any changes other than AUTHORIZED */ |
| 5912 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 5913 | return -EINVAL; |
| 5914 | break; |
| 5915 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5916 | /* reject any changes other than AUTHORIZED or WME */ |
| 5917 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5918 | BIT(NL80211_STA_FLAG_WME))) |
| 5919 | return -EINVAL; |
| 5920 | /* force (at least) rates when authorizing */ |
| 5921 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 5922 | !params->supported_rates) |
| 5923 | return -EINVAL; |
| 5924 | break; |
| 5925 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5926 | /* reject any changes */ |
| 5927 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5928 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5929 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5930 | return -EINVAL; |
| 5931 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5932 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 5933 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 5934 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5935 | return -EINVAL; |
| 5936 | break; |
| 5937 | } |
| 5938 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5939 | /* |
| 5940 | * Older kernel versions ignored this attribute entirely, so don't |
| 5941 | * reject attempts to update it but mark it as unused instead so the |
| 5942 | * driver won't look at the data. |
| 5943 | */ |
| 5944 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 5945 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 5946 | params->opmode_notif_used = false; |
| 5947 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5948 | return 0; |
| 5949 | } |
| 5950 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 5951 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5952 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 5953 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5954 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5955 | static struct net_device *get_vlan(struct genl_info *info, |
| 5956 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5957 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5958 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5959 | struct net_device *v; |
| 5960 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5961 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5962 | if (!vlanattr) |
| 5963 | return NULL; |
| 5964 | |
| 5965 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 5966 | if (!v) |
| 5967 | return ERR_PTR(-ENODEV); |
| 5968 | |
| 5969 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 5970 | ret = -EINVAL; |
| 5971 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5972 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5973 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5974 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5975 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5976 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5977 | ret = -EINVAL; |
| 5978 | goto error; |
| 5979 | } |
| 5980 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5981 | if (!netif_running(v)) { |
| 5982 | ret = -ENETDOWN; |
| 5983 | goto error; |
| 5984 | } |
| 5985 | |
| 5986 | return v; |
| 5987 | error: |
| 5988 | dev_put(v); |
| 5989 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5990 | } |
| 5991 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 5992 | static const struct nla_policy |
| 5993 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5994 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 5995 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 5996 | }; |
| 5997 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5998 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 5999 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6000 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6001 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 6002 | struct nlattr *nla; |
| 6003 | int err; |
| 6004 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6005 | /* parse WME attributes if present */ |
| 6006 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 6007 | return 0; |
| 6008 | |
| 6009 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 6010 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 6011 | nl80211_sta_wme_policy, |
| 6012 | info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6013 | if (err) |
| 6014 | return err; |
| 6015 | |
| 6016 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 6017 | params->uapsd_queues = nla_get_u8( |
| 6018 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 6019 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 6020 | return -EINVAL; |
| 6021 | |
| 6022 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 6023 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 6024 | |
| 6025 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 6026 | return -EINVAL; |
| 6027 | |
| 6028 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 6029 | |
| 6030 | return 0; |
| 6031 | } |
| 6032 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6033 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 6034 | struct station_parameters *params) |
| 6035 | { |
| 6036 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 6037 | params->supported_channels = |
| 6038 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6039 | params->supported_channels_len = |
| 6040 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6041 | /* |
| 6042 | * Need to include at least one (first channel, number of |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 6043 | * channels) tuple for each subband (checked in policy), |
| 6044 | * and must have proper tuples for the rest of the data as well. |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6045 | */ |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6046 | if (params->supported_channels_len % 2) |
| 6047 | return -EINVAL; |
| 6048 | } |
| 6049 | |
| 6050 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 6051 | params->supported_oper_classes = |
| 6052 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 6053 | params->supported_oper_classes_len = |
| 6054 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6055 | } |
| 6056 | return 0; |
| 6057 | } |
| 6058 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6059 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 6060 | struct station_parameters *params) |
| 6061 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6062 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6063 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6064 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 6065 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6066 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6067 | params->ht_capa = |
| 6068 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 6069 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6070 | params->vht_capa = |
| 6071 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6072 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6073 | params->he_capa = |
| 6074 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6075 | params->he_capa_len = |
| 6076 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6077 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6078 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6079 | err = nl80211_parse_sta_channel_info(info, params); |
| 6080 | if (err) |
| 6081 | return err; |
| 6082 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6083 | return nl80211_parse_sta_wme(info, params); |
| 6084 | } |
| 6085 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6086 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 6087 | struct station_parameters *params) |
| 6088 | { |
| 6089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6090 | int idx; |
| 6091 | |
| 6092 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 6093 | if (!rdev->ops->set_tx_power || |
| 6094 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6095 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 6096 | return -EOPNOTSUPP; |
| 6097 | |
| 6098 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 6099 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 6100 | |
| 6101 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 6102 | idx = NL80211_ATTR_STA_TX_POWER; |
| 6103 | |
| 6104 | if (info->attrs[idx]) |
| 6105 | params->txpwr.power = |
| 6106 | nla_get_s16(info->attrs[idx]); |
| 6107 | else |
| 6108 | return -EINVAL; |
| 6109 | } |
| 6110 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 6111 | } |
| 6112 | |
| 6113 | return 0; |
| 6114 | } |
| 6115 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6116 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 6117 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6119 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6120 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6121 | u8 *mac_addr; |
| 6122 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6123 | |
| 6124 | memset(¶ms, 0, sizeof(params)); |
| 6125 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6126 | if (!rdev->ops->change_station) |
| 6127 | return -EOPNOTSUPP; |
| 6128 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6129 | /* |
| 6130 | * AID and listen_interval properties can be set only for unassociated |
| 6131 | * station. Include these parameters here and will check them in |
| 6132 | * cfg80211_check_station_change(). |
| 6133 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 6134 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 6135 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6136 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6137 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6138 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6139 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6140 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6141 | params.listen_interval = |
| 6142 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 6143 | else |
| 6144 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6145 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6146 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 6147 | params.support_p2p_ps = |
| 6148 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 6149 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6150 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6151 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6152 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6153 | return -EINVAL; |
| 6154 | |
| 6155 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6156 | |
| 6157 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 6158 | params.supported_rates = |
| 6159 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6160 | params.supported_rates_len = |
| 6161 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6162 | } |
| 6163 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6164 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6165 | params.capability = |
| 6166 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6167 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6168 | } |
| 6169 | |
| 6170 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6171 | params.ext_capab = |
| 6172 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6173 | params.ext_capab_len = |
| 6174 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6175 | } |
| 6176 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6177 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6178 | return -EINVAL; |
| 6179 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6180 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6181 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6182 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6183 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6184 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6185 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6186 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6187 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 6188 | params.peer_aid = nla_get_u16( |
| 6189 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6190 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 6191 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6192 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6193 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 6194 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6195 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 6196 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6197 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6198 | params.opmode_notif_used = true; |
| 6199 | params.opmode_notif = |
| 6200 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6201 | } |
| 6202 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6203 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6204 | params.he_6ghz_capa = |
Johannes Berg | fce2ff7 | 2020-08-05 15:35:18 +0200 | [diff] [blame] | 6205 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6206 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6207 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6208 | params.airtime_weight = |
| 6209 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6210 | |
| 6211 | if (params.airtime_weight && |
| 6212 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6213 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6214 | return -EOPNOTSUPP; |
| 6215 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6216 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6217 | if (err) |
| 6218 | return err; |
| 6219 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6220 | /* Include parameters for TDLS peer (will check later) */ |
| 6221 | err = nl80211_set_station_tdls(info, ¶ms); |
| 6222 | if (err) |
| 6223 | return err; |
| 6224 | |
| 6225 | params.vlan = get_vlan(info, rdev); |
| 6226 | if (IS_ERR(params.vlan)) |
| 6227 | return PTR_ERR(params.vlan); |
| 6228 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6229 | switch (dev->ieee80211_ptr->iftype) { |
| 6230 | case NL80211_IFTYPE_AP: |
| 6231 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6232 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6233 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6234 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6235 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6236 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6237 | break; |
| 6238 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6239 | err = -EOPNOTSUPP; |
| 6240 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 6241 | } |
| 6242 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6243 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6244 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6245 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6246 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6247 | if (params.vlan) |
| 6248 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6249 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6250 | return err; |
| 6251 | } |
| 6252 | |
| 6253 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6254 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6256 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6257 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6258 | struct station_parameters params; |
| 6259 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6260 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6261 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6262 | |
| 6263 | memset(¶ms, 0, sizeof(params)); |
| 6264 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6265 | if (!rdev->ops->add_station) |
| 6266 | return -EOPNOTSUPP; |
| 6267 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6268 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6269 | return -EINVAL; |
| 6270 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6271 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6272 | return -EINVAL; |
| 6273 | |
| 6274 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6275 | return -EINVAL; |
| 6276 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6277 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6278 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 6279 | return -EINVAL; |
| 6280 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6281 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6282 | params.supported_rates = |
| 6283 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6284 | params.supported_rates_len = |
| 6285 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6286 | params.listen_interval = |
| 6287 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6288 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6289 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6290 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6291 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6292 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6293 | params.support_p2p_ps = |
| 6294 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6295 | } else { |
| 6296 | /* |
| 6297 | * if not specified, assume it's supported for P2P GO interface, |
| 6298 | * and is NOT supported for AP interface |
| 6299 | */ |
| 6300 | params.support_p2p_ps = |
| 6301 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6302 | } |
| 6303 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6304 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6305 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6306 | else |
| 6307 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6308 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6309 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6310 | params.capability = |
| 6311 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6312 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6313 | } |
| 6314 | |
| 6315 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6316 | params.ext_capab = |
| 6317 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6318 | params.ext_capab_len = |
| 6319 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6320 | } |
| 6321 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 6322 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6323 | params.ht_capa = |
| 6324 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6325 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 6326 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6327 | params.vht_capa = |
| 6328 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6329 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6330 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6331 | params.he_capa = |
| 6332 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6333 | params.he_capa_len = |
| 6334 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6335 | } |
| 6336 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6337 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6338 | params.he_6ghz_capa = |
| 6339 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6340 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 6341 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6342 | params.opmode_notif_used = true; |
| 6343 | params.opmode_notif = |
| 6344 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6345 | } |
| 6346 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6347 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6348 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6349 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6350 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6351 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6352 | params.airtime_weight = |
| 6353 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6354 | |
| 6355 | if (params.airtime_weight && |
| 6356 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6357 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6358 | return -EOPNOTSUPP; |
| 6359 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6360 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6361 | if (err) |
| 6362 | return err; |
| 6363 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6364 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6365 | if (err) |
| 6366 | return err; |
| 6367 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6368 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6369 | if (err) |
| 6370 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6371 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6372 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6373 | return -EINVAL; |
| 6374 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6375 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6376 | * as userspace might just pass through the capabilities from the IEs |
| 6377 | * directly, rather than enforcing this restriction and returning an |
| 6378 | * error in this case. |
| 6379 | */ |
| 6380 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6381 | params.ht_capa = NULL; |
| 6382 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6383 | |
| 6384 | /* HE requires WME */ |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6385 | if (params.he_capa_len || params.he_6ghz_capa) |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6386 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6387 | } |
| 6388 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6389 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
| 6390 | if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) |
| 6391 | return -EINVAL; |
| 6392 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6393 | /* When you run into this, adjust the code below for the new flag */ |
| 6394 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6395 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6396 | switch (dev->ieee80211_ptr->iftype) { |
| 6397 | case NL80211_IFTYPE_AP: |
| 6398 | case NL80211_IFTYPE_AP_VLAN: |
| 6399 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6400 | /* ignore WME attributes if iface/sta is not capable */ |
| 6401 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6402 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6403 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6404 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6405 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6406 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6407 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6408 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6409 | /* but don't bother the driver with it */ |
| 6410 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6411 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6412 | /* allow authenticated/associated only if driver handles it */ |
| 6413 | if (!(rdev->wiphy.features & |
| 6414 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6415 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6416 | return -EINVAL; |
| 6417 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6418 | /* Older userspace, or userspace wanting to be compatible with |
| 6419 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6420 | * and assoc flags in the mask, but assumes the station will be |
| 6421 | * added as associated anyway since this was the required driver |
| 6422 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6423 | * introduced. |
| 6424 | * In order to not bother drivers with this quirk in the API |
| 6425 | * set the flags in both the mask and set for new stations in |
| 6426 | * this case. |
| 6427 | */ |
| 6428 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6429 | params.sta_flags_mask |= auth_assoc; |
| 6430 | params.sta_flags_set |= auth_assoc; |
| 6431 | } |
| 6432 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6433 | /* must be last in here for error handling */ |
| 6434 | params.vlan = get_vlan(info, rdev); |
| 6435 | if (IS_ERR(params.vlan)) |
| 6436 | return PTR_ERR(params.vlan); |
| 6437 | break; |
| 6438 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6439 | /* ignore uAPSD data */ |
| 6440 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6441 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6442 | /* associated is disallowed */ |
| 6443 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6444 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6445 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6446 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6447 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6448 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6449 | break; |
| 6450 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 6451 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6452 | /* ignore uAPSD data */ |
| 6453 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6454 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6455 | /* these are disallowed */ |
| 6456 | if (params.sta_flags_mask & |
| 6457 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6458 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6459 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6460 | /* Only TDLS peers can be added */ |
| 6461 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6462 | return -EINVAL; |
| 6463 | /* Can only add if TDLS ... */ |
| 6464 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6465 | return -EOPNOTSUPP; |
| 6466 | /* ... with external setup is supported */ |
| 6467 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6468 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6469 | /* |
| 6470 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6471 | * as authorized, but it shouldn't yet be. |
| 6472 | */ |
| 6473 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6474 | break; |
| 6475 | default: |
| 6476 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6477 | } |
| 6478 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6479 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6481 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6482 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6483 | if (params.vlan) |
| 6484 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6485 | return err; |
| 6486 | } |
| 6487 | |
| 6488 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6489 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6491 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6492 | struct station_del_parameters params; |
| 6493 | |
| 6494 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6495 | |
| 6496 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6497 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6498 | |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6499 | switch (dev->ieee80211_ptr->iftype) { |
| 6500 | case NL80211_IFTYPE_AP: |
| 6501 | case NL80211_IFTYPE_AP_VLAN: |
| 6502 | case NL80211_IFTYPE_MESH_POINT: |
| 6503 | case NL80211_IFTYPE_P2P_GO: |
| 6504 | /* always accept these */ |
| 6505 | break; |
| 6506 | case NL80211_IFTYPE_ADHOC: |
| 6507 | /* conditionally accept */ |
| 6508 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6509 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) |
| 6510 | break; |
Nicolas Cavallari | edafcf4 | 2020-03-05 14:57:53 +0100 | [diff] [blame] | 6511 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6512 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6513 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6514 | } |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6515 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6516 | if (!rdev->ops->del_station) |
| 6517 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6518 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 6519 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 6520 | params.subtype = |
| 6521 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 6522 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 6523 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 6524 | return -EINVAL; |
| 6525 | } else { |
| 6526 | /* Default to Deauthentication frame */ |
| 6527 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 6528 | } |
| 6529 | |
| 6530 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 6531 | params.reason_code = |
| 6532 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6533 | if (params.reason_code == 0) |
| 6534 | return -EINVAL; /* 0 is reserved */ |
| 6535 | } else { |
| 6536 | /* Default to reason code 2 */ |
| 6537 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 6538 | } |
| 6539 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6540 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6541 | } |
| 6542 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6543 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6544 | int flags, struct net_device *dev, |
| 6545 | u8 *dst, u8 *next_hop, |
| 6546 | struct mpath_info *pinfo) |
| 6547 | { |
| 6548 | void *hdr; |
| 6549 | struct nlattr *pinfoattr; |
| 6550 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 6551 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6552 | if (!hdr) |
| 6553 | return -1; |
| 6554 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6555 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6556 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6557 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 6558 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 6559 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 6560 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6561 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6562 | if (!pinfoattr) |
| 6563 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6564 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 6565 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 6566 | pinfo->frame_qlen)) |
| 6567 | goto nla_put_failure; |
| 6568 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 6569 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 6570 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 6571 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 6572 | pinfo->metric)) || |
| 6573 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 6574 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 6575 | pinfo->exptime)) || |
| 6576 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 6577 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 6578 | pinfo->flags)) || |
| 6579 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 6580 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 6581 | pinfo->discovery_timeout)) || |
| 6582 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 6583 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 6584 | pinfo->discovery_retries)) || |
| 6585 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 6586 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 6587 | pinfo->hop_count)) || |
| 6588 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 6589 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 6590 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6591 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6592 | |
| 6593 | nla_nest_end(msg, pinfoattr); |
| 6594 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6595 | genlmsg_end(msg, hdr); |
| 6596 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6597 | |
| 6598 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 6599 | genlmsg_cancel(msg, hdr); |
| 6600 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6604 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6605 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6606 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6607 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6608 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6609 | u8 dst[ETH_ALEN]; |
| 6610 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6611 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6612 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6613 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6614 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6615 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6616 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6617 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6618 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6619 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6620 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6621 | goto out_err; |
| 6622 | } |
| 6623 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6624 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6625 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 6626 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6627 | } |
| 6628 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6629 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6630 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6631 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6632 | if (err == -ENOENT) |
| 6633 | break; |
| 6634 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6635 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6636 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6637 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6638 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6639 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6640 | &pinfo) < 0) |
| 6641 | goto out; |
| 6642 | |
| 6643 | path_idx++; |
| 6644 | } |
| 6645 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6646 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6647 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6648 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6649 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6650 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6651 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6652 | } |
| 6653 | |
| 6654 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6655 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6657 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6659 | struct mpath_info pinfo; |
| 6660 | struct sk_buff *msg; |
| 6661 | u8 *dst = NULL; |
| 6662 | u8 next_hop[ETH_ALEN]; |
| 6663 | |
| 6664 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6665 | |
| 6666 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6667 | return -EINVAL; |
| 6668 | |
| 6669 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6670 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6671 | if (!rdev->ops->get_mpath) |
| 6672 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6673 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6675 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6676 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6677 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6678 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6679 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6680 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6681 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6682 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6683 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6684 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6685 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6686 | dev, dst, next_hop, &pinfo) < 0) { |
| 6687 | nlmsg_free(msg); |
| 6688 | return -ENOBUFS; |
| 6689 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6691 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6695 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6697 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6698 | u8 *dst = NULL; |
| 6699 | u8 *next_hop = NULL; |
| 6700 | |
| 6701 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6702 | return -EINVAL; |
| 6703 | |
| 6704 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6705 | return -EINVAL; |
| 6706 | |
| 6707 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6708 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6709 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6710 | if (!rdev->ops->change_mpath) |
| 6711 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6712 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6713 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6714 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6715 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6716 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6717 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6718 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6719 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6720 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6722 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6723 | u8 *dst = NULL; |
| 6724 | u8 *next_hop = NULL; |
| 6725 | |
| 6726 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6727 | return -EINVAL; |
| 6728 | |
| 6729 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6730 | return -EINVAL; |
| 6731 | |
| 6732 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6733 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6734 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6735 | if (!rdev->ops->add_mpath) |
| 6736 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6737 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6739 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6740 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6741 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6742 | } |
| 6743 | |
| 6744 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6745 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6747 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6748 | u8 *dst = NULL; |
| 6749 | |
| 6750 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6751 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6752 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6753 | if (!rdev->ops->del_mpath) |
| 6754 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6755 | |
Miaoqing Pan | b501426 | 2019-09-26 16:16:50 +0800 | [diff] [blame] | 6756 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6757 | return -EOPNOTSUPP; |
| 6758 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6759 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6760 | } |
| 6761 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6762 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6763 | { |
| 6764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6765 | int err; |
| 6766 | struct net_device *dev = info->user_ptr[1]; |
| 6767 | struct mpath_info pinfo; |
| 6768 | struct sk_buff *msg; |
| 6769 | u8 *dst = NULL; |
| 6770 | u8 mpp[ETH_ALEN]; |
| 6771 | |
| 6772 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6773 | |
| 6774 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6775 | return -EINVAL; |
| 6776 | |
| 6777 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6778 | |
| 6779 | if (!rdev->ops->get_mpp) |
| 6780 | return -EOPNOTSUPP; |
| 6781 | |
| 6782 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6783 | return -EOPNOTSUPP; |
| 6784 | |
| 6785 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6786 | if (err) |
| 6787 | return err; |
| 6788 | |
| 6789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6790 | if (!msg) |
| 6791 | return -ENOMEM; |
| 6792 | |
| 6793 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6794 | dev, dst, mpp, &pinfo) < 0) { |
| 6795 | nlmsg_free(msg); |
| 6796 | return -ENOBUFS; |
| 6797 | } |
| 6798 | |
| 6799 | return genlmsg_reply(msg, info); |
| 6800 | } |
| 6801 | |
| 6802 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6803 | struct netlink_callback *cb) |
| 6804 | { |
| 6805 | struct mpath_info pinfo; |
| 6806 | struct cfg80211_registered_device *rdev; |
| 6807 | struct wireless_dev *wdev; |
| 6808 | u8 dst[ETH_ALEN]; |
| 6809 | u8 mpp[ETH_ALEN]; |
| 6810 | int path_idx = cb->args[2]; |
| 6811 | int err; |
| 6812 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6813 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6814 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6815 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6816 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6817 | |
| 6818 | if (!rdev->ops->dump_mpp) { |
| 6819 | err = -EOPNOTSUPP; |
| 6820 | goto out_err; |
| 6821 | } |
| 6822 | |
| 6823 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6824 | err = -EOPNOTSUPP; |
| 6825 | goto out_err; |
| 6826 | } |
| 6827 | |
| 6828 | while (1) { |
| 6829 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6830 | mpp, &pinfo); |
| 6831 | if (err == -ENOENT) |
| 6832 | break; |
| 6833 | if (err) |
| 6834 | goto out_err; |
| 6835 | |
| 6836 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6837 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6838 | wdev->netdev, dst, mpp, |
| 6839 | &pinfo) < 0) |
| 6840 | goto out; |
| 6841 | |
| 6842 | path_idx++; |
| 6843 | } |
| 6844 | |
| 6845 | out: |
| 6846 | cb->args[2] = path_idx; |
| 6847 | err = skb->len; |
| 6848 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6849 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6850 | return err; |
| 6851 | } |
| 6852 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6853 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6854 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6856 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6857 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6858 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6859 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6860 | |
| 6861 | memset(¶ms, 0, sizeof(params)); |
| 6862 | /* default to not changing parameters */ |
| 6863 | params.use_cts_prot = -1; |
| 6864 | params.use_short_preamble = -1; |
| 6865 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6866 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6867 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6868 | params.p2p_ctwindow = -1; |
| 6869 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6870 | |
| 6871 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6872 | params.use_cts_prot = |
| 6873 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6874 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6875 | params.use_short_preamble = |
| 6876 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6877 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6878 | params.use_short_slot_time = |
| 6879 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 6880 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6881 | params.basic_rates = |
| 6882 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6883 | params.basic_rates_len = |
| 6884 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6885 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6886 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6887 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6888 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6889 | params.ht_opmode = |
| 6890 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6891 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6892 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6894 | return -EINVAL; |
| 6895 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6896 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6897 | if (params.p2p_ctwindow != 0 && |
| 6898 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6899 | return -EINVAL; |
| 6900 | } |
| 6901 | |
| 6902 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6903 | u8 tmp; |
| 6904 | |
| 6905 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6906 | return -EINVAL; |
| 6907 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6908 | params.p2p_opp_ps = tmp; |
| 6909 | if (params.p2p_opp_ps && |
| 6910 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 6911 | return -EINVAL; |
| 6912 | } |
| 6913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6914 | if (!rdev->ops->change_bss) |
| 6915 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6916 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6919 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6920 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6921 | wdev_lock(wdev); |
| 6922 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 6923 | wdev_unlock(wdev); |
| 6924 | |
| 6925 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6926 | } |
| 6927 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6928 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6929 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6930 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6931 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6932 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6933 | u32 owner_nlportid; |
| 6934 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6935 | /* |
| 6936 | * You should only get this when cfg80211 hasn't yet initialized |
| 6937 | * completely when built-in to the kernel right between the time |
| 6938 | * window between nl80211_init() and regulatory_init(), if that is |
| 6939 | * even possible. |
| 6940 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6941 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 6942 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6943 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6944 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 6945 | user_reg_hint_type = |
| 6946 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 6947 | else |
| 6948 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 6949 | |
| 6950 | switch (user_reg_hint_type) { |
| 6951 | case NL80211_USER_REG_HINT_USER: |
| 6952 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 6953 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6954 | return -EINVAL; |
| 6955 | |
| 6956 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6957 | return regulatory_hint_user(data, user_reg_hint_type); |
| 6958 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6959 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 6960 | owner_nlportid = info->snd_portid; |
| 6961 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 6962 | } else { |
| 6963 | owner_nlportid = 0; |
| 6964 | is_indoor = true; |
| 6965 | } |
| 6966 | |
| 6967 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6968 | default: |
| 6969 | return -EINVAL; |
| 6970 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 6973 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 6974 | { |
| 6975 | return reg_reload_regdb(); |
| 6976 | } |
| 6977 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6978 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6979 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6980 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6982 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6984 | struct mesh_config cur_params; |
| 6985 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6986 | void *hdr; |
| 6987 | struct nlattr *pinfoattr; |
| 6988 | struct sk_buff *msg; |
| 6989 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6990 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6991 | return -EOPNOTSUPP; |
| 6992 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6993 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6994 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 6995 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6996 | wdev_lock(wdev); |
| 6997 | /* If not connected, get default parameters */ |
| 6998 | if (!wdev->mesh_id_len) |
| 6999 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 7000 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7001 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7002 | wdev_unlock(wdev); |
| 7003 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7004 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7005 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7006 | |
| 7007 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7009 | if (!msg) |
| 7010 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7011 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7012 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7013 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7014 | goto out; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7015 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7016 | if (!pinfoattr) |
| 7017 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7018 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7019 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 7020 | cur_params.dot11MeshRetryTimeout) || |
| 7021 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7022 | cur_params.dot11MeshConfirmTimeout) || |
| 7023 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7024 | cur_params.dot11MeshHoldingTimeout) || |
| 7025 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7026 | cur_params.dot11MeshMaxPeerLinks) || |
| 7027 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 7028 | cur_params.dot11MeshMaxRetries) || |
| 7029 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 7030 | cur_params.dot11MeshTTL) || |
| 7031 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 7032 | cur_params.element_ttl) || |
| 7033 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7034 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 7035 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 7036 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7037 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7038 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 7039 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7040 | cur_params.path_refresh_time) || |
| 7041 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7042 | cur_params.min_discovery_timeout) || |
| 7043 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 7044 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 7045 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 7046 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 7047 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 7048 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 7049 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 7050 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 7051 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 7052 | cur_params.dot11MeshHWMPRootMode) || |
| 7053 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7054 | cur_params.dot11MeshHWMPRannInterval) || |
| 7055 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 7056 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 7057 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 7058 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 7059 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 7060 | cur_params.rssi_threshold) || |
| 7061 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7062 | cur_params.ht_opmode) || |
| 7063 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7064 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 7065 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7066 | cur_params.dot11MeshHWMProotInterval) || |
| 7067 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7068 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 7069 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 7070 | cur_params.power_mode) || |
| 7071 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7072 | cur_params.dot11MeshAwakeWindowDuration) || |
| 7073 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7074 | cur_params.plink_timeout) || |
| 7075 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7076 | cur_params.dot11MeshConnectedToMeshGate) || |
| 7077 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7078 | cur_params.dot11MeshNolearn) || |
| 7079 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7080 | cur_params.dot11MeshConnectedToAuthServer)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7081 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7082 | nla_nest_end(msg, pinfoattr); |
| 7083 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7084 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7085 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7086 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7087 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7088 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7089 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7090 | } |
| 7091 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7092 | static const struct nla_policy |
| 7093 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 7094 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 7095 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7096 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 7097 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7098 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 7099 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7100 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 7101 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 7102 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 7103 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7104 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7105 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7106 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 7107 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7108 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 7109 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7110 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7111 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7112 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 7113 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7114 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 7115 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7116 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 7117 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7118 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 7119 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 7120 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7121 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7122 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7123 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 7124 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7125 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7126 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7127 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 7128 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7129 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 7130 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7131 | [NL80211_MESHCONF_POWER_MODE] = |
| 7132 | NLA_POLICY_RANGE(NLA_U32, |
| 7133 | NL80211_MESH_POWER_ACTIVE, |
| 7134 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7135 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7136 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7137 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7138 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7139 | [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7140 | }; |
| 7141 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7142 | static const struct nla_policy |
| 7143 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7144 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7145 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 7146 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 7147 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7148 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7149 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 7150 | [NL80211_MESH_SETUP_IE] = |
| 7151 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 7152 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7153 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7154 | }; |
| 7155 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7156 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7157 | struct mesh_config *cfg, |
| 7158 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7159 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7160 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7161 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7162 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7163 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7164 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 7165 | do { \ |
| 7166 | if (tb[attr]) { \ |
| 7167 | cfg->param = fn(tb[attr]); \ |
| 7168 | mask |= BIT((attr) - 1); \ |
| 7169 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7170 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7171 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7172 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7173 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7174 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7175 | return -EINVAL; |
| 7176 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7177 | /* This makes sure that there aren't more than 32 mesh config |
| 7178 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 7179 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 7180 | |
| 7181 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7182 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 7183 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 7184 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 7185 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7186 | nla_get_u16); |
| 7187 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 7188 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7189 | nla_get_u16); |
| 7190 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 7191 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7192 | nla_get_u16); |
| 7193 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 7194 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 7195 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 7196 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 7197 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 7198 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 7199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 7200 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7201 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7203 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7204 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7205 | nla_get_u32); |
| 7206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 7207 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7208 | nla_get_u8); |
| 7209 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 7210 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7211 | nla_get_u32); |
| 7212 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 7213 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 7214 | return -EINVAL; |
| 7215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 7216 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7217 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7219 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7220 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7221 | nla_get_u32); |
| 7222 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 7223 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 7224 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 7225 | return -EINVAL; |
| 7226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7227 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7228 | nla_get_u16); |
| 7229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7230 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7231 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7233 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7234 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7235 | nla_get_u16); |
| 7236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 7237 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 7238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 7239 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7240 | nla_get_u16); |
| 7241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7242 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7243 | nla_get_u8); |
| 7244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 7245 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 7246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 7247 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7248 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7249 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 7250 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 7251 | nla_get_u8); |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7252 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
| 7253 | NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7254 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7255 | /* |
| 7256 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7257 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7258 | */ |
| 7259 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 7260 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 7261 | |
| 7262 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 7263 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 7264 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7265 | return -EINVAL; |
| 7266 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7267 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7268 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7269 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7270 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 7271 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7272 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7273 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7274 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7275 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7276 | nla_get_u32); |
| 7277 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7278 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7279 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7280 | return -EINVAL; |
| 7281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7282 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7283 | nla_get_u16); |
| 7284 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7285 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7286 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7287 | nla_get_u16); |
| 7288 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7289 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7290 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7291 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7292 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7293 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7294 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
| 7295 | NL80211_MESHCONF_NOLEARN, nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7296 | if (mask_out) |
| 7297 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7298 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7299 | return 0; |
| 7300 | |
| 7301 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7302 | } |
| 7303 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7304 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7305 | struct mesh_setup *setup) |
| 7306 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7308 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7309 | |
| 7310 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7311 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7312 | if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7313 | return -EINVAL; |
| 7314 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7315 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7316 | setup->sync_method = |
| 7317 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7318 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7319 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7320 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7321 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7322 | setup->path_sel_proto = |
| 7323 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7324 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7325 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7326 | |
| 7327 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7328 | setup->path_metric = |
| 7329 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7330 | IEEE80211_PATH_METRIC_VENDOR : |
| 7331 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7332 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7333 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7334 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7335 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7336 | setup->ie = nla_data(ieattr); |
| 7337 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7338 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7339 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7340 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7341 | return -EINVAL; |
| 7342 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7343 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7344 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7345 | if (setup->is_secure) |
| 7346 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7347 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7348 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7349 | if (!setup->user_mpm) |
| 7350 | return -EINVAL; |
| 7351 | setup->auth_id = |
| 7352 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7353 | } |
| 7354 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7355 | return 0; |
| 7356 | } |
| 7357 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7358 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7359 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7360 | { |
| 7361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7362 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7363 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7364 | struct mesh_config cfg; |
| 7365 | u32 mask; |
| 7366 | int err; |
| 7367 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7368 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7369 | return -EOPNOTSUPP; |
| 7370 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7371 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7372 | return -EOPNOTSUPP; |
| 7373 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7374 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7375 | if (err) |
| 7376 | return err; |
| 7377 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7378 | wdev_lock(wdev); |
| 7379 | if (!wdev->mesh_id_len) |
| 7380 | err = -ENOLINK; |
| 7381 | |
| 7382 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7383 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7384 | |
| 7385 | wdev_unlock(wdev); |
| 7386 | |
| 7387 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7390 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7391 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7392 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7393 | struct nlattr *nl_reg_rules; |
| 7394 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7395 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7396 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7397 | (regdom->dfs_region && |
| 7398 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7399 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7400 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7401 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7402 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7403 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7404 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7405 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7406 | struct nlattr *nl_reg_rule; |
| 7407 | const struct ieee80211_reg_rule *reg_rule; |
| 7408 | const struct ieee80211_freq_range *freq_range; |
| 7409 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7410 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7411 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7412 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7413 | freq_range = ®_rule->freq_range; |
| 7414 | power_rule = ®_rule->power_rule; |
| 7415 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7416 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7417 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7418 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7419 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7420 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7421 | if (!max_bandwidth_khz) |
| 7422 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7423 | reg_rule); |
| 7424 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7425 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7426 | reg_rule->flags) || |
| 7427 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7428 | freq_range->start_freq_khz) || |
| 7429 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7430 | freq_range->end_freq_khz) || |
| 7431 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7432 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7433 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7434 | power_rule->max_antenna_gain) || |
| 7435 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 7436 | power_rule->max_eirp) || |
| 7437 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7438 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7439 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7440 | |
| 7441 | nla_nest_end(msg, nl_reg_rule); |
| 7442 | } |
| 7443 | |
| 7444 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7445 | return 0; |
| 7446 | |
| 7447 | nla_put_failure: |
| 7448 | return -EMSGSIZE; |
| 7449 | } |
| 7450 | |
| 7451 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7452 | { |
| 7453 | const struct ieee80211_regdomain *regdom = NULL; |
| 7454 | struct cfg80211_registered_device *rdev; |
| 7455 | struct wiphy *wiphy = NULL; |
| 7456 | struct sk_buff *msg; |
| 7457 | void *hdr; |
| 7458 | |
| 7459 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7460 | if (!msg) |
| 7461 | return -ENOBUFS; |
| 7462 | |
| 7463 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7464 | NL80211_CMD_GET_REG); |
| 7465 | if (!hdr) |
| 7466 | goto put_failure; |
| 7467 | |
| 7468 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7469 | bool self_managed; |
| 7470 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7471 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7472 | if (IS_ERR(rdev)) { |
| 7473 | nlmsg_free(msg); |
| 7474 | return PTR_ERR(rdev); |
| 7475 | } |
| 7476 | |
| 7477 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7478 | self_managed = wiphy->regulatory_flags & |
| 7479 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7480 | regdom = get_wiphy_regdom(wiphy); |
| 7481 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7482 | /* a self-managed-reg device must have a private regdom */ |
| 7483 | if (WARN_ON(!regdom && self_managed)) { |
| 7484 | nlmsg_free(msg); |
| 7485 | return -EINVAL; |
| 7486 | } |
| 7487 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7488 | if (regdom && |
| 7489 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7490 | goto nla_put_failure; |
| 7491 | } |
| 7492 | |
| 7493 | if (!wiphy && reg_last_request_cell_base() && |
| 7494 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7495 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7496 | goto nla_put_failure; |
| 7497 | |
| 7498 | rcu_read_lock(); |
| 7499 | |
| 7500 | if (!regdom) |
| 7501 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7502 | |
| 7503 | if (nl80211_put_regdom(regdom, msg)) |
| 7504 | goto nla_put_failure_rcu; |
| 7505 | |
| 7506 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7507 | |
| 7508 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7509 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7510 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7511 | nla_put_failure_rcu: |
| 7512 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7513 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7514 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7515 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7516 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7517 | } |
| 7518 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7519 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 7520 | u32 seq, int flags, struct wiphy *wiphy, |
| 7521 | const struct ieee80211_regdomain *regdom) |
| 7522 | { |
| 7523 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 7524 | NL80211_CMD_GET_REG); |
| 7525 | |
| 7526 | if (!hdr) |
| 7527 | return -1; |
| 7528 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 7529 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7530 | |
| 7531 | if (nl80211_put_regdom(regdom, msg)) |
| 7532 | goto nla_put_failure; |
| 7533 | |
| 7534 | if (!wiphy && reg_last_request_cell_base() && |
| 7535 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7536 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7537 | goto nla_put_failure; |
| 7538 | |
| 7539 | if (wiphy && |
| 7540 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7541 | goto nla_put_failure; |
| 7542 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7543 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 7544 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 7545 | goto nla_put_failure; |
| 7546 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7547 | genlmsg_end(msg, hdr); |
| 7548 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7549 | |
| 7550 | nla_put_failure: |
| 7551 | genlmsg_cancel(msg, hdr); |
| 7552 | return -EMSGSIZE; |
| 7553 | } |
| 7554 | |
| 7555 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 7556 | struct netlink_callback *cb) |
| 7557 | { |
| 7558 | const struct ieee80211_regdomain *regdom = NULL; |
| 7559 | struct cfg80211_registered_device *rdev; |
| 7560 | int err, reg_idx, start = cb->args[2]; |
| 7561 | |
| 7562 | rtnl_lock(); |
| 7563 | |
| 7564 | if (cfg80211_regdomain && start == 0) { |
| 7565 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7566 | NLM_F_MULTI, NULL, |
| 7567 | rtnl_dereference(cfg80211_regdomain)); |
| 7568 | if (err < 0) |
| 7569 | goto out_err; |
| 7570 | } |
| 7571 | |
| 7572 | /* the global regdom is idx 0 */ |
| 7573 | reg_idx = 1; |
| 7574 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 7575 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 7576 | if (!regdom) |
| 7577 | continue; |
| 7578 | |
| 7579 | if (++reg_idx <= start) |
| 7580 | continue; |
| 7581 | |
| 7582 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7583 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 7584 | if (err < 0) { |
| 7585 | reg_idx--; |
| 7586 | break; |
| 7587 | } |
| 7588 | } |
| 7589 | |
| 7590 | cb->args[2] = reg_idx; |
| 7591 | err = skb->len; |
| 7592 | out_err: |
| 7593 | rtnl_unlock(); |
| 7594 | return err; |
| 7595 | } |
| 7596 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7597 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 7598 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 7599 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 7600 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 7601 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 7602 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 7603 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 7604 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 7605 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 7606 | }; |
| 7607 | |
| 7608 | static int parse_reg_rule(struct nlattr *tb[], |
| 7609 | struct ieee80211_reg_rule *reg_rule) |
| 7610 | { |
| 7611 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 7612 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 7613 | |
| 7614 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 7615 | return -EINVAL; |
| 7616 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 7617 | return -EINVAL; |
| 7618 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 7619 | return -EINVAL; |
| 7620 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 7621 | return -EINVAL; |
| 7622 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 7623 | return -EINVAL; |
| 7624 | |
| 7625 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 7626 | |
| 7627 | freq_range->start_freq_khz = |
| 7628 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 7629 | freq_range->end_freq_khz = |
| 7630 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 7631 | freq_range->max_bandwidth_khz = |
| 7632 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 7633 | |
| 7634 | power_rule->max_eirp = |
| 7635 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 7636 | |
| 7637 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 7638 | power_rule->max_antenna_gain = |
| 7639 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 7640 | |
| 7641 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 7642 | reg_rule->dfs_cac_ms = |
| 7643 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 7644 | |
| 7645 | return 0; |
| 7646 | } |
| 7647 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7648 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7649 | { |
| 7650 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 7651 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7652 | char *alpha2; |
| 7653 | int rem_reg_rules, r; |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7654 | u32 num_rules = 0, rule_idx = 0; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 7655 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7656 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7657 | |
| 7658 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7659 | return -EINVAL; |
| 7660 | |
| 7661 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 7662 | return -EINVAL; |
| 7663 | |
| 7664 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7665 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7666 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 7667 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 7668 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7669 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7670 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7671 | num_rules++; |
| 7672 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 7673 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7674 | } |
| 7675 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 7676 | if (!reg_is_valid_request(alpha2)) |
| 7677 | return -EINVAL; |
| 7678 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7679 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 7680 | if (!rd) |
| 7681 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7682 | |
| 7683 | rd->n_reg_rules = num_rules; |
| 7684 | rd->alpha2[0] = alpha2[0]; |
| 7685 | rd->alpha2[1] = alpha2[1]; |
| 7686 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7687 | /* |
| 7688 | * Disable DFS master mode if the DFS region was |
| 7689 | * not supported or known on this kernel. |
| 7690 | */ |
| 7691 | if (reg_supported_dfs_region(dfs_region)) |
| 7692 | rd->dfs_region = dfs_region; |
| 7693 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7694 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7695 | rem_reg_rules) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7696 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 7697 | nl_reg_rule, reg_rule_policy, |
| 7698 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7699 | if (r) |
| 7700 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7701 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 7702 | if (r) |
| 7703 | goto bad_reg; |
| 7704 | |
| 7705 | rule_idx++; |
| 7706 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7707 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 7708 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7709 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7710 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7711 | } |
| 7712 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 7713 | /* set_regdom takes ownership of rd */ |
| 7714 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 7715 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7716 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7717 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7718 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7719 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7720 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7721 | static int validate_scan_freqs(struct nlattr *freqs) |
| 7722 | { |
| 7723 | struct nlattr *attr1, *attr2; |
| 7724 | int n_channels = 0, tmp1, tmp2; |
| 7725 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 7726 | nla_for_each_nested(attr1, freqs, tmp1) |
| 7727 | if (nla_len(attr1) != sizeof(u32)) |
| 7728 | return 0; |
| 7729 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7730 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 7731 | n_channels++; |
| 7732 | /* |
| 7733 | * Some hardware has a limited channel list for |
| 7734 | * scanning, and it is pretty much nonsensical |
| 7735 | * to scan for a channel twice, so disallow that |
| 7736 | * and don't require drivers to check that the |
| 7737 | * channel list they get isn't longer than what |
| 7738 | * they can scan, as long as they can scan all |
| 7739 | * the channels they registered at once. |
| 7740 | */ |
| 7741 | nla_for_each_nested(attr2, freqs, tmp2) |
| 7742 | if (attr1 != attr2 && |
| 7743 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 7744 | return 0; |
| 7745 | } |
| 7746 | |
| 7747 | return n_channels; |
| 7748 | } |
| 7749 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7750 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7751 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7752 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7753 | } |
| 7754 | |
| 7755 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7756 | struct cfg80211_bss_selection *bss_select) |
| 7757 | { |
| 7758 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7759 | struct nlattr *nest; |
| 7760 | int err; |
| 7761 | bool found = false; |
| 7762 | int i; |
| 7763 | |
| 7764 | /* only process one nested attribute */ |
| 7765 | nest = nla_data(nla); |
| 7766 | if (!nla_ok(nest, nla_len(nest))) |
| 7767 | return -EINVAL; |
| 7768 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7769 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 7770 | nest, nl80211_bss_select_policy, |
| 7771 | NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7772 | if (err) |
| 7773 | return err; |
| 7774 | |
| 7775 | /* only one attribute may be given */ |
| 7776 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7777 | if (attr[i]) { |
| 7778 | if (found) |
| 7779 | return -EINVAL; |
| 7780 | found = true; |
| 7781 | } |
| 7782 | } |
| 7783 | |
| 7784 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7785 | |
| 7786 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7787 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7788 | |
| 7789 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7790 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7791 | bss_select->param.band_pref = |
| 7792 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7793 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7794 | return -EINVAL; |
| 7795 | } |
| 7796 | |
| 7797 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7798 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7799 | |
| 7800 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7801 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7802 | bss_select->param.adjust.band = adj_param->band; |
| 7803 | bss_select->param.adjust.delta = adj_param->delta; |
| 7804 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7805 | return -EINVAL; |
| 7806 | } |
| 7807 | |
| 7808 | /* user-space did not provide behaviour attribute */ |
| 7809 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7810 | return -EINVAL; |
| 7811 | |
| 7812 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7813 | return -EINVAL; |
| 7814 | |
| 7815 | return 0; |
| 7816 | } |
| 7817 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 7818 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7819 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7820 | { |
| 7821 | int i; |
| 7822 | |
| 7823 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 7824 | eth_zero_addr(mac_addr); |
| 7825 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7826 | mac_addr[0] = 0x2; |
| 7827 | mac_addr_mask[0] = 0x3; |
| 7828 | |
| 7829 | return 0; |
| 7830 | } |
| 7831 | |
| 7832 | /* need both or none */ |
| 7833 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7834 | return -EINVAL; |
| 7835 | |
| 7836 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7837 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7838 | |
| 7839 | /* don't allow or configure an mcast address */ |
| 7840 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7841 | is_multicast_ether_addr(mac_addr)) |
| 7842 | return -EINVAL; |
| 7843 | |
| 7844 | /* |
| 7845 | * allow users to pass a MAC address that has bits set outside |
| 7846 | * of the mask, but don't bother drivers with having to deal |
| 7847 | * with such bits |
| 7848 | */ |
| 7849 | for (i = 0; i < ETH_ALEN; i++) |
| 7850 | mac_addr[i] &= mac_addr_mask[i]; |
| 7851 | |
| 7852 | return 0; |
| 7853 | } |
| 7854 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7855 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7856 | { |
| 7857 | ASSERT_WDEV_LOCK(wdev); |
| 7858 | |
| 7859 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7860 | return true; |
| 7861 | |
| 7862 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7863 | return true; |
| 7864 | |
| 7865 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7866 | } |
| 7867 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7868 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7869 | enum nl80211_ext_feature_index feat) |
| 7870 | { |
| 7871 | if (!(flags & flag)) |
| 7872 | return true; |
| 7873 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7874 | return true; |
| 7875 | return false; |
| 7876 | } |
| 7877 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7878 | static int |
| 7879 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7880 | void *request, struct nlattr **attrs, |
| 7881 | bool is_sched_scan) |
| 7882 | { |
| 7883 | u8 *mac_addr, *mac_addr_mask; |
| 7884 | u32 *flags; |
| 7885 | enum nl80211_feature_flags randomness_flag; |
| 7886 | |
| 7887 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7888 | return 0; |
| 7889 | |
| 7890 | if (is_sched_scan) { |
| 7891 | struct cfg80211_sched_scan_request *req = request; |
| 7892 | |
| 7893 | randomness_flag = wdev ? |
| 7894 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7895 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7896 | flags = &req->flags; |
| 7897 | mac_addr = req->mac_addr; |
| 7898 | mac_addr_mask = req->mac_addr_mask; |
| 7899 | } else { |
| 7900 | struct cfg80211_scan_request *req = request; |
| 7901 | |
| 7902 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7903 | flags = &req->flags; |
| 7904 | mac_addr = req->mac_addr; |
| 7905 | mac_addr_mask = req->mac_addr_mask; |
| 7906 | } |
| 7907 | |
| 7908 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7909 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 7910 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7911 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7912 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7913 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 7914 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 7915 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7916 | NL80211_SCAN_FLAG_LOW_POWER, |
| 7917 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 7918 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7919 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 7920 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 7921 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7922 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 7923 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 7924 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7925 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 7926 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 7927 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7928 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 7929 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 7930 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7931 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 7932 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 7933 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7934 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 7935 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 7936 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7937 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 7938 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7939 | return -EOPNOTSUPP; |
| 7940 | |
| 7941 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7942 | int err; |
| 7943 | |
| 7944 | if (!(wiphy->features & randomness_flag) || |
| 7945 | (wdev && wdev->current_bss)) |
| 7946 | return -EOPNOTSUPP; |
| 7947 | |
| 7948 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 7949 | if (err) |
| 7950 | return err; |
| 7951 | } |
| 7952 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7953 | return 0; |
| 7954 | } |
| 7955 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7956 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 7957 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7959 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7960 | struct cfg80211_scan_request *request; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7961 | struct nlattr *scan_freqs = NULL; |
| 7962 | bool scan_freqs_khz = false; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7963 | struct nlattr *attr; |
| 7964 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7965 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7966 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7967 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7968 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7969 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 7970 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 7971 | return -EOPNOTSUPP; |
| 7972 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7973 | if (!rdev->ops->scan) |
| 7974 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7975 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7976 | if (rdev->scan_req || rdev->scan_msg) |
| 7977 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7978 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7979 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
| 7980 | if (!wiphy_ext_feature_isset(wiphy, |
| 7981 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) |
| 7982 | return -EOPNOTSUPP; |
| 7983 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; |
| 7984 | scan_freqs_khz = true; |
| 7985 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) |
| 7986 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; |
| 7987 | |
| 7988 | if (scan_freqs) { |
| 7989 | n_channels = validate_scan_freqs(scan_freqs); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7990 | if (!n_channels) |
| 7991 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7992 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7993 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7994 | } |
| 7995 | |
| 7996 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7997 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 7998 | n_ssids++; |
| 7999 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8000 | if (n_ssids > wiphy->max_scan_ssids) |
| 8001 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8002 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8003 | if (info->attrs[NL80211_ATTR_IE]) |
| 8004 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8005 | else |
| 8006 | ie_len = 0; |
| 8007 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8008 | if (ie_len > wiphy->max_scan_ie_len) |
| 8009 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 8010 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8011 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8012 | + sizeof(*request->ssids) * n_ssids |
| 8013 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8014 | + ie_len, GFP_KERNEL); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8015 | if (!request) |
| 8016 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8017 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8018 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 8019 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8020 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8021 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8022 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8023 | request->ie = (void *)(request->ssids + n_ssids); |
| 8024 | else |
| 8025 | request->ie = (void *)(request->channels + n_channels); |
| 8026 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8027 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8028 | i = 0; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8029 | if (scan_freqs) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8030 | /* user specified, bail out if channel not found */ |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8031 | nla_for_each_nested(attr, scan_freqs, tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8032 | struct ieee80211_channel *chan; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8033 | int freq = nla_get_u32(attr); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8034 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8035 | if (!scan_freqs_khz) |
| 8036 | freq = MHZ_TO_KHZ(freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8037 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8038 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8039 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8040 | err = -EINVAL; |
| 8041 | goto out_free; |
| 8042 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8043 | |
| 8044 | /* ignore disabled channels */ |
| 8045 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8046 | continue; |
| 8047 | |
| 8048 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8049 | i++; |
| 8050 | } |
| 8051 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8052 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8053 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8054 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8055 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8056 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8057 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8058 | if (!wiphy->bands[band]) |
| 8059 | continue; |
| 8060 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8061 | struct ieee80211_channel *chan; |
| 8062 | |
| 8063 | chan = &wiphy->bands[band]->channels[j]; |
| 8064 | |
| 8065 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8066 | continue; |
| 8067 | |
| 8068 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8069 | i++; |
| 8070 | } |
| 8071 | } |
| 8072 | } |
| 8073 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8074 | if (!i) { |
| 8075 | err = -EINVAL; |
| 8076 | goto out_free; |
| 8077 | } |
| 8078 | |
| 8079 | request->n_channels = i; |
| 8080 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 8081 | wdev_lock(wdev); |
| 8082 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 8083 | struct ieee80211_channel *chan; |
| 8084 | |
| 8085 | if (request->n_channels != 1) { |
| 8086 | wdev_unlock(wdev); |
| 8087 | err = -EBUSY; |
| 8088 | goto out_free; |
| 8089 | } |
| 8090 | |
| 8091 | chan = request->channels[0]; |
| 8092 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 8093 | wdev_unlock(wdev); |
| 8094 | err = -EBUSY; |
| 8095 | goto out_free; |
| 8096 | } |
| 8097 | } |
| 8098 | wdev_unlock(wdev); |
| 8099 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8100 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8101 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8102 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8103 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8104 | err = -EINVAL; |
| 8105 | goto out_free; |
| 8106 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8107 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8108 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8109 | i++; |
| 8110 | } |
| 8111 | } |
| 8112 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8113 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8114 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 8115 | memcpy((void *)request->ie, |
| 8116 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8117 | request->ie_len); |
| 8118 | } |
| 8119 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8120 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 8121 | if (wiphy->bands[i]) |
| 8122 | request->rates[i] = |
| 8123 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8124 | |
| 8125 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 8126 | nla_for_each_nested(attr, |
| 8127 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 8128 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8129 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8130 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8131 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8132 | err = -EINVAL; |
| 8133 | goto out_free; |
| 8134 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 8135 | |
| 8136 | if (!wiphy->bands[band]) |
| 8137 | continue; |
| 8138 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8139 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 8140 | nla_data(attr), |
| 8141 | nla_len(attr), |
| 8142 | &request->rates[band]); |
| 8143 | if (err) |
| 8144 | goto out_free; |
| 8145 | } |
| 8146 | } |
| 8147 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8148 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 8149 | if (!wiphy_ext_feature_isset(wiphy, |
| 8150 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 8151 | err = -EOPNOTSUPP; |
| 8152 | goto out_free; |
| 8153 | } |
| 8154 | |
| 8155 | request->duration = |
| 8156 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 8157 | request->duration_mandatory = |
| 8158 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 8159 | } |
| 8160 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8161 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 8162 | false); |
| 8163 | if (err) |
| 8164 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8165 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 8166 | request->no_cck = |
| 8167 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 8168 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 8169 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 8170 | * BSSID to scan for. This was problematic because that same attribute |
| 8171 | * was already used for another purpose (local random MAC address). The |
| 8172 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 8173 | * compatibility with older userspace components, also use the |
| 8174 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 8175 | * the specific BSSID use case instead of the random MAC address |
| 8176 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 8177 | */ |
| 8178 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 8179 | memcpy(request->bssid, |
| 8180 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 8181 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 8182 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 8183 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 8184 | ETH_ALEN); |
| 8185 | else |
| 8186 | eth_broadcast_addr(request->bssid); |
| 8187 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8188 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8189 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8190 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8191 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8192 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8193 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8194 | |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8195 | if (err) |
| 8196 | goto out_free; |
| 8197 | |
| 8198 | nl80211_send_scan_start(rdev, wdev); |
| 8199 | if (wdev->netdev) |
| 8200 | dev_hold(wdev->netdev); |
| 8201 | |
| 8202 | return 0; |
| 8203 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8204 | out_free: |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8205 | rdev->scan_req = NULL; |
| 8206 | kfree(request); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 8207 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8208 | return err; |
| 8209 | } |
| 8210 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 8211 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 8212 | { |
| 8213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8214 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8215 | |
| 8216 | if (!rdev->ops->abort_scan) |
| 8217 | return -EOPNOTSUPP; |
| 8218 | |
| 8219 | if (rdev->scan_msg) |
| 8220 | return 0; |
| 8221 | |
| 8222 | if (!rdev->scan_req) |
| 8223 | return -ENOENT; |
| 8224 | |
| 8225 | rdev_abort_scan(rdev, wdev); |
| 8226 | return 0; |
| 8227 | } |
| 8228 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8229 | static int |
| 8230 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 8231 | struct cfg80211_sched_scan_request *request, |
| 8232 | struct nlattr **attrs) |
| 8233 | { |
| 8234 | int tmp, err, i = 0; |
| 8235 | struct nlattr *attr; |
| 8236 | |
| 8237 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8238 | u32 interval; |
| 8239 | |
| 8240 | /* |
| 8241 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 8242 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8243 | * case one scan plan will be set with the specified scan |
| 8244 | * interval and infinite number of iterations. |
| 8245 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8246 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 8247 | if (!interval) |
| 8248 | return -EINVAL; |
| 8249 | |
| 8250 | request->scan_plans[0].interval = |
| 8251 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 8252 | if (!request->scan_plans[0].interval) |
| 8253 | return -EINVAL; |
| 8254 | |
| 8255 | if (request->scan_plans[0].interval > |
| 8256 | wiphy->max_sched_scan_plan_interval) |
| 8257 | request->scan_plans[0].interval = |
| 8258 | wiphy->max_sched_scan_plan_interval; |
| 8259 | |
| 8260 | return 0; |
| 8261 | } |
| 8262 | |
| 8263 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 8264 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 8265 | |
| 8266 | if (WARN_ON(i >= n_plans)) |
| 8267 | return -EINVAL; |
| 8268 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8269 | err = nla_parse_nested_deprecated(plan, |
| 8270 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 8271 | attr, nl80211_plan_policy, |
| 8272 | NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8273 | if (err) |
| 8274 | return err; |
| 8275 | |
| 8276 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8277 | return -EINVAL; |
| 8278 | |
| 8279 | request->scan_plans[i].interval = |
| 8280 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8281 | if (!request->scan_plans[i].interval || |
| 8282 | request->scan_plans[i].interval > |
| 8283 | wiphy->max_sched_scan_plan_interval) |
| 8284 | return -EINVAL; |
| 8285 | |
| 8286 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8287 | request->scan_plans[i].iterations = |
| 8288 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8289 | if (!request->scan_plans[i].iterations || |
| 8290 | (request->scan_plans[i].iterations > |
| 8291 | wiphy->max_sched_scan_plan_iterations)) |
| 8292 | return -EINVAL; |
| 8293 | } else if (i < n_plans - 1) { |
| 8294 | /* |
| 8295 | * All scan plans but the last one must specify |
| 8296 | * a finite number of iterations |
| 8297 | */ |
| 8298 | return -EINVAL; |
| 8299 | } |
| 8300 | |
| 8301 | i++; |
| 8302 | } |
| 8303 | |
| 8304 | /* |
| 8305 | * The last scan plan must not specify the number of |
| 8306 | * iterations, it is supposed to run infinitely |
| 8307 | */ |
| 8308 | if (request->scan_plans[n_plans - 1].iterations) |
| 8309 | return -EINVAL; |
| 8310 | |
| 8311 | return 0; |
| 8312 | } |
| 8313 | |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8314 | static int |
| 8315 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8316 | struct cfg80211_match_set *match_sets, |
| 8317 | struct nlattr *tb_band_rssi, |
| 8318 | s32 rssi_thold) |
| 8319 | { |
| 8320 | struct nlattr *attr; |
| 8321 | int i, tmp, ret = 0; |
| 8322 | |
| 8323 | if (!wiphy_ext_feature_isset(wiphy, |
| 8324 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8325 | if (tb_band_rssi) |
| 8326 | ret = -EOPNOTSUPP; |
| 8327 | else |
| 8328 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8329 | match_sets->per_band_rssi_thold[i] = |
| 8330 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8331 | return ret; |
| 8332 | } |
| 8333 | |
| 8334 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8335 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8336 | |
| 8337 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8338 | enum nl80211_band band = nla_type(attr); |
| 8339 | |
| 8340 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8341 | return -EINVAL; |
| 8342 | |
| 8343 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8344 | } |
| 8345 | |
| 8346 | return 0; |
| 8347 | } |
| 8348 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8349 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8350 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8351 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8352 | { |
| 8353 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8354 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8355 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8356 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8357 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8358 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8359 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8360 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8361 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8362 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8363 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8364 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8365 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8366 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8367 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8368 | } |
| 8369 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8370 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8371 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8372 | tmp) |
| 8373 | n_ssids++; |
| 8374 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 8375 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8376 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8377 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8378 | /* |
| 8379 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8380 | * the old implementation, matchsets containing only the RSSI attribute |
| 8381 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8382 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8383 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8384 | * older userspace that treated a matchset with only the RSSI as the |
| 8385 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8386 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8387 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8388 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8389 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8390 | tmp) { |
| 8391 | struct nlattr *rssi; |
| 8392 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8393 | err = nla_parse_nested_deprecated(tb, |
| 8394 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8395 | attr, |
| 8396 | nl80211_match_policy, |
| 8397 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8398 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8399 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8400 | |
| 8401 | /* SSID and BSSID are mutually exclusive */ |
| 8402 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8403 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8404 | return ERR_PTR(-EINVAL); |
| 8405 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8406 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8407 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8408 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8409 | n_match_sets++; |
| 8410 | continue; |
| 8411 | } |
| 8412 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8413 | if (rssi) |
| 8414 | default_match_rssi = nla_get_s32(rssi); |
| 8415 | } |
| 8416 | } |
| 8417 | |
| 8418 | /* However, if there's no other matchset, add the RSSI one */ |
| 8419 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8420 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8421 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8422 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8423 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8424 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8425 | if (attrs[NL80211_ATTR_IE]) |
| 8426 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8427 | else |
| 8428 | ie_len = 0; |
| 8429 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 8430 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8431 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 8432 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8433 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8434 | /* |
| 8435 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8436 | * each scan plan already specifies its own interval |
| 8437 | */ |
| 8438 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8439 | return ERR_PTR(-EINVAL); |
| 8440 | |
| 8441 | nla_for_each_nested(attr, |
| 8442 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8443 | n_plans++; |
| 8444 | } else { |
| 8445 | /* |
| 8446 | * The scan interval attribute is kept for backward |
| 8447 | * compatibility. If no scan plans are specified and sched scan |
| 8448 | * interval is specified, one scan plan will be set with this |
| 8449 | * scan interval and infinite number of iterations. |
| 8450 | */ |
| 8451 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8452 | return ERR_PTR(-EINVAL); |
| 8453 | |
| 8454 | n_plans = 1; |
| 8455 | } |
| 8456 | |
| 8457 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8458 | return ERR_PTR(-EINVAL); |
| 8459 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8460 | if (!wiphy_ext_feature_isset( |
| 8461 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8462 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8463 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8464 | return ERR_PTR(-EINVAL); |
| 8465 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8466 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8467 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8468 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8469 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8470 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8471 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8472 | if (!request) |
| 8473 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8474 | |
| 8475 | if (n_ssids) |
| 8476 | request->ssids = (void *)&request->channels[n_channels]; |
| 8477 | request->n_ssids = n_ssids; |
| 8478 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8479 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8480 | request->ie = (void *)(request->ssids + n_ssids); |
| 8481 | else |
| 8482 | request->ie = (void *)(request->channels + n_channels); |
| 8483 | } |
| 8484 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8485 | if (n_match_sets) { |
| 8486 | if (request->ie) |
| 8487 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8488 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8489 | request->match_sets = |
| 8490 | (void *)(request->ssids + n_ssids); |
| 8491 | else |
| 8492 | request->match_sets = |
| 8493 | (void *)(request->channels + n_channels); |
| 8494 | } |
| 8495 | request->n_match_sets = n_match_sets; |
| 8496 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8497 | if (n_match_sets) |
| 8498 | request->scan_plans = (void *)(request->match_sets + |
| 8499 | n_match_sets); |
| 8500 | else if (request->ie) |
| 8501 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8502 | else if (n_ssids) |
| 8503 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8504 | else |
| 8505 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8506 | |
| 8507 | request->n_scan_plans = n_plans; |
| 8508 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8509 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8510 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8511 | /* user specified, bail out if channel not found */ |
| 8512 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8513 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8514 | tmp) { |
| 8515 | struct ieee80211_channel *chan; |
| 8516 | |
| 8517 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 8518 | |
| 8519 | if (!chan) { |
| 8520 | err = -EINVAL; |
| 8521 | goto out_free; |
| 8522 | } |
| 8523 | |
| 8524 | /* ignore disabled channels */ |
| 8525 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8526 | continue; |
| 8527 | |
| 8528 | request->channels[i] = chan; |
| 8529 | i++; |
| 8530 | } |
| 8531 | } else { |
| 8532 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8533 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8534 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8535 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8536 | if (!wiphy->bands[band]) |
| 8537 | continue; |
| 8538 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8539 | struct ieee80211_channel *chan; |
| 8540 | |
| 8541 | chan = &wiphy->bands[band]->channels[j]; |
| 8542 | |
| 8543 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8544 | continue; |
| 8545 | |
| 8546 | request->channels[i] = chan; |
| 8547 | i++; |
| 8548 | } |
| 8549 | } |
| 8550 | } |
| 8551 | |
| 8552 | if (!i) { |
| 8553 | err = -EINVAL; |
| 8554 | goto out_free; |
| 8555 | } |
| 8556 | |
| 8557 | request->n_channels = i; |
| 8558 | |
| 8559 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8560 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8561 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8562 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8563 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8564 | err = -EINVAL; |
| 8565 | goto out_free; |
| 8566 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8567 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8568 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 8569 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8570 | i++; |
| 8571 | } |
| 8572 | } |
| 8573 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8574 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8575 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8576 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8577 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8578 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8579 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8580 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8581 | err = nla_parse_nested_deprecated(tb, |
| 8582 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8583 | attr, |
| 8584 | nl80211_match_policy, |
| 8585 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8586 | if (err) |
| 8587 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 8588 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8589 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8590 | |
| 8591 | if (!ssid && !bssid) { |
| 8592 | i++; |
| 8593 | continue; |
| 8594 | } |
| 8595 | |
| 8596 | if (WARN_ON(i >= n_match_sets)) { |
| 8597 | /* this indicates a programming error, |
| 8598 | * the loop above should have verified |
| 8599 | * things properly |
| 8600 | */ |
| 8601 | err = -EINVAL; |
| 8602 | goto out_free; |
| 8603 | } |
| 8604 | |
| 8605 | if (ssid) { |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8606 | memcpy(request->match_sets[i].ssid.ssid, |
| 8607 | nla_data(ssid), nla_len(ssid)); |
| 8608 | request->match_sets[i].ssid.ssid_len = |
| 8609 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8610 | } |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 8611 | if (bssid) |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8612 | memcpy(request->match_sets[i].bssid, |
| 8613 | nla_data(bssid), ETH_ALEN); |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8614 | |
| 8615 | /* special attribute - old implementation w/a */ |
| 8616 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 8617 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8618 | if (rssi) |
| 8619 | request->match_sets[i].rssi_thold = |
| 8620 | nla_get_s32(rssi); |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8621 | |
| 8622 | /* Parse per band RSSI attribute */ |
| 8623 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 8624 | &request->match_sets[i], |
| 8625 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 8626 | request->match_sets[i].rssi_thold); |
| 8627 | if (err) |
| 8628 | goto out_free; |
| 8629 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8630 | i++; |
| 8631 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8632 | |
| 8633 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 8634 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8635 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 8636 | |
| 8637 | request->min_rssi_thold = INT_MAX; |
| 8638 | for (i = 0; i < n_match_sets; i++) |
| 8639 | request->min_rssi_thold = |
| 8640 | min(request->match_sets[i].rssi_thold, |
| 8641 | request->min_rssi_thold); |
| 8642 | } else { |
| 8643 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8644 | } |
| 8645 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 8646 | if (ie_len) { |
| 8647 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8648 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8649 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8650 | request->ie_len); |
| 8651 | } |
| 8652 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8653 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 8654 | if (err) |
| 8655 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8656 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 8657 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 8658 | request->delay = |
| 8659 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 8660 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8661 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 8662 | request->relative_rssi = nla_get_s8( |
| 8663 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 8664 | request->relative_rssi_set = true; |
| 8665 | } |
| 8666 | |
| 8667 | if (request->relative_rssi_set && |
| 8668 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 8669 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 8670 | |
| 8671 | rssi_adjust = nla_data( |
| 8672 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 8673 | request->rssi_adjust.band = rssi_adjust->band; |
| 8674 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 8675 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 8676 | err = -EINVAL; |
| 8677 | goto out_free; |
| 8678 | } |
| 8679 | } |
| 8680 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8681 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 8682 | if (err) |
| 8683 | goto out_free; |
| 8684 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8685 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8686 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8687 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8688 | |
| 8689 | out_free: |
| 8690 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8691 | return ERR_PTR(err); |
| 8692 | } |
| 8693 | |
| 8694 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 8695 | struct genl_info *info) |
| 8696 | { |
| 8697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8698 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8699 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8700 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8701 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8702 | int err; |
| 8703 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8704 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8705 | return -EOPNOTSUPP; |
| 8706 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8707 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 8708 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 8709 | if (err) |
| 8710 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8711 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8712 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8713 | info->attrs, |
| 8714 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8715 | |
| 8716 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8717 | if (err) |
| 8718 | goto out_err; |
| 8719 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8720 | /* leave request id zero for legacy request |
| 8721 | * or if driver does not support multi-scheduled scan |
| 8722 | */ |
Denis Kenzior | 2fd351a | 2019-10-08 11:43:50 -0500 | [diff] [blame] | 8723 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 8724 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8725 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8726 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8727 | if (err) |
| 8728 | goto out_free; |
| 8729 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8730 | sched_scan_req->dev = dev; |
| 8731 | sched_scan_req->wiphy = &rdev->wiphy; |
| 8732 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 8733 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 8734 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 8735 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8736 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8737 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 8738 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8739 | return 0; |
| 8740 | |
| 8741 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8742 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8743 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8744 | return err; |
| 8745 | } |
| 8746 | |
| 8747 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 8748 | struct genl_info *info) |
| 8749 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8750 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8752 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8753 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8754 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8755 | return -EOPNOTSUPP; |
| 8756 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8757 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 8758 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8759 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 8760 | } |
| 8761 | |
| 8762 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 8763 | struct cfg80211_sched_scan_request, |
| 8764 | list); |
| 8765 | if (!req || req->reqid || |
| 8766 | (req->owner_nlportid && |
| 8767 | req->owner_nlportid != info->snd_portid)) |
| 8768 | return -ENOENT; |
| 8769 | |
| 8770 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8771 | } |
| 8772 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8773 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 8774 | struct genl_info *info) |
| 8775 | { |
| 8776 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8777 | struct net_device *dev = info->user_ptr[1]; |
| 8778 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8779 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8780 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8781 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8782 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8783 | int err; |
| 8784 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8785 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8786 | if (dfs_region == NL80211_DFS_UNSET) |
| 8787 | return -EINVAL; |
| 8788 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8789 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8790 | if (err) |
| 8791 | return err; |
| 8792 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 8793 | if (netif_carrier_ok(dev)) |
| 8794 | return -EBUSY; |
| 8795 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8796 | if (wdev->cac_started) |
| 8797 | return -EBUSY; |
| 8798 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8799 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8800 | if (err < 0) |
| 8801 | return err; |
| 8802 | |
| 8803 | if (err == 0) |
| 8804 | return -EINVAL; |
| 8805 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8806 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8807 | return -EINVAL; |
| 8808 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8809 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8810 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8811 | return -EOPNOTSUPP; |
| 8812 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8813 | if (!rdev->ops->start_radar_detection) |
| 8814 | return -EOPNOTSUPP; |
| 8815 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8816 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8817 | if (WARN_ON(!cac_time_ms)) |
| 8818 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8819 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8820 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8821 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 8822 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8823 | wdev->cac_started = true; |
| 8824 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8825 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8826 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8827 | return err; |
| 8828 | } |
| 8829 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8830 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8831 | struct genl_info *info) |
| 8832 | { |
| 8833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8834 | struct net_device *dev = info->user_ptr[1]; |
| 8835 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8836 | struct wiphy *wiphy = wdev->wiphy; |
| 8837 | struct cfg80211_chan_def chandef; |
| 8838 | enum nl80211_dfs_regions dfs_region; |
| 8839 | int err; |
| 8840 | |
| 8841 | dfs_region = reg_get_dfs_region(wiphy); |
| 8842 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8843 | GENL_SET_ERR_MSG(info, |
| 8844 | "DFS Region is not set. Unexpected Radar indication"); |
| 8845 | return -EINVAL; |
| 8846 | } |
| 8847 | |
| 8848 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8849 | if (err) { |
| 8850 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8851 | return err; |
| 8852 | } |
| 8853 | |
| 8854 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8855 | if (err < 0) { |
| 8856 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8857 | return err; |
| 8858 | } |
| 8859 | |
| 8860 | if (err == 0) { |
| 8861 | GENL_SET_ERR_MSG(info, |
| 8862 | "Unexpected Radar indication for chandef/iftype"); |
| 8863 | return -EINVAL; |
| 8864 | } |
| 8865 | |
| 8866 | /* Do not process this notification if radar is already detected |
| 8867 | * by kernel on this channel, and return success. |
| 8868 | */ |
| 8869 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8870 | return 0; |
| 8871 | |
| 8872 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8873 | |
| 8874 | cfg80211_sched_dfs_chan_update(rdev); |
| 8875 | |
Luca Coelho | a680fe4 | 2019-04-17 09:34:40 +0300 | [diff] [blame] | 8876 | rdev->radar_chandef = chandef; |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8877 | |
| 8878 | /* Propagate this notification to other radios as well */ |
| 8879 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8880 | |
| 8881 | return 0; |
| 8882 | } |
| 8883 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8884 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8885 | { |
| 8886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8887 | struct net_device *dev = info->user_ptr[1]; |
| 8888 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8889 | struct cfg80211_csa_settings params; |
| 8890 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8891 | * function is called under RTNL lock, so this should not be a problem. |
| 8892 | */ |
| 8893 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8894 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8895 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8896 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8897 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8898 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8899 | |
| 8900 | if (!rdev->ops->channel_switch || |
| 8901 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8902 | return -EOPNOTSUPP; |
| 8903 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8904 | switch (dev->ieee80211_ptr->iftype) { |
| 8905 | case NL80211_IFTYPE_AP: |
| 8906 | case NL80211_IFTYPE_P2P_GO: |
| 8907 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8908 | /* For all modes except AP the handle_dfs flag needs to be |
| 8909 | * supplied to tell the kernel that userspace will handle radar |
| 8910 | * events when they happen. Otherwise a switch to a channel |
| 8911 | * requiring DFS will be rejected. |
| 8912 | */ |
| 8913 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8914 | |
| 8915 | /* useless if AP is not running */ |
| 8916 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8917 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8918 | break; |
| 8919 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8920 | if (!wdev->ssid_len) |
| 8921 | return -ENOTCONN; |
| 8922 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 8923 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8924 | if (!wdev->mesh_id_len) |
| 8925 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8926 | break; |
| 8927 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8928 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8929 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8930 | |
| 8931 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 8932 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8933 | |
| 8934 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8935 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 8936 | return -EINVAL; |
| 8937 | |
| 8938 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 8939 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8940 | return -EINVAL; |
| 8941 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8942 | /* Even though the attribute is u32, the specification says |
| 8943 | * u8, so let's make sure we don't overflow. |
| 8944 | */ |
| 8945 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 8946 | if (cs_count > 255) |
| 8947 | return -EINVAL; |
| 8948 | |
| 8949 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8950 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8951 | if (!need_new_beacon) |
| 8952 | goto skip_beacons; |
| 8953 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8954 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8955 | if (err) |
| 8956 | return err; |
| 8957 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8958 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 8959 | info->attrs[NL80211_ATTR_CSA_IES], |
| 8960 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8961 | if (err) |
| 8962 | return err; |
| 8963 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8964 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8965 | if (err) |
| 8966 | return err; |
| 8967 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 8968 | if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8969 | return -EINVAL; |
| 8970 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 8971 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8972 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8973 | return -EINVAL; |
| 8974 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8975 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 8976 | if (rdev->wiphy.max_num_csa_counters && |
| 8977 | (params.n_counter_offsets_beacon > |
| 8978 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8979 | return -EINVAL; |
| 8980 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8981 | params.counter_offsets_beacon = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 8982 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8983 | |
| 8984 | /* sanity checks - counters should fit and be the same */ |
| 8985 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 8986 | u16 offset = params.counter_offsets_beacon[i]; |
| 8987 | |
| 8988 | if (offset >= params.beacon_csa.tail_len) |
| 8989 | return -EINVAL; |
| 8990 | |
| 8991 | if (params.beacon_csa.tail[offset] != params.count) |
| 8992 | return -EINVAL; |
| 8993 | } |
| 8994 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 8995 | if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
| 8996 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8997 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8998 | return -EINVAL; |
| 8999 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9000 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 9001 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 9002 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9003 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9004 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9005 | |
| 9006 | params.counter_offsets_presp = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9007 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9008 | |
| 9009 | /* sanity checks - counters should fit and be the same */ |
| 9010 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 9011 | u16 offset = params.counter_offsets_presp[i]; |
| 9012 | |
| 9013 | if (offset >= params.beacon_csa.probe_resp_len) |
| 9014 | return -EINVAL; |
| 9015 | |
| 9016 | if (params.beacon_csa.probe_resp[offset] != |
| 9017 | params.count) |
| 9018 | return -EINVAL; |
| 9019 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9020 | } |
| 9021 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9022 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9023 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 9024 | if (err) |
| 9025 | return err; |
| 9026 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 9027 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 9028 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9029 | return -EINVAL; |
| 9030 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9031 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 9032 | ¶ms.chandef, |
| 9033 | wdev->iftype); |
| 9034 | if (err < 0) |
| 9035 | return err; |
| 9036 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9037 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9038 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9039 | if (need_handle_dfs_flag && |
| 9040 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 9041 | return -EINVAL; |
| 9042 | } |
| 9043 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9044 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9045 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 9046 | params.block_tx = true; |
| 9047 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 9048 | wdev_lock(wdev); |
| 9049 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 9050 | wdev_unlock(wdev); |
| 9051 | |
| 9052 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9053 | } |
| 9054 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9055 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 9056 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9057 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9058 | struct wireless_dev *wdev, |
| 9059 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9060 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9061 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9062 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9063 | void *hdr; |
| 9064 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9065 | |
| 9066 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9067 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9068 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9069 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 9070 | if (!hdr) |
| 9071 | return -1; |
| 9072 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 9073 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9074 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9075 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 9076 | goto nla_put_failure; |
| 9077 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9078 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 9079 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9080 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 9081 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9082 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9083 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9084 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9085 | if (!bss) |
| 9086 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9087 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9088 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9089 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9090 | |
| 9091 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9092 | /* indicate whether we have probe response data or not */ |
| 9093 | if (rcu_access_pointer(res->proberesp_ies) && |
| 9094 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 9095 | goto fail_unlock_rcu; |
| 9096 | |
| 9097 | /* this pointer prefers to be pointed to probe response data |
| 9098 | * but is always valid |
| 9099 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9100 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9101 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9102 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 9103 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9104 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9105 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 9106 | ies->len, ies->data)) |
| 9107 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9108 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9109 | |
| 9110 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9111 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9112 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9113 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 9114 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9115 | goto fail_unlock_rcu; |
| 9116 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 9117 | ies->len, ies->data)) |
| 9118 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9119 | } |
| 9120 | rcu_read_unlock(); |
| 9121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9122 | if (res->beacon_interval && |
| 9123 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 9124 | goto nla_put_failure; |
| 9125 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 9126 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9127 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
| 9128 | res->channel->freq_offset) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 9129 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9130 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 9131 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 9132 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9133 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 9134 | if (intbss->parent_tsf && |
| 9135 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 9136 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 9137 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 9138 | intbss->parent_bssid))) |
| 9139 | goto nla_put_failure; |
| 9140 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9141 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9142 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 9143 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9144 | goto nla_put_failure; |
| 9145 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 9146 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 9147 | intbss->pub.chain_signal, |
| 9148 | NL80211_BSS_CHAIN_SIGNAL)) |
| 9149 | goto nla_put_failure; |
| 9150 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 9151 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9152 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9153 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 9154 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9155 | break; |
| 9156 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9157 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 9158 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9159 | break; |
| 9160 | default: |
| 9161 | break; |
| 9162 | } |
| 9163 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9164 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9165 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9166 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9167 | if (intbss == wdev->current_bss && |
| 9168 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9169 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 9170 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9171 | break; |
| 9172 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9173 | if (intbss == wdev->current_bss && |
| 9174 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9175 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 9176 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9177 | break; |
| 9178 | default: |
| 9179 | break; |
| 9180 | } |
| 9181 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9182 | nla_nest_end(msg, bss); |
| 9183 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9184 | genlmsg_end(msg, hdr); |
| 9185 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9186 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9187 | fail_unlock_rcu: |
| 9188 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9189 | nla_put_failure: |
| 9190 | genlmsg_cancel(msg, hdr); |
| 9191 | return -EMSGSIZE; |
| 9192 | } |
| 9193 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9194 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9195 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9196 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9197 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9198 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9199 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9200 | int err; |
| 9201 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9202 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9203 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9204 | if (err) { |
| 9205 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9206 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9207 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9208 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9209 | wdev_lock(wdev); |
| 9210 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 9211 | |
| 9212 | /* |
| 9213 | * dump_scan will be called multiple times to break up the scan results |
| 9214 | * into multiple messages. It is unlikely that any more bss-es will be |
| 9215 | * expired after the first call, so only call only call this on the |
| 9216 | * first dump_scan invocation. |
| 9217 | */ |
| 9218 | if (start == 0) |
| 9219 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9220 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9221 | cb->seq = rdev->bss_generation; |
| 9222 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9223 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9224 | if (++idx <= start) |
| 9225 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9226 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9227 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9228 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9229 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9230 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9231 | } |
| 9232 | } |
| 9233 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9234 | spin_unlock_bh(&rdev->bss_lock); |
| 9235 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9236 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9237 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9238 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9239 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9240 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9241 | } |
| 9242 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9243 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9244 | int flags, struct net_device *dev, |
| 9245 | bool allow_radio_stats, |
| 9246 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9247 | { |
| 9248 | void *hdr; |
| 9249 | struct nlattr *infoattr; |
| 9250 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9251 | /* skip radio stats if userspace didn't request them */ |
| 9252 | if (!survey->channel && !allow_radio_stats) |
| 9253 | return 0; |
| 9254 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9255 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9256 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 9257 | if (!hdr) |
| 9258 | return -ENOMEM; |
| 9259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9260 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 9261 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9262 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9263 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9264 | if (!infoattr) |
| 9265 | goto nla_put_failure; |
| 9266 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9267 | if (survey->channel && |
| 9268 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9269 | survey->channel->center_freq)) |
| 9270 | goto nla_put_failure; |
| 9271 | |
| 9272 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9273 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9274 | goto nla_put_failure; |
| 9275 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9276 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9277 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9278 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9279 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9280 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9281 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9282 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9283 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9284 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9285 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9286 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9287 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9288 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9289 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9290 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9291 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9292 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9293 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9294 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9295 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9296 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9297 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9298 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9299 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9300 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9301 | goto nla_put_failure; |
Felix Fietkau | c8cd6e7 | 2019-08-28 12:20:42 +0200 | [diff] [blame] | 9302 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9303 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9304 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9305 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9306 | |
| 9307 | nla_nest_end(msg, infoattr); |
| 9308 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9309 | genlmsg_end(msg, hdr); |
| 9310 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9311 | |
| 9312 | nla_put_failure: |
| 9313 | genlmsg_cancel(msg, hdr); |
| 9314 | return -EMSGSIZE; |
| 9315 | } |
| 9316 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9317 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9318 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9319 | struct nlattr **attrbuf; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9320 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9321 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9322 | struct wireless_dev *wdev; |
| 9323 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9324 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9325 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9326 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9327 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9328 | if (!attrbuf) |
| 9329 | return -ENOMEM; |
| 9330 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9331 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9332 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9333 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9334 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9335 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9336 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9337 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9338 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9339 | if (!wdev->netdev) { |
| 9340 | res = -EINVAL; |
| 9341 | goto out_err; |
| 9342 | } |
| 9343 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9344 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9345 | res = -EOPNOTSUPP; |
| 9346 | goto out_err; |
| 9347 | } |
| 9348 | |
| 9349 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9350 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9351 | if (res == -ENOENT) |
| 9352 | break; |
| 9353 | if (res) |
| 9354 | goto out_err; |
| 9355 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9356 | /* don't send disabled channels, but do send non-channel data */ |
| 9357 | if (survey.channel && |
| 9358 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 9359 | survey_idx++; |
| 9360 | continue; |
| 9361 | } |
| 9362 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9363 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9364 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9365 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9366 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9367 | goto out; |
| 9368 | survey_idx++; |
| 9369 | } |
| 9370 | |
| 9371 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9372 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9373 | res = skb->len; |
| 9374 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9375 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9376 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9377 | return res; |
| 9378 | } |
| 9379 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9380 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9381 | { |
| 9382 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
Chung-Hsien Hsu | cc3e14c | 2019-05-09 09:49:05 +0000 | [diff] [blame] | 9383 | NL80211_WPA_VERSION_2 | |
| 9384 | NL80211_WPA_VERSION_3)); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9385 | } |
| 9386 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9387 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9388 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9390 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9391 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9392 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9393 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9394 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9395 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9396 | bool local_state_change; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9397 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9398 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9399 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9400 | return -EINVAL; |
| 9401 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 9402 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9403 | return -EINVAL; |
| 9404 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9405 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9406 | return -EINVAL; |
| 9407 | |
| 9408 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9409 | return -EINVAL; |
| 9410 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9411 | err = nl80211_parse_key(info, &key); |
| 9412 | if (err) |
| 9413 | return err; |
| 9414 | |
| 9415 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 9416 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9417 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9418 | if (!key.p.key || !key.p.key_len) |
| 9419 | return -EINVAL; |
| 9420 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9421 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9422 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9423 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9424 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 9425 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9426 | return -EINVAL; |
| 9427 | } else { |
| 9428 | key.p.key_len = 0; |
| 9429 | key.p.key = NULL; |
| 9430 | } |
| 9431 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9432 | if (key.idx >= 0) { |
| 9433 | int i; |
| 9434 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9435 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9436 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9437 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9438 | ok = true; |
| 9439 | break; |
| 9440 | } |
| 9441 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9442 | if (!ok) |
| 9443 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9444 | } |
| 9445 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9446 | if (!rdev->ops->auth) |
| 9447 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9448 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9450 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9451 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9452 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9453 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9454 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9455 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9456 | freq += |
| 9457 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9458 | |
| 9459 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9460 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9461 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9462 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9463 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9464 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9465 | |
| 9466 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9467 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9468 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9469 | } |
| 9470 | |
| 9471 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9472 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9473 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9474 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9475 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 9476 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 9477 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 9478 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9479 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9480 | return -EINVAL; |
| 9481 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9482 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9483 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 9484 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 9485 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 9486 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9487 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9488 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 9489 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9490 | } |
| 9491 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9492 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9493 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 9494 | /* |
| 9495 | * Since we no longer track auth state, ignore |
| 9496 | * requests to only change local state. |
| 9497 | */ |
| 9498 | if (local_state_change) |
| 9499 | return 0; |
| 9500 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9501 | wdev_lock(dev->ieee80211_ptr); |
| 9502 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 9503 | ssid, ssid_len, ie, ie_len, |
| 9504 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9505 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9506 | wdev_unlock(dev->ieee80211_ptr); |
| 9507 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9508 | } |
| 9509 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9510 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 9511 | struct genl_info *info) |
| 9512 | { |
| 9513 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9514 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 9515 | return -EINVAL; |
| 9516 | } |
| 9517 | |
| 9518 | if (!rdev->ops->tx_control_port || |
| 9519 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9520 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 9521 | return -EOPNOTSUPP; |
| 9522 | |
| 9523 | return 0; |
| 9524 | } |
| 9525 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9526 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 9527 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9528 | struct cfg80211_crypto_settings *settings, |
| 9529 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9530 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 9531 | memset(settings, 0, sizeof(*settings)); |
| 9532 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9533 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 9534 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9535 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 9536 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9537 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9538 | proto = nla_get_u16( |
| 9539 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 9540 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 9541 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 9542 | proto != ETH_P_PAE) |
| 9543 | return -EINVAL; |
| 9544 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 9545 | settings->control_port_no_encrypt = true; |
| 9546 | } else |
| 9547 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 9548 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9549 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9550 | int r = validate_pae_over_nl80211(rdev, info); |
| 9551 | |
| 9552 | if (r < 0) |
| 9553 | return r; |
| 9554 | |
| 9555 | settings->control_port_over_nl80211 = true; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 9556 | |
| 9557 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) |
| 9558 | settings->control_port_no_preauth = true; |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9559 | } |
| 9560 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9561 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 9562 | void *data; |
| 9563 | int len, i; |
| 9564 | |
| 9565 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9566 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9567 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 9568 | |
| 9569 | if (len % sizeof(u32)) |
| 9570 | return -EINVAL; |
| 9571 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9572 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9573 | return -EINVAL; |
| 9574 | |
| 9575 | memcpy(settings->ciphers_pairwise, data, len); |
| 9576 | |
| 9577 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9578 | if (!cfg80211_supported_cipher_suite( |
| 9579 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9580 | settings->ciphers_pairwise[i])) |
| 9581 | return -EINVAL; |
| 9582 | } |
| 9583 | |
| 9584 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 9585 | settings->cipher_group = |
| 9586 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9587 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 9588 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9589 | return -EINVAL; |
| 9590 | } |
| 9591 | |
| 9592 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 9593 | settings->wpa_versions = |
| 9594 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 9595 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 9596 | return -EINVAL; |
| 9597 | } |
| 9598 | |
| 9599 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 9600 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 9601 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9602 | |
| 9603 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9604 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9605 | settings->n_akm_suites = len / sizeof(u32); |
| 9606 | |
| 9607 | if (len % sizeof(u32)) |
| 9608 | return -EINVAL; |
| 9609 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 9610 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 9611 | return -EINVAL; |
| 9612 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9613 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9614 | } |
| 9615 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9616 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9617 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 9618 | return -EINVAL; |
| 9619 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | f966227 | 2020-06-23 08:49:35 -0500 | [diff] [blame] | 9620 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
| 9621 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9622 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9623 | return -EINVAL; |
| 9624 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9625 | } |
| 9626 | |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9627 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 9628 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 9629 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
| 9630 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9631 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9632 | return -EINVAL; |
| 9633 | settings->sae_pwd = |
| 9634 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9635 | settings->sae_pwd_len = |
| 9636 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9637 | } |
| 9638 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9639 | return 0; |
| 9640 | } |
| 9641 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9642 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 9643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9645 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9646 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9647 | struct cfg80211_assoc_request req = {}; |
| 9648 | const u8 *bssid, *ssid; |
| 9649 | int err, ssid_len = 0; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9650 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9651 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9652 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9653 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9654 | return -EPERM; |
| 9655 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9656 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9657 | !info->attrs[NL80211_ATTR_SSID] || |
| 9658 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9659 | return -EINVAL; |
| 9660 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9661 | if (!rdev->ops->assoc) |
| 9662 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9663 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9664 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9665 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9666 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9667 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9668 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9669 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9670 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9671 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9672 | freq += |
| 9673 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9674 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9675 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9676 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9677 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9678 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9679 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9680 | |
| 9681 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9682 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9683 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9684 | } |
| 9685 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9686 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9687 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9688 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9689 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9690 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9691 | else if (mfp != NL80211_MFP_NO) |
| 9692 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9693 | } |
| 9694 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9695 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9696 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9697 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9698 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9699 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9700 | |
| 9701 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9702 | memcpy(&req.ht_capa_mask, |
| 9703 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9704 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9705 | |
| 9706 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9707 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9708 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9709 | memcpy(&req.ht_capa, |
| 9710 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9711 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9712 | } |
| 9713 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9714 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9715 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9716 | |
| 9717 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9718 | memcpy(&req.vht_capa_mask, |
| 9719 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9720 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9721 | |
| 9722 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9723 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9724 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9725 | memcpy(&req.vht_capa, |
| 9726 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9727 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9728 | } |
| 9729 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9730 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9731 | if (!((rdev->wiphy.features & |
| 9732 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9733 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9734 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9735 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9736 | return -EINVAL; |
| 9737 | req.flags |= ASSOC_REQ_USE_RRM; |
| 9738 | } |
| 9739 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 9740 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 9741 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9742 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9743 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 9744 | return -EINVAL; |
| 9745 | req.fils_nonces = |
| 9746 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 9747 | } |
| 9748 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9749 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9750 | if (!err) { |
| 9751 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9752 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9753 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 9754 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9755 | |
| 9756 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9757 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 9758 | info->snd_portid; |
| 9759 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9760 | bssid, ETH_ALEN); |
| 9761 | } |
| 9762 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9763 | wdev_unlock(dev->ieee80211_ptr); |
| 9764 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9765 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9766 | return err; |
| 9767 | } |
| 9768 | |
| 9769 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 9770 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9772 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9773 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9774 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9775 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9776 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9777 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9778 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9779 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9780 | return -EPERM; |
| 9781 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9782 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9783 | return -EINVAL; |
| 9784 | |
| 9785 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9786 | return -EINVAL; |
| 9787 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9788 | if (!rdev->ops->deauth) |
| 9789 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9790 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9791 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9792 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9793 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9794 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9795 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9796 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9797 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9798 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9799 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9800 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9801 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9802 | |
| 9803 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9804 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9805 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9806 | } |
| 9807 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9808 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9809 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9810 | wdev_lock(dev->ieee80211_ptr); |
| 9811 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9812 | local_state_change); |
| 9813 | wdev_unlock(dev->ieee80211_ptr); |
| 9814 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9815 | } |
| 9816 | |
| 9817 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 9818 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9820 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9821 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9822 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9823 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9824 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9825 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9826 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9827 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9828 | return -EPERM; |
| 9829 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9830 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9831 | return -EINVAL; |
| 9832 | |
| 9833 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9834 | return -EINVAL; |
| 9835 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9836 | if (!rdev->ops->disassoc) |
| 9837 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9838 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9839 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9840 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9841 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9842 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9843 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9844 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9845 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9846 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9847 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9848 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9849 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9850 | |
| 9851 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9852 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9853 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9854 | } |
| 9855 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9856 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9857 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9858 | wdev_lock(dev->ieee80211_ptr); |
| 9859 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9860 | local_state_change); |
| 9861 | wdev_unlock(dev->ieee80211_ptr); |
| 9862 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9863 | } |
| 9864 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9865 | static bool |
| 9866 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9867 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9868 | int rateval) |
| 9869 | { |
| 9870 | struct wiphy *wiphy = &rdev->wiphy; |
| 9871 | bool found = false; |
| 9872 | int band, i; |
| 9873 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9874 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9875 | struct ieee80211_supported_band *sband; |
| 9876 | |
| 9877 | sband = wiphy->bands[band]; |
| 9878 | if (!sband) |
| 9879 | continue; |
| 9880 | |
| 9881 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9882 | if (sband->bitrates[i].bitrate == rateval) { |
| 9883 | mcast_rate[band] = i + 1; |
| 9884 | found = true; |
| 9885 | break; |
| 9886 | } |
| 9887 | } |
| 9888 | } |
| 9889 | |
| 9890 | return found; |
| 9891 | } |
| 9892 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9893 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9896 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9897 | struct cfg80211_ibss_params ibss; |
| 9898 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9899 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9900 | int err; |
| 9901 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9902 | memset(&ibss, 0, sizeof(ibss)); |
| 9903 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9904 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9905 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9906 | return -EINVAL; |
| 9907 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9908 | ibss.beacon_interval = 100; |
| 9909 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9910 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9911 | ibss.beacon_interval = |
| 9912 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9913 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9914 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 9915 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9916 | if (err) |
| 9917 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9919 | if (!rdev->ops->join_ibss) |
| 9920 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9921 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9922 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9923 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9924 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9925 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9926 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9927 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9928 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9929 | |
| 9930 | if (!is_valid_ether_addr(ibss.bssid)) |
| 9931 | return -EINVAL; |
| 9932 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9933 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9934 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9935 | |
| 9936 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9937 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9938 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9939 | } |
| 9940 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9941 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 9942 | if (err) |
| 9943 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9944 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 9945 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 9946 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9947 | return -EINVAL; |
| 9948 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9949 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 9950 | case NL80211_CHAN_WIDTH_5: |
| 9951 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9952 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 9953 | break; |
| 9954 | case NL80211_CHAN_WIDTH_20: |
| 9955 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 9956 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9957 | return -EINVAL; |
| 9958 | break; |
| 9959 | case NL80211_CHAN_WIDTH_80: |
| 9960 | case NL80211_CHAN_WIDTH_80P80: |
| 9961 | case NL80211_CHAN_WIDTH_160: |
| 9962 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9963 | return -EINVAL; |
| 9964 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9965 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 9966 | return -EINVAL; |
| 9967 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9968 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9969 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9970 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9971 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9972 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9973 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9974 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9975 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9976 | u8 *rates = |
| 9977 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9978 | int n_rates = |
| 9979 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9980 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9981 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9982 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 9983 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9984 | &ibss.basic_rates); |
| 9985 | if (err) |
| 9986 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9987 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9988 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 9989 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9990 | memcpy(&ibss.ht_capa_mask, |
| 9991 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9992 | sizeof(ibss.ht_capa_mask)); |
| 9993 | |
| 9994 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 9995 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9996 | return -EINVAL; |
| 9997 | memcpy(&ibss.ht_capa, |
| 9998 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9999 | sizeof(ibss.ht_capa)); |
| 10000 | } |
| 10001 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10002 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10003 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 10004 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10005 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10006 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10007 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10008 | bool no_ht = false; |
| 10009 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10010 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10011 | if (IS_ERR(connkeys)) |
| 10012 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10013 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 10014 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 10015 | no_ht) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10016 | kfree_sensitive(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10017 | return -EINVAL; |
| 10018 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10019 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10020 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 10021 | ibss.control_port = |
| 10022 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 10023 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10024 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10025 | int r = validate_pae_over_nl80211(rdev, info); |
| 10026 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10027 | if (r < 0) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10028 | kfree_sensitive(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10029 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10030 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10031 | |
| 10032 | ibss.control_port_over_nl80211 = true; |
| 10033 | } |
| 10034 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 10035 | ibss.userspace_handles_dfs = |
| 10036 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10037 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10038 | wdev_lock(dev->ieee80211_ptr); |
| 10039 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10040 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10041 | kfree_sensitive(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10042 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10043 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10044 | wdev_unlock(dev->ieee80211_ptr); |
| 10045 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10046 | return err; |
| 10047 | } |
| 10048 | |
| 10049 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10052 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10053 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10054 | if (!rdev->ops->leave_ibss) |
| 10055 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10057 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10058 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10060 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10061 | } |
| 10062 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10063 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 10064 | { |
| 10065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10066 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10067 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10068 | u32 nla_rate; |
| 10069 | int err; |
| 10070 | |
| 10071 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 10072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 10073 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10074 | return -EOPNOTSUPP; |
| 10075 | |
| 10076 | if (!rdev->ops->set_mcast_rate) |
| 10077 | return -EOPNOTSUPP; |
| 10078 | |
| 10079 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 10080 | |
| 10081 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 10082 | return -EINVAL; |
| 10083 | |
| 10084 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 10085 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 10086 | return -EINVAL; |
| 10087 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10088 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10089 | |
| 10090 | return err; |
| 10091 | } |
| 10092 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10093 | static struct sk_buff * |
| 10094 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10095 | struct wireless_dev *wdev, int approxlen, |
| 10096 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10097 | enum nl80211_attrs attr, |
| 10098 | const struct nl80211_vendor_cmd_info *info, |
| 10099 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10100 | { |
| 10101 | struct sk_buff *skb; |
| 10102 | void *hdr; |
| 10103 | struct nlattr *data; |
| 10104 | |
| 10105 | skb = nlmsg_new(approxlen + 100, gfp); |
| 10106 | if (!skb) |
| 10107 | return NULL; |
| 10108 | |
| 10109 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 10110 | if (!hdr) { |
| 10111 | kfree_skb(skb); |
| 10112 | return NULL; |
| 10113 | } |
| 10114 | |
| 10115 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10116 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10117 | |
| 10118 | if (info) { |
| 10119 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 10120 | info->vendor_id)) |
| 10121 | goto nla_put_failure; |
| 10122 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 10123 | info->subcmd)) |
| 10124 | goto nla_put_failure; |
| 10125 | } |
| 10126 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10127 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10128 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10129 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10130 | goto nla_put_failure; |
| 10131 | if (wdev->netdev && |
| 10132 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 10133 | wdev->netdev->ifindex)) |
| 10134 | goto nla_put_failure; |
| 10135 | } |
| 10136 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10137 | data = nla_nest_start_noflag(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10138 | if (!data) |
| 10139 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10140 | |
| 10141 | ((void **)skb->cb)[0] = rdev; |
| 10142 | ((void **)skb->cb)[1] = hdr; |
| 10143 | ((void **)skb->cb)[2] = data; |
| 10144 | |
| 10145 | return skb; |
| 10146 | |
| 10147 | nla_put_failure: |
| 10148 | kfree_skb(skb); |
| 10149 | return NULL; |
| 10150 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10151 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10152 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10153 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10154 | enum nl80211_commands cmd, |
| 10155 | enum nl80211_attrs attr, |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10156 | unsigned int portid, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10157 | int vendor_event_idx, |
| 10158 | int approxlen, gfp_t gfp) |
| 10159 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10160 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10161 | const struct nl80211_vendor_cmd_info *info; |
| 10162 | |
| 10163 | switch (cmd) { |
| 10164 | case NL80211_CMD_TESTMODE: |
| 10165 | if (WARN_ON(vendor_event_idx != -1)) |
| 10166 | return NULL; |
| 10167 | info = NULL; |
| 10168 | break; |
| 10169 | case NL80211_CMD_VENDOR: |
| 10170 | if (WARN_ON(vendor_event_idx < 0 || |
| 10171 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 10172 | return NULL; |
| 10173 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 10174 | break; |
| 10175 | default: |
| 10176 | WARN_ON(1); |
| 10177 | return NULL; |
| 10178 | } |
| 10179 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10180 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10181 | cmd, attr, info, gfp); |
| 10182 | } |
| 10183 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 10184 | |
| 10185 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 10186 | { |
| 10187 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10188 | void *hdr = ((void **)skb->cb)[1]; |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10189 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10190 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10191 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 10192 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10193 | /* clear CB data for netlink core to own from now on */ |
| 10194 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10195 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10196 | nla_nest_end(skb, data); |
| 10197 | genlmsg_end(skb, hdr); |
| 10198 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10199 | if (nlhdr->nlmsg_pid) { |
| 10200 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 10201 | nlhdr->nlmsg_pid); |
| 10202 | } else { |
| 10203 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 10204 | mcgrp = NL80211_MCGRP_VENDOR; |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10205 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10206 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 10207 | skb, 0, mcgrp, gfp); |
| 10208 | } |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10209 | } |
| 10210 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 10211 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10212 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10213 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 10214 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10216 | struct wireless_dev *wdev = |
| 10217 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10218 | int err; |
| 10219 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10220 | if (!rdev->ops->testmode_cmd) |
| 10221 | return -EOPNOTSUPP; |
| 10222 | |
| 10223 | if (IS_ERR(wdev)) { |
| 10224 | err = PTR_ERR(wdev); |
| 10225 | if (err != -EINVAL) |
| 10226 | return err; |
| 10227 | wdev = NULL; |
| 10228 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10229 | return -EINVAL; |
| 10230 | } |
| 10231 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10232 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 10233 | return -EINVAL; |
| 10234 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10235 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10236 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10237 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 10238 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10239 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10240 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10241 | return err; |
| 10242 | } |
| 10243 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10244 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 10245 | struct netlink_callback *cb) |
| 10246 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10247 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10248 | struct nlattr **attrbuf = NULL; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10249 | int err; |
| 10250 | long phy_idx; |
| 10251 | void *data = NULL; |
| 10252 | int data_len = 0; |
| 10253 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10254 | rtnl_lock(); |
| 10255 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10256 | if (cb->args[0]) { |
| 10257 | /* |
| 10258 | * 0 is a valid index, but not valid for args[0], |
| 10259 | * so we need to offset by 1. |
| 10260 | */ |
| 10261 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 10262 | |
| 10263 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 10264 | if (!rdev) { |
| 10265 | err = -ENOENT; |
| 10266 | goto out_err; |
| 10267 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10268 | } else { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10269 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 10270 | GFP_KERNEL); |
| 10271 | if (!attrbuf) { |
| 10272 | err = -ENOMEM; |
| 10273 | goto out_err; |
| 10274 | } |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10275 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 10276 | err = nlmsg_parse_deprecated(cb->nlh, |
| 10277 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10278 | attrbuf, nl80211_fam.maxattr, |
| 10279 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10280 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10281 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10282 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10283 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10284 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10285 | err = PTR_ERR(rdev); |
| 10286 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10287 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10288 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10289 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10290 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10291 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10292 | } |
| 10293 | |
| 10294 | if (cb->args[1]) { |
| 10295 | data = nla_data((void *)cb->args[1]); |
| 10296 | data_len = nla_len((void *)cb->args[1]); |
| 10297 | } |
| 10298 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10299 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10300 | err = -EOPNOTSUPP; |
| 10301 | goto out_err; |
| 10302 | } |
| 10303 | |
| 10304 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10305 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10306 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10307 | NL80211_CMD_TESTMODE); |
| 10308 | struct nlattr *tmdata; |
| 10309 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10310 | if (!hdr) |
| 10311 | break; |
| 10312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10313 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10314 | genlmsg_cancel(skb, hdr); |
| 10315 | break; |
| 10316 | } |
| 10317 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10318 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10319 | if (!tmdata) { |
| 10320 | genlmsg_cancel(skb, hdr); |
| 10321 | break; |
| 10322 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10323 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10324 | nla_nest_end(skb, tmdata); |
| 10325 | |
| 10326 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10327 | genlmsg_cancel(skb, hdr); |
| 10328 | break; |
| 10329 | } else if (err) { |
| 10330 | genlmsg_cancel(skb, hdr); |
| 10331 | goto out_err; |
| 10332 | } |
| 10333 | |
| 10334 | genlmsg_end(skb, hdr); |
| 10335 | } |
| 10336 | |
| 10337 | err = skb->len; |
| 10338 | /* see above */ |
| 10339 | cb->args[0] = phy_idx + 1; |
| 10340 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10341 | kfree(attrbuf); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10342 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10343 | return err; |
| 10344 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10345 | #endif |
| 10346 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10347 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10348 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10350 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10351 | struct cfg80211_connect_params connect; |
| 10352 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10353 | struct cfg80211_cached_keys *connkeys = NULL; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10354 | u32 freq = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10355 | int err; |
| 10356 | |
| 10357 | memset(&connect, 0, sizeof(connect)); |
| 10358 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10359 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10360 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10361 | return -EINVAL; |
| 10362 | |
| 10363 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10364 | connect.auth_type = |
| 10365 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10366 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10367 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10368 | return -EINVAL; |
| 10369 | } else |
| 10370 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10371 | |
| 10372 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10373 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 10374 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10375 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10376 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10377 | return -EINVAL; |
| 10378 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10379 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10380 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10381 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10382 | if (err) |
| 10383 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10384 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10386 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10387 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10388 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10389 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10390 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 10391 | connect.bg_scan_period = -1; |
| 10392 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10393 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10394 | connect.bg_scan_period = |
| 10395 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10396 | } |
| 10397 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10398 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10399 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10400 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10401 | connect.bssid_hint = |
| 10402 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10403 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10404 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10405 | |
| 10406 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10407 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10408 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10409 | } |
| 10410 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10411 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10412 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 10413 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10414 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10415 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10416 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10417 | } else { |
| 10418 | connect.mfp = NL80211_MFP_NO; |
| 10419 | } |
| 10420 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 10421 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10422 | connect.prev_bssid = |
| 10423 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10424 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10425 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10426 | freq = MHZ_TO_KHZ(nla_get_u32( |
| 10427 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10428 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10429 | freq += |
| 10430 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10431 | |
| 10432 | if (freq) { |
| 10433 | connect.channel = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10434 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10435 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10436 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10437 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10438 | freq = MHZ_TO_KHZ(freq); |
| 10439 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10440 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10441 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10442 | } |
| 10443 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 10444 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 10445 | connect.edmg.channels = |
| 10446 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 10447 | |
| 10448 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 10449 | connect.edmg.bw_config = |
| 10450 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 10451 | } |
| 10452 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10453 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10454 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10455 | if (IS_ERR(connkeys)) |
| 10456 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10457 | } |
| 10458 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10459 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 10460 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 10461 | |
| 10462 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10463 | memcpy(&connect.ht_capa_mask, |
| 10464 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10465 | sizeof(connect.ht_capa_mask)); |
| 10466 | |
| 10467 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10468 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10469 | kfree_sensitive(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10470 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10471 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10472 | memcpy(&connect.ht_capa, |
| 10473 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10474 | sizeof(connect.ht_capa)); |
| 10475 | } |
| 10476 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10477 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 10478 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 10479 | |
| 10480 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 10481 | memcpy(&connect.vht_capa_mask, |
| 10482 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10483 | sizeof(connect.vht_capa_mask)); |
| 10484 | |
| 10485 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 10486 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10487 | kfree_sensitive(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10488 | return -EINVAL; |
| 10489 | } |
| 10490 | memcpy(&connect.vht_capa, |
| 10491 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10492 | sizeof(connect.vht_capa)); |
| 10493 | } |
| 10494 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10495 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 10496 | if (!((rdev->wiphy.features & |
| 10497 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10498 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10499 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10500 | NL80211_EXT_FEATURE_RRM)) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10501 | kfree_sensitive(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10502 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 10503 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10504 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 10505 | } |
| 10506 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10507 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10508 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10509 | kfree_sensitive(connkeys); |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10510 | return -EOPNOTSUPP; |
| 10511 | } |
| 10512 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10513 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 10514 | /* bss selection makes no sense if bssid is set */ |
| 10515 | if (connect.bssid) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10516 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10517 | return -EINVAL; |
| 10518 | } |
| 10519 | |
| 10520 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 10521 | wiphy, &connect.bss_select); |
| 10522 | if (err) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10523 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10524 | return err; |
| 10525 | } |
| 10526 | } |
| 10527 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10528 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 10529 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10530 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10531 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10532 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10533 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10534 | connect.fils_erp_username = |
| 10535 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10536 | connect.fils_erp_username_len = |
| 10537 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10538 | connect.fils_erp_realm = |
| 10539 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10540 | connect.fils_erp_realm_len = |
| 10541 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10542 | connect.fils_erp_next_seq_num = |
| 10543 | nla_get_u16( |
| 10544 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10545 | connect.fils_erp_rrk = |
| 10546 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10547 | connect.fils_erp_rrk_len = |
| 10548 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10549 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10550 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10551 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10552 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10553 | kfree_sensitive(connkeys); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10554 | return -EINVAL; |
| 10555 | } |
| 10556 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10557 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 10558 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10559 | kfree_sensitive(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10560 | GENL_SET_ERR_MSG(info, |
| 10561 | "external auth requires connection ownership"); |
| 10562 | return -EINVAL; |
| 10563 | } |
| 10564 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 10565 | } |
| 10566 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10567 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10568 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 10569 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 10570 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10571 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10572 | kfree_sensitive(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10573 | |
| 10574 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10575 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10576 | if (connect.bssid) |
| 10577 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10578 | connect.bssid, ETH_ALEN); |
| 10579 | else |
Miaohe Lin | 3b1648f | 2020-08-01 17:15:49 +0800 | [diff] [blame] | 10580 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10581 | } |
| 10582 | |
| 10583 | wdev_unlock(dev->ieee80211_ptr); |
| 10584 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10585 | return err; |
| 10586 | } |
| 10587 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10588 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 10589 | struct genl_info *info) |
| 10590 | { |
| 10591 | struct cfg80211_connect_params connect = {}; |
| 10592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10593 | struct net_device *dev = info->user_ptr[1]; |
| 10594 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10595 | bool fils_sk_offload; |
| 10596 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10597 | u32 changed = 0; |
| 10598 | int ret; |
| 10599 | |
| 10600 | if (!rdev->ops->update_connect_params) |
| 10601 | return -EOPNOTSUPP; |
| 10602 | |
| 10603 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10604 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10605 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10606 | changed |= UPDATE_ASSOC_IES; |
| 10607 | } |
| 10608 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10609 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 10610 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 10611 | |
| 10612 | /* |
| 10613 | * when driver supports fils-sk offload all attributes must be |
| 10614 | * provided. So the else covers "fils-sk-not-all" and |
| 10615 | * "no-fils-sk-any". |
| 10616 | */ |
| 10617 | if (fils_sk_offload && |
| 10618 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10619 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10620 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10621 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10622 | connect.fils_erp_username = |
| 10623 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10624 | connect.fils_erp_username_len = |
| 10625 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10626 | connect.fils_erp_realm = |
| 10627 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10628 | connect.fils_erp_realm_len = |
| 10629 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10630 | connect.fils_erp_next_seq_num = |
| 10631 | nla_get_u16( |
| 10632 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10633 | connect.fils_erp_rrk = |
| 10634 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10635 | connect.fils_erp_rrk_len = |
| 10636 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10637 | changed |= UPDATE_FILS_ERP_INFO; |
| 10638 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10639 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10640 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10641 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10642 | return -EINVAL; |
| 10643 | } |
| 10644 | |
| 10645 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10646 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10647 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 10648 | NL80211_CMD_CONNECT)) |
| 10649 | return -EINVAL; |
| 10650 | |
| 10651 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 10652 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 10653 | return -EINVAL; |
| 10654 | |
| 10655 | connect.auth_type = auth_type; |
| 10656 | changed |= UPDATE_AUTH_TYPE; |
| 10657 | } |
| 10658 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10659 | wdev_lock(dev->ieee80211_ptr); |
| 10660 | if (!wdev->current_bss) |
| 10661 | ret = -ENOLINK; |
| 10662 | else |
| 10663 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 10664 | wdev_unlock(dev->ieee80211_ptr); |
| 10665 | |
| 10666 | return ret; |
| 10667 | } |
| 10668 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10669 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 10670 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10672 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10673 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10674 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10675 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10676 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10677 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10678 | return -EPERM; |
| 10679 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10680 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10681 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 10682 | else |
| 10683 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10684 | |
| 10685 | if (reason == 0) |
| 10686 | return -EINVAL; |
| 10687 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10688 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10689 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10690 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10691 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10692 | wdev_lock(dev->ieee80211_ptr); |
| 10693 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 10694 | wdev_unlock(dev->ieee80211_ptr); |
| 10695 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10696 | } |
| 10697 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10698 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 10699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10701 | struct net *net; |
| 10702 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10703 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10704 | if (info->attrs[NL80211_ATTR_PID]) { |
| 10705 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 10706 | |
| 10707 | net = get_net_ns_by_pid(pid); |
| 10708 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 10709 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 10710 | |
| 10711 | net = get_net_ns_by_fd(fd); |
| 10712 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10713 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10714 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10716 | if (IS_ERR(net)) |
| 10717 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10718 | |
| 10719 | err = 0; |
| 10720 | |
| 10721 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10722 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 10723 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10724 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10725 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10726 | return err; |
| 10727 | } |
| 10728 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10729 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10730 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10732 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 10733 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10734 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10735 | struct cfg80211_pmksa pmksa; |
| 10736 | |
| 10737 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 10738 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10739 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 10740 | return -EINVAL; |
| 10741 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10742 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10743 | |
| 10744 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10745 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10746 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 10747 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 10748 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 10749 | info->attrs[NL80211_ATTR_PMK])) { |
| 10750 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10751 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10752 | pmksa.cache_id = |
| 10753 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 10754 | } else { |
| 10755 | return -EINVAL; |
| 10756 | } |
| 10757 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10758 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10759 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 10760 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10761 | |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 10762 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
| 10763 | pmksa.pmk_lifetime = |
| 10764 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); |
| 10765 | |
| 10766 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) |
| 10767 | pmksa.pmk_reauth_threshold = |
| 10768 | nla_get_u8( |
| 10769 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); |
| 10770 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10771 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Liangwei Dong | 6c90036 | 2019-01-18 16:54:38 +0530 | [diff] [blame] | 10772 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 10773 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 10774 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 10775 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10776 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10777 | |
| 10778 | switch (info->genlhdr->cmd) { |
| 10779 | case NL80211_CMD_SET_PMKSA: |
| 10780 | rdev_ops = rdev->ops->set_pmksa; |
| 10781 | break; |
| 10782 | case NL80211_CMD_DEL_PMKSA: |
| 10783 | rdev_ops = rdev->ops->del_pmksa; |
| 10784 | break; |
| 10785 | default: |
| 10786 | WARN_ON(1); |
| 10787 | break; |
| 10788 | } |
| 10789 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10790 | if (!rdev_ops) |
| 10791 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10793 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10794 | } |
| 10795 | |
| 10796 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10797 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10798 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10799 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10800 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10801 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10802 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10803 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10805 | if (!rdev->ops->flush_pmksa) |
| 10806 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10807 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10808 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10809 | } |
| 10810 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10811 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 10812 | { |
| 10813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10814 | struct net_device *dev = info->user_ptr[1]; |
| 10815 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10816 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10817 | u16 status_code; |
| 10818 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10819 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10820 | |
| 10821 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10822 | !rdev->ops->tdls_mgmt) |
| 10823 | return -EOPNOTSUPP; |
| 10824 | |
| 10825 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 10826 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 10827 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 10828 | !info->attrs[NL80211_ATTR_IE] || |
| 10829 | !info->attrs[NL80211_ATTR_MAC]) |
| 10830 | return -EINVAL; |
| 10831 | |
| 10832 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10833 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 10834 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 10835 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10836 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10837 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 10838 | peer_capability = |
| 10839 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10840 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10841 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10842 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10843 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10844 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 10845 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10846 | } |
| 10847 | |
| 10848 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 10849 | { |
| 10850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10851 | struct net_device *dev = info->user_ptr[1]; |
| 10852 | enum nl80211_tdls_operation operation; |
| 10853 | u8 *peer; |
| 10854 | |
| 10855 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10856 | !rdev->ops->tdls_oper) |
| 10857 | return -EOPNOTSUPP; |
| 10858 | |
| 10859 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 10860 | !info->attrs[NL80211_ATTR_MAC]) |
| 10861 | return -EINVAL; |
| 10862 | |
| 10863 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 10864 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10865 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10866 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10867 | } |
| 10868 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10869 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 10870 | struct genl_info *info) |
| 10871 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10873 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10874 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10875 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10876 | struct sk_buff *msg; |
| 10877 | void *hdr; |
| 10878 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10879 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10880 | int err; |
| 10881 | |
| 10882 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10883 | !info->attrs[NL80211_ATTR_DURATION]) |
| 10884 | return -EINVAL; |
| 10885 | |
| 10886 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 10887 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10888 | if (!rdev->ops->remain_on_channel || |
| 10889 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10890 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10891 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10892 | /* |
| 10893 | * We should be on that channel for at least a minimum amount of |
| 10894 | * time (10ms) but no longer than the driver supports. |
| 10895 | */ |
| 10896 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10897 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 10898 | return -EINVAL; |
| 10899 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10900 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10901 | if (err) |
| 10902 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10903 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10904 | wdev_lock(wdev); |
| 10905 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 10906 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 10907 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 10908 | &chandef); |
| 10909 | if (compat_chandef != &chandef) { |
| 10910 | wdev_unlock(wdev); |
| 10911 | return -EBUSY; |
| 10912 | } |
| 10913 | } |
| 10914 | wdev_unlock(wdev); |
| 10915 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10916 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10917 | if (!msg) |
| 10918 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10919 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10920 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10921 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10922 | if (!hdr) { |
| 10923 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10924 | goto free_msg; |
| 10925 | } |
| 10926 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10927 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 10928 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10929 | |
| 10930 | if (err) |
| 10931 | goto free_msg; |
| 10932 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10933 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10934 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10935 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10936 | |
| 10937 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10938 | |
| 10939 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10940 | |
| 10941 | nla_put_failure: |
| 10942 | err = -ENOBUFS; |
| 10943 | free_msg: |
| 10944 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10945 | return err; |
| 10946 | } |
| 10947 | |
| 10948 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 10949 | struct genl_info *info) |
| 10950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10952 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10953 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10954 | |
| 10955 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10956 | return -EINVAL; |
| 10957 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10958 | if (!rdev->ops->cancel_remain_on_channel) |
| 10959 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10960 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10961 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10962 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10963 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10964 | } |
| 10965 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10966 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 10967 | struct genl_info *info) |
| 10968 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10969 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10971 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10972 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10973 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10974 | if (!rdev->ops->set_bitrate_mask) |
| 10975 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10976 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 10977 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 10978 | NL80211_ATTR_TX_RATES, &mask, |
| 10979 | dev); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10980 | if (err) |
| 10981 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 10982 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10983 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10984 | } |
| 10985 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10986 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10987 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10989 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10990 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10991 | |
| 10992 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 10993 | return -EINVAL; |
| 10994 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10995 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 10996 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10997 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10998 | switch (wdev->iftype) { |
| 10999 | case NL80211_IFTYPE_STATION: |
| 11000 | case NL80211_IFTYPE_ADHOC: |
| 11001 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11002 | case NL80211_IFTYPE_AP: |
| 11003 | case NL80211_IFTYPE_AP_VLAN: |
| 11004 | case NL80211_IFTYPE_MESH_POINT: |
| 11005 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11006 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11007 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11008 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11009 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11010 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11011 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11012 | |
| 11013 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11014 | if (!rdev->ops->mgmt_tx) |
| 11015 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11016 | |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11017 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
| 11018 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 11019 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { |
| 11020 | GENL_SET_ERR_MSG(info, |
| 11021 | "multicast RX registrations are not supported"); |
| 11022 | return -EOPNOTSUPP; |
| 11023 | } |
| 11024 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11025 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11026 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 11027 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11028 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11029 | info->extack); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11030 | } |
| 11031 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11032 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11033 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11035 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11036 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11037 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 11038 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11039 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11040 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11041 | struct cfg80211_mgmt_tx_params params = { |
| 11042 | .dont_wait_for_ack = |
| 11043 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 11044 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11045 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11046 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11047 | return -EINVAL; |
| 11048 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11049 | if (!rdev->ops->mgmt_tx) |
| 11050 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11051 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11052 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11053 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11054 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 11055 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11056 | case NL80211_IFTYPE_STATION: |
| 11057 | case NL80211_IFTYPE_ADHOC: |
| 11058 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11059 | case NL80211_IFTYPE_AP: |
| 11060 | case NL80211_IFTYPE_AP_VLAN: |
| 11061 | case NL80211_IFTYPE_MESH_POINT: |
| 11062 | case NL80211_IFTYPE_P2P_GO: |
| 11063 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11064 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11065 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11066 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11067 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11068 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11069 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11070 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11071 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11072 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11073 | |
| 11074 | /* |
| 11075 | * We should wait on the channel for at least a minimum amount |
| 11076 | * of time (10ms) but no longer than the driver supports. |
| 11077 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11078 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11079 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11080 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11081 | } |
| 11082 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11083 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11084 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11085 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11086 | return -EINVAL; |
| 11087 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11088 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 11089 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11090 | /* get the channel if any has been specified, otherwise pass NULL to |
| 11091 | * the driver. The latter will use the current one |
| 11092 | */ |
| 11093 | chandef.chan = NULL; |
| 11094 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 11095 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11096 | if (err) |
| 11097 | return err; |
| 11098 | } |
| 11099 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11100 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11101 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11102 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11103 | wdev_lock(wdev); |
| 11104 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 11105 | wdev_unlock(wdev); |
| 11106 | return -EBUSY; |
| 11107 | } |
| 11108 | wdev_unlock(wdev); |
| 11109 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 11110 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 11111 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 11112 | |
| 11113 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 11114 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11115 | int i; |
| 11116 | |
| 11117 | if (len % sizeof(u16)) |
| 11118 | return -EINVAL; |
| 11119 | |
| 11120 | params.n_csa_offsets = len / sizeof(u16); |
| 11121 | params.csa_offsets = |
| 11122 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11123 | |
| 11124 | /* check that all the offsets fit the frame */ |
| 11125 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 11126 | if (params.csa_offsets[i] >= params.len) |
| 11127 | return -EINVAL; |
| 11128 | } |
| 11129 | } |
| 11130 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11131 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11132 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11133 | if (!msg) |
| 11134 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11135 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11136 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11137 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11138 | if (!hdr) { |
| 11139 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11140 | goto free_msg; |
| 11141 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11142 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11143 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11144 | params.chan = chandef.chan; |
| 11145 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11146 | if (err) |
| 11147 | goto free_msg; |
| 11148 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11149 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11150 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11151 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11152 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11153 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11154 | genlmsg_end(msg, hdr); |
| 11155 | return genlmsg_reply(msg, info); |
| 11156 | } |
| 11157 | |
| 11158 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11159 | |
| 11160 | nla_put_failure: |
| 11161 | err = -ENOBUFS; |
| 11162 | free_msg: |
| 11163 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11164 | return err; |
| 11165 | } |
| 11166 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11167 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 11168 | { |
| 11169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11170 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11171 | u64 cookie; |
| 11172 | |
| 11173 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11174 | return -EINVAL; |
| 11175 | |
| 11176 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 11177 | return -EOPNOTSUPP; |
| 11178 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11179 | switch (wdev->iftype) { |
| 11180 | case NL80211_IFTYPE_STATION: |
| 11181 | case NL80211_IFTYPE_ADHOC: |
| 11182 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11183 | case NL80211_IFTYPE_AP: |
| 11184 | case NL80211_IFTYPE_AP_VLAN: |
| 11185 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11186 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11187 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11188 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11189 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11190 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11191 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11192 | |
| 11193 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11194 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11195 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11196 | } |
| 11197 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11198 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11199 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11201 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11202 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11203 | u8 ps_state; |
| 11204 | bool state; |
| 11205 | int err; |
| 11206 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11207 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 11208 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11209 | |
| 11210 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 11211 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11212 | wdev = dev->ieee80211_ptr; |
| 11213 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11214 | if (!rdev->ops->set_power_mgmt) |
| 11215 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11216 | |
| 11217 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 11218 | |
| 11219 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11220 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11221 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11222 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11223 | if (!err) |
| 11224 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11225 | return err; |
| 11226 | } |
| 11227 | |
| 11228 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11231 | enum nl80211_ps_state ps_state; |
| 11232 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11233 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11234 | struct sk_buff *msg; |
| 11235 | void *hdr; |
| 11236 | int err; |
| 11237 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11238 | wdev = dev->ieee80211_ptr; |
| 11239 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11240 | if (!rdev->ops->set_power_mgmt) |
| 11241 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11242 | |
| 11243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11244 | if (!msg) |
| 11245 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11246 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11247 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11248 | NL80211_CMD_GET_POWER_SAVE); |
| 11249 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11250 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11251 | goto free_msg; |
| 11252 | } |
| 11253 | |
| 11254 | if (wdev->ps) |
| 11255 | ps_state = NL80211_PS_ENABLED; |
| 11256 | else |
| 11257 | ps_state = NL80211_PS_DISABLED; |
| 11258 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11259 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 11260 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11261 | |
| 11262 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11263 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11265 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11266 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11267 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11268 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11269 | return err; |
| 11270 | } |
| 11271 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 11272 | static const struct nla_policy |
| 11273 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11274 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11275 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 11276 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11277 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 11278 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 11279 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 11280 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11281 | }; |
| 11282 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11283 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11284 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11285 | { |
| 11286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11287 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11288 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11289 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11290 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11291 | return -EINVAL; |
| 11292 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11293 | if (!rdev->ops->set_cqm_txe_config) |
| 11294 | return -EOPNOTSUPP; |
| 11295 | |
| 11296 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11297 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11298 | return -EOPNOTSUPP; |
| 11299 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11300 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11301 | } |
| 11302 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11303 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 11304 | struct net_device *dev) |
| 11305 | { |
| 11306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11307 | s32 last, low, high; |
| 11308 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11309 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11310 | int err; |
| 11311 | |
| 11312 | /* RSSI reporting disabled? */ |
| 11313 | if (!wdev->cqm_config) |
| 11314 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11315 | |
| 11316 | /* |
| 11317 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11318 | * event has been received yet, we should receive an event after a |
| 11319 | * connection is established and enough beacons received to calculate |
| 11320 | * the average. |
| 11321 | */ |
| 11322 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11323 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11324 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11325 | u8 *mac_addr; |
| 11326 | |
| 11327 | mac_addr = wdev->current_bss->pub.bssid; |
| 11328 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11329 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11330 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11331 | return err; |
| 11332 | |
Felix Fietkau | df16737 | 2020-01-08 18:06:30 +0100 | [diff] [blame] | 11333 | cfg80211_sinfo_release_content(&sinfo); |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 11334 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11335 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11336 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11337 | } |
| 11338 | |
| 11339 | last = wdev->cqm_config->last_rssi_event_value; |
| 11340 | hyst = wdev->cqm_config->rssi_hyst; |
| 11341 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11342 | |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11343 | for (i = 0; i < n; i++) { |
| 11344 | i = array_index_nospec(i, n); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11345 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11346 | break; |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11347 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11348 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11349 | low_index = i - 1; |
| 11350 | if (low_index >= 0) { |
| 11351 | low_index = array_index_nospec(low_index, n); |
| 11352 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11353 | } else { |
| 11354 | low = S32_MIN; |
| 11355 | } |
| 11356 | if (i < n) { |
| 11357 | i = array_index_nospec(i, n); |
| 11358 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11359 | } else { |
| 11360 | high = S32_MAX; |
| 11361 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11362 | |
| 11363 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11364 | } |
| 11365 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11366 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11367 | const s32 *thresholds, int n_thresholds, |
| 11368 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11369 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11372 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11373 | int i, err; |
| 11374 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11375 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11376 | /* Check all values negative and sorted */ |
| 11377 | for (i = 0; i < n_thresholds; i++) { |
| 11378 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11379 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11380 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11381 | prev = thresholds[i]; |
| 11382 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11383 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11384 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11385 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11386 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11387 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11388 | wdev_lock(wdev); |
| 11389 | cfg80211_cqm_config_free(wdev); |
| 11390 | wdev_unlock(wdev); |
| 11391 | |
| 11392 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11393 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11394 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11395 | |
| 11396 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11397 | thresholds[0], hysteresis); |
| 11398 | } |
| 11399 | |
| 11400 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11401 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11402 | return -EOPNOTSUPP; |
| 11403 | |
| 11404 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11405 | n_thresholds = 0; |
| 11406 | |
| 11407 | wdev_lock(wdev); |
| 11408 | if (n_thresholds) { |
| 11409 | struct cfg80211_cqm_config *cqm_config; |
| 11410 | |
| 11411 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 11412 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 11413 | if (!cqm_config) { |
| 11414 | err = -ENOMEM; |
| 11415 | goto unlock; |
| 11416 | } |
| 11417 | |
| 11418 | cqm_config->rssi_hyst = hysteresis; |
| 11419 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11420 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 11421 | n_thresholds * sizeof(s32)); |
| 11422 | |
| 11423 | wdev->cqm_config = cqm_config; |
| 11424 | } |
| 11425 | |
| 11426 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11427 | |
| 11428 | unlock: |
| 11429 | wdev_unlock(wdev); |
| 11430 | |
| 11431 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11432 | } |
| 11433 | |
| 11434 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11435 | { |
| 11436 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11437 | struct nlattr *cqm; |
| 11438 | int err; |
| 11439 | |
| 11440 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11441 | if (!cqm) |
| 11442 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11443 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11444 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 11445 | nl80211_attr_cqm_policy, |
| 11446 | info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11447 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11448 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11449 | |
| 11450 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 11451 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11452 | const s32 *thresholds = |
| 11453 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11454 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11455 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11456 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11457 | if (len % 4) |
| 11458 | return -EINVAL; |
| 11459 | |
| 11460 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 11461 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11462 | } |
| 11463 | |
| 11464 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 11465 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 11466 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 11467 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 11468 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 11469 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 11470 | |
| 11471 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 11472 | } |
| 11473 | |
| 11474 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11475 | } |
| 11476 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11477 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11478 | { |
| 11479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11480 | struct net_device *dev = info->user_ptr[1]; |
| 11481 | struct ocb_setup setup = {}; |
| 11482 | int err; |
| 11483 | |
| 11484 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11485 | if (err) |
| 11486 | return err; |
| 11487 | |
| 11488 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 11489 | } |
| 11490 | |
| 11491 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11492 | { |
| 11493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11494 | struct net_device *dev = info->user_ptr[1]; |
| 11495 | |
| 11496 | return cfg80211_leave_ocb(rdev, dev); |
| 11497 | } |
| 11498 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11499 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11500 | { |
| 11501 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11502 | struct net_device *dev = info->user_ptr[1]; |
| 11503 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11504 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11505 | int err; |
| 11506 | |
| 11507 | /* start with default */ |
| 11508 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11509 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11510 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11511 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11512 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11513 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11514 | if (err) |
| 11515 | return err; |
| 11516 | } |
| 11517 | |
| 11518 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 11519 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 11520 | return -EINVAL; |
| 11521 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11522 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11523 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11524 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 11525 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 11526 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 11527 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 11528 | return -EINVAL; |
| 11529 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11530 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 11531 | setup.beacon_interval = |
| 11532 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11533 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 11534 | err = cfg80211_validate_beacon_int(rdev, |
| 11535 | NL80211_IFTYPE_MESH_POINT, |
| 11536 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11537 | if (err) |
| 11538 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11539 | } |
| 11540 | |
| 11541 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 11542 | setup.dtim_period = |
| 11543 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 11544 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 11545 | return -EINVAL; |
| 11546 | } |
| 11547 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11548 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 11549 | /* parse additional setup parameters if given */ |
| 11550 | err = nl80211_parse_mesh_setup(info, &setup); |
| 11551 | if (err) |
| 11552 | return err; |
| 11553 | } |
| 11554 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 11555 | if (setup.user_mpm) |
| 11556 | cfg.auto_open_plinks = false; |
| 11557 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11558 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11559 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11560 | if (err) |
| 11561 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11562 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11563 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11564 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11565 | } |
| 11566 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 11567 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 11568 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11569 | int n_rates = |
| 11570 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11571 | struct ieee80211_supported_band *sband; |
| 11572 | |
| 11573 | if (!setup.chandef.chan) |
| 11574 | return -EINVAL; |
| 11575 | |
| 11576 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 11577 | |
| 11578 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 11579 | &setup.basic_rates); |
| 11580 | if (err) |
| 11581 | return err; |
| 11582 | } |
| 11583 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11584 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 11585 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 11586 | NL80211_ATTR_TX_RATES, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 11587 | &setup.beacon_rate, |
| 11588 | dev); |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11589 | if (err) |
| 11590 | return err; |
| 11591 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 11592 | if (!setup.chandef.chan) |
| 11593 | return -EINVAL; |
| 11594 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11595 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 11596 | &setup.beacon_rate); |
| 11597 | if (err) |
| 11598 | return err; |
| 11599 | } |
| 11600 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 11601 | setup.userspace_handles_dfs = |
| 11602 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 11603 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 11604 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 11605 | int r = validate_pae_over_nl80211(rdev, info); |
| 11606 | |
| 11607 | if (r < 0) |
| 11608 | return r; |
| 11609 | |
| 11610 | setup.control_port_over_nl80211 = true; |
| 11611 | } |
| 11612 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11613 | wdev_lock(dev->ieee80211_ptr); |
| 11614 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 11615 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 11616 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11617 | wdev_unlock(dev->ieee80211_ptr); |
| 11618 | |
| 11619 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11620 | } |
| 11621 | |
| 11622 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11623 | { |
| 11624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11625 | struct net_device *dev = info->user_ptr[1]; |
| 11626 | |
| 11627 | return cfg80211_leave_mesh(rdev, dev); |
| 11628 | } |
| 11629 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11630 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11631 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 11632 | struct cfg80211_registered_device *rdev) |
| 11633 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11634 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11635 | struct nlattr *nl_pats, *nl_pat; |
| 11636 | int i, pat_len; |
| 11637 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11638 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11639 | return 0; |
| 11640 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11641 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11642 | if (!nl_pats) |
| 11643 | return -ENOBUFS; |
| 11644 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11645 | for (i = 0; i < wowlan->n_patterns; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11646 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11647 | if (!nl_pat) |
| 11648 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11649 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11650 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11651 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11652 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11653 | wowlan->patterns[i].pattern) || |
| 11654 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11655 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11656 | return -ENOBUFS; |
| 11657 | nla_nest_end(msg, nl_pat); |
| 11658 | } |
| 11659 | nla_nest_end(msg, nl_pats); |
| 11660 | |
| 11661 | return 0; |
| 11662 | } |
| 11663 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11664 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 11665 | struct cfg80211_wowlan_tcp *tcp) |
| 11666 | { |
| 11667 | struct nlattr *nl_tcp; |
| 11668 | |
| 11669 | if (!tcp) |
| 11670 | return 0; |
| 11671 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11672 | nl_tcp = nla_nest_start_noflag(msg, |
| 11673 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11674 | if (!nl_tcp) |
| 11675 | return -ENOBUFS; |
| 11676 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 11677 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 11678 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11679 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 11680 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 11681 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 11682 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 11683 | tcp->payload_len, tcp->payload) || |
| 11684 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 11685 | tcp->data_interval) || |
| 11686 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 11687 | tcp->wake_len, tcp->wake_data) || |
| 11688 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 11689 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 11690 | return -ENOBUFS; |
| 11691 | |
| 11692 | if (tcp->payload_seq.len && |
| 11693 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 11694 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 11695 | return -ENOBUFS; |
| 11696 | |
| 11697 | if (tcp->payload_tok.len && |
| 11698 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 11699 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 11700 | &tcp->payload_tok)) |
| 11701 | return -ENOBUFS; |
| 11702 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 11703 | nla_nest_end(msg, nl_tcp); |
| 11704 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11705 | return 0; |
| 11706 | } |
| 11707 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11708 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 11709 | struct cfg80211_sched_scan_request *req) |
| 11710 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11711 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11712 | int i; |
| 11713 | |
| 11714 | if (!req) |
| 11715 | return 0; |
| 11716 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11717 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11718 | if (!nd) |
| 11719 | return -ENOBUFS; |
| 11720 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11721 | if (req->n_scan_plans == 1 && |
| 11722 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 11723 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11724 | return -ENOBUFS; |
| 11725 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 11726 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 11727 | return -ENOBUFS; |
| 11728 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 11729 | if (req->relative_rssi_set) { |
| 11730 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 11731 | |
| 11732 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 11733 | req->relative_rssi)) |
| 11734 | return -ENOBUFS; |
| 11735 | |
| 11736 | rssi_adjust.band = req->rssi_adjust.band; |
| 11737 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 11738 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 11739 | sizeof(rssi_adjust), &rssi_adjust)) |
| 11740 | return -ENOBUFS; |
| 11741 | } |
| 11742 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11743 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11744 | if (!freqs) |
| 11745 | return -ENOBUFS; |
| 11746 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11747 | for (i = 0; i < req->n_channels; i++) { |
| 11748 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11749 | return -ENOBUFS; |
| 11750 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11751 | |
| 11752 | nla_nest_end(msg, freqs); |
| 11753 | |
| 11754 | if (req->n_match_sets) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11755 | matches = nla_nest_start_noflag(msg, |
| 11756 | NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11757 | if (!matches) |
| 11758 | return -ENOBUFS; |
| 11759 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11760 | for (i = 0; i < req->n_match_sets; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11761 | match = nla_nest_start_noflag(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11762 | if (!match) |
| 11763 | return -ENOBUFS; |
| 11764 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11765 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 11766 | req->match_sets[i].ssid.ssid_len, |
| 11767 | req->match_sets[i].ssid.ssid)) |
| 11768 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11769 | nla_nest_end(msg, match); |
| 11770 | } |
| 11771 | nla_nest_end(msg, matches); |
| 11772 | } |
| 11773 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11774 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11775 | if (!scan_plans) |
| 11776 | return -ENOBUFS; |
| 11777 | |
| 11778 | for (i = 0; i < req->n_scan_plans; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11779 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11780 | if (!scan_plan) |
| 11781 | return -ENOBUFS; |
| 11782 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 11783 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11784 | req->scan_plans[i].interval) || |
| 11785 | (req->scan_plans[i].iterations && |
| 11786 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 11787 | req->scan_plans[i].iterations))) |
| 11788 | return -ENOBUFS; |
| 11789 | nla_nest_end(msg, scan_plan); |
| 11790 | } |
| 11791 | nla_nest_end(msg, scan_plans); |
| 11792 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11793 | nla_nest_end(msg, nd); |
| 11794 | |
| 11795 | return 0; |
| 11796 | } |
| 11797 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11798 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11799 | { |
| 11800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11801 | struct sk_buff *msg; |
| 11802 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11803 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11804 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11805 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11806 | return -EOPNOTSUPP; |
| 11807 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11808 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11809 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11810 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 11811 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 11812 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 11813 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11814 | } |
| 11815 | |
| 11816 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11817 | if (!msg) |
| 11818 | return -ENOMEM; |
| 11819 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11820 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11821 | NL80211_CMD_GET_WOWLAN); |
| 11822 | if (!hdr) |
| 11823 | goto nla_put_failure; |
| 11824 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11825 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11826 | struct nlattr *nl_wowlan; |
| 11827 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11828 | nl_wowlan = nla_nest_start_noflag(msg, |
| 11829 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11830 | if (!nl_wowlan) |
| 11831 | goto nla_put_failure; |
| 11832 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11833 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11834 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11835 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11836 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11837 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11838 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11839 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11840 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11841 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11842 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11843 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11844 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11845 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11846 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 11847 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11848 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11849 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 11850 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11851 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11852 | if (nl80211_send_wowlan_tcp(msg, |
| 11853 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11854 | goto nla_put_failure; |
| 11855 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11856 | if (nl80211_send_wowlan_nd( |
| 11857 | msg, |
| 11858 | rdev->wiphy.wowlan_config->nd_config)) |
| 11859 | goto nla_put_failure; |
| 11860 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11861 | nla_nest_end(msg, nl_wowlan); |
| 11862 | } |
| 11863 | |
| 11864 | genlmsg_end(msg, hdr); |
| 11865 | return genlmsg_reply(msg, info); |
| 11866 | |
| 11867 | nla_put_failure: |
| 11868 | nlmsg_free(msg); |
| 11869 | return -ENOBUFS; |
| 11870 | } |
| 11871 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11872 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 11873 | struct nlattr *attr, |
| 11874 | struct cfg80211_wowlan *trig) |
| 11875 | { |
| 11876 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 11877 | struct cfg80211_wowlan_tcp *cfg; |
| 11878 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 11879 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 11880 | u32 size; |
| 11881 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 11882 | int err, port; |
| 11883 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11884 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11885 | return -EINVAL; |
| 11886 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11887 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 11888 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11889 | if (err) |
| 11890 | return err; |
| 11891 | |
| 11892 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 11893 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 11894 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 11895 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 11896 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 11897 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 11898 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 11899 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 11900 | return -EINVAL; |
| 11901 | |
| 11902 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11903 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11904 | return -EINVAL; |
| 11905 | |
| 11906 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11907 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 11908 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11909 | return -EINVAL; |
| 11910 | |
| 11911 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11912 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11913 | return -EINVAL; |
| 11914 | |
| 11915 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 11916 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 11917 | return -EINVAL; |
| 11918 | |
| 11919 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 11920 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11921 | |
| 11922 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11923 | tokens_size = tokln - sizeof(*tok); |
| 11924 | |
| 11925 | if (!tok->len || tokens_size % tok->len) |
| 11926 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11927 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11928 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11929 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11930 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11931 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11932 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11933 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11934 | return -EINVAL; |
| 11935 | if (tok->offset + tok->len > data_size) |
| 11936 | return -EINVAL; |
| 11937 | } |
| 11938 | |
| 11939 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 11940 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11941 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11942 | return -EINVAL; |
| 11943 | if (seq->len == 0 || seq->len > 4) |
| 11944 | return -EINVAL; |
| 11945 | if (seq->len + seq->offset > data_size) |
| 11946 | return -EINVAL; |
| 11947 | } |
| 11948 | |
| 11949 | size = sizeof(*cfg); |
| 11950 | size += data_size; |
| 11951 | size += wake_size + wake_mask_size; |
| 11952 | size += tokens_size; |
| 11953 | |
| 11954 | cfg = kzalloc(size, GFP_KERNEL); |
| 11955 | if (!cfg) |
| 11956 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 11957 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 11958 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11959 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 11960 | ETH_ALEN); |
| 11961 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 11962 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 11963 | else |
| 11964 | port = 0; |
| 11965 | #ifdef CONFIG_INET |
| 11966 | /* allocate a socket and port for it and use it */ |
| 11967 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 11968 | IPPROTO_TCP, &cfg->sock, 1); |
| 11969 | if (err) { |
| 11970 | kfree(cfg); |
| 11971 | return err; |
| 11972 | } |
| 11973 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 11974 | sock_release(cfg->sock); |
| 11975 | kfree(cfg); |
| 11976 | return -EADDRINUSE; |
| 11977 | } |
| 11978 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 11979 | #else |
| 11980 | if (!port) { |
| 11981 | kfree(cfg); |
| 11982 | return -EINVAL; |
| 11983 | } |
| 11984 | cfg->src_port = port; |
| 11985 | #endif |
| 11986 | |
| 11987 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 11988 | cfg->payload_len = data_size; |
| 11989 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 11990 | memcpy((void *)cfg->payload, |
| 11991 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 11992 | data_size); |
| 11993 | if (seq) |
| 11994 | cfg->payload_seq = *seq; |
| 11995 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 11996 | cfg->wake_len = wake_size; |
| 11997 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 11998 | memcpy((void *)cfg->wake_data, |
| 11999 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 12000 | wake_size); |
| 12001 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 12002 | data_size + wake_size; |
| 12003 | memcpy((void *)cfg->wake_mask, |
| 12004 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 12005 | wake_mask_size); |
| 12006 | if (tok) { |
| 12007 | cfg->tokens_size = tokens_size; |
| 12008 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 12009 | } |
| 12010 | |
| 12011 | trig->tcp = cfg; |
| 12012 | |
| 12013 | return 0; |
| 12014 | } |
| 12015 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12016 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 12017 | const struct wiphy_wowlan_support *wowlan, |
| 12018 | struct nlattr *attr, |
| 12019 | struct cfg80211_wowlan *trig) |
| 12020 | { |
| 12021 | struct nlattr **tb; |
| 12022 | int err; |
| 12023 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12024 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12025 | if (!tb) |
| 12026 | return -ENOMEM; |
| 12027 | |
| 12028 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 12029 | err = -EOPNOTSUPP; |
| 12030 | goto out; |
| 12031 | } |
| 12032 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12033 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 12034 | nl80211_policy, NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12035 | if (err) |
| 12036 | goto out; |
| 12037 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 12038 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 12039 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12040 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 12041 | if (err) |
| 12042 | trig->nd_config = NULL; |
| 12043 | |
| 12044 | out: |
| 12045 | kfree(tb); |
| 12046 | return err; |
| 12047 | } |
| 12048 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12049 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 12050 | { |
| 12051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12052 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12053 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12054 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12055 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12056 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12057 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12058 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12059 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12060 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12061 | return -EOPNOTSUPP; |
| 12062 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12063 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 12064 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12065 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12066 | goto set_wakeup; |
| 12067 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12068 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12069 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 12070 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 12071 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12072 | if (err) |
| 12073 | return err; |
| 12074 | |
| 12075 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 12076 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 12077 | return -EINVAL; |
| 12078 | new_triggers.any = true; |
| 12079 | } |
| 12080 | |
| 12081 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 12082 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 12083 | return -EINVAL; |
| 12084 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12085 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12086 | } |
| 12087 | |
| 12088 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 12089 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 12090 | return -EINVAL; |
| 12091 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12092 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12093 | } |
| 12094 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12095 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 12096 | return -EINVAL; |
| 12097 | |
| 12098 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 12099 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 12100 | return -EINVAL; |
| 12101 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12102 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12103 | } |
| 12104 | |
| 12105 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 12106 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 12107 | return -EINVAL; |
| 12108 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12109 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12110 | } |
| 12111 | |
| 12112 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 12113 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 12114 | return -EINVAL; |
| 12115 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12116 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12117 | } |
| 12118 | |
| 12119 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 12120 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 12121 | return -EINVAL; |
| 12122 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12123 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12124 | } |
| 12125 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12126 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 12127 | struct nlattr *pat; |
| 12128 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12129 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12130 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12131 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12132 | regular = true; |
| 12133 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12134 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12135 | rem) |
| 12136 | n_patterns++; |
| 12137 | if (n_patterns > wowlan->n_patterns) |
| 12138 | return -EINVAL; |
| 12139 | |
| 12140 | new_triggers.patterns = kcalloc(n_patterns, |
| 12141 | sizeof(new_triggers.patterns[0]), |
| 12142 | GFP_KERNEL); |
| 12143 | if (!new_triggers.patterns) |
| 12144 | return -ENOMEM; |
| 12145 | |
| 12146 | new_triggers.n_patterns = n_patterns; |
| 12147 | i = 0; |
| 12148 | |
| 12149 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12150 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12151 | u8 *mask_pat; |
| 12152 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12153 | err = nla_parse_nested_deprecated(pat_tb, |
| 12154 | MAX_NL80211_PKTPAT, |
| 12155 | pat, |
| 12156 | nl80211_packet_pattern_policy, |
| 12157 | info->extack); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12158 | if (err) |
| 12159 | goto error; |
| 12160 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12161 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12162 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12163 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12164 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12165 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12166 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12167 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12168 | goto error; |
| 12169 | if (pat_len > wowlan->pattern_max_len || |
| 12170 | pat_len < wowlan->pattern_min_len) |
| 12171 | goto error; |
| 12172 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12173 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12174 | pkt_offset = 0; |
| 12175 | else |
| 12176 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12177 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12178 | if (pkt_offset > wowlan->max_pkt_offset) |
| 12179 | goto error; |
| 12180 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 12181 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12182 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12183 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12184 | err = -ENOMEM; |
| 12185 | goto error; |
| 12186 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12187 | new_triggers.patterns[i].mask = mask_pat; |
| 12188 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12189 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12190 | mask_pat += mask_len; |
| 12191 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12192 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12193 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12194 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12195 | pat_len); |
| 12196 | i++; |
| 12197 | } |
| 12198 | } |
| 12199 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12200 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12201 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12202 | err = nl80211_parse_wowlan_tcp( |
| 12203 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 12204 | &new_triggers); |
| 12205 | if (err) |
| 12206 | goto error; |
| 12207 | } |
| 12208 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12209 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12210 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12211 | err = nl80211_parse_wowlan_nd( |
| 12212 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 12213 | &new_triggers); |
| 12214 | if (err) |
| 12215 | goto error; |
| 12216 | } |
| 12217 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12218 | /* The 'any' trigger means the device continues operating more or less |
| 12219 | * as in its normal operation mode and wakes up the host on most of the |
| 12220 | * normal interrupts (like packet RX, ...) |
| 12221 | * It therefore makes little sense to combine with the more constrained |
| 12222 | * wakeup trigger modes. |
| 12223 | */ |
| 12224 | if (new_triggers.any && regular) { |
| 12225 | err = -EINVAL; |
| 12226 | goto error; |
| 12227 | } |
| 12228 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12229 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 12230 | if (!ntrig) { |
| 12231 | err = -ENOMEM; |
| 12232 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12233 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12234 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12235 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12236 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12237 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12238 | if (rdev->ops->set_wakeup && |
| 12239 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 12240 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 12241 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12242 | return 0; |
| 12243 | error: |
| 12244 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 12245 | kfree(new_triggers.patterns[i].mask); |
| 12246 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12247 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 12248 | sock_release(new_triggers.tcp->sock); |
| 12249 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 12250 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12251 | return err; |
| 12252 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12253 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12254 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12255 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 12256 | struct cfg80211_registered_device *rdev) |
| 12257 | { |
| 12258 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 12259 | int i, j, pat_len; |
| 12260 | struct cfg80211_coalesce_rules *rule; |
| 12261 | |
| 12262 | if (!rdev->coalesce->n_rules) |
| 12263 | return 0; |
| 12264 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12265 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12266 | if (!nl_rules) |
| 12267 | return -ENOBUFS; |
| 12268 | |
| 12269 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12270 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12271 | if (!nl_rule) |
| 12272 | return -ENOBUFS; |
| 12273 | |
| 12274 | rule = &rdev->coalesce->rules[i]; |
| 12275 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 12276 | rule->delay)) |
| 12277 | return -ENOBUFS; |
| 12278 | |
| 12279 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 12280 | rule->condition)) |
| 12281 | return -ENOBUFS; |
| 12282 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12283 | nl_pats = nla_nest_start_noflag(msg, |
| 12284 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12285 | if (!nl_pats) |
| 12286 | return -ENOBUFS; |
| 12287 | |
| 12288 | for (j = 0; j < rule->n_patterns; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12289 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12290 | if (!nl_pat) |
| 12291 | return -ENOBUFS; |
| 12292 | pat_len = rule->patterns[j].pattern_len; |
| 12293 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 12294 | DIV_ROUND_UP(pat_len, 8), |
| 12295 | rule->patterns[j].mask) || |
| 12296 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12297 | rule->patterns[j].pattern) || |
| 12298 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 12299 | rule->patterns[j].pkt_offset)) |
| 12300 | return -ENOBUFS; |
| 12301 | nla_nest_end(msg, nl_pat); |
| 12302 | } |
| 12303 | nla_nest_end(msg, nl_pats); |
| 12304 | nla_nest_end(msg, nl_rule); |
| 12305 | } |
| 12306 | nla_nest_end(msg, nl_rules); |
| 12307 | |
| 12308 | return 0; |
| 12309 | } |
| 12310 | |
| 12311 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12312 | { |
| 12313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12314 | struct sk_buff *msg; |
| 12315 | void *hdr; |
| 12316 | |
| 12317 | if (!rdev->wiphy.coalesce) |
| 12318 | return -EOPNOTSUPP; |
| 12319 | |
| 12320 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12321 | if (!msg) |
| 12322 | return -ENOMEM; |
| 12323 | |
| 12324 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12325 | NL80211_CMD_GET_COALESCE); |
| 12326 | if (!hdr) |
| 12327 | goto nla_put_failure; |
| 12328 | |
| 12329 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12330 | goto nla_put_failure; |
| 12331 | |
| 12332 | genlmsg_end(msg, hdr); |
| 12333 | return genlmsg_reply(msg, info); |
| 12334 | |
| 12335 | nla_put_failure: |
| 12336 | nlmsg_free(msg); |
| 12337 | return -ENOBUFS; |
| 12338 | } |
| 12339 | |
| 12340 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12341 | { |
| 12342 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12343 | int i, j; |
| 12344 | struct cfg80211_coalesce_rules *rule; |
| 12345 | |
| 12346 | if (!coalesce) |
| 12347 | return; |
| 12348 | |
| 12349 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12350 | rule = &coalesce->rules[i]; |
| 12351 | for (j = 0; j < rule->n_patterns; j++) |
| 12352 | kfree(rule->patterns[j].mask); |
| 12353 | kfree(rule->patterns); |
| 12354 | } |
| 12355 | kfree(coalesce->rules); |
| 12356 | kfree(coalesce); |
| 12357 | rdev->coalesce = NULL; |
| 12358 | } |
| 12359 | |
| 12360 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12361 | struct nlattr *rule, |
| 12362 | struct cfg80211_coalesce_rules *new_rule) |
| 12363 | { |
| 12364 | int err, i; |
| 12365 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12366 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12367 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12368 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12369 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12370 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12371 | rule, nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12372 | if (err) |
| 12373 | return err; |
| 12374 | |
| 12375 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12376 | new_rule->delay = |
| 12377 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12378 | if (new_rule->delay > coalesce->max_delay) |
| 12379 | return -EINVAL; |
| 12380 | |
| 12381 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12382 | new_rule->condition = |
| 12383 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12384 | |
| 12385 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12386 | return -EINVAL; |
| 12387 | |
| 12388 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12389 | rem) |
| 12390 | n_patterns++; |
| 12391 | if (n_patterns > coalesce->n_patterns) |
| 12392 | return -EINVAL; |
| 12393 | |
| 12394 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12395 | GFP_KERNEL); |
| 12396 | if (!new_rule->patterns) |
| 12397 | return -ENOMEM; |
| 12398 | |
| 12399 | new_rule->n_patterns = n_patterns; |
| 12400 | i = 0; |
| 12401 | |
| 12402 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12403 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12404 | u8 *mask_pat; |
| 12405 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12406 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12407 | pat, |
| 12408 | nl80211_packet_pattern_policy, |
| 12409 | NULL); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12410 | if (err) |
| 12411 | return err; |
| 12412 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12413 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12414 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12415 | return -EINVAL; |
| 12416 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12417 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12418 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12419 | return -EINVAL; |
| 12420 | if (pat_len > coalesce->pattern_max_len || |
| 12421 | pat_len < coalesce->pattern_min_len) |
| 12422 | return -EINVAL; |
| 12423 | |
| 12424 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12425 | pkt_offset = 0; |
| 12426 | else |
| 12427 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12428 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12429 | return -EINVAL; |
| 12430 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12431 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12432 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12433 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12434 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12435 | |
| 12436 | new_rule->patterns[i].mask = mask_pat; |
| 12437 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12438 | mask_len); |
| 12439 | |
| 12440 | mask_pat += mask_len; |
| 12441 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12442 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12443 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12444 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12445 | i++; |
| 12446 | } |
| 12447 | |
| 12448 | return 0; |
| 12449 | } |
| 12450 | |
| 12451 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12452 | { |
| 12453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12454 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12455 | struct cfg80211_coalesce new_coalesce = {}; |
| 12456 | struct cfg80211_coalesce *n_coalesce; |
| 12457 | int err, rem_rule, n_rules = 0, i, j; |
| 12458 | struct nlattr *rule; |
| 12459 | struct cfg80211_coalesce_rules *tmp_rule; |
| 12460 | |
| 12461 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 12462 | return -EOPNOTSUPP; |
| 12463 | |
| 12464 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 12465 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12466 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12467 | return 0; |
| 12468 | } |
| 12469 | |
| 12470 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12471 | rem_rule) |
| 12472 | n_rules++; |
| 12473 | if (n_rules > coalesce->n_rules) |
| 12474 | return -EINVAL; |
| 12475 | |
| 12476 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 12477 | GFP_KERNEL); |
| 12478 | if (!new_coalesce.rules) |
| 12479 | return -ENOMEM; |
| 12480 | |
| 12481 | new_coalesce.n_rules = n_rules; |
| 12482 | i = 0; |
| 12483 | |
| 12484 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12485 | rem_rule) { |
| 12486 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 12487 | &new_coalesce.rules[i]); |
| 12488 | if (err) |
| 12489 | goto error; |
| 12490 | |
| 12491 | i++; |
| 12492 | } |
| 12493 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12494 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12495 | if (err) |
| 12496 | goto error; |
| 12497 | |
| 12498 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 12499 | if (!n_coalesce) { |
| 12500 | err = -ENOMEM; |
| 12501 | goto error; |
| 12502 | } |
| 12503 | cfg80211_rdev_free_coalesce(rdev); |
| 12504 | rdev->coalesce = n_coalesce; |
| 12505 | |
| 12506 | return 0; |
| 12507 | error: |
| 12508 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 12509 | tmp_rule = &new_coalesce.rules[i]; |
| 12510 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 12511 | kfree(tmp_rule->patterns[j].mask); |
| 12512 | kfree(tmp_rule->patterns); |
| 12513 | } |
| 12514 | kfree(new_coalesce.rules); |
| 12515 | |
| 12516 | return err; |
| 12517 | } |
| 12518 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12519 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 12520 | { |
| 12521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12522 | struct net_device *dev = info->user_ptr[1]; |
| 12523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12524 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 12525 | struct cfg80211_gtk_rekey_data rekey_data; |
| 12526 | int err; |
| 12527 | |
| 12528 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 12529 | return -EINVAL; |
| 12530 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12531 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 12532 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 12533 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12534 | if (err) |
| 12535 | return err; |
| 12536 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 12537 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 12538 | !tb[NL80211_REKEY_DATA_KCK]) |
| 12539 | return -EINVAL; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12540 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
| 12541 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12542 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12543 | return -ERANGE; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12544 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
| 12545 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12546 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12547 | return -ERANGE; |
| 12548 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 12549 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 12550 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 12551 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12552 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 12553 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); |
| 12554 | if (tb[NL80211_REKEY_DATA_AKM]) |
| 12555 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12556 | |
| 12557 | wdev_lock(wdev); |
| 12558 | if (!wdev->current_bss) { |
| 12559 | err = -ENOTCONN; |
| 12560 | goto out; |
| 12561 | } |
| 12562 | |
| 12563 | if (!rdev->ops->set_rekey_data) { |
| 12564 | err = -EOPNOTSUPP; |
| 12565 | goto out; |
| 12566 | } |
| 12567 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12568 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12569 | out: |
| 12570 | wdev_unlock(wdev); |
| 12571 | return err; |
| 12572 | } |
| 12573 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12574 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 12575 | struct genl_info *info) |
| 12576 | { |
| 12577 | struct net_device *dev = info->user_ptr[1]; |
| 12578 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12579 | |
| 12580 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12581 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12582 | return -EINVAL; |
| 12583 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12584 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12585 | return -EBUSY; |
| 12586 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12587 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12588 | return 0; |
| 12589 | } |
| 12590 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12591 | static int nl80211_probe_client(struct sk_buff *skb, |
| 12592 | struct genl_info *info) |
| 12593 | { |
| 12594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12595 | struct net_device *dev = info->user_ptr[1]; |
| 12596 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12597 | struct sk_buff *msg; |
| 12598 | void *hdr; |
| 12599 | const u8 *addr; |
| 12600 | u64 cookie; |
| 12601 | int err; |
| 12602 | |
| 12603 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12604 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12605 | return -EOPNOTSUPP; |
| 12606 | |
| 12607 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12608 | return -EINVAL; |
| 12609 | |
| 12610 | if (!rdev->ops->probe_client) |
| 12611 | return -EOPNOTSUPP; |
| 12612 | |
| 12613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12614 | if (!msg) |
| 12615 | return -ENOMEM; |
| 12616 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12617 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12618 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 12619 | if (!hdr) { |
| 12620 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12621 | goto free_msg; |
| 12622 | } |
| 12623 | |
| 12624 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12625 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12626 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12627 | if (err) |
| 12628 | goto free_msg; |
| 12629 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12630 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12631 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12632 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12633 | |
| 12634 | genlmsg_end(msg, hdr); |
| 12635 | |
| 12636 | return genlmsg_reply(msg, info); |
| 12637 | |
| 12638 | nla_put_failure: |
| 12639 | err = -ENOBUFS; |
| 12640 | free_msg: |
| 12641 | nlmsg_free(msg); |
| 12642 | return err; |
| 12643 | } |
| 12644 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12645 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 12646 | { |
| 12647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12648 | struct cfg80211_beacon_registration *reg, *nreg; |
| 12649 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12650 | |
| 12651 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 12652 | return -EOPNOTSUPP; |
| 12653 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12654 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 12655 | if (!nreg) |
| 12656 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12657 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12658 | /* First, check if already registered. */ |
| 12659 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12660 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12661 | if (reg->nlportid == info->snd_portid) { |
| 12662 | rv = -EALREADY; |
| 12663 | goto out_err; |
| 12664 | } |
| 12665 | } |
| 12666 | /* Add it to the list */ |
| 12667 | nreg->nlportid = info->snd_portid; |
| 12668 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 12669 | |
| 12670 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12671 | |
| 12672 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12673 | out_err: |
| 12674 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12675 | kfree(nreg); |
| 12676 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12677 | } |
| 12678 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12679 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12680 | { |
| 12681 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12682 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12683 | int err; |
| 12684 | |
| 12685 | if (!rdev->ops->start_p2p_device) |
| 12686 | return -EOPNOTSUPP; |
| 12687 | |
| 12688 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12689 | return -EOPNOTSUPP; |
| 12690 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12691 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12692 | return 0; |
| 12693 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 12694 | if (rfkill_blocked(rdev->rfkill)) |
| 12695 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12696 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 12697 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12698 | if (err) |
| 12699 | return err; |
| 12700 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12701 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12702 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12703 | |
| 12704 | return 0; |
| 12705 | } |
| 12706 | |
| 12707 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12708 | { |
| 12709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12710 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12711 | |
| 12712 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12713 | return -EOPNOTSUPP; |
| 12714 | |
| 12715 | if (!rdev->ops->stop_p2p_device) |
| 12716 | return -EOPNOTSUPP; |
| 12717 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 12718 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12719 | |
| 12720 | return 0; |
| 12721 | } |
| 12722 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12723 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 12724 | { |
| 12725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12726 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12727 | struct cfg80211_nan_conf conf = {}; |
| 12728 | int err; |
| 12729 | |
| 12730 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12731 | return -EOPNOTSUPP; |
| 12732 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 12733 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12734 | return -EEXIST; |
| 12735 | |
| 12736 | if (rfkill_blocked(rdev->rfkill)) |
| 12737 | return -ERFKILL; |
| 12738 | |
| 12739 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 12740 | return -EINVAL; |
| 12741 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12742 | conf.master_pref = |
| 12743 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12744 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12745 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12746 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12747 | |
| 12748 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12749 | return -EOPNOTSUPP; |
| 12750 | |
| 12751 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12752 | return -EINVAL; |
| 12753 | |
| 12754 | conf.bands = bands; |
| 12755 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12756 | |
| 12757 | err = rdev_start_nan(rdev, wdev, &conf); |
| 12758 | if (err) |
| 12759 | return err; |
| 12760 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12761 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12762 | rdev->opencount++; |
| 12763 | |
| 12764 | return 0; |
| 12765 | } |
| 12766 | |
| 12767 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 12768 | { |
| 12769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12770 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12771 | |
| 12772 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12773 | return -EOPNOTSUPP; |
| 12774 | |
| 12775 | cfg80211_stop_nan(rdev, wdev); |
| 12776 | |
| 12777 | return 0; |
| 12778 | } |
| 12779 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12780 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 12781 | { |
| 12782 | struct nlattr *attr; |
| 12783 | int len = 0, n_entries = 0, rem; |
| 12784 | |
| 12785 | nla_for_each_nested(attr, filter_attr, rem) { |
| 12786 | len += nla_len(attr); |
| 12787 | n_entries++; |
| 12788 | } |
| 12789 | |
| 12790 | if (len >= U8_MAX) |
| 12791 | return -EINVAL; |
| 12792 | |
| 12793 | return n_entries; |
| 12794 | } |
| 12795 | |
| 12796 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 12797 | struct cfg80211_nan_func *func, |
| 12798 | bool tx) |
| 12799 | { |
| 12800 | struct nlattr *attr; |
| 12801 | int n_entries, rem, i; |
| 12802 | struct cfg80211_nan_func_filter *filter; |
| 12803 | |
| 12804 | n_entries = validate_nan_filter(attr_filter); |
| 12805 | if (n_entries < 0) |
| 12806 | return n_entries; |
| 12807 | |
| 12808 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 12809 | |
| 12810 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 12811 | if (!filter) |
| 12812 | return -ENOMEM; |
| 12813 | |
| 12814 | i = 0; |
| 12815 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 12816 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12817 | filter[i].len = nla_len(attr); |
| 12818 | i++; |
| 12819 | } |
| 12820 | if (tx) { |
| 12821 | func->num_tx_filters = n_entries; |
| 12822 | func->tx_filters = filter; |
| 12823 | } else { |
| 12824 | func->num_rx_filters = n_entries; |
| 12825 | func->rx_filters = filter; |
| 12826 | } |
| 12827 | |
| 12828 | return 0; |
| 12829 | } |
| 12830 | |
| 12831 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 12832 | struct genl_info *info) |
| 12833 | { |
| 12834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12835 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12836 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 12837 | struct cfg80211_nan_func *func; |
| 12838 | struct sk_buff *msg = NULL; |
| 12839 | void *hdr = NULL; |
| 12840 | int err = 0; |
| 12841 | |
| 12842 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12843 | return -EOPNOTSUPP; |
| 12844 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12845 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12846 | return -ENOTCONN; |
| 12847 | |
| 12848 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 12849 | return -EINVAL; |
| 12850 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12851 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 12852 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 12853 | nl80211_nan_func_policy, |
| 12854 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12855 | if (err) |
| 12856 | return err; |
| 12857 | |
| 12858 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 12859 | if (!func) |
| 12860 | return -ENOMEM; |
| 12861 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 12862 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12863 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 12864 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12865 | err = -EINVAL; |
| 12866 | goto out; |
| 12867 | } |
| 12868 | |
| 12869 | |
| 12870 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 12871 | |
| 12872 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 12873 | err = -EINVAL; |
| 12874 | goto out; |
| 12875 | } |
| 12876 | |
| 12877 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 12878 | sizeof(func->service_id)); |
| 12879 | |
| 12880 | func->close_range = |
| 12881 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 12882 | |
| 12883 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 12884 | func->serv_spec_info_len = |
| 12885 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 12886 | func->serv_spec_info = |
| 12887 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 12888 | func->serv_spec_info_len, |
| 12889 | GFP_KERNEL); |
| 12890 | if (!func->serv_spec_info) { |
| 12891 | err = -ENOMEM; |
| 12892 | goto out; |
| 12893 | } |
| 12894 | } |
| 12895 | |
| 12896 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 12897 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 12898 | |
| 12899 | switch (func->type) { |
| 12900 | case NL80211_NAN_FUNC_PUBLISH: |
| 12901 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 12902 | err = -EINVAL; |
| 12903 | goto out; |
| 12904 | } |
| 12905 | |
| 12906 | func->publish_type = |
| 12907 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 12908 | func->publish_bcast = |
| 12909 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 12910 | |
| 12911 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 12912 | func->publish_bcast) { |
| 12913 | err = -EINVAL; |
| 12914 | goto out; |
| 12915 | } |
| 12916 | break; |
| 12917 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 12918 | func->subscribe_active = |
| 12919 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 12920 | break; |
| 12921 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 12922 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 12923 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 12924 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12925 | err = -EINVAL; |
| 12926 | goto out; |
| 12927 | } |
| 12928 | |
| 12929 | func->followup_id = |
| 12930 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 12931 | func->followup_reqid = |
| 12932 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 12933 | memcpy(func->followup_dest.addr, |
| 12934 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 12935 | sizeof(func->followup_dest.addr)); |
| 12936 | if (func->ttl) { |
| 12937 | err = -EINVAL; |
| 12938 | goto out; |
| 12939 | } |
| 12940 | break; |
| 12941 | default: |
| 12942 | err = -EINVAL; |
| 12943 | goto out; |
| 12944 | } |
| 12945 | |
| 12946 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 12947 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 12948 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12949 | err = nla_parse_nested_deprecated(srf_tb, |
| 12950 | NL80211_NAN_SRF_ATTR_MAX, |
| 12951 | tb[NL80211_NAN_FUNC_SRF], |
| 12952 | nl80211_nan_srf_policy, |
| 12953 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12954 | if (err) |
| 12955 | goto out; |
| 12956 | |
| 12957 | func->srf_include = |
| 12958 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 12959 | |
| 12960 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 12961 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 12962 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 12963 | err = -EINVAL; |
| 12964 | goto out; |
| 12965 | } |
| 12966 | |
| 12967 | func->srf_bf_len = |
| 12968 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 12969 | func->srf_bf = |
| 12970 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 12971 | func->srf_bf_len, GFP_KERNEL); |
| 12972 | if (!func->srf_bf) { |
| 12973 | err = -ENOMEM; |
| 12974 | goto out; |
| 12975 | } |
| 12976 | |
| 12977 | func->srf_bf_idx = |
| 12978 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 12979 | } else { |
| 12980 | struct nlattr *attr, *mac_attr = |
| 12981 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 12982 | int n_entries, rem, i = 0; |
| 12983 | |
| 12984 | if (!mac_attr) { |
| 12985 | err = -EINVAL; |
| 12986 | goto out; |
| 12987 | } |
| 12988 | |
| 12989 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 12990 | if (n_entries <= 0) { |
| 12991 | err = -EINVAL; |
| 12992 | goto out; |
| 12993 | } |
| 12994 | |
| 12995 | func->srf_num_macs = n_entries; |
| 12996 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12997 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12998 | GFP_KERNEL); |
| 12999 | if (!func->srf_macs) { |
| 13000 | err = -ENOMEM; |
| 13001 | goto out; |
| 13002 | } |
| 13003 | |
| 13004 | nla_for_each_nested(attr, mac_attr, rem) |
| 13005 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 13006 | sizeof(*func->srf_macs)); |
| 13007 | } |
| 13008 | } |
| 13009 | |
| 13010 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 13011 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 13012 | func, true); |
| 13013 | if (err) |
| 13014 | goto out; |
| 13015 | } |
| 13016 | |
| 13017 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 13018 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 13019 | func, false); |
| 13020 | if (err) |
| 13021 | goto out; |
| 13022 | } |
| 13023 | |
| 13024 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13025 | if (!msg) { |
| 13026 | err = -ENOMEM; |
| 13027 | goto out; |
| 13028 | } |
| 13029 | |
| 13030 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13031 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 13032 | /* This can't really happen - we just allocated 4KB */ |
| 13033 | if (WARN_ON(!hdr)) { |
| 13034 | err = -ENOMEM; |
| 13035 | goto out; |
| 13036 | } |
| 13037 | |
| 13038 | err = rdev_add_nan_func(rdev, wdev, func); |
| 13039 | out: |
| 13040 | if (err < 0) { |
| 13041 | cfg80211_free_nan_func(func); |
| 13042 | nlmsg_free(msg); |
| 13043 | return err; |
| 13044 | } |
| 13045 | |
| 13046 | /* propagate the instance id and cookie to userspace */ |
| 13047 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 13048 | NL80211_ATTR_PAD)) |
| 13049 | goto nla_put_failure; |
| 13050 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13051 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13052 | if (!func_attr) |
| 13053 | goto nla_put_failure; |
| 13054 | |
| 13055 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 13056 | func->instance_id)) |
| 13057 | goto nla_put_failure; |
| 13058 | |
| 13059 | nla_nest_end(msg, func_attr); |
| 13060 | |
| 13061 | genlmsg_end(msg, hdr); |
| 13062 | return genlmsg_reply(msg, info); |
| 13063 | |
| 13064 | nla_put_failure: |
| 13065 | nlmsg_free(msg); |
| 13066 | return -ENOBUFS; |
| 13067 | } |
| 13068 | |
| 13069 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 13070 | struct genl_info *info) |
| 13071 | { |
| 13072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13073 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13074 | u64 cookie; |
| 13075 | |
| 13076 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13077 | return -EOPNOTSUPP; |
| 13078 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13079 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13080 | return -ENOTCONN; |
| 13081 | |
| 13082 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 13083 | return -EINVAL; |
| 13084 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13085 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 13086 | |
| 13087 | rdev_del_nan_func(rdev, wdev, cookie); |
| 13088 | |
| 13089 | return 0; |
| 13090 | } |
| 13091 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13092 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 13093 | struct genl_info *info) |
| 13094 | { |
| 13095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13096 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13097 | struct cfg80211_nan_conf conf = {}; |
| 13098 | u32 changed = 0; |
| 13099 | |
| 13100 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13101 | return -EOPNOTSUPP; |
| 13102 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13103 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13104 | return -ENOTCONN; |
| 13105 | |
| 13106 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 13107 | conf.master_pref = |
| 13108 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 13109 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 13110 | return -EINVAL; |
| 13111 | |
| 13112 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 13113 | } |
| 13114 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 13115 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 13116 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 13117 | |
| 13118 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 13119 | return -EOPNOTSUPP; |
| 13120 | |
| 13121 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 13122 | return -EINVAL; |
| 13123 | |
| 13124 | conf.bands = bands; |
| 13125 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13126 | } |
| 13127 | |
| 13128 | if (!changed) |
| 13129 | return -EINVAL; |
| 13130 | |
| 13131 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 13132 | } |
| 13133 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13134 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 13135 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 13136 | { |
| 13137 | struct wiphy *wiphy = wdev->wiphy; |
| 13138 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13139 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 13140 | struct sk_buff *msg; |
| 13141 | void *hdr; |
| 13142 | |
| 13143 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 13144 | return; |
| 13145 | |
| 13146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13147 | if (!msg) |
| 13148 | return; |
| 13149 | |
| 13150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 13151 | if (!hdr) { |
| 13152 | nlmsg_free(msg); |
| 13153 | return; |
| 13154 | } |
| 13155 | |
| 13156 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13157 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13158 | wdev->netdev->ifindex)) || |
| 13159 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13160 | NL80211_ATTR_PAD)) |
| 13161 | goto nla_put_failure; |
| 13162 | |
| 13163 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 13164 | NL80211_ATTR_PAD) || |
| 13165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 13166 | goto nla_put_failure; |
| 13167 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13168 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13169 | if (!match_attr) |
| 13170 | goto nla_put_failure; |
| 13171 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13172 | local_func_attr = nla_nest_start_noflag(msg, |
| 13173 | NL80211_NAN_MATCH_FUNC_LOCAL); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13174 | if (!local_func_attr) |
| 13175 | goto nla_put_failure; |
| 13176 | |
| 13177 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 13178 | goto nla_put_failure; |
| 13179 | |
| 13180 | nla_nest_end(msg, local_func_attr); |
| 13181 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13182 | peer_func_attr = nla_nest_start_noflag(msg, |
| 13183 | NL80211_NAN_MATCH_FUNC_PEER); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13184 | if (!peer_func_attr) |
| 13185 | goto nla_put_failure; |
| 13186 | |
| 13187 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 13188 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 13189 | goto nla_put_failure; |
| 13190 | |
| 13191 | if (match->info && match->info_len && |
| 13192 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 13193 | match->info)) |
| 13194 | goto nla_put_failure; |
| 13195 | |
| 13196 | nla_nest_end(msg, peer_func_attr); |
| 13197 | nla_nest_end(msg, match_attr); |
| 13198 | genlmsg_end(msg, hdr); |
| 13199 | |
| 13200 | if (!wdev->owner_nlportid) |
| 13201 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13202 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13203 | else |
| 13204 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13205 | wdev->owner_nlportid); |
| 13206 | |
| 13207 | return; |
| 13208 | |
| 13209 | nla_put_failure: |
| 13210 | nlmsg_free(msg); |
| 13211 | } |
| 13212 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 13213 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13214 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 13215 | u8 inst_id, |
| 13216 | enum nl80211_nan_func_term_reason reason, |
| 13217 | u64 cookie, gfp_t gfp) |
| 13218 | { |
| 13219 | struct wiphy *wiphy = wdev->wiphy; |
| 13220 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13221 | struct sk_buff *msg; |
| 13222 | struct nlattr *func_attr; |
| 13223 | void *hdr; |
| 13224 | |
| 13225 | if (WARN_ON(!inst_id)) |
| 13226 | return; |
| 13227 | |
| 13228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13229 | if (!msg) |
| 13230 | return; |
| 13231 | |
| 13232 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 13233 | if (!hdr) { |
| 13234 | nlmsg_free(msg); |
| 13235 | return; |
| 13236 | } |
| 13237 | |
| 13238 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13239 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13240 | wdev->netdev->ifindex)) || |
| 13241 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13242 | NL80211_ATTR_PAD)) |
| 13243 | goto nla_put_failure; |
| 13244 | |
| 13245 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13246 | NL80211_ATTR_PAD)) |
| 13247 | goto nla_put_failure; |
| 13248 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13249 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13250 | if (!func_attr) |
| 13251 | goto nla_put_failure; |
| 13252 | |
| 13253 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 13254 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 13255 | goto nla_put_failure; |
| 13256 | |
| 13257 | nla_nest_end(msg, func_attr); |
| 13258 | genlmsg_end(msg, hdr); |
| 13259 | |
| 13260 | if (!wdev->owner_nlportid) |
| 13261 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13262 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13263 | else |
| 13264 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13265 | wdev->owner_nlportid); |
| 13266 | |
| 13267 | return; |
| 13268 | |
| 13269 | nla_put_failure: |
| 13270 | nlmsg_free(msg); |
| 13271 | } |
| 13272 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 13273 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13274 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 13275 | struct genl_info *info) |
| 13276 | { |
| 13277 | void *hdr; |
| 13278 | struct sk_buff *msg; |
| 13279 | |
| 13280 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13281 | if (!msg) |
| 13282 | return -ENOMEM; |
| 13283 | |
| 13284 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13285 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 13286 | if (!hdr) |
| 13287 | goto nla_put_failure; |
| 13288 | |
| 13289 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 13290 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 13291 | goto nla_put_failure; |
| 13292 | |
| 13293 | genlmsg_end(msg, hdr); |
| 13294 | return genlmsg_reply(msg, info); |
| 13295 | |
| 13296 | nla_put_failure: |
| 13297 | kfree_skb(msg); |
| 13298 | return -ENOBUFS; |
| 13299 | } |
| 13300 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13301 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 13302 | { |
| 13303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13304 | struct cfg80211_update_ft_ies_params ft_params; |
| 13305 | struct net_device *dev = info->user_ptr[1]; |
| 13306 | |
| 13307 | if (!rdev->ops->update_ft_ies) |
| 13308 | return -EOPNOTSUPP; |
| 13309 | |
| 13310 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 13311 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13312 | return -EINVAL; |
| 13313 | |
| 13314 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13315 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13316 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13317 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13318 | |
| 13319 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13320 | } |
| 13321 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13322 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13323 | struct genl_info *info) |
| 13324 | { |
| 13325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13326 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13327 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13328 | u16 duration; |
| 13329 | int ret; |
| 13330 | |
| 13331 | if (!rdev->ops->crit_proto_start) |
| 13332 | return -EOPNOTSUPP; |
| 13333 | |
| 13334 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13335 | return -EINVAL; |
| 13336 | |
| 13337 | if (rdev->crit_proto_nlportid) |
| 13338 | return -EBUSY; |
| 13339 | |
| 13340 | /* determine protocol if provided */ |
| 13341 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13342 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13343 | |
| 13344 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13345 | return -EINVAL; |
| 13346 | |
| 13347 | /* timeout must be provided */ |
| 13348 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13349 | return -EINVAL; |
| 13350 | |
| 13351 | duration = |
| 13352 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13353 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13354 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13355 | if (!ret) |
| 13356 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13357 | |
| 13358 | return ret; |
| 13359 | } |
| 13360 | |
| 13361 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13362 | struct genl_info *info) |
| 13363 | { |
| 13364 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13365 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13366 | |
| 13367 | if (!rdev->ops->crit_proto_stop) |
| 13368 | return -EOPNOTSUPP; |
| 13369 | |
| 13370 | if (rdev->crit_proto_nlportid) { |
| 13371 | rdev->crit_proto_nlportid = 0; |
| 13372 | rdev_crit_proto_stop(rdev, wdev); |
| 13373 | } |
| 13374 | return 0; |
| 13375 | } |
| 13376 | |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13377 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13378 | struct nlattr *attr, |
| 13379 | struct netlink_ext_ack *extack) |
| 13380 | { |
| 13381 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13382 | if (attr->nla_type & NLA_F_NESTED) { |
| 13383 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13384 | "unexpected nested data"); |
| 13385 | return -EINVAL; |
| 13386 | } |
| 13387 | |
| 13388 | return 0; |
| 13389 | } |
| 13390 | |
| 13391 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13392 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13393 | return -EINVAL; |
| 13394 | } |
| 13395 | |
Michal Kubecek | 32d5109 | 2019-12-11 10:58:19 +0100 | [diff] [blame] | 13396 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13397 | } |
| 13398 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13399 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13400 | { |
| 13401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13402 | struct wireless_dev *wdev = |
| 13403 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 13404 | int i, err; |
| 13405 | u32 vid, subcmd; |
| 13406 | |
| 13407 | if (!rdev->wiphy.vendor_commands) |
| 13408 | return -EOPNOTSUPP; |
| 13409 | |
| 13410 | if (IS_ERR(wdev)) { |
| 13411 | err = PTR_ERR(wdev); |
| 13412 | if (err != -EINVAL) |
| 13413 | return err; |
| 13414 | wdev = NULL; |
| 13415 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13416 | return -EINVAL; |
| 13417 | } |
| 13418 | |
| 13419 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13420 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13421 | return -EINVAL; |
| 13422 | |
| 13423 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13424 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13425 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13426 | const struct wiphy_vendor_command *vcmd; |
| 13427 | void *data = NULL; |
| 13428 | int len = 0; |
| 13429 | |
| 13430 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13431 | |
| 13432 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13433 | continue; |
| 13434 | |
| 13435 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13436 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13437 | if (!wdev) |
| 13438 | return -EINVAL; |
| 13439 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13440 | !wdev->netdev) |
| 13441 | return -EINVAL; |
| 13442 | |
| 13443 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13444 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13445 | return -ENETDOWN; |
| 13446 | } |
| 13447 | } else { |
| 13448 | wdev = NULL; |
| 13449 | } |
| 13450 | |
Julian Squires | 4052d3d | 2020-07-06 17:13:53 -0400 | [diff] [blame] | 13451 | if (!vcmd->doit) |
| 13452 | return -EOPNOTSUPP; |
| 13453 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13454 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 13455 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 13456 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13457 | |
| 13458 | err = nl80211_vendor_check_policy(vcmd, |
| 13459 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 13460 | info->extack); |
| 13461 | if (err) |
| 13462 | return err; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13463 | } |
| 13464 | |
| 13465 | rdev->cur_cmd_info = info; |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13466 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13467 | rdev->cur_cmd_info = NULL; |
| 13468 | return err; |
| 13469 | } |
| 13470 | |
| 13471 | return -EOPNOTSUPP; |
| 13472 | } |
| 13473 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13474 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 13475 | struct netlink_callback *cb, |
| 13476 | struct cfg80211_registered_device **rdev, |
| 13477 | struct wireless_dev **wdev) |
| 13478 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13479 | struct nlattr **attrbuf; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13480 | u32 vid, subcmd; |
| 13481 | unsigned int i; |
| 13482 | int vcmd_idx = -1; |
| 13483 | int err; |
| 13484 | void *data = NULL; |
| 13485 | unsigned int data_len = 0; |
| 13486 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13487 | if (cb->args[0]) { |
| 13488 | /* subtract the 1 again here */ |
| 13489 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 13490 | struct wireless_dev *tmp; |
| 13491 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13492 | if (!wiphy) |
| 13493 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13494 | *rdev = wiphy_to_rdev(wiphy); |
| 13495 | *wdev = NULL; |
| 13496 | |
| 13497 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13498 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13499 | if (tmp->identifier == cb->args[1] - 1) { |
| 13500 | *wdev = tmp; |
| 13501 | break; |
| 13502 | } |
| 13503 | } |
| 13504 | } |
| 13505 | |
| 13506 | /* keep rtnl locked in successful case */ |
| 13507 | return 0; |
| 13508 | } |
| 13509 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13510 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 13511 | if (!attrbuf) |
| 13512 | return -ENOMEM; |
| 13513 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13514 | err = nlmsg_parse_deprecated(cb->nlh, |
| 13515 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 13516 | attrbuf, nl80211_fam.maxattr, |
| 13517 | nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13518 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13519 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13520 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13521 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13522 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 13523 | err = -EINVAL; |
| 13524 | goto out; |
| 13525 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13526 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13527 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13528 | if (IS_ERR(*wdev)) |
| 13529 | *wdev = NULL; |
| 13530 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13531 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13532 | if (IS_ERR(*rdev)) { |
| 13533 | err = PTR_ERR(*rdev); |
| 13534 | goto out; |
| 13535 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13536 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13537 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 13538 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13539 | |
| 13540 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 13541 | const struct wiphy_vendor_command *vcmd; |
| 13542 | |
| 13543 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 13544 | |
| 13545 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13546 | continue; |
| 13547 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13548 | if (!vcmd->dumpit) { |
| 13549 | err = -EOPNOTSUPP; |
| 13550 | goto out; |
| 13551 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13552 | |
| 13553 | vcmd_idx = i; |
| 13554 | break; |
| 13555 | } |
| 13556 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13557 | if (vcmd_idx < 0) { |
| 13558 | err = -EOPNOTSUPP; |
| 13559 | goto out; |
| 13560 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13561 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13562 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 13563 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 13564 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13565 | |
| 13566 | err = nl80211_vendor_check_policy( |
| 13567 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 13568 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 13569 | cb->extack); |
| 13570 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13571 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13572 | } |
| 13573 | |
| 13574 | /* 0 is the first index - add 1 to parse only once */ |
| 13575 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 13576 | /* add 1 to know if it was NULL */ |
| 13577 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 13578 | cb->args[2] = vcmd_idx; |
| 13579 | cb->args[3] = (unsigned long)data; |
| 13580 | cb->args[4] = data_len; |
| 13581 | |
| 13582 | /* keep rtnl locked in successful case */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13583 | err = 0; |
| 13584 | out: |
| 13585 | kfree(attrbuf); |
| 13586 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13587 | } |
| 13588 | |
| 13589 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 13590 | struct netlink_callback *cb) |
| 13591 | { |
| 13592 | struct cfg80211_registered_device *rdev; |
| 13593 | struct wireless_dev *wdev; |
| 13594 | unsigned int vcmd_idx; |
| 13595 | const struct wiphy_vendor_command *vcmd; |
| 13596 | void *data; |
| 13597 | int data_len; |
| 13598 | int err; |
| 13599 | struct nlattr *vendor_data; |
| 13600 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13601 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13602 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 13603 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13604 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13605 | |
| 13606 | vcmd_idx = cb->args[2]; |
| 13607 | data = (void *)cb->args[3]; |
| 13608 | data_len = cb->args[4]; |
| 13609 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 13610 | |
| 13611 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13612 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13613 | if (!wdev) { |
| 13614 | err = -EINVAL; |
| 13615 | goto out; |
| 13616 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13617 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13618 | !wdev->netdev) { |
| 13619 | err = -EINVAL; |
| 13620 | goto out; |
| 13621 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13622 | |
| 13623 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13624 | if (!wdev_running(wdev)) { |
| 13625 | err = -ENETDOWN; |
| 13626 | goto out; |
| 13627 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13628 | } |
| 13629 | } |
| 13630 | |
| 13631 | while (1) { |
| 13632 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 13633 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 13634 | NL80211_CMD_VENDOR); |
| 13635 | if (!hdr) |
| 13636 | break; |
| 13637 | |
| 13638 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13639 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 13640 | wdev_id(wdev), |
| 13641 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13642 | genlmsg_cancel(skb, hdr); |
| 13643 | break; |
| 13644 | } |
| 13645 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13646 | vendor_data = nla_nest_start_noflag(skb, |
| 13647 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13648 | if (!vendor_data) { |
| 13649 | genlmsg_cancel(skb, hdr); |
| 13650 | break; |
| 13651 | } |
| 13652 | |
| 13653 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 13654 | (unsigned long *)&cb->args[5]); |
| 13655 | nla_nest_end(skb, vendor_data); |
| 13656 | |
| 13657 | if (err == -ENOBUFS || err == -ENOENT) { |
| 13658 | genlmsg_cancel(skb, hdr); |
| 13659 | break; |
Julian Squires | 9c167b2 | 2020-07-20 12:20:35 -0230 | [diff] [blame] | 13660 | } else if (err <= 0) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13661 | genlmsg_cancel(skb, hdr); |
| 13662 | goto out; |
| 13663 | } |
| 13664 | |
| 13665 | genlmsg_end(skb, hdr); |
| 13666 | } |
| 13667 | |
| 13668 | err = skb->len; |
| 13669 | out: |
| 13670 | rtnl_unlock(); |
| 13671 | return err; |
| 13672 | } |
| 13673 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13674 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 13675 | enum nl80211_commands cmd, |
| 13676 | enum nl80211_attrs attr, |
| 13677 | int approxlen) |
| 13678 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13680 | |
| 13681 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13682 | return NULL; |
| 13683 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 13684 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13685 | rdev->cur_cmd_info->snd_portid, |
| 13686 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 13687 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13688 | } |
| 13689 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 13690 | |
| 13691 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 13692 | { |
| 13693 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 13694 | void *hdr = ((void **)skb->cb)[1]; |
| 13695 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 13696 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 13697 | /* clear CB data for netlink core to own from now on */ |
| 13698 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 13699 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13700 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 13701 | kfree_skb(skb); |
| 13702 | return -EINVAL; |
| 13703 | } |
| 13704 | |
| 13705 | nla_nest_end(skb, data); |
| 13706 | genlmsg_end(skb, hdr); |
| 13707 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 13708 | } |
| 13709 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 13710 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 13711 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 13712 | { |
| 13713 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13714 | |
| 13715 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13716 | return 0; |
| 13717 | |
| 13718 | return rdev->cur_cmd_info->snd_portid; |
| 13719 | } |
| 13720 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 13721 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13722 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 13723 | struct genl_info *info) |
| 13724 | { |
| 13725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13726 | struct cfg80211_qos_map *qos_map = NULL; |
| 13727 | struct net_device *dev = info->user_ptr[1]; |
| 13728 | u8 *pos, len, num_des, des_len, des; |
| 13729 | int ret; |
| 13730 | |
| 13731 | if (!rdev->ops->set_qos_map) |
| 13732 | return -EOPNOTSUPP; |
| 13733 | |
| 13734 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 13735 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13736 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13737 | |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 13738 | if (len % 2) |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13739 | return -EINVAL; |
| 13740 | |
| 13741 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 13742 | if (!qos_map) |
| 13743 | return -ENOMEM; |
| 13744 | |
| 13745 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 13746 | if (num_des) { |
| 13747 | des_len = num_des * |
| 13748 | sizeof(struct cfg80211_dscp_exception); |
| 13749 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 13750 | qos_map->num_des = num_des; |
| 13751 | for (des = 0; des < num_des; des++) { |
| 13752 | if (qos_map->dscp_exception[des].up > 7) { |
| 13753 | kfree(qos_map); |
| 13754 | return -EINVAL; |
| 13755 | } |
| 13756 | } |
| 13757 | pos += des_len; |
| 13758 | } |
| 13759 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 13760 | } |
| 13761 | |
| 13762 | wdev_lock(dev->ieee80211_ptr); |
| 13763 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 13764 | if (!ret) |
| 13765 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 13766 | wdev_unlock(dev->ieee80211_ptr); |
| 13767 | |
| 13768 | kfree(qos_map); |
| 13769 | return ret; |
| 13770 | } |
| 13771 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13772 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13773 | { |
| 13774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13775 | struct net_device *dev = info->user_ptr[1]; |
| 13776 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13777 | const u8 *peer; |
| 13778 | u8 tsid, up; |
| 13779 | u16 admitted_time = 0; |
| 13780 | int err; |
| 13781 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13782 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13783 | return -EOPNOTSUPP; |
| 13784 | |
| 13785 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 13786 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 13787 | return -EINVAL; |
| 13788 | |
| 13789 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13790 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13791 | |
| 13792 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13793 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13794 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13795 | * need more attributes for that (e.g. BA session requirement); |
| 13796 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13797 | */ |
| 13798 | return -EINVAL; |
| 13799 | } |
| 13800 | |
| 13801 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13802 | |
| 13803 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 13804 | admitted_time = |
| 13805 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 13806 | if (!admitted_time) |
| 13807 | return -EINVAL; |
| 13808 | } |
| 13809 | |
| 13810 | wdev_lock(wdev); |
| 13811 | switch (wdev->iftype) { |
| 13812 | case NL80211_IFTYPE_STATION: |
| 13813 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13814 | if (wdev->current_bss) |
| 13815 | break; |
| 13816 | err = -ENOTCONN; |
| 13817 | goto out; |
| 13818 | default: |
| 13819 | err = -EOPNOTSUPP; |
| 13820 | goto out; |
| 13821 | } |
| 13822 | |
| 13823 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 13824 | |
| 13825 | out: |
| 13826 | wdev_unlock(wdev); |
| 13827 | return err; |
| 13828 | } |
| 13829 | |
| 13830 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13831 | { |
| 13832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13833 | struct net_device *dev = info->user_ptr[1]; |
| 13834 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13835 | const u8 *peer; |
| 13836 | u8 tsid; |
| 13837 | int err; |
| 13838 | |
| 13839 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 13840 | return -EINVAL; |
| 13841 | |
| 13842 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 13843 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13844 | |
| 13845 | wdev_lock(wdev); |
| 13846 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 13847 | wdev_unlock(wdev); |
| 13848 | |
| 13849 | return err; |
| 13850 | } |
| 13851 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13852 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 13853 | struct genl_info *info) |
| 13854 | { |
| 13855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13856 | struct net_device *dev = info->user_ptr[1]; |
| 13857 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13858 | struct cfg80211_chan_def chandef = {}; |
| 13859 | const u8 *addr; |
| 13860 | u8 oper_class; |
| 13861 | int err; |
| 13862 | |
| 13863 | if (!rdev->ops->tdls_channel_switch || |
| 13864 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13865 | return -EOPNOTSUPP; |
| 13866 | |
| 13867 | switch (dev->ieee80211_ptr->iftype) { |
| 13868 | case NL80211_IFTYPE_STATION: |
| 13869 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13870 | break; |
| 13871 | default: |
| 13872 | return -EOPNOTSUPP; |
| 13873 | } |
| 13874 | |
| 13875 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 13876 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 13877 | return -EINVAL; |
| 13878 | |
| 13879 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 13880 | if (err) |
| 13881 | return err; |
| 13882 | |
| 13883 | /* |
| 13884 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 13885 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 13886 | * specification is not defined for them. |
| 13887 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 13888 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13889 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 13890 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 13891 | return -EINVAL; |
| 13892 | |
| 13893 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 13894 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 13895 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13896 | return -EINVAL; |
| 13897 | |
| 13898 | /* don't allow switching to DFS channels */ |
| 13899 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 13900 | return -EINVAL; |
| 13901 | |
| 13902 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13903 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 13904 | |
| 13905 | wdev_lock(wdev); |
| 13906 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 13907 | wdev_unlock(wdev); |
| 13908 | |
| 13909 | return err; |
| 13910 | } |
| 13911 | |
| 13912 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 13913 | struct genl_info *info) |
| 13914 | { |
| 13915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13916 | struct net_device *dev = info->user_ptr[1]; |
| 13917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13918 | const u8 *addr; |
| 13919 | |
| 13920 | if (!rdev->ops->tdls_channel_switch || |
| 13921 | !rdev->ops->tdls_cancel_channel_switch || |
| 13922 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13923 | return -EOPNOTSUPP; |
| 13924 | |
| 13925 | switch (dev->ieee80211_ptr->iftype) { |
| 13926 | case NL80211_IFTYPE_STATION: |
| 13927 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13928 | break; |
| 13929 | default: |
| 13930 | return -EOPNOTSUPP; |
| 13931 | } |
| 13932 | |
| 13933 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13934 | return -EINVAL; |
| 13935 | |
| 13936 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13937 | |
| 13938 | wdev_lock(wdev); |
| 13939 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 13940 | wdev_unlock(wdev); |
| 13941 | |
| 13942 | return 0; |
| 13943 | } |
| 13944 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13945 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 13946 | struct genl_info *info) |
| 13947 | { |
| 13948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13949 | struct net_device *dev = info->user_ptr[1]; |
| 13950 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13951 | const struct nlattr *nla; |
| 13952 | bool enabled; |
| 13953 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13954 | if (!rdev->ops->set_multicast_to_unicast) |
| 13955 | return -EOPNOTSUPP; |
| 13956 | |
| 13957 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 13958 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 13959 | return -EOPNOTSUPP; |
| 13960 | |
| 13961 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 13962 | enabled = nla_get_flag(nla); |
| 13963 | |
| 13964 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 13965 | } |
| 13966 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13967 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13968 | { |
| 13969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13970 | struct net_device *dev = info->user_ptr[1]; |
| 13971 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13972 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 13973 | int ret; |
| 13974 | |
| 13975 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13976 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13977 | return -EOPNOTSUPP; |
| 13978 | |
| 13979 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13980 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13981 | return -EOPNOTSUPP; |
| 13982 | |
| 13983 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 13984 | return -EINVAL; |
| 13985 | |
| 13986 | wdev_lock(wdev); |
| 13987 | if (!wdev->current_bss) { |
| 13988 | ret = -ENOTCONN; |
| 13989 | goto out; |
| 13990 | } |
| 13991 | |
| 13992 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13993 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 13994 | ret = -EINVAL; |
| 13995 | goto out; |
| 13996 | } |
| 13997 | |
| 13998 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 13999 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 14000 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 14001 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 14002 | ret = -EINVAL; |
| 14003 | goto out; |
| 14004 | } |
| 14005 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14006 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14007 | pmk_conf.pmk_r0_name = |
| 14008 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14009 | |
| 14010 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 14011 | out: |
| 14012 | wdev_unlock(wdev); |
| 14013 | return ret; |
| 14014 | } |
| 14015 | |
| 14016 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14017 | { |
| 14018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14019 | struct net_device *dev = info->user_ptr[1]; |
| 14020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14021 | const u8 *aa; |
| 14022 | int ret; |
| 14023 | |
| 14024 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14025 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14026 | return -EOPNOTSUPP; |
| 14027 | |
| 14028 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14029 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14030 | return -EOPNOTSUPP; |
| 14031 | |
| 14032 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14033 | return -EINVAL; |
| 14034 | |
| 14035 | wdev_lock(wdev); |
| 14036 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14037 | ret = rdev_del_pmk(rdev, dev, aa); |
| 14038 | wdev_unlock(wdev); |
| 14039 | |
| 14040 | return ret; |
| 14041 | } |
| 14042 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14043 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 14044 | { |
| 14045 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14046 | struct net_device *dev = info->user_ptr[1]; |
| 14047 | struct cfg80211_external_auth_params params; |
| 14048 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 14049 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14050 | return -EOPNOTSUPP; |
| 14051 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14052 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 14053 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 14054 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14055 | return -EINVAL; |
| 14056 | |
| 14057 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 14058 | return -EINVAL; |
| 14059 | |
| 14060 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 14061 | return -EINVAL; |
| 14062 | |
| 14063 | memset(¶ms, 0, sizeof(params)); |
| 14064 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14065 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 14066 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14067 | if (params.ssid.ssid_len == 0) |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14068 | return -EINVAL; |
| 14069 | memcpy(params.ssid.ssid, |
| 14070 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 14071 | params.ssid.ssid_len); |
| 14072 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14073 | |
| 14074 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 14075 | ETH_ALEN); |
| 14076 | |
| 14077 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14078 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14079 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 14080 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 14081 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14082 | return rdev_external_auth(rdev, dev, ¶ms); |
| 14083 | } |
| 14084 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14085 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 14086 | { |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14087 | bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14089 | struct net_device *dev = info->user_ptr[1]; |
| 14090 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14091 | const u8 *buf; |
| 14092 | size_t len; |
| 14093 | u8 *dest; |
| 14094 | u16 proto; |
| 14095 | bool noencrypt; |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14096 | u64 cookie = 0; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14097 | int err; |
| 14098 | |
| 14099 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14100 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 14101 | return -EOPNOTSUPP; |
| 14102 | |
| 14103 | if (!rdev->ops->tx_control_port) |
| 14104 | return -EOPNOTSUPP; |
| 14105 | |
| 14106 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 14107 | !info->attrs[NL80211_ATTR_MAC] || |
| 14108 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 14109 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 14110 | return -EINVAL; |
| 14111 | } |
| 14112 | |
| 14113 | wdev_lock(wdev); |
| 14114 | |
| 14115 | switch (wdev->iftype) { |
| 14116 | case NL80211_IFTYPE_AP: |
| 14117 | case NL80211_IFTYPE_P2P_GO: |
| 14118 | case NL80211_IFTYPE_MESH_POINT: |
| 14119 | break; |
| 14120 | case NL80211_IFTYPE_ADHOC: |
| 14121 | case NL80211_IFTYPE_STATION: |
| 14122 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14123 | if (wdev->current_bss) |
| 14124 | break; |
| 14125 | err = -ENOTCONN; |
| 14126 | goto out; |
| 14127 | default: |
| 14128 | err = -EOPNOTSUPP; |
| 14129 | goto out; |
| 14130 | } |
| 14131 | |
| 14132 | wdev_unlock(wdev); |
| 14133 | |
| 14134 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14135 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14136 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14137 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 14138 | noencrypt = |
| 14139 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 14140 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14141 | err = rdev_tx_control_port(rdev, dev, buf, len, |
| 14142 | dest, cpu_to_be16(proto), noencrypt, |
| 14143 | dont_wait_for_ack ? NULL : &cookie); |
| 14144 | if (!err && !dont_wait_for_ack) |
| 14145 | nl_set_extack_cookie_u64(info->extack, cookie); |
| 14146 | return err; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14147 | out: |
| 14148 | wdev_unlock(wdev); |
| 14149 | return err; |
| 14150 | } |
| 14151 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14152 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 14153 | struct genl_info *info) |
| 14154 | { |
| 14155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14156 | struct net_device *dev = info->user_ptr[1]; |
| 14157 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14158 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 14159 | struct sk_buff *msg; |
| 14160 | void *hdr; |
| 14161 | struct nlattr *ftm_stats_attr; |
| 14162 | int err; |
| 14163 | |
| 14164 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 14165 | return -EOPNOTSUPP; |
| 14166 | |
| 14167 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 14168 | if (err) |
| 14169 | return err; |
| 14170 | |
| 14171 | if (!ftm_stats.filled) |
| 14172 | return -ENODATA; |
| 14173 | |
| 14174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14175 | if (!msg) |
| 14176 | return -ENOMEM; |
| 14177 | |
| 14178 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 14179 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 14180 | if (!hdr) |
Navid Emamdoost | 1399c59 | 2019-10-04 14:42:19 -0500 | [diff] [blame] | 14181 | goto nla_put_failure; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14182 | |
| 14183 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 14184 | goto nla_put_failure; |
| 14185 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 14186 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 14187 | NL80211_ATTR_FTM_RESPONDER_STATS); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14188 | if (!ftm_stats_attr) |
| 14189 | goto nla_put_failure; |
| 14190 | |
| 14191 | #define SET_FTM(field, name, type) \ |
| 14192 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14193 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 14194 | ftm_stats.field)) \ |
| 14195 | goto nla_put_failure; } while (0) |
| 14196 | #define SET_FTM_U64(field, name) \ |
| 14197 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14198 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 14199 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 14200 | goto nla_put_failure; } while (0) |
| 14201 | |
| 14202 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 14203 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 14204 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 14205 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 14206 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 14207 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 14208 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 14209 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 14210 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 14211 | #undef SET_FTM |
| 14212 | |
| 14213 | nla_nest_end(msg, ftm_stats_attr); |
| 14214 | |
| 14215 | genlmsg_end(msg, hdr); |
| 14216 | return genlmsg_reply(msg, info); |
| 14217 | |
| 14218 | nla_put_failure: |
| 14219 | nlmsg_free(msg); |
| 14220 | return -ENOBUFS; |
| 14221 | } |
| 14222 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 14223 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 14224 | { |
| 14225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14226 | struct cfg80211_update_owe_info owe_info; |
| 14227 | struct net_device *dev = info->user_ptr[1]; |
| 14228 | |
| 14229 | if (!rdev->ops->update_owe_info) |
| 14230 | return -EOPNOTSUPP; |
| 14231 | |
| 14232 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 14233 | !info->attrs[NL80211_ATTR_MAC]) |
| 14234 | return -EINVAL; |
| 14235 | |
| 14236 | memset(&owe_info, 0, sizeof(owe_info)); |
| 14237 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14238 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 14239 | |
| 14240 | if (info->attrs[NL80211_ATTR_IE]) { |
| 14241 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 14242 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 14243 | } |
| 14244 | |
| 14245 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 14246 | } |
| 14247 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14248 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 14249 | { |
| 14250 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14251 | struct net_device *dev = info->user_ptr[1]; |
| 14252 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14253 | struct station_info sinfo = {}; |
| 14254 | const u8 *buf; |
| 14255 | size_t len; |
| 14256 | u8 *dest; |
| 14257 | int err; |
| 14258 | |
| 14259 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 14260 | return -EOPNOTSUPP; |
| 14261 | |
| 14262 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14263 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 14264 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 14265 | return -EINVAL; |
| 14266 | } |
| 14267 | |
| 14268 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 14269 | return -EOPNOTSUPP; |
| 14270 | |
| 14271 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14272 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14273 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14274 | |
| 14275 | if (len < sizeof(struct ethhdr)) |
| 14276 | return -EINVAL; |
| 14277 | |
| 14278 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 14279 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 14280 | return -EINVAL; |
| 14281 | |
| 14282 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 14283 | if (err) |
| 14284 | return err; |
| 14285 | |
Felix Fietkau | 2a279b34 | 2020-01-08 18:06:29 +0100 | [diff] [blame] | 14286 | cfg80211_sinfo_release_content(&sinfo); |
| 14287 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14288 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 14289 | } |
| 14290 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14291 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 14292 | struct nlattr *attrs[], struct net_device *dev, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14293 | struct cfg80211_tid_cfg *tid_conf, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14294 | struct genl_info *info, const u8 *peer) |
| 14295 | { |
| 14296 | struct netlink_ext_ack *extack = info->extack; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14297 | u64 mask; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14298 | int err; |
| 14299 | |
| 14300 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 14301 | return -EINVAL; |
| 14302 | |
| 14303 | tid_conf->config_override = |
| 14304 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14305 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14306 | |
| 14307 | if (tid_conf->config_override) { |
| 14308 | if (rdev->ops->reset_tid_config) { |
| 14309 | err = rdev_reset_tid_config(rdev, dev, peer, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14310 | tid_conf->tids); |
Sergey Matyukevich | c033695 | 2020-04-24 14:29:04 +0300 | [diff] [blame] | 14311 | if (err) |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14312 | return err; |
| 14313 | } else { |
| 14314 | return -EINVAL; |
| 14315 | } |
| 14316 | } |
| 14317 | |
| 14318 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14319 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14320 | tid_conf->noack = |
| 14321 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14322 | } |
| 14323 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 14324 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
| 14325 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); |
| 14326 | tid_conf->retry_short = |
| 14327 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); |
| 14328 | |
| 14329 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) |
| 14330 | return -EINVAL; |
| 14331 | } |
| 14332 | |
| 14333 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { |
| 14334 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); |
| 14335 | tid_conf->retry_long = |
| 14336 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); |
| 14337 | |
| 14338 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) |
| 14339 | return -EINVAL; |
| 14340 | } |
| 14341 | |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 14342 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
| 14343 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); |
| 14344 | tid_conf->ampdu = |
| 14345 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); |
| 14346 | } |
| 14347 | |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 14348 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
| 14349 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); |
| 14350 | tid_conf->rtscts = |
| 14351 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); |
| 14352 | } |
| 14353 | |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 14354 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
| 14355 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); |
| 14356 | tid_conf->amsdu = |
| 14357 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); |
| 14358 | } |
| 14359 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14360 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
| 14361 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; |
| 14362 | |
| 14363 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); |
| 14364 | |
| 14365 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { |
| 14366 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; |
| 14367 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 14368 | &tid_conf->txrate_mask, dev); |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14369 | if (err) |
| 14370 | return err; |
| 14371 | |
| 14372 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); |
| 14373 | } |
| 14374 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); |
| 14375 | } |
| 14376 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14377 | if (peer) |
| 14378 | mask = rdev->wiphy.tid_config_support.peer; |
| 14379 | else |
| 14380 | mask = rdev->wiphy.tid_config_support.vif; |
| 14381 | |
| 14382 | if (tid_conf->mask & ~mask) { |
| 14383 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14384 | return -ENOTSUPP; |
| 14385 | } |
| 14386 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14387 | return 0; |
| 14388 | } |
| 14389 | |
| 14390 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14391 | struct genl_info *info) |
| 14392 | { |
| 14393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14394 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14395 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14396 | struct cfg80211_tid_config *tid_config; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14397 | struct nlattr *tid; |
| 14398 | int conf_idx = 0, rem_conf; |
| 14399 | int ret = -EINVAL; |
| 14400 | u32 num_conf = 0; |
| 14401 | |
| 14402 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14403 | return -EINVAL; |
| 14404 | |
| 14405 | if (!rdev->ops->set_tid_config) |
| 14406 | return -EOPNOTSUPP; |
| 14407 | |
| 14408 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14409 | rem_conf) |
| 14410 | num_conf++; |
| 14411 | |
| 14412 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14413 | GFP_KERNEL); |
| 14414 | if (!tid_config) |
| 14415 | return -ENOMEM; |
| 14416 | |
| 14417 | tid_config->n_tid_conf = num_conf; |
| 14418 | |
| 14419 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14420 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14421 | |
| 14422 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14423 | rem_conf) { |
| 14424 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14425 | tid, NULL, NULL); |
| 14426 | |
| 14427 | if (ret) |
| 14428 | goto bad_tid_conf; |
| 14429 | |
| 14430 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14431 | &tid_config->tid_conf[conf_idx], |
| 14432 | info, tid_config->peer); |
| 14433 | if (ret) |
| 14434 | goto bad_tid_conf; |
| 14435 | |
| 14436 | conf_idx++; |
| 14437 | } |
| 14438 | |
| 14439 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 14440 | |
| 14441 | bad_tid_conf: |
| 14442 | kfree(tid_config); |
| 14443 | return ret; |
| 14444 | } |
| 14445 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14446 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 14447 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 14448 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14449 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 14450 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 14451 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14452 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14453 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14454 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 14455 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14456 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14457 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14458 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14459 | struct genl_info *info) |
| 14460 | { |
| 14461 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14462 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14463 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14464 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 14465 | |
| 14466 | if (rtnl) |
| 14467 | rtnl_lock(); |
| 14468 | |
| 14469 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 14470 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14471 | if (IS_ERR(rdev)) { |
| 14472 | if (rtnl) |
| 14473 | rtnl_unlock(); |
| 14474 | return PTR_ERR(rdev); |
| 14475 | } |
| 14476 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14477 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 14478 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14479 | ASSERT_RTNL(); |
| 14480 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14481 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 14482 | info->attrs); |
| 14483 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14484 | if (rtnl) |
| 14485 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14486 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14487 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14488 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14489 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14490 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14491 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14492 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 14493 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14494 | if (rtnl) |
| 14495 | rtnl_unlock(); |
| 14496 | return -EINVAL; |
| 14497 | } |
| 14498 | |
| 14499 | info->user_ptr[1] = dev; |
| 14500 | } else { |
| 14501 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14502 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14503 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14504 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 14505 | !wdev_running(wdev)) { |
| 14506 | if (rtnl) |
| 14507 | rtnl_unlock(); |
| 14508 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14509 | } |
| 14510 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14511 | if (dev) |
| 14512 | dev_hold(dev); |
| 14513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14514 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14515 | } |
| 14516 | |
| 14517 | return 0; |
| 14518 | } |
| 14519 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14520 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14521 | struct genl_info *info) |
| 14522 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14523 | if (info->user_ptr[1]) { |
| 14524 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14525 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 14526 | |
| 14527 | if (wdev->netdev) |
| 14528 | dev_put(wdev->netdev); |
| 14529 | } else { |
| 14530 | dev_put(info->user_ptr[1]); |
| 14531 | } |
| 14532 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14533 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14534 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 14535 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14536 | |
| 14537 | /* If needed, clear the netlink message payload from the SKB |
| 14538 | * as it might contain key data that shouldn't stick around on |
| 14539 | * the heap after the SKB is freed. The netlink message header |
| 14540 | * is still needed for further processing, so leave it intact. |
| 14541 | */ |
| 14542 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 14543 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 14544 | |
| 14545 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 14546 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14547 | } |
| 14548 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 14549 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14550 | { |
| 14551 | .cmd = NL80211_CMD_GET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14552 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14553 | .doit = nl80211_get_wiphy, |
| 14554 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 14555 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14556 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14557 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14558 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14559 | }, |
| 14560 | { |
| 14561 | .cmd = NL80211_CMD_SET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14562 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14563 | .doit = nl80211_set_wiphy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14564 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14565 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14566 | }, |
| 14567 | { |
| 14568 | .cmd = NL80211_CMD_GET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14569 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14570 | .doit = nl80211_get_interface, |
| 14571 | .dumpit = nl80211_dump_interface, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14572 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14573 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14574 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14575 | }, |
| 14576 | { |
| 14577 | .cmd = NL80211_CMD_SET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14578 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14579 | .doit = nl80211_set_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14580 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14581 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14582 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14583 | }, |
| 14584 | { |
| 14585 | .cmd = NL80211_CMD_NEW_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14586 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14587 | .doit = nl80211_new_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14588 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14589 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14590 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14591 | }, |
| 14592 | { |
| 14593 | .cmd = NL80211_CMD_DEL_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14594 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14595 | .doit = nl80211_del_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14596 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 14597 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14598 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14599 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14600 | { |
| 14601 | .cmd = NL80211_CMD_GET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14602 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14603 | .doit = nl80211_get_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14604 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14605 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14606 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14607 | }, |
| 14608 | { |
| 14609 | .cmd = NL80211_CMD_SET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14610 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14611 | .doit = nl80211_set_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14612 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14614 | NL80211_FLAG_NEED_RTNL | |
| 14615 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14616 | }, |
| 14617 | { |
| 14618 | .cmd = NL80211_CMD_NEW_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14619 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14620 | .doit = nl80211_new_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14621 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14623 | NL80211_FLAG_NEED_RTNL | |
| 14624 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14625 | }, |
| 14626 | { |
| 14627 | .cmd = NL80211_CMD_DEL_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14628 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14629 | .doit = nl80211_del_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14630 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14632 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14633 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14634 | { |
| 14635 | .cmd = NL80211_CMD_SET_BEACON, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14636 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14637 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14638 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14640 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14641 | }, |
| 14642 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14643 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14644 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14645 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14646 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14648 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14649 | }, |
| 14650 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14651 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14652 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14653 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14654 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14656 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14657 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14658 | { |
| 14659 | .cmd = NL80211_CMD_GET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14660 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14661 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14662 | .dumpit = nl80211_dump_station, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14663 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14664 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14665 | }, |
| 14666 | { |
| 14667 | .cmd = NL80211_CMD_SET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14668 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14669 | .doit = nl80211_set_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14670 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14672 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14673 | }, |
| 14674 | { |
| 14675 | .cmd = NL80211_CMD_NEW_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14676 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14677 | .doit = nl80211_new_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14678 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14680 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14681 | }, |
| 14682 | { |
| 14683 | .cmd = NL80211_CMD_DEL_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14684 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14685 | .doit = nl80211_del_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14686 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14688 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14689 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14690 | { |
| 14691 | .cmd = NL80211_CMD_GET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14692 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14693 | .doit = nl80211_get_mpath, |
| 14694 | .dumpit = nl80211_dump_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14695 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14696 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14697 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14698 | }, |
| 14699 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14700 | .cmd = NL80211_CMD_GET_MPP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14701 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14702 | .doit = nl80211_get_mpp, |
| 14703 | .dumpit = nl80211_dump_mpp, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14704 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14705 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14706 | NL80211_FLAG_NEED_RTNL, |
| 14707 | }, |
| 14708 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14709 | .cmd = NL80211_CMD_SET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14710 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14711 | .doit = nl80211_set_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14712 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14713 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14714 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14715 | }, |
| 14716 | { |
| 14717 | .cmd = NL80211_CMD_NEW_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14718 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14719 | .doit = nl80211_new_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14720 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14721 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14722 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14723 | }, |
| 14724 | { |
| 14725 | .cmd = NL80211_CMD_DEL_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14726 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14727 | .doit = nl80211_del_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14728 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14729 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14730 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14731 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14732 | { |
| 14733 | .cmd = NL80211_CMD_SET_BSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14734 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14735 | .doit = nl80211_set_bss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14736 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14738 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14739 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14740 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14741 | .cmd = NL80211_CMD_GET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14742 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14743 | .doit = nl80211_get_reg_do, |
| 14744 | .dumpit = nl80211_get_reg_dump, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14745 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14746 | /* can be retrieved by unprivileged users */ |
| 14747 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14748 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14749 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14750 | .cmd = NL80211_CMD_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14751 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14752 | .doit = nl80211_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14754 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14755 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14756 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14757 | { |
| 14758 | .cmd = NL80211_CMD_REQ_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14759 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14760 | .doit = nl80211_req_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14761 | .flags = GENL_ADMIN_PERM, |
| 14762 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14763 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14764 | .cmd = NL80211_CMD_RELOAD_REGDB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14765 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14766 | .doit = nl80211_reload_regdb, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14767 | .flags = GENL_ADMIN_PERM, |
| 14768 | }, |
| 14769 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14770 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14771 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14772 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14773 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14775 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14776 | }, |
| 14777 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14778 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14779 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14780 | .doit = nl80211_update_mesh_config, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14781 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14782 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14783 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14784 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 14785 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14786 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14787 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14788 | .doit = nl80211_trigger_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14789 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14790 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14791 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14792 | }, |
| 14793 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14794 | .cmd = NL80211_CMD_ABORT_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14795 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14796 | .doit = nl80211_abort_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14797 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14798 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14799 | NL80211_FLAG_NEED_RTNL, |
| 14800 | }, |
| 14801 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14802 | .cmd = NL80211_CMD_GET_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14803 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14804 | .dumpit = nl80211_dump_scan, |
| 14805 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14806 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14807 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14808 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14809 | .doit = nl80211_start_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14810 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14812 | NL80211_FLAG_NEED_RTNL, |
| 14813 | }, |
| 14814 | { |
| 14815 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14816 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14817 | .doit = nl80211_stop_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14818 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14819 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14820 | NL80211_FLAG_NEED_RTNL, |
| 14821 | }, |
| 14822 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14823 | .cmd = NL80211_CMD_AUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14824 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14825 | .doit = nl80211_authenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14827 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14828 | NL80211_FLAG_NEED_RTNL | |
| 14829 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14830 | }, |
| 14831 | { |
| 14832 | .cmd = NL80211_CMD_ASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14833 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14834 | .doit = nl80211_associate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14835 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14837 | NL80211_FLAG_NEED_RTNL | |
| 14838 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14839 | }, |
| 14840 | { |
| 14841 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14842 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14843 | .doit = nl80211_deauthenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14844 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14845 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14846 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14847 | }, |
| 14848 | { |
| 14849 | .cmd = NL80211_CMD_DISASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14850 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14851 | .doit = nl80211_disassociate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14852 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14854 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14855 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14856 | { |
| 14857 | .cmd = NL80211_CMD_JOIN_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14858 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14859 | .doit = nl80211_join_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14860 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14862 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14863 | }, |
| 14864 | { |
| 14865 | .cmd = NL80211_CMD_LEAVE_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14866 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14867 | .doit = nl80211_leave_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14868 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14870 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14871 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14872 | #ifdef CONFIG_NL80211_TESTMODE |
| 14873 | { |
| 14874 | .cmd = NL80211_CMD_TESTMODE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14875 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14876 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 14877 | .dumpit = nl80211_testmode_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14878 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14879 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14880 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14881 | }, |
| 14882 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14883 | { |
| 14884 | .cmd = NL80211_CMD_CONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14885 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14886 | .doit = nl80211_connect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14887 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14889 | NL80211_FLAG_NEED_RTNL | |
| 14890 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14891 | }, |
| 14892 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14893 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14894 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14895 | .doit = nl80211_update_connect_params, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14896 | .flags = GENL_ADMIN_PERM, |
| 14897 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14898 | NL80211_FLAG_NEED_RTNL | |
| 14899 | NL80211_FLAG_CLEAR_SKB, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14900 | }, |
| 14901 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14902 | .cmd = NL80211_CMD_DISCONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14903 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14904 | .doit = nl80211_disconnect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14905 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14906 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14907 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14908 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14909 | { |
| 14910 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14911 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14912 | .doit = nl80211_wiphy_netns, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14913 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14914 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14915 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14916 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14917 | { |
| 14918 | .cmd = NL80211_CMD_GET_SURVEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14919 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14920 | .dumpit = nl80211_dump_survey, |
| 14921 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14922 | { |
| 14923 | .cmd = NL80211_CMD_SET_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14924 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14925 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14926 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14927 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14928 | NL80211_FLAG_NEED_RTNL | |
| 14929 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14930 | }, |
| 14931 | { |
| 14932 | .cmd = NL80211_CMD_DEL_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14933 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14934 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14935 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14936 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14937 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14938 | }, |
| 14939 | { |
| 14940 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14941 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14942 | .doit = nl80211_flush_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14943 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14944 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14945 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14946 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14947 | { |
| 14948 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14949 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14950 | .doit = nl80211_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14951 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14952 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14953 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14954 | }, |
| 14955 | { |
| 14956 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14957 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14958 | .doit = nl80211_cancel_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14959 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14960 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14961 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14962 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14963 | { |
| 14964 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14965 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14966 | .doit = nl80211_set_tx_bitrate_mask, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14967 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14968 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14969 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14970 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14971 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14972 | .cmd = NL80211_CMD_REGISTER_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14973 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14974 | .doit = nl80211_register_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14975 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14976 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14977 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14978 | }, |
| 14979 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14980 | .cmd = NL80211_CMD_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14981 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14982 | .doit = nl80211_tx_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14983 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14984 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14985 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14986 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14987 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14988 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14989 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14990 | .doit = nl80211_tx_mgmt_cancel_wait, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14991 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14992 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14993 | NL80211_FLAG_NEED_RTNL, |
| 14994 | }, |
| 14995 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14996 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14997 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14998 | .doit = nl80211_set_power_save, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14999 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15000 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15001 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15002 | }, |
| 15003 | { |
| 15004 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15005 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15006 | .doit = nl80211_get_power_save, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15007 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15008 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15009 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15010 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15011 | { |
| 15012 | .cmd = NL80211_CMD_SET_CQM, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15013 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15014 | .doit = nl80211_set_cqm, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15015 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15016 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15017 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15018 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15019 | { |
| 15020 | .cmd = NL80211_CMD_SET_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15021 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15022 | .doit = nl80211_set_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15023 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15024 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15025 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15026 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15027 | { |
| 15028 | .cmd = NL80211_CMD_SET_WDS_PEER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15029 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15030 | .doit = nl80211_set_wds_peer, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15031 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 15032 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15033 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15034 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15035 | { |
| 15036 | .cmd = NL80211_CMD_JOIN_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15037 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15038 | .doit = nl80211_join_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15039 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15040 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15041 | NL80211_FLAG_NEED_RTNL, |
| 15042 | }, |
| 15043 | { |
| 15044 | .cmd = NL80211_CMD_LEAVE_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15045 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15046 | .doit = nl80211_leave_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15047 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15048 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15049 | NL80211_FLAG_NEED_RTNL, |
| 15050 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15051 | { |
| 15052 | .cmd = NL80211_CMD_JOIN_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15053 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15054 | .doit = nl80211_join_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15055 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15056 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15057 | NL80211_FLAG_NEED_RTNL, |
| 15058 | }, |
| 15059 | { |
| 15060 | .cmd = NL80211_CMD_LEAVE_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15061 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15062 | .doit = nl80211_leave_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15063 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15064 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15065 | NL80211_FLAG_NEED_RTNL, |
| 15066 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15067 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15068 | { |
| 15069 | .cmd = NL80211_CMD_GET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15070 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15071 | .doit = nl80211_get_wowlan, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15072 | /* can be retrieved by unprivileged users */ |
| 15073 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15074 | NL80211_FLAG_NEED_RTNL, |
| 15075 | }, |
| 15076 | { |
| 15077 | .cmd = NL80211_CMD_SET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15078 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15079 | .doit = nl80211_set_wowlan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15080 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15081 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15082 | NL80211_FLAG_NEED_RTNL, |
| 15083 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15084 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15085 | { |
| 15086 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15087 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15088 | .doit = nl80211_set_rekey_data, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15089 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15091 | NL80211_FLAG_NEED_RTNL | |
| 15092 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15093 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15094 | { |
| 15095 | .cmd = NL80211_CMD_TDLS_MGMT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15096 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15097 | .doit = nl80211_tdls_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15098 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15099 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15100 | NL80211_FLAG_NEED_RTNL, |
| 15101 | }, |
| 15102 | { |
| 15103 | .cmd = NL80211_CMD_TDLS_OPER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15104 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15105 | .doit = nl80211_tdls_oper, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15106 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15107 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15108 | NL80211_FLAG_NEED_RTNL, |
| 15109 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15110 | { |
| 15111 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15112 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15113 | .doit = nl80211_register_unexpected_frame, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15114 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15115 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15116 | NL80211_FLAG_NEED_RTNL, |
| 15117 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15118 | { |
| 15119 | .cmd = NL80211_CMD_PROBE_CLIENT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15120 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15121 | .doit = nl80211_probe_client, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15122 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15123 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15124 | NL80211_FLAG_NEED_RTNL, |
| 15125 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15126 | { |
| 15127 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15128 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15129 | .doit = nl80211_register_beacons, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15130 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15131 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15132 | NL80211_FLAG_NEED_RTNL, |
| 15133 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15134 | { |
| 15135 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15136 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15137 | .doit = nl80211_set_noack_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15138 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15139 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15140 | NL80211_FLAG_NEED_RTNL, |
| 15141 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15142 | { |
| 15143 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15144 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15145 | .doit = nl80211_start_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15146 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15147 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15148 | NL80211_FLAG_NEED_RTNL, |
| 15149 | }, |
| 15150 | { |
| 15151 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15152 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15153 | .doit = nl80211_stop_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15154 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15155 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15156 | NL80211_FLAG_NEED_RTNL, |
| 15157 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15158 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15159 | .cmd = NL80211_CMD_START_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15160 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15161 | .doit = nl80211_start_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15162 | .flags = GENL_ADMIN_PERM, |
| 15163 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15164 | NL80211_FLAG_NEED_RTNL, |
| 15165 | }, |
| 15166 | { |
| 15167 | .cmd = NL80211_CMD_STOP_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15168 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15169 | .doit = nl80211_stop_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15170 | .flags = GENL_ADMIN_PERM, |
| 15171 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15172 | NL80211_FLAG_NEED_RTNL, |
| 15173 | }, |
| 15174 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15175 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15176 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15177 | .doit = nl80211_nan_add_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15178 | .flags = GENL_ADMIN_PERM, |
| 15179 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15180 | NL80211_FLAG_NEED_RTNL, |
| 15181 | }, |
| 15182 | { |
| 15183 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15184 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15185 | .doit = nl80211_nan_del_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15186 | .flags = GENL_ADMIN_PERM, |
| 15187 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15188 | NL80211_FLAG_NEED_RTNL, |
| 15189 | }, |
| 15190 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15191 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15192 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15193 | .doit = nl80211_nan_change_config, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15194 | .flags = GENL_ADMIN_PERM, |
| 15195 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15196 | NL80211_FLAG_NEED_RTNL, |
| 15197 | }, |
| 15198 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15199 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15200 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15201 | .doit = nl80211_set_mcast_rate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15202 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15203 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15204 | NL80211_FLAG_NEED_RTNL, |
| 15205 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15206 | { |
| 15207 | .cmd = NL80211_CMD_SET_MAC_ACL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15208 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15209 | .doit = nl80211_set_mac_acl, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15210 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15211 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15212 | NL80211_FLAG_NEED_RTNL, |
| 15213 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15214 | { |
| 15215 | .cmd = NL80211_CMD_RADAR_DETECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15216 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15217 | .doit = nl80211_start_radar_detection, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15218 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15220 | NL80211_FLAG_NEED_RTNL, |
| 15221 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15222 | { |
| 15223 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15224 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15225 | .doit = nl80211_get_protocol_features, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15226 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15227 | { |
| 15228 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15229 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15230 | .doit = nl80211_update_ft_ies, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15231 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15232 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15233 | NL80211_FLAG_NEED_RTNL, |
| 15234 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15235 | { |
| 15236 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15237 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15238 | .doit = nl80211_crit_protocol_start, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15239 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15240 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15241 | NL80211_FLAG_NEED_RTNL, |
| 15242 | }, |
| 15243 | { |
| 15244 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15245 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15246 | .doit = nl80211_crit_protocol_stop, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15247 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15248 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15249 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15250 | }, |
| 15251 | { |
| 15252 | .cmd = NL80211_CMD_GET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15253 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15254 | .doit = nl80211_get_coalesce, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15255 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15256 | NL80211_FLAG_NEED_RTNL, |
| 15257 | }, |
| 15258 | { |
| 15259 | .cmd = NL80211_CMD_SET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15260 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15261 | .doit = nl80211_set_coalesce, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15262 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15263 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15264 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15265 | }, |
| 15266 | { |
| 15267 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15268 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15269 | .doit = nl80211_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15270 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15271 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15272 | NL80211_FLAG_NEED_RTNL, |
| 15273 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15274 | { |
| 15275 | .cmd = NL80211_CMD_VENDOR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15276 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15277 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 15278 | .dumpit = nl80211_vendor_cmd_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15279 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15280 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15281 | NL80211_FLAG_NEED_RTNL | |
| 15282 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15283 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15284 | { |
| 15285 | .cmd = NL80211_CMD_SET_QOS_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15286 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15287 | .doit = nl80211_set_qos_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15288 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15289 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15290 | NL80211_FLAG_NEED_RTNL, |
| 15291 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15292 | { |
| 15293 | .cmd = NL80211_CMD_ADD_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15294 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15295 | .doit = nl80211_add_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15296 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15297 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15298 | NL80211_FLAG_NEED_RTNL, |
| 15299 | }, |
| 15300 | { |
| 15301 | .cmd = NL80211_CMD_DEL_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15302 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15303 | .doit = nl80211_del_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15304 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15305 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15306 | NL80211_FLAG_NEED_RTNL, |
| 15307 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15308 | { |
| 15309 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15310 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15311 | .doit = nl80211_tdls_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15312 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15313 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15314 | NL80211_FLAG_NEED_RTNL, |
| 15315 | }, |
| 15316 | { |
| 15317 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15318 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15319 | .doit = nl80211_tdls_cancel_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15320 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15321 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15322 | NL80211_FLAG_NEED_RTNL, |
| 15323 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15324 | { |
| 15325 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15326 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15327 | .doit = nl80211_set_multicast_to_unicast, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15328 | .flags = GENL_UNS_ADMIN_PERM, |
| 15329 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15330 | NL80211_FLAG_NEED_RTNL, |
| 15331 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15332 | { |
| 15333 | .cmd = NL80211_CMD_SET_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15334 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15335 | .doit = nl80211_set_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15337 | NL80211_FLAG_NEED_RTNL | |
| 15338 | NL80211_FLAG_CLEAR_SKB, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15339 | }, |
| 15340 | { |
| 15341 | .cmd = NL80211_CMD_DEL_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15342 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15343 | .doit = nl80211_del_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15345 | NL80211_FLAG_NEED_RTNL, |
| 15346 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15347 | { |
| 15348 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15349 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15350 | .doit = nl80211_external_auth, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15351 | .flags = GENL_ADMIN_PERM, |
| 15352 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15353 | NL80211_FLAG_NEED_RTNL, |
| 15354 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15355 | { |
| 15356 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15357 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15358 | .doit = nl80211_tx_control_port, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15359 | .flags = GENL_UNS_ADMIN_PERM, |
| 15360 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15361 | NL80211_FLAG_NEED_RTNL, |
| 15362 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15363 | { |
| 15364 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15365 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15366 | .doit = nl80211_get_ftm_responder_stats, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15367 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15368 | NL80211_FLAG_NEED_RTNL, |
| 15369 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15370 | { |
| 15371 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15372 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15373 | .doit = nl80211_pmsr_start, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15374 | .flags = GENL_UNS_ADMIN_PERM, |
| 15375 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15376 | NL80211_FLAG_NEED_RTNL, |
| 15377 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15378 | { |
| 15379 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15380 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15381 | .doit = nl80211_notify_radar_detection, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15382 | .flags = GENL_UNS_ADMIN_PERM, |
| 15383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15384 | NL80211_FLAG_NEED_RTNL, |
| 15385 | }, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 15386 | { |
| 15387 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 15388 | .doit = nl80211_update_owe_info, |
| 15389 | .flags = GENL_ADMIN_PERM, |
| 15390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15391 | NL80211_FLAG_NEED_RTNL, |
| 15392 | }, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 15393 | { |
| 15394 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 15395 | .doit = nl80211_probe_mesh_link, |
| 15396 | .flags = GENL_UNS_ADMIN_PERM, |
| 15397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15398 | NL80211_FLAG_NEED_RTNL, |
| 15399 | }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 15400 | { |
| 15401 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 15402 | .doit = nl80211_set_tid_config, |
| 15403 | .flags = GENL_UNS_ADMIN_PERM, |
| 15404 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15405 | NL80211_FLAG_NEED_RTNL, |
| 15406 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15407 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15408 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15409 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15410 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 15411 | .hdrsize = 0, /* no private header */ |
| 15412 | .version = 1, /* no particular meaning now */ |
| 15413 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 3b0f31f | 2019-03-21 22:51:02 +0100 | [diff] [blame] | 15414 | .policy = nl80211_policy, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15415 | .netnsok = true, |
| 15416 | .pre_doit = nl80211_pre_doit, |
| 15417 | .post_doit = nl80211_post_doit, |
| 15418 | .module = THIS_MODULE, |
| 15419 | .ops = nl80211_ops, |
| 15420 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 15421 | .mcgrps = nl80211_mcgrps, |
| 15422 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 15423 | .parallel_ops = true, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15424 | }; |
| 15425 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15426 | /* notification functions */ |
| 15427 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15428 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 15429 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15430 | { |
| 15431 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 15432 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15433 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15434 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 15435 | cmd != NL80211_CMD_DEL_WIPHY); |
| 15436 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15437 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15438 | if (!msg) |
| 15439 | return; |
| 15440 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15441 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15442 | nlmsg_free(msg); |
| 15443 | return; |
| 15444 | } |
| 15445 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15446 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15447 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15448 | } |
| 15449 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15450 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 15451 | struct wireless_dev *wdev, |
| 15452 | enum nl80211_commands cmd) |
| 15453 | { |
| 15454 | struct sk_buff *msg; |
| 15455 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15457 | if (!msg) |
| 15458 | return; |
| 15459 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 15460 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15461 | nlmsg_free(msg); |
| 15462 | return; |
| 15463 | } |
| 15464 | |
| 15465 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15466 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15467 | } |
| 15468 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15469 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 15470 | struct cfg80211_registered_device *rdev) |
| 15471 | { |
| 15472 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 15473 | struct nlattr *nest; |
| 15474 | int i; |
| 15475 | |
| 15476 | if (WARN_ON(!req)) |
| 15477 | return 0; |
| 15478 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15479 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15480 | if (!nest) |
| 15481 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15482 | for (i = 0; i < req->n_ssids; i++) { |
| 15483 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 15484 | goto nla_put_failure; |
| 15485 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15486 | nla_nest_end(msg, nest); |
| 15487 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15488 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
| 15489 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); |
| 15490 | if (!nest) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15491 | goto nla_put_failure; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15492 | for (i = 0; i < req->n_channels; i++) { |
| 15493 | if (nla_put_u32(msg, i, |
| 15494 | ieee80211_channel_to_khz(req->channels[i]))) |
| 15495 | goto nla_put_failure; |
| 15496 | } |
| 15497 | nla_nest_end(msg, nest); |
| 15498 | } else { |
| 15499 | nest = nla_nest_start_noflag(msg, |
| 15500 | NL80211_ATTR_SCAN_FREQUENCIES); |
| 15501 | if (!nest) |
| 15502 | goto nla_put_failure; |
| 15503 | for (i = 0; i < req->n_channels; i++) { |
| 15504 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 15505 | goto nla_put_failure; |
| 15506 | } |
| 15507 | nla_nest_end(msg, nest); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15508 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15509 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15510 | if (req->ie && |
| 15511 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 15512 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15513 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15514 | if (req->flags && |
| 15515 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 15516 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 15517 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15518 | if (req->info.scan_start_tsf && |
| 15519 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 15520 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 15521 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 15522 | req->info.tsf_bssid))) |
| 15523 | goto nla_put_failure; |
| 15524 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15525 | return 0; |
| 15526 | nla_put_failure: |
| 15527 | return -ENOBUFS; |
| 15528 | } |
| 15529 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15530 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15531 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15532 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15533 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15534 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15535 | { |
| 15536 | void *hdr; |
| 15537 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15538 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15539 | if (!hdr) |
| 15540 | return -1; |
| 15541 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15542 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15543 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15544 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15545 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15546 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15547 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15548 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15549 | /* ignore errors and send incomplete event anyway */ |
| 15550 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15551 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15552 | genlmsg_end(msg, hdr); |
| 15553 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15554 | |
| 15555 | nla_put_failure: |
| 15556 | genlmsg_cancel(msg, hdr); |
| 15557 | return -EMSGSIZE; |
| 15558 | } |
| 15559 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15560 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15561 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15562 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15563 | { |
| 15564 | void *hdr; |
| 15565 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15566 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15567 | if (!hdr) |
| 15568 | return -1; |
| 15569 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15570 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 15571 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 15572 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 15573 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 15574 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15575 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15576 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15577 | genlmsg_end(msg, hdr); |
| 15578 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15579 | |
| 15580 | nla_put_failure: |
| 15581 | genlmsg_cancel(msg, hdr); |
| 15582 | return -EMSGSIZE; |
| 15583 | } |
| 15584 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15585 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15586 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15587 | { |
| 15588 | struct sk_buff *msg; |
| 15589 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15591 | if (!msg) |
| 15592 | return; |
| 15593 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15594 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15595 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 15596 | nlmsg_free(msg); |
| 15597 | return; |
| 15598 | } |
| 15599 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15600 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15601 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15602 | } |
| 15603 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15604 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 15605 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15606 | { |
| 15607 | struct sk_buff *msg; |
| 15608 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15609 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15610 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15611 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15612 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15613 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15614 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 15615 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15616 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15617 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15618 | } |
| 15619 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15620 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15621 | } |
| 15622 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15623 | /* send message created by nl80211_build_scan_msg() */ |
| 15624 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 15625 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15626 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15627 | if (!msg) |
| 15628 | return; |
| 15629 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15630 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15631 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15632 | } |
| 15633 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15634 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15635 | { |
| 15636 | struct sk_buff *msg; |
| 15637 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15639 | if (!msg) |
| 15640 | return; |
| 15641 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15642 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15643 | nlmsg_free(msg); |
| 15644 | return; |
| 15645 | } |
| 15646 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15647 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15648 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15649 | } |
| 15650 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15651 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 15652 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15653 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15654 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15655 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 15656 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15658 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 15659 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15660 | NL80211_REGDOM_TYPE_WORLD)) |
| 15661 | goto nla_put_failure; |
| 15662 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 15663 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15664 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 15665 | goto nla_put_failure; |
| 15666 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 15667 | request->intersect) { |
| 15668 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15669 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 15670 | goto nla_put_failure; |
| 15671 | } else { |
| 15672 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15673 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 15674 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 15675 | request->alpha2)) |
| 15676 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15677 | } |
| 15678 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15679 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 15680 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 15681 | |
| 15682 | if (wiphy && |
| 15683 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 15684 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 15685 | |
| 15686 | if (wiphy && |
| 15687 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 15688 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 15689 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15690 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15691 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15692 | return true; |
| 15693 | |
| 15694 | nla_put_failure: |
| 15695 | return false; |
| 15696 | } |
| 15697 | |
| 15698 | /* |
| 15699 | * This can happen on global regulatory changes or device specific settings |
| 15700 | * based on custom regulatory domains. |
| 15701 | */ |
| 15702 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 15703 | struct regulatory_request *request) |
| 15704 | { |
| 15705 | struct sk_buff *msg; |
| 15706 | void *hdr; |
| 15707 | |
| 15708 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15709 | if (!msg) |
| 15710 | return; |
| 15711 | |
| 15712 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15713 | if (!hdr) |
| 15714 | goto nla_put_failure; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15715 | |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15716 | if (!nl80211_reg_change_event_fill(msg, request)) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15717 | goto nla_put_failure; |
| 15718 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15719 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15720 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15721 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15722 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15723 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15724 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15725 | |
| 15726 | return; |
| 15727 | |
| 15728 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15729 | nlmsg_free(msg); |
| 15730 | } |
| 15731 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15732 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 15733 | struct net_device *netdev, |
| 15734 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15735 | enum nl80211_commands cmd, gfp_t gfp, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15736 | int uapsd_queues, const u8 *req_ies, |
| 15737 | size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15738 | { |
| 15739 | struct sk_buff *msg; |
| 15740 | void *hdr; |
| 15741 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15742 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15743 | if (!msg) |
| 15744 | return; |
| 15745 | |
| 15746 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15747 | if (!hdr) { |
| 15748 | nlmsg_free(msg); |
| 15749 | return; |
| 15750 | } |
| 15751 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15752 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15753 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15754 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15755 | (req_ies && |
| 15756 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15757 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15758 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15759 | if (uapsd_queues >= 0) { |
| 15760 | struct nlattr *nla_wmm = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15761 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15762 | if (!nla_wmm) |
| 15763 | goto nla_put_failure; |
| 15764 | |
| 15765 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 15766 | uapsd_queues)) |
| 15767 | goto nla_put_failure; |
| 15768 | |
| 15769 | nla_nest_end(msg, nla_wmm); |
| 15770 | } |
| 15771 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15772 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15773 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15774 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15775 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15776 | return; |
| 15777 | |
| 15778 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15779 | nlmsg_free(msg); |
| 15780 | } |
| 15781 | |
| 15782 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15783 | struct net_device *netdev, const u8 *buf, |
| 15784 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15785 | { |
| 15786 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15787 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15788 | } |
| 15789 | |
| 15790 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 15791 | struct net_device *netdev, const u8 *buf, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15792 | size_t len, gfp_t gfp, int uapsd_queues, |
| 15793 | const u8 *req_ies, size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15794 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15795 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15796 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
| 15797 | req_ies, req_ies_len); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15798 | } |
| 15799 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15800 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15801 | struct net_device *netdev, const u8 *buf, |
| 15802 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15803 | { |
| 15804 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15805 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15806 | } |
| 15807 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15808 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 15809 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15810 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15811 | { |
| 15812 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15813 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15814 | } |
| 15815 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15816 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 15817 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15818 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15819 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15820 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15821 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15822 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 15823 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15824 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15825 | if (WARN_ON(len < 2)) |
| 15826 | return; |
| 15827 | |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15828 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15829 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15830 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15831 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15832 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
| 15833 | if (wdev->unprot_beacon_reported && |
| 15834 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) |
| 15835 | return; |
| 15836 | cmd = NL80211_CMD_UNPROT_BEACON; |
| 15837 | wdev->unprot_beacon_reported = jiffies; |
| 15838 | } else { |
| 15839 | return; |
| 15840 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15841 | |
| 15842 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15843 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
| 15844 | NULL, 0); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15845 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15846 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15847 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 15848 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 15849 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15850 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15851 | { |
| 15852 | struct sk_buff *msg; |
| 15853 | void *hdr; |
| 15854 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15855 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15856 | if (!msg) |
| 15857 | return; |
| 15858 | |
| 15859 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15860 | if (!hdr) { |
| 15861 | nlmsg_free(msg); |
| 15862 | return; |
| 15863 | } |
| 15864 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15865 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15866 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15867 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 15868 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 15869 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15870 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15871 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15872 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15873 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15874 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15875 | return; |
| 15876 | |
| 15877 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15878 | nlmsg_free(msg); |
| 15879 | } |
| 15880 | |
| 15881 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15882 | struct net_device *netdev, const u8 *addr, |
| 15883 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15884 | { |
| 15885 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15886 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15887 | } |
| 15888 | |
| 15889 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15890 | struct net_device *netdev, const u8 *addr, |
| 15891 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15892 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15893 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 15894 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15895 | } |
| 15896 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15897 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15898 | struct net_device *netdev, |
| 15899 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15900 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15901 | { |
| 15902 | struct sk_buff *msg; |
| 15903 | void *hdr; |
| 15904 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15905 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15906 | cr->fils.kek_len + cr->fils.pmk_len + |
| 15907 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15908 | if (!msg) |
| 15909 | return; |
| 15910 | |
| 15911 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 15912 | if (!hdr) { |
| 15913 | nlmsg_free(msg); |
| 15914 | return; |
| 15915 | } |
| 15916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15917 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15918 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15919 | (cr->bssid && |
| 15920 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 15921 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15922 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 15923 | cr->status) || |
| 15924 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15925 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15926 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 15927 | cr->timeout_reason))) || |
| 15928 | (cr->req_ie && |
| 15929 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 15930 | (cr->resp_ie && |
| 15931 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15932 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15933 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15934 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15935 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15936 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15937 | ((cr->fils.kek && |
| 15938 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 15939 | cr->fils.kek)) || |
| 15940 | (cr->fils.pmk && |
| 15941 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 15942 | (cr->fils.pmkid && |
| 15943 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15944 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15945 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15946 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15947 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15948 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15949 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15950 | return; |
| 15951 | |
| 15952 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15953 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15954 | } |
| 15955 | |
| 15956 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15957 | struct net_device *netdev, |
| 15958 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15959 | { |
| 15960 | struct sk_buff *msg; |
| 15961 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15962 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15963 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15964 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 15965 | info->fils.kek_len + info->fils.pmk_len + |
| 15966 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15967 | if (!msg) |
| 15968 | return; |
| 15969 | |
| 15970 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 15971 | if (!hdr) { |
| 15972 | nlmsg_free(msg); |
| 15973 | return; |
| 15974 | } |
| 15975 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15976 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15977 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15978 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15979 | (info->req_ie && |
| 15980 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 15981 | info->req_ie)) || |
| 15982 | (info->resp_ie && |
| 15983 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15984 | info->resp_ie)) || |
| 15985 | (info->fils.update_erp_next_seq_num && |
| 15986 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 15987 | info->fils.erp_next_seq_num)) || |
| 15988 | (info->fils.kek && |
| 15989 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 15990 | info->fils.kek)) || |
| 15991 | (info->fils.pmk && |
| 15992 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 15993 | (info->fils.pmkid && |
| 15994 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15995 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15996 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15997 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15998 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15999 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16000 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16001 | return; |
| 16002 | |
| 16003 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16004 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16005 | } |
| 16006 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16007 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 16008 | struct net_device *netdev, const u8 *bssid) |
| 16009 | { |
| 16010 | struct sk_buff *msg; |
| 16011 | void *hdr; |
| 16012 | |
| 16013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16014 | if (!msg) |
| 16015 | return; |
| 16016 | |
| 16017 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 16018 | if (!hdr) { |
| 16019 | nlmsg_free(msg); |
| 16020 | return; |
| 16021 | } |
| 16022 | |
Chung-Hsien Hsu | f4d7599 | 2019-05-09 09:48:25 +0000 | [diff] [blame] | 16023 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16024 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16025 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16026 | goto nla_put_failure; |
| 16027 | |
| 16028 | genlmsg_end(msg, hdr); |
| 16029 | |
| 16030 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16031 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16032 | return; |
| 16033 | |
| 16034 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16035 | nlmsg_free(msg); |
| 16036 | } |
| 16037 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16038 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 16039 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 16040 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16041 | { |
| 16042 | struct sk_buff *msg; |
| 16043 | void *hdr; |
| 16044 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16045 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16046 | if (!msg) |
| 16047 | return; |
| 16048 | |
| 16049 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 16050 | if (!hdr) { |
| 16051 | nlmsg_free(msg); |
| 16052 | return; |
| 16053 | } |
| 16054 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16055 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16056 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 16057 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16058 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 16059 | (from_ap && |
| 16060 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 16061 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 16062 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16063 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16064 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16065 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16066 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16067 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16068 | return; |
| 16069 | |
| 16070 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16071 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16072 | } |
| 16073 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16074 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 16075 | struct net_device *netdev, const u8 *bssid, |
| 16076 | gfp_t gfp) |
| 16077 | { |
| 16078 | struct sk_buff *msg; |
| 16079 | void *hdr; |
| 16080 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16081 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16082 | if (!msg) |
| 16083 | return; |
| 16084 | |
| 16085 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 16086 | if (!hdr) { |
| 16087 | nlmsg_free(msg); |
| 16088 | return; |
| 16089 | } |
| 16090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16091 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16092 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16093 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16094 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16095 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16096 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16097 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16098 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16099 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16100 | return; |
| 16101 | |
| 16102 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16103 | nlmsg_free(msg); |
| 16104 | } |
| 16105 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16106 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 16107 | const u8 *ie, u8 ie_len, |
| 16108 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16109 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16110 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16111 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16112 | struct sk_buff *msg; |
| 16113 | void *hdr; |
| 16114 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16115 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 16116 | return; |
| 16117 | |
| 16118 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 16119 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16120 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16121 | if (!msg) |
| 16122 | return; |
| 16123 | |
| 16124 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 16125 | if (!hdr) { |
| 16126 | nlmsg_free(msg); |
| 16127 | return; |
| 16128 | } |
| 16129 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16131 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16132 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16133 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 16134 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 16135 | (sig_dbm && |
| 16136 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16137 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16138 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16139 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16140 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16141 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16142 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16143 | return; |
| 16144 | |
| 16145 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16146 | nlmsg_free(msg); |
| 16147 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16148 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16149 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16150 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 16151 | struct net_device *netdev, const u8 *addr, |
| 16152 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16153 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16154 | { |
| 16155 | struct sk_buff *msg; |
| 16156 | void *hdr; |
| 16157 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16158 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16159 | if (!msg) |
| 16160 | return; |
| 16161 | |
| 16162 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 16163 | if (!hdr) { |
| 16164 | nlmsg_free(msg); |
| 16165 | return; |
| 16166 | } |
| 16167 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16169 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16170 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 16171 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 16172 | (key_id != -1 && |
| 16173 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 16174 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 16175 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16176 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16177 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16178 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16179 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16180 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16181 | return; |
| 16182 | |
| 16183 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16184 | nlmsg_free(msg); |
| 16185 | } |
| 16186 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16187 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 16188 | struct ieee80211_channel *channel_before, |
| 16189 | struct ieee80211_channel *channel_after) |
| 16190 | { |
| 16191 | struct sk_buff *msg; |
| 16192 | void *hdr; |
| 16193 | struct nlattr *nl_freq; |
| 16194 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16195 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16196 | if (!msg) |
| 16197 | return; |
| 16198 | |
| 16199 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 16200 | if (!hdr) { |
| 16201 | nlmsg_free(msg); |
| 16202 | return; |
| 16203 | } |
| 16204 | |
| 16205 | /* |
| 16206 | * Since we are applying the beacon hint to a wiphy we know its |
| 16207 | * wiphy_idx is valid |
| 16208 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 16210 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16211 | |
| 16212 | /* Before */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16213 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16214 | if (!nl_freq) |
| 16215 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16216 | |
| 16217 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16218 | goto nla_put_failure; |
| 16219 | nla_nest_end(msg, nl_freq); |
| 16220 | |
| 16221 | /* After */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16222 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16223 | if (!nl_freq) |
| 16224 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16225 | |
| 16226 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16227 | goto nla_put_failure; |
| 16228 | nla_nest_end(msg, nl_freq); |
| 16229 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16230 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16231 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16232 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16233 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16234 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16235 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16236 | |
| 16237 | return; |
| 16238 | |
| 16239 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16240 | nlmsg_free(msg); |
| 16241 | } |
| 16242 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16243 | static void nl80211_send_remain_on_chan_event( |
| 16244 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16245 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16246 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16247 | unsigned int duration, gfp_t gfp) |
| 16248 | { |
| 16249 | struct sk_buff *msg; |
| 16250 | void *hdr; |
| 16251 | |
| 16252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16253 | if (!msg) |
| 16254 | return; |
| 16255 | |
| 16256 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16257 | if (!hdr) { |
| 16258 | nlmsg_free(msg); |
| 16259 | return; |
| 16260 | } |
| 16261 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16262 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16263 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16264 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16265 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16266 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16267 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16268 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 16269 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16270 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16271 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16272 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16273 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16274 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 16275 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 16276 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16277 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16278 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16279 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16280 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16281 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16282 | return; |
| 16283 | |
| 16284 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16285 | nlmsg_free(msg); |
| 16286 | } |
| 16287 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16288 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 16289 | struct ieee80211_channel *chan, |
| 16290 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16291 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16292 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16293 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16294 | |
| 16295 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16296 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16297 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16298 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16299 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16300 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16301 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16302 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 16303 | struct ieee80211_channel *chan, |
| 16304 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16305 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16306 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16307 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16308 | |
| 16309 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16310 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16311 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16312 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16313 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16314 | |
James Prestwood | 1c38c7f | 2019-06-12 12:35:09 -0700 | [diff] [blame] | 16315 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 16316 | struct ieee80211_channel *chan, |
| 16317 | gfp_t gfp) |
| 16318 | { |
| 16319 | struct wiphy *wiphy = wdev->wiphy; |
| 16320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16321 | |
| 16322 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 16323 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 16324 | rdev, wdev, cookie, chan, 0, gfp); |
| 16325 | } |
| 16326 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 16327 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16328 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 16329 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16330 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16331 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16332 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16333 | struct sk_buff *msg; |
| 16334 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16335 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 16336 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16338 | if (!msg) |
| 16339 | return; |
| 16340 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16341 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 16342 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16343 | nlmsg_free(msg); |
| 16344 | return; |
| 16345 | } |
| 16346 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16347 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16348 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16349 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16350 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16351 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16352 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 16353 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16354 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16355 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16356 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16357 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16358 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16359 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16360 | if (!sinfo) |
| 16361 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16362 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16363 | trace_cfg80211_del_sta(dev, mac_addr); |
| 16364 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16366 | if (!msg) { |
| 16367 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16368 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16369 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16370 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16371 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 16372 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16373 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16374 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16375 | } |
| 16376 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16377 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16378 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16379 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16380 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16381 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16382 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 16383 | enum nl80211_connect_failed_reason reason, |
| 16384 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16385 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16386 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16387 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16388 | struct sk_buff *msg; |
| 16389 | void *hdr; |
| 16390 | |
| 16391 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 16392 | if (!msg) |
| 16393 | return; |
| 16394 | |
| 16395 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 16396 | if (!hdr) { |
| 16397 | nlmsg_free(msg); |
| 16398 | return; |
| 16399 | } |
| 16400 | |
| 16401 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16402 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 16403 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 16404 | goto nla_put_failure; |
| 16405 | |
| 16406 | genlmsg_end(msg, hdr); |
| 16407 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16408 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16409 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16410 | return; |
| 16411 | |
| 16412 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16413 | nlmsg_free(msg); |
| 16414 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16415 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16416 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16417 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 16418 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16419 | { |
| 16420 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16421 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16422 | struct sk_buff *msg; |
| 16423 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 16424 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16425 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16426 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16427 | return false; |
| 16428 | |
| 16429 | msg = nlmsg_new(100, gfp); |
| 16430 | if (!msg) |
| 16431 | return true; |
| 16432 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16433 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16434 | if (!hdr) { |
| 16435 | nlmsg_free(msg); |
| 16436 | return true; |
| 16437 | } |
| 16438 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16439 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16440 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16441 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16442 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16443 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16444 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16445 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16446 | return true; |
| 16447 | |
| 16448 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16449 | nlmsg_free(msg); |
| 16450 | return true; |
| 16451 | } |
| 16452 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16453 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 16454 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16455 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16456 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16457 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16458 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16459 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 16460 | |
| 16461 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16462 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 16463 | trace_cfg80211_return_bool(false); |
| 16464 | return false; |
| 16465 | } |
| 16466 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 16467 | addr, gfp); |
| 16468 | trace_cfg80211_return_bool(ret); |
| 16469 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16470 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16471 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 16472 | |
| 16473 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 16474 | const u8 *addr, gfp_t gfp) |
| 16475 | { |
| 16476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16477 | bool ret; |
| 16478 | |
| 16479 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 16480 | |
| 16481 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16482 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 16483 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 16484 | trace_cfg80211_return_bool(false); |
| 16485 | return false; |
| 16486 | } |
| 16487 | ret = __nl80211_unexpected_frame(dev, |
| 16488 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 16489 | addr, gfp); |
| 16490 | trace_cfg80211_return_bool(ret); |
| 16491 | return ret; |
| 16492 | } |
| 16493 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16494 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16495 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16496 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 16497 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16498 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16499 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16500 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16501 | struct sk_buff *msg; |
| 16502 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16503 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16504 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16505 | if (!msg) |
| 16506 | return -ENOMEM; |
| 16507 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16508 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16509 | if (!hdr) { |
| 16510 | nlmsg_free(msg); |
| 16511 | return -ENOMEM; |
| 16512 | } |
| 16513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16514 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16515 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16516 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16517 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16518 | NL80211_ATTR_PAD) || |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 16519 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 16520 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16521 | (sig_dbm && |
| 16522 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16523 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16524 | (flags && |
| 16525 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16526 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16527 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16528 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16529 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16530 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16531 | |
| 16532 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16533 | nlmsg_free(msg); |
| 16534 | return -ENOBUFS; |
| 16535 | } |
| 16536 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16537 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16538 | const u8 *buf, size_t len, bool ack, |
| 16539 | gfp_t gfp, enum nl80211_commands command) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16540 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16541 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16542 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16543 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16544 | struct sk_buff *msg; |
| 16545 | void *hdr; |
| 16546 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16547 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
| 16548 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 16549 | else |
| 16550 | trace_cfg80211_control_port_tx_status(wdev, cookie, ack); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16551 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16552 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16553 | if (!msg) |
| 16554 | return; |
| 16555 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16556 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16557 | if (!hdr) { |
| 16558 | nlmsg_free(msg); |
| 16559 | return; |
| 16560 | } |
| 16561 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16562 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16563 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16564 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16565 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16566 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16567 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16568 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16569 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16570 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 16571 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16572 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16573 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16574 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16575 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16576 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16577 | return; |
| 16578 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16579 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16580 | nlmsg_free(msg); |
| 16581 | } |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16582 | |
| 16583 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16584 | const u8 *buf, size_t len, bool ack, |
| 16585 | gfp_t gfp) |
| 16586 | { |
| 16587 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16588 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
| 16589 | } |
| 16590 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); |
| 16591 | |
| 16592 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16593 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
| 16594 | { |
| 16595 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16596 | NL80211_CMD_FRAME_TX_STATUS); |
| 16597 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16598 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16599 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16600 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16601 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16602 | bool unencrypted, gfp_t gfp) |
| 16603 | { |
| 16604 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16605 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16606 | struct ethhdr *ehdr = eth_hdr(skb); |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16607 | const u8 *addr = ehdr->h_source; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16608 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16609 | struct sk_buff *msg; |
| 16610 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16611 | struct nlattr *frame; |
| 16612 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16613 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 16614 | |
| 16615 | if (!nlportid) |
| 16616 | return -ENOENT; |
| 16617 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16618 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16619 | if (!msg) |
| 16620 | return -ENOMEM; |
| 16621 | |
| 16622 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 16623 | if (!hdr) { |
| 16624 | nlmsg_free(msg); |
| 16625 | return -ENOBUFS; |
| 16626 | } |
| 16627 | |
| 16628 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16629 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16630 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16631 | NL80211_ATTR_PAD) || |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16632 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16633 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 16634 | (unencrypted && nla_put_flag(msg, |
| 16635 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 16636 | goto nla_put_failure; |
| 16637 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16638 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 16639 | if (!frame) |
| 16640 | goto nla_put_failure; |
| 16641 | |
| 16642 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16643 | genlmsg_end(msg, hdr); |
| 16644 | |
| 16645 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16646 | |
| 16647 | nla_put_failure: |
| 16648 | nlmsg_free(msg); |
| 16649 | return -ENOBUFS; |
| 16650 | } |
| 16651 | |
| 16652 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16653 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16654 | { |
| 16655 | int ret; |
| 16656 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16657 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 16658 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16659 | trace_cfg80211_return_bool(ret == 0); |
| 16660 | return ret == 0; |
| 16661 | } |
| 16662 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 16663 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16664 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 16665 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16666 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16667 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16668 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16669 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16670 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16671 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16672 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16673 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16674 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16675 | cb = (void **)msg->cb; |
| 16676 | |
| 16677 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 16678 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16679 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16680 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16681 | } |
| 16682 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16683 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16684 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16685 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16686 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16687 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16688 | goto nla_put_failure; |
| 16689 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16690 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16691 | if (!cb[1]) |
| 16692 | goto nla_put_failure; |
| 16693 | |
| 16694 | cb[2] = rdev; |
| 16695 | |
| 16696 | return msg; |
| 16697 | nla_put_failure: |
| 16698 | nlmsg_free(msg); |
| 16699 | return NULL; |
| 16700 | } |
| 16701 | |
| 16702 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 16703 | { |
| 16704 | void **cb = (void **)msg->cb; |
| 16705 | struct cfg80211_registered_device *rdev = cb[2]; |
| 16706 | |
| 16707 | nla_nest_end(msg, cb[1]); |
| 16708 | genlmsg_end(msg, cb[0]); |
| 16709 | |
| 16710 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 16711 | |
| 16712 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16713 | NL80211_MCGRP_MLME, gfp); |
| 16714 | } |
| 16715 | |
| 16716 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 16717 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16718 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16719 | { |
| 16720 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16721 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16722 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16723 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16724 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16725 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16726 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 16727 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 16728 | return; |
| 16729 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16730 | if (wdev->cqm_config) { |
| 16731 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 16732 | |
| 16733 | cfg80211_cqm_rssi_update(rdev, dev); |
| 16734 | |
| 16735 | if (rssi_level == 0) |
| 16736 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 16737 | } |
| 16738 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16739 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16740 | if (!msg) |
| 16741 | return; |
| 16742 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16743 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 16744 | rssi_event)) |
| 16745 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16746 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16747 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 16748 | rssi_level)) |
| 16749 | goto nla_put_failure; |
| 16750 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16751 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16752 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16753 | return; |
| 16754 | |
| 16755 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16756 | nlmsg_free(msg); |
| 16757 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16758 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16759 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16760 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 16761 | const u8 *peer, u32 num_packets, |
| 16762 | u32 rate, u32 intvl, gfp_t gfp) |
| 16763 | { |
| 16764 | struct sk_buff *msg; |
| 16765 | |
| 16766 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16767 | if (!msg) |
| 16768 | return; |
| 16769 | |
| 16770 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 16771 | goto nla_put_failure; |
| 16772 | |
| 16773 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 16774 | goto nla_put_failure; |
| 16775 | |
| 16776 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 16777 | goto nla_put_failure; |
| 16778 | |
| 16779 | cfg80211_send_cqm(msg, gfp); |
| 16780 | return; |
| 16781 | |
| 16782 | nla_put_failure: |
| 16783 | nlmsg_free(msg); |
| 16784 | } |
| 16785 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 16786 | |
| 16787 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 16788 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 16789 | { |
| 16790 | struct sk_buff *msg; |
| 16791 | |
| 16792 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 16793 | |
| 16794 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16795 | if (!msg) |
| 16796 | return; |
| 16797 | |
| 16798 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 16799 | goto nla_put_failure; |
| 16800 | |
| 16801 | cfg80211_send_cqm(msg, gfp); |
| 16802 | return; |
| 16803 | |
| 16804 | nla_put_failure: |
| 16805 | nlmsg_free(msg); |
| 16806 | } |
| 16807 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 16808 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16809 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 16810 | { |
| 16811 | struct sk_buff *msg; |
| 16812 | |
| 16813 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16814 | if (!msg) |
| 16815 | return; |
| 16816 | |
| 16817 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 16818 | goto nla_put_failure; |
| 16819 | |
| 16820 | cfg80211_send_cqm(msg, gfp); |
| 16821 | return; |
| 16822 | |
| 16823 | nla_put_failure: |
| 16824 | nlmsg_free(msg); |
| 16825 | } |
| 16826 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 16827 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16828 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 16829 | struct net_device *netdev, const u8 *bssid, |
| 16830 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16831 | { |
| 16832 | struct sk_buff *msg; |
| 16833 | struct nlattr *rekey_attr; |
| 16834 | void *hdr; |
| 16835 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16836 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16837 | if (!msg) |
| 16838 | return; |
| 16839 | |
| 16840 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 16841 | if (!hdr) { |
| 16842 | nlmsg_free(msg); |
| 16843 | return; |
| 16844 | } |
| 16845 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16847 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16849 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16850 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16851 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16852 | if (!rekey_attr) |
| 16853 | goto nla_put_failure; |
| 16854 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16855 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 16856 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 16857 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16858 | |
| 16859 | nla_nest_end(msg, rekey_attr); |
| 16860 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16861 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16862 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16863 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16864 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16865 | return; |
| 16866 | |
| 16867 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16868 | nlmsg_free(msg); |
| 16869 | } |
| 16870 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16871 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 16872 | const u8 *replay_ctr, gfp_t gfp) |
| 16873 | { |
| 16874 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16875 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16876 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16877 | |
| 16878 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 16879 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 16880 | } |
| 16881 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 16882 | |
| 16883 | static void |
| 16884 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 16885 | struct net_device *netdev, int index, |
| 16886 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16887 | { |
| 16888 | struct sk_buff *msg; |
| 16889 | struct nlattr *attr; |
| 16890 | void *hdr; |
| 16891 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16892 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16893 | if (!msg) |
| 16894 | return; |
| 16895 | |
| 16896 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 16897 | if (!hdr) { |
| 16898 | nlmsg_free(msg); |
| 16899 | return; |
| 16900 | } |
| 16901 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16902 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16903 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16904 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16905 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16906 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16907 | if (!attr) |
| 16908 | goto nla_put_failure; |
| 16909 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16910 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 16911 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 16912 | (preauth && |
| 16913 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 16914 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16915 | |
| 16916 | nla_nest_end(msg, attr); |
| 16917 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16918 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16919 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16920 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16921 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16922 | return; |
| 16923 | |
| 16924 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16925 | nlmsg_free(msg); |
| 16926 | } |
| 16927 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16928 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 16929 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 16930 | { |
| 16931 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16932 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16933 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16934 | |
| 16935 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 16936 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 16937 | } |
| 16938 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 16939 | |
| 16940 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 16941 | struct net_device *netdev, |
| 16942 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16943 | gfp_t gfp, |
| 16944 | enum nl80211_commands notif, |
| 16945 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16946 | { |
| 16947 | struct sk_buff *msg; |
| 16948 | void *hdr; |
| 16949 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16950 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16951 | if (!msg) |
| 16952 | return; |
| 16953 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16954 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16955 | if (!hdr) { |
| 16956 | nlmsg_free(msg); |
| 16957 | return; |
| 16958 | } |
| 16959 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 16960 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16961 | goto nla_put_failure; |
| 16962 | |
| 16963 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 16964 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16965 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16966 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 16967 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 16968 | goto nla_put_failure; |
| 16969 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16970 | genlmsg_end(msg, hdr); |
| 16971 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16972 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16973 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16974 | return; |
| 16975 | |
| 16976 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16977 | nlmsg_free(msg); |
| 16978 | } |
| 16979 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16980 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 16981 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 16982 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16984 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16985 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16986 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16987 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16988 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16989 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16990 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 16991 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 16992 | wdev->preset_chandef = *chandef; |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16993 | |
| 16994 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 16995 | !WARN_ON(!wdev->current_bss)) |
Sergey Matyukevich | 0afd425 | 2019-07-26 16:39:34 +0000 | [diff] [blame] | 16996 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16997 | |
Michael Vassernis | d34990b | 2019-07-29 06:01:16 +0000 | [diff] [blame] | 16998 | cfg80211_sched_dfs_chan_update(rdev); |
| 16999 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17000 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17001 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17002 | } |
| 17003 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 17004 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17005 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 17006 | struct cfg80211_chan_def *chandef, |
| 17007 | u8 count) |
| 17008 | { |
| 17009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17010 | struct wiphy *wiphy = wdev->wiphy; |
| 17011 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17012 | |
| 17013 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 17014 | |
| 17015 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17016 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 17017 | } |
| 17018 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 17019 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 17020 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17021 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 17022 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17023 | enum nl80211_radar_event event, |
| 17024 | struct net_device *netdev, gfp_t gfp) |
| 17025 | { |
| 17026 | struct sk_buff *msg; |
| 17027 | void *hdr; |
| 17028 | |
| 17029 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17030 | if (!msg) |
| 17031 | return; |
| 17032 | |
| 17033 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 17034 | if (!hdr) { |
| 17035 | nlmsg_free(msg); |
| 17036 | return; |
| 17037 | } |
| 17038 | |
| 17039 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17040 | goto nla_put_failure; |
| 17041 | |
| 17042 | /* NOP and radar events don't need a netdev parameter */ |
| 17043 | if (netdev) { |
| 17044 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 17045 | |
| 17046 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17047 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17048 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17049 | goto nla_put_failure; |
| 17050 | } |
| 17051 | |
| 17052 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 17053 | goto nla_put_failure; |
| 17054 | |
| 17055 | if (nl80211_send_chandef(msg, chandef)) |
| 17056 | goto nla_put_failure; |
| 17057 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17058 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17059 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17060 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17061 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17062 | return; |
| 17063 | |
| 17064 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17065 | nlmsg_free(msg); |
| 17066 | } |
| 17067 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17068 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 17069 | struct sta_opmode_info *sta_opmode, |
| 17070 | gfp_t gfp) |
| 17071 | { |
| 17072 | struct sk_buff *msg; |
| 17073 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17074 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17075 | void *hdr; |
| 17076 | |
| 17077 | if (WARN_ON(!mac)) |
| 17078 | return; |
| 17079 | |
| 17080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17081 | if (!msg) |
| 17082 | return; |
| 17083 | |
| 17084 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 17085 | if (!hdr) { |
| 17086 | nlmsg_free(msg); |
| 17087 | return; |
| 17088 | } |
| 17089 | |
| 17090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17091 | goto nla_put_failure; |
| 17092 | |
| 17093 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 17094 | goto nla_put_failure; |
| 17095 | |
| 17096 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 17097 | goto nla_put_failure; |
| 17098 | |
| 17099 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 17100 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 17101 | goto nla_put_failure; |
| 17102 | |
| 17103 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
Johannes Berg | 0016d32 | 2020-03-25 09:05:32 +0100 | [diff] [blame] | 17104 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17105 | goto nla_put_failure; |
| 17106 | |
| 17107 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 17108 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 17109 | goto nla_put_failure; |
| 17110 | |
| 17111 | genlmsg_end(msg, hdr); |
| 17112 | |
| 17113 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17114 | NL80211_MCGRP_MLME, gfp); |
| 17115 | |
| 17116 | return; |
| 17117 | |
| 17118 | nla_put_failure: |
| 17119 | nlmsg_free(msg); |
| 17120 | } |
| 17121 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 17122 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17123 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17124 | u64 cookie, bool acked, s32 ack_signal, |
| 17125 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17126 | { |
| 17127 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17128 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17129 | struct sk_buff *msg; |
| 17130 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17131 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17132 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 17133 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17134 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17135 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17136 | if (!msg) |
| 17137 | return; |
| 17138 | |
| 17139 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 17140 | if (!hdr) { |
| 17141 | nlmsg_free(msg); |
| 17142 | return; |
| 17143 | } |
| 17144 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17146 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17147 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17148 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17149 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17150 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 17151 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 17152 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17153 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17154 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17155 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17156 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17157 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17158 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17159 | return; |
| 17160 | |
| 17161 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17162 | nlmsg_free(msg); |
| 17163 | } |
| 17164 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 17165 | |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17166 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
| 17167 | size_t len, int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17168 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17169 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17170 | struct sk_buff *msg; |
| 17171 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17172 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17173 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17174 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 17175 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17176 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17177 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 17178 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 17179 | if (!msg) { |
| 17180 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17181 | return; |
| 17182 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17183 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17184 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 17185 | if (!hdr) |
| 17186 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17187 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17188 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17189 | (freq && |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 17190 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 17191 | KHZ_TO_MHZ(freq)) || |
| 17192 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 17193 | freq % 1000))) || |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17194 | (sig_dbm && |
| 17195 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 17196 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 17197 | goto nla_put_failure; |
| 17198 | |
| 17199 | genlmsg_end(msg, hdr); |
| 17200 | |
| 17201 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17202 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17203 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17204 | return; |
| 17205 | |
| 17206 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17207 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17208 | nlmsg_free(msg); |
| 17209 | } |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17210 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17211 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17212 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17213 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 17214 | struct cfg80211_wowlan_wakeup *wakeup) |
| 17215 | { |
| 17216 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 17217 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 17218 | int i, j; |
| 17219 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17220 | nl_results = nla_nest_start_noflag(msg, |
| 17221 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17222 | if (!nl_results) |
| 17223 | return -EMSGSIZE; |
| 17224 | |
| 17225 | for (i = 0; i < nd->n_matches; i++) { |
| 17226 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 17227 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17228 | nl_match = nla_nest_start_noflag(msg, i); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17229 | if (!nl_match) |
| 17230 | break; |
| 17231 | |
| 17232 | /* The SSID attribute is optional in nl80211, but for |
| 17233 | * simplicity reasons it's always present in the |
| 17234 | * cfg80211 structure. If a driver can't pass the |
| 17235 | * SSID, that needs to be changed. A zero length SSID |
| 17236 | * is still a valid SSID (wildcard), so it cannot be |
| 17237 | * used for this purpose. |
| 17238 | */ |
| 17239 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 17240 | match->ssid.ssid)) { |
| 17241 | nla_nest_cancel(msg, nl_match); |
| 17242 | goto out; |
| 17243 | } |
| 17244 | |
| 17245 | if (match->n_channels) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17246 | nl_freqs = nla_nest_start_noflag(msg, |
| 17247 | NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17248 | if (!nl_freqs) { |
| 17249 | nla_nest_cancel(msg, nl_match); |
| 17250 | goto out; |
| 17251 | } |
| 17252 | |
| 17253 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 17254 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17255 | nla_nest_cancel(msg, nl_freqs); |
| 17256 | nla_nest_cancel(msg, nl_match); |
| 17257 | goto out; |
| 17258 | } |
| 17259 | } |
| 17260 | |
| 17261 | nla_nest_end(msg, nl_freqs); |
| 17262 | } |
| 17263 | |
| 17264 | nla_nest_end(msg, nl_match); |
| 17265 | } |
| 17266 | |
| 17267 | out: |
| 17268 | nla_nest_end(msg, nl_results); |
| 17269 | return 0; |
| 17270 | } |
| 17271 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17272 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 17273 | struct cfg80211_wowlan_wakeup *wakeup, |
| 17274 | gfp_t gfp) |
| 17275 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17276 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17277 | struct sk_buff *msg; |
| 17278 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17279 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17280 | |
| 17281 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 17282 | |
| 17283 | if (wakeup) |
| 17284 | size += wakeup->packet_present_len; |
| 17285 | |
| 17286 | msg = nlmsg_new(size, gfp); |
| 17287 | if (!msg) |
| 17288 | return; |
| 17289 | |
| 17290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 17291 | if (!hdr) |
| 17292 | goto free_msg; |
| 17293 | |
| 17294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17295 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17296 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17297 | goto free_msg; |
| 17298 | |
| 17299 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17300 | wdev->netdev->ifindex)) |
| 17301 | goto free_msg; |
| 17302 | |
| 17303 | if (wakeup) { |
| 17304 | struct nlattr *reasons; |
| 17305 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17306 | reasons = nla_nest_start_noflag(msg, |
| 17307 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 17308 | if (!reasons) |
| 17309 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17310 | |
| 17311 | if (wakeup->disconnect && |
| 17312 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 17313 | goto free_msg; |
| 17314 | if (wakeup->magic_pkt && |
| 17315 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 17316 | goto free_msg; |
| 17317 | if (wakeup->gtk_rekey_failure && |
| 17318 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 17319 | goto free_msg; |
| 17320 | if (wakeup->eap_identity_req && |
| 17321 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 17322 | goto free_msg; |
| 17323 | if (wakeup->four_way_handshake && |
| 17324 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 17325 | goto free_msg; |
| 17326 | if (wakeup->rfkill_release && |
| 17327 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 17328 | goto free_msg; |
| 17329 | |
| 17330 | if (wakeup->pattern_idx >= 0 && |
| 17331 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 17332 | wakeup->pattern_idx)) |
| 17333 | goto free_msg; |
| 17334 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17335 | if (wakeup->tcp_match && |
| 17336 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 17337 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17338 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17339 | if (wakeup->tcp_connlost && |
| 17340 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 17341 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17342 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17343 | if (wakeup->tcp_nomoretokens && |
| 17344 | nla_put_flag(msg, |
| 17345 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 17346 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17347 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17348 | if (wakeup->packet) { |
| 17349 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 17350 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 17351 | |
| 17352 | if (!wakeup->packet_80211) { |
| 17353 | pkt_attr = |
| 17354 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 17355 | len_attr = |
| 17356 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 17357 | } |
| 17358 | |
| 17359 | if (wakeup->packet_len && |
| 17360 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 17361 | goto free_msg; |
| 17362 | |
| 17363 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 17364 | wakeup->packet)) |
| 17365 | goto free_msg; |
| 17366 | } |
| 17367 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17368 | if (wakeup->net_detect && |
| 17369 | cfg80211_net_detect_results(msg, wakeup)) |
| 17370 | goto free_msg; |
| 17371 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17372 | nla_nest_end(msg, reasons); |
| 17373 | } |
| 17374 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17375 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17376 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17377 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17378 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17379 | return; |
| 17380 | |
| 17381 | free_msg: |
| 17382 | nlmsg_free(msg); |
| 17383 | } |
| 17384 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 17385 | #endif |
| 17386 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17387 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 17388 | enum nl80211_tdls_operation oper, |
| 17389 | u16 reason_code, gfp_t gfp) |
| 17390 | { |
| 17391 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17392 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17393 | struct sk_buff *msg; |
| 17394 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17395 | |
| 17396 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 17397 | reason_code); |
| 17398 | |
| 17399 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17400 | if (!msg) |
| 17401 | return; |
| 17402 | |
| 17403 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 17404 | if (!hdr) { |
| 17405 | nlmsg_free(msg); |
| 17406 | return; |
| 17407 | } |
| 17408 | |
| 17409 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17410 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17411 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 17412 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 17413 | (reason_code > 0 && |
| 17414 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 17415 | goto nla_put_failure; |
| 17416 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17417 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17418 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17419 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17420 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17421 | return; |
| 17422 | |
| 17423 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17424 | nlmsg_free(msg); |
| 17425 | } |
| 17426 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 17427 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17428 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 17429 | unsigned long state, |
| 17430 | void *_notify) |
| 17431 | { |
| 17432 | struct netlink_notify *notify = _notify; |
| 17433 | struct cfg80211_registered_device *rdev; |
| 17434 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17435 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17436 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 17437 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17438 | return NOTIFY_DONE; |
| 17439 | |
| 17440 | rcu_read_lock(); |
| 17441 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17442 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17443 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 17444 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17445 | list_for_each_entry_rcu(sched_scan_req, |
| 17446 | &rdev->sched_scan_req_list, |
| 17447 | list) { |
| 17448 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 17449 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17450 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17451 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17452 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17453 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 17454 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17455 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17456 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17457 | if (wdev->owner_nlportid == notify->portid) { |
| 17458 | wdev->nl_owner_dead = true; |
| 17459 | schedule_work(&rdev->destroy_work); |
| 17460 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 17461 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17462 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 17463 | |
| 17464 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17465 | } |
| 17466 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17467 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17468 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 17469 | list) { |
| 17470 | if (reg->nlportid == notify->portid) { |
| 17471 | list_del(®->list); |
| 17472 | kfree(reg); |
| 17473 | break; |
| 17474 | } |
| 17475 | } |
| 17476 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17477 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17478 | |
| 17479 | rcu_read_unlock(); |
| 17480 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 17481 | /* |
| 17482 | * It is possible that the user space process that is controlling the |
| 17483 | * indoor setting disappeared, so notify the regulatory core. |
| 17484 | */ |
| 17485 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 17486 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17487 | } |
| 17488 | |
| 17489 | static struct notifier_block nl80211_netlink_notifier = { |
| 17490 | .notifier_call = nl80211_netlink_notify, |
| 17491 | }; |
| 17492 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17493 | void cfg80211_ft_event(struct net_device *netdev, |
| 17494 | struct cfg80211_ft_event_params *ft_event) |
| 17495 | { |
| 17496 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17497 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17498 | struct sk_buff *msg; |
| 17499 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17500 | |
| 17501 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 17502 | |
| 17503 | if (!ft_event->target_ap) |
| 17504 | return; |
| 17505 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 17506 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 17507 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17508 | if (!msg) |
| 17509 | return; |
| 17510 | |
| 17511 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17512 | if (!hdr) |
| 17513 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17514 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17515 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17516 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17517 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 17518 | goto out; |
| 17519 | |
| 17520 | if (ft_event->ies && |
| 17521 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 17522 | goto out; |
| 17523 | if (ft_event->ric_ies && |
| 17524 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 17525 | ft_event->ric_ies)) |
| 17526 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17527 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17528 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17529 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17530 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17531 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17532 | return; |
| 17533 | out: |
| 17534 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17535 | } |
| 17536 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 17537 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17538 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 17539 | { |
| 17540 | struct cfg80211_registered_device *rdev; |
| 17541 | struct sk_buff *msg; |
| 17542 | void *hdr; |
| 17543 | u32 nlportid; |
| 17544 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17545 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17546 | if (!rdev->crit_proto_nlportid) |
| 17547 | return; |
| 17548 | |
| 17549 | nlportid = rdev->crit_proto_nlportid; |
| 17550 | rdev->crit_proto_nlportid = 0; |
| 17551 | |
| 17552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17553 | if (!msg) |
| 17554 | return; |
| 17555 | |
| 17556 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 17557 | if (!hdr) |
| 17558 | goto nla_put_failure; |
| 17559 | |
| 17560 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17561 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17562 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17563 | goto nla_put_failure; |
| 17564 | |
| 17565 | genlmsg_end(msg, hdr); |
| 17566 | |
| 17567 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17568 | return; |
| 17569 | |
| 17570 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17571 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17572 | } |
| 17573 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 17574 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17575 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 17576 | { |
| 17577 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17578 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17579 | struct sk_buff *msg; |
| 17580 | void *hdr; |
| 17581 | |
| 17582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 17583 | if (!msg) |
| 17584 | return; |
| 17585 | |
| 17586 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 17587 | if (!hdr) |
| 17588 | goto out; |
| 17589 | |
| 17590 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17591 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17592 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17593 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17594 | goto out; |
| 17595 | |
| 17596 | genlmsg_end(msg, hdr); |
| 17597 | |
| 17598 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 17599 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17600 | return; |
| 17601 | out: |
| 17602 | nlmsg_free(msg); |
| 17603 | } |
| 17604 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 17605 | int cfg80211_external_auth_request(struct net_device *dev, |
| 17606 | struct cfg80211_external_auth_params *params, |
| 17607 | gfp_t gfp) |
| 17608 | { |
| 17609 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17610 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17611 | struct sk_buff *msg; |
| 17612 | void *hdr; |
| 17613 | |
| 17614 | if (!wdev->conn_owner_nlportid) |
| 17615 | return -EINVAL; |
| 17616 | |
| 17617 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17618 | if (!msg) |
| 17619 | return -ENOMEM; |
| 17620 | |
| 17621 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 17622 | if (!hdr) |
| 17623 | goto nla_put_failure; |
| 17624 | |
| 17625 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17626 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17627 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 17628 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 17629 | params->action) || |
| 17630 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 17631 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 17632 | params->ssid.ssid)) |
| 17633 | goto nla_put_failure; |
| 17634 | |
| 17635 | genlmsg_end(msg, hdr); |
| 17636 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 17637 | wdev->conn_owner_nlportid); |
| 17638 | return 0; |
| 17639 | |
| 17640 | nla_put_failure: |
| 17641 | nlmsg_free(msg); |
| 17642 | return -ENOBUFS; |
| 17643 | } |
| 17644 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 17645 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 17646 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 17647 | struct cfg80211_update_owe_info *owe_info, |
| 17648 | gfp_t gfp) |
| 17649 | { |
| 17650 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17651 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17652 | struct sk_buff *msg; |
| 17653 | void *hdr; |
| 17654 | |
| 17655 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 17656 | |
| 17657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17658 | if (!msg) |
| 17659 | return; |
| 17660 | |
| 17661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 17662 | if (!hdr) |
| 17663 | goto nla_put_failure; |
| 17664 | |
| 17665 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17666 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17667 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 17668 | goto nla_put_failure; |
| 17669 | |
| 17670 | if (!owe_info->ie_len || |
| 17671 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 17672 | goto nla_put_failure; |
| 17673 | |
| 17674 | genlmsg_end(msg, hdr); |
| 17675 | |
| 17676 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17677 | NL80211_MCGRP_MLME, gfp); |
| 17678 | return; |
| 17679 | |
| 17680 | nla_put_failure: |
| 17681 | genlmsg_cancel(msg, hdr); |
| 17682 | nlmsg_free(msg); |
| 17683 | } |
| 17684 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 17685 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17686 | /* initialisation/exit functions */ |
| 17687 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 17688 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17689 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 17690 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17691 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 17692 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17693 | if (err) |
| 17694 | return err; |
| 17695 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17696 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 17697 | if (err) |
| 17698 | goto err_out; |
| 17699 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17700 | return 0; |
| 17701 | err_out: |
| 17702 | genl_unregister_family(&nl80211_fam); |
| 17703 | return err; |
| 17704 | } |
| 17705 | |
| 17706 | void nl80211_exit(void) |
| 17707 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17708 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17709 | genl_unregister_family(&nl80211_fam); |
| 17710 | } |