| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * This is the new netlink-based wireless configuration interface. |
| 4 | * |
| 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
| 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
| 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8 | * Copyright (C) 2018-2021 Intel Corporation |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/if.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/slab.h> |
| 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> |
| 21 | #include <linux/nospec.h> |
| 22 | #include <linux/etherdevice.h> |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 23 | #include <linux/if_vlan.h> |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
| 25 | #include <net/genetlink.h> |
| 26 | #include <net/cfg80211.h> |
| 27 | #include <net/sock.h> |
| 28 | #include <net/inet_connection_sock.h> |
| 29 | #include "core.h" |
| 30 | #include "nl80211.h" |
| 31 | #include "reg.h" |
| 32 | #include "rdev-ops.h" |
| 33 | |
| 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 | |
| 39 | /* the netlink family */ |
| 40 | static struct genl_family nl80211_fam; |
| 41 | |
| 42 | /* multicast groups */ |
| 43 | enum nl80211_multicast_groups { |
| 44 | NL80211_MCGRP_CONFIG, |
| 45 | NL80211_MCGRP_SCAN, |
| 46 | NL80211_MCGRP_REGULATORY, |
| 47 | NL80211_MCGRP_MLME, |
| 48 | NL80211_MCGRP_VENDOR, |
| 49 | NL80211_MCGRP_NAN, |
| 50 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 51 | }; |
| 52 | |
| 53 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 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 }, |
| 59 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
| 60 | #ifdef CONFIG_NL80211_TESTMODE |
| 61 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
| 62 | #endif |
| 63 | }; |
| 64 | |
| 65 | /* returns ERR_PTR values */ |
| 66 | static struct wireless_dev * |
| 67 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
| 68 | { |
| 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; |
| 76 | |
| 77 | ASSERT_RTNL(); |
| 78 | |
| 79 | if (!have_ifidx && !have_wdev_id) |
| 80 | return ERR_PTR(-EINVAL); |
| 81 | |
| 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; |
| 87 | } |
| 88 | |
| 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 | |
| 98 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 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 | } |
| 109 | |
| 110 | if (result) |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (result) |
| 115 | return result; |
| 116 | return ERR_PTR(-ENODEV); |
| 117 | } |
| 118 | |
| 119 | static struct cfg80211_registered_device * |
| 120 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
| 121 | { |
| 122 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 123 | struct net_device *netdev; |
| 124 | |
| 125 | ASSERT_RTNL(); |
| 126 | |
| 127 | if (!attrs[NL80211_ATTR_WIPHY] && |
| 128 | !attrs[NL80211_ATTR_IFINDEX] && |
| 129 | !attrs[NL80211_ATTR_WDEV]) |
| 130 | return ERR_PTR(-EINVAL); |
| 131 | |
| 132 | if (attrs[NL80211_ATTR_WIPHY]) |
| 133 | rdev = cfg80211_rdev_by_wiphy_idx( |
| 134 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
| 135 | |
| 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 */ |
| 144 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
| 145 | if (wdev->identifier != (u32)wdev_id) |
| 146 | continue; |
| 147 | found = true; |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | if (!found) |
| 152 | tmp = NULL; |
| 153 | |
| 154 | if (rdev && tmp != rdev) |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | rdev = tmp; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 161 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 162 | |
| 163 | netdev = __dev_get_by_index(netns, ifindex); |
| 164 | if (netdev) { |
| 165 | if (netdev->ieee80211_ptr) |
| 166 | tmp = wiphy_to_rdev( |
| 167 | netdev->ieee80211_ptr->wiphy); |
| 168 | else |
| 169 | tmp = NULL; |
| 170 | |
| 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; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | if (!rdev) |
| 184 | return ERR_PTR(-ENODEV); |
| 185 | |
| 186 | if (netns != wiphy_net(&rdev->wiphy)) |
| 187 | return ERR_PTR(-ENODEV); |
| 188 | |
| 189 | return rdev; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * This function returns a pointer to the driver |
| 194 | * that the genl_info item that is passed refers to. |
| 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 * |
| 200 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
| 201 | { |
| 202 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
| 203 | } |
| 204 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [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; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 212 | unsigned int fixedlen, hdrlen; |
| 213 | bool s1g_bcn; |
| 214 | |
| 215 | if (len < offsetofend(typeof(*mgmt), frame_control)) |
| 216 | goto err; |
| 217 | |
| 218 | s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); |
| 219 | if (s1g_bcn) { |
| 220 | fixedlen = offsetof(struct ieee80211_ext, |
| 221 | u.s1g_beacon.variable); |
| 222 | hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); |
| 223 | } else { |
| 224 | fixedlen = offsetof(struct ieee80211_mgmt, |
| 225 | u.beacon.variable); |
| 226 | hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); |
| 227 | } |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 228 | |
| 229 | if (len < fixedlen) |
| 230 | goto err; |
| 231 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 232 | if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 233 | goto err; |
| 234 | |
| 235 | data += fixedlen; |
| 236 | len -= fixedlen; |
| 237 | |
| 238 | for_each_element(elem, data, len) { |
| 239 | /* nothing */ |
| 240 | } |
| 241 | |
| 242 | if (for_each_element_completed(elem, data, len)) |
| 243 | return 0; |
| 244 | |
| 245 | err: |
| 246 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 247 | return -EINVAL; |
| 248 | } |
| 249 | |
| 250 | static int validate_ie_attr(const struct nlattr *attr, |
| 251 | struct netlink_ext_ack *extack) |
| 252 | { |
| 253 | const u8 *data = nla_data(attr); |
| 254 | unsigned int len = nla_len(attr); |
| 255 | const struct element *elem; |
| 256 | |
| 257 | for_each_element(elem, data, len) { |
| 258 | /* nothing */ |
| 259 | } |
| 260 | |
| 261 | if (for_each_element_completed(elem, data, len)) |
| 262 | return 0; |
| 263 | |
| 264 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 268 | /* policy for the attributes */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 269 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
| 270 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 271 | static const struct nla_policy |
| 272 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 273 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 274 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 275 | .len = U8_MAX }, |
| 276 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 277 | .len = U8_MAX }, |
| 278 | }; |
| 279 | |
| 280 | static const struct nla_policy |
| 281 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 282 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 283 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 284 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 285 | NLA_POLICY_MAX(NLA_U8, 15), |
| 286 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 287 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 288 | NLA_POLICY_MAX(NLA_U8, 15), |
| 289 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
| 290 | NLA_POLICY_MAX(NLA_U8, 31), |
| 291 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 292 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 293 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 294 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| 295 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | static const struct nla_policy |
| 299 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 300 | [NL80211_PMSR_TYPE_FTM] = |
| 301 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
| 302 | }; |
| 303 | |
| 304 | static const struct nla_policy |
| 305 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 306 | [NL80211_PMSR_REQ_ATTR_DATA] = |
| 307 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
| 308 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 309 | }; |
| 310 | |
| 311 | static const struct nla_policy |
| 312 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 313 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 314 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 315 | [NL80211_PMSR_PEER_ATTR_REQ] = |
| 316 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
| 317 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 318 | }; |
| 319 | |
| 320 | static const struct nla_policy |
| 321 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 322 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 323 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 324 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 325 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 326 | [NL80211_PMSR_ATTR_PEERS] = |
| 327 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
| 328 | }; |
| 329 | |
| 330 | static const struct nla_policy |
| 331 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 332 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 333 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 334 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 335 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 336 | [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = |
| 337 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 338 | [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = |
| 339 | NLA_POLICY_EXACT_LEN(8), |
| 340 | [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = |
| 341 | NLA_POLICY_EXACT_LEN(8), |
| 342 | [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 345 | static const struct nla_policy |
| 346 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 347 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 348 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 349 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 350 | }; |
| 351 | |
| 352 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 353 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 354 | .len = NL80211_MAX_SUPP_RATES }, |
| 355 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 356 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 357 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), |
| 358 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 359 | [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), |
| 360 | [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, |
| 361 | NL80211_RATE_INFO_HE_GI_0_8, |
| 362 | NL80211_RATE_INFO_HE_GI_3_2), |
| 363 | [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, |
| 364 | NL80211_RATE_INFO_HE_1XLTF, |
| 365 | NL80211_RATE_INFO_HE_4XLTF), |
| 366 | }; |
| 367 | |
| 368 | static const struct nla_policy |
| 369 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
| 370 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 371 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
| 372 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
| 373 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
| 374 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 375 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
| 376 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 377 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
| 378 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
| 379 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
| 380 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
| 381 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
| 382 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
| 383 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
| 384 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
| 385 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), |
| 386 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = |
| 387 | NLA_POLICY_NESTED(nl80211_txattr_policy), |
| 388 | }; |
| 389 | |
| 390 | static const struct nla_policy |
| 391 | nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { |
| 392 | [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 393 | [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 394 | NLA_POLICY_RANGE(NLA_BINARY, |
| 395 | NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, |
| 396 | IEEE80211_MAX_DATA_LEN), |
| 397 | }; |
| 398 | |
| 399 | static const struct nla_policy |
| 400 | nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { |
| 401 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), |
| 402 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, |
| 403 | .len = IEEE80211_MAX_DATA_LEN } |
| 404 | }; |
| 405 | |
| 406 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 407 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 408 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 409 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
| 410 | .len = 20-1 }, |
| 411 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
| 412 | |
| 413 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
| 414 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 415 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 416 | NL80211_EDMG_CHANNELS_MIN, |
| 417 | NL80211_EDMG_CHANNELS_MAX), |
| 418 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 419 | NL80211_EDMG_BW_CONFIG_MIN, |
| 420 | NL80211_EDMG_BW_CONFIG_MAX), |
| 421 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 422 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 423 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 424 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 425 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 426 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 427 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 428 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 429 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 430 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
| 431 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
| 432 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
| 433 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 434 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 435 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 436 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
| 437 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 438 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| 439 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 440 | |
| 441 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
| 442 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 443 | .len = WLAN_MAX_KEY_LEN }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 444 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 445 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 446 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 447 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 448 | [NL80211_ATTR_KEY_TYPE] = |
| 449 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 450 | |
| 451 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 452 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 453 | [NL80211_ATTR_BEACON_HEAD] = |
| 454 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 455 | IEEE80211_MAX_DATA_LEN), |
| 456 | [NL80211_ATTR_BEACON_TAIL] = |
| 457 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 458 | IEEE80211_MAX_DATA_LEN), |
| 459 | [NL80211_ATTR_STA_AID] = |
| 460 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 461 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 462 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 463 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 464 | .len = NL80211_MAX_SUPP_RATES }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 465 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 466 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
| 467 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 468 | NLA_POLICY_RANGE(NLA_U8, |
| 469 | NL80211_TX_POWER_AUTOMATIC, |
| 470 | NL80211_TX_POWER_FIXED), |
| 471 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 472 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
| 473 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
| 474 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 475 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 476 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 477 | |
| 478 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 479 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 480 | |
| 481 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 482 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 483 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
| 484 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 485 | .len = NL80211_MAX_SUPP_RATES }, |
| 486 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
| 487 | |
| 488 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
| 489 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
| 490 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 491 | [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 492 | |
| 493 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 494 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 495 | validate_ie_attr, |
| 496 | IEEE80211_MAX_DATA_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 497 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 498 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
| 499 | |
| 500 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 501 | .len = IEEE80211_MAX_SSID_LEN }, |
| 502 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 503 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
| 504 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
| 505 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 506 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 507 | NL80211_MFP_NO, |
| 508 | NL80211_MFP_OPTIONAL), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 509 | [NL80211_ATTR_STA_FLAGS2] = { |
| 510 | .len = sizeof(struct nl80211_sta_flag_update), |
| 511 | }, |
| 512 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
| 513 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 514 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
| 515 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
| 516 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 517 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 518 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 519 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
| 520 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
| 521 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 522 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 523 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 524 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
| 525 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
| 526 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 527 | .len = IEEE80211_MAX_DATA_LEN }, |
| 528 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 529 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 530 | NL80211_PS_DISABLED, |
| 531 | NL80211_PS_ENABLED), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 532 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
| 533 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
| 534 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
| 535 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 536 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
| 537 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
| 538 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 539 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
| 540 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
| 541 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
| 542 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 543 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 544 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 545 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 546 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
| 547 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 548 | [NL80211_ATTR_MESH_PEER_AID] = |
| 549 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 550 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
| 551 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
| 552 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 553 | [NL80211_ATTR_HIDDEN_SSID] = |
| 554 | NLA_POLICY_RANGE(NLA_U32, |
| 555 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 556 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
| 557 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 558 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 559 | IEEE80211_MAX_DATA_LEN), |
| 560 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 561 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 562 | IEEE80211_MAX_DATA_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 563 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
| 564 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
| 565 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
| 566 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 567 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 568 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 569 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 570 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
| 571 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
| 572 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
| 573 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 574 | .len = IEEE80211_MAX_DATA_LEN }, |
| 575 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
| 576 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 577 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 578 | .len = NL80211_HT_CAPABILITY_LEN |
| 579 | }, |
| 580 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
| 581 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
| 582 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
| 583 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
| 584 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 585 | |
| 586 | /* need to include at least Auth Transaction and Status Code */ |
| 587 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), |
| 588 | |
| 589 | [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 590 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 591 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 592 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 593 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 594 | NLA_POLICY_RANGE(NLA_U32, |
| 595 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 596 | NL80211_MESH_POWER_MAX), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 597 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 598 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 599 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 600 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
| 601 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
| 602 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 603 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 604 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 605 | }, |
| 606 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 607 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 608 | .len = IEEE80211_MAX_DATA_LEN }, |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 609 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 610 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
| 611 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 612 | [NL80211_ATTR_PEER_AID] = |
| 613 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 614 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 615 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 616 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 617 | [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, |
| 618 | [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, |
| 619 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
| 620 | /* |
| 621 | * The value of the Length field of the Supported Operating |
| 622 | * Classes element is between 2 and 253. |
| 623 | */ |
| 624 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = |
| 625 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 626 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
| 627 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
| 628 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 629 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 630 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 631 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
| 632 | IEEE80211_QOS_MAP_LEN_MIN, |
| 633 | IEEE80211_QOS_MAP_LEN_MAX), |
| 634 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 635 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
| 636 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
| 637 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
| 638 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
| 639 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 640 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 641 | [NL80211_ATTR_USER_PRIO] = |
| 642 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 643 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
| 644 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 645 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 646 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 647 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
| 648 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
| 649 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
| 650 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
| 651 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
| 652 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 653 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 654 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 655 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 656 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 657 | }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 658 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 659 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 660 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
| 661 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
| 662 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 663 | .len = FILS_MAX_KEK_LEN }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 664 | [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 665 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 666 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 667 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 668 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 669 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 670 | }, |
| 671 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
| 672 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 673 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 674 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 675 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 676 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 677 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 678 | .len = FILS_ERP_MAX_RRK_LEN }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 679 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 680 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 681 | [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 682 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
| 683 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
| 684 | |
| 685 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 686 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 687 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 688 | [NL80211_ATTR_HE_CAPABILITY] = |
| 689 | NLA_POLICY_RANGE(NLA_BINARY, |
| 690 | NL80211_HE_MIN_CAPABILITY_LEN, |
| 691 | NL80211_HE_MAX_CAPABILITY_LEN), |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 692 | [NL80211_ATTR_FTM_RESPONDER] = |
| 693 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 694 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 695 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
| 696 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
| 697 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
| 698 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 699 | .len = SAE_PASSWORD_MAX_LEN }, |
| 700 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
| 701 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 702 | [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), |
| 703 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
| 704 | [NL80211_ATTR_TID_CONFIG] = |
| 705 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
| 706 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
| 707 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
| 708 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), |
| 709 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
| 710 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
| 711 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
| 712 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
| 713 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), |
| 714 | [NL80211_ATTR_FILS_DISCOVERY] = |
| 715 | NLA_POLICY_NESTED(nl80211_fils_discovery_policy), |
| 716 | [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = |
| 717 | NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), |
| 718 | [NL80211_ATTR_S1G_CAPABILITY] = |
| 719 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
| 720 | [NL80211_ATTR_S1G_CAPABILITY_MASK] = |
| 721 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 722 | }; |
| 723 | |
| 724 | /* policy for the key attributes */ |
| 725 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
| 726 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
| 727 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 728 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 729 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
| 730 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 731 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 732 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 733 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 734 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | /* policy for the key default flags */ |
| 738 | static const struct nla_policy |
| 739 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 740 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 741 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
| 742 | }; |
| 743 | |
| 744 | #ifdef CONFIG_PM |
| 745 | /* policy for WoWLAN attributes */ |
| 746 | static const struct nla_policy |
| 747 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 748 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 749 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 750 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 751 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 752 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 753 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 754 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 755 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
| 756 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 757 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
| 758 | }; |
| 759 | |
| 760 | static const struct nla_policy |
| 761 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 762 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 763 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 764 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 765 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 766 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 767 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 768 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 769 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 770 | }, |
| 771 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 772 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 773 | }, |
| 774 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 775 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| 776 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 777 | }; |
| 778 | #endif /* CONFIG_PM */ |
| 779 | |
| 780 | /* policy for coalesce rule attributes */ |
| 781 | static const struct nla_policy |
| 782 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 783 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 784 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 785 | NLA_POLICY_RANGE(NLA_U32, |
| 786 | NL80211_COALESCE_CONDITION_MATCH, |
| 787 | NL80211_COALESCE_CONDITION_NO_MATCH), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 788 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 789 | }; |
| 790 | |
| 791 | /* policy for GTK rekey offload attributes */ |
| 792 | static const struct nla_policy |
| 793 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 794 | [NL80211_REKEY_DATA_KEK] = { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 795 | .type = NLA_BINARY, |
| 796 | .len = NL80211_KEK_EXT_LEN |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 797 | }, |
| 798 | [NL80211_REKEY_DATA_KCK] = { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 799 | .type = NLA_BINARY, |
| 800 | .len = NL80211_KCK_EXT_LEN |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 801 | }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 802 | [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), |
| 803 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 804 | }; |
| 805 | |
| 806 | static const struct nla_policy |
| 807 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 808 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 809 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
| 810 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
| 811 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 812 | }; |
| 813 | |
| 814 | static const struct nla_policy |
| 815 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 816 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
| 817 | .len = IEEE80211_MAX_SSID_LEN }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 818 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 819 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 820 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 821 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 822 | }; |
| 823 | |
| 824 | static const struct nla_policy |
| 825 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 826 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 827 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 828 | }; |
| 829 | |
| 830 | static const struct nla_policy |
| 831 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 832 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 833 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 834 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 835 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 836 | }, |
| 837 | }; |
| 838 | |
| 839 | /* policy for NAN function attributes */ |
| 840 | static const struct nla_policy |
| 841 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 842 | [NL80211_NAN_FUNC_TYPE] = |
| 843 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 844 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
| 845 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 846 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 847 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 848 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 849 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 850 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 851 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 852 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 853 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 854 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 855 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 856 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 857 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 858 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 859 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 860 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 861 | }; |
| 862 | |
| 863 | /* policy for Service Response Filter attributes */ |
| 864 | static const struct nla_policy |
| 865 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 866 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 867 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 868 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 869 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 870 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 871 | }; |
| 872 | |
| 873 | /* policy for packet pattern attributes */ |
| 874 | static const struct nla_policy |
| 875 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 876 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 877 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 878 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 879 | }; |
| 880 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 881 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 882 | struct cfg80211_registered_device **rdev, |
| 883 | struct wireless_dev **wdev) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 884 | { |
| 885 | int err; |
| 886 | |
| 887 | if (!cb->args[0]) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 888 | struct nlattr **attrbuf; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 889 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 890 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 891 | GFP_KERNEL); |
| 892 | if (!attrbuf) |
| 893 | return -ENOMEM; |
| 894 | |
| 895 | err = nlmsg_parse_deprecated(cb->nlh, |
| 896 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 897 | attrbuf, nl80211_fam.maxattr, |
| 898 | nl80211_policy, NULL); |
| 899 | if (err) { |
| 900 | kfree(attrbuf); |
| 901 | return err; |
| 902 | } |
| 903 | |
| 904 | *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), |
| 905 | attrbuf); |
| 906 | kfree(attrbuf); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 907 | if (IS_ERR(*wdev)) |
| 908 | return PTR_ERR(*wdev); |
| 909 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
| 910 | /* 0 is the first index - add 1 to parse only once */ |
| 911 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 912 | cb->args[1] = (*wdev)->identifier; |
| 913 | } else { |
| 914 | /* subtract the 1 again here */ |
| 915 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 916 | struct wireless_dev *tmp; |
| 917 | |
| 918 | if (!wiphy) |
| 919 | return -ENODEV; |
| 920 | *rdev = wiphy_to_rdev(wiphy); |
| 921 | *wdev = NULL; |
| 922 | |
| 923 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
| 924 | if (tmp->identifier == cb->args[1]) { |
| 925 | *wdev = tmp; |
| 926 | break; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | if (!*wdev) |
| 931 | return -ENODEV; |
| 932 | } |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 937 | /* message building helper */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 938 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 939 | int flags, u8 cmd) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 940 | { |
| 941 | /* since there is no private header just add the generic one */ |
| 942 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
| 943 | } |
| 944 | |
| 945 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 946 | const struct ieee80211_reg_rule *rule) |
| 947 | { |
| 948 | int j; |
| 949 | struct nlattr *nl_wmm_rules = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 950 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 951 | |
| 952 | if (!nl_wmm_rules) |
| 953 | goto nla_put_failure; |
| 954 | |
| 955 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 956 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 957 | |
| 958 | if (!nl_wmm_rule) |
| 959 | goto nla_put_failure; |
| 960 | |
| 961 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
| 962 | rule->wmm_rule.client[j].cw_min) || |
| 963 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
| 964 | rule->wmm_rule.client[j].cw_max) || |
| 965 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
| 966 | rule->wmm_rule.client[j].aifsn) || |
| 967 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 968 | rule->wmm_rule.client[j].cot)) |
| 969 | goto nla_put_failure; |
| 970 | |
| 971 | nla_nest_end(msg, nl_wmm_rule); |
| 972 | } |
| 973 | nla_nest_end(msg, nl_wmm_rules); |
| 974 | |
| 975 | return 0; |
| 976 | |
| 977 | nla_put_failure: |
| 978 | return -ENOBUFS; |
| 979 | } |
| 980 | |
| 981 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, |
| 982 | struct ieee80211_channel *chan, |
| 983 | bool large) |
| 984 | { |
| 985 | /* Some channels must be completely excluded from the |
| 986 | * list to protect old user-space tools from breaking |
| 987 | */ |
| 988 | if (!large && chan->flags & |
| 989 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 990 | return 0; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 991 | if (!large && chan->freq_offset) |
| 992 | return 0; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 993 | |
| 994 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 995 | chan->center_freq)) |
| 996 | goto nla_put_failure; |
| 997 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 998 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
| 999 | goto nla_put_failure; |
| 1000 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1001 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 1002 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 1003 | goto nla_put_failure; |
| 1004 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 1005 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 1006 | goto nla_put_failure; |
| 1007 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 1008 | goto nla_put_failure; |
| 1009 | } |
| 1010 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1011 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 1012 | goto nla_put_failure; |
| 1013 | if (large) { |
| 1014 | u32 time; |
| 1015 | |
| 1016 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 1017 | |
| 1018 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 1019 | chan->dfs_state)) |
| 1020 | goto nla_put_failure; |
| 1021 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 1022 | time)) |
| 1023 | goto nla_put_failure; |
| 1024 | if (nla_put_u32(msg, |
| 1025 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 1026 | chan->dfs_cac_ms)) |
| 1027 | goto nla_put_failure; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | if (large) { |
| 1032 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 1033 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 1034 | goto nla_put_failure; |
| 1035 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 1036 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 1037 | goto nla_put_failure; |
| 1038 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 1039 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 1040 | goto nla_put_failure; |
| 1041 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 1042 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 1043 | goto nla_put_failure; |
| 1044 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 1045 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 1046 | goto nla_put_failure; |
| 1047 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 1048 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
| 1049 | goto nla_put_failure; |
| 1050 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 1051 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 1052 | goto nla_put_failure; |
| 1053 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 1054 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 1055 | goto nla_put_failure; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1056 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 1057 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 1058 | goto nla_put_failure; |
| 1059 | if ((chan->flags & IEEE80211_CHAN_1MHZ) && |
| 1060 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) |
| 1061 | goto nla_put_failure; |
| 1062 | if ((chan->flags & IEEE80211_CHAN_2MHZ) && |
| 1063 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) |
| 1064 | goto nla_put_failure; |
| 1065 | if ((chan->flags & IEEE80211_CHAN_4MHZ) && |
| 1066 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) |
| 1067 | goto nla_put_failure; |
| 1068 | if ((chan->flags & IEEE80211_CHAN_8MHZ) && |
| 1069 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) |
| 1070 | goto nla_put_failure; |
| 1071 | if ((chan->flags & IEEE80211_CHAN_16MHZ) && |
| 1072 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) |
| 1073 | goto nla_put_failure; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 1077 | DBM_TO_MBM(chan->max_power))) |
| 1078 | goto nla_put_failure; |
| 1079 | |
| 1080 | if (large) { |
| 1081 | const struct ieee80211_reg_rule *rule = |
| 1082 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
| 1083 | |
| 1084 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
| 1085 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1086 | goto nla_put_failure; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | return 0; |
| 1091 | |
| 1092 | nla_put_failure: |
| 1093 | return -ENOBUFS; |
| 1094 | } |
| 1095 | |
| 1096 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1097 | struct cfg80211_txq_stats *txqstats, |
| 1098 | int attrtype) |
| 1099 | { |
| 1100 | struct nlattr *txqattr; |
| 1101 | |
| 1102 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1103 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1104 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1105 | return false; \ |
| 1106 | } while (0) |
| 1107 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1108 | txqattr = nla_nest_start_noflag(msg, attrtype); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1109 | if (!txqattr) |
| 1110 | return false; |
| 1111 | |
| 1112 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1113 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1114 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1115 | PUT_TXQVAL_U32(DROPS, drops); |
| 1116 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1117 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1118 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1119 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1120 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1121 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1122 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1123 | nla_nest_end(msg, txqattr); |
| 1124 | |
| 1125 | #undef PUT_TXQVAL_U32 |
| 1126 | return true; |
| 1127 | } |
| 1128 | |
| 1129 | /* netlink command implementations */ |
| 1130 | |
| 1131 | struct key_parse { |
| 1132 | struct key_params p; |
| 1133 | int idx; |
| 1134 | int type; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1135 | bool def, defmgmt, defbeacon; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1136 | bool def_uni, def_multi; |
| 1137 | }; |
| 1138 | |
| 1139 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1140 | struct key_parse *k) |
| 1141 | { |
| 1142 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1143 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1144 | nl80211_key_policy, |
| 1145 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1146 | if (err) |
| 1147 | return err; |
| 1148 | |
| 1149 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1150 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1151 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1152 | |
| 1153 | if (k->def) { |
| 1154 | k->def_uni = true; |
| 1155 | k->def_multi = true; |
| 1156 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1157 | if (k->defmgmt || k->defbeacon) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1158 | k->def_multi = true; |
| 1159 | |
| 1160 | if (tb[NL80211_KEY_IDX]) |
| 1161 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1162 | |
| 1163 | if (tb[NL80211_KEY_DATA]) { |
| 1164 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1165 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1166 | } |
| 1167 | |
| 1168 | if (tb[NL80211_KEY_SEQ]) { |
| 1169 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1170 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1171 | } |
| 1172 | |
| 1173 | if (tb[NL80211_KEY_CIPHER]) |
| 1174 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1175 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1176 | if (tb[NL80211_KEY_TYPE]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1177 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1178 | |
| 1179 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1180 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 1181 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1182 | err = nla_parse_nested_deprecated(kdt, |
| 1183 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1184 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1185 | nl80211_key_default_policy, |
| 1186 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1187 | if (err) |
| 1188 | return err; |
| 1189 | |
| 1190 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1191 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1192 | } |
| 1193 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1194 | if (tb[NL80211_KEY_MODE]) |
| 1195 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1196 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1201 | { |
| 1202 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1203 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1204 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1205 | } |
| 1206 | |
| 1207 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1208 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1209 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1210 | } |
| 1211 | |
| 1212 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1213 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1214 | |
| 1215 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1216 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1217 | |
| 1218 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1219 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1220 | |
| 1221 | if (k->def) { |
| 1222 | k->def_uni = true; |
| 1223 | k->def_multi = true; |
| 1224 | } |
| 1225 | if (k->defmgmt) |
| 1226 | k->def_multi = true; |
| 1227 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1228 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1229 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1230 | |
| 1231 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1232 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1233 | int err = nla_parse_nested_deprecated(kdt, |
| 1234 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1235 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1236 | nl80211_key_default_policy, |
| 1237 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1238 | if (err) |
| 1239 | return err; |
| 1240 | |
| 1241 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1242 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1243 | } |
| 1244 | |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1249 | { |
| 1250 | int err; |
| 1251 | |
| 1252 | memset(k, 0, sizeof(*k)); |
| 1253 | k->idx = -1; |
| 1254 | k->type = -1; |
| 1255 | |
| 1256 | if (info->attrs[NL80211_ATTR_KEY]) |
| 1257 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
| 1258 | else |
| 1259 | err = nl80211_parse_key_old(info, k); |
| 1260 | |
| 1261 | if (err) |
| 1262 | return err; |
| 1263 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1264 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1265 | (k->defbeacon ? 1 : 0) > 1) { |
| 1266 | GENL_SET_ERR_MSG(info, |
| 1267 | "key with multiple default flags is invalid"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1268 | return -EINVAL; |
| 1269 | } |
| 1270 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1271 | if (k->defmgmt || k->defbeacon) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1272 | if (k->def_uni || !k->def_multi) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1273 | GENL_SET_ERR_MSG(info, |
| 1274 | "defmgmt/defbeacon key must be mcast"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1275 | return -EINVAL; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | if (k->idx != -1) { |
| 1280 | if (k->defmgmt) { |
| 1281 | if (k->idx < 4 || k->idx > 5) { |
| 1282 | GENL_SET_ERR_MSG(info, |
| 1283 | "defmgmt key idx not 4 or 5"); |
| 1284 | return -EINVAL; |
| 1285 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1286 | } else if (k->defbeacon) { |
| 1287 | if (k->idx < 6 || k->idx > 7) { |
| 1288 | GENL_SET_ERR_MSG(info, |
| 1289 | "defbeacon key idx not 6 or 7"); |
| 1290 | return -EINVAL; |
| 1291 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1292 | } else if (k->def) { |
| 1293 | if (k->idx < 0 || k->idx > 3) { |
| 1294 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
| 1295 | return -EINVAL; |
| 1296 | } |
| 1297 | } else { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1298 | if (k->idx < 0 || k->idx > 7) { |
| 1299 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1300 | return -EINVAL; |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static struct cfg80211_cached_keys * |
| 1309 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 1310 | struct genl_info *info, bool *no_ht) |
| 1311 | { |
| 1312 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
| 1313 | struct key_parse parse; |
| 1314 | struct nlattr *key; |
| 1315 | struct cfg80211_cached_keys *result; |
| 1316 | int rem, err, def = 0; |
| 1317 | bool have_key = false; |
| 1318 | |
| 1319 | nla_for_each_nested(key, keys, rem) { |
| 1320 | have_key = true; |
| 1321 | break; |
| 1322 | } |
| 1323 | |
| 1324 | if (!have_key) |
| 1325 | return NULL; |
| 1326 | |
| 1327 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1328 | if (!result) |
| 1329 | return ERR_PTR(-ENOMEM); |
| 1330 | |
| 1331 | result->def = -1; |
| 1332 | |
| 1333 | nla_for_each_nested(key, keys, rem) { |
| 1334 | memset(&parse, 0, sizeof(parse)); |
| 1335 | parse.idx = -1; |
| 1336 | |
| 1337 | err = nl80211_parse_key_new(info, key, &parse); |
| 1338 | if (err) |
| 1339 | goto error; |
| 1340 | err = -EINVAL; |
| 1341 | if (!parse.p.key) |
| 1342 | goto error; |
| 1343 | if (parse.idx < 0 || parse.idx > 3) { |
| 1344 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
| 1345 | goto error; |
| 1346 | } |
| 1347 | if (parse.def) { |
| 1348 | if (def) { |
| 1349 | GENL_SET_ERR_MSG(info, |
| 1350 | "only one key can be default"); |
| 1351 | goto error; |
| 1352 | } |
| 1353 | def = 1; |
| 1354 | result->def = parse.idx; |
| 1355 | if (!parse.def_uni || !parse.def_multi) |
| 1356 | goto error; |
| 1357 | } else if (parse.defmgmt) |
| 1358 | goto error; |
| 1359 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
| 1360 | parse.idx, false, NULL); |
| 1361 | if (err) |
| 1362 | goto error; |
| 1363 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1364 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 1365 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
| 1366 | err = -EINVAL; |
| 1367 | goto error; |
| 1368 | } |
| 1369 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1370 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1371 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1372 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 1373 | |
| 1374 | /* must be WEP key if we got here */ |
| 1375 | if (no_ht) |
| 1376 | *no_ht = true; |
| 1377 | } |
| 1378 | |
| 1379 | if (result->def < 0) { |
| 1380 | err = -EINVAL; |
| 1381 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
| 1382 | goto error; |
| 1383 | } |
| 1384 | |
| 1385 | return result; |
| 1386 | error: |
| 1387 | kfree(result); |
| 1388 | return ERR_PTR(err); |
| 1389 | } |
| 1390 | |
| 1391 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1392 | { |
| 1393 | ASSERT_WDEV_LOCK(wdev); |
| 1394 | |
| 1395 | switch (wdev->iftype) { |
| 1396 | case NL80211_IFTYPE_AP: |
| 1397 | case NL80211_IFTYPE_AP_VLAN: |
| 1398 | case NL80211_IFTYPE_P2P_GO: |
| 1399 | case NL80211_IFTYPE_MESH_POINT: |
| 1400 | break; |
| 1401 | case NL80211_IFTYPE_ADHOC: |
| 1402 | case NL80211_IFTYPE_STATION: |
| 1403 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1404 | if (!wdev->current_bss) |
| 1405 | return -ENOLINK; |
| 1406 | break; |
| 1407 | case NL80211_IFTYPE_UNSPECIFIED: |
| 1408 | case NL80211_IFTYPE_OCB: |
| 1409 | case NL80211_IFTYPE_MONITOR: |
| 1410 | case NL80211_IFTYPE_NAN: |
| 1411 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1412 | case NL80211_IFTYPE_WDS: |
| 1413 | case NUM_NL80211_IFTYPES: |
| 1414 | return -EINVAL; |
| 1415 | } |
| 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
| 1420 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1421 | u32 freq) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1422 | { |
| 1423 | struct ieee80211_channel *chan; |
| 1424 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1425 | chan = ieee80211_get_channel_khz(wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1426 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1427 | return NULL; |
| 1428 | return chan; |
| 1429 | } |
| 1430 | |
| 1431 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1432 | { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1433 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1434 | int i; |
| 1435 | |
| 1436 | if (!nl_modes) |
| 1437 | goto nla_put_failure; |
| 1438 | |
| 1439 | i = 0; |
| 1440 | while (ifmodes) { |
| 1441 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1442 | goto nla_put_failure; |
| 1443 | ifmodes >>= 1; |
| 1444 | i++; |
| 1445 | } |
| 1446 | |
| 1447 | nla_nest_end(msg, nl_modes); |
| 1448 | return 0; |
| 1449 | |
| 1450 | nla_put_failure: |
| 1451 | return -ENOBUFS; |
| 1452 | } |
| 1453 | |
| 1454 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 1455 | struct sk_buff *msg, |
| 1456 | bool large) |
| 1457 | { |
| 1458 | struct nlattr *nl_combis; |
| 1459 | int i, j; |
| 1460 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1461 | nl_combis = nla_nest_start_noflag(msg, |
| 1462 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1463 | if (!nl_combis) |
| 1464 | goto nla_put_failure; |
| 1465 | |
| 1466 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1467 | const struct ieee80211_iface_combination *c; |
| 1468 | struct nlattr *nl_combi, *nl_limits; |
| 1469 | |
| 1470 | c = &wiphy->iface_combinations[i]; |
| 1471 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1472 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1473 | if (!nl_combi) |
| 1474 | goto nla_put_failure; |
| 1475 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1476 | nl_limits = nla_nest_start_noflag(msg, |
| 1477 | NL80211_IFACE_COMB_LIMITS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1478 | if (!nl_limits) |
| 1479 | goto nla_put_failure; |
| 1480 | |
| 1481 | for (j = 0; j < c->n_limits; j++) { |
| 1482 | struct nlattr *nl_limit; |
| 1483 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1484 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1485 | if (!nl_limit) |
| 1486 | goto nla_put_failure; |
| 1487 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1488 | c->limits[j].max)) |
| 1489 | goto nla_put_failure; |
| 1490 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1491 | c->limits[j].types)) |
| 1492 | goto nla_put_failure; |
| 1493 | nla_nest_end(msg, nl_limit); |
| 1494 | } |
| 1495 | |
| 1496 | nla_nest_end(msg, nl_limits); |
| 1497 | |
| 1498 | if (c->beacon_int_infra_match && |
| 1499 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1500 | goto nla_put_failure; |
| 1501 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1502 | c->num_different_channels) || |
| 1503 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1504 | c->max_interfaces)) |
| 1505 | goto nla_put_failure; |
| 1506 | if (large && |
| 1507 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1508 | c->radar_detect_widths) || |
| 1509 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1510 | c->radar_detect_regions))) |
| 1511 | goto nla_put_failure; |
| 1512 | if (c->beacon_int_min_gcd && |
| 1513 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1514 | c->beacon_int_min_gcd)) |
| 1515 | goto nla_put_failure; |
| 1516 | |
| 1517 | nla_nest_end(msg, nl_combi); |
| 1518 | } |
| 1519 | |
| 1520 | nla_nest_end(msg, nl_combis); |
| 1521 | |
| 1522 | return 0; |
| 1523 | nla_put_failure: |
| 1524 | return -ENOBUFS; |
| 1525 | } |
| 1526 | |
| 1527 | #ifdef CONFIG_PM |
| 1528 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1529 | struct sk_buff *msg) |
| 1530 | { |
| 1531 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
| 1532 | struct nlattr *nl_tcp; |
| 1533 | |
| 1534 | if (!tcp) |
| 1535 | return 0; |
| 1536 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1537 | nl_tcp = nla_nest_start_noflag(msg, |
| 1538 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1539 | if (!nl_tcp) |
| 1540 | return -ENOBUFS; |
| 1541 | |
| 1542 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1543 | tcp->data_payload_max)) |
| 1544 | return -ENOBUFS; |
| 1545 | |
| 1546 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1547 | tcp->data_payload_max)) |
| 1548 | return -ENOBUFS; |
| 1549 | |
| 1550 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1551 | return -ENOBUFS; |
| 1552 | |
| 1553 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1554 | sizeof(*tcp->tok), tcp->tok)) |
| 1555 | return -ENOBUFS; |
| 1556 | |
| 1557 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1558 | tcp->data_interval_max)) |
| 1559 | return -ENOBUFS; |
| 1560 | |
| 1561 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1562 | tcp->wake_payload_max)) |
| 1563 | return -ENOBUFS; |
| 1564 | |
| 1565 | nla_nest_end(msg, nl_tcp); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
| 1569 | static int nl80211_send_wowlan(struct sk_buff *msg, |
| 1570 | struct cfg80211_registered_device *rdev, |
| 1571 | bool large) |
| 1572 | { |
| 1573 | struct nlattr *nl_wowlan; |
| 1574 | |
| 1575 | if (!rdev->wiphy.wowlan) |
| 1576 | return 0; |
| 1577 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1578 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1579 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1580 | if (!nl_wowlan) |
| 1581 | return -ENOBUFS; |
| 1582 | |
| 1583 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
| 1584 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1585 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1586 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1587 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1588 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1589 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1590 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1591 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1592 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1593 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1594 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1595 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1596 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1597 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1598 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1599 | return -ENOBUFS; |
| 1600 | |
| 1601 | if (rdev->wiphy.wowlan->n_patterns) { |
| 1602 | struct nl80211_pattern_support pat = { |
| 1603 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1604 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1605 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1606 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
| 1607 | }; |
| 1608 | |
| 1609 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1610 | sizeof(pat), &pat)) |
| 1611 | return -ENOBUFS; |
| 1612 | } |
| 1613 | |
| 1614 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1615 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1616 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1617 | return -ENOBUFS; |
| 1618 | |
| 1619 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
| 1620 | return -ENOBUFS; |
| 1621 | |
| 1622 | nla_nest_end(msg, nl_wowlan); |
| 1623 | |
| 1624 | return 0; |
| 1625 | } |
| 1626 | #endif |
| 1627 | |
| 1628 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1629 | struct cfg80211_registered_device *rdev) |
| 1630 | { |
| 1631 | struct nl80211_coalesce_rule_support rule; |
| 1632 | |
| 1633 | if (!rdev->wiphy.coalesce) |
| 1634 | return 0; |
| 1635 | |
| 1636 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1637 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1638 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1639 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1640 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1641 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
| 1642 | |
| 1643 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1644 | return -ENOBUFS; |
| 1645 | |
| 1646 | return 0; |
| 1647 | } |
| 1648 | |
| 1649 | static int |
| 1650 | nl80211_send_iftype_data(struct sk_buff *msg, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1651 | const struct ieee80211_supported_band *sband, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1652 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1653 | { |
| 1654 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1655 | |
| 1656 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1657 | iftdata->types_mask)) |
| 1658 | return -ENOBUFS; |
| 1659 | |
| 1660 | if (he_cap->has_he) { |
| 1661 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1662 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1663 | he_cap->he_cap_elem.mac_cap_info) || |
| 1664 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1665 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1666 | he_cap->he_cap_elem.phy_cap_info) || |
| 1667 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1668 | sizeof(he_cap->he_mcs_nss_supp), |
| 1669 | &he_cap->he_mcs_nss_supp) || |
| 1670 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1671 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1672 | return -ENOBUFS; |
| 1673 | } |
| 1674 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1675 | if (sband->band == NL80211_BAND_6GHZ && |
| 1676 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, |
| 1677 | sizeof(iftdata->he_6ghz_capa), |
| 1678 | &iftdata->he_6ghz_capa)) |
| 1679 | return -ENOBUFS; |
| 1680 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1681 | return 0; |
| 1682 | } |
| 1683 | |
| 1684 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1685 | struct ieee80211_supported_band *sband, |
| 1686 | bool large) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1687 | { |
| 1688 | struct nlattr *nl_rates, *nl_rate; |
| 1689 | struct ieee80211_rate *rate; |
| 1690 | int i; |
| 1691 | |
| 1692 | /* add HT info */ |
| 1693 | if (sband->ht_cap.ht_supported && |
| 1694 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1695 | sizeof(sband->ht_cap.mcs), |
| 1696 | &sband->ht_cap.mcs) || |
| 1697 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1698 | sband->ht_cap.cap) || |
| 1699 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1700 | sband->ht_cap.ampdu_factor) || |
| 1701 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1702 | sband->ht_cap.ampdu_density))) |
| 1703 | return -ENOBUFS; |
| 1704 | |
| 1705 | /* add VHT info */ |
| 1706 | if (sband->vht_cap.vht_supported && |
| 1707 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1708 | sizeof(sband->vht_cap.vht_mcs), |
| 1709 | &sband->vht_cap.vht_mcs) || |
| 1710 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1711 | sband->vht_cap.cap))) |
| 1712 | return -ENOBUFS; |
| 1713 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1714 | if (large && sband->n_iftype_data) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1715 | struct nlattr *nl_iftype_data = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1716 | nla_nest_start_noflag(msg, |
| 1717 | NL80211_BAND_ATTR_IFTYPE_DATA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1718 | int err; |
| 1719 | |
| 1720 | if (!nl_iftype_data) |
| 1721 | return -ENOBUFS; |
| 1722 | |
| 1723 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1724 | struct nlattr *iftdata; |
| 1725 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1726 | iftdata = nla_nest_start_noflag(msg, i + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1727 | if (!iftdata) |
| 1728 | return -ENOBUFS; |
| 1729 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1730 | err = nl80211_send_iftype_data(msg, sband, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1731 | &sband->iftype_data[i]); |
| 1732 | if (err) |
| 1733 | return err; |
| 1734 | |
| 1735 | nla_nest_end(msg, iftdata); |
| 1736 | } |
| 1737 | |
| 1738 | nla_nest_end(msg, nl_iftype_data); |
| 1739 | } |
| 1740 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1741 | /* add EDMG info */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1742 | if (large && sband->edmg_cap.channels && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1743 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1744 | sband->edmg_cap.channels) || |
| 1745 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1746 | sband->edmg_cap.bw_config))) |
| 1747 | |
| 1748 | return -ENOBUFS; |
| 1749 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1750 | /* add bitrates */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1751 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1752 | if (!nl_rates) |
| 1753 | return -ENOBUFS; |
| 1754 | |
| 1755 | for (i = 0; i < sband->n_bitrates; i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1756 | nl_rate = nla_nest_start_noflag(msg, i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1757 | if (!nl_rate) |
| 1758 | return -ENOBUFS; |
| 1759 | |
| 1760 | rate = &sband->bitrates[i]; |
| 1761 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1762 | rate->bitrate)) |
| 1763 | return -ENOBUFS; |
| 1764 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1765 | nla_put_flag(msg, |
| 1766 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1767 | return -ENOBUFS; |
| 1768 | |
| 1769 | nla_nest_end(msg, nl_rate); |
| 1770 | } |
| 1771 | |
| 1772 | nla_nest_end(msg, nl_rates); |
| 1773 | |
| 1774 | return 0; |
| 1775 | } |
| 1776 | |
| 1777 | static int |
| 1778 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1779 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1780 | { |
| 1781 | u16 stypes; |
| 1782 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1783 | enum nl80211_iftype ift; |
| 1784 | int i; |
| 1785 | |
| 1786 | if (!mgmt_stypes) |
| 1787 | return 0; |
| 1788 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1789 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1790 | if (!nl_ifs) |
| 1791 | return -ENOBUFS; |
| 1792 | |
| 1793 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1794 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1795 | if (!nl_ftypes) |
| 1796 | return -ENOBUFS; |
| 1797 | i = 0; |
| 1798 | stypes = mgmt_stypes[ift].tx; |
| 1799 | while (stypes) { |
| 1800 | if ((stypes & 1) && |
| 1801 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1802 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1803 | return -ENOBUFS; |
| 1804 | stypes >>= 1; |
| 1805 | i++; |
| 1806 | } |
| 1807 | nla_nest_end(msg, nl_ftypes); |
| 1808 | } |
| 1809 | |
| 1810 | nla_nest_end(msg, nl_ifs); |
| 1811 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1812 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1813 | if (!nl_ifs) |
| 1814 | return -ENOBUFS; |
| 1815 | |
| 1816 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1817 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1818 | if (!nl_ftypes) |
| 1819 | return -ENOBUFS; |
| 1820 | i = 0; |
| 1821 | stypes = mgmt_stypes[ift].rx; |
| 1822 | while (stypes) { |
| 1823 | if ((stypes & 1) && |
| 1824 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1825 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1826 | return -ENOBUFS; |
| 1827 | stypes >>= 1; |
| 1828 | i++; |
| 1829 | } |
| 1830 | nla_nest_end(msg, nl_ftypes); |
| 1831 | } |
| 1832 | nla_nest_end(msg, nl_ifs); |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | |
| 1837 | #define CMD(op, n) \ |
| 1838 | do { \ |
| 1839 | if (rdev->ops->op) { \ |
| 1840 | i++; \ |
| 1841 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1842 | goto nla_put_failure; \ |
| 1843 | } \ |
| 1844 | } while (0) |
| 1845 | |
| 1846 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1847 | struct sk_buff *msg) |
| 1848 | { |
| 1849 | int i = 0; |
| 1850 | |
| 1851 | /* |
| 1852 | * do *NOT* add anything into this function, new things need to be |
| 1853 | * advertised only to new versions of userspace that can deal with |
| 1854 | * the split (and they can't possibly care about new features... |
| 1855 | */ |
| 1856 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1857 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1858 | CMD(add_key, NEW_KEY); |
| 1859 | CMD(start_ap, START_AP); |
| 1860 | CMD(add_station, NEW_STATION); |
| 1861 | CMD(add_mpath, NEW_MPATH); |
| 1862 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1863 | CMD(change_bss, SET_BSS); |
| 1864 | CMD(auth, AUTHENTICATE); |
| 1865 | CMD(assoc, ASSOCIATE); |
| 1866 | CMD(deauth, DEAUTHENTICATE); |
| 1867 | CMD(disassoc, DISASSOCIATE); |
| 1868 | CMD(join_ibss, JOIN_IBSS); |
| 1869 | CMD(join_mesh, JOIN_MESH); |
| 1870 | CMD(set_pmksa, SET_PMKSA); |
| 1871 | CMD(del_pmksa, DEL_PMKSA); |
| 1872 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1873 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1874 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1875 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1876 | CMD(mgmt_tx, FRAME); |
| 1877 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1878 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1879 | i++; |
| 1880 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1881 | goto nla_put_failure; |
| 1882 | } |
| 1883 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1884 | rdev->ops->join_mesh) { |
| 1885 | i++; |
| 1886 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1887 | goto nla_put_failure; |
| 1888 | } |
| 1889 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1890 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1891 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1892 | CMD(tdls_oper, TDLS_OPER); |
| 1893 | } |
| 1894 | if (rdev->wiphy.max_sched_scan_reqs) |
| 1895 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1896 | CMD(probe_client, PROBE_CLIENT); |
| 1897 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1898 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1899 | i++; |
| 1900 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1901 | goto nla_put_failure; |
| 1902 | } |
| 1903 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1904 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1905 | #ifdef CONFIG_NL80211_TESTMODE |
| 1906 | CMD(testmode_cmd, TESTMODE); |
| 1907 | #endif |
| 1908 | |
| 1909 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1910 | i++; |
| 1911 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1912 | goto nla_put_failure; |
| 1913 | } |
| 1914 | |
| 1915 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1916 | i++; |
| 1917 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1918 | goto nla_put_failure; |
| 1919 | } |
| 1920 | |
| 1921 | return i; |
| 1922 | nla_put_failure: |
| 1923 | return -ENOBUFS; |
| 1924 | } |
| 1925 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1926 | static int |
| 1927 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1928 | struct sk_buff *msg) |
| 1929 | { |
| 1930 | struct nlattr *ftm; |
| 1931 | |
| 1932 | if (!cap->ftm.supported) |
| 1933 | return 0; |
| 1934 | |
| 1935 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
| 1936 | if (!ftm) |
| 1937 | return -ENOBUFS; |
| 1938 | |
| 1939 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1940 | return -ENOBUFS; |
| 1941 | if (cap->ftm.non_asap && |
| 1942 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1943 | return -ENOBUFS; |
| 1944 | if (cap->ftm.request_lci && |
| 1945 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1946 | return -ENOBUFS; |
| 1947 | if (cap->ftm.request_civicloc && |
| 1948 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1949 | return -ENOBUFS; |
| 1950 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1951 | cap->ftm.preambles)) |
| 1952 | return -ENOBUFS; |
| 1953 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1954 | cap->ftm.bandwidths)) |
| 1955 | return -ENOBUFS; |
| 1956 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1957 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1958 | cap->ftm.max_bursts_exponent)) |
| 1959 | return -ENOBUFS; |
| 1960 | if (cap->ftm.max_ftms_per_burst && |
| 1961 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1962 | cap->ftm.max_ftms_per_burst)) |
| 1963 | return -ENOBUFS; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1964 | if (cap->ftm.trigger_based && |
| 1965 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) |
| 1966 | return -ENOBUFS; |
| 1967 | if (cap->ftm.non_trigger_based && |
| 1968 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) |
| 1969 | return -ENOBUFS; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1970 | |
| 1971 | nla_nest_end(msg, ftm); |
| 1972 | return 0; |
| 1973 | } |
| 1974 | |
| 1975 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1976 | struct sk_buff *msg) |
| 1977 | { |
| 1978 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1979 | struct nlattr *pmsr, *caps; |
| 1980 | |
| 1981 | if (!cap) |
| 1982 | return 0; |
| 1983 | |
| 1984 | /* |
| 1985 | * we don't need to clean up anything here since the caller |
| 1986 | * will genlmsg_cancel() if we fail |
| 1987 | */ |
| 1988 | |
| 1989 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
| 1990 | if (!pmsr) |
| 1991 | return -ENOBUFS; |
| 1992 | |
| 1993 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1994 | return -ENOBUFS; |
| 1995 | |
| 1996 | if (cap->report_ap_tsf && |
| 1997 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1998 | return -ENOBUFS; |
| 1999 | |
| 2000 | if (cap->randomize_mac_addr && |
| 2001 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 2002 | return -ENOBUFS; |
| 2003 | |
| 2004 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
| 2005 | if (!caps) |
| 2006 | return -ENOBUFS; |
| 2007 | |
| 2008 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 2009 | return -ENOBUFS; |
| 2010 | |
| 2011 | nla_nest_end(msg, caps); |
| 2012 | nla_nest_end(msg, pmsr); |
| 2013 | |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2017 | static int |
| 2018 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 2019 | struct sk_buff *msg) |
| 2020 | { |
| 2021 | int i; |
| 2022 | struct nlattr *nested, *nested_akms; |
| 2023 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 2024 | |
| 2025 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 2026 | !rdev->wiphy.iftype_akm_suites) |
| 2027 | return 0; |
| 2028 | |
| 2029 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 2030 | if (!nested) |
| 2031 | return -ENOBUFS; |
| 2032 | |
| 2033 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 2034 | nested_akms = nla_nest_start(msg, i + 1); |
| 2035 | if (!nested_akms) |
| 2036 | return -ENOBUFS; |
| 2037 | |
| 2038 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 2039 | |
| 2040 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 2041 | iftype_akms->iftypes_mask)) |
| 2042 | return -ENOBUFS; |
| 2043 | |
| 2044 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 2045 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 2046 | iftype_akms->akm_suites)) { |
| 2047 | return -ENOBUFS; |
| 2048 | } |
| 2049 | nla_nest_end(msg, nested_akms); |
| 2050 | } |
| 2051 | |
| 2052 | nla_nest_end(msg, nested); |
| 2053 | |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | static int |
| 2058 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 2059 | struct sk_buff *msg) |
| 2060 | { |
| 2061 | struct nlattr *supp; |
| 2062 | |
| 2063 | if (!rdev->wiphy.tid_config_support.vif && |
| 2064 | !rdev->wiphy.tid_config_support.peer) |
| 2065 | return 0; |
| 2066 | |
| 2067 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 2068 | if (!supp) |
| 2069 | return -ENOSPC; |
| 2070 | |
| 2071 | if (rdev->wiphy.tid_config_support.vif && |
| 2072 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 2073 | rdev->wiphy.tid_config_support.vif, |
| 2074 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2075 | goto fail; |
| 2076 | |
| 2077 | if (rdev->wiphy.tid_config_support.peer && |
| 2078 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 2079 | rdev->wiphy.tid_config_support.peer, |
| 2080 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2081 | goto fail; |
| 2082 | |
| 2083 | /* for now we just use the same value ... makes more sense */ |
| 2084 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, |
| 2085 | rdev->wiphy.tid_config_support.max_retry)) |
| 2086 | goto fail; |
| 2087 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, |
| 2088 | rdev->wiphy.tid_config_support.max_retry)) |
| 2089 | goto fail; |
| 2090 | |
| 2091 | nla_nest_end(msg, supp); |
| 2092 | |
| 2093 | return 0; |
| 2094 | fail: |
| 2095 | nla_nest_cancel(msg, supp); |
| 2096 | return -ENOBUFS; |
| 2097 | } |
| 2098 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2099 | struct nl80211_dump_wiphy_state { |
| 2100 | s64 filter_wiphy; |
| 2101 | long start; |
| 2102 | long split_start, band_start, chan_start, capa_start; |
| 2103 | bool split; |
| 2104 | }; |
| 2105 | |
| 2106 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
| 2107 | enum nl80211_commands cmd, |
| 2108 | struct sk_buff *msg, u32 portid, u32 seq, |
| 2109 | int flags, struct nl80211_dump_wiphy_state *state) |
| 2110 | { |
| 2111 | void *hdr; |
| 2112 | struct nlattr *nl_bands, *nl_band; |
| 2113 | struct nlattr *nl_freqs, *nl_freq; |
| 2114 | struct nlattr *nl_cmds; |
| 2115 | enum nl80211_band band; |
| 2116 | struct ieee80211_channel *chan; |
| 2117 | int i; |
| 2118 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 2119 | rdev->wiphy.mgmt_stypes; |
| 2120 | u32 features; |
| 2121 | |
| 2122 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
| 2123 | if (!hdr) |
| 2124 | return -ENOBUFS; |
| 2125 | |
| 2126 | if (WARN_ON(!state)) |
| 2127 | return -EINVAL; |
| 2128 | |
| 2129 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2130 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 2131 | wiphy_name(&rdev->wiphy)) || |
| 2132 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2133 | cfg80211_rdev_list_generation)) |
| 2134 | goto nla_put_failure; |
| 2135 | |
| 2136 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2137 | goto finish; |
| 2138 | |
| 2139 | switch (state->split_start) { |
| 2140 | case 0: |
| 2141 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 2142 | rdev->wiphy.retry_short) || |
| 2143 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 2144 | rdev->wiphy.retry_long) || |
| 2145 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 2146 | rdev->wiphy.frag_threshold) || |
| 2147 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 2148 | rdev->wiphy.rts_threshold) || |
| 2149 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 2150 | rdev->wiphy.coverage_class) || |
| 2151 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 2152 | rdev->wiphy.max_scan_ssids) || |
| 2153 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 2154 | rdev->wiphy.max_sched_scan_ssids) || |
| 2155 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 2156 | rdev->wiphy.max_scan_ie_len) || |
| 2157 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 2158 | rdev->wiphy.max_sched_scan_ie_len) || |
| 2159 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2160 | rdev->wiphy.max_match_sets)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2161 | goto nla_put_failure; |
| 2162 | |
| 2163 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 2164 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2165 | goto nla_put_failure; |
| 2166 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 2167 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2168 | goto nla_put_failure; |
| 2169 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2170 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2171 | goto nla_put_failure; |
| 2172 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 2173 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2174 | goto nla_put_failure; |
| 2175 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2176 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2177 | goto nla_put_failure; |
| 2178 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 2179 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 2180 | goto nla_put_failure; |
| 2181 | state->split_start++; |
| 2182 | if (state->split) |
| 2183 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2184 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2185 | case 1: |
| 2186 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 2187 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2188 | rdev->wiphy.cipher_suites)) |
| 2189 | goto nla_put_failure; |
| 2190 | |
| 2191 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 2192 | rdev->wiphy.max_num_pmkids)) |
| 2193 | goto nla_put_failure; |
| 2194 | |
| 2195 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 2196 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2197 | goto nla_put_failure; |
| 2198 | |
| 2199 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 2200 | rdev->wiphy.available_antennas_tx) || |
| 2201 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 2202 | rdev->wiphy.available_antennas_rx)) |
| 2203 | goto nla_put_failure; |
| 2204 | |
| 2205 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 2206 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 2207 | rdev->wiphy.probe_resp_offload)) |
| 2208 | goto nla_put_failure; |
| 2209 | |
| 2210 | if ((rdev->wiphy.available_antennas_tx || |
| 2211 | rdev->wiphy.available_antennas_rx) && |
| 2212 | rdev->ops->get_antenna) { |
| 2213 | u32 tx_ant = 0, rx_ant = 0; |
| 2214 | int res; |
| 2215 | |
| 2216 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
| 2217 | if (!res) { |
| 2218 | if (nla_put_u32(msg, |
| 2219 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2220 | tx_ant) || |
| 2221 | nla_put_u32(msg, |
| 2222 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2223 | rx_ant)) |
| 2224 | goto nla_put_failure; |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | state->split_start++; |
| 2229 | if (state->split) |
| 2230 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2231 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2232 | case 2: |
| 2233 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 2234 | rdev->wiphy.interface_modes)) |
| 2235 | goto nla_put_failure; |
| 2236 | state->split_start++; |
| 2237 | if (state->split) |
| 2238 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2239 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2240 | case 3: |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2241 | nl_bands = nla_nest_start_noflag(msg, |
| 2242 | NL80211_ATTR_WIPHY_BANDS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2243 | if (!nl_bands) |
| 2244 | goto nla_put_failure; |
| 2245 | |
| 2246 | for (band = state->band_start; |
| 2247 | band < NUM_NL80211_BANDS; band++) { |
| 2248 | struct ieee80211_supported_band *sband; |
| 2249 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2250 | /* omit higher bands for ancient software */ |
| 2251 | if (band > NL80211_BAND_5GHZ && !state->split) |
| 2252 | break; |
| 2253 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2254 | sband = rdev->wiphy.bands[band]; |
| 2255 | |
| 2256 | if (!sband) |
| 2257 | continue; |
| 2258 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2259 | nl_band = nla_nest_start_noflag(msg, band); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2260 | if (!nl_band) |
| 2261 | goto nla_put_failure; |
| 2262 | |
| 2263 | switch (state->chan_start) { |
| 2264 | case 0: |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2265 | if (nl80211_send_band_rateinfo(msg, sband, |
| 2266 | state->split)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2267 | goto nla_put_failure; |
| 2268 | state->chan_start++; |
| 2269 | if (state->split) |
| 2270 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2271 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2272 | default: |
| 2273 | /* add frequencies */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2274 | nl_freqs = nla_nest_start_noflag(msg, |
| 2275 | NL80211_BAND_ATTR_FREQS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2276 | if (!nl_freqs) |
| 2277 | goto nla_put_failure; |
| 2278 | |
| 2279 | for (i = state->chan_start - 1; |
| 2280 | i < sband->n_channels; |
| 2281 | i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2282 | nl_freq = nla_nest_start_noflag(msg, |
| 2283 | i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2284 | if (!nl_freq) |
| 2285 | goto nla_put_failure; |
| 2286 | |
| 2287 | chan = &sband->channels[i]; |
| 2288 | |
| 2289 | if (nl80211_msg_put_channel( |
| 2290 | msg, &rdev->wiphy, chan, |
| 2291 | state->split)) |
| 2292 | goto nla_put_failure; |
| 2293 | |
| 2294 | nla_nest_end(msg, nl_freq); |
| 2295 | if (state->split) |
| 2296 | break; |
| 2297 | } |
| 2298 | if (i < sband->n_channels) |
| 2299 | state->chan_start = i + 2; |
| 2300 | else |
| 2301 | state->chan_start = 0; |
| 2302 | nla_nest_end(msg, nl_freqs); |
| 2303 | } |
| 2304 | |
| 2305 | nla_nest_end(msg, nl_band); |
| 2306 | |
| 2307 | if (state->split) { |
| 2308 | /* start again here */ |
| 2309 | if (state->chan_start) |
| 2310 | band--; |
| 2311 | break; |
| 2312 | } |
| 2313 | } |
| 2314 | nla_nest_end(msg, nl_bands); |
| 2315 | |
| 2316 | if (band < NUM_NL80211_BANDS) |
| 2317 | state->band_start = band + 1; |
| 2318 | else |
| 2319 | state->band_start = 0; |
| 2320 | |
| 2321 | /* if bands & channels are done, continue outside */ |
| 2322 | if (state->band_start == 0 && state->chan_start == 0) |
| 2323 | state->split_start++; |
| 2324 | if (state->split) |
| 2325 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2326 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2327 | case 4: |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2328 | nl_cmds = nla_nest_start_noflag(msg, |
| 2329 | NL80211_ATTR_SUPPORTED_COMMANDS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2330 | if (!nl_cmds) |
| 2331 | goto nla_put_failure; |
| 2332 | |
| 2333 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2334 | if (i < 0) |
| 2335 | goto nla_put_failure; |
| 2336 | if (state->split) { |
| 2337 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2338 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
| 2339 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 2340 | CMD(channel_switch, CHANNEL_SWITCH); |
| 2341 | CMD(set_qos_map, SET_QOS_MAP); |
| 2342 | if (rdev->wiphy.features & |
| 2343 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
| 2344 | CMD(add_tx_ts, ADD_TX_TS); |
| 2345 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
| 2346 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2347 | CMD(update_ft_ies, UPDATE_FT_IES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2348 | } |
| 2349 | #undef CMD |
| 2350 | |
| 2351 | nla_nest_end(msg, nl_cmds); |
| 2352 | state->split_start++; |
| 2353 | if (state->split) |
| 2354 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2355 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2356 | case 5: |
| 2357 | if (rdev->ops->remain_on_channel && |
| 2358 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 2359 | nla_put_u32(msg, |
| 2360 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 2361 | rdev->wiphy.max_remain_on_channel_duration)) |
| 2362 | goto nla_put_failure; |
| 2363 | |
| 2364 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 2365 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2366 | goto nla_put_failure; |
| 2367 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2368 | state->split_start++; |
| 2369 | if (state->split) |
| 2370 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2371 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2372 | case 6: |
| 2373 | #ifdef CONFIG_PM |
| 2374 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
| 2375 | goto nla_put_failure; |
| 2376 | state->split_start++; |
| 2377 | if (state->split) |
| 2378 | break; |
| 2379 | #else |
| 2380 | state->split_start++; |
| 2381 | #endif |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2382 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2383 | case 7: |
| 2384 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 2385 | rdev->wiphy.software_iftypes)) |
| 2386 | goto nla_put_failure; |
| 2387 | |
| 2388 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
| 2389 | state->split)) |
| 2390 | goto nla_put_failure; |
| 2391 | |
| 2392 | state->split_start++; |
| 2393 | if (state->split) |
| 2394 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2395 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2396 | case 8: |
| 2397 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 2398 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 2399 | rdev->wiphy.ap_sme_capa)) |
| 2400 | goto nla_put_failure; |
| 2401 | |
| 2402 | features = rdev->wiphy.features; |
| 2403 | /* |
| 2404 | * We can only add the per-channel limit information if the |
| 2405 | * dump is split, otherwise it makes it too big. Therefore |
| 2406 | * only advertise it in that case. |
| 2407 | */ |
| 2408 | if (state->split) |
| 2409 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2410 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
| 2411 | goto nla_put_failure; |
| 2412 | |
| 2413 | if (rdev->wiphy.ht_capa_mod_mask && |
| 2414 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 2415 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2416 | rdev->wiphy.ht_capa_mod_mask)) |
| 2417 | goto nla_put_failure; |
| 2418 | |
| 2419 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2420 | rdev->wiphy.max_acl_mac_addrs && |
| 2421 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 2422 | rdev->wiphy.max_acl_mac_addrs)) |
| 2423 | goto nla_put_failure; |
| 2424 | |
| 2425 | /* |
| 2426 | * Any information below this point is only available to |
| 2427 | * applications that can deal with it being split. This |
| 2428 | * helps ensure that newly added capabilities don't break |
| 2429 | * older tools by overrunning their buffers. |
| 2430 | * |
| 2431 | * We still increment split_start so that in the split |
| 2432 | * case we'll continue with more data in the next round, |
| 2433 | * but break unconditionally so unsplit data stops here. |
| 2434 | */ |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 2435 | if (state->split) |
| 2436 | state->split_start++; |
| 2437 | else |
| 2438 | state->split_start = 0; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2439 | break; |
| 2440 | case 9: |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2441 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2442 | goto nla_put_failure; |
| 2443 | |
| 2444 | if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2445 | rdev->wiphy.max_sched_scan_plans) || |
| 2446 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2447 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2448 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2449 | rdev->wiphy.max_sched_scan_plan_iterations)) |
| 2450 | goto nla_put_failure; |
| 2451 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2452 | if (rdev->wiphy.extended_capabilities && |
| 2453 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2454 | rdev->wiphy.extended_capabilities_len, |
| 2455 | rdev->wiphy.extended_capabilities) || |
| 2456 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2457 | rdev->wiphy.extended_capabilities_len, |
| 2458 | rdev->wiphy.extended_capabilities_mask))) |
| 2459 | goto nla_put_failure; |
| 2460 | |
| 2461 | if (rdev->wiphy.vht_capa_mod_mask && |
| 2462 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 2463 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2464 | rdev->wiphy.vht_capa_mod_mask)) |
| 2465 | goto nla_put_failure; |
| 2466 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2467 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2468 | rdev->wiphy.perm_addr)) |
| 2469 | goto nla_put_failure; |
| 2470 | |
| 2471 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2472 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2473 | rdev->wiphy.addr_mask)) |
| 2474 | goto nla_put_failure; |
| 2475 | |
| 2476 | if (rdev->wiphy.n_addresses > 1) { |
| 2477 | void *attr; |
| 2478 | |
| 2479 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2480 | if (!attr) |
| 2481 | goto nla_put_failure; |
| 2482 | |
| 2483 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2484 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2485 | rdev->wiphy.addresses[i].addr)) |
| 2486 | goto nla_put_failure; |
| 2487 | |
| 2488 | nla_nest_end(msg, attr); |
| 2489 | } |
| 2490 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2491 | state->split_start++; |
| 2492 | break; |
| 2493 | case 10: |
| 2494 | if (nl80211_send_coalesce(msg, rdev)) |
| 2495 | goto nla_put_failure; |
| 2496 | |
| 2497 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 2498 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2499 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2500 | goto nla_put_failure; |
| 2501 | |
| 2502 | if (rdev->wiphy.max_ap_assoc_sta && |
| 2503 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
| 2504 | rdev->wiphy.max_ap_assoc_sta)) |
| 2505 | goto nla_put_failure; |
| 2506 | |
| 2507 | state->split_start++; |
| 2508 | break; |
| 2509 | case 11: |
| 2510 | if (rdev->wiphy.n_vendor_commands) { |
| 2511 | const struct nl80211_vendor_cmd_info *info; |
| 2512 | struct nlattr *nested; |
| 2513 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2514 | nested = nla_nest_start_noflag(msg, |
| 2515 | NL80211_ATTR_VENDOR_DATA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2516 | if (!nested) |
| 2517 | goto nla_put_failure; |
| 2518 | |
| 2519 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2520 | info = &rdev->wiphy.vendor_commands[i].info; |
| 2521 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2522 | goto nla_put_failure; |
| 2523 | } |
| 2524 | nla_nest_end(msg, nested); |
| 2525 | } |
| 2526 | |
| 2527 | if (rdev->wiphy.n_vendor_events) { |
| 2528 | const struct nl80211_vendor_cmd_info *info; |
| 2529 | struct nlattr *nested; |
| 2530 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2531 | nested = nla_nest_start_noflag(msg, |
| 2532 | NL80211_ATTR_VENDOR_EVENTS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2533 | if (!nested) |
| 2534 | goto nla_put_failure; |
| 2535 | |
| 2536 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2537 | info = &rdev->wiphy.vendor_events[i]; |
| 2538 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2539 | goto nla_put_failure; |
| 2540 | } |
| 2541 | nla_nest_end(msg, nested); |
| 2542 | } |
| 2543 | state->split_start++; |
| 2544 | break; |
| 2545 | case 12: |
| 2546 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2547 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2548 | rdev->wiphy.max_num_csa_counters)) |
| 2549 | goto nla_put_failure; |
| 2550 | |
| 2551 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2552 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2553 | goto nla_put_failure; |
| 2554 | |
| 2555 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2556 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2557 | rdev->wiphy.max_sched_scan_reqs)) |
| 2558 | goto nla_put_failure; |
| 2559 | |
| 2560 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2561 | sizeof(rdev->wiphy.ext_features), |
| 2562 | rdev->wiphy.ext_features)) |
| 2563 | goto nla_put_failure; |
| 2564 | |
| 2565 | if (rdev->wiphy.bss_select_support) { |
| 2566 | struct nlattr *nested; |
| 2567 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2568 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2569 | nested = nla_nest_start_noflag(msg, |
| 2570 | NL80211_ATTR_BSS_SELECT); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2571 | if (!nested) |
| 2572 | goto nla_put_failure; |
| 2573 | |
| 2574 | i = 0; |
| 2575 | while (bss_select_support) { |
| 2576 | if ((bss_select_support & 1) && |
| 2577 | nla_put_flag(msg, i)) |
| 2578 | goto nla_put_failure; |
| 2579 | i++; |
| 2580 | bss_select_support >>= 1; |
| 2581 | } |
| 2582 | nla_nest_end(msg, nested); |
| 2583 | } |
| 2584 | |
| 2585 | state->split_start++; |
| 2586 | break; |
| 2587 | case 13: |
| 2588 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2589 | rdev->wiphy.iftype_ext_capab) { |
| 2590 | struct nlattr *nested_ext_capab, *nested; |
| 2591 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2592 | nested = nla_nest_start_noflag(msg, |
| 2593 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2594 | if (!nested) |
| 2595 | goto nla_put_failure; |
| 2596 | |
| 2597 | for (i = state->capa_start; |
| 2598 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2599 | const struct wiphy_iftype_ext_capab *capab; |
| 2600 | |
| 2601 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2602 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2603 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2604 | i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2605 | if (!nested_ext_capab || |
| 2606 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2607 | capab->iftype) || |
| 2608 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2609 | capab->extended_capabilities_len, |
| 2610 | capab->extended_capabilities) || |
| 2611 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2612 | capab->extended_capabilities_len, |
| 2613 | capab->extended_capabilities_mask)) |
| 2614 | goto nla_put_failure; |
| 2615 | |
| 2616 | nla_nest_end(msg, nested_ext_capab); |
| 2617 | if (state->split) |
| 2618 | break; |
| 2619 | } |
| 2620 | nla_nest_end(msg, nested); |
| 2621 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2622 | state->capa_start = i + 1; |
| 2623 | break; |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2628 | rdev->wiphy.nan_supported_bands)) |
| 2629 | goto nla_put_failure; |
| 2630 | |
| 2631 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2632 | NL80211_EXT_FEATURE_TXQS)) { |
| 2633 | struct cfg80211_txq_stats txqstats = {}; |
| 2634 | int res; |
| 2635 | |
| 2636 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2637 | if (!res && |
| 2638 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2639 | NL80211_ATTR_TXQ_STATS)) |
| 2640 | goto nla_put_failure; |
| 2641 | |
| 2642 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2643 | rdev->wiphy.txq_limit)) |
| 2644 | goto nla_put_failure; |
| 2645 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2646 | rdev->wiphy.txq_memory_limit)) |
| 2647 | goto nla_put_failure; |
| 2648 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2649 | rdev->wiphy.txq_quantum)) |
| 2650 | goto nla_put_failure; |
| 2651 | } |
| 2652 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2653 | state->split_start++; |
| 2654 | break; |
| 2655 | case 14: |
| 2656 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2657 | goto nla_put_failure; |
| 2658 | |
| 2659 | state->split_start++; |
| 2660 | break; |
| 2661 | case 15: |
| 2662 | if (rdev->wiphy.akm_suites && |
| 2663 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2664 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2665 | rdev->wiphy.akm_suites)) |
| 2666 | goto nla_put_failure; |
| 2667 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2668 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2669 | goto nla_put_failure; |
| 2670 | |
| 2671 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2672 | goto nla_put_failure; |
| 2673 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2674 | /* done */ |
| 2675 | state->split_start = 0; |
| 2676 | break; |
| 2677 | } |
| 2678 | finish: |
| 2679 | genlmsg_end(msg, hdr); |
| 2680 | return 0; |
| 2681 | |
| 2682 | nla_put_failure: |
| 2683 | genlmsg_cancel(msg, hdr); |
| 2684 | return -EMSGSIZE; |
| 2685 | } |
| 2686 | |
| 2687 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2688 | struct netlink_callback *cb, |
| 2689 | struct nl80211_dump_wiphy_state *state) |
| 2690 | { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2691 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2692 | int ret; |
| 2693 | |
| 2694 | if (!tb) |
| 2695 | return -ENOMEM; |
| 2696 | |
| 2697 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2698 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2699 | tb, nl80211_fam.maxattr, |
| 2700 | nl80211_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2701 | /* ignore parse errors for backward compatibility */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2702 | if (ret) { |
| 2703 | ret = 0; |
| 2704 | goto out; |
| 2705 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2706 | |
| 2707 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2708 | if (tb[NL80211_ATTR_WIPHY]) |
| 2709 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2710 | if (tb[NL80211_ATTR_WDEV]) |
| 2711 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2712 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2713 | struct net_device *netdev; |
| 2714 | struct cfg80211_registered_device *rdev; |
| 2715 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2716 | |
| 2717 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2718 | if (!netdev) { |
| 2719 | ret = -ENODEV; |
| 2720 | goto out; |
| 2721 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2722 | if (netdev->ieee80211_ptr) { |
| 2723 | rdev = wiphy_to_rdev( |
| 2724 | netdev->ieee80211_ptr->wiphy); |
| 2725 | state->filter_wiphy = rdev->wiphy_idx; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2729 | ret = 0; |
| 2730 | out: |
| 2731 | kfree(tb); |
| 2732 | return ret; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2736 | { |
| 2737 | int idx = 0, ret; |
| 2738 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
| 2739 | struct cfg80211_registered_device *rdev; |
| 2740 | |
| 2741 | rtnl_lock(); |
| 2742 | if (!state) { |
| 2743 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 2744 | if (!state) { |
| 2745 | rtnl_unlock(); |
| 2746 | return -ENOMEM; |
| 2747 | } |
| 2748 | state->filter_wiphy = -1; |
| 2749 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2750 | if (ret) { |
| 2751 | kfree(state); |
| 2752 | rtnl_unlock(); |
| 2753 | return ret; |
| 2754 | } |
| 2755 | cb->args[0] = (long)state; |
| 2756 | } |
| 2757 | |
| 2758 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2759 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
| 2760 | continue; |
| 2761 | if (++idx <= state->start) |
| 2762 | continue; |
| 2763 | if (state->filter_wiphy != -1 && |
| 2764 | state->filter_wiphy != rdev->wiphy_idx) |
| 2765 | continue; |
| 2766 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2767 | do { |
| 2768 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2769 | skb, |
| 2770 | NETLINK_CB(cb->skb).portid, |
| 2771 | cb->nlh->nlmsg_seq, |
| 2772 | NLM_F_MULTI, state); |
| 2773 | if (ret < 0) { |
| 2774 | /* |
| 2775 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2776 | * or EMSGSIZE returned), this SKB is still |
| 2777 | * empty (so it's not too big because another |
| 2778 | * wiphy dataset is already in the skb) and |
| 2779 | * we've not tried to adjust the dump allocation |
| 2780 | * yet ... then adjust the alloc size to be |
| 2781 | * bigger, and return 1 but with the empty skb. |
| 2782 | * This results in an empty message being RX'ed |
| 2783 | * in userspace, but that is ignored. |
| 2784 | * |
| 2785 | * We can then retry with the larger buffer. |
| 2786 | */ |
| 2787 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 2788 | !skb->len && !state->split && |
| 2789 | cb->min_dump_alloc < 4096) { |
| 2790 | cb->min_dump_alloc = 4096; |
| 2791 | state->split_start = 0; |
| 2792 | rtnl_unlock(); |
| 2793 | return 1; |
| 2794 | } |
| 2795 | idx--; |
| 2796 | break; |
| 2797 | } |
| 2798 | } while (state->split_start > 0); |
| 2799 | break; |
| 2800 | } |
| 2801 | rtnl_unlock(); |
| 2802 | |
| 2803 | state->start = idx; |
| 2804 | |
| 2805 | return skb->len; |
| 2806 | } |
| 2807 | |
| 2808 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2809 | { |
| 2810 | kfree((void *)cb->args[0]); |
| 2811 | return 0; |
| 2812 | } |
| 2813 | |
| 2814 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2815 | { |
| 2816 | struct sk_buff *msg; |
| 2817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2818 | struct nl80211_dump_wiphy_state state = {}; |
| 2819 | |
| 2820 | msg = nlmsg_new(4096, GFP_KERNEL); |
| 2821 | if (!msg) |
| 2822 | return -ENOMEM; |
| 2823 | |
| 2824 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2825 | info->snd_portid, info->snd_seq, 0, |
| 2826 | &state) < 0) { |
| 2827 | nlmsg_free(msg); |
| 2828 | return -ENOBUFS; |
| 2829 | } |
| 2830 | |
| 2831 | return genlmsg_reply(msg, info); |
| 2832 | } |
| 2833 | |
| 2834 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2835 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2836 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2837 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2838 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2839 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2840 | }; |
| 2841 | |
| 2842 | static int parse_txq_params(struct nlattr *tb[], |
| 2843 | struct ieee80211_txq_params *txq_params) |
| 2844 | { |
| 2845 | u8 ac; |
| 2846 | |
| 2847 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 2848 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2849 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2850 | return -EINVAL; |
| 2851 | |
| 2852 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
| 2853 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2854 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2855 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2856 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2857 | |
| 2858 | if (ac >= NL80211_NUM_ACS) |
| 2859 | return -EINVAL; |
| 2860 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
| 2861 | return 0; |
| 2862 | } |
| 2863 | |
| 2864 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2865 | { |
| 2866 | /* |
| 2867 | * You can only set the channel explicitly for WDS interfaces, |
| 2868 | * all others have their channel managed via their respective |
| 2869 | * "establish a connection" command (connect, join, ...) |
| 2870 | * |
| 2871 | * For AP/GO and mesh mode, the channel can be set with the |
| 2872 | * channel userspace API, but is only stored and passed to the |
| 2873 | * low-level driver when the AP starts or the mesh is joined. |
| 2874 | * This is for backward compatibility, userspace can also give |
| 2875 | * the channel in the start-ap or join-mesh commands instead. |
| 2876 | * |
| 2877 | * Monitors are special as they are normally slaved to |
| 2878 | * whatever else is going on, so they have their own special |
| 2879 | * operation to set the monitor channel if possible. |
| 2880 | */ |
| 2881 | return !wdev || |
| 2882 | wdev->iftype == NL80211_IFTYPE_AP || |
| 2883 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
| 2884 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2885 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
| 2886 | } |
| 2887 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2888 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2889 | struct genl_info *info, |
| 2890 | struct cfg80211_chan_def *chandef) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2891 | { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2892 | struct netlink_ext_ack *extack = info->extack; |
| 2893 | struct nlattr **attrs = info->attrs; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2894 | u32 control_freq; |
| 2895 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2896 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2897 | return -EINVAL; |
| 2898 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2899 | control_freq = MHZ_TO_KHZ( |
| 2900 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2901 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 2902 | control_freq += |
| 2903 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2904 | |
| 2905 | memset(chandef, 0, sizeof(*chandef)); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2906 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2907 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2908 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
| 2909 | chandef->freq1_offset = control_freq % 1000; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2910 | chandef->center_freq2 = 0; |
| 2911 | |
| 2912 | /* Primary channel not allowed */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2913 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2914 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2915 | "Channel is disabled"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2916 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2917 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2918 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2919 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2920 | enum nl80211_channel_type chantype; |
| 2921 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2922 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2923 | |
| 2924 | switch (chantype) { |
| 2925 | case NL80211_CHAN_NO_HT: |
| 2926 | case NL80211_CHAN_HT20: |
| 2927 | case NL80211_CHAN_HT40PLUS: |
| 2928 | case NL80211_CHAN_HT40MINUS: |
| 2929 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2930 | chantype); |
| 2931 | /* user input for center_freq is incorrect */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2932 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2933 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2934 | NL_SET_ERR_MSG_ATTR(extack, |
| 2935 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2936 | "bad center frequency 1"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2937 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2938 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2939 | /* center_freq2 must be zero */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2940 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2941 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2942 | NL_SET_ERR_MSG_ATTR(extack, |
| 2943 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2944 | "center frequency 2 can't be used"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2945 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2946 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2947 | break; |
| 2948 | default: |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2949 | NL_SET_ERR_MSG_ATTR(extack, |
| 2950 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2951 | "invalid channel type"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2952 | return -EINVAL; |
| 2953 | } |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2954 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2955 | chandef->width = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2956 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2957 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2958 | chandef->center_freq1 = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2959 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2960 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
| 2961 | chandef->freq1_offset = nla_get_u32( |
| 2962 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); |
| 2963 | else |
| 2964 | chandef->freq1_offset = 0; |
| 2965 | } |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2966 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2967 | chandef->center_freq2 = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2968 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2971 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 2972 | chandef->edmg.channels = |
| 2973 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 2974 | |
| 2975 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 2976 | chandef->edmg.bw_config = |
| 2977 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 2978 | } else { |
| 2979 | chandef->edmg.bw_config = 0; |
| 2980 | chandef->edmg.channels = 0; |
| 2981 | } |
| 2982 | |
| 2983 | if (!cfg80211_chandef_valid(chandef)) { |
| 2984 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2985 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2986 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2987 | |
| 2988 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2989 | IEEE80211_CHAN_DISABLED)) { |
| 2990 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2991 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2992 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2993 | |
| 2994 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2995 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2996 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2997 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2998 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2999 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3000 | |
| 3001 | return 0; |
| 3002 | } |
| 3003 | |
| 3004 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 3005 | struct net_device *dev, |
| 3006 | struct genl_info *info) |
| 3007 | { |
| 3008 | struct cfg80211_chan_def chandef; |
| 3009 | int result; |
| 3010 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 3011 | struct wireless_dev *wdev = NULL; |
| 3012 | |
| 3013 | if (dev) |
| 3014 | wdev = dev->ieee80211_ptr; |
| 3015 | if (!nl80211_can_set_dev_channel(wdev)) |
| 3016 | return -EOPNOTSUPP; |
| 3017 | if (wdev) |
| 3018 | iftype = wdev->iftype; |
| 3019 | |
| 3020 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 3021 | if (result) |
| 3022 | return result; |
| 3023 | |
| 3024 | switch (iftype) { |
| 3025 | case NL80211_IFTYPE_AP: |
| 3026 | case NL80211_IFTYPE_P2P_GO: |
| 3027 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 3028 | iftype)) { |
| 3029 | result = -EINVAL; |
| 3030 | break; |
| 3031 | } |
| 3032 | if (wdev->beacon_interval) { |
| 3033 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 3034 | !(rdev->wiphy.features & |
| 3035 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 3036 | result = -EBUSY; |
| 3037 | break; |
| 3038 | } |
| 3039 | |
| 3040 | /* Only allow dynamic channel width changes */ |
| 3041 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 3042 | result = -EBUSY; |
| 3043 | break; |
| 3044 | } |
| 3045 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 3046 | if (result) |
| 3047 | break; |
| 3048 | } |
| 3049 | wdev->preset_chandef = chandef; |
| 3050 | result = 0; |
| 3051 | break; |
| 3052 | case NL80211_IFTYPE_MESH_POINT: |
| 3053 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
| 3054 | break; |
| 3055 | case NL80211_IFTYPE_MONITOR: |
| 3056 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
| 3057 | break; |
| 3058 | default: |
| 3059 | result = -EINVAL; |
| 3060 | } |
| 3061 | |
| 3062 | return result; |
| 3063 | } |
| 3064 | |
| 3065 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 3066 | { |
| 3067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3068 | struct net_device *netdev = info->user_ptr[1]; |
| 3069 | |
| 3070 | return __nl80211_set_channel(rdev, netdev, info); |
| 3071 | } |
| 3072 | |
| 3073 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 3074 | { |
| 3075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3076 | struct net_device *dev = info->user_ptr[1]; |
| 3077 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3078 | const u8 *bssid; |
| 3079 | |
| 3080 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3081 | return -EINVAL; |
| 3082 | |
| 3083 | if (netif_running(dev)) |
| 3084 | return -EBUSY; |
| 3085 | |
| 3086 | if (!rdev->ops->set_wds_peer) |
| 3087 | return -EOPNOTSUPP; |
| 3088 | |
| 3089 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 3090 | return -EOPNOTSUPP; |
| 3091 | |
| 3092 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3093 | return rdev_set_wds_peer(rdev, dev, bssid); |
| 3094 | } |
| 3095 | |
| 3096 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 3097 | { |
| 3098 | struct cfg80211_registered_device *rdev; |
| 3099 | struct net_device *netdev = NULL; |
| 3100 | struct wireless_dev *wdev; |
| 3101 | int result = 0, rem_txq_params = 0; |
| 3102 | struct nlattr *nl_txq_params; |
| 3103 | u32 changed; |
| 3104 | u8 retry_short = 0, retry_long = 0; |
| 3105 | u32 frag_threshold = 0, rts_threshold = 0; |
| 3106 | u8 coverage_class = 0; |
| 3107 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
| 3108 | |
| 3109 | ASSERT_RTNL(); |
| 3110 | |
| 3111 | /* |
| 3112 | * Try to find the wiphy and netdev. Normally this |
| 3113 | * function shouldn't need the netdev, but this is |
| 3114 | * done for backward compatibility -- previously |
| 3115 | * setting the channel was done per wiphy, but now |
| 3116 | * it is per netdev. Previous userland like hostapd |
| 3117 | * also passed a netdev to set_wiphy, so that it is |
| 3118 | * possible to let that go to the right netdev! |
| 3119 | */ |
| 3120 | |
| 3121 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 3122 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 3123 | |
| 3124 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
| 3125 | if (netdev && netdev->ieee80211_ptr) |
| 3126 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
| 3127 | else |
| 3128 | netdev = NULL; |
| 3129 | } |
| 3130 | |
| 3131 | if (!netdev) { |
| 3132 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3133 | info->attrs); |
| 3134 | if (IS_ERR(rdev)) |
| 3135 | return PTR_ERR(rdev); |
| 3136 | wdev = NULL; |
| 3137 | netdev = NULL; |
| 3138 | result = 0; |
| 3139 | } else |
| 3140 | wdev = netdev->ieee80211_ptr; |
| 3141 | |
| 3142 | /* |
| 3143 | * end workaround code, by now the rdev is available |
| 3144 | * and locked, and wdev may or may not be NULL. |
| 3145 | */ |
| 3146 | |
| 3147 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
| 3148 | result = cfg80211_dev_rename( |
| 3149 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
| 3150 | |
| 3151 | if (result) |
| 3152 | return result; |
| 3153 | |
| 3154 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3155 | struct ieee80211_txq_params txq_params; |
| 3156 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3157 | |
| 3158 | if (!rdev->ops->set_txq_params) |
| 3159 | return -EOPNOTSUPP; |
| 3160 | |
| 3161 | if (!netdev) |
| 3162 | return -EINVAL; |
| 3163 | |
| 3164 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3165 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3166 | return -EINVAL; |
| 3167 | |
| 3168 | if (!netif_running(netdev)) |
| 3169 | return -ENETDOWN; |
| 3170 | |
| 3171 | nla_for_each_nested(nl_txq_params, |
| 3172 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3173 | rem_txq_params) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3174 | result = nla_parse_nested_deprecated(tb, |
| 3175 | NL80211_TXQ_ATTR_MAX, |
| 3176 | nl_txq_params, |
| 3177 | txq_params_policy, |
| 3178 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3179 | if (result) |
| 3180 | return result; |
| 3181 | result = parse_txq_params(tb, &txq_params); |
| 3182 | if (result) |
| 3183 | return result; |
| 3184 | |
| 3185 | result = rdev_set_txq_params(rdev, netdev, |
| 3186 | &txq_params); |
| 3187 | if (result) |
| 3188 | return result; |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 3193 | result = __nl80211_set_channel( |
| 3194 | rdev, |
| 3195 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3196 | info); |
| 3197 | if (result) |
| 3198 | return result; |
| 3199 | } |
| 3200 | |
| 3201 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 3202 | struct wireless_dev *txp_wdev = wdev; |
| 3203 | enum nl80211_tx_power_setting type; |
| 3204 | int idx, mbm = 0; |
| 3205 | |
| 3206 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3207 | txp_wdev = NULL; |
| 3208 | |
| 3209 | if (!rdev->ops->set_tx_power) |
| 3210 | return -EOPNOTSUPP; |
| 3211 | |
| 3212 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3213 | type = nla_get_u32(info->attrs[idx]); |
| 3214 | |
| 3215 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 3216 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 3217 | return -EINVAL; |
| 3218 | |
| 3219 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3220 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3221 | mbm = nla_get_u32(info->attrs[idx]); |
| 3222 | } |
| 3223 | |
| 3224 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
| 3225 | if (result) |
| 3226 | return result; |
| 3227 | } |
| 3228 | |
| 3229 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3230 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3231 | u32 tx_ant, rx_ant; |
| 3232 | |
| 3233 | if ((!rdev->wiphy.available_antennas_tx && |
| 3234 | !rdev->wiphy.available_antennas_rx) || |
| 3235 | !rdev->ops->set_antenna) |
| 3236 | return -EOPNOTSUPP; |
| 3237 | |
| 3238 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3239 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3240 | |
| 3241 | /* reject antenna configurations which don't match the |
| 3242 | * available antenna masks, except for the "all" mask */ |
| 3243 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 3244 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 3245 | return -EINVAL; |
| 3246 | |
| 3247 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3248 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
| 3249 | |
| 3250 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
| 3251 | if (result) |
| 3252 | return result; |
| 3253 | } |
| 3254 | |
| 3255 | changed = 0; |
| 3256 | |
| 3257 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3258 | retry_short = nla_get_u8( |
| 3259 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3260 | |
| 3261 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3262 | } |
| 3263 | |
| 3264 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3265 | retry_long = nla_get_u8( |
| 3266 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3267 | |
| 3268 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3269 | } |
| 3270 | |
| 3271 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3272 | frag_threshold = nla_get_u32( |
| 3273 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 3274 | if (frag_threshold < 256) |
| 3275 | return -EINVAL; |
| 3276 | |
| 3277 | if (frag_threshold != (u32) -1) { |
| 3278 | /* |
| 3279 | * Fragments (apart from the last one) are required to |
| 3280 | * have even length. Make the fragmentation code |
| 3281 | * simpler by stripping LSB should someone try to use |
| 3282 | * odd threshold value. |
| 3283 | */ |
| 3284 | frag_threshold &= ~0x1; |
| 3285 | } |
| 3286 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3287 | } |
| 3288 | |
| 3289 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3290 | rts_threshold = nla_get_u32( |
| 3291 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3292 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3293 | } |
| 3294 | |
| 3295 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 3296 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 3297 | return -EINVAL; |
| 3298 | |
| 3299 | coverage_class = nla_get_u8( |
| 3300 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3301 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3302 | } |
| 3303 | |
| 3304 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3305 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 3306 | return -EOPNOTSUPP; |
| 3307 | |
| 3308 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3309 | } |
| 3310 | |
| 3311 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3312 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3313 | NL80211_EXT_FEATURE_TXQS)) |
| 3314 | return -EOPNOTSUPP; |
| 3315 | txq_limit = nla_get_u32( |
| 3316 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3317 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3318 | } |
| 3319 | |
| 3320 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3321 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3322 | NL80211_EXT_FEATURE_TXQS)) |
| 3323 | return -EOPNOTSUPP; |
| 3324 | txq_memory_limit = nla_get_u32( |
| 3325 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3326 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3327 | } |
| 3328 | |
| 3329 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3330 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3331 | NL80211_EXT_FEATURE_TXQS)) |
| 3332 | return -EOPNOTSUPP; |
| 3333 | txq_quantum = nla_get_u32( |
| 3334 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3335 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3336 | } |
| 3337 | |
| 3338 | if (changed) { |
| 3339 | u8 old_retry_short, old_retry_long; |
| 3340 | u32 old_frag_threshold, old_rts_threshold; |
| 3341 | u8 old_coverage_class; |
| 3342 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
| 3343 | |
| 3344 | if (!rdev->ops->set_wiphy_params) |
| 3345 | return -EOPNOTSUPP; |
| 3346 | |
| 3347 | old_retry_short = rdev->wiphy.retry_short; |
| 3348 | old_retry_long = rdev->wiphy.retry_long; |
| 3349 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3350 | old_rts_threshold = rdev->wiphy.rts_threshold; |
| 3351 | old_coverage_class = rdev->wiphy.coverage_class; |
| 3352 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3353 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3354 | old_txq_quantum = rdev->wiphy.txq_quantum; |
| 3355 | |
| 3356 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3357 | rdev->wiphy.retry_short = retry_short; |
| 3358 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3359 | rdev->wiphy.retry_long = retry_long; |
| 3360 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3361 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3362 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3363 | rdev->wiphy.rts_threshold = rts_threshold; |
| 3364 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3365 | rdev->wiphy.coverage_class = coverage_class; |
| 3366 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3367 | rdev->wiphy.txq_limit = txq_limit; |
| 3368 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3369 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3370 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3371 | rdev->wiphy.txq_quantum = txq_quantum; |
| 3372 | |
| 3373 | result = rdev_set_wiphy_params(rdev, changed); |
| 3374 | if (result) { |
| 3375 | rdev->wiphy.retry_short = old_retry_short; |
| 3376 | rdev->wiphy.retry_long = old_retry_long; |
| 3377 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3378 | rdev->wiphy.rts_threshold = old_rts_threshold; |
| 3379 | rdev->wiphy.coverage_class = old_coverage_class; |
| 3380 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3381 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3382 | rdev->wiphy.txq_quantum = old_txq_quantum; |
| 3383 | return result; |
| 3384 | } |
| 3385 | } |
| 3386 | return 0; |
| 3387 | } |
| 3388 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3389 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 3390 | const struct cfg80211_chan_def *chandef) |
| 3391 | { |
| 3392 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3393 | return -EINVAL; |
| 3394 | |
| 3395 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3396 | chandef->chan->center_freq)) |
| 3397 | return -ENOBUFS; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 3398 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 3399 | chandef->chan->freq_offset)) |
| 3400 | return -ENOBUFS; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3401 | switch (chandef->width) { |
| 3402 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3403 | case NL80211_CHAN_WIDTH_20: |
| 3404 | case NL80211_CHAN_WIDTH_40: |
| 3405 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3406 | cfg80211_get_chandef_type(chandef))) |
| 3407 | return -ENOBUFS; |
| 3408 | break; |
| 3409 | default: |
| 3410 | break; |
| 3411 | } |
| 3412 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3413 | return -ENOBUFS; |
| 3414 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3415 | return -ENOBUFS; |
| 3416 | if (chandef->center_freq2 && |
| 3417 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
| 3418 | return -ENOBUFS; |
| 3419 | return 0; |
| 3420 | } |
| 3421 | |
| 3422 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
| 3423 | struct cfg80211_registered_device *rdev, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3424 | struct wireless_dev *wdev, |
| 3425 | enum nl80211_commands cmd) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3426 | { |
| 3427 | struct net_device *dev = wdev->netdev; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3428 | void *hdr; |
| 3429 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3430 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3431 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3432 | cmd != NL80211_CMD_SET_INTERFACE); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3433 | |
| 3434 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
| 3435 | if (!hdr) |
| 3436 | return -1; |
| 3437 | |
| 3438 | if (dev && |
| 3439 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3440 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
| 3441 | goto nla_put_failure; |
| 3442 | |
| 3443 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3444 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
| 3445 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3446 | NL80211_ATTR_PAD) || |
| 3447 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
| 3448 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3449 | rdev->devlist_generation ^ |
| 3450 | (cfg80211_rdev_list_generation << 2)) || |
| 3451 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
| 3452 | goto nla_put_failure; |
| 3453 | |
| 3454 | if (rdev->ops->get_channel) { |
| 3455 | int ret; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3456 | struct cfg80211_chan_def chandef = {}; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3457 | |
| 3458 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3459 | if (ret == 0) { |
| 3460 | if (nl80211_send_chandef(msg, &chandef)) |
| 3461 | goto nla_put_failure; |
| 3462 | } |
| 3463 | } |
| 3464 | |
| 3465 | if (rdev->ops->get_tx_power) { |
| 3466 | int dbm, ret; |
| 3467 | |
| 3468 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3469 | if (ret == 0 && |
| 3470 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3471 | DBM_TO_MBM(dbm))) |
| 3472 | goto nla_put_failure; |
| 3473 | } |
| 3474 | |
| 3475 | wdev_lock(wdev); |
| 3476 | switch (wdev->iftype) { |
| 3477 | case NL80211_IFTYPE_AP: |
| 3478 | if (wdev->ssid_len && |
| 3479 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 3480 | goto nla_put_failure_locked; |
| 3481 | break; |
| 3482 | case NL80211_IFTYPE_STATION: |
| 3483 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3484 | case NL80211_IFTYPE_ADHOC: { |
| 3485 | const u8 *ssid_ie; |
| 3486 | if (!wdev->current_bss) |
| 3487 | break; |
| 3488 | rcu_read_lock(); |
| 3489 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3490 | WLAN_EID_SSID); |
| 3491 | if (ssid_ie && |
| 3492 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3493 | goto nla_put_failure_rcu_locked; |
| 3494 | rcu_read_unlock(); |
| 3495 | break; |
| 3496 | } |
| 3497 | default: |
| 3498 | /* nothing */ |
| 3499 | break; |
| 3500 | } |
| 3501 | wdev_unlock(wdev); |
| 3502 | |
| 3503 | if (rdev->ops->get_txq_stats) { |
| 3504 | struct cfg80211_txq_stats txqstats = {}; |
| 3505 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3506 | |
| 3507 | if (ret == 0 && |
| 3508 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3509 | NL80211_ATTR_TXQ_STATS)) |
| 3510 | goto nla_put_failure; |
| 3511 | } |
| 3512 | |
| 3513 | genlmsg_end(msg, hdr); |
| 3514 | return 0; |
| 3515 | |
| 3516 | nla_put_failure_rcu_locked: |
| 3517 | rcu_read_unlock(); |
| 3518 | nla_put_failure_locked: |
| 3519 | wdev_unlock(wdev); |
| 3520 | nla_put_failure: |
| 3521 | genlmsg_cancel(msg, hdr); |
| 3522 | return -EMSGSIZE; |
| 3523 | } |
| 3524 | |
| 3525 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3526 | { |
| 3527 | int wp_idx = 0; |
| 3528 | int if_idx = 0; |
| 3529 | int wp_start = cb->args[0]; |
| 3530 | int if_start = cb->args[1]; |
| 3531 | int filter_wiphy = -1; |
| 3532 | struct cfg80211_registered_device *rdev; |
| 3533 | struct wireless_dev *wdev; |
| 3534 | int ret; |
| 3535 | |
| 3536 | rtnl_lock(); |
| 3537 | if (!cb->args[2]) { |
| 3538 | struct nl80211_dump_wiphy_state state = { |
| 3539 | .filter_wiphy = -1, |
| 3540 | }; |
| 3541 | |
| 3542 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3543 | if (ret) |
| 3544 | goto out_unlock; |
| 3545 | |
| 3546 | filter_wiphy = state.filter_wiphy; |
| 3547 | |
| 3548 | /* |
| 3549 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3550 | * value needed to determine that parsing is necessary. |
| 3551 | */ |
| 3552 | if (filter_wiphy >= 0) |
| 3553 | cb->args[2] = filter_wiphy + 1; |
| 3554 | else |
| 3555 | cb->args[2] = -1; |
| 3556 | } else if (cb->args[2] > 0) { |
| 3557 | filter_wiphy = cb->args[2] - 1; |
| 3558 | } |
| 3559 | |
| 3560 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3561 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
| 3562 | continue; |
| 3563 | if (wp_idx < wp_start) { |
| 3564 | wp_idx++; |
| 3565 | continue; |
| 3566 | } |
| 3567 | |
| 3568 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3569 | continue; |
| 3570 | |
| 3571 | if_idx = 0; |
| 3572 | |
| 3573 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 3574 | if (if_idx < if_start) { |
| 3575 | if_idx++; |
| 3576 | continue; |
| 3577 | } |
| 3578 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
| 3579 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3580 | rdev, wdev, |
| 3581 | NL80211_CMD_NEW_INTERFACE) < 0) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3582 | goto out; |
| 3583 | } |
| 3584 | if_idx++; |
| 3585 | } |
| 3586 | |
| 3587 | wp_idx++; |
| 3588 | } |
| 3589 | out: |
| 3590 | cb->args[0] = wp_idx; |
| 3591 | cb->args[1] = if_idx; |
| 3592 | |
| 3593 | ret = skb->len; |
| 3594 | out_unlock: |
| 3595 | rtnl_unlock(); |
| 3596 | |
| 3597 | return ret; |
| 3598 | } |
| 3599 | |
| 3600 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3601 | { |
| 3602 | struct sk_buff *msg; |
| 3603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3604 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 3605 | |
| 3606 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3607 | if (!msg) |
| 3608 | return -ENOMEM; |
| 3609 | |
| 3610 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3611 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3612 | nlmsg_free(msg); |
| 3613 | return -ENOBUFS; |
| 3614 | } |
| 3615 | |
| 3616 | return genlmsg_reply(msg, info); |
| 3617 | } |
| 3618 | |
| 3619 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3620 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3621 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3622 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3623 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3624 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 3625 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
| 3626 | }; |
| 3627 | |
| 3628 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3629 | { |
| 3630 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3631 | int flag; |
| 3632 | |
| 3633 | *mntrflags = 0; |
| 3634 | |
| 3635 | if (!nla) |
| 3636 | return -EINVAL; |
| 3637 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3638 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3639 | return -EINVAL; |
| 3640 | |
| 3641 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3642 | if (flags[flag]) |
| 3643 | *mntrflags |= (1<<flag); |
| 3644 | |
| 3645 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3646 | |
| 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3651 | enum nl80211_iftype type, |
| 3652 | struct genl_info *info, |
| 3653 | struct vif_params *params) |
| 3654 | { |
| 3655 | bool change = false; |
| 3656 | int err; |
| 3657 | |
| 3658 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3659 | if (type != NL80211_IFTYPE_MONITOR) |
| 3660 | return -EINVAL; |
| 3661 | |
| 3662 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3663 | ¶ms->flags); |
| 3664 | if (err) |
| 3665 | return err; |
| 3666 | |
| 3667 | change = true; |
| 3668 | } |
| 3669 | |
| 3670 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3671 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3672 | return -EOPNOTSUPP; |
| 3673 | |
| 3674 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3675 | const u8 *mumimo_groups; |
| 3676 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3677 | |
| 3678 | if (type != NL80211_IFTYPE_MONITOR) |
| 3679 | return -EINVAL; |
| 3680 | |
| 3681 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3682 | return -EOPNOTSUPP; |
| 3683 | |
| 3684 | mumimo_groups = |
| 3685 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3686 | |
| 3687 | /* bits 0 and 63 are reserved and must be zero */ |
| 3688 | if ((mumimo_groups[0] & BIT(0)) || |
| 3689 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
| 3690 | return -EINVAL; |
| 3691 | |
| 3692 | params->vht_mumimo_groups = mumimo_groups; |
| 3693 | change = true; |
| 3694 | } |
| 3695 | |
| 3696 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3697 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3698 | |
| 3699 | if (type != NL80211_IFTYPE_MONITOR) |
| 3700 | return -EINVAL; |
| 3701 | |
| 3702 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3703 | return -EOPNOTSUPP; |
| 3704 | |
| 3705 | params->vht_mumimo_follow_addr = |
| 3706 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3707 | change = true; |
| 3708 | } |
| 3709 | |
| 3710 | return change ? 1 : 0; |
| 3711 | } |
| 3712 | |
| 3713 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
| 3714 | struct net_device *netdev, u8 use_4addr, |
| 3715 | enum nl80211_iftype iftype) |
| 3716 | { |
| 3717 | if (!use_4addr) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 3718 | if (netdev && netif_is_bridge_port(netdev)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3719 | return -EBUSY; |
| 3720 | return 0; |
| 3721 | } |
| 3722 | |
| 3723 | switch (iftype) { |
| 3724 | case NL80211_IFTYPE_AP_VLAN: |
| 3725 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3726 | return 0; |
| 3727 | break; |
| 3728 | case NL80211_IFTYPE_STATION: |
| 3729 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3730 | return 0; |
| 3731 | break; |
| 3732 | default: |
| 3733 | break; |
| 3734 | } |
| 3735 | |
| 3736 | return -EOPNOTSUPP; |
| 3737 | } |
| 3738 | |
| 3739 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3740 | { |
| 3741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3742 | struct vif_params params; |
| 3743 | int err; |
| 3744 | enum nl80211_iftype otype, ntype; |
| 3745 | struct net_device *dev = info->user_ptr[1]; |
| 3746 | bool change = false; |
| 3747 | |
| 3748 | memset(¶ms, 0, sizeof(params)); |
| 3749 | |
| 3750 | otype = ntype = dev->ieee80211_ptr->iftype; |
| 3751 | |
| 3752 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 3753 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 3754 | if (otype != ntype) |
| 3755 | change = true; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
| 3759 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3760 | |
| 3761 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3762 | return -EINVAL; |
| 3763 | if (netif_running(dev)) |
| 3764 | return -EBUSY; |
| 3765 | |
| 3766 | wdev_lock(wdev); |
| 3767 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3768 | IEEE80211_MAX_MESH_ID_LEN); |
| 3769 | wdev->mesh_id_up_len = |
| 3770 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3771 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3772 | wdev->mesh_id_up_len); |
| 3773 | wdev_unlock(wdev); |
| 3774 | } |
| 3775 | |
| 3776 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3777 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3778 | change = true; |
| 3779 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
| 3780 | if (err) |
| 3781 | return err; |
| 3782 | } else { |
| 3783 | params.use_4addr = -1; |
| 3784 | } |
| 3785 | |
| 3786 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3787 | if (err < 0) |
| 3788 | return err; |
| 3789 | if (err > 0) |
| 3790 | change = true; |
| 3791 | |
| 3792 | if (change) |
| 3793 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
| 3794 | else |
| 3795 | err = 0; |
| 3796 | |
| 3797 | if (!err && params.use_4addr != -1) |
| 3798 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3799 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3800 | if (change && !err) { |
| 3801 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3802 | |
| 3803 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3804 | } |
| 3805 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3806 | return err; |
| 3807 | } |
| 3808 | |
| 3809 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3810 | { |
| 3811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3812 | struct vif_params params; |
| 3813 | struct wireless_dev *wdev; |
| 3814 | struct sk_buff *msg; |
| 3815 | int err; |
| 3816 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3817 | |
| 3818 | /* to avoid failing a new interface creation due to pending removal */ |
| 3819 | cfg80211_destroy_ifaces(rdev); |
| 3820 | |
| 3821 | memset(¶ms, 0, sizeof(params)); |
| 3822 | |
| 3823 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3824 | return -EINVAL; |
| 3825 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3826 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3827 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3828 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3829 | if (!rdev->ops->add_virtual_intf) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3830 | return -EOPNOTSUPP; |
| 3831 | |
| 3832 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
| 3833 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3834 | info->attrs[NL80211_ATTR_MAC]) { |
| 3835 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3836 | ETH_ALEN); |
| 3837 | if (!is_valid_ether_addr(params.macaddr)) |
| 3838 | return -EADDRNOTAVAIL; |
| 3839 | } |
| 3840 | |
| 3841 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3842 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3843 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
| 3844 | if (err) |
| 3845 | return err; |
| 3846 | } |
| 3847 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3848 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
| 3849 | return -EOPNOTSUPP; |
| 3850 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3851 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3852 | if (err < 0) |
| 3853 | return err; |
| 3854 | |
| 3855 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3856 | if (!msg) |
| 3857 | return -ENOMEM; |
| 3858 | |
| 3859 | wdev = rdev_add_virtual_intf(rdev, |
| 3860 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 3861 | NET_NAME_USER, type, ¶ms); |
| 3862 | if (WARN_ON(!wdev)) { |
| 3863 | nlmsg_free(msg); |
| 3864 | return -EPROTO; |
| 3865 | } else if (IS_ERR(wdev)) { |
| 3866 | nlmsg_free(msg); |
| 3867 | return PTR_ERR(wdev); |
| 3868 | } |
| 3869 | |
| 3870 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 3871 | wdev->owner_nlportid = info->snd_portid; |
| 3872 | |
| 3873 | switch (type) { |
| 3874 | case NL80211_IFTYPE_MESH_POINT: |
| 3875 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3876 | break; |
| 3877 | wdev_lock(wdev); |
| 3878 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3879 | IEEE80211_MAX_MESH_ID_LEN); |
| 3880 | wdev->mesh_id_up_len = |
| 3881 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3882 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3883 | wdev->mesh_id_up_len); |
| 3884 | wdev_unlock(wdev); |
| 3885 | break; |
| 3886 | case NL80211_IFTYPE_NAN: |
| 3887 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3888 | /* |
| 3889 | * P2P Device and NAN do not have a netdev, so don't go |
| 3890 | * through the netdev notifier and must be added here |
| 3891 | */ |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 3892 | cfg80211_init_wdev(wdev); |
| 3893 | cfg80211_register_wdev(rdev, wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3894 | break; |
| 3895 | default: |
| 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3900 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3901 | nlmsg_free(msg); |
| 3902 | return -ENOBUFS; |
| 3903 | } |
| 3904 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3905 | return genlmsg_reply(msg, info); |
| 3906 | } |
| 3907 | |
| 3908 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3909 | { |
| 3910 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3911 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 3912 | |
| 3913 | if (!rdev->ops->del_virtual_intf) |
| 3914 | return -EOPNOTSUPP; |
| 3915 | |
| 3916 | /* |
| 3917 | * If we remove a wireless device without a netdev then clear |
| 3918 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3919 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3920 | * since the wdev has been freed, unlike with a netdev where |
| 3921 | * we need the dev_put() for the netdev to really be freed. |
| 3922 | */ |
| 3923 | if (!wdev->netdev) |
| 3924 | info->user_ptr[1] = NULL; |
| 3925 | |
| 3926 | return rdev_del_virtual_intf(rdev, wdev); |
| 3927 | } |
| 3928 | |
| 3929 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3930 | { |
| 3931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3932 | struct net_device *dev = info->user_ptr[1]; |
| 3933 | u16 noack_map; |
| 3934 | |
| 3935 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3936 | return -EINVAL; |
| 3937 | |
| 3938 | if (!rdev->ops->set_noack_map) |
| 3939 | return -EOPNOTSUPP; |
| 3940 | |
| 3941 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3942 | |
| 3943 | return rdev_set_noack_map(rdev, dev, noack_map); |
| 3944 | } |
| 3945 | |
| 3946 | struct get_key_cookie { |
| 3947 | struct sk_buff *msg; |
| 3948 | int error; |
| 3949 | int idx; |
| 3950 | }; |
| 3951 | |
| 3952 | static void get_key_callback(void *c, struct key_params *params) |
| 3953 | { |
| 3954 | struct nlattr *key; |
| 3955 | struct get_key_cookie *cookie = c; |
| 3956 | |
| 3957 | if ((params->key && |
| 3958 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3959 | params->key_len, params->key)) || |
| 3960 | (params->seq && |
| 3961 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3962 | params->seq_len, params->seq)) || |
| 3963 | (params->cipher && |
| 3964 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3965 | params->cipher))) |
| 3966 | goto nla_put_failure; |
| 3967 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3968 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3969 | if (!key) |
| 3970 | goto nla_put_failure; |
| 3971 | |
| 3972 | if ((params->key && |
| 3973 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3974 | params->key_len, params->key)) || |
| 3975 | (params->seq && |
| 3976 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3977 | params->seq_len, params->seq)) || |
| 3978 | (params->cipher && |
| 3979 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3980 | params->cipher))) |
| 3981 | goto nla_put_failure; |
| 3982 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 3983 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3984 | goto nla_put_failure; |
| 3985 | |
| 3986 | nla_nest_end(cookie->msg, key); |
| 3987 | |
| 3988 | return; |
| 3989 | nla_put_failure: |
| 3990 | cookie->error = 1; |
| 3991 | } |
| 3992 | |
| 3993 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3994 | { |
| 3995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3996 | int err; |
| 3997 | struct net_device *dev = info->user_ptr[1]; |
| 3998 | u8 key_idx = 0; |
| 3999 | const u8 *mac_addr = NULL; |
| 4000 | bool pairwise; |
| 4001 | struct get_key_cookie cookie = { |
| 4002 | .error = 0, |
| 4003 | }; |
| 4004 | void *hdr; |
| 4005 | struct sk_buff *msg; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4006 | bool bigtk_support = false; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4007 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4008 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 4009 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 4010 | bigtk_support = true; |
| 4011 | |
| 4012 | if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || |
| 4013 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| 4014 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4015 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
| 4016 | bigtk_support = true; |
| 4017 | |
| 4018 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4019 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 4020 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4021 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { |
| 4022 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); |
| 4023 | return -EINVAL; |
| 4024 | } |
| 4025 | } |
| 4026 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4027 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4028 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4029 | |
| 4030 | pairwise = !!mac_addr; |
| 4031 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 4032 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 4033 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4034 | if (kt != NL80211_KEYTYPE_GROUP && |
| 4035 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 4036 | return -EINVAL; |
| 4037 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 4038 | } |
| 4039 | |
| 4040 | if (!rdev->ops->get_key) |
| 4041 | return -EOPNOTSUPP; |
| 4042 | |
| 4043 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4044 | return -ENOENT; |
| 4045 | |
| 4046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4047 | if (!msg) |
| 4048 | return -ENOMEM; |
| 4049 | |
| 4050 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 4051 | NL80211_CMD_NEW_KEY); |
| 4052 | if (!hdr) |
| 4053 | goto nla_put_failure; |
| 4054 | |
| 4055 | cookie.msg = msg; |
| 4056 | cookie.idx = key_idx; |
| 4057 | |
| 4058 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4059 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 4060 | goto nla_put_failure; |
| 4061 | if (mac_addr && |
| 4062 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 4063 | goto nla_put_failure; |
| 4064 | |
| 4065 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 4066 | get_key_callback); |
| 4067 | |
| 4068 | if (err) |
| 4069 | goto free_msg; |
| 4070 | |
| 4071 | if (cookie.error) |
| 4072 | goto nla_put_failure; |
| 4073 | |
| 4074 | genlmsg_end(msg, hdr); |
| 4075 | return genlmsg_reply(msg, info); |
| 4076 | |
| 4077 | nla_put_failure: |
| 4078 | err = -ENOBUFS; |
| 4079 | free_msg: |
| 4080 | nlmsg_free(msg); |
| 4081 | return err; |
| 4082 | } |
| 4083 | |
| 4084 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 4085 | { |
| 4086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4087 | struct key_parse key; |
| 4088 | int err; |
| 4089 | struct net_device *dev = info->user_ptr[1]; |
| 4090 | |
| 4091 | err = nl80211_parse_key(info, &key); |
| 4092 | if (err) |
| 4093 | return err; |
| 4094 | |
| 4095 | if (key.idx < 0) |
| 4096 | return -EINVAL; |
| 4097 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4098 | /* Only support setting default key and |
| 4099 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 4100 | */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4101 | if (!key.def && !key.defmgmt && !key.defbeacon && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4102 | !(key.p.mode == NL80211_KEY_SET_TX)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4103 | return -EINVAL; |
| 4104 | |
| 4105 | wdev_lock(dev->ieee80211_ptr); |
| 4106 | |
| 4107 | if (key.def) { |
| 4108 | if (!rdev->ops->set_default_key) { |
| 4109 | err = -EOPNOTSUPP; |
| 4110 | goto out; |
| 4111 | } |
| 4112 | |
| 4113 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4114 | if (err) |
| 4115 | goto out; |
| 4116 | |
| 4117 | err = rdev_set_default_key(rdev, dev, key.idx, |
| 4118 | key.def_uni, key.def_multi); |
| 4119 | |
| 4120 | if (err) |
| 4121 | goto out; |
| 4122 | |
| 4123 | #ifdef CONFIG_CFG80211_WEXT |
| 4124 | dev->ieee80211_ptr->wext.default_key = key.idx; |
| 4125 | #endif |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4126 | } else if (key.defmgmt) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4127 | if (key.def_uni || !key.def_multi) { |
| 4128 | err = -EINVAL; |
| 4129 | goto out; |
| 4130 | } |
| 4131 | |
| 4132 | if (!rdev->ops->set_default_mgmt_key) { |
| 4133 | err = -EOPNOTSUPP; |
| 4134 | goto out; |
| 4135 | } |
| 4136 | |
| 4137 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4138 | if (err) |
| 4139 | goto out; |
| 4140 | |
| 4141 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
| 4142 | if (err) |
| 4143 | goto out; |
| 4144 | |
| 4145 | #ifdef CONFIG_CFG80211_WEXT |
| 4146 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4147 | #endif |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4148 | } else if (key.defbeacon) { |
| 4149 | if (key.def_uni || !key.def_multi) { |
| 4150 | err = -EINVAL; |
| 4151 | goto out; |
| 4152 | } |
| 4153 | |
| 4154 | if (!rdev->ops->set_default_beacon_key) { |
| 4155 | err = -EOPNOTSUPP; |
| 4156 | goto out; |
| 4157 | } |
| 4158 | |
| 4159 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4160 | if (err) |
| 4161 | goto out; |
| 4162 | |
| 4163 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4164 | if (err) |
| 4165 | goto out; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4166 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4167 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4168 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4169 | u8 *mac_addr = NULL; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4170 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4171 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4172 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4173 | |
| 4174 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4175 | err = -EINVAL; |
| 4176 | goto out; |
| 4177 | } |
| 4178 | |
| 4179 | err = rdev_add_key(rdev, dev, key.idx, |
| 4180 | NL80211_KEYTYPE_PAIRWISE, |
| 4181 | mac_addr, &key.p); |
| 4182 | } else { |
| 4183 | err = -EINVAL; |
| 4184 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4185 | out: |
| 4186 | wdev_unlock(dev->ieee80211_ptr); |
| 4187 | |
| 4188 | return err; |
| 4189 | } |
| 4190 | |
| 4191 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4192 | { |
| 4193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4194 | int err; |
| 4195 | struct net_device *dev = info->user_ptr[1]; |
| 4196 | struct key_parse key; |
| 4197 | const u8 *mac_addr = NULL; |
| 4198 | |
| 4199 | err = nl80211_parse_key(info, &key); |
| 4200 | if (err) |
| 4201 | return err; |
| 4202 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4203 | if (!key.p.key) { |
| 4204 | GENL_SET_ERR_MSG(info, "no key"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4205 | return -EINVAL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4206 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4207 | |
| 4208 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4209 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4210 | |
| 4211 | if (key.type == -1) { |
| 4212 | if (mac_addr) |
| 4213 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4214 | else |
| 4215 | key.type = NL80211_KEYTYPE_GROUP; |
| 4216 | } |
| 4217 | |
| 4218 | /* for now */ |
| 4219 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4220 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4221 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4222 | return -EINVAL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4223 | } |
| 4224 | |
| 4225 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4226 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4227 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4228 | |
| 4229 | if (!rdev->ops->add_key) |
| 4230 | return -EOPNOTSUPP; |
| 4231 | |
| 4232 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4233 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4234 | mac_addr)) { |
| 4235 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4236 | return -EINVAL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4237 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4238 | |
| 4239 | wdev_lock(dev->ieee80211_ptr); |
| 4240 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4241 | if (err) |
| 4242 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4243 | if (!err) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4244 | err = rdev_add_key(rdev, dev, key.idx, |
| 4245 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4246 | mac_addr, &key.p); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4247 | if (err) |
| 4248 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4249 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4250 | wdev_unlock(dev->ieee80211_ptr); |
| 4251 | |
| 4252 | return err; |
| 4253 | } |
| 4254 | |
| 4255 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4256 | { |
| 4257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4258 | int err; |
| 4259 | struct net_device *dev = info->user_ptr[1]; |
| 4260 | u8 *mac_addr = NULL; |
| 4261 | struct key_parse key; |
| 4262 | |
| 4263 | err = nl80211_parse_key(info, &key); |
| 4264 | if (err) |
| 4265 | return err; |
| 4266 | |
| 4267 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4268 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4269 | |
| 4270 | if (key.type == -1) { |
| 4271 | if (mac_addr) |
| 4272 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4273 | else |
| 4274 | key.type = NL80211_KEYTYPE_GROUP; |
| 4275 | } |
| 4276 | |
| 4277 | /* for now */ |
| 4278 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4279 | key.type != NL80211_KEYTYPE_GROUP) |
| 4280 | return -EINVAL; |
| 4281 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 4282 | if (!cfg80211_valid_key_idx(rdev, key.idx, |
| 4283 | key.type == NL80211_KEYTYPE_PAIRWISE)) |
| 4284 | return -EINVAL; |
| 4285 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4286 | if (!rdev->ops->del_key) |
| 4287 | return -EOPNOTSUPP; |
| 4288 | |
| 4289 | wdev_lock(dev->ieee80211_ptr); |
| 4290 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4291 | |
| 4292 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
| 4293 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4294 | err = -ENOENT; |
| 4295 | |
| 4296 | if (!err) |
| 4297 | err = rdev_del_key(rdev, dev, key.idx, |
| 4298 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4299 | mac_addr); |
| 4300 | |
| 4301 | #ifdef CONFIG_CFG80211_WEXT |
| 4302 | if (!err) { |
| 4303 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
| 4304 | dev->ieee80211_ptr->wext.default_key = -1; |
| 4305 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
| 4306 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4307 | } |
| 4308 | #endif |
| 4309 | wdev_unlock(dev->ieee80211_ptr); |
| 4310 | |
| 4311 | return err; |
| 4312 | } |
| 4313 | |
| 4314 | /* This function returns an error or the number of nested attributes */ |
| 4315 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4316 | { |
| 4317 | struct nlattr *attr; |
| 4318 | int n_entries = 0, tmp; |
| 4319 | |
| 4320 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4321 | if (nla_len(attr) != ETH_ALEN) |
| 4322 | return -EINVAL; |
| 4323 | |
| 4324 | n_entries++; |
| 4325 | } |
| 4326 | |
| 4327 | return n_entries; |
| 4328 | } |
| 4329 | |
| 4330 | /* |
| 4331 | * This function parses ACL information and allocates memory for ACL data. |
| 4332 | * On successful return, the calling function is responsible to free the |
| 4333 | * ACL buffer returned by this function. |
| 4334 | */ |
| 4335 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4336 | struct genl_info *info) |
| 4337 | { |
| 4338 | enum nl80211_acl_policy acl_policy; |
| 4339 | struct nlattr *attr; |
| 4340 | struct cfg80211_acl_data *acl; |
| 4341 | int i = 0, n_entries, tmp; |
| 4342 | |
| 4343 | if (!wiphy->max_acl_mac_addrs) |
| 4344 | return ERR_PTR(-EOPNOTSUPP); |
| 4345 | |
| 4346 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4347 | return ERR_PTR(-EINVAL); |
| 4348 | |
| 4349 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4350 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4351 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4352 | return ERR_PTR(-EINVAL); |
| 4353 | |
| 4354 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4355 | return ERR_PTR(-EINVAL); |
| 4356 | |
| 4357 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4358 | if (n_entries < 0) |
| 4359 | return ERR_PTR(n_entries); |
| 4360 | |
| 4361 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4362 | return ERR_PTR(-ENOTSUPP); |
| 4363 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4364 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4365 | if (!acl) |
| 4366 | return ERR_PTR(-ENOMEM); |
| 4367 | |
| 4368 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4369 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4370 | i++; |
| 4371 | } |
| 4372 | |
| 4373 | acl->n_acl_entries = n_entries; |
| 4374 | acl->acl_policy = acl_policy; |
| 4375 | |
| 4376 | return acl; |
| 4377 | } |
| 4378 | |
| 4379 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4380 | { |
| 4381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4382 | struct net_device *dev = info->user_ptr[1]; |
| 4383 | struct cfg80211_acl_data *acl; |
| 4384 | int err; |
| 4385 | |
| 4386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4387 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4388 | return -EOPNOTSUPP; |
| 4389 | |
| 4390 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4391 | return -EINVAL; |
| 4392 | |
| 4393 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4394 | if (IS_ERR(acl)) |
| 4395 | return PTR_ERR(acl); |
| 4396 | |
| 4397 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4398 | |
| 4399 | kfree(acl); |
| 4400 | |
| 4401 | return err; |
| 4402 | } |
| 4403 | |
| 4404 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4405 | u8 *rates, u8 rates_len) |
| 4406 | { |
| 4407 | u8 i; |
| 4408 | u32 mask = 0; |
| 4409 | |
| 4410 | for (i = 0; i < rates_len; i++) { |
| 4411 | int rate = (rates[i] & 0x7f) * 5; |
| 4412 | int ridx; |
| 4413 | |
| 4414 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4415 | struct ieee80211_rate *srate = |
| 4416 | &sband->bitrates[ridx]; |
| 4417 | if (rate == srate->bitrate) { |
| 4418 | mask |= 1 << ridx; |
| 4419 | break; |
| 4420 | } |
| 4421 | } |
| 4422 | if (ridx == sband->n_bitrates) |
| 4423 | return 0; /* rate not found */ |
| 4424 | } |
| 4425 | |
| 4426 | return mask; |
| 4427 | } |
| 4428 | |
| 4429 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4430 | u8 *rates, u8 rates_len, |
| 4431 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4432 | { |
| 4433 | u8 i; |
| 4434 | |
| 4435 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4436 | |
| 4437 | for (i = 0; i < rates_len; i++) { |
| 4438 | int ridx, rbit; |
| 4439 | |
| 4440 | ridx = rates[i] / 8; |
| 4441 | rbit = BIT(rates[i] % 8); |
| 4442 | |
| 4443 | /* check validity */ |
| 4444 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4445 | return false; |
| 4446 | |
| 4447 | /* check availability */ |
| 4448 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
| 4449 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4450 | mcs[ridx] |= rbit; |
| 4451 | else |
| 4452 | return false; |
| 4453 | } |
| 4454 | |
| 4455 | return true; |
| 4456 | } |
| 4457 | |
| 4458 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4459 | { |
| 4460 | u16 mcs_mask = 0; |
| 4461 | |
| 4462 | switch (vht_mcs_map) { |
| 4463 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4464 | break; |
| 4465 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4466 | mcs_mask = 0x00FF; |
| 4467 | break; |
| 4468 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4469 | mcs_mask = 0x01FF; |
| 4470 | break; |
| 4471 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4472 | mcs_mask = 0x03FF; |
| 4473 | break; |
| 4474 | default: |
| 4475 | break; |
| 4476 | } |
| 4477 | |
| 4478 | return mcs_mask; |
| 4479 | } |
| 4480 | |
| 4481 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4482 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4483 | { |
| 4484 | u8 nss; |
| 4485 | |
| 4486 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4487 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4488 | vht_mcs_map >>= 2; |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4493 | struct nl80211_txrate_vht *txrate, |
| 4494 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4495 | { |
| 4496 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4497 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4498 | u8 i; |
| 4499 | |
| 4500 | if (!sband->vht_cap.vht_supported) |
| 4501 | return false; |
| 4502 | |
| 4503 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4504 | |
| 4505 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4506 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4507 | |
| 4508 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4509 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4510 | mcs[i] = txrate->mcs[i]; |
| 4511 | else |
| 4512 | return false; |
| 4513 | } |
| 4514 | |
| 4515 | return true; |
| 4516 | } |
| 4517 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4518 | static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) |
| 4519 | { |
| 4520 | switch (he_mcs_map) { |
| 4521 | case IEEE80211_HE_MCS_NOT_SUPPORTED: |
| 4522 | return 0; |
| 4523 | case IEEE80211_HE_MCS_SUPPORT_0_7: |
| 4524 | return 0x00FF; |
| 4525 | case IEEE80211_HE_MCS_SUPPORT_0_9: |
| 4526 | return 0x03FF; |
| 4527 | case IEEE80211_HE_MCS_SUPPORT_0_11: |
| 4528 | return 0xFFF; |
| 4529 | default: |
| 4530 | break; |
| 4531 | } |
| 4532 | return 0; |
| 4533 | } |
| 4534 | |
| 4535 | static void he_build_mcs_mask(u16 he_mcs_map, |
| 4536 | u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 4537 | { |
| 4538 | u8 nss; |
| 4539 | |
| 4540 | for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { |
| 4541 | he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); |
| 4542 | he_mcs_map >>= 2; |
| 4543 | } |
| 4544 | } |
| 4545 | |
| 4546 | static u16 he_get_txmcsmap(struct genl_info *info, |
| 4547 | const struct ieee80211_sta_he_cap *he_cap) |
| 4548 | { |
| 4549 | struct net_device *dev = info->user_ptr[1]; |
| 4550 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4551 | __le16 tx_mcs; |
| 4552 | |
| 4553 | switch (wdev->chandef.width) { |
| 4554 | case NL80211_CHAN_WIDTH_80P80: |
| 4555 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 4556 | break; |
| 4557 | case NL80211_CHAN_WIDTH_160: |
| 4558 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; |
| 4559 | break; |
| 4560 | default: |
| 4561 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; |
| 4562 | break; |
| 4563 | } |
| 4564 | return le16_to_cpu(tx_mcs); |
| 4565 | } |
| 4566 | |
| 4567 | static bool he_set_mcs_mask(struct genl_info *info, |
| 4568 | struct wireless_dev *wdev, |
| 4569 | struct ieee80211_supported_band *sband, |
| 4570 | struct nl80211_txrate_he *txrate, |
| 4571 | u16 mcs[NL80211_HE_NSS_MAX]) |
| 4572 | { |
| 4573 | const struct ieee80211_sta_he_cap *he_cap; |
| 4574 | u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; |
| 4575 | u16 tx_mcs_map = 0; |
| 4576 | u8 i; |
| 4577 | |
| 4578 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4579 | if (!he_cap) |
| 4580 | return false; |
| 4581 | |
| 4582 | memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); |
| 4583 | |
| 4584 | tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4585 | |
| 4586 | /* Build he_mcs_mask from HE capabilities */ |
| 4587 | he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4588 | |
| 4589 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 4590 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4591 | mcs[i] = txrate->mcs[i]; |
| 4592 | else |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
| 4596 | return true; |
| 4597 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4598 | |
| 4599 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4600 | struct nlattr *attrs[], |
| 4601 | enum nl80211_attrs attr, |
| 4602 | struct cfg80211_bitrate_mask *mask, |
| 4603 | struct net_device *dev) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4604 | { |
| 4605 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4608 | int rem, i; |
| 4609 | struct nlattr *tx_rates; |
| 4610 | struct ieee80211_supported_band *sband; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4611 | u16 vht_tx_mcs_map, he_tx_mcs_map; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4612 | |
| 4613 | memset(mask, 0, sizeof(*mask)); |
| 4614 | /* Default to all rates enabled */ |
| 4615 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4616 | const struct ieee80211_sta_he_cap *he_cap; |
| 4617 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4618 | sband = rdev->wiphy.bands[i]; |
| 4619 | |
| 4620 | if (!sband) |
| 4621 | continue; |
| 4622 | |
| 4623 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4624 | memcpy(mask->control[i].ht_mcs, |
| 4625 | sband->ht_cap.mcs.rx_mask, |
| 4626 | sizeof(mask->control[i].ht_mcs)); |
| 4627 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4628 | if (sband->vht_cap.vht_supported) { |
| 4629 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4630 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 4631 | } |
| 4632 | |
| 4633 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4634 | if (!he_cap) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4635 | continue; |
| 4636 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4637 | he_tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4638 | he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); |
| 4639 | |
| 4640 | mask->control[i].he_gi = 0xFF; |
| 4641 | mask->control[i].he_ltf = 0xFF; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | /* if no rates are given set it back to the defaults */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4645 | if (!attrs[attr]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4646 | goto out; |
| 4647 | |
| 4648 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4649 | * directly to the enum nl80211_band values used in cfg80211. |
| 4650 | */ |
| 4651 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4652 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4653 | enum nl80211_band band = nla_type(tx_rates); |
| 4654 | int err; |
| 4655 | |
| 4656 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4657 | return -EINVAL; |
| 4658 | sband = rdev->wiphy.bands[band]; |
| 4659 | if (sband == NULL) |
| 4660 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4661 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4662 | tx_rates, |
| 4663 | nl80211_txattr_policy, |
| 4664 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4665 | if (err) |
| 4666 | return err; |
| 4667 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4668 | mask->control[band].legacy = rateset_to_mask( |
| 4669 | sband, |
| 4670 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4671 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4672 | if ((mask->control[band].legacy == 0) && |
| 4673 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4674 | return -EINVAL; |
| 4675 | } |
| 4676 | if (tb[NL80211_TXRATE_HT]) { |
| 4677 | if (!ht_rateset_to_mask( |
| 4678 | sband, |
| 4679 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4680 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4681 | mask->control[band].ht_mcs)) |
| 4682 | return -EINVAL; |
| 4683 | } |
| 4684 | if (tb[NL80211_TXRATE_VHT]) { |
| 4685 | if (!vht_set_mcs_mask( |
| 4686 | sband, |
| 4687 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4688 | mask->control[band].vht_mcs)) |
| 4689 | return -EINVAL; |
| 4690 | } |
| 4691 | if (tb[NL80211_TXRATE_GI]) { |
| 4692 | mask->control[band].gi = |
| 4693 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4694 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4695 | return -EINVAL; |
| 4696 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4697 | if (tb[NL80211_TXRATE_HE] && |
| 4698 | !he_set_mcs_mask(info, wdev, sband, |
| 4699 | nla_data(tb[NL80211_TXRATE_HE]), |
| 4700 | mask->control[band].he_mcs)) |
| 4701 | return -EINVAL; |
| 4702 | if (tb[NL80211_TXRATE_HE_GI]) |
| 4703 | mask->control[band].he_gi = |
| 4704 | nla_get_u8(tb[NL80211_TXRATE_HE_GI]); |
| 4705 | if (tb[NL80211_TXRATE_HE_LTF]) |
| 4706 | mask->control[band].he_ltf = |
| 4707 | nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4708 | |
| 4709 | if (mask->control[band].legacy == 0) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4710 | /* don't allow empty legacy rates if HT, VHT or HE |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4711 | * are not even supported. |
| 4712 | */ |
| 4713 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4714 | rdev->wiphy.bands[band]->vht_cap.vht_supported || |
| 4715 | ieee80211_get_he_iftype_cap(sband, wdev->iftype))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4716 | return -EINVAL; |
| 4717 | |
| 4718 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4719 | if (mask->control[band].ht_mcs[i]) |
| 4720 | goto out; |
| 4721 | |
| 4722 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4723 | if (mask->control[band].vht_mcs[i]) |
| 4724 | goto out; |
| 4725 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4726 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) |
| 4727 | if (mask->control[band].he_mcs[i]) |
| 4728 | goto out; |
| 4729 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4730 | /* legacy and mcs rates may not be both empty */ |
| 4731 | return -EINVAL; |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | out: |
| 4736 | return 0; |
| 4737 | } |
| 4738 | |
| 4739 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4740 | enum nl80211_band band, |
| 4741 | struct cfg80211_bitrate_mask *beacon_rate) |
| 4742 | { |
| 4743 | u32 count_ht, count_vht, i; |
| 4744 | u32 rate = beacon_rate->control[band].legacy; |
| 4745 | |
| 4746 | /* Allow only one rate */ |
| 4747 | if (hweight32(rate) > 1) |
| 4748 | return -EINVAL; |
| 4749 | |
| 4750 | count_ht = 0; |
| 4751 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
| 4752 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
| 4753 | return -EINVAL; |
| 4754 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
| 4755 | count_ht++; |
| 4756 | if (count_ht > 1) |
| 4757 | return -EINVAL; |
| 4758 | } |
| 4759 | if (count_ht && rate) |
| 4760 | return -EINVAL; |
| 4761 | } |
| 4762 | |
| 4763 | count_vht = 0; |
| 4764 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4765 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
| 4766 | return -EINVAL; |
| 4767 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
| 4768 | count_vht++; |
| 4769 | if (count_vht > 1) |
| 4770 | return -EINVAL; |
| 4771 | } |
| 4772 | if (count_vht && rate) |
| 4773 | return -EINVAL; |
| 4774 | } |
| 4775 | |
| 4776 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4777 | return -EINVAL; |
| 4778 | |
| 4779 | if (rate && |
| 4780 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4781 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4782 | return -EINVAL; |
| 4783 | if (count_ht && |
| 4784 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4785 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4786 | return -EINVAL; |
| 4787 | if (count_vht && |
| 4788 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4789 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4790 | return -EINVAL; |
| 4791 | |
| 4792 | return 0; |
| 4793 | } |
| 4794 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4795 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4796 | struct nlattr *attrs[], |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4797 | struct cfg80211_beacon_data *bcn) |
| 4798 | { |
| 4799 | bool haveinfo = false; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4800 | int err; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4801 | |
| 4802 | memset(bcn, 0, sizeof(*bcn)); |
| 4803 | |
| 4804 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4805 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4806 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4807 | if (!bcn->head_len) |
| 4808 | return -EINVAL; |
| 4809 | haveinfo = true; |
| 4810 | } |
| 4811 | |
| 4812 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4813 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4814 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4815 | haveinfo = true; |
| 4816 | } |
| 4817 | |
| 4818 | if (!haveinfo) |
| 4819 | return -EINVAL; |
| 4820 | |
| 4821 | if (attrs[NL80211_ATTR_IE]) { |
| 4822 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4823 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
| 4824 | } |
| 4825 | |
| 4826 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 4827 | bcn->proberesp_ies = |
| 4828 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 4829 | bcn->proberesp_ies_len = |
| 4830 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 4831 | } |
| 4832 | |
| 4833 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 4834 | bcn->assocresp_ies = |
| 4835 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 4836 | bcn->assocresp_ies_len = |
| 4837 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 4838 | } |
| 4839 | |
| 4840 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4841 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4842 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4843 | } |
| 4844 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4845 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4846 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4847 | |
| 4848 | err = nla_parse_nested_deprecated(tb, |
| 4849 | NL80211_FTM_RESP_ATTR_MAX, |
| 4850 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4851 | NULL, NULL); |
| 4852 | if (err) |
| 4853 | return err; |
| 4854 | |
| 4855 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4856 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4857 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4858 | bcn->ftm_responder = 1; |
| 4859 | else |
| 4860 | return -EOPNOTSUPP; |
| 4861 | |
| 4862 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4863 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4864 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4865 | } |
| 4866 | |
| 4867 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4868 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4869 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4870 | } |
| 4871 | } else { |
| 4872 | bcn->ftm_responder = -1; |
| 4873 | } |
| 4874 | |
| 4875 | return 0; |
| 4876 | } |
| 4877 | |
| 4878 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 4879 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 4880 | { |
| 4881 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 4882 | int err; |
| 4883 | |
| 4884 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 4885 | he_obss_pd_policy, NULL); |
| 4886 | if (err) |
| 4887 | return err; |
| 4888 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4889 | if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) |
| 4890 | return -EINVAL; |
| 4891 | |
| 4892 | he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); |
| 4893 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 4894 | if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) |
| 4895 | he_obss_pd->min_offset = |
| 4896 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 4897 | if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 4898 | he_obss_pd->max_offset = |
| 4899 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4900 | if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) |
| 4901 | he_obss_pd->non_srg_max_offset = |
| 4902 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4903 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 4904 | if (he_obss_pd->min_offset > he_obss_pd->max_offset) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4905 | return -EINVAL; |
| 4906 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4907 | if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) |
| 4908 | memcpy(he_obss_pd->bss_color_bitmap, |
| 4909 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), |
| 4910 | sizeof(he_obss_pd->bss_color_bitmap)); |
| 4911 | |
| 4912 | if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) |
| 4913 | memcpy(he_obss_pd->partial_bssid_bitmap, |
| 4914 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), |
| 4915 | sizeof(he_obss_pd->partial_bssid_bitmap)); |
| 4916 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 4917 | he_obss_pd->enable = true; |
| 4918 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4919 | return 0; |
| 4920 | } |
| 4921 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 4922 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 4923 | struct cfg80211_he_bss_color *he_bss_color) |
| 4924 | { |
| 4925 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 4926 | int err; |
| 4927 | |
| 4928 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 4929 | he_bss_color_policy, NULL); |
| 4930 | if (err) |
| 4931 | return err; |
| 4932 | |
| 4933 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 4934 | return -EINVAL; |
| 4935 | |
| 4936 | he_bss_color->color = |
| 4937 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
| 4938 | he_bss_color->enabled = |
| 4939 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
| 4940 | he_bss_color->partial = |
| 4941 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 4942 | |
| 4943 | return 0; |
| 4944 | } |
| 4945 | |
| 4946 | static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, |
| 4947 | struct nlattr *attrs, |
| 4948 | struct cfg80211_ap_settings *params) |
| 4949 | { |
| 4950 | struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; |
| 4951 | int ret; |
| 4952 | struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; |
| 4953 | |
| 4954 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4955 | NL80211_EXT_FEATURE_FILS_DISCOVERY)) |
| 4956 | return -EINVAL; |
| 4957 | |
| 4958 | ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, |
| 4959 | NULL, NULL); |
| 4960 | if (ret) |
| 4961 | return ret; |
| 4962 | |
| 4963 | if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || |
| 4964 | !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || |
| 4965 | !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) |
| 4966 | return -EINVAL; |
| 4967 | |
| 4968 | fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4969 | fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4970 | fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); |
| 4971 | fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); |
| 4972 | |
| 4973 | return 0; |
| 4974 | } |
| 4975 | |
| 4976 | static int |
| 4977 | nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, |
| 4978 | struct nlattr *attrs, |
| 4979 | struct cfg80211_ap_settings *params) |
| 4980 | { |
| 4981 | struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; |
| 4982 | int ret; |
| 4983 | struct cfg80211_unsol_bcast_probe_resp *presp = |
| 4984 | ¶ms->unsol_bcast_probe_resp; |
| 4985 | |
| 4986 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4987 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) |
| 4988 | return -EINVAL; |
| 4989 | |
| 4990 | ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, |
| 4991 | attrs, NULL, NULL); |
| 4992 | if (ret) |
| 4993 | return ret; |
| 4994 | |
| 4995 | if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || |
| 4996 | !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) |
| 4997 | return -EINVAL; |
| 4998 | |
| 4999 | presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 5000 | presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 5001 | presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); |
| 5002 | return 0; |
| 5003 | } |
| 5004 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5005 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 5006 | const u8 *rates) |
| 5007 | { |
| 5008 | int i; |
| 5009 | |
| 5010 | if (!rates) |
| 5011 | return; |
| 5012 | |
| 5013 | for (i = 0; i < rates[1]; i++) { |
| 5014 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 5015 | params->ht_required = true; |
| 5016 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 5017 | params->vht_required = true; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5018 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
| 5019 | params->he_required = true; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | |
| 5023 | /* |
| 5024 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 5025 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 5026 | * benefit of drivers that rebuild IEs in the firmware. |
| 5027 | */ |
| 5028 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 5029 | { |
| 5030 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
| 5031 | size_t ies_len = bcn->tail_len; |
| 5032 | const u8 *ies = bcn->tail; |
| 5033 | const u8 *rates; |
| 5034 | const u8 *cap; |
| 5035 | |
| 5036 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 5037 | nl80211_check_ap_rate_selectors(params, rates); |
| 5038 | |
| 5039 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 5040 | nl80211_check_ap_rate_selectors(params, rates); |
| 5041 | |
| 5042 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 5043 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 5044 | params->ht_cap = (void *)(cap + 2); |
| 5045 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 5046 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 5047 | params->vht_cap = (void *)(cap + 2); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5048 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 5049 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 5050 | params->he_cap = (void *)(cap + 3); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5051 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); |
| 5052 | if (cap && cap[1] >= sizeof(*params->he_oper) + 1) |
| 5053 | params->he_oper = (void *)(cap + 3); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 5057 | struct cfg80211_ap_settings *params) |
| 5058 | { |
| 5059 | struct wireless_dev *wdev; |
| 5060 | bool ret = false; |
| 5061 | |
| 5062 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 5063 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5064 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5065 | continue; |
| 5066 | |
| 5067 | if (!wdev->preset_chandef.chan) |
| 5068 | continue; |
| 5069 | |
| 5070 | params->chandef = wdev->preset_chandef; |
| 5071 | ret = true; |
| 5072 | break; |
| 5073 | } |
| 5074 | |
| 5075 | return ret; |
| 5076 | } |
| 5077 | |
| 5078 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 5079 | enum nl80211_auth_type auth_type, |
| 5080 | enum nl80211_commands cmd) |
| 5081 | { |
| 5082 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 5083 | return false; |
| 5084 | |
| 5085 | switch (cmd) { |
| 5086 | case NL80211_CMD_AUTHENTICATE: |
| 5087 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 5088 | auth_type == NL80211_AUTHTYPE_SAE) |
| 5089 | return false; |
| 5090 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5091 | NL80211_EXT_FEATURE_FILS_STA) && |
| 5092 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5093 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5094 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 5095 | return false; |
| 5096 | return true; |
| 5097 | case NL80211_CMD_CONNECT: |
| 5098 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5099 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5100 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5101 | auth_type == NL80211_AUTHTYPE_SAE) |
| 5102 | return false; |
| 5103 | |
| 5104 | /* FILS with SK PFS or PK not supported yet */ |
| 5105 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5106 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5107 | return false; |
| 5108 | if (!wiphy_ext_feature_isset( |
| 5109 | &rdev->wiphy, |
| 5110 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 5111 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 5112 | return false; |
| 5113 | return true; |
| 5114 | case NL80211_CMD_START_AP: |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5115 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5116 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && |
| 5117 | auth_type == NL80211_AUTHTYPE_SAE) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5118 | return false; |
| 5119 | /* FILS not supported yet */ |
| 5120 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5121 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5122 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5123 | return false; |
| 5124 | return true; |
| 5125 | default: |
| 5126 | return false; |
| 5127 | } |
| 5128 | } |
| 5129 | |
| 5130 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 5131 | { |
| 5132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5133 | struct net_device *dev = info->user_ptr[1]; |
| 5134 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5135 | struct cfg80211_ap_settings params; |
| 5136 | int err; |
| 5137 | |
| 5138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5139 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5140 | return -EOPNOTSUPP; |
| 5141 | |
| 5142 | if (!rdev->ops->start_ap) |
| 5143 | return -EOPNOTSUPP; |
| 5144 | |
| 5145 | if (wdev->beacon_interval) |
| 5146 | return -EALREADY; |
| 5147 | |
| 5148 | memset(¶ms, 0, sizeof(params)); |
| 5149 | |
| 5150 | /* these are required for START_AP */ |
| 5151 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 5152 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 5153 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 5154 | return -EINVAL; |
| 5155 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5156 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5157 | if (err) |
| 5158 | return err; |
| 5159 | |
| 5160 | params.beacon_interval = |
| 5161 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5162 | params.dtim_period = |
| 5163 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 5164 | |
| 5165 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 5166 | params.beacon_interval); |
| 5167 | if (err) |
| 5168 | return err; |
| 5169 | |
| 5170 | /* |
| 5171 | * In theory, some of these attributes should be required here |
| 5172 | * but since they were not used when the command was originally |
| 5173 | * added, keep them optional for old user space programs to let |
| 5174 | * them continue to work with drivers that do not need the |
| 5175 | * additional information -- drivers must check! |
| 5176 | */ |
| 5177 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 5178 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5179 | params.ssid_len = |
| 5180 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5181 | if (params.ssid_len == 0) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5182 | return -EINVAL; |
| 5183 | } |
| 5184 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5185 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5186 | params.hidden_ssid = nla_get_u32( |
| 5187 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5188 | |
| 5189 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 5190 | |
| 5191 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5192 | params.auth_type = nla_get_u32( |
| 5193 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5194 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 5195 | NL80211_CMD_START_AP)) |
| 5196 | return -EINVAL; |
| 5197 | } else |
| 5198 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5199 | |
| 5200 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 5201 | NL80211_MAX_NR_CIPHER_SUITES); |
| 5202 | if (err) |
| 5203 | return err; |
| 5204 | |
| 5205 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 5206 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 5207 | return -EOPNOTSUPP; |
| 5208 | params.inactivity_timeout = nla_get_u16( |
| 5209 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 5210 | } |
| 5211 | |
| 5212 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5213 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5214 | return -EINVAL; |
| 5215 | params.p2p_ctwindow = |
| 5216 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5217 | if (params.p2p_ctwindow != 0 && |
| 5218 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5219 | return -EINVAL; |
| 5220 | } |
| 5221 | |
| 5222 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5223 | u8 tmp; |
| 5224 | |
| 5225 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5226 | return -EINVAL; |
| 5227 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5228 | params.p2p_opp_ps = tmp; |
| 5229 | if (params.p2p_opp_ps != 0 && |
| 5230 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5231 | return -EINVAL; |
| 5232 | } |
| 5233 | |
| 5234 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5235 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5236 | if (err) |
| 5237 | return err; |
| 5238 | } else if (wdev->preset_chandef.chan) { |
| 5239 | params.chandef = wdev->preset_chandef; |
| 5240 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
| 5241 | return -EINVAL; |
| 5242 | |
| 5243 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 5244 | wdev->iftype)) |
| 5245 | return -EINVAL; |
| 5246 | |
| 5247 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5248 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 5249 | NL80211_ATTR_TX_RATES, |
| 5250 | ¶ms.beacon_rate, |
| 5251 | dev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5252 | if (err) |
| 5253 | return err; |
| 5254 | |
| 5255 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 5256 | ¶ms.beacon_rate); |
| 5257 | if (err) |
| 5258 | return err; |
| 5259 | } |
| 5260 | |
| 5261 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 5262 | params.smps_mode = |
| 5263 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 5264 | switch (params.smps_mode) { |
| 5265 | case NL80211_SMPS_OFF: |
| 5266 | break; |
| 5267 | case NL80211_SMPS_STATIC: |
| 5268 | if (!(rdev->wiphy.features & |
| 5269 | NL80211_FEATURE_STATIC_SMPS)) |
| 5270 | return -EINVAL; |
| 5271 | break; |
| 5272 | case NL80211_SMPS_DYNAMIC: |
| 5273 | if (!(rdev->wiphy.features & |
| 5274 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 5275 | return -EINVAL; |
| 5276 | break; |
| 5277 | default: |
| 5278 | return -EINVAL; |
| 5279 | } |
| 5280 | } else { |
| 5281 | params.smps_mode = NL80211_SMPS_OFF; |
| 5282 | } |
| 5283 | |
| 5284 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 5285 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 5286 | return -EOPNOTSUPP; |
| 5287 | |
| 5288 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 5289 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 5290 | if (IS_ERR(params.acl)) |
| 5291 | return PTR_ERR(params.acl); |
| 5292 | } |
| 5293 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5294 | params.twt_responder = |
| 5295 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 5296 | |
| 5297 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 5298 | err = nl80211_parse_he_obss_pd( |
| 5299 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
| 5300 | ¶ms.he_obss_pd); |
| 5301 | if (err) |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 5302 | goto out; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5303 | } |
| 5304 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5305 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 5306 | err = nl80211_parse_he_bss_color( |
| 5307 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
| 5308 | ¶ms.he_bss_color); |
| 5309 | if (err) |
| 5310 | goto out; |
| 5311 | } |
| 5312 | |
| 5313 | if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { |
| 5314 | err = nl80211_parse_fils_discovery(rdev, |
| 5315 | info->attrs[NL80211_ATTR_FILS_DISCOVERY], |
| 5316 | ¶ms); |
| 5317 | if (err) |
| 5318 | goto out; |
| 5319 | } |
| 5320 | |
| 5321 | if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { |
| 5322 | err = nl80211_parse_unsol_bcast_probe_resp( |
| 5323 | rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], |
| 5324 | ¶ms); |
| 5325 | if (err) |
| 5326 | goto out; |
| 5327 | } |
| 5328 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5329 | nl80211_calculate_ap_params(¶ms); |
| 5330 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5331 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 5332 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 5333 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5334 | wdev_lock(wdev); |
| 5335 | err = rdev_start_ap(rdev, dev, ¶ms); |
| 5336 | if (!err) { |
| 5337 | wdev->preset_chandef = params.chandef; |
| 5338 | wdev->beacon_interval = params.beacon_interval; |
| 5339 | wdev->chandef = params.chandef; |
| 5340 | wdev->ssid_len = params.ssid_len; |
| 5341 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
| 5342 | |
| 5343 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5344 | wdev->conn_owner_nlportid = info->snd_portid; |
| 5345 | } |
| 5346 | wdev_unlock(wdev); |
| 5347 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 5348 | out: |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5349 | kfree(params.acl); |
| 5350 | |
| 5351 | return err; |
| 5352 | } |
| 5353 | |
| 5354 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5355 | { |
| 5356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5357 | struct net_device *dev = info->user_ptr[1]; |
| 5358 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5359 | struct cfg80211_beacon_data params; |
| 5360 | int err; |
| 5361 | |
| 5362 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5363 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5364 | return -EOPNOTSUPP; |
| 5365 | |
| 5366 | if (!rdev->ops->change_beacon) |
| 5367 | return -EOPNOTSUPP; |
| 5368 | |
| 5369 | if (!wdev->beacon_interval) |
| 5370 | return -EINVAL; |
| 5371 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5372 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5373 | if (err) |
| 5374 | return err; |
| 5375 | |
| 5376 | wdev_lock(wdev); |
| 5377 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5378 | wdev_unlock(wdev); |
| 5379 | |
| 5380 | return err; |
| 5381 | } |
| 5382 | |
| 5383 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
| 5384 | { |
| 5385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5386 | struct net_device *dev = info->user_ptr[1]; |
| 5387 | |
| 5388 | return cfg80211_stop_ap(rdev, dev, false); |
| 5389 | } |
| 5390 | |
| 5391 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5392 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5393 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5394 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
| 5395 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
| 5396 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
| 5397 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
| 5398 | }; |
| 5399 | |
| 5400 | static int parse_station_flags(struct genl_info *info, |
| 5401 | enum nl80211_iftype iftype, |
| 5402 | struct station_parameters *params) |
| 5403 | { |
| 5404 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
| 5405 | struct nlattr *nla; |
| 5406 | int flag; |
| 5407 | |
| 5408 | /* |
| 5409 | * Try parsing the new attribute first so userspace |
| 5410 | * can specify both for older kernels. |
| 5411 | */ |
| 5412 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5413 | if (nla) { |
| 5414 | struct nl80211_sta_flag_update *sta_flags; |
| 5415 | |
| 5416 | sta_flags = nla_data(nla); |
| 5417 | params->sta_flags_mask = sta_flags->mask; |
| 5418 | params->sta_flags_set = sta_flags->set; |
| 5419 | params->sta_flags_set &= params->sta_flags_mask; |
| 5420 | if ((params->sta_flags_mask | |
| 5421 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5422 | return -EINVAL; |
| 5423 | return 0; |
| 5424 | } |
| 5425 | |
| 5426 | /* if present, parse the old attribute */ |
| 5427 | |
| 5428 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
| 5429 | if (!nla) |
| 5430 | return 0; |
| 5431 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5432 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5433 | return -EINVAL; |
| 5434 | |
| 5435 | /* |
| 5436 | * Only allow certain flags for interface types so that |
| 5437 | * other attributes are silently ignored. Remember that |
| 5438 | * this is backward compatibility code with old userspace |
| 5439 | * and shouldn't be hit in other cases anyway. |
| 5440 | */ |
| 5441 | switch (iftype) { |
| 5442 | case NL80211_IFTYPE_AP: |
| 5443 | case NL80211_IFTYPE_AP_VLAN: |
| 5444 | case NL80211_IFTYPE_P2P_GO: |
| 5445 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5446 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5447 | BIT(NL80211_STA_FLAG_WME) | |
| 5448 | BIT(NL80211_STA_FLAG_MFP); |
| 5449 | break; |
| 5450 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5451 | case NL80211_IFTYPE_STATION: |
| 5452 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5453 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5454 | break; |
| 5455 | case NL80211_IFTYPE_MESH_POINT: |
| 5456 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5457 | BIT(NL80211_STA_FLAG_MFP) | |
| 5458 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5459 | break; |
| 5460 | default: |
| 5461 | return -EINVAL; |
| 5462 | } |
| 5463 | |
| 5464 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5465 | if (flags[flag]) { |
| 5466 | params->sta_flags_set |= (1<<flag); |
| 5467 | |
| 5468 | /* no longer support new API additions in old API */ |
| 5469 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5470 | return -EINVAL; |
| 5471 | } |
| 5472 | } |
| 5473 | |
| 5474 | return 0; |
| 5475 | } |
| 5476 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5477 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5478 | { |
| 5479 | struct nlattr *rate; |
| 5480 | u32 bitrate; |
| 5481 | u16 bitrate_compat; |
| 5482 | enum nl80211_rate_info rate_flg; |
| 5483 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5484 | rate = nla_nest_start_noflag(msg, attr); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5485 | if (!rate) |
| 5486 | return false; |
| 5487 | |
| 5488 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5489 | bitrate = cfg80211_calculate_bitrate(info); |
| 5490 | /* report 16-bit bitrate only if we can */ |
| 5491 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
| 5492 | if (bitrate > 0 && |
| 5493 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5494 | return false; |
| 5495 | if (bitrate_compat > 0 && |
| 5496 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5497 | return false; |
| 5498 | |
| 5499 | switch (info->bw) { |
| 5500 | case RATE_INFO_BW_5: |
| 5501 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5502 | break; |
| 5503 | case RATE_INFO_BW_10: |
| 5504 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5505 | break; |
| 5506 | default: |
| 5507 | WARN_ON(1); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5508 | fallthrough; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5509 | case RATE_INFO_BW_20: |
| 5510 | rate_flg = 0; |
| 5511 | break; |
| 5512 | case RATE_INFO_BW_40: |
| 5513 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5514 | break; |
| 5515 | case RATE_INFO_BW_80: |
| 5516 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5517 | break; |
| 5518 | case RATE_INFO_BW_160: |
| 5519 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5520 | break; |
| 5521 | case RATE_INFO_BW_HE_RU: |
| 5522 | rate_flg = 0; |
| 5523 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
| 5524 | } |
| 5525 | |
| 5526 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5527 | return false; |
| 5528 | |
| 5529 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5530 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5531 | return false; |
| 5532 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5533 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5534 | return false; |
| 5535 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5536 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5537 | return false; |
| 5538 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5539 | return false; |
| 5540 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5541 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5542 | return false; |
| 5543 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5544 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5545 | return false; |
| 5546 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5547 | return false; |
| 5548 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5549 | return false; |
| 5550 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5551 | return false; |
| 5552 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5553 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5554 | info->he_ru_alloc)) |
| 5555 | return false; |
| 5556 | } |
| 5557 | |
| 5558 | nla_nest_end(msg, rate); |
| 5559 | return true; |
| 5560 | } |
| 5561 | |
| 5562 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5563 | int id) |
| 5564 | { |
| 5565 | void *attr; |
| 5566 | int i = 0; |
| 5567 | |
| 5568 | if (!mask) |
| 5569 | return true; |
| 5570 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5571 | attr = nla_nest_start_noflag(msg, id); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5572 | if (!attr) |
| 5573 | return false; |
| 5574 | |
| 5575 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5576 | if (!(mask & BIT(i))) |
| 5577 | continue; |
| 5578 | |
| 5579 | if (nla_put_u8(msg, i, signal[i])) |
| 5580 | return false; |
| 5581 | } |
| 5582 | |
| 5583 | nla_nest_end(msg, attr); |
| 5584 | |
| 5585 | return true; |
| 5586 | } |
| 5587 | |
| 5588 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5589 | u32 seq, int flags, |
| 5590 | struct cfg80211_registered_device *rdev, |
| 5591 | struct net_device *dev, |
| 5592 | const u8 *mac_addr, struct station_info *sinfo) |
| 5593 | { |
| 5594 | void *hdr; |
| 5595 | struct nlattr *sinfoattr, *bss_param; |
| 5596 | |
| 5597 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5598 | if (!hdr) { |
| 5599 | cfg80211_sinfo_release_content(sinfo); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5600 | return -1; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5601 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5602 | |
| 5603 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5604 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5605 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5606 | goto nla_put_failure; |
| 5607 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5608 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5609 | if (!sinfoattr) |
| 5610 | goto nla_put_failure; |
| 5611 | |
| 5612 | #define PUT_SINFO(attr, memb, type) do { \ |
| 5613 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
| 5614 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
| 5615 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 5616 | sinfo->memb)) \ |
| 5617 | goto nla_put_failure; \ |
| 5618 | } while (0) |
| 5619 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 5620 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
| 5621 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 5622 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 5623 | goto nla_put_failure; \ |
| 5624 | } while (0) |
| 5625 | |
| 5626 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 5627 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5628 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5629 | |
| 5630 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 5631 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
| 5632 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 5633 | (u32)sinfo->rx_bytes)) |
| 5634 | goto nla_put_failure; |
| 5635 | |
| 5636 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 5637 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
| 5638 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 5639 | (u32)sinfo->tx_bytes)) |
| 5640 | goto nla_put_failure; |
| 5641 | |
| 5642 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 5643 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
| 5644 | PUT_SINFO(LLID, llid, u16); |
| 5645 | PUT_SINFO(PLID, plid, u16); |
| 5646 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
| 5647 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5648 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 5649 | |
| 5650 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 5651 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5652 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5653 | |
| 5654 | switch (rdev->wiphy.signal_type) { |
| 5655 | case CFG80211_SIGNAL_TYPE_MBM: |
| 5656 | PUT_SINFO(SIGNAL, signal, u8); |
| 5657 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
| 5658 | break; |
| 5659 | default: |
| 5660 | break; |
| 5661 | } |
| 5662 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
| 5663 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5664 | sinfo->chain_signal, |
| 5665 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 5666 | goto nla_put_failure; |
| 5667 | } |
| 5668 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
| 5669 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5670 | sinfo->chain_signal_avg, |
| 5671 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 5672 | goto nla_put_failure; |
| 5673 | } |
| 5674 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
| 5675 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 5676 | NL80211_STA_INFO_TX_BITRATE)) |
| 5677 | goto nla_put_failure; |
| 5678 | } |
| 5679 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
| 5680 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 5681 | NL80211_STA_INFO_RX_BITRATE)) |
| 5682 | goto nla_put_failure; |
| 5683 | } |
| 5684 | |
| 5685 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 5686 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 5687 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 5688 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 5689 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5690 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5691 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 5692 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 5693 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 5694 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5695 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 5696 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5697 | |
| 5698 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5699 | bss_param = nla_nest_start_noflag(msg, |
| 5700 | NL80211_STA_INFO_BSS_PARAM); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5701 | if (!bss_param) |
| 5702 | goto nla_put_failure; |
| 5703 | |
| 5704 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 5705 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 5706 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 5707 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 5708 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 5709 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 5710 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 5711 | sinfo->bss_param.dtim_period) || |
| 5712 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 5713 | sinfo->bss_param.beacon_interval)) |
| 5714 | goto nla_put_failure; |
| 5715 | |
| 5716 | nla_nest_end(msg, bss_param); |
| 5717 | } |
| 5718 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
| 5719 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 5720 | sizeof(struct nl80211_sta_flag_update), |
| 5721 | &sinfo->sta_flags)) |
| 5722 | goto nla_put_failure; |
| 5723 | |
| 5724 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 5725 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 5726 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
| 5727 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5728 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 5729 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5730 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5731 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 5732 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 5733 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 5734 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5735 | |
| 5736 | #undef PUT_SINFO |
| 5737 | #undef PUT_SINFO_U64 |
| 5738 | |
| 5739 | if (sinfo->pertid) { |
| 5740 | struct nlattr *tidsattr; |
| 5741 | int tid; |
| 5742 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5743 | tidsattr = nla_nest_start_noflag(msg, |
| 5744 | NL80211_STA_INFO_TID_STATS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5745 | if (!tidsattr) |
| 5746 | goto nla_put_failure; |
| 5747 | |
| 5748 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 5749 | struct cfg80211_tid_stats *tidstats; |
| 5750 | struct nlattr *tidattr; |
| 5751 | |
| 5752 | tidstats = &sinfo->pertid[tid]; |
| 5753 | |
| 5754 | if (!tidstats->filled) |
| 5755 | continue; |
| 5756 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5757 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5758 | if (!tidattr) |
| 5759 | goto nla_put_failure; |
| 5760 | |
| 5761 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
| 5762 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
| 5763 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 5764 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
| 5765 | goto nla_put_failure; \ |
| 5766 | } while (0) |
| 5767 | |
| 5768 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 5769 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 5770 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 5771 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
| 5772 | |
| 5773 | #undef PUT_TIDVAL_U64 |
| 5774 | if ((tidstats->filled & |
| 5775 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 5776 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 5777 | NL80211_TID_STATS_TXQ_STATS)) |
| 5778 | goto nla_put_failure; |
| 5779 | |
| 5780 | nla_nest_end(msg, tidattr); |
| 5781 | } |
| 5782 | |
| 5783 | nla_nest_end(msg, tidsattr); |
| 5784 | } |
| 5785 | |
| 5786 | nla_nest_end(msg, sinfoattr); |
| 5787 | |
| 5788 | if (sinfo->assoc_req_ies_len && |
| 5789 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5790 | sinfo->assoc_req_ies)) |
| 5791 | goto nla_put_failure; |
| 5792 | |
| 5793 | cfg80211_sinfo_release_content(sinfo); |
| 5794 | genlmsg_end(msg, hdr); |
| 5795 | return 0; |
| 5796 | |
| 5797 | nla_put_failure: |
| 5798 | cfg80211_sinfo_release_content(sinfo); |
| 5799 | genlmsg_cancel(msg, hdr); |
| 5800 | return -EMSGSIZE; |
| 5801 | } |
| 5802 | |
| 5803 | static int nl80211_dump_station(struct sk_buff *skb, |
| 5804 | struct netlink_callback *cb) |
| 5805 | { |
| 5806 | struct station_info sinfo; |
| 5807 | struct cfg80211_registered_device *rdev; |
| 5808 | struct wireless_dev *wdev; |
| 5809 | u8 mac_addr[ETH_ALEN]; |
| 5810 | int sta_idx = cb->args[2]; |
| 5811 | int err; |
| 5812 | |
| 5813 | rtnl_lock(); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 5814 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 5815 | if (err) |
| 5816 | goto out_err; |
| 5817 | |
| 5818 | if (!wdev->netdev) { |
| 5819 | err = -EINVAL; |
| 5820 | goto out_err; |
| 5821 | } |
| 5822 | |
| 5823 | if (!rdev->ops->dump_station) { |
| 5824 | err = -EOPNOTSUPP; |
| 5825 | goto out_err; |
| 5826 | } |
| 5827 | |
| 5828 | while (1) { |
| 5829 | memset(&sinfo, 0, sizeof(sinfo)); |
| 5830 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
| 5831 | mac_addr, &sinfo); |
| 5832 | if (err == -ENOENT) |
| 5833 | break; |
| 5834 | if (err) |
| 5835 | goto out_err; |
| 5836 | |
| 5837 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
| 5838 | NETLINK_CB(cb->skb).portid, |
| 5839 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5840 | rdev, wdev->netdev, mac_addr, |
| 5841 | &sinfo) < 0) |
| 5842 | goto out; |
| 5843 | |
| 5844 | sta_idx++; |
| 5845 | } |
| 5846 | |
| 5847 | out: |
| 5848 | cb->args[2] = sta_idx; |
| 5849 | err = skb->len; |
| 5850 | out_err: |
| 5851 | rtnl_unlock(); |
| 5852 | |
| 5853 | return err; |
| 5854 | } |
| 5855 | |
| 5856 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5857 | { |
| 5858 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5859 | struct net_device *dev = info->user_ptr[1]; |
| 5860 | struct station_info sinfo; |
| 5861 | struct sk_buff *msg; |
| 5862 | u8 *mac_addr = NULL; |
| 5863 | int err; |
| 5864 | |
| 5865 | memset(&sinfo, 0, sizeof(sinfo)); |
| 5866 | |
| 5867 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5868 | return -EINVAL; |
| 5869 | |
| 5870 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5871 | |
| 5872 | if (!rdev->ops->get_station) |
| 5873 | return -EOPNOTSUPP; |
| 5874 | |
| 5875 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 5876 | if (err) |
| 5877 | return err; |
| 5878 | |
| 5879 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5880 | if (!msg) { |
| 5881 | cfg80211_sinfo_release_content(&sinfo); |
| 5882 | return -ENOMEM; |
| 5883 | } |
| 5884 | |
| 5885 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5886 | info->snd_portid, info->snd_seq, 0, |
| 5887 | rdev, dev, mac_addr, &sinfo) < 0) { |
| 5888 | nlmsg_free(msg); |
| 5889 | return -ENOBUFS; |
| 5890 | } |
| 5891 | |
| 5892 | return genlmsg_reply(msg, info); |
| 5893 | } |
| 5894 | |
| 5895 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5896 | struct station_parameters *params, |
| 5897 | enum cfg80211_station_type statype) |
| 5898 | { |
| 5899 | if (params->listen_interval != -1 && |
| 5900 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5901 | return -EINVAL; |
| 5902 | |
| 5903 | if (params->support_p2p_ps != -1 && |
| 5904 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5905 | return -EINVAL; |
| 5906 | |
| 5907 | if (params->aid && |
| 5908 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5909 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5910 | return -EINVAL; |
| 5911 | |
| 5912 | /* When you run into this, adjust the code below for the new flag */ |
| 5913 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5914 | |
| 5915 | switch (statype) { |
| 5916 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5917 | case CFG80211_STA_MESH_PEER_USER: |
| 5918 | /* |
| 5919 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5920 | * code doesn't have the bug of including TDLS in the |
| 5921 | * mask everywhere. |
| 5922 | */ |
| 5923 | if (params->sta_flags_mask & |
| 5924 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5925 | BIT(NL80211_STA_FLAG_MFP) | |
| 5926 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5927 | return -EINVAL; |
| 5928 | break; |
| 5929 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5930 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5931 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5932 | return -EINVAL; |
| 5933 | /* ignore since it can't change */ |
| 5934 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5935 | break; |
| 5936 | default: |
| 5937 | /* disallow mesh-specific things */ |
| 5938 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5939 | return -EINVAL; |
| 5940 | if (params->local_pm) |
| 5941 | return -EINVAL; |
| 5942 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5943 | return -EINVAL; |
| 5944 | } |
| 5945 | |
| 5946 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5947 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5948 | /* TDLS can't be set, ... */ |
| 5949 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5950 | return -EINVAL; |
| 5951 | /* |
| 5952 | * ... but don't bother the driver with it. This works around |
| 5953 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5954 | * TLDS_PEER flag in the mask even for AP mode. |
| 5955 | */ |
| 5956 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5957 | } |
| 5958 | |
| 5959 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5960 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
| 5961 | /* reject other things that can't change */ |
| 5962 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5963 | return -EINVAL; |
| 5964 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5965 | return -EINVAL; |
| 5966 | if (params->supported_rates) |
| 5967 | return -EINVAL; |
| 5968 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5969 | params->he_capa) |
| 5970 | return -EINVAL; |
| 5971 | } |
| 5972 | |
| 5973 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5974 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
| 5975 | if (params->vlan) |
| 5976 | return -EINVAL; |
| 5977 | } |
| 5978 | |
| 5979 | switch (statype) { |
| 5980 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5981 | /* Use this only for authorizing/unauthorizing a station */ |
| 5982 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5983 | return -EOPNOTSUPP; |
| 5984 | break; |
| 5985 | case CFG80211_STA_AP_CLIENT: |
| 5986 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
| 5987 | /* accept only the listed bits */ |
| 5988 | if (params->sta_flags_mask & |
| 5989 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5990 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5991 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5992 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5993 | BIT(NL80211_STA_FLAG_WME) | |
| 5994 | BIT(NL80211_STA_FLAG_MFP))) |
| 5995 | return -EINVAL; |
| 5996 | |
| 5997 | /* but authenticated/associated only if driver handles it */ |
| 5998 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5999 | params->sta_flags_mask & |
| 6000 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6001 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 6002 | return -EINVAL; |
| 6003 | break; |
| 6004 | case CFG80211_STA_IBSS: |
| 6005 | case CFG80211_STA_AP_STA: |
| 6006 | /* reject any changes other than AUTHORIZED */ |
| 6007 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 6008 | return -EINVAL; |
| 6009 | break; |
| 6010 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 6011 | /* reject any changes other than AUTHORIZED or WME */ |
| 6012 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 6013 | BIT(NL80211_STA_FLAG_WME))) |
| 6014 | return -EINVAL; |
| 6015 | /* force (at least) rates when authorizing */ |
| 6016 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 6017 | !params->supported_rates) |
| 6018 | return -EINVAL; |
| 6019 | break; |
| 6020 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 6021 | /* reject any changes */ |
| 6022 | return -EINVAL; |
| 6023 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 6024 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 6025 | return -EINVAL; |
| 6026 | break; |
| 6027 | case CFG80211_STA_MESH_PEER_USER: |
| 6028 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 6029 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
| 6030 | return -EINVAL; |
| 6031 | break; |
| 6032 | } |
| 6033 | |
| 6034 | /* |
| 6035 | * Older kernel versions ignored this attribute entirely, so don't |
| 6036 | * reject attempts to update it but mark it as unused instead so the |
| 6037 | * driver won't look at the data. |
| 6038 | */ |
| 6039 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 6040 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 6041 | params->opmode_notif_used = false; |
| 6042 | |
| 6043 | return 0; |
| 6044 | } |
| 6045 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 6046 | |
| 6047 | /* |
| 6048 | * Get vlan interface making sure it is running and on the right wiphy. |
| 6049 | */ |
| 6050 | static struct net_device *get_vlan(struct genl_info *info, |
| 6051 | struct cfg80211_registered_device *rdev) |
| 6052 | { |
| 6053 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
| 6054 | struct net_device *v; |
| 6055 | int ret; |
| 6056 | |
| 6057 | if (!vlanattr) |
| 6058 | return NULL; |
| 6059 | |
| 6060 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 6061 | if (!v) |
| 6062 | return ERR_PTR(-ENODEV); |
| 6063 | |
| 6064 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 6065 | ret = -EINVAL; |
| 6066 | goto error; |
| 6067 | } |
| 6068 | |
| 6069 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 6070 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6071 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 6072 | ret = -EINVAL; |
| 6073 | goto error; |
| 6074 | } |
| 6075 | |
| 6076 | if (!netif_running(v)) { |
| 6077 | ret = -ENETDOWN; |
| 6078 | goto error; |
| 6079 | } |
| 6080 | |
| 6081 | return v; |
| 6082 | error: |
| 6083 | dev_put(v); |
| 6084 | return ERR_PTR(ret); |
| 6085 | } |
| 6086 | |
| 6087 | static const struct nla_policy |
| 6088 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
| 6089 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 6090 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 6091 | }; |
| 6092 | |
| 6093 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 6094 | struct station_parameters *params) |
| 6095 | { |
| 6096 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 6097 | struct nlattr *nla; |
| 6098 | int err; |
| 6099 | |
| 6100 | /* parse WME attributes if present */ |
| 6101 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 6102 | return 0; |
| 6103 | |
| 6104 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6105 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 6106 | nl80211_sta_wme_policy, |
| 6107 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6108 | if (err) |
| 6109 | return err; |
| 6110 | |
| 6111 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 6112 | params->uapsd_queues = nla_get_u8( |
| 6113 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 6114 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 6115 | return -EINVAL; |
| 6116 | |
| 6117 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 6118 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 6119 | |
| 6120 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 6121 | return -EINVAL; |
| 6122 | |
| 6123 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 6124 | |
| 6125 | return 0; |
| 6126 | } |
| 6127 | |
| 6128 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 6129 | struct station_parameters *params) |
| 6130 | { |
| 6131 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 6132 | params->supported_channels = |
| 6133 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6134 | params->supported_channels_len = |
| 6135 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6136 | /* |
| 6137 | * Need to include at least one (first channel, number of |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6138 | * channels) tuple for each subband (checked in policy), |
| 6139 | * and must have proper tuples for the rest of the data as well. |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6140 | */ |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6141 | if (params->supported_channels_len % 2) |
| 6142 | return -EINVAL; |
| 6143 | } |
| 6144 | |
| 6145 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 6146 | params->supported_oper_classes = |
| 6147 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 6148 | params->supported_oper_classes_len = |
| 6149 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6150 | } |
| 6151 | return 0; |
| 6152 | } |
| 6153 | |
| 6154 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 6155 | struct station_parameters *params) |
| 6156 | { |
| 6157 | int err; |
| 6158 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
| 6159 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 6160 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
| 6161 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6162 | params->ht_capa = |
| 6163 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 6164 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6165 | params->vht_capa = |
| 6166 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6167 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6168 | params->he_capa = |
| 6169 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6170 | params->he_capa_len = |
| 6171 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | err = nl80211_parse_sta_channel_info(info, params); |
| 6175 | if (err) |
| 6176 | return err; |
| 6177 | |
| 6178 | return nl80211_parse_sta_wme(info, params); |
| 6179 | } |
| 6180 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6181 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 6182 | struct station_parameters *params) |
| 6183 | { |
| 6184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6185 | int idx; |
| 6186 | |
| 6187 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 6188 | if (!rdev->ops->set_tx_power || |
| 6189 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6190 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 6191 | return -EOPNOTSUPP; |
| 6192 | |
| 6193 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 6194 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 6195 | |
| 6196 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 6197 | idx = NL80211_ATTR_STA_TX_POWER; |
| 6198 | |
| 6199 | if (info->attrs[idx]) |
| 6200 | params->txpwr.power = |
| 6201 | nla_get_s16(info->attrs[idx]); |
| 6202 | else |
| 6203 | return -EINVAL; |
| 6204 | } |
| 6205 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 6206 | } |
| 6207 | |
| 6208 | return 0; |
| 6209 | } |
| 6210 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6211 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 6212 | { |
| 6213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6214 | struct net_device *dev = info->user_ptr[1]; |
| 6215 | struct station_parameters params; |
| 6216 | u8 *mac_addr; |
| 6217 | int err; |
| 6218 | |
| 6219 | memset(¶ms, 0, sizeof(params)); |
| 6220 | |
| 6221 | if (!rdev->ops->change_station) |
| 6222 | return -EOPNOTSUPP; |
| 6223 | |
| 6224 | /* |
| 6225 | * AID and listen_interval properties can be set only for unassociated |
| 6226 | * station. Include these parameters here and will check them in |
| 6227 | * cfg80211_check_station_change(). |
| 6228 | */ |
| 6229 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 6230 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 6231 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6232 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6233 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6234 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6235 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6236 | params.listen_interval = |
| 6237 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 6238 | else |
| 6239 | params.listen_interval = -1; |
| 6240 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6241 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 6242 | params.support_p2p_ps = |
| 6243 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 6244 | else |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6245 | params.support_p2p_ps = -1; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6246 | |
| 6247 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6248 | return -EINVAL; |
| 6249 | |
| 6250 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6251 | |
| 6252 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 6253 | params.supported_rates = |
| 6254 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6255 | params.supported_rates_len = |
| 6256 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6257 | } |
| 6258 | |
| 6259 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6260 | params.capability = |
| 6261 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6262 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6263 | } |
| 6264 | |
| 6265 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6266 | params.ext_capab = |
| 6267 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6268 | params.ext_capab_len = |
| 6269 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6270 | } |
| 6271 | |
| 6272 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
| 6273 | return -EINVAL; |
| 6274 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6275 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6276 | params.plink_action = |
| 6277 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6278 | |
| 6279 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
| 6280 | params.plink_state = |
| 6281 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6282 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6283 | params.peer_aid = nla_get_u16( |
| 6284 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6285 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 6286 | } |
| 6287 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6288 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 6289 | params.local_pm = nla_get_u32( |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6290 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 6291 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6292 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6293 | params.opmode_notif_used = true; |
| 6294 | params.opmode_notif = |
| 6295 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6296 | } |
| 6297 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6298 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6299 | params.he_6ghz_capa = |
| 6300 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6301 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6302 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6303 | params.airtime_weight = |
| 6304 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6305 | |
| 6306 | if (params.airtime_weight && |
| 6307 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6308 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6309 | return -EOPNOTSUPP; |
| 6310 | |
| 6311 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6312 | if (err) |
| 6313 | return err; |
| 6314 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6315 | /* Include parameters for TDLS peer (will check later) */ |
| 6316 | err = nl80211_set_station_tdls(info, ¶ms); |
| 6317 | if (err) |
| 6318 | return err; |
| 6319 | |
| 6320 | params.vlan = get_vlan(info, rdev); |
| 6321 | if (IS_ERR(params.vlan)) |
| 6322 | return PTR_ERR(params.vlan); |
| 6323 | |
| 6324 | switch (dev->ieee80211_ptr->iftype) { |
| 6325 | case NL80211_IFTYPE_AP: |
| 6326 | case NL80211_IFTYPE_AP_VLAN: |
| 6327 | case NL80211_IFTYPE_P2P_GO: |
| 6328 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6329 | case NL80211_IFTYPE_STATION: |
| 6330 | case NL80211_IFTYPE_ADHOC: |
| 6331 | case NL80211_IFTYPE_MESH_POINT: |
| 6332 | break; |
| 6333 | default: |
| 6334 | err = -EOPNOTSUPP; |
| 6335 | goto out_put_vlan; |
| 6336 | } |
| 6337 | |
| 6338 | /* driver will call cfg80211_check_station_change() */ |
| 6339 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
| 6340 | |
| 6341 | out_put_vlan: |
| 6342 | if (params.vlan) |
| 6343 | dev_put(params.vlan); |
| 6344 | |
| 6345 | return err; |
| 6346 | } |
| 6347 | |
| 6348 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6349 | { |
| 6350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6351 | int err; |
| 6352 | struct net_device *dev = info->user_ptr[1]; |
| 6353 | struct station_parameters params; |
| 6354 | u8 *mac_addr = NULL; |
| 6355 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6356 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 6357 | |
| 6358 | memset(¶ms, 0, sizeof(params)); |
| 6359 | |
| 6360 | if (!rdev->ops->add_station) |
| 6361 | return -EOPNOTSUPP; |
| 6362 | |
| 6363 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6364 | return -EINVAL; |
| 6365 | |
| 6366 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6367 | return -EINVAL; |
| 6368 | |
| 6369 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6373 | !info->attrs[NL80211_ATTR_PEER_AID]) |
| 6374 | return -EINVAL; |
| 6375 | |
| 6376 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6377 | params.supported_rates = |
| 6378 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6379 | params.supported_rates_len = |
| 6380 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6381 | params.listen_interval = |
| 6382 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 6383 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6384 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6385 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6386 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6387 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6388 | params.support_p2p_ps = |
| 6389 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6390 | } else { |
| 6391 | /* |
| 6392 | * if not specified, assume it's supported for P2P GO interface, |
| 6393 | * and is NOT supported for AP interface |
| 6394 | */ |
| 6395 | params.support_p2p_ps = |
| 6396 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6397 | } |
| 6398 | |
| 6399 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 6400 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
| 6401 | else |
| 6402 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6403 | |
| 6404 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6405 | params.capability = |
| 6406 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6407 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6408 | } |
| 6409 | |
| 6410 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6411 | params.ext_capab = |
| 6412 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6413 | params.ext_capab_len = |
| 6414 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6415 | } |
| 6416 | |
| 6417 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6418 | params.ht_capa = |
| 6419 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 6420 | |
| 6421 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6422 | params.vht_capa = |
| 6423 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6424 | |
| 6425 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6426 | params.he_capa = |
| 6427 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6428 | params.he_capa_len = |
| 6429 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6430 | } |
| 6431 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6432 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6433 | params.he_6ghz_capa = |
| 6434 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6435 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6436 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6437 | params.opmode_notif_used = true; |
| 6438 | params.opmode_notif = |
| 6439 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6440 | } |
| 6441 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6442 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6443 | params.plink_action = |
| 6444 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6445 | |
| 6446 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6447 | params.airtime_weight = |
| 6448 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6449 | |
| 6450 | if (params.airtime_weight && |
| 6451 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6452 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6453 | return -EOPNOTSUPP; |
| 6454 | |
| 6455 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6456 | if (err) |
| 6457 | return err; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6458 | |
| 6459 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6460 | if (err) |
| 6461 | return err; |
| 6462 | |
| 6463 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6464 | if (err) |
| 6465 | return err; |
| 6466 | |
| 6467 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
| 6468 | return -EINVAL; |
| 6469 | |
| 6470 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6471 | * as userspace might just pass through the capabilities from the IEs |
| 6472 | * directly, rather than enforcing this restriction and returning an |
| 6473 | * error in this case. |
| 6474 | */ |
| 6475 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6476 | params.ht_capa = NULL; |
| 6477 | params.vht_capa = NULL; |
| 6478 | |
| 6479 | /* HE requires WME */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6480 | if (params.he_capa_len || params.he_6ghz_capa) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6481 | return -EINVAL; |
| 6482 | } |
| 6483 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6484 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
| 6485 | if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) |
| 6486 | return -EINVAL; |
| 6487 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6488 | /* When you run into this, adjust the code below for the new flag */ |
| 6489 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6490 | |
| 6491 | switch (dev->ieee80211_ptr->iftype) { |
| 6492 | case NL80211_IFTYPE_AP: |
| 6493 | case NL80211_IFTYPE_AP_VLAN: |
| 6494 | case NL80211_IFTYPE_P2P_GO: |
| 6495 | /* ignore WME attributes if iface/sta is not capable */ |
| 6496 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6497 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6498 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6499 | |
| 6500 | /* TDLS peers cannot be added */ |
| 6501 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6502 | info->attrs[NL80211_ATTR_PEER_AID]) |
| 6503 | return -EINVAL; |
| 6504 | /* but don't bother the driver with it */ |
| 6505 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 6506 | |
| 6507 | /* allow authenticated/associated only if driver handles it */ |
| 6508 | if (!(rdev->wiphy.features & |
| 6509 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 6510 | params.sta_flags_mask & auth_assoc) |
| 6511 | return -EINVAL; |
| 6512 | |
| 6513 | /* Older userspace, or userspace wanting to be compatible with |
| 6514 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6515 | * and assoc flags in the mask, but assumes the station will be |
| 6516 | * added as associated anyway since this was the required driver |
| 6517 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6518 | * introduced. |
| 6519 | * In order to not bother drivers with this quirk in the API |
| 6520 | * set the flags in both the mask and set for new stations in |
| 6521 | * this case. |
| 6522 | */ |
| 6523 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6524 | params.sta_flags_mask |= auth_assoc; |
| 6525 | params.sta_flags_set |= auth_assoc; |
| 6526 | } |
| 6527 | |
| 6528 | /* must be last in here for error handling */ |
| 6529 | params.vlan = get_vlan(info, rdev); |
| 6530 | if (IS_ERR(params.vlan)) |
| 6531 | return PTR_ERR(params.vlan); |
| 6532 | break; |
| 6533 | case NL80211_IFTYPE_MESH_POINT: |
| 6534 | /* ignore uAPSD data */ |
| 6535 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6536 | |
| 6537 | /* associated is disallowed */ |
| 6538 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6539 | return -EINVAL; |
| 6540 | /* TDLS peers cannot be added */ |
| 6541 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6542 | info->attrs[NL80211_ATTR_PEER_AID]) |
| 6543 | return -EINVAL; |
| 6544 | break; |
| 6545 | case NL80211_IFTYPE_STATION: |
| 6546 | case NL80211_IFTYPE_P2P_CLIENT: |
| 6547 | /* ignore uAPSD data */ |
| 6548 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6549 | |
| 6550 | /* these are disallowed */ |
| 6551 | if (params.sta_flags_mask & |
| 6552 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6553 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
| 6554 | return -EINVAL; |
| 6555 | /* Only TDLS peers can be added */ |
| 6556 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6557 | return -EINVAL; |
| 6558 | /* Can only add if TDLS ... */ |
| 6559 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6560 | return -EOPNOTSUPP; |
| 6561 | /* ... with external setup is supported */ |
| 6562 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6563 | return -EOPNOTSUPP; |
| 6564 | /* |
| 6565 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6566 | * as authorized, but it shouldn't yet be. |
| 6567 | */ |
| 6568 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6569 | break; |
| 6570 | default: |
| 6571 | return -EOPNOTSUPP; |
| 6572 | } |
| 6573 | |
| 6574 | /* be aware of params.vlan when changing code here */ |
| 6575 | |
| 6576 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
| 6577 | |
| 6578 | if (params.vlan) |
| 6579 | dev_put(params.vlan); |
| 6580 | return err; |
| 6581 | } |
| 6582 | |
| 6583 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6584 | { |
| 6585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6586 | struct net_device *dev = info->user_ptr[1]; |
| 6587 | struct station_del_parameters params; |
| 6588 | |
| 6589 | memset(¶ms, 0, sizeof(params)); |
| 6590 | |
| 6591 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6592 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6593 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6594 | switch (dev->ieee80211_ptr->iftype) { |
| 6595 | case NL80211_IFTYPE_AP: |
| 6596 | case NL80211_IFTYPE_AP_VLAN: |
| 6597 | case NL80211_IFTYPE_MESH_POINT: |
| 6598 | case NL80211_IFTYPE_P2P_GO: |
| 6599 | /* always accept these */ |
| 6600 | break; |
| 6601 | case NL80211_IFTYPE_ADHOC: |
| 6602 | /* conditionally accept */ |
| 6603 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6604 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) |
| 6605 | break; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6606 | return -EINVAL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 6607 | default: |
| 6608 | return -EINVAL; |
| 6609 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6610 | |
| 6611 | if (!rdev->ops->del_station) |
| 6612 | return -EOPNOTSUPP; |
| 6613 | |
| 6614 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 6615 | params.subtype = |
| 6616 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 6617 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 6618 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 6619 | return -EINVAL; |
| 6620 | } else { |
| 6621 | /* Default to Deauthentication frame */ |
| 6622 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 6623 | } |
| 6624 | |
| 6625 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 6626 | params.reason_code = |
| 6627 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6628 | if (params.reason_code == 0) |
| 6629 | return -EINVAL; /* 0 is reserved */ |
| 6630 | } else { |
| 6631 | /* Default to reason code 2 */ |
| 6632 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 6633 | } |
| 6634 | |
| 6635 | return rdev_del_station(rdev, dev, ¶ms); |
| 6636 | } |
| 6637 | |
| 6638 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
| 6639 | int flags, struct net_device *dev, |
| 6640 | u8 *dst, u8 *next_hop, |
| 6641 | struct mpath_info *pinfo) |
| 6642 | { |
| 6643 | void *hdr; |
| 6644 | struct nlattr *pinfoattr; |
| 6645 | |
| 6646 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
| 6647 | if (!hdr) |
| 6648 | return -1; |
| 6649 | |
| 6650 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6651 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6652 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 6653 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 6654 | goto nla_put_failure; |
| 6655 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6656 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6657 | if (!pinfoattr) |
| 6658 | goto nla_put_failure; |
| 6659 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 6660 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 6661 | pinfo->frame_qlen)) |
| 6662 | goto nla_put_failure; |
| 6663 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 6664 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 6665 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 6666 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 6667 | pinfo->metric)) || |
| 6668 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 6669 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 6670 | pinfo->exptime)) || |
| 6671 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 6672 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 6673 | pinfo->flags)) || |
| 6674 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 6675 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 6676 | pinfo->discovery_timeout)) || |
| 6677 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 6678 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6679 | pinfo->discovery_retries)) || |
| 6680 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 6681 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
| 6682 | pinfo->hop_count)) || |
| 6683 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 6684 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 6685 | pinfo->path_change_count))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6686 | goto nla_put_failure; |
| 6687 | |
| 6688 | nla_nest_end(msg, pinfoattr); |
| 6689 | |
| 6690 | genlmsg_end(msg, hdr); |
| 6691 | return 0; |
| 6692 | |
| 6693 | nla_put_failure: |
| 6694 | genlmsg_cancel(msg, hdr); |
| 6695 | return -EMSGSIZE; |
| 6696 | } |
| 6697 | |
| 6698 | static int nl80211_dump_mpath(struct sk_buff *skb, |
| 6699 | struct netlink_callback *cb) |
| 6700 | { |
| 6701 | struct mpath_info pinfo; |
| 6702 | struct cfg80211_registered_device *rdev; |
| 6703 | struct wireless_dev *wdev; |
| 6704 | u8 dst[ETH_ALEN]; |
| 6705 | u8 next_hop[ETH_ALEN]; |
| 6706 | int path_idx = cb->args[2]; |
| 6707 | int err; |
| 6708 | |
| 6709 | rtnl_lock(); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6710 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6711 | if (err) |
| 6712 | goto out_err; |
| 6713 | |
| 6714 | if (!rdev->ops->dump_mpath) { |
| 6715 | err = -EOPNOTSUPP; |
| 6716 | goto out_err; |
| 6717 | } |
| 6718 | |
| 6719 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6720 | err = -EOPNOTSUPP; |
| 6721 | goto out_err; |
| 6722 | } |
| 6723 | |
| 6724 | while (1) { |
| 6725 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
| 6726 | next_hop, &pinfo); |
| 6727 | if (err == -ENOENT) |
| 6728 | break; |
| 6729 | if (err) |
| 6730 | goto out_err; |
| 6731 | |
| 6732 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6733 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6734 | wdev->netdev, dst, next_hop, |
| 6735 | &pinfo) < 0) |
| 6736 | goto out; |
| 6737 | |
| 6738 | path_idx++; |
| 6739 | } |
| 6740 | |
| 6741 | out: |
| 6742 | cb->args[2] = path_idx; |
| 6743 | err = skb->len; |
| 6744 | out_err: |
| 6745 | rtnl_unlock(); |
| 6746 | return err; |
| 6747 | } |
| 6748 | |
| 6749 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6750 | { |
| 6751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6752 | int err; |
| 6753 | struct net_device *dev = info->user_ptr[1]; |
| 6754 | struct mpath_info pinfo; |
| 6755 | struct sk_buff *msg; |
| 6756 | u8 *dst = NULL; |
| 6757 | u8 next_hop[ETH_ALEN]; |
| 6758 | |
| 6759 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6760 | |
| 6761 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6762 | return -EINVAL; |
| 6763 | |
| 6764 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6765 | |
| 6766 | if (!rdev->ops->get_mpath) |
| 6767 | return -EOPNOTSUPP; |
| 6768 | |
| 6769 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6770 | return -EOPNOTSUPP; |
| 6771 | |
| 6772 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
| 6773 | if (err) |
| 6774 | return err; |
| 6775 | |
| 6776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6777 | if (!msg) |
| 6778 | return -ENOMEM; |
| 6779 | |
| 6780 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6781 | dev, dst, next_hop, &pinfo) < 0) { |
| 6782 | nlmsg_free(msg); |
| 6783 | return -ENOBUFS; |
| 6784 | } |
| 6785 | |
| 6786 | return genlmsg_reply(msg, info); |
| 6787 | } |
| 6788 | |
| 6789 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6790 | { |
| 6791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6792 | struct net_device *dev = info->user_ptr[1]; |
| 6793 | u8 *dst = NULL; |
| 6794 | u8 *next_hop = NULL; |
| 6795 | |
| 6796 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6797 | return -EINVAL; |
| 6798 | |
| 6799 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6800 | return -EINVAL; |
| 6801 | |
| 6802 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6803 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6804 | |
| 6805 | if (!rdev->ops->change_mpath) |
| 6806 | return -EOPNOTSUPP; |
| 6807 | |
| 6808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6809 | return -EOPNOTSUPP; |
| 6810 | |
| 6811 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
| 6812 | } |
| 6813 | |
| 6814 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6815 | { |
| 6816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6817 | struct net_device *dev = info->user_ptr[1]; |
| 6818 | u8 *dst = NULL; |
| 6819 | u8 *next_hop = NULL; |
| 6820 | |
| 6821 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6822 | return -EINVAL; |
| 6823 | |
| 6824 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6825 | return -EINVAL; |
| 6826 | |
| 6827 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6828 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6829 | |
| 6830 | if (!rdev->ops->add_mpath) |
| 6831 | return -EOPNOTSUPP; |
| 6832 | |
| 6833 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6834 | return -EOPNOTSUPP; |
| 6835 | |
| 6836 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
| 6837 | } |
| 6838 | |
| 6839 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6840 | { |
| 6841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6842 | struct net_device *dev = info->user_ptr[1]; |
| 6843 | u8 *dst = NULL; |
| 6844 | |
| 6845 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6846 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6847 | |
| 6848 | if (!rdev->ops->del_mpath) |
| 6849 | return -EOPNOTSUPP; |
| 6850 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6851 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6852 | return -EOPNOTSUPP; |
| 6853 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6854 | return rdev_del_mpath(rdev, dev, dst); |
| 6855 | } |
| 6856 | |
| 6857 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6858 | { |
| 6859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6860 | int err; |
| 6861 | struct net_device *dev = info->user_ptr[1]; |
| 6862 | struct mpath_info pinfo; |
| 6863 | struct sk_buff *msg; |
| 6864 | u8 *dst = NULL; |
| 6865 | u8 mpp[ETH_ALEN]; |
| 6866 | |
| 6867 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6868 | |
| 6869 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6870 | return -EINVAL; |
| 6871 | |
| 6872 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6873 | |
| 6874 | if (!rdev->ops->get_mpp) |
| 6875 | return -EOPNOTSUPP; |
| 6876 | |
| 6877 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6878 | return -EOPNOTSUPP; |
| 6879 | |
| 6880 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6881 | if (err) |
| 6882 | return err; |
| 6883 | |
| 6884 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6885 | if (!msg) |
| 6886 | return -ENOMEM; |
| 6887 | |
| 6888 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6889 | dev, dst, mpp, &pinfo) < 0) { |
| 6890 | nlmsg_free(msg); |
| 6891 | return -ENOBUFS; |
| 6892 | } |
| 6893 | |
| 6894 | return genlmsg_reply(msg, info); |
| 6895 | } |
| 6896 | |
| 6897 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6898 | struct netlink_callback *cb) |
| 6899 | { |
| 6900 | struct mpath_info pinfo; |
| 6901 | struct cfg80211_registered_device *rdev; |
| 6902 | struct wireless_dev *wdev; |
| 6903 | u8 dst[ETH_ALEN]; |
| 6904 | u8 mpp[ETH_ALEN]; |
| 6905 | int path_idx = cb->args[2]; |
| 6906 | int err; |
| 6907 | |
| 6908 | rtnl_lock(); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6909 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6910 | if (err) |
| 6911 | goto out_err; |
| 6912 | |
| 6913 | if (!rdev->ops->dump_mpp) { |
| 6914 | err = -EOPNOTSUPP; |
| 6915 | goto out_err; |
| 6916 | } |
| 6917 | |
| 6918 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6919 | err = -EOPNOTSUPP; |
| 6920 | goto out_err; |
| 6921 | } |
| 6922 | |
| 6923 | while (1) { |
| 6924 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6925 | mpp, &pinfo); |
| 6926 | if (err == -ENOENT) |
| 6927 | break; |
| 6928 | if (err) |
| 6929 | goto out_err; |
| 6930 | |
| 6931 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6932 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6933 | wdev->netdev, dst, mpp, |
| 6934 | &pinfo) < 0) |
| 6935 | goto out; |
| 6936 | |
| 6937 | path_idx++; |
| 6938 | } |
| 6939 | |
| 6940 | out: |
| 6941 | cb->args[2] = path_idx; |
| 6942 | err = skb->len; |
| 6943 | out_err: |
| 6944 | rtnl_unlock(); |
| 6945 | return err; |
| 6946 | } |
| 6947 | |
| 6948 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6949 | { |
| 6950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6951 | struct net_device *dev = info->user_ptr[1]; |
| 6952 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6953 | struct bss_parameters params; |
| 6954 | int err; |
| 6955 | |
| 6956 | memset(¶ms, 0, sizeof(params)); |
| 6957 | /* default to not changing parameters */ |
| 6958 | params.use_cts_prot = -1; |
| 6959 | params.use_short_preamble = -1; |
| 6960 | params.use_short_slot_time = -1; |
| 6961 | params.ap_isolate = -1; |
| 6962 | params.ht_opmode = -1; |
| 6963 | params.p2p_ctwindow = -1; |
| 6964 | params.p2p_opp_ps = -1; |
| 6965 | |
| 6966 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6967 | params.use_cts_prot = |
| 6968 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6969 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6970 | params.use_short_preamble = |
| 6971 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6972 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6973 | params.use_short_slot_time = |
| 6974 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
| 6975 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6976 | params.basic_rates = |
| 6977 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6978 | params.basic_rates_len = |
| 6979 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6980 | } |
| 6981 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6982 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
| 6983 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6984 | params.ht_opmode = |
| 6985 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
| 6986 | |
| 6987 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6988 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6989 | return -EINVAL; |
| 6990 | params.p2p_ctwindow = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 6991 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6992 | if (params.p2p_ctwindow != 0 && |
| 6993 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6994 | return -EINVAL; |
| 6995 | } |
| 6996 | |
| 6997 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6998 | u8 tmp; |
| 6999 | |
| 7000 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7001 | return -EINVAL; |
| 7002 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7003 | params.p2p_opp_ps = tmp; |
| 7004 | if (params.p2p_opp_ps && |
| 7005 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 7006 | return -EINVAL; |
| 7007 | } |
| 7008 | |
| 7009 | if (!rdev->ops->change_bss) |
| 7010 | return -EOPNOTSUPP; |
| 7011 | |
| 7012 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 7013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7014 | return -EOPNOTSUPP; |
| 7015 | |
| 7016 | wdev_lock(wdev); |
| 7017 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 7018 | wdev_unlock(wdev); |
| 7019 | |
| 7020 | return err; |
| 7021 | } |
| 7022 | |
| 7023 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7024 | { |
| 7025 | char *data = NULL; |
| 7026 | bool is_indoor; |
| 7027 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
| 7028 | u32 owner_nlportid; |
| 7029 | |
| 7030 | /* |
| 7031 | * You should only get this when cfg80211 hasn't yet initialized |
| 7032 | * completely when built-in to the kernel right between the time |
| 7033 | * window between nl80211_init() and regulatory_init(), if that is |
| 7034 | * even possible. |
| 7035 | */ |
| 7036 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
| 7037 | return -EINPROGRESS; |
| 7038 | |
| 7039 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 7040 | user_reg_hint_type = |
| 7041 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 7042 | else |
| 7043 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 7044 | |
| 7045 | switch (user_reg_hint_type) { |
| 7046 | case NL80211_USER_REG_HINT_USER: |
| 7047 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 7048 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7049 | return -EINVAL; |
| 7050 | |
| 7051 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7052 | return regulatory_hint_user(data, user_reg_hint_type); |
| 7053 | case NL80211_USER_REG_HINT_INDOOR: |
| 7054 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 7055 | owner_nlportid = info->snd_portid; |
| 7056 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 7057 | } else { |
| 7058 | owner_nlportid = 0; |
| 7059 | is_indoor = true; |
| 7060 | } |
| 7061 | |
| 7062 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
| 7063 | default: |
| 7064 | return -EINVAL; |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 7069 | { |
| 7070 | return reg_reload_regdb(); |
| 7071 | } |
| 7072 | |
| 7073 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
| 7074 | struct genl_info *info) |
| 7075 | { |
| 7076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7077 | struct net_device *dev = info->user_ptr[1]; |
| 7078 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7079 | struct mesh_config cur_params; |
| 7080 | int err = 0; |
| 7081 | void *hdr; |
| 7082 | struct nlattr *pinfoattr; |
| 7083 | struct sk_buff *msg; |
| 7084 | |
| 7085 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7086 | return -EOPNOTSUPP; |
| 7087 | |
| 7088 | if (!rdev->ops->get_mesh_config) |
| 7089 | return -EOPNOTSUPP; |
| 7090 | |
| 7091 | wdev_lock(wdev); |
| 7092 | /* If not connected, get default parameters */ |
| 7093 | if (!wdev->mesh_id_len) |
| 7094 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 7095 | else |
| 7096 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
| 7097 | wdev_unlock(wdev); |
| 7098 | |
| 7099 | if (err) |
| 7100 | return err; |
| 7101 | |
| 7102 | /* Draw up a netlink message to send back */ |
| 7103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7104 | if (!msg) |
| 7105 | return -ENOMEM; |
| 7106 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7107 | NL80211_CMD_GET_MESH_CONFIG); |
| 7108 | if (!hdr) |
| 7109 | goto out; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7110 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7111 | if (!pinfoattr) |
| 7112 | goto nla_put_failure; |
| 7113 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7114 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 7115 | cur_params.dot11MeshRetryTimeout) || |
| 7116 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7117 | cur_params.dot11MeshConfirmTimeout) || |
| 7118 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7119 | cur_params.dot11MeshHoldingTimeout) || |
| 7120 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7121 | cur_params.dot11MeshMaxPeerLinks) || |
| 7122 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 7123 | cur_params.dot11MeshMaxRetries) || |
| 7124 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 7125 | cur_params.dot11MeshTTL) || |
| 7126 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 7127 | cur_params.element_ttl) || |
| 7128 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7129 | cur_params.auto_open_plinks) || |
| 7130 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 7131 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
| 7132 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7133 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 7134 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7135 | cur_params.path_refresh_time) || |
| 7136 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7137 | cur_params.min_discovery_timeout) || |
| 7138 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 7139 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 7140 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 7141 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 7142 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 7143 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 7144 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 7145 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 7146 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 7147 | cur_params.dot11MeshHWMPRootMode) || |
| 7148 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7149 | cur_params.dot11MeshHWMPRannInterval) || |
| 7150 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 7151 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 7152 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 7153 | cur_params.dot11MeshForwarding) || |
| 7154 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7155 | cur_params.rssi_threshold) || |
| 7156 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
| 7157 | cur_params.ht_opmode) || |
| 7158 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7159 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 7160 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7161 | cur_params.dot11MeshHWMProotInterval) || |
| 7162 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 7163 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 7164 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 7165 | cur_params.power_mode) || |
| 7166 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 7167 | cur_params.dot11MeshAwakeWindowDuration) || |
| 7168 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7169 | cur_params.plink_timeout) || |
| 7170 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 7171 | cur_params.dot11MeshConnectedToMeshGate) || |
| 7172 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, |
| 7173 | cur_params.dot11MeshNolearn) || |
| 7174 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7175 | cur_params.dot11MeshConnectedToAuthServer)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7176 | goto nla_put_failure; |
| 7177 | nla_nest_end(msg, pinfoattr); |
| 7178 | genlmsg_end(msg, hdr); |
| 7179 | return genlmsg_reply(msg, info); |
| 7180 | |
| 7181 | nla_put_failure: |
| 7182 | out: |
| 7183 | nlmsg_free(msg); |
| 7184 | return -ENOBUFS; |
| 7185 | } |
| 7186 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7187 | static const struct nla_policy |
| 7188 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 7189 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 7190 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7191 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 7192 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7193 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 7194 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7195 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 7196 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 7197 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 7198 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7199 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7200 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7201 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 7202 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7203 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 7204 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7205 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7206 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7207 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 7208 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7209 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 7210 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7211 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 7212 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7213 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 7214 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 7215 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7216 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7217 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7218 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 7219 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7220 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
| 7221 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7222 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 7223 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7224 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 7225 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7226 | [NL80211_MESHCONF_POWER_MODE] = |
| 7227 | NLA_POLICY_RANGE(NLA_U32, |
| 7228 | NL80211_MESH_POWER_ACTIVE, |
| 7229 | NL80211_MESH_POWER_MAX), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7230 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
| 7231 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7232 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 7233 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
| 7234 | [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7235 | }; |
| 7236 | |
| 7237 | static const struct nla_policy |
| 7238 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 7239 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
| 7240 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 7241 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
| 7242 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
| 7243 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
| 7244 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7245 | [NL80211_MESH_SETUP_IE] = |
| 7246 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 7247 | IEEE80211_MAX_DATA_LEN), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7248 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
| 7249 | }; |
| 7250 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7251 | static int nl80211_parse_mesh_config(struct genl_info *info, |
| 7252 | struct mesh_config *cfg, |
| 7253 | u32 *mask_out) |
| 7254 | { |
| 7255 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 7256 | u32 mask = 0; |
| 7257 | u16 ht_opmode; |
| 7258 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7259 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 7260 | do { \ |
| 7261 | if (tb[attr]) { \ |
| 7262 | cfg->param = fn(tb[attr]); \ |
| 7263 | mask |= BIT((attr) - 1); \ |
| 7264 | } \ |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7265 | } while (0) |
| 7266 | |
| 7267 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
| 7268 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7269 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7270 | return -EINVAL; |
| 7271 | |
| 7272 | /* This makes sure that there aren't more than 32 mesh config |
| 7273 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 7274 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 7275 | |
| 7276 | /* Fill in the params struct */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 7278 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 7279 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 7280 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7281 | nla_get_u16); |
| 7282 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 7283 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7284 | nla_get_u16); |
| 7285 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 7286 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7287 | nla_get_u16); |
| 7288 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 7289 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 7290 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 7291 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 7292 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 7293 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 7294 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 7295 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7296 | nla_get_u8); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7297 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7298 | mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7299 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7300 | nla_get_u32); |
| 7301 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 7302 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7303 | nla_get_u8); |
| 7304 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 7305 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7306 | nla_get_u32); |
| 7307 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 7308 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 7309 | return -EINVAL; |
| 7310 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 7311 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7312 | nla_get_u16); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7313 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7314 | mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7315 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7316 | nla_get_u32); |
| 7317 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 7318 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 7319 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 7320 | return -EINVAL; |
| 7321 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7322 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7323 | nla_get_u16); |
| 7324 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7325 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7326 | nla_get_u16); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7327 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7328 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7329 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7330 | nla_get_u16); |
| 7331 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 7332 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 7333 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 7334 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7335 | nla_get_u16); |
| 7336 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7337 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7338 | nla_get_u8); |
| 7339 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 7340 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 7341 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 7342 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7343 | nla_get_s32); |
| 7344 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 7345 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 7346 | nla_get_u8); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 7347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
| 7348 | NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7349 | nla_get_u8); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7350 | /* |
| 7351 | * Check HT operation mode based on |
| 7352 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
| 7353 | */ |
| 7354 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 7355 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 7356 | |
| 7357 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 7358 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 7359 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7360 | return -EINVAL; |
| 7361 | |
| 7362 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7363 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
| 7364 | |
| 7365 | cfg->ht_opmode = ht_opmode; |
| 7366 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
| 7367 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7368 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7369 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7370 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7371 | nla_get_u32); |
| 7372 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7373 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7374 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7375 | return -EINVAL; |
| 7376 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7377 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7378 | nla_get_u16); |
| 7379 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7380 | mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7381 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7382 | nla_get_u16); |
| 7383 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7384 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7385 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7386 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7387 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7388 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 7389 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
| 7390 | NL80211_MESHCONF_NOLEARN, nla_get_u8); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7391 | if (mask_out) |
| 7392 | *mask_out = mask; |
| 7393 | |
| 7394 | return 0; |
| 7395 | |
| 7396 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7397 | } |
| 7398 | |
| 7399 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7400 | struct mesh_setup *setup) |
| 7401 | { |
| 7402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7403 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7404 | |
| 7405 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7406 | return -EINVAL; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7407 | if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7408 | return -EINVAL; |
| 7409 | |
| 7410 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7411 | setup->sync_method = |
| 7412 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7413 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7414 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7415 | |
| 7416 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7417 | setup->path_sel_proto = |
| 7418 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7419 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7420 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7421 | |
| 7422 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7423 | setup->path_metric = |
| 7424 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7425 | IEEE80211_PATH_METRIC_VENDOR : |
| 7426 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7427 | |
| 7428 | if (tb[NL80211_MESH_SETUP_IE]) { |
| 7429 | struct nlattr *ieattr = |
| 7430 | tb[NL80211_MESH_SETUP_IE]; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7431 | setup->ie = nla_data(ieattr); |
| 7432 | setup->ie_len = nla_len(ieattr); |
| 7433 | } |
| 7434 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7435 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7436 | return -EINVAL; |
| 7437 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
| 7438 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7439 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
| 7440 | if (setup->is_secure) |
| 7441 | setup->user_mpm = true; |
| 7442 | |
| 7443 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7444 | if (!setup->user_mpm) |
| 7445 | return -EINVAL; |
| 7446 | setup->auth_id = |
| 7447 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7448 | } |
| 7449 | |
| 7450 | return 0; |
| 7451 | } |
| 7452 | |
| 7453 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
| 7454 | struct genl_info *info) |
| 7455 | { |
| 7456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7457 | struct net_device *dev = info->user_ptr[1]; |
| 7458 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7459 | struct mesh_config cfg; |
| 7460 | u32 mask; |
| 7461 | int err; |
| 7462 | |
| 7463 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7464 | return -EOPNOTSUPP; |
| 7465 | |
| 7466 | if (!rdev->ops->update_mesh_config) |
| 7467 | return -EOPNOTSUPP; |
| 7468 | |
| 7469 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
| 7470 | if (err) |
| 7471 | return err; |
| 7472 | |
| 7473 | wdev_lock(wdev); |
| 7474 | if (!wdev->mesh_id_len) |
| 7475 | err = -ENOLINK; |
| 7476 | |
| 7477 | if (!err) |
| 7478 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
| 7479 | |
| 7480 | wdev_unlock(wdev); |
| 7481 | |
| 7482 | return err; |
| 7483 | } |
| 7484 | |
| 7485 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7486 | struct sk_buff *msg) |
| 7487 | { |
| 7488 | struct nlattr *nl_reg_rules; |
| 7489 | unsigned int i; |
| 7490 | |
| 7491 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7492 | (regdom->dfs_region && |
| 7493 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 7494 | goto nla_put_failure; |
| 7495 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7496 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7497 | if (!nl_reg_rules) |
| 7498 | goto nla_put_failure; |
| 7499 | |
| 7500 | for (i = 0; i < regdom->n_reg_rules; i++) { |
| 7501 | struct nlattr *nl_reg_rule; |
| 7502 | const struct ieee80211_reg_rule *reg_rule; |
| 7503 | const struct ieee80211_freq_range *freq_range; |
| 7504 | const struct ieee80211_power_rule *power_rule; |
| 7505 | unsigned int max_bandwidth_khz; |
| 7506 | |
| 7507 | reg_rule = ®dom->reg_rules[i]; |
| 7508 | freq_range = ®_rule->freq_range; |
| 7509 | power_rule = ®_rule->power_rule; |
| 7510 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7511 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7512 | if (!nl_reg_rule) |
| 7513 | goto nla_put_failure; |
| 7514 | |
| 7515 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7516 | if (!max_bandwidth_khz) |
| 7517 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7518 | reg_rule); |
| 7519 | |
| 7520 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7521 | reg_rule->flags) || |
| 7522 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7523 | freq_range->start_freq_khz) || |
| 7524 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7525 | freq_range->end_freq_khz) || |
| 7526 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 7527 | max_bandwidth_khz) || |
| 7528 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7529 | power_rule->max_antenna_gain) || |
| 7530 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 7531 | power_rule->max_eirp) || |
| 7532 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7533 | reg_rule->dfs_cac_ms)) |
| 7534 | goto nla_put_failure; |
| 7535 | |
| 7536 | nla_nest_end(msg, nl_reg_rule); |
| 7537 | } |
| 7538 | |
| 7539 | nla_nest_end(msg, nl_reg_rules); |
| 7540 | return 0; |
| 7541 | |
| 7542 | nla_put_failure: |
| 7543 | return -EMSGSIZE; |
| 7544 | } |
| 7545 | |
| 7546 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7547 | { |
| 7548 | const struct ieee80211_regdomain *regdom = NULL; |
| 7549 | struct cfg80211_registered_device *rdev; |
| 7550 | struct wiphy *wiphy = NULL; |
| 7551 | struct sk_buff *msg; |
| 7552 | void *hdr; |
| 7553 | |
| 7554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7555 | if (!msg) |
| 7556 | return -ENOBUFS; |
| 7557 | |
| 7558 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7559 | NL80211_CMD_GET_REG); |
| 7560 | if (!hdr) |
| 7561 | goto put_failure; |
| 7562 | |
| 7563 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
| 7564 | bool self_managed; |
| 7565 | |
| 7566 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7567 | if (IS_ERR(rdev)) { |
| 7568 | nlmsg_free(msg); |
| 7569 | return PTR_ERR(rdev); |
| 7570 | } |
| 7571 | |
| 7572 | wiphy = &rdev->wiphy; |
| 7573 | self_managed = wiphy->regulatory_flags & |
| 7574 | REGULATORY_WIPHY_SELF_MANAGED; |
| 7575 | regdom = get_wiphy_regdom(wiphy); |
| 7576 | |
| 7577 | /* a self-managed-reg device must have a private regdom */ |
| 7578 | if (WARN_ON(!regdom && self_managed)) { |
| 7579 | nlmsg_free(msg); |
| 7580 | return -EINVAL; |
| 7581 | } |
| 7582 | |
| 7583 | if (regdom && |
| 7584 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7585 | goto nla_put_failure; |
| 7586 | } |
| 7587 | |
| 7588 | if (!wiphy && reg_last_request_cell_base() && |
| 7589 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7590 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7591 | goto nla_put_failure; |
| 7592 | |
| 7593 | rcu_read_lock(); |
| 7594 | |
| 7595 | if (!regdom) |
| 7596 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7597 | |
| 7598 | if (nl80211_put_regdom(regdom, msg)) |
| 7599 | goto nla_put_failure_rcu; |
| 7600 | |
| 7601 | rcu_read_unlock(); |
| 7602 | |
| 7603 | genlmsg_end(msg, hdr); |
| 7604 | return genlmsg_reply(msg, info); |
| 7605 | |
| 7606 | nla_put_failure_rcu: |
| 7607 | rcu_read_unlock(); |
| 7608 | nla_put_failure: |
| 7609 | put_failure: |
| 7610 | nlmsg_free(msg); |
| 7611 | return -EMSGSIZE; |
| 7612 | } |
| 7613 | |
| 7614 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 7615 | u32 seq, int flags, struct wiphy *wiphy, |
| 7616 | const struct ieee80211_regdomain *regdom) |
| 7617 | { |
| 7618 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 7619 | NL80211_CMD_GET_REG); |
| 7620 | |
| 7621 | if (!hdr) |
| 7622 | return -1; |
| 7623 | |
| 7624 | genl_dump_check_consistent(cb, hdr); |
| 7625 | |
| 7626 | if (nl80211_put_regdom(regdom, msg)) |
| 7627 | goto nla_put_failure; |
| 7628 | |
| 7629 | if (!wiphy && reg_last_request_cell_base() && |
| 7630 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7631 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7632 | goto nla_put_failure; |
| 7633 | |
| 7634 | if (wiphy && |
| 7635 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7636 | goto nla_put_failure; |
| 7637 | |
| 7638 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 7639 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 7640 | goto nla_put_failure; |
| 7641 | |
| 7642 | genlmsg_end(msg, hdr); |
| 7643 | return 0; |
| 7644 | |
| 7645 | nla_put_failure: |
| 7646 | genlmsg_cancel(msg, hdr); |
| 7647 | return -EMSGSIZE; |
| 7648 | } |
| 7649 | |
| 7650 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 7651 | struct netlink_callback *cb) |
| 7652 | { |
| 7653 | const struct ieee80211_regdomain *regdom = NULL; |
| 7654 | struct cfg80211_registered_device *rdev; |
| 7655 | int err, reg_idx, start = cb->args[2]; |
| 7656 | |
| 7657 | rtnl_lock(); |
| 7658 | |
| 7659 | if (cfg80211_regdomain && start == 0) { |
| 7660 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7661 | NLM_F_MULTI, NULL, |
| 7662 | rtnl_dereference(cfg80211_regdomain)); |
| 7663 | if (err < 0) |
| 7664 | goto out_err; |
| 7665 | } |
| 7666 | |
| 7667 | /* the global regdom is idx 0 */ |
| 7668 | reg_idx = 1; |
| 7669 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 7670 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 7671 | if (!regdom) |
| 7672 | continue; |
| 7673 | |
| 7674 | if (++reg_idx <= start) |
| 7675 | continue; |
| 7676 | |
| 7677 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7678 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 7679 | if (err < 0) { |
| 7680 | reg_idx--; |
| 7681 | break; |
| 7682 | } |
| 7683 | } |
| 7684 | |
| 7685 | cb->args[2] = reg_idx; |
| 7686 | err = skb->len; |
| 7687 | out_err: |
| 7688 | rtnl_unlock(); |
| 7689 | return err; |
| 7690 | } |
| 7691 | |
| 7692 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 7693 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 7694 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 7695 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 7696 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 7697 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 7698 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 7699 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 7700 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 7701 | }; |
| 7702 | |
| 7703 | static int parse_reg_rule(struct nlattr *tb[], |
| 7704 | struct ieee80211_reg_rule *reg_rule) |
| 7705 | { |
| 7706 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 7707 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 7708 | |
| 7709 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 7710 | return -EINVAL; |
| 7711 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 7712 | return -EINVAL; |
| 7713 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 7714 | return -EINVAL; |
| 7715 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 7716 | return -EINVAL; |
| 7717 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 7718 | return -EINVAL; |
| 7719 | |
| 7720 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 7721 | |
| 7722 | freq_range->start_freq_khz = |
| 7723 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 7724 | freq_range->end_freq_khz = |
| 7725 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 7726 | freq_range->max_bandwidth_khz = |
| 7727 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 7728 | |
| 7729 | power_rule->max_eirp = |
| 7730 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 7731 | |
| 7732 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 7733 | power_rule->max_antenna_gain = |
| 7734 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 7735 | |
| 7736 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 7737 | reg_rule->dfs_cac_ms = |
| 7738 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 7739 | |
| 7740 | return 0; |
| 7741 | } |
| 7742 | |
| 7743 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7744 | { |
| 7745 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 7746 | struct nlattr *nl_reg_rule; |
| 7747 | char *alpha2; |
| 7748 | int rem_reg_rules, r; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7749 | u32 num_rules = 0, rule_idx = 0; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7750 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
| 7751 | struct ieee80211_regdomain *rd; |
| 7752 | |
| 7753 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7754 | return -EINVAL; |
| 7755 | |
| 7756 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 7757 | return -EINVAL; |
| 7758 | |
| 7759 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7760 | |
| 7761 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 7762 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 7763 | |
| 7764 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 7765 | rem_reg_rules) { |
| 7766 | num_rules++; |
| 7767 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 7768 | return -EINVAL; |
| 7769 | } |
| 7770 | |
| 7771 | if (!reg_is_valid_request(alpha2)) |
| 7772 | return -EINVAL; |
| 7773 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7774 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7775 | if (!rd) |
| 7776 | return -ENOMEM; |
| 7777 | |
| 7778 | rd->n_reg_rules = num_rules; |
| 7779 | rd->alpha2[0] = alpha2[0]; |
| 7780 | rd->alpha2[1] = alpha2[1]; |
| 7781 | |
| 7782 | /* |
| 7783 | * Disable DFS master mode if the DFS region was |
| 7784 | * not supported or known on this kernel. |
| 7785 | */ |
| 7786 | if (reg_supported_dfs_region(dfs_region)) |
| 7787 | rd->dfs_region = dfs_region; |
| 7788 | |
| 7789 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 7790 | rem_reg_rules) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7791 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 7792 | nl_reg_rule, reg_rule_policy, |
| 7793 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7794 | if (r) |
| 7795 | goto bad_reg; |
| 7796 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 7797 | if (r) |
| 7798 | goto bad_reg; |
| 7799 | |
| 7800 | rule_idx++; |
| 7801 | |
| 7802 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 7803 | r = -EINVAL; |
| 7804 | goto bad_reg; |
| 7805 | } |
| 7806 | } |
| 7807 | |
| 7808 | /* set_regdom takes ownership of rd */ |
| 7809 | return set_regdom(rd, REGD_SOURCE_CRDA); |
| 7810 | bad_reg: |
| 7811 | kfree(rd); |
| 7812 | return r; |
| 7813 | } |
| 7814 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
| 7815 | |
| 7816 | static int validate_scan_freqs(struct nlattr *freqs) |
| 7817 | { |
| 7818 | struct nlattr *attr1, *attr2; |
| 7819 | int n_channels = 0, tmp1, tmp2; |
| 7820 | |
| 7821 | nla_for_each_nested(attr1, freqs, tmp1) |
| 7822 | if (nla_len(attr1) != sizeof(u32)) |
| 7823 | return 0; |
| 7824 | |
| 7825 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 7826 | n_channels++; |
| 7827 | /* |
| 7828 | * Some hardware has a limited channel list for |
| 7829 | * scanning, and it is pretty much nonsensical |
| 7830 | * to scan for a channel twice, so disallow that |
| 7831 | * and don't require drivers to check that the |
| 7832 | * channel list they get isn't longer than what |
| 7833 | * they can scan, as long as they can scan all |
| 7834 | * the channels they registered at once. |
| 7835 | */ |
| 7836 | nla_for_each_nested(attr2, freqs, tmp2) |
| 7837 | if (attr1 != attr2 && |
| 7838 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 7839 | return 0; |
| 7840 | } |
| 7841 | |
| 7842 | return n_channels; |
| 7843 | } |
| 7844 | |
| 7845 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
| 7846 | { |
| 7847 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
| 7848 | } |
| 7849 | |
| 7850 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7851 | struct cfg80211_bss_selection *bss_select) |
| 7852 | { |
| 7853 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7854 | struct nlattr *nest; |
| 7855 | int err; |
| 7856 | bool found = false; |
| 7857 | int i; |
| 7858 | |
| 7859 | /* only process one nested attribute */ |
| 7860 | nest = nla_data(nla); |
| 7861 | if (!nla_ok(nest, nla_len(nest))) |
| 7862 | return -EINVAL; |
| 7863 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7864 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 7865 | nest, nl80211_bss_select_policy, |
| 7866 | NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7867 | if (err) |
| 7868 | return err; |
| 7869 | |
| 7870 | /* only one attribute may be given */ |
| 7871 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7872 | if (attr[i]) { |
| 7873 | if (found) |
| 7874 | return -EINVAL; |
| 7875 | found = true; |
| 7876 | } |
| 7877 | } |
| 7878 | |
| 7879 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7880 | |
| 7881 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7882 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7883 | |
| 7884 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7885 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7886 | bss_select->param.band_pref = |
| 7887 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7888 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7889 | return -EINVAL; |
| 7890 | } |
| 7891 | |
| 7892 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7893 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7894 | |
| 7895 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7896 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7897 | bss_select->param.adjust.band = adj_param->band; |
| 7898 | bss_select->param.adjust.delta = adj_param->delta; |
| 7899 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7900 | return -EINVAL; |
| 7901 | } |
| 7902 | |
| 7903 | /* user-space did not provide behaviour attribute */ |
| 7904 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7905 | return -EINVAL; |
| 7906 | |
| 7907 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7908 | return -EINVAL; |
| 7909 | |
| 7910 | return 0; |
| 7911 | } |
| 7912 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7913 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7914 | u8 *mac_addr, u8 *mac_addr_mask) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7915 | { |
| 7916 | int i; |
| 7917 | |
| 7918 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
| 7919 | eth_zero_addr(mac_addr); |
| 7920 | eth_zero_addr(mac_addr_mask); |
| 7921 | mac_addr[0] = 0x2; |
| 7922 | mac_addr_mask[0] = 0x3; |
| 7923 | |
| 7924 | return 0; |
| 7925 | } |
| 7926 | |
| 7927 | /* need both or none */ |
| 7928 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7929 | return -EINVAL; |
| 7930 | |
| 7931 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7932 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7933 | |
| 7934 | /* don't allow or configure an mcast address */ |
| 7935 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7936 | is_multicast_ether_addr(mac_addr)) |
| 7937 | return -EINVAL; |
| 7938 | |
| 7939 | /* |
| 7940 | * allow users to pass a MAC address that has bits set outside |
| 7941 | * of the mask, but don't bother drivers with having to deal |
| 7942 | * with such bits |
| 7943 | */ |
| 7944 | for (i = 0; i < ETH_ALEN; i++) |
| 7945 | mac_addr[i] &= mac_addr_mask[i]; |
| 7946 | |
| 7947 | return 0; |
| 7948 | } |
| 7949 | |
| 7950 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7951 | { |
| 7952 | ASSERT_WDEV_LOCK(wdev); |
| 7953 | |
| 7954 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7955 | return true; |
| 7956 | |
| 7957 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7958 | return true; |
| 7959 | |
| 7960 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7961 | } |
| 7962 | |
| 7963 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7964 | enum nl80211_ext_feature_index feat) |
| 7965 | { |
| 7966 | if (!(flags & flag)) |
| 7967 | return true; |
| 7968 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7969 | return true; |
| 7970 | return false; |
| 7971 | } |
| 7972 | |
| 7973 | static int |
| 7974 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7975 | void *request, struct nlattr **attrs, |
| 7976 | bool is_sched_scan) |
| 7977 | { |
| 7978 | u8 *mac_addr, *mac_addr_mask; |
| 7979 | u32 *flags; |
| 7980 | enum nl80211_feature_flags randomness_flag; |
| 7981 | |
| 7982 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7983 | return 0; |
| 7984 | |
| 7985 | if (is_sched_scan) { |
| 7986 | struct cfg80211_sched_scan_request *req = request; |
| 7987 | |
| 7988 | randomness_flag = wdev ? |
| 7989 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7990 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7991 | flags = &req->flags; |
| 7992 | mac_addr = req->mac_addr; |
| 7993 | mac_addr_mask = req->mac_addr_mask; |
| 7994 | } else { |
| 7995 | struct cfg80211_scan_request *req = request; |
| 7996 | |
| 7997 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7998 | flags = &req->flags; |
| 7999 | mac_addr = req->mac_addr; |
| 8000 | mac_addr_mask = req->mac_addr_mask; |
| 8001 | } |
| 8002 | |
| 8003 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 8004 | |
| 8005 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 8006 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 8007 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8008 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 8009 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 8010 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8011 | NL80211_SCAN_FLAG_LOW_POWER, |
| 8012 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 8013 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8014 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 8015 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 8016 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8017 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 8018 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 8019 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8020 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 8021 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 8022 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8023 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 8024 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 8025 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8026 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
| 8027 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 8028 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8029 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 8030 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 8031 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8032 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 8033 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
| 8034 | return -EOPNOTSUPP; |
| 8035 | |
| 8036 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 8037 | int err; |
| 8038 | |
| 8039 | if (!(wiphy->features & randomness_flag) || |
| 8040 | (wdev && wdev->current_bss)) |
| 8041 | return -EOPNOTSUPP; |
| 8042 | |
| 8043 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 8044 | if (err) |
| 8045 | return err; |
| 8046 | } |
| 8047 | |
| 8048 | return 0; |
| 8049 | } |
| 8050 | |
| 8051 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 8052 | { |
| 8053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8054 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8055 | struct cfg80211_scan_request *request; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8056 | struct nlattr *scan_freqs = NULL; |
| 8057 | bool scan_freqs_khz = false; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8058 | struct nlattr *attr; |
| 8059 | struct wiphy *wiphy; |
| 8060 | int err, tmp, n_ssids = 0, n_channels, i; |
| 8061 | size_t ie_len; |
| 8062 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8063 | wiphy = &rdev->wiphy; |
| 8064 | |
| 8065 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 8066 | return -EOPNOTSUPP; |
| 8067 | |
| 8068 | if (!rdev->ops->scan) |
| 8069 | return -EOPNOTSUPP; |
| 8070 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8071 | if (rdev->scan_req || rdev->scan_msg) |
| 8072 | return -EBUSY; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8073 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8074 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
| 8075 | if (!wiphy_ext_feature_isset(wiphy, |
| 8076 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) |
| 8077 | return -EOPNOTSUPP; |
| 8078 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; |
| 8079 | scan_freqs_khz = true; |
| 8080 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) |
| 8081 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; |
| 8082 | |
| 8083 | if (scan_freqs) { |
| 8084 | n_channels = validate_scan_freqs(scan_freqs); |
| 8085 | if (!n_channels) |
| 8086 | return -EINVAL; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8087 | } else { |
| 8088 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
| 8089 | } |
| 8090 | |
| 8091 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8092 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 8093 | n_ssids++; |
| 8094 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8095 | if (n_ssids > wiphy->max_scan_ssids) |
| 8096 | return -EINVAL; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8097 | |
| 8098 | if (info->attrs[NL80211_ATTR_IE]) |
| 8099 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8100 | else |
| 8101 | ie_len = 0; |
| 8102 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8103 | if (ie_len > wiphy->max_scan_ie_len) |
| 8104 | return -EINVAL; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8105 | |
| 8106 | request = kzalloc(sizeof(*request) |
| 8107 | + sizeof(*request->ssids) * n_ssids |
| 8108 | + sizeof(*request->channels) * n_channels |
| 8109 | + ie_len, GFP_KERNEL); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8110 | if (!request) |
| 8111 | return -ENOMEM; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8112 | |
| 8113 | if (n_ssids) |
| 8114 | request->ssids = (void *)&request->channels[n_channels]; |
| 8115 | request->n_ssids = n_ssids; |
| 8116 | if (ie_len) { |
| 8117 | if (n_ssids) |
| 8118 | request->ie = (void *)(request->ssids + n_ssids); |
| 8119 | else |
| 8120 | request->ie = (void *)(request->channels + n_channels); |
| 8121 | } |
| 8122 | |
| 8123 | i = 0; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8124 | if (scan_freqs) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8125 | /* user specified, bail out if channel not found */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8126 | nla_for_each_nested(attr, scan_freqs, tmp) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8127 | struct ieee80211_channel *chan; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8128 | int freq = nla_get_u32(attr); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8129 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8130 | if (!scan_freqs_khz) |
| 8131 | freq = MHZ_TO_KHZ(freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8132 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8133 | chan = ieee80211_get_channel_khz(wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8134 | if (!chan) { |
| 8135 | err = -EINVAL; |
| 8136 | goto out_free; |
| 8137 | } |
| 8138 | |
| 8139 | /* ignore disabled channels */ |
| 8140 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8141 | continue; |
| 8142 | |
| 8143 | request->channels[i] = chan; |
| 8144 | i++; |
| 8145 | } |
| 8146 | } else { |
| 8147 | enum nl80211_band band; |
| 8148 | |
| 8149 | /* all channels */ |
| 8150 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| 8151 | int j; |
| 8152 | |
| 8153 | if (!wiphy->bands[band]) |
| 8154 | continue; |
| 8155 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8156 | struct ieee80211_channel *chan; |
| 8157 | |
| 8158 | chan = &wiphy->bands[band]->channels[j]; |
| 8159 | |
| 8160 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8161 | continue; |
| 8162 | |
| 8163 | request->channels[i] = chan; |
| 8164 | i++; |
| 8165 | } |
| 8166 | } |
| 8167 | } |
| 8168 | |
| 8169 | if (!i) { |
| 8170 | err = -EINVAL; |
| 8171 | goto out_free; |
| 8172 | } |
| 8173 | |
| 8174 | request->n_channels = i; |
| 8175 | |
| 8176 | wdev_lock(wdev); |
| 8177 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 8178 | struct ieee80211_channel *chan; |
| 8179 | |
| 8180 | if (request->n_channels != 1) { |
| 8181 | wdev_unlock(wdev); |
| 8182 | err = -EBUSY; |
| 8183 | goto out_free; |
| 8184 | } |
| 8185 | |
| 8186 | chan = request->channels[0]; |
| 8187 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 8188 | wdev_unlock(wdev); |
| 8189 | err = -EBUSY; |
| 8190 | goto out_free; |
| 8191 | } |
| 8192 | } |
| 8193 | wdev_unlock(wdev); |
| 8194 | |
| 8195 | i = 0; |
| 8196 | if (n_ssids) { |
| 8197 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 8198 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
| 8199 | err = -EINVAL; |
| 8200 | goto out_free; |
| 8201 | } |
| 8202 | request->ssids[i].ssid_len = nla_len(attr); |
| 8203 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 8204 | i++; |
| 8205 | } |
| 8206 | } |
| 8207 | |
| 8208 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8209 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8210 | memcpy((void *)request->ie, |
| 8211 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8212 | request->ie_len); |
| 8213 | } |
| 8214 | |
| 8215 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8216 | if (wiphy->bands[i]) |
| 8217 | request->rates[i] = |
| 8218 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
| 8219 | |
| 8220 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 8221 | nla_for_each_nested(attr, |
| 8222 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 8223 | tmp) { |
| 8224 | enum nl80211_band band = nla_type(attr); |
| 8225 | |
| 8226 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
| 8227 | err = -EINVAL; |
| 8228 | goto out_free; |
| 8229 | } |
| 8230 | |
| 8231 | if (!wiphy->bands[band]) |
| 8232 | continue; |
| 8233 | |
| 8234 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 8235 | nla_data(attr), |
| 8236 | nla_len(attr), |
| 8237 | &request->rates[band]); |
| 8238 | if (err) |
| 8239 | goto out_free; |
| 8240 | } |
| 8241 | } |
| 8242 | |
| 8243 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 8244 | if (!wiphy_ext_feature_isset(wiphy, |
| 8245 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 8246 | err = -EOPNOTSUPP; |
| 8247 | goto out_free; |
| 8248 | } |
| 8249 | |
| 8250 | request->duration = |
| 8251 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 8252 | request->duration_mandatory = |
| 8253 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 8254 | } |
| 8255 | |
| 8256 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 8257 | false); |
| 8258 | if (err) |
| 8259 | goto out_free; |
| 8260 | |
| 8261 | request->no_cck = |
| 8262 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 8263 | |
| 8264 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 8265 | * BSSID to scan for. This was problematic because that same attribute |
| 8266 | * was already used for another purpose (local random MAC address). The |
| 8267 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 8268 | * compatibility with older userspace components, also use the |
| 8269 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 8270 | * the specific BSSID use case instead of the random MAC address |
| 8271 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 8272 | */ |
| 8273 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 8274 | memcpy(request->bssid, |
| 8275 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 8276 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 8277 | info->attrs[NL80211_ATTR_MAC]) |
| 8278 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 8279 | ETH_ALEN); |
| 8280 | else |
| 8281 | eth_broadcast_addr(request->bssid); |
| 8282 | |
| 8283 | request->wdev = wdev; |
| 8284 | request->wiphy = &rdev->wiphy; |
| 8285 | request->scan_start = jiffies; |
| 8286 | |
| 8287 | rdev->scan_req = request; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8288 | err = cfg80211_scan(rdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8289 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8290 | if (err) |
| 8291 | goto out_free; |
| 8292 | |
| 8293 | nl80211_send_scan_start(rdev, wdev); |
| 8294 | if (wdev->netdev) |
| 8295 | dev_hold(wdev->netdev); |
| 8296 | |
| 8297 | return 0; |
| 8298 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8299 | out_free: |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8300 | rdev->scan_req = NULL; |
| 8301 | kfree(request); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8302 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8303 | return err; |
| 8304 | } |
| 8305 | |
| 8306 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 8307 | { |
| 8308 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8309 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8310 | |
| 8311 | if (!rdev->ops->abort_scan) |
| 8312 | return -EOPNOTSUPP; |
| 8313 | |
| 8314 | if (rdev->scan_msg) |
| 8315 | return 0; |
| 8316 | |
| 8317 | if (!rdev->scan_req) |
| 8318 | return -ENOENT; |
| 8319 | |
| 8320 | rdev_abort_scan(rdev, wdev); |
| 8321 | return 0; |
| 8322 | } |
| 8323 | |
| 8324 | static int |
| 8325 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 8326 | struct cfg80211_sched_scan_request *request, |
| 8327 | struct nlattr **attrs) |
| 8328 | { |
| 8329 | int tmp, err, i = 0; |
| 8330 | struct nlattr *attr; |
| 8331 | |
| 8332 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8333 | u32 interval; |
| 8334 | |
| 8335 | /* |
| 8336 | * If scan plans are not specified, |
| 8337 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
| 8338 | * case one scan plan will be set with the specified scan |
| 8339 | * interval and infinite number of iterations. |
| 8340 | */ |
| 8341 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 8342 | if (!interval) |
| 8343 | return -EINVAL; |
| 8344 | |
| 8345 | request->scan_plans[0].interval = |
| 8346 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 8347 | if (!request->scan_plans[0].interval) |
| 8348 | return -EINVAL; |
| 8349 | |
| 8350 | if (request->scan_plans[0].interval > |
| 8351 | wiphy->max_sched_scan_plan_interval) |
| 8352 | request->scan_plans[0].interval = |
| 8353 | wiphy->max_sched_scan_plan_interval; |
| 8354 | |
| 8355 | return 0; |
| 8356 | } |
| 8357 | |
| 8358 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 8359 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 8360 | |
| 8361 | if (WARN_ON(i >= n_plans)) |
| 8362 | return -EINVAL; |
| 8363 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8364 | err = nla_parse_nested_deprecated(plan, |
| 8365 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 8366 | attr, nl80211_plan_policy, |
| 8367 | NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8368 | if (err) |
| 8369 | return err; |
| 8370 | |
| 8371 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8372 | return -EINVAL; |
| 8373 | |
| 8374 | request->scan_plans[i].interval = |
| 8375 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8376 | if (!request->scan_plans[i].interval || |
| 8377 | request->scan_plans[i].interval > |
| 8378 | wiphy->max_sched_scan_plan_interval) |
| 8379 | return -EINVAL; |
| 8380 | |
| 8381 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8382 | request->scan_plans[i].iterations = |
| 8383 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8384 | if (!request->scan_plans[i].iterations || |
| 8385 | (request->scan_plans[i].iterations > |
| 8386 | wiphy->max_sched_scan_plan_iterations)) |
| 8387 | return -EINVAL; |
| 8388 | } else if (i < n_plans - 1) { |
| 8389 | /* |
| 8390 | * All scan plans but the last one must specify |
| 8391 | * a finite number of iterations |
| 8392 | */ |
| 8393 | return -EINVAL; |
| 8394 | } |
| 8395 | |
| 8396 | i++; |
| 8397 | } |
| 8398 | |
| 8399 | /* |
| 8400 | * The last scan plan must not specify the number of |
| 8401 | * iterations, it is supposed to run infinitely |
| 8402 | */ |
| 8403 | if (request->scan_plans[n_plans - 1].iterations) |
| 8404 | return -EINVAL; |
| 8405 | |
| 8406 | return 0; |
| 8407 | } |
| 8408 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8409 | static int |
| 8410 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8411 | struct cfg80211_match_set *match_sets, |
| 8412 | struct nlattr *tb_band_rssi, |
| 8413 | s32 rssi_thold) |
| 8414 | { |
| 8415 | struct nlattr *attr; |
| 8416 | int i, tmp, ret = 0; |
| 8417 | |
| 8418 | if (!wiphy_ext_feature_isset(wiphy, |
| 8419 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8420 | if (tb_band_rssi) |
| 8421 | ret = -EOPNOTSUPP; |
| 8422 | else |
| 8423 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8424 | match_sets->per_band_rssi_thold[i] = |
| 8425 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8426 | return ret; |
| 8427 | } |
| 8428 | |
| 8429 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8430 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8431 | |
| 8432 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8433 | enum nl80211_band band = nla_type(attr); |
| 8434 | |
| 8435 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8436 | return -EINVAL; |
| 8437 | |
| 8438 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8439 | } |
| 8440 | |
| 8441 | return 0; |
| 8442 | } |
| 8443 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8444 | static struct cfg80211_sched_scan_request * |
| 8445 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 8446 | struct nlattr **attrs, int max_match_sets) |
| 8447 | { |
| 8448 | struct cfg80211_sched_scan_request *request; |
| 8449 | struct nlattr *attr; |
| 8450 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
| 8451 | enum nl80211_band band; |
| 8452 | size_t ie_len; |
| 8453 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
| 8454 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
| 8455 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8456 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 8457 | n_channels = validate_scan_freqs( |
| 8458 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 8459 | if (!n_channels) |
| 8460 | return ERR_PTR(-EINVAL); |
| 8461 | } else { |
| 8462 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
| 8463 | } |
| 8464 | |
| 8465 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8466 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
| 8467 | tmp) |
| 8468 | n_ssids++; |
| 8469 | |
| 8470 | if (n_ssids > wiphy->max_sched_scan_ssids) |
| 8471 | return ERR_PTR(-EINVAL); |
| 8472 | |
| 8473 | /* |
| 8474 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8475 | * the old implementation, matchsets containing only the RSSI attribute |
| 8476 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8477 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8478 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8479 | * older userspace that treated a matchset with only the RSSI as the |
| 8480 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8481 | */ |
| 8482 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 8483 | nla_for_each_nested(attr, |
| 8484 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 8485 | tmp) { |
| 8486 | struct nlattr *rssi; |
| 8487 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8488 | err = nla_parse_nested_deprecated(tb, |
| 8489 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8490 | attr, |
| 8491 | nl80211_match_policy, |
| 8492 | NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8493 | if (err) |
| 8494 | return ERR_PTR(err); |
| 8495 | |
| 8496 | /* SSID and BSSID are mutually exclusive */ |
| 8497 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8498 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8499 | return ERR_PTR(-EINVAL); |
| 8500 | |
| 8501 | /* add other standalone attributes here */ |
| 8502 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8503 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
| 8504 | n_match_sets++; |
| 8505 | continue; |
| 8506 | } |
| 8507 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8508 | if (rssi) |
| 8509 | default_match_rssi = nla_get_s32(rssi); |
| 8510 | } |
| 8511 | } |
| 8512 | |
| 8513 | /* However, if there's no other matchset, add the RSSI one */ |
| 8514 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8515 | n_match_sets = 1; |
| 8516 | |
| 8517 | if (n_match_sets > max_match_sets) |
| 8518 | return ERR_PTR(-EINVAL); |
| 8519 | |
| 8520 | if (attrs[NL80211_ATTR_IE]) |
| 8521 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
| 8522 | else |
| 8523 | ie_len = 0; |
| 8524 | |
| 8525 | if (ie_len > wiphy->max_sched_scan_ie_len) |
| 8526 | return ERR_PTR(-EINVAL); |
| 8527 | |
| 8528 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8529 | /* |
| 8530 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8531 | * each scan plan already specifies its own interval |
| 8532 | */ |
| 8533 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8534 | return ERR_PTR(-EINVAL); |
| 8535 | |
| 8536 | nla_for_each_nested(attr, |
| 8537 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8538 | n_plans++; |
| 8539 | } else { |
| 8540 | /* |
| 8541 | * The scan interval attribute is kept for backward |
| 8542 | * compatibility. If no scan plans are specified and sched scan |
| 8543 | * interval is specified, one scan plan will be set with this |
| 8544 | * scan interval and infinite number of iterations. |
| 8545 | */ |
| 8546 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8547 | return ERR_PTR(-EINVAL); |
| 8548 | |
| 8549 | n_plans = 1; |
| 8550 | } |
| 8551 | |
| 8552 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8553 | return ERR_PTR(-EINVAL); |
| 8554 | |
| 8555 | if (!wiphy_ext_feature_isset( |
| 8556 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8557 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8558 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8559 | return ERR_PTR(-EINVAL); |
| 8560 | |
| 8561 | request = kzalloc(sizeof(*request) |
| 8562 | + sizeof(*request->ssids) * n_ssids |
| 8563 | + sizeof(*request->match_sets) * n_match_sets |
| 8564 | + sizeof(*request->scan_plans) * n_plans |
| 8565 | + sizeof(*request->channels) * n_channels |
| 8566 | + ie_len, GFP_KERNEL); |
| 8567 | if (!request) |
| 8568 | return ERR_PTR(-ENOMEM); |
| 8569 | |
| 8570 | if (n_ssids) |
| 8571 | request->ssids = (void *)&request->channels[n_channels]; |
| 8572 | request->n_ssids = n_ssids; |
| 8573 | if (ie_len) { |
| 8574 | if (n_ssids) |
| 8575 | request->ie = (void *)(request->ssids + n_ssids); |
| 8576 | else |
| 8577 | request->ie = (void *)(request->channels + n_channels); |
| 8578 | } |
| 8579 | |
| 8580 | if (n_match_sets) { |
| 8581 | if (request->ie) |
| 8582 | request->match_sets = (void *)(request->ie + ie_len); |
| 8583 | else if (n_ssids) |
| 8584 | request->match_sets = |
| 8585 | (void *)(request->ssids + n_ssids); |
| 8586 | else |
| 8587 | request->match_sets = |
| 8588 | (void *)(request->channels + n_channels); |
| 8589 | } |
| 8590 | request->n_match_sets = n_match_sets; |
| 8591 | |
| 8592 | if (n_match_sets) |
| 8593 | request->scan_plans = (void *)(request->match_sets + |
| 8594 | n_match_sets); |
| 8595 | else if (request->ie) |
| 8596 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8597 | else if (n_ssids) |
| 8598 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8599 | else |
| 8600 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8601 | |
| 8602 | request->n_scan_plans = n_plans; |
| 8603 | |
| 8604 | i = 0; |
| 8605 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 8606 | /* user specified, bail out if channel not found */ |
| 8607 | nla_for_each_nested(attr, |
| 8608 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 8609 | tmp) { |
| 8610 | struct ieee80211_channel *chan; |
| 8611 | |
| 8612 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 8613 | |
| 8614 | if (!chan) { |
| 8615 | err = -EINVAL; |
| 8616 | goto out_free; |
| 8617 | } |
| 8618 | |
| 8619 | /* ignore disabled channels */ |
| 8620 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8621 | continue; |
| 8622 | |
| 8623 | request->channels[i] = chan; |
| 8624 | i++; |
| 8625 | } |
| 8626 | } else { |
| 8627 | /* all channels */ |
| 8628 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| 8629 | int j; |
| 8630 | |
| 8631 | if (!wiphy->bands[band]) |
| 8632 | continue; |
| 8633 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8634 | struct ieee80211_channel *chan; |
| 8635 | |
| 8636 | chan = &wiphy->bands[band]->channels[j]; |
| 8637 | |
| 8638 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8639 | continue; |
| 8640 | |
| 8641 | request->channels[i] = chan; |
| 8642 | i++; |
| 8643 | } |
| 8644 | } |
| 8645 | } |
| 8646 | |
| 8647 | if (!i) { |
| 8648 | err = -EINVAL; |
| 8649 | goto out_free; |
| 8650 | } |
| 8651 | |
| 8652 | request->n_channels = i; |
| 8653 | |
| 8654 | i = 0; |
| 8655 | if (n_ssids) { |
| 8656 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
| 8657 | tmp) { |
| 8658 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
| 8659 | err = -EINVAL; |
| 8660 | goto out_free; |
| 8661 | } |
| 8662 | request->ssids[i].ssid_len = nla_len(attr); |
| 8663 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 8664 | nla_len(attr)); |
| 8665 | i++; |
| 8666 | } |
| 8667 | } |
| 8668 | |
| 8669 | i = 0; |
| 8670 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 8671 | nla_for_each_nested(attr, |
| 8672 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 8673 | tmp) { |
| 8674 | struct nlattr *ssid, *bssid, *rssi; |
| 8675 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8676 | err = nla_parse_nested_deprecated(tb, |
| 8677 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8678 | attr, |
| 8679 | nl80211_match_policy, |
| 8680 | NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8681 | if (err) |
| 8682 | goto out_free; |
| 8683 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
| 8684 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8685 | |
| 8686 | if (!ssid && !bssid) { |
| 8687 | i++; |
| 8688 | continue; |
| 8689 | } |
| 8690 | |
| 8691 | if (WARN_ON(i >= n_match_sets)) { |
| 8692 | /* this indicates a programming error, |
| 8693 | * the loop above should have verified |
| 8694 | * things properly |
| 8695 | */ |
| 8696 | err = -EINVAL; |
| 8697 | goto out_free; |
| 8698 | } |
| 8699 | |
| 8700 | if (ssid) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8701 | memcpy(request->match_sets[i].ssid.ssid, |
| 8702 | nla_data(ssid), nla_len(ssid)); |
| 8703 | request->match_sets[i].ssid.ssid_len = |
| 8704 | nla_len(ssid); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8705 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8706 | if (bssid) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8707 | memcpy(request->match_sets[i].bssid, |
| 8708 | nla_data(bssid), ETH_ALEN); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8709 | |
| 8710 | /* special attribute - old implementation w/a */ |
| 8711 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 8712 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8713 | if (rssi) |
| 8714 | request->match_sets[i].rssi_thold = |
| 8715 | nla_get_s32(rssi); |
| 8716 | |
| 8717 | /* Parse per band RSSI attribute */ |
| 8718 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 8719 | &request->match_sets[i], |
| 8720 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 8721 | request->match_sets[i].rssi_thold); |
| 8722 | if (err) |
| 8723 | goto out_free; |
| 8724 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8725 | i++; |
| 8726 | } |
| 8727 | |
| 8728 | /* there was no other matchset, so the RSSI one is alone */ |
| 8729 | if (i == 0 && n_match_sets) |
| 8730 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 8731 | |
| 8732 | request->min_rssi_thold = INT_MAX; |
| 8733 | for (i = 0; i < n_match_sets; i++) |
| 8734 | request->min_rssi_thold = |
| 8735 | min(request->match_sets[i].rssi_thold, |
| 8736 | request->min_rssi_thold); |
| 8737 | } else { |
| 8738 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
| 8739 | } |
| 8740 | |
| 8741 | if (ie_len) { |
| 8742 | request->ie_len = ie_len; |
| 8743 | memcpy((void *)request->ie, |
| 8744 | nla_data(attrs[NL80211_ATTR_IE]), |
| 8745 | request->ie_len); |
| 8746 | } |
| 8747 | |
| 8748 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 8749 | if (err) |
| 8750 | goto out_free; |
| 8751 | |
| 8752 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 8753 | request->delay = |
| 8754 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 8755 | |
| 8756 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 8757 | request->relative_rssi = nla_get_s8( |
| 8758 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 8759 | request->relative_rssi_set = true; |
| 8760 | } |
| 8761 | |
| 8762 | if (request->relative_rssi_set && |
| 8763 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 8764 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 8765 | |
| 8766 | rssi_adjust = nla_data( |
| 8767 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 8768 | request->rssi_adjust.band = rssi_adjust->band; |
| 8769 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 8770 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 8771 | err = -EINVAL; |
| 8772 | goto out_free; |
| 8773 | } |
| 8774 | } |
| 8775 | |
| 8776 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 8777 | if (err) |
| 8778 | goto out_free; |
| 8779 | |
| 8780 | request->scan_start = jiffies; |
| 8781 | |
| 8782 | return request; |
| 8783 | |
| 8784 | out_free: |
| 8785 | kfree(request); |
| 8786 | return ERR_PTR(err); |
| 8787 | } |
| 8788 | |
| 8789 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 8790 | struct genl_info *info) |
| 8791 | { |
| 8792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8793 | struct net_device *dev = info->user_ptr[1]; |
| 8794 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8795 | struct cfg80211_sched_scan_request *sched_scan_req; |
| 8796 | bool want_multi; |
| 8797 | int err; |
| 8798 | |
| 8799 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
| 8800 | return -EOPNOTSUPP; |
| 8801 | |
| 8802 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 8803 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 8804 | if (err) |
| 8805 | return err; |
| 8806 | |
| 8807 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 8808 | info->attrs, |
| 8809 | rdev->wiphy.max_match_sets); |
| 8810 | |
| 8811 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
| 8812 | if (err) |
| 8813 | goto out_err; |
| 8814 | |
| 8815 | /* leave request id zero for legacy request |
| 8816 | * or if driver does not support multi-scheduled scan |
| 8817 | */ |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 8818 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 8819 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8820 | |
| 8821 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
| 8822 | if (err) |
| 8823 | goto out_free; |
| 8824 | |
| 8825 | sched_scan_req->dev = dev; |
| 8826 | sched_scan_req->wiphy = &rdev->wiphy; |
| 8827 | |
| 8828 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 8829 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 8830 | |
| 8831 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
| 8832 | |
| 8833 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
| 8834 | return 0; |
| 8835 | |
| 8836 | out_free: |
| 8837 | kfree(sched_scan_req); |
| 8838 | out_err: |
| 8839 | return err; |
| 8840 | } |
| 8841 | |
| 8842 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 8843 | struct genl_info *info) |
| 8844 | { |
| 8845 | struct cfg80211_sched_scan_request *req; |
| 8846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8847 | u64 cookie; |
| 8848 | |
| 8849 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
| 8850 | return -EOPNOTSUPP; |
| 8851 | |
| 8852 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 8853 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8854 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 8855 | } |
| 8856 | |
| 8857 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 8858 | struct cfg80211_sched_scan_request, |
| 8859 | list); |
| 8860 | if (!req || req->reqid || |
| 8861 | (req->owner_nlportid && |
| 8862 | req->owner_nlportid != info->snd_portid)) |
| 8863 | return -ENOENT; |
| 8864 | |
| 8865 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
| 8866 | } |
| 8867 | |
| 8868 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 8869 | struct genl_info *info) |
| 8870 | { |
| 8871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8872 | struct net_device *dev = info->user_ptr[1]; |
| 8873 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8874 | struct wiphy *wiphy = wdev->wiphy; |
| 8875 | struct cfg80211_chan_def chandef; |
| 8876 | enum nl80211_dfs_regions dfs_region; |
| 8877 | unsigned int cac_time_ms; |
| 8878 | int err; |
| 8879 | |
| 8880 | dfs_region = reg_get_dfs_region(wiphy); |
| 8881 | if (dfs_region == NL80211_DFS_UNSET) |
| 8882 | return -EINVAL; |
| 8883 | |
| 8884 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8885 | if (err) |
| 8886 | return err; |
| 8887 | |
| 8888 | if (netif_carrier_ok(dev)) |
| 8889 | return -EBUSY; |
| 8890 | |
| 8891 | if (wdev->cac_started) |
| 8892 | return -EBUSY; |
| 8893 | |
| 8894 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8895 | if (err < 0) |
| 8896 | return err; |
| 8897 | |
| 8898 | if (err == 0) |
| 8899 | return -EINVAL; |
| 8900 | |
| 8901 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
| 8902 | return -EINVAL; |
| 8903 | |
| 8904 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8905 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8906 | return -EOPNOTSUPP; |
| 8907 | |
| 8908 | if (!rdev->ops->start_radar_detection) |
| 8909 | return -EOPNOTSUPP; |
| 8910 | |
| 8911 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8912 | if (WARN_ON(!cac_time_ms)) |
| 8913 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8914 | |
| 8915 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
| 8916 | if (!err) { |
| 8917 | wdev->chandef = chandef; |
| 8918 | wdev->cac_started = true; |
| 8919 | wdev->cac_start_time = jiffies; |
| 8920 | wdev->cac_time_ms = cac_time_ms; |
| 8921 | } |
| 8922 | return err; |
| 8923 | } |
| 8924 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 8925 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8926 | struct genl_info *info) |
| 8927 | { |
| 8928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8929 | struct net_device *dev = info->user_ptr[1]; |
| 8930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8931 | struct wiphy *wiphy = wdev->wiphy; |
| 8932 | struct cfg80211_chan_def chandef; |
| 8933 | enum nl80211_dfs_regions dfs_region; |
| 8934 | int err; |
| 8935 | |
| 8936 | dfs_region = reg_get_dfs_region(wiphy); |
| 8937 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8938 | GENL_SET_ERR_MSG(info, |
| 8939 | "DFS Region is not set. Unexpected Radar indication"); |
| 8940 | return -EINVAL; |
| 8941 | } |
| 8942 | |
| 8943 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8944 | if (err) { |
| 8945 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8946 | return err; |
| 8947 | } |
| 8948 | |
| 8949 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8950 | if (err < 0) { |
| 8951 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8952 | return err; |
| 8953 | } |
| 8954 | |
| 8955 | if (err == 0) { |
| 8956 | GENL_SET_ERR_MSG(info, |
| 8957 | "Unexpected Radar indication for chandef/iftype"); |
| 8958 | return -EINVAL; |
| 8959 | } |
| 8960 | |
| 8961 | /* Do not process this notification if radar is already detected |
| 8962 | * by kernel on this channel, and return success. |
| 8963 | */ |
| 8964 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8965 | return 0; |
| 8966 | |
| 8967 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8968 | |
| 8969 | cfg80211_sched_dfs_chan_update(rdev); |
| 8970 | |
| 8971 | rdev->radar_chandef = chandef; |
| 8972 | |
| 8973 | /* Propagate this notification to other radios as well */ |
| 8974 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8975 | |
| 8976 | return 0; |
| 8977 | } |
| 8978 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8979 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8980 | { |
| 8981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8982 | struct net_device *dev = info->user_ptr[1]; |
| 8983 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8984 | struct cfg80211_csa_settings params; |
| 8985 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8986 | * function is called under RTNL lock, so this should not be a problem. |
| 8987 | */ |
| 8988 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 8989 | int err; |
| 8990 | bool need_new_beacon = false; |
| 8991 | bool need_handle_dfs_flag = true; |
| 8992 | int len, i; |
| 8993 | u32 cs_count; |
| 8994 | |
| 8995 | if (!rdev->ops->channel_switch || |
| 8996 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8997 | return -EOPNOTSUPP; |
| 8998 | |
| 8999 | switch (dev->ieee80211_ptr->iftype) { |
| 9000 | case NL80211_IFTYPE_AP: |
| 9001 | case NL80211_IFTYPE_P2P_GO: |
| 9002 | need_new_beacon = true; |
| 9003 | /* For all modes except AP the handle_dfs flag needs to be |
| 9004 | * supplied to tell the kernel that userspace will handle radar |
| 9005 | * events when they happen. Otherwise a switch to a channel |
| 9006 | * requiring DFS will be rejected. |
| 9007 | */ |
| 9008 | need_handle_dfs_flag = false; |
| 9009 | |
| 9010 | /* useless if AP is not running */ |
| 9011 | if (!wdev->beacon_interval) |
| 9012 | return -ENOTCONN; |
| 9013 | break; |
| 9014 | case NL80211_IFTYPE_ADHOC: |
| 9015 | if (!wdev->ssid_len) |
| 9016 | return -ENOTCONN; |
| 9017 | break; |
| 9018 | case NL80211_IFTYPE_MESH_POINT: |
| 9019 | if (!wdev->mesh_id_len) |
| 9020 | return -ENOTCONN; |
| 9021 | break; |
| 9022 | default: |
| 9023 | return -EOPNOTSUPP; |
| 9024 | } |
| 9025 | |
| 9026 | memset(¶ms, 0, sizeof(params)); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9027 | params.beacon_csa.ftm_responder = -1; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9028 | |
| 9029 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9030 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 9031 | return -EINVAL; |
| 9032 | |
| 9033 | /* only important for AP, IBSS and mesh create IEs internally */ |
| 9034 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
| 9035 | return -EINVAL; |
| 9036 | |
| 9037 | /* Even though the attribute is u32, the specification says |
| 9038 | * u8, so let's make sure we don't overflow. |
| 9039 | */ |
| 9040 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 9041 | if (cs_count > 255) |
| 9042 | return -EINVAL; |
| 9043 | |
| 9044 | params.count = cs_count; |
| 9045 | |
| 9046 | if (!need_new_beacon) |
| 9047 | goto skip_beacons; |
| 9048 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9049 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9050 | if (err) |
| 9051 | return err; |
| 9052 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9053 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 9054 | info->attrs[NL80211_ATTR_CSA_IES], |
| 9055 | nl80211_policy, info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9056 | if (err) |
| 9057 | return err; |
| 9058 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9059 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9060 | if (err) |
| 9061 | return err; |
| 9062 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9063 | if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9064 | return -EINVAL; |
| 9065 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9066 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9067 | if (!len || (len % sizeof(u16))) |
| 9068 | return -EINVAL; |
| 9069 | |
| 9070 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 9071 | if (rdev->wiphy.max_num_csa_counters && |
| 9072 | (params.n_counter_offsets_beacon > |
| 9073 | rdev->wiphy.max_num_csa_counters)) |
| 9074 | return -EINVAL; |
| 9075 | |
| 9076 | params.counter_offsets_beacon = |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9077 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9078 | |
| 9079 | /* sanity checks - counters should fit and be the same */ |
| 9080 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 9081 | u16 offset = params.counter_offsets_beacon[i]; |
| 9082 | |
| 9083 | if (offset >= params.beacon_csa.tail_len) |
| 9084 | return -EINVAL; |
| 9085 | |
| 9086 | if (params.beacon_csa.tail[offset] != params.count) |
| 9087 | return -EINVAL; |
| 9088 | } |
| 9089 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9090 | if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
| 9091 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9092 | if (!len || (len % sizeof(u16))) |
| 9093 | return -EINVAL; |
| 9094 | |
| 9095 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 9096 | if (rdev->wiphy.max_num_csa_counters && |
| 9097 | (params.n_counter_offsets_presp > |
| 9098 | rdev->wiphy.max_num_csa_counters)) |
| 9099 | return -EINVAL; |
| 9100 | |
| 9101 | params.counter_offsets_presp = |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9102 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9103 | |
| 9104 | /* sanity checks - counters should fit and be the same */ |
| 9105 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 9106 | u16 offset = params.counter_offsets_presp[i]; |
| 9107 | |
| 9108 | if (offset >= params.beacon_csa.probe_resp_len) |
| 9109 | return -EINVAL; |
| 9110 | |
| 9111 | if (params.beacon_csa.probe_resp[offset] != |
| 9112 | params.count) |
| 9113 | return -EINVAL; |
| 9114 | } |
| 9115 | } |
| 9116 | |
| 9117 | skip_beacons: |
| 9118 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 9119 | if (err) |
| 9120 | return err; |
| 9121 | |
| 9122 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 9123 | wdev->iftype)) |
| 9124 | return -EINVAL; |
| 9125 | |
| 9126 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 9127 | ¶ms.chandef, |
| 9128 | wdev->iftype); |
| 9129 | if (err < 0) |
| 9130 | return err; |
| 9131 | |
| 9132 | if (err > 0) { |
| 9133 | params.radar_required = true; |
| 9134 | if (need_handle_dfs_flag && |
| 9135 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 9136 | return -EINVAL; |
| 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 9141 | params.block_tx = true; |
| 9142 | |
| 9143 | wdev_lock(wdev); |
| 9144 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 9145 | wdev_unlock(wdev); |
| 9146 | |
| 9147 | return err; |
| 9148 | } |
| 9149 | |
| 9150 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 9151 | u32 seq, int flags, |
| 9152 | struct cfg80211_registered_device *rdev, |
| 9153 | struct wireless_dev *wdev, |
| 9154 | struct cfg80211_internal_bss *intbss) |
| 9155 | { |
| 9156 | struct cfg80211_bss *res = &intbss->pub; |
| 9157 | const struct cfg80211_bss_ies *ies; |
| 9158 | void *hdr; |
| 9159 | struct nlattr *bss; |
| 9160 | |
| 9161 | ASSERT_WDEV_LOCK(wdev); |
| 9162 | |
| 9163 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 9164 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 9165 | if (!hdr) |
| 9166 | return -1; |
| 9167 | |
| 9168 | genl_dump_check_consistent(cb, hdr); |
| 9169 | |
| 9170 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 9171 | goto nla_put_failure; |
| 9172 | if (wdev->netdev && |
| 9173 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 9174 | goto nla_put_failure; |
| 9175 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 9176 | NL80211_ATTR_PAD)) |
| 9177 | goto nla_put_failure; |
| 9178 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9179 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9180 | if (!bss) |
| 9181 | goto nla_put_failure; |
| 9182 | if ((!is_zero_ether_addr(res->bssid) && |
| 9183 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
| 9184 | goto nla_put_failure; |
| 9185 | |
| 9186 | rcu_read_lock(); |
| 9187 | /* indicate whether we have probe response data or not */ |
| 9188 | if (rcu_access_pointer(res->proberesp_ies) && |
| 9189 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 9190 | goto fail_unlock_rcu; |
| 9191 | |
| 9192 | /* this pointer prefers to be pointed to probe response data |
| 9193 | * but is always valid |
| 9194 | */ |
| 9195 | ies = rcu_dereference(res->ies); |
| 9196 | if (ies) { |
| 9197 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 9198 | NL80211_BSS_PAD)) |
| 9199 | goto fail_unlock_rcu; |
| 9200 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 9201 | ies->len, ies->data)) |
| 9202 | goto fail_unlock_rcu; |
| 9203 | } |
| 9204 | |
| 9205 | /* and this pointer is always (unless driver didn't know) beacon data */ |
| 9206 | ies = rcu_dereference(res->beacon_ies); |
| 9207 | if (ies && ies->from_beacon) { |
| 9208 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 9209 | NL80211_BSS_PAD)) |
| 9210 | goto fail_unlock_rcu; |
| 9211 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 9212 | ies->len, ies->data)) |
| 9213 | goto fail_unlock_rcu; |
| 9214 | } |
| 9215 | rcu_read_unlock(); |
| 9216 | |
| 9217 | if (res->beacon_interval && |
| 9218 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 9219 | goto nla_put_failure; |
| 9220 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 9221 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9222 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
| 9223 | res->channel->freq_offset) || |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9224 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
| 9225 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 9226 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 9227 | goto nla_put_failure; |
| 9228 | |
| 9229 | if (intbss->parent_tsf && |
| 9230 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 9231 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 9232 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 9233 | intbss->parent_bssid))) |
| 9234 | goto nla_put_failure; |
| 9235 | |
| 9236 | if (intbss->ts_boottime && |
| 9237 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 9238 | intbss->ts_boottime, NL80211_BSS_PAD)) |
| 9239 | goto nla_put_failure; |
| 9240 | |
| 9241 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 9242 | intbss->pub.chain_signal, |
| 9243 | NL80211_BSS_CHAIN_SIGNAL)) |
| 9244 | goto nla_put_failure; |
| 9245 | |
| 9246 | switch (rdev->wiphy.signal_type) { |
| 9247 | case CFG80211_SIGNAL_TYPE_MBM: |
| 9248 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 9249 | goto nla_put_failure; |
| 9250 | break; |
| 9251 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 9252 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 9253 | goto nla_put_failure; |
| 9254 | break; |
| 9255 | default: |
| 9256 | break; |
| 9257 | } |
| 9258 | |
| 9259 | switch (wdev->iftype) { |
| 9260 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9261 | case NL80211_IFTYPE_STATION: |
| 9262 | if (intbss == wdev->current_bss && |
| 9263 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9264 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 9265 | goto nla_put_failure; |
| 9266 | break; |
| 9267 | case NL80211_IFTYPE_ADHOC: |
| 9268 | if (intbss == wdev->current_bss && |
| 9269 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9270 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 9271 | goto nla_put_failure; |
| 9272 | break; |
| 9273 | default: |
| 9274 | break; |
| 9275 | } |
| 9276 | |
| 9277 | nla_nest_end(msg, bss); |
| 9278 | |
| 9279 | genlmsg_end(msg, hdr); |
| 9280 | return 0; |
| 9281 | |
| 9282 | fail_unlock_rcu: |
| 9283 | rcu_read_unlock(); |
| 9284 | nla_put_failure: |
| 9285 | genlmsg_cancel(msg, hdr); |
| 9286 | return -EMSGSIZE; |
| 9287 | } |
| 9288 | |
| 9289 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
| 9290 | { |
| 9291 | struct cfg80211_registered_device *rdev; |
| 9292 | struct cfg80211_internal_bss *scan; |
| 9293 | struct wireless_dev *wdev; |
| 9294 | int start = cb->args[2], idx = 0; |
| 9295 | int err; |
| 9296 | |
| 9297 | rtnl_lock(); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9298 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9299 | if (err) { |
| 9300 | rtnl_unlock(); |
| 9301 | return err; |
| 9302 | } |
| 9303 | |
| 9304 | wdev_lock(wdev); |
| 9305 | spin_lock_bh(&rdev->bss_lock); |
| 9306 | |
| 9307 | /* |
| 9308 | * dump_scan will be called multiple times to break up the scan results |
| 9309 | * into multiple messages. It is unlikely that any more bss-es will be |
| 9310 | * expired after the first call, so only call only call this on the |
| 9311 | * first dump_scan invocation. |
| 9312 | */ |
| 9313 | if (start == 0) |
| 9314 | cfg80211_bss_expire(rdev); |
| 9315 | |
| 9316 | cb->seq = rdev->bss_generation; |
| 9317 | |
| 9318 | list_for_each_entry(scan, &rdev->bss_list, list) { |
| 9319 | if (++idx <= start) |
| 9320 | continue; |
| 9321 | if (nl80211_send_bss(skb, cb, |
| 9322 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 9323 | rdev, wdev, scan) < 0) { |
| 9324 | idx--; |
| 9325 | break; |
| 9326 | } |
| 9327 | } |
| 9328 | |
| 9329 | spin_unlock_bh(&rdev->bss_lock); |
| 9330 | wdev_unlock(wdev); |
| 9331 | |
| 9332 | cb->args[2] = idx; |
| 9333 | rtnl_unlock(); |
| 9334 | |
| 9335 | return skb->len; |
| 9336 | } |
| 9337 | |
| 9338 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
| 9339 | int flags, struct net_device *dev, |
| 9340 | bool allow_radio_stats, |
| 9341 | struct survey_info *survey) |
| 9342 | { |
| 9343 | void *hdr; |
| 9344 | struct nlattr *infoattr; |
| 9345 | |
| 9346 | /* skip radio stats if userspace didn't request them */ |
| 9347 | if (!survey->channel && !allow_radio_stats) |
| 9348 | return 0; |
| 9349 | |
| 9350 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
| 9351 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 9352 | if (!hdr) |
| 9353 | return -ENOMEM; |
| 9354 | |
| 9355 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 9356 | goto nla_put_failure; |
| 9357 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9358 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9359 | if (!infoattr) |
| 9360 | goto nla_put_failure; |
| 9361 | |
| 9362 | if (survey->channel && |
| 9363 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 9364 | survey->channel->center_freq)) |
| 9365 | goto nla_put_failure; |
| 9366 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9367 | if (survey->channel && survey->channel->freq_offset && |
| 9368 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, |
| 9369 | survey->channel->freq_offset)) |
| 9370 | goto nla_put_failure; |
| 9371 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9372 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9373 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9374 | goto nla_put_failure; |
| 9375 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9376 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9377 | goto nla_put_failure; |
| 9378 | if ((survey->filled & SURVEY_INFO_TIME) && |
| 9379 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9380 | survey->time, NL80211_SURVEY_INFO_PAD)) |
| 9381 | goto nla_put_failure; |
| 9382 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
| 9383 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9384 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
| 9385 | goto nla_put_failure; |
| 9386 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
| 9387 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9388 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
| 9389 | goto nla_put_failure; |
| 9390 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
| 9391 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9392 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
| 9393 | goto nla_put_failure; |
| 9394 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
| 9395 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9396 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
| 9397 | goto nla_put_failure; |
| 9398 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
| 9399 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9400 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
| 9401 | goto nla_put_failure; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9402 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9403 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9404 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9405 | goto nla_put_failure; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9406 | |
| 9407 | nla_nest_end(msg, infoattr); |
| 9408 | |
| 9409 | genlmsg_end(msg, hdr); |
| 9410 | return 0; |
| 9411 | |
| 9412 | nla_put_failure: |
| 9413 | genlmsg_cancel(msg, hdr); |
| 9414 | return -EMSGSIZE; |
| 9415 | } |
| 9416 | |
| 9417 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
| 9418 | { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9419 | struct nlattr **attrbuf; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9420 | struct survey_info survey; |
| 9421 | struct cfg80211_registered_device *rdev; |
| 9422 | struct wireless_dev *wdev; |
| 9423 | int survey_idx = cb->args[2]; |
| 9424 | int res; |
| 9425 | bool radio_stats; |
| 9426 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9427 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9428 | if (!attrbuf) |
| 9429 | return -ENOMEM; |
| 9430 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9431 | rtnl_lock(); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9432 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9433 | if (res) |
| 9434 | goto out_err; |
| 9435 | |
| 9436 | /* prepare_wdev_dump parsed the attributes */ |
| 9437 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
| 9438 | |
| 9439 | if (!wdev->netdev) { |
| 9440 | res = -EINVAL; |
| 9441 | goto out_err; |
| 9442 | } |
| 9443 | |
| 9444 | if (!rdev->ops->dump_survey) { |
| 9445 | res = -EOPNOTSUPP; |
| 9446 | goto out_err; |
| 9447 | } |
| 9448 | |
| 9449 | while (1) { |
| 9450 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
| 9451 | if (res == -ENOENT) |
| 9452 | break; |
| 9453 | if (res) |
| 9454 | goto out_err; |
| 9455 | |
| 9456 | /* don't send disabled channels, but do send non-channel data */ |
| 9457 | if (survey.channel && |
| 9458 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 9459 | survey_idx++; |
| 9460 | continue; |
| 9461 | } |
| 9462 | |
| 9463 | if (nl80211_send_survey(skb, |
| 9464 | NETLINK_CB(cb->skb).portid, |
| 9465 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 9466 | wdev->netdev, radio_stats, &survey) < 0) |
| 9467 | goto out; |
| 9468 | survey_idx++; |
| 9469 | } |
| 9470 | |
| 9471 | out: |
| 9472 | cb->args[2] = survey_idx; |
| 9473 | res = skb->len; |
| 9474 | out_err: |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9475 | kfree(attrbuf); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9476 | rtnl_unlock(); |
| 9477 | return res; |
| 9478 | } |
| 9479 | |
| 9480 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9481 | { |
| 9482 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9483 | NL80211_WPA_VERSION_2 | |
| 9484 | NL80211_WPA_VERSION_3)); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9485 | } |
| 9486 | |
| 9487 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9488 | { |
| 9489 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9490 | struct net_device *dev = info->user_ptr[1]; |
| 9491 | struct ieee80211_channel *chan; |
| 9492 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9493 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
| 9494 | enum nl80211_auth_type auth_type; |
| 9495 | struct key_parse key; |
| 9496 | bool local_state_change; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9497 | u32 freq; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9498 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9499 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9500 | return -EINVAL; |
| 9501 | |
| 9502 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9503 | return -EINVAL; |
| 9504 | |
| 9505 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9506 | return -EINVAL; |
| 9507 | |
| 9508 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9509 | return -EINVAL; |
| 9510 | |
| 9511 | err = nl80211_parse_key(info, &key); |
| 9512 | if (err) |
| 9513 | return err; |
| 9514 | |
| 9515 | if (key.idx >= 0) { |
| 9516 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9517 | return -EINVAL; |
| 9518 | if (!key.p.key || !key.p.key_len) |
| 9519 | return -EINVAL; |
| 9520 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9521 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9522 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9523 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9524 | return -EINVAL; |
| 9525 | if (key.idx > 3) |
| 9526 | return -EINVAL; |
| 9527 | } else { |
| 9528 | key.p.key_len = 0; |
| 9529 | key.p.key = NULL; |
| 9530 | } |
| 9531 | |
| 9532 | if (key.idx >= 0) { |
| 9533 | int i; |
| 9534 | bool ok = false; |
| 9535 | |
| 9536 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9537 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9538 | ok = true; |
| 9539 | break; |
| 9540 | } |
| 9541 | } |
| 9542 | if (!ok) |
| 9543 | return -EINVAL; |
| 9544 | } |
| 9545 | |
| 9546 | if (!rdev->ops->auth) |
| 9547 | return -EOPNOTSUPP; |
| 9548 | |
| 9549 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 9550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9551 | return -EOPNOTSUPP; |
| 9552 | |
| 9553 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9554 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9555 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9556 | freq += |
| 9557 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9558 | |
| 9559 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9560 | if (!chan) |
| 9561 | return -EINVAL; |
| 9562 | |
| 9563 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9564 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9565 | |
| 9566 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9567 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9568 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9569 | } |
| 9570 | |
| 9571 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 9572 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
| 9573 | return -EINVAL; |
| 9574 | |
| 9575 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 9576 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 9577 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 9578 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
| 9579 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
| 9580 | return -EINVAL; |
| 9581 | |
| 9582 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
| 9583 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 9584 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 9585 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 9586 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
| 9587 | return -EINVAL; |
| 9588 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 9589 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9590 | } |
| 9591 | |
| 9592 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9593 | |
| 9594 | /* |
| 9595 | * Since we no longer track auth state, ignore |
| 9596 | * requests to only change local state. |
| 9597 | */ |
| 9598 | if (local_state_change) |
| 9599 | return 0; |
| 9600 | |
| 9601 | wdev_lock(dev->ieee80211_ptr); |
| 9602 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 9603 | ssid, ssid_len, ie, ie_len, |
| 9604 | key.p.key, key.p.key_len, key.idx, |
| 9605 | auth_data, auth_data_len); |
| 9606 | wdev_unlock(dev->ieee80211_ptr); |
| 9607 | return err; |
| 9608 | } |
| 9609 | |
| 9610 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 9611 | struct genl_info *info) |
| 9612 | { |
| 9613 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9614 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 9615 | return -EINVAL; |
| 9616 | } |
| 9617 | |
| 9618 | if (!rdev->ops->tx_control_port || |
| 9619 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9620 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 9621 | return -EOPNOTSUPP; |
| 9622 | |
| 9623 | return 0; |
| 9624 | } |
| 9625 | |
| 9626 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 9627 | struct genl_info *info, |
| 9628 | struct cfg80211_crypto_settings *settings, |
| 9629 | int cipher_limit) |
| 9630 | { |
| 9631 | memset(settings, 0, sizeof(*settings)); |
| 9632 | |
| 9633 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 9634 | |
| 9635 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 9636 | u16 proto; |
| 9637 | |
| 9638 | proto = nla_get_u16( |
| 9639 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 9640 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 9641 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 9642 | proto != ETH_P_PAE) |
| 9643 | return -EINVAL; |
| 9644 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 9645 | settings->control_port_no_encrypt = true; |
| 9646 | } else |
| 9647 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 9648 | |
| 9649 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9650 | int r = validate_pae_over_nl80211(rdev, info); |
| 9651 | |
| 9652 | if (r < 0) |
| 9653 | return r; |
| 9654 | |
| 9655 | settings->control_port_over_nl80211 = true; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9656 | |
| 9657 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) |
| 9658 | settings->control_port_no_preauth = true; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9659 | } |
| 9660 | |
| 9661 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 9662 | void *data; |
| 9663 | int len, i; |
| 9664 | |
| 9665 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9666 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9667 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 9668 | |
| 9669 | if (len % sizeof(u32)) |
| 9670 | return -EINVAL; |
| 9671 | |
| 9672 | if (settings->n_ciphers_pairwise > cipher_limit) |
| 9673 | return -EINVAL; |
| 9674 | |
| 9675 | memcpy(settings->ciphers_pairwise, data, len); |
| 9676 | |
| 9677 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 9678 | if (!cfg80211_supported_cipher_suite( |
| 9679 | &rdev->wiphy, |
| 9680 | settings->ciphers_pairwise[i])) |
| 9681 | return -EINVAL; |
| 9682 | } |
| 9683 | |
| 9684 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 9685 | settings->cipher_group = |
| 9686 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 9687 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 9688 | settings->cipher_group)) |
| 9689 | return -EINVAL; |
| 9690 | } |
| 9691 | |
| 9692 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 9693 | settings->wpa_versions = |
| 9694 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 9695 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 9696 | return -EINVAL; |
| 9697 | } |
| 9698 | |
| 9699 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 9700 | void *data; |
| 9701 | int len; |
| 9702 | |
| 9703 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9704 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9705 | settings->n_akm_suites = len / sizeof(u32); |
| 9706 | |
| 9707 | if (len % sizeof(u32)) |
| 9708 | return -EINVAL; |
| 9709 | |
| 9710 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 9711 | return -EINVAL; |
| 9712 | |
| 9713 | memcpy(settings->akm_suites, data, len); |
| 9714 | } |
| 9715 | |
| 9716 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9717 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 9718 | return -EINVAL; |
| 9719 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9720 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
| 9721 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9722 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9723 | return -EINVAL; |
| 9724 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9725 | } |
| 9726 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9727 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 9728 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9729 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
| 9730 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9731 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9732 | return -EINVAL; |
| 9733 | settings->sae_pwd = |
| 9734 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9735 | settings->sae_pwd_len = |
| 9736 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9737 | } |
| 9738 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9739 | return 0; |
| 9740 | } |
| 9741 | |
| 9742 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 9743 | { |
| 9744 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9745 | struct net_device *dev = info->user_ptr[1]; |
| 9746 | struct ieee80211_channel *chan; |
| 9747 | struct cfg80211_assoc_request req = {}; |
| 9748 | const u8 *bssid, *ssid; |
| 9749 | int err, ssid_len = 0; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9750 | u32 freq; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9751 | |
| 9752 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9753 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9754 | return -EPERM; |
| 9755 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9756 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 9757 | !info->attrs[NL80211_ATTR_SSID] || |
| 9758 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9759 | return -EINVAL; |
| 9760 | |
| 9761 | if (!rdev->ops->assoc) |
| 9762 | return -EOPNOTSUPP; |
| 9763 | |
| 9764 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 9765 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9766 | return -EOPNOTSUPP; |
| 9767 | |
| 9768 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9769 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9770 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9771 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9772 | freq += |
| 9773 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9774 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9775 | if (!chan) |
| 9776 | return -EINVAL; |
| 9777 | |
| 9778 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9779 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9780 | |
| 9781 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9782 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9783 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9784 | } |
| 9785 | |
| 9786 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 9787 | enum nl80211_mfp mfp = |
| 9788 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 9789 | if (mfp == NL80211_MFP_REQUIRED) |
| 9790 | req.use_mfp = true; |
| 9791 | else if (mfp != NL80211_MFP_NO) |
| 9792 | return -EINVAL; |
| 9793 | } |
| 9794 | |
| 9795 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 9796 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 9797 | |
| 9798 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 9799 | req.flags |= ASSOC_REQ_DISABLE_HT; |
| 9800 | |
| 9801 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9802 | memcpy(&req.ht_capa_mask, |
| 9803 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9804 | sizeof(req.ht_capa_mask)); |
| 9805 | |
| 9806 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 9807 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9808 | return -EINVAL; |
| 9809 | memcpy(&req.ht_capa, |
| 9810 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9811 | sizeof(req.ht_capa)); |
| 9812 | } |
| 9813 | |
| 9814 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 9815 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
| 9816 | |
| 9817 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9818 | memcpy(&req.vht_capa_mask, |
| 9819 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9820 | sizeof(req.vht_capa_mask)); |
| 9821 | |
| 9822 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 9823 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 9824 | return -EINVAL; |
| 9825 | memcpy(&req.vht_capa, |
| 9826 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9827 | sizeof(req.vht_capa)); |
| 9828 | } |
| 9829 | |
| 9830 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 9831 | if (!((rdev->wiphy.features & |
| 9832 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9833 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9834 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9835 | NL80211_EXT_FEATURE_RRM)) |
| 9836 | return -EINVAL; |
| 9837 | req.flags |= ASSOC_REQ_USE_RRM; |
| 9838 | } |
| 9839 | |
| 9840 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 9841 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9842 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9843 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 9844 | return -EINVAL; |
| 9845 | req.fils_nonces = |
| 9846 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 9847 | } |
| 9848 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 9849 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { |
| 9850 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) |
| 9851 | return -EINVAL; |
| 9852 | memcpy(&req.s1g_capa_mask, |
| 9853 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), |
| 9854 | sizeof(req.s1g_capa_mask)); |
| 9855 | } |
| 9856 | |
| 9857 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { |
| 9858 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) |
| 9859 | return -EINVAL; |
| 9860 | memcpy(&req.s1g_capa, |
| 9861 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), |
| 9862 | sizeof(req.s1g_capa)); |
| 9863 | } |
| 9864 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9865 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
| 9866 | if (!err) { |
| 9867 | wdev_lock(dev->ieee80211_ptr); |
| 9868 | |
| 9869 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 9870 | ssid, ssid_len, &req); |
| 9871 | |
| 9872 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9873 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 9874 | info->snd_portid; |
| 9875 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9876 | bssid, ETH_ALEN); |
| 9877 | } |
| 9878 | |
| 9879 | wdev_unlock(dev->ieee80211_ptr); |
| 9880 | } |
| 9881 | |
| 9882 | return err; |
| 9883 | } |
| 9884 | |
| 9885 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 9886 | { |
| 9887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9888 | struct net_device *dev = info->user_ptr[1]; |
| 9889 | const u8 *ie = NULL, *bssid; |
| 9890 | int ie_len = 0, err; |
| 9891 | u16 reason_code; |
| 9892 | bool local_state_change; |
| 9893 | |
| 9894 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9895 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9896 | return -EPERM; |
| 9897 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9898 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9899 | return -EINVAL; |
| 9900 | |
| 9901 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9902 | return -EINVAL; |
| 9903 | |
| 9904 | if (!rdev->ops->deauth) |
| 9905 | return -EOPNOTSUPP; |
| 9906 | |
| 9907 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 9908 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9909 | return -EOPNOTSUPP; |
| 9910 | |
| 9911 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9912 | |
| 9913 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9914 | if (reason_code == 0) { |
| 9915 | /* Reason Code 0 is reserved */ |
| 9916 | return -EINVAL; |
| 9917 | } |
| 9918 | |
| 9919 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9920 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9921 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9922 | } |
| 9923 | |
| 9924 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9925 | |
| 9926 | wdev_lock(dev->ieee80211_ptr); |
| 9927 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9928 | local_state_change); |
| 9929 | wdev_unlock(dev->ieee80211_ptr); |
| 9930 | return err; |
| 9931 | } |
| 9932 | |
| 9933 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 9934 | { |
| 9935 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9936 | struct net_device *dev = info->user_ptr[1]; |
| 9937 | const u8 *ie = NULL, *bssid; |
| 9938 | int ie_len = 0, err; |
| 9939 | u16 reason_code; |
| 9940 | bool local_state_change; |
| 9941 | |
| 9942 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9943 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9944 | return -EPERM; |
| 9945 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 9946 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9947 | return -EINVAL; |
| 9948 | |
| 9949 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9950 | return -EINVAL; |
| 9951 | |
| 9952 | if (!rdev->ops->disassoc) |
| 9953 | return -EOPNOTSUPP; |
| 9954 | |
| 9955 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 9956 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9957 | return -EOPNOTSUPP; |
| 9958 | |
| 9959 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9960 | |
| 9961 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9962 | if (reason_code == 0) { |
| 9963 | /* Reason Code 0 is reserved */ |
| 9964 | return -EINVAL; |
| 9965 | } |
| 9966 | |
| 9967 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9968 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9969 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9970 | } |
| 9971 | |
| 9972 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9973 | |
| 9974 | wdev_lock(dev->ieee80211_ptr); |
| 9975 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9976 | local_state_change); |
| 9977 | wdev_unlock(dev->ieee80211_ptr); |
| 9978 | return err; |
| 9979 | } |
| 9980 | |
| 9981 | static bool |
| 9982 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 9983 | int mcast_rate[NUM_NL80211_BANDS], |
| 9984 | int rateval) |
| 9985 | { |
| 9986 | struct wiphy *wiphy = &rdev->wiphy; |
| 9987 | bool found = false; |
| 9988 | int band, i; |
| 9989 | |
| 9990 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| 9991 | struct ieee80211_supported_band *sband; |
| 9992 | |
| 9993 | sband = wiphy->bands[band]; |
| 9994 | if (!sband) |
| 9995 | continue; |
| 9996 | |
| 9997 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9998 | if (sband->bitrates[i].bitrate == rateval) { |
| 9999 | mcast_rate[band] = i + 1; |
| 10000 | found = true; |
| 10001 | break; |
| 10002 | } |
| 10003 | } |
| 10004 | } |
| 10005 | |
| 10006 | return found; |
| 10007 | } |
| 10008 | |
| 10009 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10010 | { |
| 10011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10012 | struct net_device *dev = info->user_ptr[1]; |
| 10013 | struct cfg80211_ibss_params ibss; |
| 10014 | struct wiphy *wiphy; |
| 10015 | struct cfg80211_cached_keys *connkeys = NULL; |
| 10016 | int err; |
| 10017 | |
| 10018 | memset(&ibss, 0, sizeof(ibss)); |
| 10019 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10020 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10021 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10022 | return -EINVAL; |
| 10023 | |
| 10024 | ibss.beacon_interval = 100; |
| 10025 | |
| 10026 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
| 10027 | ibss.beacon_interval = |
| 10028 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 10029 | |
| 10030 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 10031 | ibss.beacon_interval); |
| 10032 | if (err) |
| 10033 | return err; |
| 10034 | |
| 10035 | if (!rdev->ops->join_ibss) |
| 10036 | return -EOPNOTSUPP; |
| 10037 | |
| 10038 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10039 | return -EOPNOTSUPP; |
| 10040 | |
| 10041 | wiphy = &rdev->wiphy; |
| 10042 | |
| 10043 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10044 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10045 | |
| 10046 | if (!is_valid_ether_addr(ibss.bssid)) |
| 10047 | return -EINVAL; |
| 10048 | } |
| 10049 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10050 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10051 | |
| 10052 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10053 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10054 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10055 | } |
| 10056 | |
| 10057 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 10058 | if (err) |
| 10059 | return err; |
| 10060 | |
| 10061 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 10062 | NL80211_IFTYPE_ADHOC)) |
| 10063 | return -EINVAL; |
| 10064 | |
| 10065 | switch (ibss.chandef.width) { |
| 10066 | case NL80211_CHAN_WIDTH_5: |
| 10067 | case NL80211_CHAN_WIDTH_10: |
| 10068 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 10069 | break; |
| 10070 | case NL80211_CHAN_WIDTH_20: |
| 10071 | case NL80211_CHAN_WIDTH_40: |
| 10072 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10073 | return -EINVAL; |
| 10074 | break; |
| 10075 | case NL80211_CHAN_WIDTH_80: |
| 10076 | case NL80211_CHAN_WIDTH_80P80: |
| 10077 | case NL80211_CHAN_WIDTH_160: |
| 10078 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10079 | return -EINVAL; |
| 10080 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10081 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 10082 | return -EINVAL; |
| 10083 | break; |
| 10084 | default: |
| 10085 | return -EINVAL; |
| 10086 | } |
| 10087 | |
| 10088 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
| 10089 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 10090 | |
| 10091 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10092 | u8 *rates = |
| 10093 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10094 | int n_rates = |
| 10095 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10096 | struct ieee80211_supported_band *sband = |
| 10097 | wiphy->bands[ibss.chandef.chan->band]; |
| 10098 | |
| 10099 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10100 | &ibss.basic_rates); |
| 10101 | if (err) |
| 10102 | return err; |
| 10103 | } |
| 10104 | |
| 10105 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10106 | memcpy(&ibss.ht_capa_mask, |
| 10107 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10108 | sizeof(ibss.ht_capa_mask)); |
| 10109 | |
| 10110 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 10111 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10112 | return -EINVAL; |
| 10113 | memcpy(&ibss.ht_capa, |
| 10114 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10115 | sizeof(ibss.ht_capa)); |
| 10116 | } |
| 10117 | |
| 10118 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10119 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 10120 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10121 | return -EINVAL; |
| 10122 | |
| 10123 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 10124 | bool no_ht = false; |
| 10125 | |
| 10126 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
| 10127 | if (IS_ERR(connkeys)) |
| 10128 | return PTR_ERR(connkeys); |
| 10129 | |
| 10130 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 10131 | no_ht) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10132 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10133 | return -EINVAL; |
| 10134 | } |
| 10135 | } |
| 10136 | |
| 10137 | ibss.control_port = |
| 10138 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 10139 | |
| 10140 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10141 | int r = validate_pae_over_nl80211(rdev, info); |
| 10142 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10143 | if (r < 0) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10144 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10145 | return r; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10146 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10147 | |
| 10148 | ibss.control_port_over_nl80211 = true; |
| 10149 | } |
| 10150 | |
| 10151 | ibss.userspace_handles_dfs = |
| 10152 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10153 | |
| 10154 | wdev_lock(dev->ieee80211_ptr); |
| 10155 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
| 10156 | if (err) |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10157 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10158 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10159 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10160 | wdev_unlock(dev->ieee80211_ptr); |
| 10161 | |
| 10162 | return err; |
| 10163 | } |
| 10164 | |
| 10165 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10166 | { |
| 10167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10168 | struct net_device *dev = info->user_ptr[1]; |
| 10169 | |
| 10170 | if (!rdev->ops->leave_ibss) |
| 10171 | return -EOPNOTSUPP; |
| 10172 | |
| 10173 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10174 | return -EOPNOTSUPP; |
| 10175 | |
| 10176 | return cfg80211_leave_ibss(rdev, dev, false); |
| 10177 | } |
| 10178 | |
| 10179 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 10180 | { |
| 10181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10182 | struct net_device *dev = info->user_ptr[1]; |
| 10183 | int mcast_rate[NUM_NL80211_BANDS]; |
| 10184 | u32 nla_rate; |
| 10185 | int err; |
| 10186 | |
| 10187 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 10188 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 10189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
| 10190 | return -EOPNOTSUPP; |
| 10191 | |
| 10192 | if (!rdev->ops->set_mcast_rate) |
| 10193 | return -EOPNOTSUPP; |
| 10194 | |
| 10195 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 10196 | |
| 10197 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 10198 | return -EINVAL; |
| 10199 | |
| 10200 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 10201 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 10202 | return -EINVAL; |
| 10203 | |
| 10204 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
| 10205 | |
| 10206 | return err; |
| 10207 | } |
| 10208 | |
| 10209 | static struct sk_buff * |
| 10210 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 10211 | struct wireless_dev *wdev, int approxlen, |
| 10212 | u32 portid, u32 seq, enum nl80211_commands cmd, |
| 10213 | enum nl80211_attrs attr, |
| 10214 | const struct nl80211_vendor_cmd_info *info, |
| 10215 | gfp_t gfp) |
| 10216 | { |
| 10217 | struct sk_buff *skb; |
| 10218 | void *hdr; |
| 10219 | struct nlattr *data; |
| 10220 | |
| 10221 | skb = nlmsg_new(approxlen + 100, gfp); |
| 10222 | if (!skb) |
| 10223 | return NULL; |
| 10224 | |
| 10225 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 10226 | if (!hdr) { |
| 10227 | kfree_skb(skb); |
| 10228 | return NULL; |
| 10229 | } |
| 10230 | |
| 10231 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10232 | goto nla_put_failure; |
| 10233 | |
| 10234 | if (info) { |
| 10235 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 10236 | info->vendor_id)) |
| 10237 | goto nla_put_failure; |
| 10238 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 10239 | info->subcmd)) |
| 10240 | goto nla_put_failure; |
| 10241 | } |
| 10242 | |
| 10243 | if (wdev) { |
| 10244 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10245 | wdev_id(wdev), NL80211_ATTR_PAD)) |
| 10246 | goto nla_put_failure; |
| 10247 | if (wdev->netdev && |
| 10248 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 10249 | wdev->netdev->ifindex)) |
| 10250 | goto nla_put_failure; |
| 10251 | } |
| 10252 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10253 | data = nla_nest_start_noflag(skb, attr); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10254 | if (!data) |
| 10255 | goto nla_put_failure; |
| 10256 | |
| 10257 | ((void **)skb->cb)[0] = rdev; |
| 10258 | ((void **)skb->cb)[1] = hdr; |
| 10259 | ((void **)skb->cb)[2] = data; |
| 10260 | |
| 10261 | return skb; |
| 10262 | |
| 10263 | nla_put_failure: |
| 10264 | kfree_skb(skb); |
| 10265 | return NULL; |
| 10266 | } |
| 10267 | |
| 10268 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 10269 | struct wireless_dev *wdev, |
| 10270 | enum nl80211_commands cmd, |
| 10271 | enum nl80211_attrs attr, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10272 | unsigned int portid, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10273 | int vendor_event_idx, |
| 10274 | int approxlen, gfp_t gfp) |
| 10275 | { |
| 10276 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 10277 | const struct nl80211_vendor_cmd_info *info; |
| 10278 | |
| 10279 | switch (cmd) { |
| 10280 | case NL80211_CMD_TESTMODE: |
| 10281 | if (WARN_ON(vendor_event_idx != -1)) |
| 10282 | return NULL; |
| 10283 | info = NULL; |
| 10284 | break; |
| 10285 | case NL80211_CMD_VENDOR: |
| 10286 | if (WARN_ON(vendor_event_idx < 0 || |
| 10287 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 10288 | return NULL; |
| 10289 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 10290 | break; |
| 10291 | default: |
| 10292 | WARN_ON(1); |
| 10293 | return NULL; |
| 10294 | } |
| 10295 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10296 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10297 | cmd, attr, info, gfp); |
| 10298 | } |
| 10299 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 10300 | |
| 10301 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 10302 | { |
| 10303 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10304 | void *hdr = ((void **)skb->cb)[1]; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10305 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10306 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10307 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 10308 | |
| 10309 | /* clear CB data for netlink core to own from now on */ |
| 10310 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10311 | |
| 10312 | nla_nest_end(skb, data); |
| 10313 | genlmsg_end(skb, hdr); |
| 10314 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10315 | if (nlhdr->nlmsg_pid) { |
| 10316 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 10317 | nlhdr->nlmsg_pid); |
| 10318 | } else { |
| 10319 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 10320 | mcgrp = NL80211_MCGRP_VENDOR; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10321 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10322 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 10323 | skb, 0, mcgrp, gfp); |
| 10324 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10325 | } |
| 10326 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 10327 | |
| 10328 | #ifdef CONFIG_NL80211_TESTMODE |
| 10329 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 10330 | { |
| 10331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10332 | struct wireless_dev *wdev = |
| 10333 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 10334 | int err; |
| 10335 | |
| 10336 | if (!rdev->ops->testmode_cmd) |
| 10337 | return -EOPNOTSUPP; |
| 10338 | |
| 10339 | if (IS_ERR(wdev)) { |
| 10340 | err = PTR_ERR(wdev); |
| 10341 | if (err != -EINVAL) |
| 10342 | return err; |
| 10343 | wdev = NULL; |
| 10344 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10345 | return -EINVAL; |
| 10346 | } |
| 10347 | |
| 10348 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 10349 | return -EINVAL; |
| 10350 | |
| 10351 | rdev->cur_cmd_info = info; |
| 10352 | err = rdev_testmode_cmd(rdev, wdev, |
| 10353 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 10354 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 10355 | rdev->cur_cmd_info = NULL; |
| 10356 | |
| 10357 | return err; |
| 10358 | } |
| 10359 | |
| 10360 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 10361 | struct netlink_callback *cb) |
| 10362 | { |
| 10363 | struct cfg80211_registered_device *rdev; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10364 | struct nlattr **attrbuf = NULL; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10365 | int err; |
| 10366 | long phy_idx; |
| 10367 | void *data = NULL; |
| 10368 | int data_len = 0; |
| 10369 | |
| 10370 | rtnl_lock(); |
| 10371 | |
| 10372 | if (cb->args[0]) { |
| 10373 | /* |
| 10374 | * 0 is a valid index, but not valid for args[0], |
| 10375 | * so we need to offset by 1. |
| 10376 | */ |
| 10377 | phy_idx = cb->args[0] - 1; |
| 10378 | |
| 10379 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 10380 | if (!rdev) { |
| 10381 | err = -ENOENT; |
| 10382 | goto out_err; |
| 10383 | } |
| 10384 | } else { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10385 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 10386 | GFP_KERNEL); |
| 10387 | if (!attrbuf) { |
| 10388 | err = -ENOMEM; |
| 10389 | goto out_err; |
| 10390 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10391 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10392 | err = nlmsg_parse_deprecated(cb->nlh, |
| 10393 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10394 | attrbuf, nl80211_fam.maxattr, |
| 10395 | nl80211_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10396 | if (err) |
| 10397 | goto out_err; |
| 10398 | |
| 10399 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
| 10400 | if (IS_ERR(rdev)) { |
| 10401 | err = PTR_ERR(rdev); |
| 10402 | goto out_err; |
| 10403 | } |
| 10404 | phy_idx = rdev->wiphy_idx; |
| 10405 | |
| 10406 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10407 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
| 10408 | } |
| 10409 | |
| 10410 | if (cb->args[1]) { |
| 10411 | data = nla_data((void *)cb->args[1]); |
| 10412 | data_len = nla_len((void *)cb->args[1]); |
| 10413 | } |
| 10414 | |
| 10415 | if (!rdev->ops->testmode_dump) { |
| 10416 | err = -EOPNOTSUPP; |
| 10417 | goto out_err; |
| 10418 | } |
| 10419 | |
| 10420 | while (1) { |
| 10421 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 10422 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10423 | NL80211_CMD_TESTMODE); |
| 10424 | struct nlattr *tmdata; |
| 10425 | |
| 10426 | if (!hdr) |
| 10427 | break; |
| 10428 | |
| 10429 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
| 10430 | genlmsg_cancel(skb, hdr); |
| 10431 | break; |
| 10432 | } |
| 10433 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10434 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10435 | if (!tmdata) { |
| 10436 | genlmsg_cancel(skb, hdr); |
| 10437 | break; |
| 10438 | } |
| 10439 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
| 10440 | nla_nest_end(skb, tmdata); |
| 10441 | |
| 10442 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10443 | genlmsg_cancel(skb, hdr); |
| 10444 | break; |
| 10445 | } else if (err) { |
| 10446 | genlmsg_cancel(skb, hdr); |
| 10447 | goto out_err; |
| 10448 | } |
| 10449 | |
| 10450 | genlmsg_end(skb, hdr); |
| 10451 | } |
| 10452 | |
| 10453 | err = skb->len; |
| 10454 | /* see above */ |
| 10455 | cb->args[0] = phy_idx + 1; |
| 10456 | out_err: |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10457 | kfree(attrbuf); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10458 | rtnl_unlock(); |
| 10459 | return err; |
| 10460 | } |
| 10461 | #endif |
| 10462 | |
| 10463 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10464 | { |
| 10465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10466 | struct net_device *dev = info->user_ptr[1]; |
| 10467 | struct cfg80211_connect_params connect; |
| 10468 | struct wiphy *wiphy; |
| 10469 | struct cfg80211_cached_keys *connkeys = NULL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10470 | u32 freq = 0; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10471 | int err; |
| 10472 | |
| 10473 | memset(&connect, 0, sizeof(connect)); |
| 10474 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10475 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10476 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10477 | return -EINVAL; |
| 10478 | |
| 10479 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10480 | connect.auth_type = |
| 10481 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10482 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10483 | NL80211_CMD_CONNECT)) |
| 10484 | return -EINVAL; |
| 10485 | } else |
| 10486 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10487 | |
| 10488 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10489 | |
| 10490 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10491 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10492 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10493 | return -EINVAL; |
| 10494 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10495 | |
| 10496 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
| 10497 | NL80211_MAX_NR_CIPHER_SUITES); |
| 10498 | if (err) |
| 10499 | return err; |
| 10500 | |
| 10501 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 10502 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10503 | return -EOPNOTSUPP; |
| 10504 | |
| 10505 | wiphy = &rdev->wiphy; |
| 10506 | |
| 10507 | connect.bg_scan_period = -1; |
| 10508 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10509 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10510 | connect.bg_scan_period = |
| 10511 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10512 | } |
| 10513 | |
| 10514 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10515 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10516 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10517 | connect.bssid_hint = |
| 10518 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
| 10519 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10520 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10521 | |
| 10522 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10523 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10524 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10525 | } |
| 10526 | |
| 10527 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10528 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 10529 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10530 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10531 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10532 | return -EOPNOTSUPP; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10533 | } else { |
| 10534 | connect.mfp = NL80211_MFP_NO; |
| 10535 | } |
| 10536 | |
| 10537 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10538 | connect.prev_bssid = |
| 10539 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10540 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10541 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10542 | freq = MHZ_TO_KHZ(nla_get_u32( |
| 10543 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10544 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10545 | freq += |
| 10546 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10547 | |
| 10548 | if (freq) { |
| 10549 | connect.channel = nl80211_get_valid_chan(wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10550 | if (!connect.channel) |
| 10551 | return -EINVAL; |
| 10552 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10553 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10554 | freq = MHZ_TO_KHZ(freq); |
| 10555 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10556 | if (!connect.channel_hint) |
| 10557 | return -EINVAL; |
| 10558 | } |
| 10559 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10560 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 10561 | connect.edmg.channels = |
| 10562 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 10563 | |
| 10564 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 10565 | connect.edmg.bw_config = |
| 10566 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 10567 | } |
| 10568 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10569 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 10570 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
| 10571 | if (IS_ERR(connkeys)) |
| 10572 | return PTR_ERR(connkeys); |
| 10573 | } |
| 10574 | |
| 10575 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 10576 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 10577 | |
| 10578 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10579 | memcpy(&connect.ht_capa_mask, |
| 10580 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10581 | sizeof(connect.ht_capa_mask)); |
| 10582 | |
| 10583 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 10584 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10585 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10586 | return -EINVAL; |
| 10587 | } |
| 10588 | memcpy(&connect.ht_capa, |
| 10589 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10590 | sizeof(connect.ht_capa)); |
| 10591 | } |
| 10592 | |
| 10593 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 10594 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 10595 | |
| 10596 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 10597 | memcpy(&connect.vht_capa_mask, |
| 10598 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10599 | sizeof(connect.vht_capa_mask)); |
| 10600 | |
| 10601 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 10602 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10603 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10604 | return -EINVAL; |
| 10605 | } |
| 10606 | memcpy(&connect.vht_capa, |
| 10607 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10608 | sizeof(connect.vht_capa)); |
| 10609 | } |
| 10610 | |
| 10611 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 10612 | if (!((rdev->wiphy.features & |
| 10613 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10614 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10615 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10616 | NL80211_EXT_FEATURE_RRM)) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10617 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10618 | return -EINVAL; |
| 10619 | } |
| 10620 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 10621 | } |
| 10622 | |
| 10623 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 10624 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10625 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10626 | return -EOPNOTSUPP; |
| 10627 | } |
| 10628 | |
| 10629 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 10630 | /* bss selection makes no sense if bssid is set */ |
| 10631 | if (connect.bssid) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10632 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10633 | return -EINVAL; |
| 10634 | } |
| 10635 | |
| 10636 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 10637 | wiphy, &connect.bss_select); |
| 10638 | if (err) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10639 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10640 | return err; |
| 10641 | } |
| 10642 | } |
| 10643 | |
| 10644 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 10645 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10646 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10647 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10648 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10649 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10650 | connect.fils_erp_username = |
| 10651 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10652 | connect.fils_erp_username_len = |
| 10653 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10654 | connect.fils_erp_realm = |
| 10655 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10656 | connect.fils_erp_realm_len = |
| 10657 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10658 | connect.fils_erp_next_seq_num = |
| 10659 | nla_get_u16( |
| 10660 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10661 | connect.fils_erp_rrk = |
| 10662 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10663 | connect.fils_erp_rrk_len = |
| 10664 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10665 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10666 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10667 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10668 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10669 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10670 | return -EINVAL; |
| 10671 | } |
| 10672 | |
| 10673 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 10674 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10675 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10676 | GENL_SET_ERR_MSG(info, |
| 10677 | "external auth requires connection ownership"); |
| 10678 | return -EINVAL; |
| 10679 | } |
| 10680 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 10681 | } |
| 10682 | |
| 10683 | wdev_lock(dev->ieee80211_ptr); |
| 10684 | |
| 10685 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 10686 | connect.prev_bssid); |
| 10687 | if (err) |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10688 | kfree_sensitive(connkeys); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10689 | |
| 10690 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10691 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10692 | if (connect.bssid) |
| 10693 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10694 | connect.bssid, ETH_ALEN); |
| 10695 | else |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10696 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10697 | } |
| 10698 | |
| 10699 | wdev_unlock(dev->ieee80211_ptr); |
| 10700 | |
| 10701 | return err; |
| 10702 | } |
| 10703 | |
| 10704 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 10705 | struct genl_info *info) |
| 10706 | { |
| 10707 | struct cfg80211_connect_params connect = {}; |
| 10708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10709 | struct net_device *dev = info->user_ptr[1]; |
| 10710 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10711 | bool fils_sk_offload; |
| 10712 | u32 auth_type; |
| 10713 | u32 changed = 0; |
| 10714 | int ret; |
| 10715 | |
| 10716 | if (!rdev->ops->update_connect_params) |
| 10717 | return -EOPNOTSUPP; |
| 10718 | |
| 10719 | if (info->attrs[NL80211_ATTR_IE]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10720 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10721 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10722 | changed |= UPDATE_ASSOC_IES; |
| 10723 | } |
| 10724 | |
| 10725 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 10726 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 10727 | |
| 10728 | /* |
| 10729 | * when driver supports fils-sk offload all attributes must be |
| 10730 | * provided. So the else covers "fils-sk-not-all" and |
| 10731 | * "no-fils-sk-any". |
| 10732 | */ |
| 10733 | if (fils_sk_offload && |
| 10734 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10735 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10736 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10737 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10738 | connect.fils_erp_username = |
| 10739 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10740 | connect.fils_erp_username_len = |
| 10741 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10742 | connect.fils_erp_realm = |
| 10743 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10744 | connect.fils_erp_realm_len = |
| 10745 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10746 | connect.fils_erp_next_seq_num = |
| 10747 | nla_get_u16( |
| 10748 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10749 | connect.fils_erp_rrk = |
| 10750 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10751 | connect.fils_erp_rrk_len = |
| 10752 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10753 | changed |= UPDATE_FILS_ERP_INFO; |
| 10754 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10755 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10756 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10757 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10758 | return -EINVAL; |
| 10759 | } |
| 10760 | |
| 10761 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10762 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10763 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 10764 | NL80211_CMD_CONNECT)) |
| 10765 | return -EINVAL; |
| 10766 | |
| 10767 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 10768 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 10769 | return -EINVAL; |
| 10770 | |
| 10771 | connect.auth_type = auth_type; |
| 10772 | changed |= UPDATE_AUTH_TYPE; |
| 10773 | } |
| 10774 | |
| 10775 | wdev_lock(dev->ieee80211_ptr); |
| 10776 | if (!wdev->current_bss) |
| 10777 | ret = -ENOLINK; |
| 10778 | else |
| 10779 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 10780 | wdev_unlock(dev->ieee80211_ptr); |
| 10781 | |
| 10782 | return ret; |
| 10783 | } |
| 10784 | |
| 10785 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 10786 | { |
| 10787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10788 | struct net_device *dev = info->user_ptr[1]; |
| 10789 | u16 reason; |
| 10790 | int ret; |
| 10791 | |
| 10792 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10793 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10794 | return -EPERM; |
| 10795 | |
| 10796 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10797 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 10798 | else |
| 10799 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10800 | |
| 10801 | if (reason == 0) |
| 10802 | return -EINVAL; |
| 10803 | |
| 10804 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 10805 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10806 | return -EOPNOTSUPP; |
| 10807 | |
| 10808 | wdev_lock(dev->ieee80211_ptr); |
| 10809 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 10810 | wdev_unlock(dev->ieee80211_ptr); |
| 10811 | return ret; |
| 10812 | } |
| 10813 | |
| 10814 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 10815 | { |
| 10816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10817 | struct net *net; |
| 10818 | int err; |
| 10819 | |
| 10820 | if (info->attrs[NL80211_ATTR_PID]) { |
| 10821 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 10822 | |
| 10823 | net = get_net_ns_by_pid(pid); |
| 10824 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 10825 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 10826 | |
| 10827 | net = get_net_ns_by_fd(fd); |
| 10828 | } else { |
| 10829 | return -EINVAL; |
| 10830 | } |
| 10831 | |
| 10832 | if (IS_ERR(net)) |
| 10833 | return PTR_ERR(net); |
| 10834 | |
| 10835 | err = 0; |
| 10836 | |
| 10837 | /* check if anything to do */ |
| 10838 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 10839 | err = cfg80211_switch_netns(rdev, net); |
| 10840 | |
| 10841 | put_net(net); |
| 10842 | return err; |
| 10843 | } |
| 10844 | |
| 10845 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10846 | { |
| 10847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10848 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 10849 | struct cfg80211_pmksa *pmksa) = NULL; |
| 10850 | struct net_device *dev = info->user_ptr[1]; |
| 10851 | struct cfg80211_pmksa pmksa; |
| 10852 | |
| 10853 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 10854 | |
| 10855 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 10856 | return -EINVAL; |
| 10857 | |
| 10858 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 10859 | |
| 10860 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10861 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10862 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 10863 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 10864 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 10865 | info->attrs[NL80211_ATTR_PMK])) { |
| 10866 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10867 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10868 | pmksa.cache_id = |
| 10869 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 10870 | } else { |
| 10871 | return -EINVAL; |
| 10872 | } |
| 10873 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10874 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10875 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 10876 | } |
| 10877 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 10878 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
| 10879 | pmksa.pmk_lifetime = |
| 10880 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); |
| 10881 | |
| 10882 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) |
| 10883 | pmksa.pmk_reauth_threshold = |
| 10884 | nla_get_u8( |
| 10885 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); |
| 10886 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 10888 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 10889 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 10890 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 10891 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10892 | return -EOPNOTSUPP; |
| 10893 | |
| 10894 | switch (info->genlhdr->cmd) { |
| 10895 | case NL80211_CMD_SET_PMKSA: |
| 10896 | rdev_ops = rdev->ops->set_pmksa; |
| 10897 | break; |
| 10898 | case NL80211_CMD_DEL_PMKSA: |
| 10899 | rdev_ops = rdev->ops->del_pmksa; |
| 10900 | break; |
| 10901 | default: |
| 10902 | WARN_ON(1); |
| 10903 | break; |
| 10904 | } |
| 10905 | |
| 10906 | if (!rdev_ops) |
| 10907 | return -EOPNOTSUPP; |
| 10908 | |
| 10909 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
| 10910 | } |
| 10911 | |
| 10912 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10913 | { |
| 10914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10915 | struct net_device *dev = info->user_ptr[1]; |
| 10916 | |
| 10917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 10918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10919 | return -EOPNOTSUPP; |
| 10920 | |
| 10921 | if (!rdev->ops->flush_pmksa) |
| 10922 | return -EOPNOTSUPP; |
| 10923 | |
| 10924 | return rdev_flush_pmksa(rdev, dev); |
| 10925 | } |
| 10926 | |
| 10927 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 10928 | { |
| 10929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10930 | struct net_device *dev = info->user_ptr[1]; |
| 10931 | u8 action_code, dialog_token; |
| 10932 | u32 peer_capability = 0; |
| 10933 | u16 status_code; |
| 10934 | u8 *peer; |
| 10935 | bool initiator; |
| 10936 | |
| 10937 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10938 | !rdev->ops->tdls_mgmt) |
| 10939 | return -EOPNOTSUPP; |
| 10940 | |
| 10941 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 10942 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 10943 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 10944 | !info->attrs[NL80211_ATTR_IE] || |
| 10945 | !info->attrs[NL80211_ATTR_MAC]) |
| 10946 | return -EINVAL; |
| 10947 | |
| 10948 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10949 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 10950 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 10951 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 10952 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
| 10953 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 10954 | peer_capability = |
| 10955 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
| 10956 | |
| 10957 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 10958 | dialog_token, status_code, peer_capability, |
| 10959 | initiator, |
| 10960 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 10961 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 10962 | } |
| 10963 | |
| 10964 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 10965 | { |
| 10966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10967 | struct net_device *dev = info->user_ptr[1]; |
| 10968 | enum nl80211_tdls_operation operation; |
| 10969 | u8 *peer; |
| 10970 | |
| 10971 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10972 | !rdev->ops->tdls_oper) |
| 10973 | return -EOPNOTSUPP; |
| 10974 | |
| 10975 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 10976 | !info->attrs[NL80211_ATTR_MAC]) |
| 10977 | return -EINVAL; |
| 10978 | |
| 10979 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 10980 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10981 | |
| 10982 | return rdev_tdls_oper(rdev, dev, peer, operation); |
| 10983 | } |
| 10984 | |
| 10985 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 10986 | struct genl_info *info) |
| 10987 | { |
| 10988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10989 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10990 | struct cfg80211_chan_def chandef; |
| 10991 | const struct cfg80211_chan_def *compat_chandef; |
| 10992 | struct sk_buff *msg; |
| 10993 | void *hdr; |
| 10994 | u64 cookie; |
| 10995 | u32 duration; |
| 10996 | int err; |
| 10997 | |
| 10998 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10999 | !info->attrs[NL80211_ATTR_DURATION]) |
| 11000 | return -EINVAL; |
| 11001 | |
| 11002 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 11003 | |
| 11004 | if (!rdev->ops->remain_on_channel || |
| 11005 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
| 11006 | return -EOPNOTSUPP; |
| 11007 | |
| 11008 | /* |
| 11009 | * We should be on that channel for at least a minimum amount of |
| 11010 | * time (10ms) but no longer than the driver supports. |
| 11011 | */ |
| 11012 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11013 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 11014 | return -EINVAL; |
| 11015 | |
| 11016 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11017 | if (err) |
| 11018 | return err; |
| 11019 | |
| 11020 | wdev_lock(wdev); |
| 11021 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 11022 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 11023 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 11024 | &chandef); |
| 11025 | if (compat_chandef != &chandef) { |
| 11026 | wdev_unlock(wdev); |
| 11027 | return -EBUSY; |
| 11028 | } |
| 11029 | } |
| 11030 | wdev_unlock(wdev); |
| 11031 | |
| 11032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11033 | if (!msg) |
| 11034 | return -ENOMEM; |
| 11035 | |
| 11036 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11037 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 11038 | if (!hdr) { |
| 11039 | err = -ENOBUFS; |
| 11040 | goto free_msg; |
| 11041 | } |
| 11042 | |
| 11043 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 11044 | duration, &cookie); |
| 11045 | |
| 11046 | if (err) |
| 11047 | goto free_msg; |
| 11048 | |
| 11049 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11050 | NL80211_ATTR_PAD)) |
| 11051 | goto nla_put_failure; |
| 11052 | |
| 11053 | genlmsg_end(msg, hdr); |
| 11054 | |
| 11055 | return genlmsg_reply(msg, info); |
| 11056 | |
| 11057 | nla_put_failure: |
| 11058 | err = -ENOBUFS; |
| 11059 | free_msg: |
| 11060 | nlmsg_free(msg); |
| 11061 | return err; |
| 11062 | } |
| 11063 | |
| 11064 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 11065 | struct genl_info *info) |
| 11066 | { |
| 11067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11068 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11069 | u64 cookie; |
| 11070 | |
| 11071 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11072 | return -EINVAL; |
| 11073 | |
| 11074 | if (!rdev->ops->cancel_remain_on_channel) |
| 11075 | return -EOPNOTSUPP; |
| 11076 | |
| 11077 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11078 | |
| 11079 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
| 11080 | } |
| 11081 | |
| 11082 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 11083 | struct genl_info *info) |
| 11084 | { |
| 11085 | struct cfg80211_bitrate_mask mask; |
| 11086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11087 | struct net_device *dev = info->user_ptr[1]; |
| 11088 | int err; |
| 11089 | |
| 11090 | if (!rdev->ops->set_bitrate_mask) |
| 11091 | return -EOPNOTSUPP; |
| 11092 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 11093 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 11094 | NL80211_ATTR_TX_RATES, &mask, |
| 11095 | dev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11096 | if (err) |
| 11097 | return err; |
| 11098 | |
| 11099 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
| 11100 | } |
| 11101 | |
| 11102 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 11103 | { |
| 11104 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11105 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11106 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
| 11107 | |
| 11108 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 11109 | return -EINVAL; |
| 11110 | |
| 11111 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 11112 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
| 11113 | |
| 11114 | switch (wdev->iftype) { |
| 11115 | case NL80211_IFTYPE_STATION: |
| 11116 | case NL80211_IFTYPE_ADHOC: |
| 11117 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11118 | case NL80211_IFTYPE_AP: |
| 11119 | case NL80211_IFTYPE_AP_VLAN: |
| 11120 | case NL80211_IFTYPE_MESH_POINT: |
| 11121 | case NL80211_IFTYPE_P2P_GO: |
| 11122 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11123 | break; |
| 11124 | case NL80211_IFTYPE_NAN: |
| 11125 | default: |
| 11126 | return -EOPNOTSUPP; |
| 11127 | } |
| 11128 | |
| 11129 | /* not much point in registering if we can't reply */ |
| 11130 | if (!rdev->ops->mgmt_tx) |
| 11131 | return -EOPNOTSUPP; |
| 11132 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 11133 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
| 11134 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 11135 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { |
| 11136 | GENL_SET_ERR_MSG(info, |
| 11137 | "multicast RX registrations are not supported"); |
| 11138 | return -EOPNOTSUPP; |
| 11139 | } |
| 11140 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11141 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 11142 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 11143 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 11144 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
| 11145 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11146 | } |
| 11147 | |
| 11148 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 11149 | { |
| 11150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11151 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11152 | struct cfg80211_chan_def chandef; |
| 11153 | int err; |
| 11154 | void *hdr = NULL; |
| 11155 | u64 cookie; |
| 11156 | struct sk_buff *msg = NULL; |
| 11157 | struct cfg80211_mgmt_tx_params params = { |
| 11158 | .dont_wait_for_ack = |
| 11159 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 11160 | }; |
| 11161 | |
| 11162 | if (!info->attrs[NL80211_ATTR_FRAME]) |
| 11163 | return -EINVAL; |
| 11164 | |
| 11165 | if (!rdev->ops->mgmt_tx) |
| 11166 | return -EOPNOTSUPP; |
| 11167 | |
| 11168 | switch (wdev->iftype) { |
| 11169 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11170 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 11171 | return -EINVAL; |
| 11172 | case NL80211_IFTYPE_STATION: |
| 11173 | case NL80211_IFTYPE_ADHOC: |
| 11174 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11175 | case NL80211_IFTYPE_AP: |
| 11176 | case NL80211_IFTYPE_AP_VLAN: |
| 11177 | case NL80211_IFTYPE_MESH_POINT: |
| 11178 | case NL80211_IFTYPE_P2P_GO: |
| 11179 | break; |
| 11180 | case NL80211_IFTYPE_NAN: |
| 11181 | default: |
| 11182 | return -EOPNOTSUPP; |
| 11183 | } |
| 11184 | |
| 11185 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 11186 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 11187 | return -EINVAL; |
| 11188 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 11189 | |
| 11190 | /* |
| 11191 | * We should wait on the channel for at least a minimum amount |
| 11192 | * of time (10ms) but no longer than the driver supports. |
| 11193 | */ |
| 11194 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11195 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
| 11196 | return -EINVAL; |
| 11197 | } |
| 11198 | |
| 11199 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 11200 | |
| 11201 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 11202 | return -EINVAL; |
| 11203 | |
| 11204 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 11205 | |
| 11206 | /* get the channel if any has been specified, otherwise pass NULL to |
| 11207 | * the driver. The latter will use the current one |
| 11208 | */ |
| 11209 | chandef.chan = NULL; |
| 11210 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 11211 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11212 | if (err) |
| 11213 | return err; |
| 11214 | } |
| 11215 | |
| 11216 | if (!chandef.chan && params.offchan) |
| 11217 | return -EINVAL; |
| 11218 | |
| 11219 | wdev_lock(wdev); |
| 11220 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 11221 | wdev_unlock(wdev); |
| 11222 | return -EBUSY; |
| 11223 | } |
| 11224 | wdev_unlock(wdev); |
| 11225 | |
| 11226 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 11227 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 11228 | |
| 11229 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 11230 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11231 | int i; |
| 11232 | |
| 11233 | if (len % sizeof(u16)) |
| 11234 | return -EINVAL; |
| 11235 | |
| 11236 | params.n_csa_offsets = len / sizeof(u16); |
| 11237 | params.csa_offsets = |
| 11238 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11239 | |
| 11240 | /* check that all the offsets fit the frame */ |
| 11241 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 11242 | if (params.csa_offsets[i] >= params.len) |
| 11243 | return -EINVAL; |
| 11244 | } |
| 11245 | } |
| 11246 | |
| 11247 | if (!params.dont_wait_for_ack) { |
| 11248 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11249 | if (!msg) |
| 11250 | return -ENOMEM; |
| 11251 | |
| 11252 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11253 | NL80211_CMD_FRAME); |
| 11254 | if (!hdr) { |
| 11255 | err = -ENOBUFS; |
| 11256 | goto free_msg; |
| 11257 | } |
| 11258 | } |
| 11259 | |
| 11260 | params.chan = chandef.chan; |
| 11261 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
| 11262 | if (err) |
| 11263 | goto free_msg; |
| 11264 | |
| 11265 | if (msg) { |
| 11266 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11267 | NL80211_ATTR_PAD)) |
| 11268 | goto nla_put_failure; |
| 11269 | |
| 11270 | genlmsg_end(msg, hdr); |
| 11271 | return genlmsg_reply(msg, info); |
| 11272 | } |
| 11273 | |
| 11274 | return 0; |
| 11275 | |
| 11276 | nla_put_failure: |
| 11277 | err = -ENOBUFS; |
| 11278 | free_msg: |
| 11279 | nlmsg_free(msg); |
| 11280 | return err; |
| 11281 | } |
| 11282 | |
| 11283 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 11284 | { |
| 11285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11286 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11287 | u64 cookie; |
| 11288 | |
| 11289 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11290 | return -EINVAL; |
| 11291 | |
| 11292 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 11293 | return -EOPNOTSUPP; |
| 11294 | |
| 11295 | switch (wdev->iftype) { |
| 11296 | case NL80211_IFTYPE_STATION: |
| 11297 | case NL80211_IFTYPE_ADHOC: |
| 11298 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11299 | case NL80211_IFTYPE_AP: |
| 11300 | case NL80211_IFTYPE_AP_VLAN: |
| 11301 | case NL80211_IFTYPE_P2P_GO: |
| 11302 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11303 | break; |
| 11304 | case NL80211_IFTYPE_NAN: |
| 11305 | default: |
| 11306 | return -EOPNOTSUPP; |
| 11307 | } |
| 11308 | |
| 11309 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11310 | |
| 11311 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
| 11312 | } |
| 11313 | |
| 11314 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11315 | { |
| 11316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11317 | struct wireless_dev *wdev; |
| 11318 | struct net_device *dev = info->user_ptr[1]; |
| 11319 | u8 ps_state; |
| 11320 | bool state; |
| 11321 | int err; |
| 11322 | |
| 11323 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 11324 | return -EINVAL; |
| 11325 | |
| 11326 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 11327 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11328 | wdev = dev->ieee80211_ptr; |
| 11329 | |
| 11330 | if (!rdev->ops->set_power_mgmt) |
| 11331 | return -EOPNOTSUPP; |
| 11332 | |
| 11333 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 11334 | |
| 11335 | if (state == wdev->ps) |
| 11336 | return 0; |
| 11337 | |
| 11338 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
| 11339 | if (!err) |
| 11340 | wdev->ps = state; |
| 11341 | return err; |
| 11342 | } |
| 11343 | |
| 11344 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11345 | { |
| 11346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11347 | enum nl80211_ps_state ps_state; |
| 11348 | struct wireless_dev *wdev; |
| 11349 | struct net_device *dev = info->user_ptr[1]; |
| 11350 | struct sk_buff *msg; |
| 11351 | void *hdr; |
| 11352 | int err; |
| 11353 | |
| 11354 | wdev = dev->ieee80211_ptr; |
| 11355 | |
| 11356 | if (!rdev->ops->set_power_mgmt) |
| 11357 | return -EOPNOTSUPP; |
| 11358 | |
| 11359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11360 | if (!msg) |
| 11361 | return -ENOMEM; |
| 11362 | |
| 11363 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11364 | NL80211_CMD_GET_POWER_SAVE); |
| 11365 | if (!hdr) { |
| 11366 | err = -ENOBUFS; |
| 11367 | goto free_msg; |
| 11368 | } |
| 11369 | |
| 11370 | if (wdev->ps) |
| 11371 | ps_state = NL80211_PS_ENABLED; |
| 11372 | else |
| 11373 | ps_state = NL80211_PS_DISABLED; |
| 11374 | |
| 11375 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 11376 | goto nla_put_failure; |
| 11377 | |
| 11378 | genlmsg_end(msg, hdr); |
| 11379 | return genlmsg_reply(msg, info); |
| 11380 | |
| 11381 | nla_put_failure: |
| 11382 | err = -ENOBUFS; |
| 11383 | free_msg: |
| 11384 | nlmsg_free(msg); |
| 11385 | return err; |
| 11386 | } |
| 11387 | |
| 11388 | static const struct nla_policy |
| 11389 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
| 11390 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
| 11391 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 11392 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 11393 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 11394 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 11395 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
| 11396 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
| 11397 | }; |
| 11398 | |
| 11399 | static int nl80211_set_cqm_txe(struct genl_info *info, |
| 11400 | u32 rate, u32 pkts, u32 intvl) |
| 11401 | { |
| 11402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11403 | struct net_device *dev = info->user_ptr[1]; |
| 11404 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11405 | |
| 11406 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
| 11407 | return -EINVAL; |
| 11408 | |
| 11409 | if (!rdev->ops->set_cqm_txe_config) |
| 11410 | return -EOPNOTSUPP; |
| 11411 | |
| 11412 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11413 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11414 | return -EOPNOTSUPP; |
| 11415 | |
| 11416 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
| 11417 | } |
| 11418 | |
| 11419 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 11420 | struct net_device *dev) |
| 11421 | { |
| 11422 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11423 | s32 last, low, high; |
| 11424 | u32 hyst; |
| 11425 | int i, n, low_index; |
| 11426 | int err; |
| 11427 | |
| 11428 | /* RSSI reporting disabled? */ |
| 11429 | if (!wdev->cqm_config) |
| 11430 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11431 | |
| 11432 | /* |
| 11433 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11434 | * event has been received yet, we should receive an event after a |
| 11435 | * connection is established and enough beacons received to calculate |
| 11436 | * the average. |
| 11437 | */ |
| 11438 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11439 | rdev->ops->get_station) { |
| 11440 | struct station_info sinfo = {}; |
| 11441 | u8 *mac_addr; |
| 11442 | |
| 11443 | mac_addr = wdev->current_bss->pub.bssid; |
| 11444 | |
| 11445 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11446 | if (err) |
| 11447 | return err; |
| 11448 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 11449 | cfg80211_sinfo_release_content(&sinfo); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11450 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
| 11451 | wdev->cqm_config->last_rssi_event_value = |
| 11452 | (s8) sinfo.rx_beacon_signal_avg; |
| 11453 | } |
| 11454 | |
| 11455 | last = wdev->cqm_config->last_rssi_event_value; |
| 11456 | hyst = wdev->cqm_config->rssi_hyst; |
| 11457 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11458 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11459 | for (i = 0; i < n; i++) { |
| 11460 | i = array_index_nospec(i, n); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11461 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11462 | break; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11463 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11464 | |
| 11465 | low_index = i - 1; |
| 11466 | if (low_index >= 0) { |
| 11467 | low_index = array_index_nospec(low_index, n); |
| 11468 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11469 | } else { |
| 11470 | low = S32_MIN; |
| 11471 | } |
| 11472 | if (i < n) { |
| 11473 | i = array_index_nospec(i, n); |
| 11474 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11475 | } else { |
| 11476 | high = S32_MAX; |
| 11477 | } |
| 11478 | |
| 11479 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11480 | } |
| 11481 | |
| 11482 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 11483 | const s32 *thresholds, int n_thresholds, |
| 11484 | u32 hysteresis) |
| 11485 | { |
| 11486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11487 | struct net_device *dev = info->user_ptr[1]; |
| 11488 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11489 | int i, err; |
| 11490 | s32 prev = S32_MIN; |
| 11491 | |
| 11492 | /* Check all values negative and sorted */ |
| 11493 | for (i = 0; i < n_thresholds; i++) { |
| 11494 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11495 | return -EINVAL; |
| 11496 | |
| 11497 | prev = thresholds[i]; |
| 11498 | } |
| 11499 | |
| 11500 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11501 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11502 | return -EOPNOTSUPP; |
| 11503 | |
| 11504 | wdev_lock(wdev); |
| 11505 | cfg80211_cqm_config_free(wdev); |
| 11506 | wdev_unlock(wdev); |
| 11507 | |
| 11508 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11509 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11510 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11511 | |
| 11512 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11513 | thresholds[0], hysteresis); |
| 11514 | } |
| 11515 | |
| 11516 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11517 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11518 | return -EOPNOTSUPP; |
| 11519 | |
| 11520 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11521 | n_thresholds = 0; |
| 11522 | |
| 11523 | wdev_lock(wdev); |
| 11524 | if (n_thresholds) { |
| 11525 | struct cfg80211_cqm_config *cqm_config; |
| 11526 | |
| 11527 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 11528 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 11529 | if (!cqm_config) { |
| 11530 | err = -ENOMEM; |
| 11531 | goto unlock; |
| 11532 | } |
| 11533 | |
| 11534 | cqm_config->rssi_hyst = hysteresis; |
| 11535 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11536 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 11537 | n_thresholds * sizeof(s32)); |
| 11538 | |
| 11539 | wdev->cqm_config = cqm_config; |
| 11540 | } |
| 11541 | |
| 11542 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11543 | |
| 11544 | unlock: |
| 11545 | wdev_unlock(wdev); |
| 11546 | |
| 11547 | return err; |
| 11548 | } |
| 11549 | |
| 11550 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11551 | { |
| 11552 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11553 | struct nlattr *cqm; |
| 11554 | int err; |
| 11555 | |
| 11556 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 11557 | if (!cqm) |
| 11558 | return -EINVAL; |
| 11559 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11560 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 11561 | nl80211_attr_cqm_policy, |
| 11562 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11563 | if (err) |
| 11564 | return err; |
| 11565 | |
| 11566 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 11567 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 11568 | const s32 *thresholds = |
| 11569 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11570 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11571 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 11572 | |
| 11573 | if (len % 4) |
| 11574 | return -EINVAL; |
| 11575 | |
| 11576 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 11577 | hysteresis); |
| 11578 | } |
| 11579 | |
| 11580 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 11581 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 11582 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 11583 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 11584 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 11585 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 11586 | |
| 11587 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 11588 | } |
| 11589 | |
| 11590 | return -EINVAL; |
| 11591 | } |
| 11592 | |
| 11593 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11594 | { |
| 11595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11596 | struct net_device *dev = info->user_ptr[1]; |
| 11597 | struct ocb_setup setup = {}; |
| 11598 | int err; |
| 11599 | |
| 11600 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11601 | if (err) |
| 11602 | return err; |
| 11603 | |
| 11604 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 11605 | } |
| 11606 | |
| 11607 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11608 | { |
| 11609 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11610 | struct net_device *dev = info->user_ptr[1]; |
| 11611 | |
| 11612 | return cfg80211_leave_ocb(rdev, dev); |
| 11613 | } |
| 11614 | |
| 11615 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11616 | { |
| 11617 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11618 | struct net_device *dev = info->user_ptr[1]; |
| 11619 | struct mesh_config cfg; |
| 11620 | struct mesh_setup setup; |
| 11621 | int err; |
| 11622 | |
| 11623 | /* start with default */ |
| 11624 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
| 11625 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
| 11626 | |
| 11627 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
| 11628 | /* and parse parameters if given */ |
| 11629 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
| 11630 | if (err) |
| 11631 | return err; |
| 11632 | } |
| 11633 | |
| 11634 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 11635 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 11636 | return -EINVAL; |
| 11637 | |
| 11638 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11639 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11640 | |
| 11641 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 11642 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 11643 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 11644 | return -EINVAL; |
| 11645 | |
| 11646 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 11647 | setup.beacon_interval = |
| 11648 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 11649 | |
| 11650 | err = cfg80211_validate_beacon_int(rdev, |
| 11651 | NL80211_IFTYPE_MESH_POINT, |
| 11652 | setup.beacon_interval); |
| 11653 | if (err) |
| 11654 | return err; |
| 11655 | } |
| 11656 | |
| 11657 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 11658 | setup.dtim_period = |
| 11659 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 11660 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 11661 | return -EINVAL; |
| 11662 | } |
| 11663 | |
| 11664 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 11665 | /* parse additional setup parameters if given */ |
| 11666 | err = nl80211_parse_mesh_setup(info, &setup); |
| 11667 | if (err) |
| 11668 | return err; |
| 11669 | } |
| 11670 | |
| 11671 | if (setup.user_mpm) |
| 11672 | cfg.auto_open_plinks = false; |
| 11673 | |
| 11674 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 11675 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11676 | if (err) |
| 11677 | return err; |
| 11678 | } else { |
| 11679 | /* __cfg80211_join_mesh() will sort it out */ |
| 11680 | setup.chandef.chan = NULL; |
| 11681 | } |
| 11682 | |
| 11683 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 11684 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11685 | int n_rates = |
| 11686 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11687 | struct ieee80211_supported_band *sband; |
| 11688 | |
| 11689 | if (!setup.chandef.chan) |
| 11690 | return -EINVAL; |
| 11691 | |
| 11692 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 11693 | |
| 11694 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 11695 | &setup.basic_rates); |
| 11696 | if (err) |
| 11697 | return err; |
| 11698 | } |
| 11699 | |
| 11700 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 11701 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 11702 | NL80211_ATTR_TX_RATES, |
| 11703 | &setup.beacon_rate, |
| 11704 | dev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11705 | if (err) |
| 11706 | return err; |
| 11707 | |
| 11708 | if (!setup.chandef.chan) |
| 11709 | return -EINVAL; |
| 11710 | |
| 11711 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 11712 | &setup.beacon_rate); |
| 11713 | if (err) |
| 11714 | return err; |
| 11715 | } |
| 11716 | |
| 11717 | setup.userspace_handles_dfs = |
| 11718 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 11719 | |
| 11720 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 11721 | int r = validate_pae_over_nl80211(rdev, info); |
| 11722 | |
| 11723 | if (r < 0) |
| 11724 | return r; |
| 11725 | |
| 11726 | setup.control_port_over_nl80211 = true; |
| 11727 | } |
| 11728 | |
| 11729 | wdev_lock(dev->ieee80211_ptr); |
| 11730 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 11731 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 11732 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11733 | wdev_unlock(dev->ieee80211_ptr); |
| 11734 | |
| 11735 | return err; |
| 11736 | } |
| 11737 | |
| 11738 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11739 | { |
| 11740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11741 | struct net_device *dev = info->user_ptr[1]; |
| 11742 | |
| 11743 | return cfg80211_leave_mesh(rdev, dev); |
| 11744 | } |
| 11745 | |
| 11746 | #ifdef CONFIG_PM |
| 11747 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 11748 | struct cfg80211_registered_device *rdev) |
| 11749 | { |
| 11750 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
| 11751 | struct nlattr *nl_pats, *nl_pat; |
| 11752 | int i, pat_len; |
| 11753 | |
| 11754 | if (!wowlan->n_patterns) |
| 11755 | return 0; |
| 11756 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11757 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11758 | if (!nl_pats) |
| 11759 | return -ENOBUFS; |
| 11760 | |
| 11761 | for (i = 0; i < wowlan->n_patterns; i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11762 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11763 | if (!nl_pat) |
| 11764 | return -ENOBUFS; |
| 11765 | pat_len = wowlan->patterns[i].pattern_len; |
| 11766 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
| 11767 | wowlan->patterns[i].mask) || |
| 11768 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11769 | wowlan->patterns[i].pattern) || |
| 11770 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 11771 | wowlan->patterns[i].pkt_offset)) |
| 11772 | return -ENOBUFS; |
| 11773 | nla_nest_end(msg, nl_pat); |
| 11774 | } |
| 11775 | nla_nest_end(msg, nl_pats); |
| 11776 | |
| 11777 | return 0; |
| 11778 | } |
| 11779 | |
| 11780 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 11781 | struct cfg80211_wowlan_tcp *tcp) |
| 11782 | { |
| 11783 | struct nlattr *nl_tcp; |
| 11784 | |
| 11785 | if (!tcp) |
| 11786 | return 0; |
| 11787 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11788 | nl_tcp = nla_nest_start_noflag(msg, |
| 11789 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11790 | if (!nl_tcp) |
| 11791 | return -ENOBUFS; |
| 11792 | |
| 11793 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 11794 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 11795 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 11796 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 11797 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 11798 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 11799 | tcp->payload_len, tcp->payload) || |
| 11800 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 11801 | tcp->data_interval) || |
| 11802 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 11803 | tcp->wake_len, tcp->wake_data) || |
| 11804 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 11805 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 11806 | return -ENOBUFS; |
| 11807 | |
| 11808 | if (tcp->payload_seq.len && |
| 11809 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 11810 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 11811 | return -ENOBUFS; |
| 11812 | |
| 11813 | if (tcp->payload_tok.len && |
| 11814 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 11815 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 11816 | &tcp->payload_tok)) |
| 11817 | return -ENOBUFS; |
| 11818 | |
| 11819 | nla_nest_end(msg, nl_tcp); |
| 11820 | |
| 11821 | return 0; |
| 11822 | } |
| 11823 | |
| 11824 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 11825 | struct cfg80211_sched_scan_request *req) |
| 11826 | { |
| 11827 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
| 11828 | int i; |
| 11829 | |
| 11830 | if (!req) |
| 11831 | return 0; |
| 11832 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11833 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11834 | if (!nd) |
| 11835 | return -ENOBUFS; |
| 11836 | |
| 11837 | if (req->n_scan_plans == 1 && |
| 11838 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 11839 | req->scan_plans[0].interval * 1000)) |
| 11840 | return -ENOBUFS; |
| 11841 | |
| 11842 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 11843 | return -ENOBUFS; |
| 11844 | |
| 11845 | if (req->relative_rssi_set) { |
| 11846 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 11847 | |
| 11848 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 11849 | req->relative_rssi)) |
| 11850 | return -ENOBUFS; |
| 11851 | |
| 11852 | rssi_adjust.band = req->rssi_adjust.band; |
| 11853 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 11854 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 11855 | sizeof(rssi_adjust), &rssi_adjust)) |
| 11856 | return -ENOBUFS; |
| 11857 | } |
| 11858 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11859 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11860 | if (!freqs) |
| 11861 | return -ENOBUFS; |
| 11862 | |
| 11863 | for (i = 0; i < req->n_channels; i++) { |
| 11864 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11865 | return -ENOBUFS; |
| 11866 | } |
| 11867 | |
| 11868 | nla_nest_end(msg, freqs); |
| 11869 | |
| 11870 | if (req->n_match_sets) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11871 | matches = nla_nest_start_noflag(msg, |
| 11872 | NL80211_ATTR_SCHED_SCAN_MATCH); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11873 | if (!matches) |
| 11874 | return -ENOBUFS; |
| 11875 | |
| 11876 | for (i = 0; i < req->n_match_sets; i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11877 | match = nla_nest_start_noflag(msg, i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11878 | if (!match) |
| 11879 | return -ENOBUFS; |
| 11880 | |
| 11881 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 11882 | req->match_sets[i].ssid.ssid_len, |
| 11883 | req->match_sets[i].ssid.ssid)) |
| 11884 | return -ENOBUFS; |
| 11885 | nla_nest_end(msg, match); |
| 11886 | } |
| 11887 | nla_nest_end(msg, matches); |
| 11888 | } |
| 11889 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11890 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11891 | if (!scan_plans) |
| 11892 | return -ENOBUFS; |
| 11893 | |
| 11894 | for (i = 0; i < req->n_scan_plans; i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11895 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11896 | if (!scan_plan) |
| 11897 | return -ENOBUFS; |
| 11898 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11899 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11900 | req->scan_plans[i].interval) || |
| 11901 | (req->scan_plans[i].iterations && |
| 11902 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 11903 | req->scan_plans[i].iterations))) |
| 11904 | return -ENOBUFS; |
| 11905 | nla_nest_end(msg, scan_plan); |
| 11906 | } |
| 11907 | nla_nest_end(msg, scan_plans); |
| 11908 | |
| 11909 | nla_nest_end(msg, nd); |
| 11910 | |
| 11911 | return 0; |
| 11912 | } |
| 11913 | |
| 11914 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11915 | { |
| 11916 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11917 | struct sk_buff *msg; |
| 11918 | void *hdr; |
| 11919 | u32 size = NLMSG_DEFAULT_SIZE; |
| 11920 | |
| 11921 | if (!rdev->wiphy.wowlan) |
| 11922 | return -EOPNOTSUPP; |
| 11923 | |
| 11924 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
| 11925 | /* adjust size to have room for all the data */ |
| 11926 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 11927 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 11928 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 11929 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
| 11930 | } |
| 11931 | |
| 11932 | msg = nlmsg_new(size, GFP_KERNEL); |
| 11933 | if (!msg) |
| 11934 | return -ENOMEM; |
| 11935 | |
| 11936 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11937 | NL80211_CMD_GET_WOWLAN); |
| 11938 | if (!hdr) |
| 11939 | goto nla_put_failure; |
| 11940 | |
| 11941 | if (rdev->wiphy.wowlan_config) { |
| 11942 | struct nlattr *nl_wowlan; |
| 11943 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11944 | nl_wowlan = nla_nest_start_noflag(msg, |
| 11945 | NL80211_ATTR_WOWLAN_TRIGGERS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11946 | if (!nl_wowlan) |
| 11947 | goto nla_put_failure; |
| 11948 | |
| 11949 | if ((rdev->wiphy.wowlan_config->any && |
| 11950 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 11951 | (rdev->wiphy.wowlan_config->disconnect && |
| 11952 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 11953 | (rdev->wiphy.wowlan_config->magic_pkt && |
| 11954 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 11955 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
| 11956 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 11957 | (rdev->wiphy.wowlan_config->eap_identity_req && |
| 11958 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 11959 | (rdev->wiphy.wowlan_config->four_way_handshake && |
| 11960 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 11961 | (rdev->wiphy.wowlan_config->rfkill_release && |
| 11962 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 11963 | goto nla_put_failure; |
| 11964 | |
| 11965 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 11966 | goto nla_put_failure; |
| 11967 | |
| 11968 | if (nl80211_send_wowlan_tcp(msg, |
| 11969 | rdev->wiphy.wowlan_config->tcp)) |
| 11970 | goto nla_put_failure; |
| 11971 | |
| 11972 | if (nl80211_send_wowlan_nd( |
| 11973 | msg, |
| 11974 | rdev->wiphy.wowlan_config->nd_config)) |
| 11975 | goto nla_put_failure; |
| 11976 | |
| 11977 | nla_nest_end(msg, nl_wowlan); |
| 11978 | } |
| 11979 | |
| 11980 | genlmsg_end(msg, hdr); |
| 11981 | return genlmsg_reply(msg, info); |
| 11982 | |
| 11983 | nla_put_failure: |
| 11984 | nlmsg_free(msg); |
| 11985 | return -ENOBUFS; |
| 11986 | } |
| 11987 | |
| 11988 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 11989 | struct nlattr *attr, |
| 11990 | struct cfg80211_wowlan *trig) |
| 11991 | { |
| 11992 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 11993 | struct cfg80211_wowlan_tcp *cfg; |
| 11994 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 11995 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 11996 | u32 size; |
| 11997 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 11998 | int err, port; |
| 11999 | |
| 12000 | if (!rdev->wiphy.wowlan->tcp) |
| 12001 | return -EINVAL; |
| 12002 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12003 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 12004 | nl80211_wowlan_tcp_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12005 | if (err) |
| 12006 | return err; |
| 12007 | |
| 12008 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 12009 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 12010 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 12011 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 12012 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 12013 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 12014 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 12015 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 12016 | return -EINVAL; |
| 12017 | |
| 12018 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 12019 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
| 12020 | return -EINVAL; |
| 12021 | |
| 12022 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
| 12023 | rdev->wiphy.wowlan->tcp->data_interval_max || |
| 12024 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
| 12025 | return -EINVAL; |
| 12026 | |
| 12027 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 12028 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
| 12029 | return -EINVAL; |
| 12030 | |
| 12031 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 12032 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 12033 | return -EINVAL; |
| 12034 | |
| 12035 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 12036 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12037 | |
| 12038 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12039 | tokens_size = tokln - sizeof(*tok); |
| 12040 | |
| 12041 | if (!tok->len || tokens_size % tok->len) |
| 12042 | return -EINVAL; |
| 12043 | if (!rdev->wiphy.wowlan->tcp->tok) |
| 12044 | return -EINVAL; |
| 12045 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
| 12046 | return -EINVAL; |
| 12047 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
| 12048 | return -EINVAL; |
| 12049 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
| 12050 | return -EINVAL; |
| 12051 | if (tok->offset + tok->len > data_size) |
| 12052 | return -EINVAL; |
| 12053 | } |
| 12054 | |
| 12055 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 12056 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 12057 | if (!rdev->wiphy.wowlan->tcp->seq) |
| 12058 | return -EINVAL; |
| 12059 | if (seq->len == 0 || seq->len > 4) |
| 12060 | return -EINVAL; |
| 12061 | if (seq->len + seq->offset > data_size) |
| 12062 | return -EINVAL; |
| 12063 | } |
| 12064 | |
| 12065 | size = sizeof(*cfg); |
| 12066 | size += data_size; |
| 12067 | size += wake_size + wake_mask_size; |
| 12068 | size += tokens_size; |
| 12069 | |
| 12070 | cfg = kzalloc(size, GFP_KERNEL); |
| 12071 | if (!cfg) |
| 12072 | return -ENOMEM; |
| 12073 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 12074 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 12075 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 12076 | ETH_ALEN); |
| 12077 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 12078 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 12079 | else |
| 12080 | port = 0; |
| 12081 | #ifdef CONFIG_INET |
| 12082 | /* allocate a socket and port for it and use it */ |
| 12083 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 12084 | IPPROTO_TCP, &cfg->sock, 1); |
| 12085 | if (err) { |
| 12086 | kfree(cfg); |
| 12087 | return err; |
| 12088 | } |
| 12089 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 12090 | sock_release(cfg->sock); |
| 12091 | kfree(cfg); |
| 12092 | return -EADDRINUSE; |
| 12093 | } |
| 12094 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 12095 | #else |
| 12096 | if (!port) { |
| 12097 | kfree(cfg); |
| 12098 | return -EINVAL; |
| 12099 | } |
| 12100 | cfg->src_port = port; |
| 12101 | #endif |
| 12102 | |
| 12103 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 12104 | cfg->payload_len = data_size; |
| 12105 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 12106 | memcpy((void *)cfg->payload, |
| 12107 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 12108 | data_size); |
| 12109 | if (seq) |
| 12110 | cfg->payload_seq = *seq; |
| 12111 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 12112 | cfg->wake_len = wake_size; |
| 12113 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 12114 | memcpy((void *)cfg->wake_data, |
| 12115 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 12116 | wake_size); |
| 12117 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 12118 | data_size + wake_size; |
| 12119 | memcpy((void *)cfg->wake_mask, |
| 12120 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 12121 | wake_mask_size); |
| 12122 | if (tok) { |
| 12123 | cfg->tokens_size = tokens_size; |
| 12124 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 12125 | } |
| 12126 | |
| 12127 | trig->tcp = cfg; |
| 12128 | |
| 12129 | return 0; |
| 12130 | } |
| 12131 | |
| 12132 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 12133 | const struct wiphy_wowlan_support *wowlan, |
| 12134 | struct nlattr *attr, |
| 12135 | struct cfg80211_wowlan *trig) |
| 12136 | { |
| 12137 | struct nlattr **tb; |
| 12138 | int err; |
| 12139 | |
| 12140 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 12141 | if (!tb) |
| 12142 | return -ENOMEM; |
| 12143 | |
| 12144 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 12145 | err = -EOPNOTSUPP; |
| 12146 | goto out; |
| 12147 | } |
| 12148 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12149 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 12150 | nl80211_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12151 | if (err) |
| 12152 | goto out; |
| 12153 | |
| 12154 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 12155 | wowlan->max_nd_match_sets); |
| 12156 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 12157 | if (err) |
| 12158 | trig->nd_config = NULL; |
| 12159 | |
| 12160 | out: |
| 12161 | kfree(tb); |
| 12162 | return err; |
| 12163 | } |
| 12164 | |
| 12165 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 12166 | { |
| 12167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12168 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 12169 | struct cfg80211_wowlan new_triggers = {}; |
| 12170 | struct cfg80211_wowlan *ntrig; |
| 12171 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
| 12172 | int err, i; |
| 12173 | bool prev_enabled = rdev->wiphy.wowlan_config; |
| 12174 | bool regular = false; |
| 12175 | |
| 12176 | if (!wowlan) |
| 12177 | return -EOPNOTSUPP; |
| 12178 | |
| 12179 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 12180 | cfg80211_rdev_free_wowlan(rdev); |
| 12181 | rdev->wiphy.wowlan_config = NULL; |
| 12182 | goto set_wakeup; |
| 12183 | } |
| 12184 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12185 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 12186 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 12187 | nl80211_wowlan_policy, info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12188 | if (err) |
| 12189 | return err; |
| 12190 | |
| 12191 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 12192 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 12193 | return -EINVAL; |
| 12194 | new_triggers.any = true; |
| 12195 | } |
| 12196 | |
| 12197 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 12198 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 12199 | return -EINVAL; |
| 12200 | new_triggers.disconnect = true; |
| 12201 | regular = true; |
| 12202 | } |
| 12203 | |
| 12204 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 12205 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 12206 | return -EINVAL; |
| 12207 | new_triggers.magic_pkt = true; |
| 12208 | regular = true; |
| 12209 | } |
| 12210 | |
| 12211 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 12212 | return -EINVAL; |
| 12213 | |
| 12214 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 12215 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 12216 | return -EINVAL; |
| 12217 | new_triggers.gtk_rekey_failure = true; |
| 12218 | regular = true; |
| 12219 | } |
| 12220 | |
| 12221 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 12222 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 12223 | return -EINVAL; |
| 12224 | new_triggers.eap_identity_req = true; |
| 12225 | regular = true; |
| 12226 | } |
| 12227 | |
| 12228 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 12229 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 12230 | return -EINVAL; |
| 12231 | new_triggers.four_way_handshake = true; |
| 12232 | regular = true; |
| 12233 | } |
| 12234 | |
| 12235 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 12236 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 12237 | return -EINVAL; |
| 12238 | new_triggers.rfkill_release = true; |
| 12239 | regular = true; |
| 12240 | } |
| 12241 | |
| 12242 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 12243 | struct nlattr *pat; |
| 12244 | int n_patterns = 0; |
| 12245 | int rem, pat_len, mask_len, pkt_offset; |
| 12246 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12247 | |
| 12248 | regular = true; |
| 12249 | |
| 12250 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12251 | rem) |
| 12252 | n_patterns++; |
| 12253 | if (n_patterns > wowlan->n_patterns) |
| 12254 | return -EINVAL; |
| 12255 | |
| 12256 | new_triggers.patterns = kcalloc(n_patterns, |
| 12257 | sizeof(new_triggers.patterns[0]), |
| 12258 | GFP_KERNEL); |
| 12259 | if (!new_triggers.patterns) |
| 12260 | return -ENOMEM; |
| 12261 | |
| 12262 | new_triggers.n_patterns = n_patterns; |
| 12263 | i = 0; |
| 12264 | |
| 12265 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12266 | rem) { |
| 12267 | u8 *mask_pat; |
| 12268 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12269 | err = nla_parse_nested_deprecated(pat_tb, |
| 12270 | MAX_NL80211_PKTPAT, |
| 12271 | pat, |
| 12272 | nl80211_packet_pattern_policy, |
| 12273 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12274 | if (err) |
| 12275 | goto error; |
| 12276 | |
| 12277 | err = -EINVAL; |
| 12278 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12279 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12280 | goto error; |
| 12281 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12282 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12283 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12284 | goto error; |
| 12285 | if (pat_len > wowlan->pattern_max_len || |
| 12286 | pat_len < wowlan->pattern_min_len) |
| 12287 | goto error; |
| 12288 | |
| 12289 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12290 | pkt_offset = 0; |
| 12291 | else |
| 12292 | pkt_offset = nla_get_u32( |
| 12293 | pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12294 | if (pkt_offset > wowlan->max_pkt_offset) |
| 12295 | goto error; |
| 12296 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 12297 | |
| 12298 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12299 | if (!mask_pat) { |
| 12300 | err = -ENOMEM; |
| 12301 | goto error; |
| 12302 | } |
| 12303 | new_triggers.patterns[i].mask = mask_pat; |
| 12304 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12305 | mask_len); |
| 12306 | mask_pat += mask_len; |
| 12307 | new_triggers.patterns[i].pattern = mask_pat; |
| 12308 | new_triggers.patterns[i].pattern_len = pat_len; |
| 12309 | memcpy(mask_pat, |
| 12310 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12311 | pat_len); |
| 12312 | i++; |
| 12313 | } |
| 12314 | } |
| 12315 | |
| 12316 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 12317 | regular = true; |
| 12318 | err = nl80211_parse_wowlan_tcp( |
| 12319 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 12320 | &new_triggers); |
| 12321 | if (err) |
| 12322 | goto error; |
| 12323 | } |
| 12324 | |
| 12325 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
| 12326 | regular = true; |
| 12327 | err = nl80211_parse_wowlan_nd( |
| 12328 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 12329 | &new_triggers); |
| 12330 | if (err) |
| 12331 | goto error; |
| 12332 | } |
| 12333 | |
| 12334 | /* The 'any' trigger means the device continues operating more or less |
| 12335 | * as in its normal operation mode and wakes up the host on most of the |
| 12336 | * normal interrupts (like packet RX, ...) |
| 12337 | * It therefore makes little sense to combine with the more constrained |
| 12338 | * wakeup trigger modes. |
| 12339 | */ |
| 12340 | if (new_triggers.any && regular) { |
| 12341 | err = -EINVAL; |
| 12342 | goto error; |
| 12343 | } |
| 12344 | |
| 12345 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 12346 | if (!ntrig) { |
| 12347 | err = -ENOMEM; |
| 12348 | goto error; |
| 12349 | } |
| 12350 | cfg80211_rdev_free_wowlan(rdev); |
| 12351 | rdev->wiphy.wowlan_config = ntrig; |
| 12352 | |
| 12353 | set_wakeup: |
| 12354 | if (rdev->ops->set_wakeup && |
| 12355 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 12356 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
| 12357 | |
| 12358 | return 0; |
| 12359 | error: |
| 12360 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 12361 | kfree(new_triggers.patterns[i].mask); |
| 12362 | kfree(new_triggers.patterns); |
| 12363 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 12364 | sock_release(new_triggers.tcp->sock); |
| 12365 | kfree(new_triggers.tcp); |
| 12366 | kfree(new_triggers.nd_config); |
| 12367 | return err; |
| 12368 | } |
| 12369 | #endif |
| 12370 | |
| 12371 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 12372 | struct cfg80211_registered_device *rdev) |
| 12373 | { |
| 12374 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 12375 | int i, j, pat_len; |
| 12376 | struct cfg80211_coalesce_rules *rule; |
| 12377 | |
| 12378 | if (!rdev->coalesce->n_rules) |
| 12379 | return 0; |
| 12380 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12381 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12382 | if (!nl_rules) |
| 12383 | return -ENOBUFS; |
| 12384 | |
| 12385 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12386 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12387 | if (!nl_rule) |
| 12388 | return -ENOBUFS; |
| 12389 | |
| 12390 | rule = &rdev->coalesce->rules[i]; |
| 12391 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 12392 | rule->delay)) |
| 12393 | return -ENOBUFS; |
| 12394 | |
| 12395 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 12396 | rule->condition)) |
| 12397 | return -ENOBUFS; |
| 12398 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12399 | nl_pats = nla_nest_start_noflag(msg, |
| 12400 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12401 | if (!nl_pats) |
| 12402 | return -ENOBUFS; |
| 12403 | |
| 12404 | for (j = 0; j < rule->n_patterns; j++) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12405 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12406 | if (!nl_pat) |
| 12407 | return -ENOBUFS; |
| 12408 | pat_len = rule->patterns[j].pattern_len; |
| 12409 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 12410 | DIV_ROUND_UP(pat_len, 8), |
| 12411 | rule->patterns[j].mask) || |
| 12412 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12413 | rule->patterns[j].pattern) || |
| 12414 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 12415 | rule->patterns[j].pkt_offset)) |
| 12416 | return -ENOBUFS; |
| 12417 | nla_nest_end(msg, nl_pat); |
| 12418 | } |
| 12419 | nla_nest_end(msg, nl_pats); |
| 12420 | nla_nest_end(msg, nl_rule); |
| 12421 | } |
| 12422 | nla_nest_end(msg, nl_rules); |
| 12423 | |
| 12424 | return 0; |
| 12425 | } |
| 12426 | |
| 12427 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12428 | { |
| 12429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12430 | struct sk_buff *msg; |
| 12431 | void *hdr; |
| 12432 | |
| 12433 | if (!rdev->wiphy.coalesce) |
| 12434 | return -EOPNOTSUPP; |
| 12435 | |
| 12436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12437 | if (!msg) |
| 12438 | return -ENOMEM; |
| 12439 | |
| 12440 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12441 | NL80211_CMD_GET_COALESCE); |
| 12442 | if (!hdr) |
| 12443 | goto nla_put_failure; |
| 12444 | |
| 12445 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12446 | goto nla_put_failure; |
| 12447 | |
| 12448 | genlmsg_end(msg, hdr); |
| 12449 | return genlmsg_reply(msg, info); |
| 12450 | |
| 12451 | nla_put_failure: |
| 12452 | nlmsg_free(msg); |
| 12453 | return -ENOBUFS; |
| 12454 | } |
| 12455 | |
| 12456 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12457 | { |
| 12458 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12459 | int i, j; |
| 12460 | struct cfg80211_coalesce_rules *rule; |
| 12461 | |
| 12462 | if (!coalesce) |
| 12463 | return; |
| 12464 | |
| 12465 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12466 | rule = &coalesce->rules[i]; |
| 12467 | for (j = 0; j < rule->n_patterns; j++) |
| 12468 | kfree(rule->patterns[j].mask); |
| 12469 | kfree(rule->patterns); |
| 12470 | } |
| 12471 | kfree(coalesce->rules); |
| 12472 | kfree(coalesce); |
| 12473 | rdev->coalesce = NULL; |
| 12474 | } |
| 12475 | |
| 12476 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12477 | struct nlattr *rule, |
| 12478 | struct cfg80211_coalesce_rules *new_rule) |
| 12479 | { |
| 12480 | int err, i; |
| 12481 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12482 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12483 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12484 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12485 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12486 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12487 | rule, nl80211_coalesce_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12488 | if (err) |
| 12489 | return err; |
| 12490 | |
| 12491 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12492 | new_rule->delay = |
| 12493 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12494 | if (new_rule->delay > coalesce->max_delay) |
| 12495 | return -EINVAL; |
| 12496 | |
| 12497 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12498 | new_rule->condition = |
| 12499 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12500 | |
| 12501 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12502 | return -EINVAL; |
| 12503 | |
| 12504 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12505 | rem) |
| 12506 | n_patterns++; |
| 12507 | if (n_patterns > coalesce->n_patterns) |
| 12508 | return -EINVAL; |
| 12509 | |
| 12510 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12511 | GFP_KERNEL); |
| 12512 | if (!new_rule->patterns) |
| 12513 | return -ENOMEM; |
| 12514 | |
| 12515 | new_rule->n_patterns = n_patterns; |
| 12516 | i = 0; |
| 12517 | |
| 12518 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12519 | rem) { |
| 12520 | u8 *mask_pat; |
| 12521 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12522 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12523 | pat, |
| 12524 | nl80211_packet_pattern_policy, |
| 12525 | NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12526 | if (err) |
| 12527 | return err; |
| 12528 | |
| 12529 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12530 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12531 | return -EINVAL; |
| 12532 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12533 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12534 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12535 | return -EINVAL; |
| 12536 | if (pat_len > coalesce->pattern_max_len || |
| 12537 | pat_len < coalesce->pattern_min_len) |
| 12538 | return -EINVAL; |
| 12539 | |
| 12540 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12541 | pkt_offset = 0; |
| 12542 | else |
| 12543 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12544 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12545 | return -EINVAL; |
| 12546 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12547 | |
| 12548 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12549 | if (!mask_pat) |
| 12550 | return -ENOMEM; |
| 12551 | |
| 12552 | new_rule->patterns[i].mask = mask_pat; |
| 12553 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12554 | mask_len); |
| 12555 | |
| 12556 | mask_pat += mask_len; |
| 12557 | new_rule->patterns[i].pattern = mask_pat; |
| 12558 | new_rule->patterns[i].pattern_len = pat_len; |
| 12559 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12560 | pat_len); |
| 12561 | i++; |
| 12562 | } |
| 12563 | |
| 12564 | return 0; |
| 12565 | } |
| 12566 | |
| 12567 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12568 | { |
| 12569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12570 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12571 | struct cfg80211_coalesce new_coalesce = {}; |
| 12572 | struct cfg80211_coalesce *n_coalesce; |
| 12573 | int err, rem_rule, n_rules = 0, i, j; |
| 12574 | struct nlattr *rule; |
| 12575 | struct cfg80211_coalesce_rules *tmp_rule; |
| 12576 | |
| 12577 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 12578 | return -EOPNOTSUPP; |
| 12579 | |
| 12580 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 12581 | cfg80211_rdev_free_coalesce(rdev); |
| 12582 | rdev_set_coalesce(rdev, NULL); |
| 12583 | return 0; |
| 12584 | } |
| 12585 | |
| 12586 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12587 | rem_rule) |
| 12588 | n_rules++; |
| 12589 | if (n_rules > coalesce->n_rules) |
| 12590 | return -EINVAL; |
| 12591 | |
| 12592 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 12593 | GFP_KERNEL); |
| 12594 | if (!new_coalesce.rules) |
| 12595 | return -ENOMEM; |
| 12596 | |
| 12597 | new_coalesce.n_rules = n_rules; |
| 12598 | i = 0; |
| 12599 | |
| 12600 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12601 | rem_rule) { |
| 12602 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 12603 | &new_coalesce.rules[i]); |
| 12604 | if (err) |
| 12605 | goto error; |
| 12606 | |
| 12607 | i++; |
| 12608 | } |
| 12609 | |
| 12610 | err = rdev_set_coalesce(rdev, &new_coalesce); |
| 12611 | if (err) |
| 12612 | goto error; |
| 12613 | |
| 12614 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 12615 | if (!n_coalesce) { |
| 12616 | err = -ENOMEM; |
| 12617 | goto error; |
| 12618 | } |
| 12619 | cfg80211_rdev_free_coalesce(rdev); |
| 12620 | rdev->coalesce = n_coalesce; |
| 12621 | |
| 12622 | return 0; |
| 12623 | error: |
| 12624 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 12625 | tmp_rule = &new_coalesce.rules[i]; |
| 12626 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 12627 | kfree(tmp_rule->patterns[j].mask); |
| 12628 | kfree(tmp_rule->patterns); |
| 12629 | } |
| 12630 | kfree(new_coalesce.rules); |
| 12631 | |
| 12632 | return err; |
| 12633 | } |
| 12634 | |
| 12635 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 12636 | { |
| 12637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12638 | struct net_device *dev = info->user_ptr[1]; |
| 12639 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12640 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 12641 | struct cfg80211_gtk_rekey_data rekey_data = {}; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12642 | int err; |
| 12643 | |
| 12644 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 12645 | return -EINVAL; |
| 12646 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12647 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 12648 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 12649 | nl80211_rekey_policy, info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12650 | if (err) |
| 12651 | return err; |
| 12652 | |
| 12653 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 12654 | !tb[NL80211_REKEY_DATA_KCK]) |
| 12655 | return -EINVAL; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12656 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
| 12657 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12658 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12659 | return -ERANGE; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12660 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
| 12661 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12662 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12663 | return -ERANGE; |
| 12664 | |
| 12665 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 12666 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 12667 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12668 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 12669 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); |
| 12670 | if (tb[NL80211_REKEY_DATA_AKM]) |
| 12671 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12672 | |
| 12673 | wdev_lock(wdev); |
| 12674 | if (!wdev->current_bss) { |
| 12675 | err = -ENOTCONN; |
| 12676 | goto out; |
| 12677 | } |
| 12678 | |
| 12679 | if (!rdev->ops->set_rekey_data) { |
| 12680 | err = -EOPNOTSUPP; |
| 12681 | goto out; |
| 12682 | } |
| 12683 | |
| 12684 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
| 12685 | out: |
| 12686 | wdev_unlock(wdev); |
| 12687 | return err; |
| 12688 | } |
| 12689 | |
| 12690 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 12691 | struct genl_info *info) |
| 12692 | { |
| 12693 | struct net_device *dev = info->user_ptr[1]; |
| 12694 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12695 | |
| 12696 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12697 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12698 | return -EINVAL; |
| 12699 | |
| 12700 | if (wdev->ap_unexpected_nlportid) |
| 12701 | return -EBUSY; |
| 12702 | |
| 12703 | wdev->ap_unexpected_nlportid = info->snd_portid; |
| 12704 | return 0; |
| 12705 | } |
| 12706 | |
| 12707 | static int nl80211_probe_client(struct sk_buff *skb, |
| 12708 | struct genl_info *info) |
| 12709 | { |
| 12710 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12711 | struct net_device *dev = info->user_ptr[1]; |
| 12712 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12713 | struct sk_buff *msg; |
| 12714 | void *hdr; |
| 12715 | const u8 *addr; |
| 12716 | u64 cookie; |
| 12717 | int err; |
| 12718 | |
| 12719 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12720 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12721 | return -EOPNOTSUPP; |
| 12722 | |
| 12723 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12724 | return -EINVAL; |
| 12725 | |
| 12726 | if (!rdev->ops->probe_client) |
| 12727 | return -EOPNOTSUPP; |
| 12728 | |
| 12729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12730 | if (!msg) |
| 12731 | return -ENOMEM; |
| 12732 | |
| 12733 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12734 | NL80211_CMD_PROBE_CLIENT); |
| 12735 | if (!hdr) { |
| 12736 | err = -ENOBUFS; |
| 12737 | goto free_msg; |
| 12738 | } |
| 12739 | |
| 12740 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12741 | |
| 12742 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
| 12743 | if (err) |
| 12744 | goto free_msg; |
| 12745 | |
| 12746 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12747 | NL80211_ATTR_PAD)) |
| 12748 | goto nla_put_failure; |
| 12749 | |
| 12750 | genlmsg_end(msg, hdr); |
| 12751 | |
| 12752 | return genlmsg_reply(msg, info); |
| 12753 | |
| 12754 | nla_put_failure: |
| 12755 | err = -ENOBUFS; |
| 12756 | free_msg: |
| 12757 | nlmsg_free(msg); |
| 12758 | return err; |
| 12759 | } |
| 12760 | |
| 12761 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 12762 | { |
| 12763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12764 | struct cfg80211_beacon_registration *reg, *nreg; |
| 12765 | int rv; |
| 12766 | |
| 12767 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 12768 | return -EOPNOTSUPP; |
| 12769 | |
| 12770 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 12771 | if (!nreg) |
| 12772 | return -ENOMEM; |
| 12773 | |
| 12774 | /* First, check if already registered. */ |
| 12775 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12776 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12777 | if (reg->nlportid == info->snd_portid) { |
| 12778 | rv = -EALREADY; |
| 12779 | goto out_err; |
| 12780 | } |
| 12781 | } |
| 12782 | /* Add it to the list */ |
| 12783 | nreg->nlportid = info->snd_portid; |
| 12784 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 12785 | |
| 12786 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12787 | |
| 12788 | return 0; |
| 12789 | out_err: |
| 12790 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12791 | kfree(nreg); |
| 12792 | return rv; |
| 12793 | } |
| 12794 | |
| 12795 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12796 | { |
| 12797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12798 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12799 | int err; |
| 12800 | |
| 12801 | if (!rdev->ops->start_p2p_device) |
| 12802 | return -EOPNOTSUPP; |
| 12803 | |
| 12804 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12805 | return -EOPNOTSUPP; |
| 12806 | |
| 12807 | if (wdev_running(wdev)) |
| 12808 | return 0; |
| 12809 | |
| 12810 | if (rfkill_blocked(rdev->rfkill)) |
| 12811 | return -ERFKILL; |
| 12812 | |
| 12813 | err = rdev_start_p2p_device(rdev, wdev); |
| 12814 | if (err) |
| 12815 | return err; |
| 12816 | |
| 12817 | wdev->is_running = true; |
| 12818 | rdev->opencount++; |
| 12819 | |
| 12820 | return 0; |
| 12821 | } |
| 12822 | |
| 12823 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12824 | { |
| 12825 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12826 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12827 | |
| 12828 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12829 | return -EOPNOTSUPP; |
| 12830 | |
| 12831 | if (!rdev->ops->stop_p2p_device) |
| 12832 | return -EOPNOTSUPP; |
| 12833 | |
| 12834 | cfg80211_stop_p2p_device(rdev, wdev); |
| 12835 | |
| 12836 | return 0; |
| 12837 | } |
| 12838 | |
| 12839 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 12840 | { |
| 12841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12842 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12843 | struct cfg80211_nan_conf conf = {}; |
| 12844 | int err; |
| 12845 | |
| 12846 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12847 | return -EOPNOTSUPP; |
| 12848 | |
| 12849 | if (wdev_running(wdev)) |
| 12850 | return -EEXIST; |
| 12851 | |
| 12852 | if (rfkill_blocked(rdev->rfkill)) |
| 12853 | return -ERFKILL; |
| 12854 | |
| 12855 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 12856 | return -EINVAL; |
| 12857 | |
| 12858 | conf.master_pref = |
| 12859 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12860 | |
| 12861 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12862 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12863 | |
| 12864 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12865 | return -EOPNOTSUPP; |
| 12866 | |
| 12867 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12868 | return -EINVAL; |
| 12869 | |
| 12870 | conf.bands = bands; |
| 12871 | } |
| 12872 | |
| 12873 | err = rdev_start_nan(rdev, wdev, &conf); |
| 12874 | if (err) |
| 12875 | return err; |
| 12876 | |
| 12877 | wdev->is_running = true; |
| 12878 | rdev->opencount++; |
| 12879 | |
| 12880 | return 0; |
| 12881 | } |
| 12882 | |
| 12883 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 12884 | { |
| 12885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12886 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12887 | |
| 12888 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12889 | return -EOPNOTSUPP; |
| 12890 | |
| 12891 | cfg80211_stop_nan(rdev, wdev); |
| 12892 | |
| 12893 | return 0; |
| 12894 | } |
| 12895 | |
| 12896 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 12897 | { |
| 12898 | struct nlattr *attr; |
| 12899 | int len = 0, n_entries = 0, rem; |
| 12900 | |
| 12901 | nla_for_each_nested(attr, filter_attr, rem) { |
| 12902 | len += nla_len(attr); |
| 12903 | n_entries++; |
| 12904 | } |
| 12905 | |
| 12906 | if (len >= U8_MAX) |
| 12907 | return -EINVAL; |
| 12908 | |
| 12909 | return n_entries; |
| 12910 | } |
| 12911 | |
| 12912 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 12913 | struct cfg80211_nan_func *func, |
| 12914 | bool tx) |
| 12915 | { |
| 12916 | struct nlattr *attr; |
| 12917 | int n_entries, rem, i; |
| 12918 | struct cfg80211_nan_func_filter *filter; |
| 12919 | |
| 12920 | n_entries = validate_nan_filter(attr_filter); |
| 12921 | if (n_entries < 0) |
| 12922 | return n_entries; |
| 12923 | |
| 12924 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 12925 | |
| 12926 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 12927 | if (!filter) |
| 12928 | return -ENOMEM; |
| 12929 | |
| 12930 | i = 0; |
| 12931 | nla_for_each_nested(attr, attr_filter, rem) { |
| 12932 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12933 | if (!filter[i].filter) |
| 12934 | goto err; |
| 12935 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12936 | filter[i].len = nla_len(attr); |
| 12937 | i++; |
| 12938 | } |
| 12939 | if (tx) { |
| 12940 | func->num_tx_filters = n_entries; |
| 12941 | func->tx_filters = filter; |
| 12942 | } else { |
| 12943 | func->num_rx_filters = n_entries; |
| 12944 | func->rx_filters = filter; |
| 12945 | } |
| 12946 | |
| 12947 | return 0; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12948 | |
| 12949 | err: |
| 12950 | i = 0; |
| 12951 | nla_for_each_nested(attr, attr_filter, rem) { |
| 12952 | kfree(filter[i].filter); |
| 12953 | i++; |
| 12954 | } |
| 12955 | kfree(filter); |
| 12956 | return -ENOMEM; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12957 | } |
| 12958 | |
| 12959 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 12960 | struct genl_info *info) |
| 12961 | { |
| 12962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12963 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12964 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 12965 | struct cfg80211_nan_func *func; |
| 12966 | struct sk_buff *msg = NULL; |
| 12967 | void *hdr = NULL; |
| 12968 | int err = 0; |
| 12969 | |
| 12970 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12971 | return -EOPNOTSUPP; |
| 12972 | |
| 12973 | if (!wdev_running(wdev)) |
| 12974 | return -ENOTCONN; |
| 12975 | |
| 12976 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 12977 | return -EINVAL; |
| 12978 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12979 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 12980 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 12981 | nl80211_nan_func_policy, |
| 12982 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12983 | if (err) |
| 12984 | return err; |
| 12985 | |
| 12986 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 12987 | if (!func) |
| 12988 | return -ENOMEM; |
| 12989 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 12990 | func->cookie = cfg80211_assign_cookie(rdev); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12991 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12992 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12993 | err = -EINVAL; |
| 12994 | goto out; |
| 12995 | } |
| 12996 | |
| 12997 | |
| 12998 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 12999 | |
| 13000 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 13001 | err = -EINVAL; |
| 13002 | goto out; |
| 13003 | } |
| 13004 | |
| 13005 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 13006 | sizeof(func->service_id)); |
| 13007 | |
| 13008 | func->close_range = |
| 13009 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 13010 | |
| 13011 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 13012 | func->serv_spec_info_len = |
| 13013 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 13014 | func->serv_spec_info = |
| 13015 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 13016 | func->serv_spec_info_len, |
| 13017 | GFP_KERNEL); |
| 13018 | if (!func->serv_spec_info) { |
| 13019 | err = -ENOMEM; |
| 13020 | goto out; |
| 13021 | } |
| 13022 | } |
| 13023 | |
| 13024 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 13025 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 13026 | |
| 13027 | switch (func->type) { |
| 13028 | case NL80211_NAN_FUNC_PUBLISH: |
| 13029 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 13030 | err = -EINVAL; |
| 13031 | goto out; |
| 13032 | } |
| 13033 | |
| 13034 | func->publish_type = |
| 13035 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 13036 | func->publish_bcast = |
| 13037 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 13038 | |
| 13039 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 13040 | func->publish_bcast) { |
| 13041 | err = -EINVAL; |
| 13042 | goto out; |
| 13043 | } |
| 13044 | break; |
| 13045 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 13046 | func->subscribe_active = |
| 13047 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 13048 | break; |
| 13049 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 13050 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 13051 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 13052 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
| 13053 | err = -EINVAL; |
| 13054 | goto out; |
| 13055 | } |
| 13056 | |
| 13057 | func->followup_id = |
| 13058 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 13059 | func->followup_reqid = |
| 13060 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 13061 | memcpy(func->followup_dest.addr, |
| 13062 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 13063 | sizeof(func->followup_dest.addr)); |
| 13064 | if (func->ttl) { |
| 13065 | err = -EINVAL; |
| 13066 | goto out; |
| 13067 | } |
| 13068 | break; |
| 13069 | default: |
| 13070 | err = -EINVAL; |
| 13071 | goto out; |
| 13072 | } |
| 13073 | |
| 13074 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 13075 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 13076 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13077 | err = nla_parse_nested_deprecated(srf_tb, |
| 13078 | NL80211_NAN_SRF_ATTR_MAX, |
| 13079 | tb[NL80211_NAN_FUNC_SRF], |
| 13080 | nl80211_nan_srf_policy, |
| 13081 | info->extack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13082 | if (err) |
| 13083 | goto out; |
| 13084 | |
| 13085 | func->srf_include = |
| 13086 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 13087 | |
| 13088 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 13089 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 13090 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 13091 | err = -EINVAL; |
| 13092 | goto out; |
| 13093 | } |
| 13094 | |
| 13095 | func->srf_bf_len = |
| 13096 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 13097 | func->srf_bf = |
| 13098 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 13099 | func->srf_bf_len, GFP_KERNEL); |
| 13100 | if (!func->srf_bf) { |
| 13101 | err = -ENOMEM; |
| 13102 | goto out; |
| 13103 | } |
| 13104 | |
| 13105 | func->srf_bf_idx = |
| 13106 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 13107 | } else { |
| 13108 | struct nlattr *attr, *mac_attr = |
| 13109 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 13110 | int n_entries, rem, i = 0; |
| 13111 | |
| 13112 | if (!mac_attr) { |
| 13113 | err = -EINVAL; |
| 13114 | goto out; |
| 13115 | } |
| 13116 | |
| 13117 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 13118 | if (n_entries <= 0) { |
| 13119 | err = -EINVAL; |
| 13120 | goto out; |
| 13121 | } |
| 13122 | |
| 13123 | func->srf_num_macs = n_entries; |
| 13124 | func->srf_macs = |
| 13125 | kcalloc(n_entries, sizeof(*func->srf_macs), |
| 13126 | GFP_KERNEL); |
| 13127 | if (!func->srf_macs) { |
| 13128 | err = -ENOMEM; |
| 13129 | goto out; |
| 13130 | } |
| 13131 | |
| 13132 | nla_for_each_nested(attr, mac_attr, rem) |
| 13133 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 13134 | sizeof(*func->srf_macs)); |
| 13135 | } |
| 13136 | } |
| 13137 | |
| 13138 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 13139 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 13140 | func, true); |
| 13141 | if (err) |
| 13142 | goto out; |
| 13143 | } |
| 13144 | |
| 13145 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 13146 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 13147 | func, false); |
| 13148 | if (err) |
| 13149 | goto out; |
| 13150 | } |
| 13151 | |
| 13152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13153 | if (!msg) { |
| 13154 | err = -ENOMEM; |
| 13155 | goto out; |
| 13156 | } |
| 13157 | |
| 13158 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13159 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 13160 | /* This can't really happen - we just allocated 4KB */ |
| 13161 | if (WARN_ON(!hdr)) { |
| 13162 | err = -ENOMEM; |
| 13163 | goto out; |
| 13164 | } |
| 13165 | |
| 13166 | err = rdev_add_nan_func(rdev, wdev, func); |
| 13167 | out: |
| 13168 | if (err < 0) { |
| 13169 | cfg80211_free_nan_func(func); |
| 13170 | nlmsg_free(msg); |
| 13171 | return err; |
| 13172 | } |
| 13173 | |
| 13174 | /* propagate the instance id and cookie to userspace */ |
| 13175 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 13176 | NL80211_ATTR_PAD)) |
| 13177 | goto nla_put_failure; |
| 13178 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13179 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13180 | if (!func_attr) |
| 13181 | goto nla_put_failure; |
| 13182 | |
| 13183 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 13184 | func->instance_id)) |
| 13185 | goto nla_put_failure; |
| 13186 | |
| 13187 | nla_nest_end(msg, func_attr); |
| 13188 | |
| 13189 | genlmsg_end(msg, hdr); |
| 13190 | return genlmsg_reply(msg, info); |
| 13191 | |
| 13192 | nla_put_failure: |
| 13193 | nlmsg_free(msg); |
| 13194 | return -ENOBUFS; |
| 13195 | } |
| 13196 | |
| 13197 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 13198 | struct genl_info *info) |
| 13199 | { |
| 13200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13201 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13202 | u64 cookie; |
| 13203 | |
| 13204 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13205 | return -EOPNOTSUPP; |
| 13206 | |
| 13207 | if (!wdev_running(wdev)) |
| 13208 | return -ENOTCONN; |
| 13209 | |
| 13210 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 13211 | return -EINVAL; |
| 13212 | |
| 13213 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 13214 | |
| 13215 | rdev_del_nan_func(rdev, wdev, cookie); |
| 13216 | |
| 13217 | return 0; |
| 13218 | } |
| 13219 | |
| 13220 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 13221 | struct genl_info *info) |
| 13222 | { |
| 13223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13224 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13225 | struct cfg80211_nan_conf conf = {}; |
| 13226 | u32 changed = 0; |
| 13227 | |
| 13228 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13229 | return -EOPNOTSUPP; |
| 13230 | |
| 13231 | if (!wdev_running(wdev)) |
| 13232 | return -ENOTCONN; |
| 13233 | |
| 13234 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 13235 | conf.master_pref = |
| 13236 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 13237 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 13238 | return -EINVAL; |
| 13239 | |
| 13240 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 13241 | } |
| 13242 | |
| 13243 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 13244 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 13245 | |
| 13246 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 13247 | return -EOPNOTSUPP; |
| 13248 | |
| 13249 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 13250 | return -EINVAL; |
| 13251 | |
| 13252 | conf.bands = bands; |
| 13253 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
| 13254 | } |
| 13255 | |
| 13256 | if (!changed) |
| 13257 | return -EINVAL; |
| 13258 | |
| 13259 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 13260 | } |
| 13261 | |
| 13262 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 13263 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 13264 | { |
| 13265 | struct wiphy *wiphy = wdev->wiphy; |
| 13266 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13267 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 13268 | struct sk_buff *msg; |
| 13269 | void *hdr; |
| 13270 | |
| 13271 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 13272 | return; |
| 13273 | |
| 13274 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13275 | if (!msg) |
| 13276 | return; |
| 13277 | |
| 13278 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 13279 | if (!hdr) { |
| 13280 | nlmsg_free(msg); |
| 13281 | return; |
| 13282 | } |
| 13283 | |
| 13284 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13285 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13286 | wdev->netdev->ifindex)) || |
| 13287 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13288 | NL80211_ATTR_PAD)) |
| 13289 | goto nla_put_failure; |
| 13290 | |
| 13291 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 13292 | NL80211_ATTR_PAD) || |
| 13293 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 13294 | goto nla_put_failure; |
| 13295 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13296 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13297 | if (!match_attr) |
| 13298 | goto nla_put_failure; |
| 13299 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13300 | local_func_attr = nla_nest_start_noflag(msg, |
| 13301 | NL80211_NAN_MATCH_FUNC_LOCAL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13302 | if (!local_func_attr) |
| 13303 | goto nla_put_failure; |
| 13304 | |
| 13305 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 13306 | goto nla_put_failure; |
| 13307 | |
| 13308 | nla_nest_end(msg, local_func_attr); |
| 13309 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13310 | peer_func_attr = nla_nest_start_noflag(msg, |
| 13311 | NL80211_NAN_MATCH_FUNC_PEER); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13312 | if (!peer_func_attr) |
| 13313 | goto nla_put_failure; |
| 13314 | |
| 13315 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 13316 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 13317 | goto nla_put_failure; |
| 13318 | |
| 13319 | if (match->info && match->info_len && |
| 13320 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 13321 | match->info)) |
| 13322 | goto nla_put_failure; |
| 13323 | |
| 13324 | nla_nest_end(msg, peer_func_attr); |
| 13325 | nla_nest_end(msg, match_attr); |
| 13326 | genlmsg_end(msg, hdr); |
| 13327 | |
| 13328 | if (!wdev->owner_nlportid) |
| 13329 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13330 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13331 | else |
| 13332 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13333 | wdev->owner_nlportid); |
| 13334 | |
| 13335 | return; |
| 13336 | |
| 13337 | nla_put_failure: |
| 13338 | nlmsg_free(msg); |
| 13339 | } |
| 13340 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 13341 | |
| 13342 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 13343 | u8 inst_id, |
| 13344 | enum nl80211_nan_func_term_reason reason, |
| 13345 | u64 cookie, gfp_t gfp) |
| 13346 | { |
| 13347 | struct wiphy *wiphy = wdev->wiphy; |
| 13348 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13349 | struct sk_buff *msg; |
| 13350 | struct nlattr *func_attr; |
| 13351 | void *hdr; |
| 13352 | |
| 13353 | if (WARN_ON(!inst_id)) |
| 13354 | return; |
| 13355 | |
| 13356 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13357 | if (!msg) |
| 13358 | return; |
| 13359 | |
| 13360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 13361 | if (!hdr) { |
| 13362 | nlmsg_free(msg); |
| 13363 | return; |
| 13364 | } |
| 13365 | |
| 13366 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13367 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13368 | wdev->netdev->ifindex)) || |
| 13369 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13370 | NL80211_ATTR_PAD)) |
| 13371 | goto nla_put_failure; |
| 13372 | |
| 13373 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13374 | NL80211_ATTR_PAD)) |
| 13375 | goto nla_put_failure; |
| 13376 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13377 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13378 | if (!func_attr) |
| 13379 | goto nla_put_failure; |
| 13380 | |
| 13381 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 13382 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 13383 | goto nla_put_failure; |
| 13384 | |
| 13385 | nla_nest_end(msg, func_attr); |
| 13386 | genlmsg_end(msg, hdr); |
| 13387 | |
| 13388 | if (!wdev->owner_nlportid) |
| 13389 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13390 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13391 | else |
| 13392 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13393 | wdev->owner_nlportid); |
| 13394 | |
| 13395 | return; |
| 13396 | |
| 13397 | nla_put_failure: |
| 13398 | nlmsg_free(msg); |
| 13399 | } |
| 13400 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 13401 | |
| 13402 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 13403 | struct genl_info *info) |
| 13404 | { |
| 13405 | void *hdr; |
| 13406 | struct sk_buff *msg; |
| 13407 | |
| 13408 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13409 | if (!msg) |
| 13410 | return -ENOMEM; |
| 13411 | |
| 13412 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13413 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 13414 | if (!hdr) |
| 13415 | goto nla_put_failure; |
| 13416 | |
| 13417 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 13418 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 13419 | goto nla_put_failure; |
| 13420 | |
| 13421 | genlmsg_end(msg, hdr); |
| 13422 | return genlmsg_reply(msg, info); |
| 13423 | |
| 13424 | nla_put_failure: |
| 13425 | kfree_skb(msg); |
| 13426 | return -ENOBUFS; |
| 13427 | } |
| 13428 | |
| 13429 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 13430 | { |
| 13431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13432 | struct cfg80211_update_ft_ies_params ft_params; |
| 13433 | struct net_device *dev = info->user_ptr[1]; |
| 13434 | |
| 13435 | if (!rdev->ops->update_ft_ies) |
| 13436 | return -EOPNOTSUPP; |
| 13437 | |
| 13438 | if (!info->attrs[NL80211_ATTR_MDID] || |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13439 | !info->attrs[NL80211_ATTR_IE]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13440 | return -EINVAL; |
| 13441 | |
| 13442 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13443 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13444 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13445 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13446 | |
| 13447 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13448 | } |
| 13449 | |
| 13450 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13451 | struct genl_info *info) |
| 13452 | { |
| 13453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13454 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13455 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13456 | u16 duration; |
| 13457 | int ret; |
| 13458 | |
| 13459 | if (!rdev->ops->crit_proto_start) |
| 13460 | return -EOPNOTSUPP; |
| 13461 | |
| 13462 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13463 | return -EINVAL; |
| 13464 | |
| 13465 | if (rdev->crit_proto_nlportid) |
| 13466 | return -EBUSY; |
| 13467 | |
| 13468 | /* determine protocol if provided */ |
| 13469 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13470 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13471 | |
| 13472 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13473 | return -EINVAL; |
| 13474 | |
| 13475 | /* timeout must be provided */ |
| 13476 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13477 | return -EINVAL; |
| 13478 | |
| 13479 | duration = |
| 13480 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13481 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13482 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13483 | if (!ret) |
| 13484 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13485 | |
| 13486 | return ret; |
| 13487 | } |
| 13488 | |
| 13489 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13490 | struct genl_info *info) |
| 13491 | { |
| 13492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13493 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13494 | |
| 13495 | if (!rdev->ops->crit_proto_stop) |
| 13496 | return -EOPNOTSUPP; |
| 13497 | |
| 13498 | if (rdev->crit_proto_nlportid) { |
| 13499 | rdev->crit_proto_nlportid = 0; |
| 13500 | rdev_crit_proto_stop(rdev, wdev); |
| 13501 | } |
| 13502 | return 0; |
| 13503 | } |
| 13504 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13505 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13506 | struct nlattr *attr, |
| 13507 | struct netlink_ext_ack *extack) |
| 13508 | { |
| 13509 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13510 | if (attr->nla_type & NLA_F_NESTED) { |
| 13511 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13512 | "unexpected nested data"); |
| 13513 | return -EINVAL; |
| 13514 | } |
| 13515 | |
| 13516 | return 0; |
| 13517 | } |
| 13518 | |
| 13519 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13520 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13521 | return -EINVAL; |
| 13522 | } |
| 13523 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 13524 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13525 | } |
| 13526 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13527 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13528 | { |
| 13529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13530 | struct wireless_dev *wdev = |
| 13531 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 13532 | int i, err; |
| 13533 | u32 vid, subcmd; |
| 13534 | |
| 13535 | if (!rdev->wiphy.vendor_commands) |
| 13536 | return -EOPNOTSUPP; |
| 13537 | |
| 13538 | if (IS_ERR(wdev)) { |
| 13539 | err = PTR_ERR(wdev); |
| 13540 | if (err != -EINVAL) |
| 13541 | return err; |
| 13542 | wdev = NULL; |
| 13543 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13544 | return -EINVAL; |
| 13545 | } |
| 13546 | |
| 13547 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13548 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13549 | return -EINVAL; |
| 13550 | |
| 13551 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13552 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13553 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13554 | const struct wiphy_vendor_command *vcmd; |
| 13555 | void *data = NULL; |
| 13556 | int len = 0; |
| 13557 | |
| 13558 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13559 | |
| 13560 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13561 | continue; |
| 13562 | |
| 13563 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13564 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13565 | if (!wdev) |
| 13566 | return -EINVAL; |
| 13567 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13568 | !wdev->netdev) |
| 13569 | return -EINVAL; |
| 13570 | |
| 13571 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 13572 | if (!wdev_running(wdev)) |
| 13573 | return -ENETDOWN; |
| 13574 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13575 | } else { |
| 13576 | wdev = NULL; |
| 13577 | } |
| 13578 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 13579 | if (!vcmd->doit) |
| 13580 | return -EOPNOTSUPP; |
| 13581 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13582 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 13583 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 13584 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13585 | |
| 13586 | err = nl80211_vendor_check_policy(vcmd, |
| 13587 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 13588 | info->extack); |
| 13589 | if (err) |
| 13590 | return err; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13591 | } |
| 13592 | |
| 13593 | rdev->cur_cmd_info = info; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13594 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13595 | rdev->cur_cmd_info = NULL; |
| 13596 | return err; |
| 13597 | } |
| 13598 | |
| 13599 | return -EOPNOTSUPP; |
| 13600 | } |
| 13601 | |
| 13602 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 13603 | struct netlink_callback *cb, |
| 13604 | struct cfg80211_registered_device **rdev, |
| 13605 | struct wireless_dev **wdev) |
| 13606 | { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13607 | struct nlattr **attrbuf; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13608 | u32 vid, subcmd; |
| 13609 | unsigned int i; |
| 13610 | int vcmd_idx = -1; |
| 13611 | int err; |
| 13612 | void *data = NULL; |
| 13613 | unsigned int data_len = 0; |
| 13614 | |
| 13615 | if (cb->args[0]) { |
| 13616 | /* subtract the 1 again here */ |
| 13617 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 13618 | struct wireless_dev *tmp; |
| 13619 | |
| 13620 | if (!wiphy) |
| 13621 | return -ENODEV; |
| 13622 | *rdev = wiphy_to_rdev(wiphy); |
| 13623 | *wdev = NULL; |
| 13624 | |
| 13625 | if (cb->args[1]) { |
| 13626 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
| 13627 | if (tmp->identifier == cb->args[1] - 1) { |
| 13628 | *wdev = tmp; |
| 13629 | break; |
| 13630 | } |
| 13631 | } |
| 13632 | } |
| 13633 | |
| 13634 | /* keep rtnl locked in successful case */ |
| 13635 | return 0; |
| 13636 | } |
| 13637 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13638 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 13639 | if (!attrbuf) |
| 13640 | return -ENOMEM; |
| 13641 | |
| 13642 | err = nlmsg_parse_deprecated(cb->nlh, |
| 13643 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 13644 | attrbuf, nl80211_fam.maxattr, |
| 13645 | nl80211_policy, NULL); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13646 | if (err) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13647 | goto out; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13648 | |
| 13649 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13650 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 13651 | err = -EINVAL; |
| 13652 | goto out; |
| 13653 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13654 | |
| 13655 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
| 13656 | if (IS_ERR(*wdev)) |
| 13657 | *wdev = NULL; |
| 13658 | |
| 13659 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13660 | if (IS_ERR(*rdev)) { |
| 13661 | err = PTR_ERR(*rdev); |
| 13662 | goto out; |
| 13663 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13664 | |
| 13665 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 13666 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13667 | |
| 13668 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 13669 | const struct wiphy_vendor_command *vcmd; |
| 13670 | |
| 13671 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 13672 | |
| 13673 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13674 | continue; |
| 13675 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13676 | if (!vcmd->dumpit) { |
| 13677 | err = -EOPNOTSUPP; |
| 13678 | goto out; |
| 13679 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13680 | |
| 13681 | vcmd_idx = i; |
| 13682 | break; |
| 13683 | } |
| 13684 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13685 | if (vcmd_idx < 0) { |
| 13686 | err = -EOPNOTSUPP; |
| 13687 | goto out; |
| 13688 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13689 | |
| 13690 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 13691 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 13692 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13693 | |
| 13694 | err = nl80211_vendor_check_policy( |
| 13695 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 13696 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 13697 | cb->extack); |
| 13698 | if (err) |
| 13699 | goto out; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13700 | } |
| 13701 | |
| 13702 | /* 0 is the first index - add 1 to parse only once */ |
| 13703 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 13704 | /* add 1 to know if it was NULL */ |
| 13705 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 13706 | cb->args[2] = vcmd_idx; |
| 13707 | cb->args[3] = (unsigned long)data; |
| 13708 | cb->args[4] = data_len; |
| 13709 | |
| 13710 | /* keep rtnl locked in successful case */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13711 | err = 0; |
| 13712 | out: |
| 13713 | kfree(attrbuf); |
| 13714 | return err; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13715 | } |
| 13716 | |
| 13717 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 13718 | struct netlink_callback *cb) |
| 13719 | { |
| 13720 | struct cfg80211_registered_device *rdev; |
| 13721 | struct wireless_dev *wdev; |
| 13722 | unsigned int vcmd_idx; |
| 13723 | const struct wiphy_vendor_command *vcmd; |
| 13724 | void *data; |
| 13725 | int data_len; |
| 13726 | int err; |
| 13727 | struct nlattr *vendor_data; |
| 13728 | |
| 13729 | rtnl_lock(); |
| 13730 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 13731 | if (err) |
| 13732 | goto out; |
| 13733 | |
| 13734 | vcmd_idx = cb->args[2]; |
| 13735 | data = (void *)cb->args[3]; |
| 13736 | data_len = cb->args[4]; |
| 13737 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 13738 | |
| 13739 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13740 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13741 | if (!wdev) { |
| 13742 | err = -EINVAL; |
| 13743 | goto out; |
| 13744 | } |
| 13745 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13746 | !wdev->netdev) { |
| 13747 | err = -EINVAL; |
| 13748 | goto out; |
| 13749 | } |
| 13750 | |
| 13751 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 13752 | if (!wdev_running(wdev)) { |
| 13753 | err = -ENETDOWN; |
| 13754 | goto out; |
| 13755 | } |
| 13756 | } |
| 13757 | } |
| 13758 | |
| 13759 | while (1) { |
| 13760 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 13761 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 13762 | NL80211_CMD_VENDOR); |
| 13763 | if (!hdr) |
| 13764 | break; |
| 13765 | |
| 13766 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13767 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 13768 | wdev_id(wdev), |
| 13769 | NL80211_ATTR_PAD))) { |
| 13770 | genlmsg_cancel(skb, hdr); |
| 13771 | break; |
| 13772 | } |
| 13773 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13774 | vendor_data = nla_nest_start_noflag(skb, |
| 13775 | NL80211_ATTR_VENDOR_DATA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13776 | if (!vendor_data) { |
| 13777 | genlmsg_cancel(skb, hdr); |
| 13778 | break; |
| 13779 | } |
| 13780 | |
| 13781 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 13782 | (unsigned long *)&cb->args[5]); |
| 13783 | nla_nest_end(skb, vendor_data); |
| 13784 | |
| 13785 | if (err == -ENOBUFS || err == -ENOENT) { |
| 13786 | genlmsg_cancel(skb, hdr); |
| 13787 | break; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 13788 | } else if (err <= 0) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13789 | genlmsg_cancel(skb, hdr); |
| 13790 | goto out; |
| 13791 | } |
| 13792 | |
| 13793 | genlmsg_end(skb, hdr); |
| 13794 | } |
| 13795 | |
| 13796 | err = skb->len; |
| 13797 | out: |
| 13798 | rtnl_unlock(); |
| 13799 | return err; |
| 13800 | } |
| 13801 | |
| 13802 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 13803 | enum nl80211_commands cmd, |
| 13804 | enum nl80211_attrs attr, |
| 13805 | int approxlen) |
| 13806 | { |
| 13807 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13808 | |
| 13809 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13810 | return NULL; |
| 13811 | |
| 13812 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
| 13813 | rdev->cur_cmd_info->snd_portid, |
| 13814 | rdev->cur_cmd_info->snd_seq, |
| 13815 | cmd, attr, NULL, GFP_KERNEL); |
| 13816 | } |
| 13817 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 13818 | |
| 13819 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 13820 | { |
| 13821 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 13822 | void *hdr = ((void **)skb->cb)[1]; |
| 13823 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 13824 | |
| 13825 | /* clear CB data for netlink core to own from now on */ |
| 13826 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 13827 | |
| 13828 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 13829 | kfree_skb(skb); |
| 13830 | return -EINVAL; |
| 13831 | } |
| 13832 | |
| 13833 | nla_nest_end(skb, data); |
| 13834 | genlmsg_end(skb, hdr); |
| 13835 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 13836 | } |
| 13837 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 13838 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13839 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 13840 | { |
| 13841 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13842 | |
| 13843 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13844 | return 0; |
| 13845 | |
| 13846 | return rdev->cur_cmd_info->snd_portid; |
| 13847 | } |
| 13848 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 13849 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13850 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 13851 | struct genl_info *info) |
| 13852 | { |
| 13853 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13854 | struct cfg80211_qos_map *qos_map = NULL; |
| 13855 | struct net_device *dev = info->user_ptr[1]; |
| 13856 | u8 *pos, len, num_des, des_len, des; |
| 13857 | int ret; |
| 13858 | |
| 13859 | if (!rdev->ops->set_qos_map) |
| 13860 | return -EOPNOTSUPP; |
| 13861 | |
| 13862 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 13863 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13864 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13865 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 13866 | if (len % 2) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13867 | return -EINVAL; |
| 13868 | |
| 13869 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 13870 | if (!qos_map) |
| 13871 | return -ENOMEM; |
| 13872 | |
| 13873 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 13874 | if (num_des) { |
| 13875 | des_len = num_des * |
| 13876 | sizeof(struct cfg80211_dscp_exception); |
| 13877 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 13878 | qos_map->num_des = num_des; |
| 13879 | for (des = 0; des < num_des; des++) { |
| 13880 | if (qos_map->dscp_exception[des].up > 7) { |
| 13881 | kfree(qos_map); |
| 13882 | return -EINVAL; |
| 13883 | } |
| 13884 | } |
| 13885 | pos += des_len; |
| 13886 | } |
| 13887 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 13888 | } |
| 13889 | |
| 13890 | wdev_lock(dev->ieee80211_ptr); |
| 13891 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 13892 | if (!ret) |
| 13893 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 13894 | wdev_unlock(dev->ieee80211_ptr); |
| 13895 | |
| 13896 | kfree(qos_map); |
| 13897 | return ret; |
| 13898 | } |
| 13899 | |
| 13900 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13901 | { |
| 13902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13903 | struct net_device *dev = info->user_ptr[1]; |
| 13904 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13905 | const u8 *peer; |
| 13906 | u8 tsid, up; |
| 13907 | u16 admitted_time = 0; |
| 13908 | int err; |
| 13909 | |
| 13910 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
| 13911 | return -EOPNOTSUPP; |
| 13912 | |
| 13913 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 13914 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 13915 | return -EINVAL; |
| 13916 | |
| 13917 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13918 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13919 | |
| 13920 | /* WMM uses TIDs 0-7 even for TSPEC */ |
| 13921 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
| 13922 | /* TODO: handle 802.11 TSPEC/admission control |
| 13923 | * need more attributes for that (e.g. BA session requirement); |
| 13924 | * change the WMM adminssion test above to allow both then |
| 13925 | */ |
| 13926 | return -EINVAL; |
| 13927 | } |
| 13928 | |
| 13929 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13930 | |
| 13931 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 13932 | admitted_time = |
| 13933 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 13934 | if (!admitted_time) |
| 13935 | return -EINVAL; |
| 13936 | } |
| 13937 | |
| 13938 | wdev_lock(wdev); |
| 13939 | switch (wdev->iftype) { |
| 13940 | case NL80211_IFTYPE_STATION: |
| 13941 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13942 | if (wdev->current_bss) |
| 13943 | break; |
| 13944 | err = -ENOTCONN; |
| 13945 | goto out; |
| 13946 | default: |
| 13947 | err = -EOPNOTSUPP; |
| 13948 | goto out; |
| 13949 | } |
| 13950 | |
| 13951 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 13952 | |
| 13953 | out: |
| 13954 | wdev_unlock(wdev); |
| 13955 | return err; |
| 13956 | } |
| 13957 | |
| 13958 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13959 | { |
| 13960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13961 | struct net_device *dev = info->user_ptr[1]; |
| 13962 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13963 | const u8 *peer; |
| 13964 | u8 tsid; |
| 13965 | int err; |
| 13966 | |
| 13967 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 13968 | return -EINVAL; |
| 13969 | |
| 13970 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 13971 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13972 | |
| 13973 | wdev_lock(wdev); |
| 13974 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 13975 | wdev_unlock(wdev); |
| 13976 | |
| 13977 | return err; |
| 13978 | } |
| 13979 | |
| 13980 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 13981 | struct genl_info *info) |
| 13982 | { |
| 13983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13984 | struct net_device *dev = info->user_ptr[1]; |
| 13985 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13986 | struct cfg80211_chan_def chandef = {}; |
| 13987 | const u8 *addr; |
| 13988 | u8 oper_class; |
| 13989 | int err; |
| 13990 | |
| 13991 | if (!rdev->ops->tdls_channel_switch || |
| 13992 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13993 | return -EOPNOTSUPP; |
| 13994 | |
| 13995 | switch (dev->ieee80211_ptr->iftype) { |
| 13996 | case NL80211_IFTYPE_STATION: |
| 13997 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13998 | break; |
| 13999 | default: |
| 14000 | return -EOPNOTSUPP; |
| 14001 | } |
| 14002 | |
| 14003 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14004 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 14005 | return -EINVAL; |
| 14006 | |
| 14007 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 14008 | if (err) |
| 14009 | return err; |
| 14010 | |
| 14011 | /* |
| 14012 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 14013 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 14014 | * specification is not defined for them. |
| 14015 | */ |
| 14016 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
| 14017 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 14018 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 14019 | return -EINVAL; |
| 14020 | |
| 14021 | /* we will be active on the TDLS link */ |
| 14022 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 14023 | wdev->iftype)) |
| 14024 | return -EINVAL; |
| 14025 | |
| 14026 | /* don't allow switching to DFS channels */ |
| 14027 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 14028 | return -EINVAL; |
| 14029 | |
| 14030 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14031 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 14032 | |
| 14033 | wdev_lock(wdev); |
| 14034 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 14035 | wdev_unlock(wdev); |
| 14036 | |
| 14037 | return err; |
| 14038 | } |
| 14039 | |
| 14040 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 14041 | struct genl_info *info) |
| 14042 | { |
| 14043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14044 | struct net_device *dev = info->user_ptr[1]; |
| 14045 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14046 | const u8 *addr; |
| 14047 | |
| 14048 | if (!rdev->ops->tdls_channel_switch || |
| 14049 | !rdev->ops->tdls_cancel_channel_switch || |
| 14050 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 14051 | return -EOPNOTSUPP; |
| 14052 | |
| 14053 | switch (dev->ieee80211_ptr->iftype) { |
| 14054 | case NL80211_IFTYPE_STATION: |
| 14055 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14056 | break; |
| 14057 | default: |
| 14058 | return -EOPNOTSUPP; |
| 14059 | } |
| 14060 | |
| 14061 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14062 | return -EINVAL; |
| 14063 | |
| 14064 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14065 | |
| 14066 | wdev_lock(wdev); |
| 14067 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 14068 | wdev_unlock(wdev); |
| 14069 | |
| 14070 | return 0; |
| 14071 | } |
| 14072 | |
| 14073 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 14074 | struct genl_info *info) |
| 14075 | { |
| 14076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14077 | struct net_device *dev = info->user_ptr[1]; |
| 14078 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14079 | const struct nlattr *nla; |
| 14080 | bool enabled; |
| 14081 | |
| 14082 | if (!rdev->ops->set_multicast_to_unicast) |
| 14083 | return -EOPNOTSUPP; |
| 14084 | |
| 14085 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 14086 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 14087 | return -EOPNOTSUPP; |
| 14088 | |
| 14089 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 14090 | enabled = nla_get_flag(nla); |
| 14091 | |
| 14092 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 14093 | } |
| 14094 | |
| 14095 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14096 | { |
| 14097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14098 | struct net_device *dev = info->user_ptr[1]; |
| 14099 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14100 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 14101 | int ret; |
| 14102 | |
| 14103 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14104 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14105 | return -EOPNOTSUPP; |
| 14106 | |
| 14107 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14108 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14109 | return -EOPNOTSUPP; |
| 14110 | |
| 14111 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 14112 | return -EINVAL; |
| 14113 | |
| 14114 | wdev_lock(wdev); |
| 14115 | if (!wdev->current_bss) { |
| 14116 | ret = -ENOTCONN; |
| 14117 | goto out; |
| 14118 | } |
| 14119 | |
| 14120 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14121 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 14122 | ret = -EINVAL; |
| 14123 | goto out; |
| 14124 | } |
| 14125 | |
| 14126 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 14127 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 14128 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 14129 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 14130 | ret = -EINVAL; |
| 14131 | goto out; |
| 14132 | } |
| 14133 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14134 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14135 | pmk_conf.pmk_r0_name = |
| 14136 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14137 | |
| 14138 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 14139 | out: |
| 14140 | wdev_unlock(wdev); |
| 14141 | return ret; |
| 14142 | } |
| 14143 | |
| 14144 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14145 | { |
| 14146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14147 | struct net_device *dev = info->user_ptr[1]; |
| 14148 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14149 | const u8 *aa; |
| 14150 | int ret; |
| 14151 | |
| 14152 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14153 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14154 | return -EOPNOTSUPP; |
| 14155 | |
| 14156 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14157 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14158 | return -EOPNOTSUPP; |
| 14159 | |
| 14160 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14161 | return -EINVAL; |
| 14162 | |
| 14163 | wdev_lock(wdev); |
| 14164 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14165 | ret = rdev_del_pmk(rdev, dev, aa); |
| 14166 | wdev_unlock(wdev); |
| 14167 | |
| 14168 | return ret; |
| 14169 | } |
| 14170 | |
| 14171 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 14172 | { |
| 14173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14174 | struct net_device *dev = info->user_ptr[1]; |
| 14175 | struct cfg80211_external_auth_params params; |
| 14176 | |
| 14177 | if (!rdev->ops->external_auth) |
| 14178 | return -EOPNOTSUPP; |
| 14179 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14180 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 14181 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 14182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14183 | return -EINVAL; |
| 14184 | |
| 14185 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 14186 | return -EINVAL; |
| 14187 | |
| 14188 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 14189 | return -EINVAL; |
| 14190 | |
| 14191 | memset(¶ms, 0, sizeof(params)); |
| 14192 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14193 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 14194 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14195 | if (params.ssid.ssid_len == 0) |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14196 | return -EINVAL; |
| 14197 | memcpy(params.ssid.ssid, |
| 14198 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 14199 | params.ssid.ssid_len); |
| 14200 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14201 | |
| 14202 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 14203 | ETH_ALEN); |
| 14204 | |
| 14205 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14206 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14207 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 14208 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 14209 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14210 | return rdev_external_auth(rdev, dev, ¶ms); |
| 14211 | } |
| 14212 | |
| 14213 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 14214 | { |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14215 | bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14216 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14217 | struct net_device *dev = info->user_ptr[1]; |
| 14218 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14219 | const u8 *buf; |
| 14220 | size_t len; |
| 14221 | u8 *dest; |
| 14222 | u16 proto; |
| 14223 | bool noencrypt; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14224 | u64 cookie = 0; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14225 | int err; |
| 14226 | |
| 14227 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14228 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 14229 | return -EOPNOTSUPP; |
| 14230 | |
| 14231 | if (!rdev->ops->tx_control_port) |
| 14232 | return -EOPNOTSUPP; |
| 14233 | |
| 14234 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 14235 | !info->attrs[NL80211_ATTR_MAC] || |
| 14236 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 14237 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 14238 | return -EINVAL; |
| 14239 | } |
| 14240 | |
| 14241 | wdev_lock(wdev); |
| 14242 | |
| 14243 | switch (wdev->iftype) { |
| 14244 | case NL80211_IFTYPE_AP: |
| 14245 | case NL80211_IFTYPE_P2P_GO: |
| 14246 | case NL80211_IFTYPE_MESH_POINT: |
| 14247 | break; |
| 14248 | case NL80211_IFTYPE_ADHOC: |
| 14249 | case NL80211_IFTYPE_STATION: |
| 14250 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14251 | if (wdev->current_bss) |
| 14252 | break; |
| 14253 | err = -ENOTCONN; |
| 14254 | goto out; |
| 14255 | default: |
| 14256 | err = -EOPNOTSUPP; |
| 14257 | goto out; |
| 14258 | } |
| 14259 | |
| 14260 | wdev_unlock(wdev); |
| 14261 | |
| 14262 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14263 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14264 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14265 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 14266 | noencrypt = |
| 14267 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 14268 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14269 | err = rdev_tx_control_port(rdev, dev, buf, len, |
| 14270 | dest, cpu_to_be16(proto), noencrypt, |
| 14271 | dont_wait_for_ack ? NULL : &cookie); |
| 14272 | if (!err && !dont_wait_for_ack) |
| 14273 | nl_set_extack_cookie_u64(info->extack, cookie); |
| 14274 | return err; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14275 | out: |
| 14276 | wdev_unlock(wdev); |
| 14277 | return err; |
| 14278 | } |
| 14279 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14280 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 14281 | struct genl_info *info) |
| 14282 | { |
| 14283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14284 | struct net_device *dev = info->user_ptr[1]; |
| 14285 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14286 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 14287 | struct sk_buff *msg; |
| 14288 | void *hdr; |
| 14289 | struct nlattr *ftm_stats_attr; |
| 14290 | int err; |
| 14291 | |
| 14292 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 14293 | return -EOPNOTSUPP; |
| 14294 | |
| 14295 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 14296 | if (err) |
| 14297 | return err; |
| 14298 | |
| 14299 | if (!ftm_stats.filled) |
| 14300 | return -ENODATA; |
| 14301 | |
| 14302 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14303 | if (!msg) |
| 14304 | return -ENOMEM; |
| 14305 | |
| 14306 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 14307 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 14308 | if (!hdr) |
| 14309 | goto nla_put_failure; |
| 14310 | |
| 14311 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 14312 | goto nla_put_failure; |
| 14313 | |
| 14314 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 14315 | NL80211_ATTR_FTM_RESPONDER_STATS); |
| 14316 | if (!ftm_stats_attr) |
| 14317 | goto nla_put_failure; |
| 14318 | |
| 14319 | #define SET_FTM(field, name, type) \ |
| 14320 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14321 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 14322 | ftm_stats.field)) \ |
| 14323 | goto nla_put_failure; } while (0) |
| 14324 | #define SET_FTM_U64(field, name) \ |
| 14325 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14326 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 14327 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 14328 | goto nla_put_failure; } while (0) |
| 14329 | |
| 14330 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 14331 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 14332 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 14333 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 14334 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 14335 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 14336 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 14337 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 14338 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 14339 | #undef SET_FTM |
| 14340 | |
| 14341 | nla_nest_end(msg, ftm_stats_attr); |
| 14342 | |
| 14343 | genlmsg_end(msg, hdr); |
| 14344 | return genlmsg_reply(msg, info); |
| 14345 | |
| 14346 | nla_put_failure: |
| 14347 | nlmsg_free(msg); |
| 14348 | return -ENOBUFS; |
| 14349 | } |
| 14350 | |
| 14351 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 14352 | { |
| 14353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14354 | struct cfg80211_update_owe_info owe_info; |
| 14355 | struct net_device *dev = info->user_ptr[1]; |
| 14356 | |
| 14357 | if (!rdev->ops->update_owe_info) |
| 14358 | return -EOPNOTSUPP; |
| 14359 | |
| 14360 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 14361 | !info->attrs[NL80211_ATTR_MAC]) |
| 14362 | return -EINVAL; |
| 14363 | |
| 14364 | memset(&owe_info, 0, sizeof(owe_info)); |
| 14365 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14366 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 14367 | |
| 14368 | if (info->attrs[NL80211_ATTR_IE]) { |
| 14369 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 14370 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 14371 | } |
| 14372 | |
| 14373 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 14374 | } |
| 14375 | |
| 14376 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 14377 | { |
| 14378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14379 | struct net_device *dev = info->user_ptr[1]; |
| 14380 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14381 | struct station_info sinfo = {}; |
| 14382 | const u8 *buf; |
| 14383 | size_t len; |
| 14384 | u8 *dest; |
| 14385 | int err; |
| 14386 | |
| 14387 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 14388 | return -EOPNOTSUPP; |
| 14389 | |
| 14390 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14391 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 14392 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 14393 | return -EINVAL; |
| 14394 | } |
| 14395 | |
| 14396 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 14397 | return -EOPNOTSUPP; |
| 14398 | |
| 14399 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14400 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14401 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14402 | |
| 14403 | if (len < sizeof(struct ethhdr)) |
| 14404 | return -EINVAL; |
| 14405 | |
| 14406 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 14407 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 14408 | return -EINVAL; |
| 14409 | |
| 14410 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 14411 | if (err) |
| 14412 | return err; |
| 14413 | |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 14414 | cfg80211_sinfo_release_content(&sinfo); |
| 14415 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14416 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 14417 | } |
| 14418 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14419 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 14420 | struct nlattr *attrs[], struct net_device *dev, |
| 14421 | struct cfg80211_tid_cfg *tid_conf, |
| 14422 | struct genl_info *info, const u8 *peer) |
| 14423 | { |
| 14424 | struct netlink_ext_ack *extack = info->extack; |
| 14425 | u64 mask; |
| 14426 | int err; |
| 14427 | |
| 14428 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 14429 | return -EINVAL; |
| 14430 | |
| 14431 | tid_conf->config_override = |
| 14432 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
| 14433 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
| 14434 | |
| 14435 | if (tid_conf->config_override) { |
| 14436 | if (rdev->ops->reset_tid_config) { |
| 14437 | err = rdev_reset_tid_config(rdev, dev, peer, |
| 14438 | tid_conf->tids); |
| 14439 | if (err) |
| 14440 | return err; |
| 14441 | } else { |
| 14442 | return -EINVAL; |
| 14443 | } |
| 14444 | } |
| 14445 | |
| 14446 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
| 14447 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
| 14448 | tid_conf->noack = |
| 14449 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14450 | } |
| 14451 | |
| 14452 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
| 14453 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); |
| 14454 | tid_conf->retry_short = |
| 14455 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); |
| 14456 | |
| 14457 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) |
| 14458 | return -EINVAL; |
| 14459 | } |
| 14460 | |
| 14461 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { |
| 14462 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); |
| 14463 | tid_conf->retry_long = |
| 14464 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); |
| 14465 | |
| 14466 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) |
| 14467 | return -EINVAL; |
| 14468 | } |
| 14469 | |
| 14470 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
| 14471 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); |
| 14472 | tid_conf->ampdu = |
| 14473 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); |
| 14474 | } |
| 14475 | |
| 14476 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
| 14477 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); |
| 14478 | tid_conf->rtscts = |
| 14479 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); |
| 14480 | } |
| 14481 | |
| 14482 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
| 14483 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); |
| 14484 | tid_conf->amsdu = |
| 14485 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); |
| 14486 | } |
| 14487 | |
| 14488 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
| 14489 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; |
| 14490 | |
| 14491 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); |
| 14492 | |
| 14493 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { |
| 14494 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; |
| 14495 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, |
| 14496 | &tid_conf->txrate_mask, dev); |
| 14497 | if (err) |
| 14498 | return err; |
| 14499 | |
| 14500 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); |
| 14501 | } |
| 14502 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); |
| 14503 | } |
| 14504 | |
| 14505 | if (peer) |
| 14506 | mask = rdev->wiphy.tid_config_support.peer; |
| 14507 | else |
| 14508 | mask = rdev->wiphy.tid_config_support.vif; |
| 14509 | |
| 14510 | if (tid_conf->mask & ~mask) { |
| 14511 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14512 | return -ENOTSUPP; |
| 14513 | } |
| 14514 | |
| 14515 | return 0; |
| 14516 | } |
| 14517 | |
| 14518 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14519 | struct genl_info *info) |
| 14520 | { |
| 14521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14522 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14523 | struct net_device *dev = info->user_ptr[1]; |
| 14524 | struct cfg80211_tid_config *tid_config; |
| 14525 | struct nlattr *tid; |
| 14526 | int conf_idx = 0, rem_conf; |
| 14527 | int ret = -EINVAL; |
| 14528 | u32 num_conf = 0; |
| 14529 | |
| 14530 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14531 | return -EINVAL; |
| 14532 | |
| 14533 | if (!rdev->ops->set_tid_config) |
| 14534 | return -EOPNOTSUPP; |
| 14535 | |
| 14536 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14537 | rem_conf) |
| 14538 | num_conf++; |
| 14539 | |
| 14540 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14541 | GFP_KERNEL); |
| 14542 | if (!tid_config) |
| 14543 | return -ENOMEM; |
| 14544 | |
| 14545 | tid_config->n_tid_conf = num_conf; |
| 14546 | |
| 14547 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14548 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14549 | |
| 14550 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14551 | rem_conf) { |
| 14552 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14553 | tid, NULL, NULL); |
| 14554 | |
| 14555 | if (ret) |
| 14556 | goto bad_tid_conf; |
| 14557 | |
| 14558 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14559 | &tid_config->tid_conf[conf_idx], |
| 14560 | info, tid_config->peer); |
| 14561 | if (ret) |
| 14562 | goto bad_tid_conf; |
| 14563 | |
| 14564 | conf_idx++; |
| 14565 | } |
| 14566 | |
| 14567 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 14568 | |
| 14569 | bad_tid_conf: |
| 14570 | kfree(tid_config); |
| 14571 | return ret; |
| 14572 | } |
| 14573 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14574 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 14575 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 14576 | #define NL80211_FLAG_NEED_RTNL 0x04 |
| 14577 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 14578 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 14579 | NL80211_FLAG_CHECK_NETDEV_UP) |
| 14580 | #define NL80211_FLAG_NEED_WDEV 0x10 |
| 14581 | /* If a netdev is associated, it must be UP, P2P must be started */ |
| 14582 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 14583 | NL80211_FLAG_CHECK_NETDEV_UP) |
| 14584 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
| 14585 | |
| 14586 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
| 14587 | struct genl_info *info) |
| 14588 | { |
| 14589 | struct cfg80211_registered_device *rdev; |
| 14590 | struct wireless_dev *wdev; |
| 14591 | struct net_device *dev; |
| 14592 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 14593 | |
| 14594 | if (rtnl) |
| 14595 | rtnl_lock(); |
| 14596 | |
| 14597 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 14598 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 14599 | if (IS_ERR(rdev)) { |
| 14600 | if (rtnl) |
| 14601 | rtnl_unlock(); |
| 14602 | return PTR_ERR(rdev); |
| 14603 | } |
| 14604 | info->user_ptr[0] = rdev; |
| 14605 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 14606 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14607 | ASSERT_RTNL(); |
| 14608 | |
| 14609 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 14610 | info->attrs); |
| 14611 | if (IS_ERR(wdev)) { |
| 14612 | if (rtnl) |
| 14613 | rtnl_unlock(); |
| 14614 | return PTR_ERR(wdev); |
| 14615 | } |
| 14616 | |
| 14617 | dev = wdev->netdev; |
| 14618 | rdev = wiphy_to_rdev(wdev->wiphy); |
| 14619 | |
| 14620 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 14621 | if (!dev) { |
| 14622 | if (rtnl) |
| 14623 | rtnl_unlock(); |
| 14624 | return -EINVAL; |
| 14625 | } |
| 14626 | |
| 14627 | info->user_ptr[1] = dev; |
| 14628 | } else { |
| 14629 | info->user_ptr[1] = wdev; |
| 14630 | } |
| 14631 | |
| 14632 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 14633 | !wdev_running(wdev)) { |
| 14634 | if (rtnl) |
| 14635 | rtnl_unlock(); |
| 14636 | return -ENETDOWN; |
| 14637 | } |
| 14638 | |
| 14639 | if (dev) |
| 14640 | dev_hold(dev); |
| 14641 | |
| 14642 | info->user_ptr[0] = rdev; |
| 14643 | } |
| 14644 | |
| 14645 | return 0; |
| 14646 | } |
| 14647 | |
| 14648 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
| 14649 | struct genl_info *info) |
| 14650 | { |
| 14651 | if (info->user_ptr[1]) { |
| 14652 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14653 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 14654 | |
| 14655 | if (wdev->netdev) |
| 14656 | dev_put(wdev->netdev); |
| 14657 | } else { |
| 14658 | dev_put(info->user_ptr[1]); |
| 14659 | } |
| 14660 | } |
| 14661 | |
| 14662 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 14663 | rtnl_unlock(); |
| 14664 | |
| 14665 | /* If needed, clear the netlink message payload from the SKB |
| 14666 | * as it might contain key data that shouldn't stick around on |
| 14667 | * the heap after the SKB is freed. The netlink message header |
| 14668 | * is still needed for further processing, so leave it intact. |
| 14669 | */ |
| 14670 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 14671 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 14672 | |
| 14673 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 14674 | } |
| 14675 | } |
| 14676 | |
| 14677 | static const struct genl_ops nl80211_ops[] = { |
| 14678 | { |
| 14679 | .cmd = NL80211_CMD_GET_WIPHY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14680 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14681 | .doit = nl80211_get_wiphy, |
| 14682 | .dumpit = nl80211_dump_wiphy, |
| 14683 | .done = nl80211_dump_wiphy_done, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14684 | /* can be retrieved by unprivileged users */ |
| 14685 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14686 | NL80211_FLAG_NEED_RTNL, |
| 14687 | }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 14688 | }; |
| 14689 | |
| 14690 | static const struct genl_small_ops nl80211_small_ops[] = { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14691 | { |
| 14692 | .cmd = NL80211_CMD_SET_WIPHY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14693 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14694 | .doit = nl80211_set_wiphy, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14695 | .flags = GENL_UNS_ADMIN_PERM, |
| 14696 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
| 14697 | }, |
| 14698 | { |
| 14699 | .cmd = NL80211_CMD_GET_INTERFACE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14700 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14701 | .doit = nl80211_get_interface, |
| 14702 | .dumpit = nl80211_dump_interface, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14703 | /* can be retrieved by unprivileged users */ |
| 14704 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14705 | NL80211_FLAG_NEED_RTNL, |
| 14706 | }, |
| 14707 | { |
| 14708 | .cmd = NL80211_CMD_SET_INTERFACE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14709 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14710 | .doit = nl80211_set_interface, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14711 | .flags = GENL_UNS_ADMIN_PERM, |
| 14712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14713 | NL80211_FLAG_NEED_RTNL, |
| 14714 | }, |
| 14715 | { |
| 14716 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14717 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14718 | .doit = nl80211_new_interface, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14719 | .flags = GENL_UNS_ADMIN_PERM, |
| 14720 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14721 | NL80211_FLAG_NEED_RTNL, |
| 14722 | }, |
| 14723 | { |
| 14724 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14725 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14726 | .doit = nl80211_del_interface, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14727 | .flags = GENL_UNS_ADMIN_PERM, |
| 14728 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14729 | NL80211_FLAG_NEED_RTNL, |
| 14730 | }, |
| 14731 | { |
| 14732 | .cmd = NL80211_CMD_GET_KEY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14733 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14734 | .doit = nl80211_get_key, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14735 | .flags = GENL_UNS_ADMIN_PERM, |
| 14736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14737 | NL80211_FLAG_NEED_RTNL, |
| 14738 | }, |
| 14739 | { |
| 14740 | .cmd = NL80211_CMD_SET_KEY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14741 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14742 | .doit = nl80211_set_key, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14743 | .flags = GENL_UNS_ADMIN_PERM, |
| 14744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14745 | NL80211_FLAG_NEED_RTNL | |
| 14746 | NL80211_FLAG_CLEAR_SKB, |
| 14747 | }, |
| 14748 | { |
| 14749 | .cmd = NL80211_CMD_NEW_KEY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14750 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14751 | .doit = nl80211_new_key, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14752 | .flags = GENL_UNS_ADMIN_PERM, |
| 14753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14754 | NL80211_FLAG_NEED_RTNL | |
| 14755 | NL80211_FLAG_CLEAR_SKB, |
| 14756 | }, |
| 14757 | { |
| 14758 | .cmd = NL80211_CMD_DEL_KEY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14759 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14760 | .doit = nl80211_del_key, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14761 | .flags = GENL_UNS_ADMIN_PERM, |
| 14762 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14763 | NL80211_FLAG_NEED_RTNL, |
| 14764 | }, |
| 14765 | { |
| 14766 | .cmd = NL80211_CMD_SET_BEACON, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14767 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14768 | .flags = GENL_UNS_ADMIN_PERM, |
| 14769 | .doit = nl80211_set_beacon, |
| 14770 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14771 | NL80211_FLAG_NEED_RTNL, |
| 14772 | }, |
| 14773 | { |
| 14774 | .cmd = NL80211_CMD_START_AP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14775 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14776 | .flags = GENL_UNS_ADMIN_PERM, |
| 14777 | .doit = nl80211_start_ap, |
| 14778 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14779 | NL80211_FLAG_NEED_RTNL, |
| 14780 | }, |
| 14781 | { |
| 14782 | .cmd = NL80211_CMD_STOP_AP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14783 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14784 | .flags = GENL_UNS_ADMIN_PERM, |
| 14785 | .doit = nl80211_stop_ap, |
| 14786 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14787 | NL80211_FLAG_NEED_RTNL, |
| 14788 | }, |
| 14789 | { |
| 14790 | .cmd = NL80211_CMD_GET_STATION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14791 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14792 | .doit = nl80211_get_station, |
| 14793 | .dumpit = nl80211_dump_station, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14794 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14795 | NL80211_FLAG_NEED_RTNL, |
| 14796 | }, |
| 14797 | { |
| 14798 | .cmd = NL80211_CMD_SET_STATION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14799 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14800 | .doit = nl80211_set_station, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14801 | .flags = GENL_UNS_ADMIN_PERM, |
| 14802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14803 | NL80211_FLAG_NEED_RTNL, |
| 14804 | }, |
| 14805 | { |
| 14806 | .cmd = NL80211_CMD_NEW_STATION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14807 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14808 | .doit = nl80211_new_station, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14809 | .flags = GENL_UNS_ADMIN_PERM, |
| 14810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14811 | NL80211_FLAG_NEED_RTNL, |
| 14812 | }, |
| 14813 | { |
| 14814 | .cmd = NL80211_CMD_DEL_STATION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14815 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14816 | .doit = nl80211_del_station, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14817 | .flags = GENL_UNS_ADMIN_PERM, |
| 14818 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14819 | NL80211_FLAG_NEED_RTNL, |
| 14820 | }, |
| 14821 | { |
| 14822 | .cmd = NL80211_CMD_GET_MPATH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14823 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14824 | .doit = nl80211_get_mpath, |
| 14825 | .dumpit = nl80211_dump_mpath, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14826 | .flags = GENL_UNS_ADMIN_PERM, |
| 14827 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14828 | NL80211_FLAG_NEED_RTNL, |
| 14829 | }, |
| 14830 | { |
| 14831 | .cmd = NL80211_CMD_GET_MPP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14832 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14833 | .doit = nl80211_get_mpp, |
| 14834 | .dumpit = nl80211_dump_mpp, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14835 | .flags = GENL_UNS_ADMIN_PERM, |
| 14836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14837 | NL80211_FLAG_NEED_RTNL, |
| 14838 | }, |
| 14839 | { |
| 14840 | .cmd = NL80211_CMD_SET_MPATH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14841 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14842 | .doit = nl80211_set_mpath, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14843 | .flags = GENL_UNS_ADMIN_PERM, |
| 14844 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14845 | NL80211_FLAG_NEED_RTNL, |
| 14846 | }, |
| 14847 | { |
| 14848 | .cmd = NL80211_CMD_NEW_MPATH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14849 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14850 | .doit = nl80211_new_mpath, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14851 | .flags = GENL_UNS_ADMIN_PERM, |
| 14852 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14853 | NL80211_FLAG_NEED_RTNL, |
| 14854 | }, |
| 14855 | { |
| 14856 | .cmd = NL80211_CMD_DEL_MPATH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14857 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14858 | .doit = nl80211_del_mpath, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14859 | .flags = GENL_UNS_ADMIN_PERM, |
| 14860 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14861 | NL80211_FLAG_NEED_RTNL, |
| 14862 | }, |
| 14863 | { |
| 14864 | .cmd = NL80211_CMD_SET_BSS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14865 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14866 | .doit = nl80211_set_bss, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14867 | .flags = GENL_UNS_ADMIN_PERM, |
| 14868 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14869 | NL80211_FLAG_NEED_RTNL, |
| 14870 | }, |
| 14871 | { |
| 14872 | .cmd = NL80211_CMD_GET_REG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14873 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14874 | .doit = nl80211_get_reg_do, |
| 14875 | .dumpit = nl80211_get_reg_dump, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14876 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
| 14877 | /* can be retrieved by unprivileged users */ |
| 14878 | }, |
| 14879 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 14880 | { |
| 14881 | .cmd = NL80211_CMD_SET_REG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14882 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14883 | .doit = nl80211_set_reg, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14884 | .flags = GENL_ADMIN_PERM, |
| 14885 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
| 14886 | }, |
| 14887 | #endif |
| 14888 | { |
| 14889 | .cmd = NL80211_CMD_REQ_SET_REG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14890 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14891 | .doit = nl80211_req_set_reg, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14892 | .flags = GENL_ADMIN_PERM, |
| 14893 | }, |
| 14894 | { |
| 14895 | .cmd = NL80211_CMD_RELOAD_REGDB, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14896 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14897 | .doit = nl80211_reload_regdb, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14898 | .flags = GENL_ADMIN_PERM, |
| 14899 | }, |
| 14900 | { |
| 14901 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14902 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14903 | .doit = nl80211_get_mesh_config, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14904 | /* can be retrieved by unprivileged users */ |
| 14905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14906 | NL80211_FLAG_NEED_RTNL, |
| 14907 | }, |
| 14908 | { |
| 14909 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14910 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14911 | .doit = nl80211_update_mesh_config, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14912 | .flags = GENL_UNS_ADMIN_PERM, |
| 14913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14914 | NL80211_FLAG_NEED_RTNL, |
| 14915 | }, |
| 14916 | { |
| 14917 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14918 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14919 | .doit = nl80211_trigger_scan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14920 | .flags = GENL_UNS_ADMIN_PERM, |
| 14921 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14922 | NL80211_FLAG_NEED_RTNL, |
| 14923 | }, |
| 14924 | { |
| 14925 | .cmd = NL80211_CMD_ABORT_SCAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14926 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14927 | .doit = nl80211_abort_scan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14928 | .flags = GENL_UNS_ADMIN_PERM, |
| 14929 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14930 | NL80211_FLAG_NEED_RTNL, |
| 14931 | }, |
| 14932 | { |
| 14933 | .cmd = NL80211_CMD_GET_SCAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14934 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14935 | .dumpit = nl80211_dump_scan, |
| 14936 | }, |
| 14937 | { |
| 14938 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14939 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14940 | .doit = nl80211_start_sched_scan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14941 | .flags = GENL_UNS_ADMIN_PERM, |
| 14942 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14943 | NL80211_FLAG_NEED_RTNL, |
| 14944 | }, |
| 14945 | { |
| 14946 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14947 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14948 | .doit = nl80211_stop_sched_scan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14949 | .flags = GENL_UNS_ADMIN_PERM, |
| 14950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14951 | NL80211_FLAG_NEED_RTNL, |
| 14952 | }, |
| 14953 | { |
| 14954 | .cmd = NL80211_CMD_AUTHENTICATE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14955 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14956 | .doit = nl80211_authenticate, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14957 | .flags = GENL_UNS_ADMIN_PERM, |
| 14958 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14959 | NL80211_FLAG_NEED_RTNL | |
| 14960 | NL80211_FLAG_CLEAR_SKB, |
| 14961 | }, |
| 14962 | { |
| 14963 | .cmd = NL80211_CMD_ASSOCIATE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14964 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14965 | .doit = nl80211_associate, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14966 | .flags = GENL_UNS_ADMIN_PERM, |
| 14967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14968 | NL80211_FLAG_NEED_RTNL | |
| 14969 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14970 | }, |
| 14971 | { |
| 14972 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14973 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14974 | .doit = nl80211_deauthenticate, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14975 | .flags = GENL_UNS_ADMIN_PERM, |
| 14976 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14977 | NL80211_FLAG_NEED_RTNL, |
| 14978 | }, |
| 14979 | { |
| 14980 | .cmd = NL80211_CMD_DISASSOCIATE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14981 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14982 | .doit = nl80211_disassociate, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14983 | .flags = GENL_UNS_ADMIN_PERM, |
| 14984 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14985 | NL80211_FLAG_NEED_RTNL, |
| 14986 | }, |
| 14987 | { |
| 14988 | .cmd = NL80211_CMD_JOIN_IBSS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14989 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14990 | .doit = nl80211_join_ibss, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14991 | .flags = GENL_UNS_ADMIN_PERM, |
| 14992 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14993 | NL80211_FLAG_NEED_RTNL, |
| 14994 | }, |
| 14995 | { |
| 14996 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 14997 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14998 | .doit = nl80211_leave_ibss, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14999 | .flags = GENL_UNS_ADMIN_PERM, |
| 15000 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15001 | NL80211_FLAG_NEED_RTNL, |
| 15002 | }, |
| 15003 | #ifdef CONFIG_NL80211_TESTMODE |
| 15004 | { |
| 15005 | .cmd = NL80211_CMD_TESTMODE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15006 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15007 | .doit = nl80211_testmode_do, |
| 15008 | .dumpit = nl80211_testmode_dump, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15009 | .flags = GENL_UNS_ADMIN_PERM, |
| 15010 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15011 | NL80211_FLAG_NEED_RTNL, |
| 15012 | }, |
| 15013 | #endif |
| 15014 | { |
| 15015 | .cmd = NL80211_CMD_CONNECT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15016 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15017 | .doit = nl80211_connect, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15018 | .flags = GENL_UNS_ADMIN_PERM, |
| 15019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15020 | NL80211_FLAG_NEED_RTNL | |
| 15021 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15022 | }, |
| 15023 | { |
| 15024 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15025 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15026 | .doit = nl80211_update_connect_params, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15027 | .flags = GENL_ADMIN_PERM, |
| 15028 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15029 | NL80211_FLAG_NEED_RTNL | |
| 15030 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15031 | }, |
| 15032 | { |
| 15033 | .cmd = NL80211_CMD_DISCONNECT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15034 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15035 | .doit = nl80211_disconnect, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15036 | .flags = GENL_UNS_ADMIN_PERM, |
| 15037 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15038 | NL80211_FLAG_NEED_RTNL, |
| 15039 | }, |
| 15040 | { |
| 15041 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15042 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15043 | .doit = nl80211_wiphy_netns, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15044 | .flags = GENL_UNS_ADMIN_PERM, |
| 15045 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15046 | NL80211_FLAG_NEED_RTNL, |
| 15047 | }, |
| 15048 | { |
| 15049 | .cmd = NL80211_CMD_GET_SURVEY, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15050 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15051 | .dumpit = nl80211_dump_survey, |
| 15052 | }, |
| 15053 | { |
| 15054 | .cmd = NL80211_CMD_SET_PMKSA, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15055 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15056 | .doit = nl80211_setdel_pmksa, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15057 | .flags = GENL_UNS_ADMIN_PERM, |
| 15058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15059 | NL80211_FLAG_NEED_RTNL | |
| 15060 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15061 | }, |
| 15062 | { |
| 15063 | .cmd = NL80211_CMD_DEL_PMKSA, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15064 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15065 | .doit = nl80211_setdel_pmksa, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15066 | .flags = GENL_UNS_ADMIN_PERM, |
| 15067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15068 | NL80211_FLAG_NEED_RTNL, |
| 15069 | }, |
| 15070 | { |
| 15071 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15072 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15073 | .doit = nl80211_flush_pmksa, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15074 | .flags = GENL_UNS_ADMIN_PERM, |
| 15075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15076 | NL80211_FLAG_NEED_RTNL, |
| 15077 | }, |
| 15078 | { |
| 15079 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15080 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15081 | .doit = nl80211_remain_on_channel, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15082 | .flags = GENL_UNS_ADMIN_PERM, |
| 15083 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15084 | NL80211_FLAG_NEED_RTNL, |
| 15085 | }, |
| 15086 | { |
| 15087 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15088 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15089 | .doit = nl80211_cancel_remain_on_channel, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15090 | .flags = GENL_UNS_ADMIN_PERM, |
| 15091 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15092 | NL80211_FLAG_NEED_RTNL, |
| 15093 | }, |
| 15094 | { |
| 15095 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15096 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15097 | .doit = nl80211_set_tx_bitrate_mask, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15098 | .flags = GENL_UNS_ADMIN_PERM, |
| 15099 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15100 | NL80211_FLAG_NEED_RTNL, |
| 15101 | }, |
| 15102 | { |
| 15103 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15104 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15105 | .doit = nl80211_register_mgmt, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15106 | .flags = GENL_UNS_ADMIN_PERM, |
| 15107 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15108 | NL80211_FLAG_NEED_RTNL, |
| 15109 | }, |
| 15110 | { |
| 15111 | .cmd = NL80211_CMD_FRAME, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15112 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15113 | .doit = nl80211_tx_mgmt, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15114 | .flags = GENL_UNS_ADMIN_PERM, |
| 15115 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15116 | NL80211_FLAG_NEED_RTNL, |
| 15117 | }, |
| 15118 | { |
| 15119 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15120 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15121 | .doit = nl80211_tx_mgmt_cancel_wait, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15122 | .flags = GENL_UNS_ADMIN_PERM, |
| 15123 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15124 | NL80211_FLAG_NEED_RTNL, |
| 15125 | }, |
| 15126 | { |
| 15127 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15128 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15129 | .doit = nl80211_set_power_save, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15130 | .flags = GENL_UNS_ADMIN_PERM, |
| 15131 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15132 | NL80211_FLAG_NEED_RTNL, |
| 15133 | }, |
| 15134 | { |
| 15135 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15136 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15137 | .doit = nl80211_get_power_save, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15138 | /* can be retrieved by unprivileged users */ |
| 15139 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15140 | NL80211_FLAG_NEED_RTNL, |
| 15141 | }, |
| 15142 | { |
| 15143 | .cmd = NL80211_CMD_SET_CQM, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15144 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15145 | .doit = nl80211_set_cqm, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15146 | .flags = GENL_UNS_ADMIN_PERM, |
| 15147 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15148 | NL80211_FLAG_NEED_RTNL, |
| 15149 | }, |
| 15150 | { |
| 15151 | .cmd = NL80211_CMD_SET_CHANNEL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15152 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15153 | .doit = nl80211_set_channel, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15154 | .flags = GENL_UNS_ADMIN_PERM, |
| 15155 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15156 | NL80211_FLAG_NEED_RTNL, |
| 15157 | }, |
| 15158 | { |
| 15159 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15160 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15161 | .doit = nl80211_set_wds_peer, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15162 | .flags = GENL_UNS_ADMIN_PERM, |
| 15163 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15164 | NL80211_FLAG_NEED_RTNL, |
| 15165 | }, |
| 15166 | { |
| 15167 | .cmd = NL80211_CMD_JOIN_MESH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15168 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15169 | .doit = nl80211_join_mesh, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15170 | .flags = GENL_UNS_ADMIN_PERM, |
| 15171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15172 | NL80211_FLAG_NEED_RTNL, |
| 15173 | }, |
| 15174 | { |
| 15175 | .cmd = NL80211_CMD_LEAVE_MESH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15176 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15177 | .doit = nl80211_leave_mesh, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15178 | .flags = GENL_UNS_ADMIN_PERM, |
| 15179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15180 | NL80211_FLAG_NEED_RTNL, |
| 15181 | }, |
| 15182 | { |
| 15183 | .cmd = NL80211_CMD_JOIN_OCB, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15184 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15185 | .doit = nl80211_join_ocb, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15186 | .flags = GENL_UNS_ADMIN_PERM, |
| 15187 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15188 | NL80211_FLAG_NEED_RTNL, |
| 15189 | }, |
| 15190 | { |
| 15191 | .cmd = NL80211_CMD_LEAVE_OCB, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15192 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15193 | .doit = nl80211_leave_ocb, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15194 | .flags = GENL_UNS_ADMIN_PERM, |
| 15195 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15196 | NL80211_FLAG_NEED_RTNL, |
| 15197 | }, |
| 15198 | #ifdef CONFIG_PM |
| 15199 | { |
| 15200 | .cmd = NL80211_CMD_GET_WOWLAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15201 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15202 | .doit = nl80211_get_wowlan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15203 | /* can be retrieved by unprivileged users */ |
| 15204 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15205 | NL80211_FLAG_NEED_RTNL, |
| 15206 | }, |
| 15207 | { |
| 15208 | .cmd = NL80211_CMD_SET_WOWLAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15209 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15210 | .doit = nl80211_set_wowlan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15211 | .flags = GENL_UNS_ADMIN_PERM, |
| 15212 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15213 | NL80211_FLAG_NEED_RTNL, |
| 15214 | }, |
| 15215 | #endif |
| 15216 | { |
| 15217 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15218 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15219 | .doit = nl80211_set_rekey_data, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15220 | .flags = GENL_UNS_ADMIN_PERM, |
| 15221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15222 | NL80211_FLAG_NEED_RTNL | |
| 15223 | NL80211_FLAG_CLEAR_SKB, |
| 15224 | }, |
| 15225 | { |
| 15226 | .cmd = NL80211_CMD_TDLS_MGMT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15227 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15228 | .doit = nl80211_tdls_mgmt, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15229 | .flags = GENL_UNS_ADMIN_PERM, |
| 15230 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15231 | NL80211_FLAG_NEED_RTNL, |
| 15232 | }, |
| 15233 | { |
| 15234 | .cmd = NL80211_CMD_TDLS_OPER, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15235 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15236 | .doit = nl80211_tdls_oper, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15237 | .flags = GENL_UNS_ADMIN_PERM, |
| 15238 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15239 | NL80211_FLAG_NEED_RTNL, |
| 15240 | }, |
| 15241 | { |
| 15242 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15243 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15244 | .doit = nl80211_register_unexpected_frame, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15245 | .flags = GENL_UNS_ADMIN_PERM, |
| 15246 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15247 | NL80211_FLAG_NEED_RTNL, |
| 15248 | }, |
| 15249 | { |
| 15250 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15251 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15252 | .doit = nl80211_probe_client, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15253 | .flags = GENL_UNS_ADMIN_PERM, |
| 15254 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15255 | NL80211_FLAG_NEED_RTNL, |
| 15256 | }, |
| 15257 | { |
| 15258 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15259 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15260 | .doit = nl80211_register_beacons, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15261 | .flags = GENL_UNS_ADMIN_PERM, |
| 15262 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15263 | NL80211_FLAG_NEED_RTNL, |
| 15264 | }, |
| 15265 | { |
| 15266 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15267 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15268 | .doit = nl80211_set_noack_map, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15269 | .flags = GENL_UNS_ADMIN_PERM, |
| 15270 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15271 | NL80211_FLAG_NEED_RTNL, |
| 15272 | }, |
| 15273 | { |
| 15274 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15275 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15276 | .doit = nl80211_start_p2p_device, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15277 | .flags = GENL_UNS_ADMIN_PERM, |
| 15278 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15279 | NL80211_FLAG_NEED_RTNL, |
| 15280 | }, |
| 15281 | { |
| 15282 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15283 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15284 | .doit = nl80211_stop_p2p_device, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15285 | .flags = GENL_UNS_ADMIN_PERM, |
| 15286 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15287 | NL80211_FLAG_NEED_RTNL, |
| 15288 | }, |
| 15289 | { |
| 15290 | .cmd = NL80211_CMD_START_NAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15291 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15292 | .doit = nl80211_start_nan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15293 | .flags = GENL_ADMIN_PERM, |
| 15294 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15295 | NL80211_FLAG_NEED_RTNL, |
| 15296 | }, |
| 15297 | { |
| 15298 | .cmd = NL80211_CMD_STOP_NAN, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15299 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15300 | .doit = nl80211_stop_nan, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15301 | .flags = GENL_ADMIN_PERM, |
| 15302 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15303 | NL80211_FLAG_NEED_RTNL, |
| 15304 | }, |
| 15305 | { |
| 15306 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15307 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15308 | .doit = nl80211_nan_add_func, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15309 | .flags = GENL_ADMIN_PERM, |
| 15310 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15311 | NL80211_FLAG_NEED_RTNL, |
| 15312 | }, |
| 15313 | { |
| 15314 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15315 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15316 | .doit = nl80211_nan_del_func, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15317 | .flags = GENL_ADMIN_PERM, |
| 15318 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15319 | NL80211_FLAG_NEED_RTNL, |
| 15320 | }, |
| 15321 | { |
| 15322 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15323 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15324 | .doit = nl80211_nan_change_config, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15325 | .flags = GENL_ADMIN_PERM, |
| 15326 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15327 | NL80211_FLAG_NEED_RTNL, |
| 15328 | }, |
| 15329 | { |
| 15330 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15331 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15332 | .doit = nl80211_set_mcast_rate, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15333 | .flags = GENL_UNS_ADMIN_PERM, |
| 15334 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15335 | NL80211_FLAG_NEED_RTNL, |
| 15336 | }, |
| 15337 | { |
| 15338 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15339 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15340 | .doit = nl80211_set_mac_acl, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15341 | .flags = GENL_UNS_ADMIN_PERM, |
| 15342 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15343 | NL80211_FLAG_NEED_RTNL, |
| 15344 | }, |
| 15345 | { |
| 15346 | .cmd = NL80211_CMD_RADAR_DETECT, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15347 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15348 | .doit = nl80211_start_radar_detection, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15349 | .flags = GENL_UNS_ADMIN_PERM, |
| 15350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15351 | NL80211_FLAG_NEED_RTNL, |
| 15352 | }, |
| 15353 | { |
| 15354 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15355 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15356 | .doit = nl80211_get_protocol_features, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15357 | }, |
| 15358 | { |
| 15359 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15360 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15361 | .doit = nl80211_update_ft_ies, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15362 | .flags = GENL_UNS_ADMIN_PERM, |
| 15363 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15364 | NL80211_FLAG_NEED_RTNL, |
| 15365 | }, |
| 15366 | { |
| 15367 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15368 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15369 | .doit = nl80211_crit_protocol_start, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15370 | .flags = GENL_UNS_ADMIN_PERM, |
| 15371 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15372 | NL80211_FLAG_NEED_RTNL, |
| 15373 | }, |
| 15374 | { |
| 15375 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15376 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15377 | .doit = nl80211_crit_protocol_stop, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15378 | .flags = GENL_UNS_ADMIN_PERM, |
| 15379 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15380 | NL80211_FLAG_NEED_RTNL, |
| 15381 | }, |
| 15382 | { |
| 15383 | .cmd = NL80211_CMD_GET_COALESCE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15384 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15385 | .doit = nl80211_get_coalesce, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15386 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15387 | NL80211_FLAG_NEED_RTNL, |
| 15388 | }, |
| 15389 | { |
| 15390 | .cmd = NL80211_CMD_SET_COALESCE, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15391 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15392 | .doit = nl80211_set_coalesce, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15393 | .flags = GENL_UNS_ADMIN_PERM, |
| 15394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15395 | NL80211_FLAG_NEED_RTNL, |
| 15396 | }, |
| 15397 | { |
| 15398 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15399 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15400 | .doit = nl80211_channel_switch, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15401 | .flags = GENL_UNS_ADMIN_PERM, |
| 15402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15403 | NL80211_FLAG_NEED_RTNL, |
| 15404 | }, |
| 15405 | { |
| 15406 | .cmd = NL80211_CMD_VENDOR, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15407 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15408 | .doit = nl80211_vendor_cmd, |
| 15409 | .dumpit = nl80211_vendor_cmd_dump, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15410 | .flags = GENL_UNS_ADMIN_PERM, |
| 15411 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15412 | NL80211_FLAG_NEED_RTNL | |
| 15413 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15414 | }, |
| 15415 | { |
| 15416 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15417 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15418 | .doit = nl80211_set_qos_map, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15419 | .flags = GENL_UNS_ADMIN_PERM, |
| 15420 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15421 | NL80211_FLAG_NEED_RTNL, |
| 15422 | }, |
| 15423 | { |
| 15424 | .cmd = NL80211_CMD_ADD_TX_TS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15425 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15426 | .doit = nl80211_add_tx_ts, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15427 | .flags = GENL_UNS_ADMIN_PERM, |
| 15428 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15429 | NL80211_FLAG_NEED_RTNL, |
| 15430 | }, |
| 15431 | { |
| 15432 | .cmd = NL80211_CMD_DEL_TX_TS, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15433 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15434 | .doit = nl80211_del_tx_ts, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15435 | .flags = GENL_UNS_ADMIN_PERM, |
| 15436 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15437 | NL80211_FLAG_NEED_RTNL, |
| 15438 | }, |
| 15439 | { |
| 15440 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15441 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15442 | .doit = nl80211_tdls_channel_switch, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15443 | .flags = GENL_UNS_ADMIN_PERM, |
| 15444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15445 | NL80211_FLAG_NEED_RTNL, |
| 15446 | }, |
| 15447 | { |
| 15448 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15449 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15450 | .doit = nl80211_tdls_cancel_channel_switch, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15451 | .flags = GENL_UNS_ADMIN_PERM, |
| 15452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15453 | NL80211_FLAG_NEED_RTNL, |
| 15454 | }, |
| 15455 | { |
| 15456 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15457 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15458 | .doit = nl80211_set_multicast_to_unicast, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15459 | .flags = GENL_UNS_ADMIN_PERM, |
| 15460 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15461 | NL80211_FLAG_NEED_RTNL, |
| 15462 | }, |
| 15463 | { |
| 15464 | .cmd = NL80211_CMD_SET_PMK, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15465 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15466 | .doit = nl80211_set_pmk, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15468 | NL80211_FLAG_NEED_RTNL | |
| 15469 | NL80211_FLAG_CLEAR_SKB, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15470 | }, |
| 15471 | { |
| 15472 | .cmd = NL80211_CMD_DEL_PMK, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15473 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15474 | .doit = nl80211_del_pmk, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15475 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15476 | NL80211_FLAG_NEED_RTNL, |
| 15477 | }, |
| 15478 | { |
| 15479 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15480 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15481 | .doit = nl80211_external_auth, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15482 | .flags = GENL_ADMIN_PERM, |
| 15483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15484 | NL80211_FLAG_NEED_RTNL, |
| 15485 | }, |
| 15486 | { |
| 15487 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15488 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15489 | .doit = nl80211_tx_control_port, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15490 | .flags = GENL_UNS_ADMIN_PERM, |
| 15491 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15492 | NL80211_FLAG_NEED_RTNL, |
| 15493 | }, |
| 15494 | { |
| 15495 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
| 15496 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 15497 | .doit = nl80211_get_ftm_responder_stats, |
| 15498 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15499 | NL80211_FLAG_NEED_RTNL, |
| 15500 | }, |
| 15501 | { |
| 15502 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
| 15503 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 15504 | .doit = nl80211_pmsr_start, |
| 15505 | .flags = GENL_UNS_ADMIN_PERM, |
| 15506 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15507 | NL80211_FLAG_NEED_RTNL, |
| 15508 | }, |
| 15509 | { |
| 15510 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
| 15511 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 15512 | .doit = nl80211_notify_radar_detection, |
| 15513 | .flags = GENL_UNS_ADMIN_PERM, |
| 15514 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15515 | NL80211_FLAG_NEED_RTNL, |
| 15516 | }, |
| 15517 | { |
| 15518 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 15519 | .doit = nl80211_update_owe_info, |
| 15520 | .flags = GENL_ADMIN_PERM, |
| 15521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15522 | NL80211_FLAG_NEED_RTNL, |
| 15523 | }, |
| 15524 | { |
| 15525 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 15526 | .doit = nl80211_probe_mesh_link, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15527 | .flags = GENL_UNS_ADMIN_PERM, |
| 15528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15529 | NL80211_FLAG_NEED_RTNL, |
| 15530 | }, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15531 | { |
| 15532 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 15533 | .doit = nl80211_set_tid_config, |
| 15534 | .flags = GENL_UNS_ADMIN_PERM, |
| 15535 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15536 | NL80211_FLAG_NEED_RTNL, |
| 15537 | }, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15538 | }; |
| 15539 | |
| 15540 | static struct genl_family nl80211_fam __ro_after_init = { |
| 15541 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 15542 | .hdrsize = 0, /* no private header */ |
| 15543 | .version = 1, /* no particular meaning now */ |
| 15544 | .maxattr = NL80211_ATTR_MAX, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15545 | .policy = nl80211_policy, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15546 | .netnsok = true, |
| 15547 | .pre_doit = nl80211_pre_doit, |
| 15548 | .post_doit = nl80211_post_doit, |
| 15549 | .module = THIS_MODULE, |
| 15550 | .ops = nl80211_ops, |
| 15551 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15552 | .small_ops = nl80211_small_ops, |
| 15553 | .n_small_ops = ARRAY_SIZE(nl80211_small_ops), |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15554 | .mcgrps = nl80211_mcgrps, |
| 15555 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15556 | .parallel_ops = true, |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15557 | }; |
| 15558 | |
| 15559 | /* notification functions */ |
| 15560 | |
| 15561 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 15562 | enum nl80211_commands cmd) |
| 15563 | { |
| 15564 | struct sk_buff *msg; |
| 15565 | struct nl80211_dump_wiphy_state state = {}; |
| 15566 | |
| 15567 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 15568 | cmd != NL80211_CMD_DEL_WIPHY); |
| 15569 | |
| 15570 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15571 | if (!msg) |
| 15572 | return; |
| 15573 | |
| 15574 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
| 15575 | nlmsg_free(msg); |
| 15576 | return; |
| 15577 | } |
| 15578 | |
| 15579 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15580 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15581 | } |
| 15582 | |
| 15583 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 15584 | struct wireless_dev *wdev, |
| 15585 | enum nl80211_commands cmd) |
| 15586 | { |
| 15587 | struct sk_buff *msg; |
| 15588 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15589 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15590 | if (!msg) |
| 15591 | return; |
| 15592 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15593 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15594 | nlmsg_free(msg); |
| 15595 | return; |
| 15596 | } |
| 15597 | |
| 15598 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15599 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15600 | } |
| 15601 | |
| 15602 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 15603 | struct cfg80211_registered_device *rdev) |
| 15604 | { |
| 15605 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 15606 | struct nlattr *nest; |
| 15607 | int i; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15608 | struct cfg80211_scan_info *info; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15609 | |
| 15610 | if (WARN_ON(!req)) |
| 15611 | return 0; |
| 15612 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15613 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15614 | if (!nest) |
| 15615 | goto nla_put_failure; |
| 15616 | for (i = 0; i < req->n_ssids; i++) { |
| 15617 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 15618 | goto nla_put_failure; |
| 15619 | } |
| 15620 | nla_nest_end(msg, nest); |
| 15621 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15622 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
| 15623 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); |
| 15624 | if (!nest) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15625 | goto nla_put_failure; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15626 | for (i = 0; i < req->n_channels; i++) { |
| 15627 | if (nla_put_u32(msg, i, |
| 15628 | ieee80211_channel_to_khz(req->channels[i]))) |
| 15629 | goto nla_put_failure; |
| 15630 | } |
| 15631 | nla_nest_end(msg, nest); |
| 15632 | } else { |
| 15633 | nest = nla_nest_start_noflag(msg, |
| 15634 | NL80211_ATTR_SCAN_FREQUENCIES); |
| 15635 | if (!nest) |
| 15636 | goto nla_put_failure; |
| 15637 | for (i = 0; i < req->n_channels; i++) { |
| 15638 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 15639 | goto nla_put_failure; |
| 15640 | } |
| 15641 | nla_nest_end(msg, nest); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15642 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15643 | |
| 15644 | if (req->ie && |
| 15645 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 15646 | goto nla_put_failure; |
| 15647 | |
| 15648 | if (req->flags && |
| 15649 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 15650 | goto nla_put_failure; |
| 15651 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15652 | info = rdev->int_scan_req ? &rdev->int_scan_req->info : |
| 15653 | &rdev->scan_req->info; |
| 15654 | if (info->scan_start_tsf && |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15655 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15656 | info->scan_start_tsf, NL80211_BSS_PAD) || |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15657 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15658 | info->tsf_bssid))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15659 | goto nla_put_failure; |
| 15660 | |
| 15661 | return 0; |
| 15662 | nla_put_failure: |
| 15663 | return -ENOBUFS; |
| 15664 | } |
| 15665 | |
| 15666 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
| 15667 | struct cfg80211_registered_device *rdev, |
| 15668 | struct wireless_dev *wdev, |
| 15669 | u32 portid, u32 seq, int flags, |
| 15670 | u32 cmd) |
| 15671 | { |
| 15672 | void *hdr; |
| 15673 | |
| 15674 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
| 15675 | if (!hdr) |
| 15676 | return -1; |
| 15677 | |
| 15678 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15679 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15680 | wdev->netdev->ifindex)) || |
| 15681 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15682 | NL80211_ATTR_PAD)) |
| 15683 | goto nla_put_failure; |
| 15684 | |
| 15685 | /* ignore errors and send incomplete event anyway */ |
| 15686 | nl80211_add_scan_req(msg, rdev); |
| 15687 | |
| 15688 | genlmsg_end(msg, hdr); |
| 15689 | return 0; |
| 15690 | |
| 15691 | nla_put_failure: |
| 15692 | genlmsg_cancel(msg, hdr); |
| 15693 | return -EMSGSIZE; |
| 15694 | } |
| 15695 | |
| 15696 | static int |
| 15697 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
| 15698 | struct cfg80211_sched_scan_request *req, u32 cmd) |
| 15699 | { |
| 15700 | void *hdr; |
| 15701 | |
| 15702 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15703 | if (!hdr) |
| 15704 | return -1; |
| 15705 | |
| 15706 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 15707 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 15708 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 15709 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 15710 | NL80211_ATTR_PAD)) |
| 15711 | goto nla_put_failure; |
| 15712 | |
| 15713 | genlmsg_end(msg, hdr); |
| 15714 | return 0; |
| 15715 | |
| 15716 | nla_put_failure: |
| 15717 | genlmsg_cancel(msg, hdr); |
| 15718 | return -EMSGSIZE; |
| 15719 | } |
| 15720 | |
| 15721 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 15722 | struct wireless_dev *wdev) |
| 15723 | { |
| 15724 | struct sk_buff *msg; |
| 15725 | |
| 15726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15727 | if (!msg) |
| 15728 | return; |
| 15729 | |
| 15730 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
| 15731 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 15732 | nlmsg_free(msg); |
| 15733 | return; |
| 15734 | } |
| 15735 | |
| 15736 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15737 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
| 15738 | } |
| 15739 | |
| 15740 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 15741 | struct wireless_dev *wdev, bool aborted) |
| 15742 | { |
| 15743 | struct sk_buff *msg; |
| 15744 | |
| 15745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15746 | if (!msg) |
| 15747 | return NULL; |
| 15748 | |
| 15749 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
| 15750 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 15751 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
| 15752 | nlmsg_free(msg); |
| 15753 | return NULL; |
| 15754 | } |
| 15755 | |
| 15756 | return msg; |
| 15757 | } |
| 15758 | |
| 15759 | /* send message created by nl80211_build_scan_msg() */ |
| 15760 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 15761 | struct sk_buff *msg) |
| 15762 | { |
| 15763 | if (!msg) |
| 15764 | return; |
| 15765 | |
| 15766 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15767 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
| 15768 | } |
| 15769 | |
| 15770 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
| 15771 | { |
| 15772 | struct sk_buff *msg; |
| 15773 | |
| 15774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15775 | if (!msg) |
| 15776 | return; |
| 15777 | |
| 15778 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
| 15779 | nlmsg_free(msg); |
| 15780 | return; |
| 15781 | } |
| 15782 | |
| 15783 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
| 15784 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
| 15785 | } |
| 15786 | |
| 15787 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 15788 | struct regulatory_request *request) |
| 15789 | { |
| 15790 | /* Userspace can always count this one always being set */ |
| 15791 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 15792 | goto nla_put_failure; |
| 15793 | |
| 15794 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 15795 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15796 | NL80211_REGDOM_TYPE_WORLD)) |
| 15797 | goto nla_put_failure; |
| 15798 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 15799 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15800 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 15801 | goto nla_put_failure; |
| 15802 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 15803 | request->intersect) { |
| 15804 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15805 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 15806 | goto nla_put_failure; |
| 15807 | } else { |
| 15808 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15809 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 15810 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 15811 | request->alpha2)) |
| 15812 | goto nla_put_failure; |
| 15813 | } |
| 15814 | |
| 15815 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 15816 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 15817 | |
| 15818 | if (wiphy && |
| 15819 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 15820 | goto nla_put_failure; |
| 15821 | |
| 15822 | if (wiphy && |
| 15823 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 15824 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 15825 | goto nla_put_failure; |
| 15826 | } |
| 15827 | |
| 15828 | return true; |
| 15829 | |
| 15830 | nla_put_failure: |
| 15831 | return false; |
| 15832 | } |
| 15833 | |
| 15834 | /* |
| 15835 | * This can happen on global regulatory changes or device specific settings |
| 15836 | * based on custom regulatory domains. |
| 15837 | */ |
| 15838 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 15839 | struct regulatory_request *request) |
| 15840 | { |
| 15841 | struct sk_buff *msg; |
| 15842 | void *hdr; |
| 15843 | |
| 15844 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15845 | if (!msg) |
| 15846 | return; |
| 15847 | |
| 15848 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15849 | if (!hdr) |
| 15850 | goto nla_put_failure; |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15851 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15852 | if (!nl80211_reg_change_event_fill(msg, request)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15853 | goto nla_put_failure; |
| 15854 | |
| 15855 | genlmsg_end(msg, hdr); |
| 15856 | |
| 15857 | rcu_read_lock(); |
| 15858 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
| 15859 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
| 15860 | rcu_read_unlock(); |
| 15861 | |
| 15862 | return; |
| 15863 | |
| 15864 | nla_put_failure: |
| 15865 | nlmsg_free(msg); |
| 15866 | } |
| 15867 | |
| 15868 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 15869 | struct net_device *netdev, |
| 15870 | const u8 *buf, size_t len, |
| 15871 | enum nl80211_commands cmd, gfp_t gfp, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15872 | int uapsd_queues, const u8 *req_ies, |
| 15873 | size_t req_ies_len) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15874 | { |
| 15875 | struct sk_buff *msg; |
| 15876 | void *hdr; |
| 15877 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15878 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15879 | if (!msg) |
| 15880 | return; |
| 15881 | |
| 15882 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15883 | if (!hdr) { |
| 15884 | nlmsg_free(msg); |
| 15885 | return; |
| 15886 | } |
| 15887 | |
| 15888 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15889 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15890 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15891 | (req_ies && |
| 15892 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15893 | goto nla_put_failure; |
| 15894 | |
| 15895 | if (uapsd_queues >= 0) { |
| 15896 | struct nlattr *nla_wmm = |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15897 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15898 | if (!nla_wmm) |
| 15899 | goto nla_put_failure; |
| 15900 | |
| 15901 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 15902 | uapsd_queues)) |
| 15903 | goto nla_put_failure; |
| 15904 | |
| 15905 | nla_nest_end(msg, nla_wmm); |
| 15906 | } |
| 15907 | |
| 15908 | genlmsg_end(msg, hdr); |
| 15909 | |
| 15910 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15911 | NL80211_MCGRP_MLME, gfp); |
| 15912 | return; |
| 15913 | |
| 15914 | nla_put_failure: |
| 15915 | nlmsg_free(msg); |
| 15916 | } |
| 15917 | |
| 15918 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
| 15919 | struct net_device *netdev, const u8 *buf, |
| 15920 | size_t len, gfp_t gfp) |
| 15921 | { |
| 15922 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15923 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15924 | } |
| 15925 | |
| 15926 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 15927 | struct net_device *netdev, const u8 *buf, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15928 | size_t len, gfp_t gfp, int uapsd_queues, |
| 15929 | const u8 *req_ies, size_t req_ies_len) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15930 | { |
| 15931 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15932 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
| 15933 | req_ies, req_ies_len); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15934 | } |
| 15935 | |
| 15936 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
| 15937 | struct net_device *netdev, const u8 *buf, |
| 15938 | size_t len, gfp_t gfp) |
| 15939 | { |
| 15940 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15941 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15942 | } |
| 15943 | |
| 15944 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 15945 | struct net_device *netdev, const u8 *buf, |
| 15946 | size_t len, gfp_t gfp) |
| 15947 | { |
| 15948 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15949 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15950 | } |
| 15951 | |
| 15952 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 15953 | size_t len) |
| 15954 | { |
| 15955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15956 | struct wiphy *wiphy = wdev->wiphy; |
| 15957 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 15958 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 15959 | u32 cmd; |
| 15960 | |
| 15961 | if (WARN_ON(len < 2)) |
| 15962 | return; |
| 15963 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15964 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15965 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15966 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15967 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 15968 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
| 15969 | if (wdev->unprot_beacon_reported && |
| 15970 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) |
| 15971 | return; |
| 15972 | cmd = NL80211_CMD_UNPROT_BEACON; |
| 15973 | wdev->unprot_beacon_reported = jiffies; |
| 15974 | } else { |
| 15975 | return; |
| 15976 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15977 | |
| 15978 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 15979 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
| 15980 | NULL, 0); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15981 | } |
| 15982 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
| 15983 | |
| 15984 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 15985 | struct net_device *netdev, int cmd, |
| 15986 | const u8 *addr, gfp_t gfp) |
| 15987 | { |
| 15988 | struct sk_buff *msg; |
| 15989 | void *hdr; |
| 15990 | |
| 15991 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15992 | if (!msg) |
| 15993 | return; |
| 15994 | |
| 15995 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15996 | if (!hdr) { |
| 15997 | nlmsg_free(msg); |
| 15998 | return; |
| 15999 | } |
| 16000 | |
| 16001 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16002 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16003 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 16004 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16005 | goto nla_put_failure; |
| 16006 | |
| 16007 | genlmsg_end(msg, hdr); |
| 16008 | |
| 16009 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16010 | NL80211_MCGRP_MLME, gfp); |
| 16011 | return; |
| 16012 | |
| 16013 | nla_put_failure: |
| 16014 | nlmsg_free(msg); |
| 16015 | } |
| 16016 | |
| 16017 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
| 16018 | struct net_device *netdev, const u8 *addr, |
| 16019 | gfp_t gfp) |
| 16020 | { |
| 16021 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
| 16022 | addr, gfp); |
| 16023 | } |
| 16024 | |
| 16025 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
| 16026 | struct net_device *netdev, const u8 *addr, |
| 16027 | gfp_t gfp) |
| 16028 | { |
| 16029 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 16030 | addr, gfp); |
| 16031 | } |
| 16032 | |
| 16033 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 16034 | struct net_device *netdev, |
| 16035 | struct cfg80211_connect_resp_params *cr, |
| 16036 | gfp_t gfp) |
| 16037 | { |
| 16038 | struct sk_buff *msg; |
| 16039 | void *hdr; |
| 16040 | |
| 16041 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 16042 | cr->fils.kek_len + cr->fils.pmk_len + |
| 16043 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
| 16044 | if (!msg) |
| 16045 | return; |
| 16046 | |
| 16047 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 16048 | if (!hdr) { |
| 16049 | nlmsg_free(msg); |
| 16050 | return; |
| 16051 | } |
| 16052 | |
| 16053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16054 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16055 | (cr->bssid && |
| 16056 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
| 16057 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 16058 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 16059 | cr->status) || |
| 16060 | (cr->status < 0 && |
| 16061 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 16062 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 16063 | cr->timeout_reason))) || |
| 16064 | (cr->req_ie && |
| 16065 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 16066 | (cr->resp_ie && |
| 16067 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
| 16068 | cr->resp_ie)) || |
| 16069 | (cr->fils.update_erp_next_seq_num && |
| 16070 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 16071 | cr->fils.erp_next_seq_num)) || |
| 16072 | (cr->status == WLAN_STATUS_SUCCESS && |
| 16073 | ((cr->fils.kek && |
| 16074 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 16075 | cr->fils.kek)) || |
| 16076 | (cr->fils.pmk && |
| 16077 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 16078 | (cr->fils.pmkid && |
| 16079 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) |
| 16080 | goto nla_put_failure; |
| 16081 | |
| 16082 | genlmsg_end(msg, hdr); |
| 16083 | |
| 16084 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16085 | NL80211_MCGRP_MLME, gfp); |
| 16086 | return; |
| 16087 | |
| 16088 | nla_put_failure: |
| 16089 | nlmsg_free(msg); |
| 16090 | } |
| 16091 | |
| 16092 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 16093 | struct net_device *netdev, |
| 16094 | struct cfg80211_roam_info *info, gfp_t gfp) |
| 16095 | { |
| 16096 | struct sk_buff *msg; |
| 16097 | void *hdr; |
| 16098 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
| 16099 | |
| 16100 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 16101 | info->fils.kek_len + info->fils.pmk_len + |
| 16102 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
| 16103 | if (!msg) |
| 16104 | return; |
| 16105 | |
| 16106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 16107 | if (!hdr) { |
| 16108 | nlmsg_free(msg); |
| 16109 | return; |
| 16110 | } |
| 16111 | |
| 16112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16113 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16114 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 16115 | (info->req_ie && |
| 16116 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 16117 | info->req_ie)) || |
| 16118 | (info->resp_ie && |
| 16119 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
| 16120 | info->resp_ie)) || |
| 16121 | (info->fils.update_erp_next_seq_num && |
| 16122 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 16123 | info->fils.erp_next_seq_num)) || |
| 16124 | (info->fils.kek && |
| 16125 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 16126 | info->fils.kek)) || |
| 16127 | (info->fils.pmk && |
| 16128 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 16129 | (info->fils.pmkid && |
| 16130 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) |
| 16131 | goto nla_put_failure; |
| 16132 | |
| 16133 | genlmsg_end(msg, hdr); |
| 16134 | |
| 16135 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16136 | NL80211_MCGRP_MLME, gfp); |
| 16137 | return; |
| 16138 | |
| 16139 | nla_put_failure: |
| 16140 | nlmsg_free(msg); |
| 16141 | } |
| 16142 | |
| 16143 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 16144 | struct net_device *netdev, const u8 *bssid) |
| 16145 | { |
| 16146 | struct sk_buff *msg; |
| 16147 | void *hdr; |
| 16148 | |
| 16149 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16150 | if (!msg) |
| 16151 | return; |
| 16152 | |
| 16153 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 16154 | if (!hdr) { |
| 16155 | nlmsg_free(msg); |
| 16156 | return; |
| 16157 | } |
| 16158 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16159 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16160 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16161 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16162 | goto nla_put_failure; |
| 16163 | |
| 16164 | genlmsg_end(msg, hdr); |
| 16165 | |
| 16166 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16167 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16168 | return; |
| 16169 | |
| 16170 | nla_put_failure: |
| 16171 | nlmsg_free(msg); |
| 16172 | } |
| 16173 | |
| 16174 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 16175 | struct net_device *netdev, u16 reason, |
| 16176 | const u8 *ie, size_t ie_len, bool from_ap) |
| 16177 | { |
| 16178 | struct sk_buff *msg; |
| 16179 | void *hdr; |
| 16180 | |
| 16181 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
| 16182 | if (!msg) |
| 16183 | return; |
| 16184 | |
| 16185 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 16186 | if (!hdr) { |
| 16187 | nlmsg_free(msg); |
| 16188 | return; |
| 16189 | } |
| 16190 | |
| 16191 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16192 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16193 | (reason && |
| 16194 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 16195 | (from_ap && |
| 16196 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 16197 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 16198 | goto nla_put_failure; |
| 16199 | |
| 16200 | genlmsg_end(msg, hdr); |
| 16201 | |
| 16202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16203 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16204 | return; |
| 16205 | |
| 16206 | nla_put_failure: |
| 16207 | nlmsg_free(msg); |
| 16208 | } |
| 16209 | |
| 16210 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 16211 | struct net_device *netdev, const u8 *bssid, |
| 16212 | gfp_t gfp) |
| 16213 | { |
| 16214 | struct sk_buff *msg; |
| 16215 | void *hdr; |
| 16216 | |
| 16217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16218 | if (!msg) |
| 16219 | return; |
| 16220 | |
| 16221 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 16222 | if (!hdr) { |
| 16223 | nlmsg_free(msg); |
| 16224 | return; |
| 16225 | } |
| 16226 | |
| 16227 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16228 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16229 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16230 | goto nla_put_failure; |
| 16231 | |
| 16232 | genlmsg_end(msg, hdr); |
| 16233 | |
| 16234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16235 | NL80211_MCGRP_MLME, gfp); |
| 16236 | return; |
| 16237 | |
| 16238 | nla_put_failure: |
| 16239 | nlmsg_free(msg); |
| 16240 | } |
| 16241 | |
| 16242 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16243 | const u8 *ie, u8 ie_len, |
| 16244 | int sig_dbm, gfp_t gfp) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16245 | { |
| 16246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16247 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16248 | struct sk_buff *msg; |
| 16249 | void *hdr; |
| 16250 | |
| 16251 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 16252 | return; |
| 16253 | |
| 16254 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 16255 | |
| 16256 | msg = nlmsg_new(100 + ie_len, gfp); |
| 16257 | if (!msg) |
| 16258 | return; |
| 16259 | |
| 16260 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 16261 | if (!hdr) { |
| 16262 | nlmsg_free(msg); |
| 16263 | return; |
| 16264 | } |
| 16265 | |
| 16266 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16267 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16268 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 16269 | (ie_len && ie && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16270 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 16271 | (sig_dbm && |
| 16272 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16273 | goto nla_put_failure; |
| 16274 | |
| 16275 | genlmsg_end(msg, hdr); |
| 16276 | |
| 16277 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16278 | NL80211_MCGRP_MLME, gfp); |
| 16279 | return; |
| 16280 | |
| 16281 | nla_put_failure: |
| 16282 | nlmsg_free(msg); |
| 16283 | } |
| 16284 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
| 16285 | |
| 16286 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 16287 | struct net_device *netdev, const u8 *addr, |
| 16288 | enum nl80211_key_type key_type, int key_id, |
| 16289 | const u8 *tsc, gfp_t gfp) |
| 16290 | { |
| 16291 | struct sk_buff *msg; |
| 16292 | void *hdr; |
| 16293 | |
| 16294 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16295 | if (!msg) |
| 16296 | return; |
| 16297 | |
| 16298 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 16299 | if (!hdr) { |
| 16300 | nlmsg_free(msg); |
| 16301 | return; |
| 16302 | } |
| 16303 | |
| 16304 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16305 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16306 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 16307 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 16308 | (key_id != -1 && |
| 16309 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 16310 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 16311 | goto nla_put_failure; |
| 16312 | |
| 16313 | genlmsg_end(msg, hdr); |
| 16314 | |
| 16315 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16316 | NL80211_MCGRP_MLME, gfp); |
| 16317 | return; |
| 16318 | |
| 16319 | nla_put_failure: |
| 16320 | nlmsg_free(msg); |
| 16321 | } |
| 16322 | |
| 16323 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 16324 | struct ieee80211_channel *channel_before, |
| 16325 | struct ieee80211_channel *channel_after) |
| 16326 | { |
| 16327 | struct sk_buff *msg; |
| 16328 | void *hdr; |
| 16329 | struct nlattr *nl_freq; |
| 16330 | |
| 16331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
| 16332 | if (!msg) |
| 16333 | return; |
| 16334 | |
| 16335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 16336 | if (!hdr) { |
| 16337 | nlmsg_free(msg); |
| 16338 | return; |
| 16339 | } |
| 16340 | |
| 16341 | /* |
| 16342 | * Since we are applying the beacon hint to a wiphy we know its |
| 16343 | * wiphy_idx is valid |
| 16344 | */ |
| 16345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 16346 | goto nla_put_failure; |
| 16347 | |
| 16348 | /* Before */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16349 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16350 | if (!nl_freq) |
| 16351 | goto nla_put_failure; |
| 16352 | |
| 16353 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
| 16354 | goto nla_put_failure; |
| 16355 | nla_nest_end(msg, nl_freq); |
| 16356 | |
| 16357 | /* After */ |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16358 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16359 | if (!nl_freq) |
| 16360 | goto nla_put_failure; |
| 16361 | |
| 16362 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
| 16363 | goto nla_put_failure; |
| 16364 | nla_nest_end(msg, nl_freq); |
| 16365 | |
| 16366 | genlmsg_end(msg, hdr); |
| 16367 | |
| 16368 | rcu_read_lock(); |
| 16369 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
| 16370 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
| 16371 | rcu_read_unlock(); |
| 16372 | |
| 16373 | return; |
| 16374 | |
| 16375 | nla_put_failure: |
| 16376 | nlmsg_free(msg); |
| 16377 | } |
| 16378 | |
| 16379 | static void nl80211_send_remain_on_chan_event( |
| 16380 | int cmd, struct cfg80211_registered_device *rdev, |
| 16381 | struct wireless_dev *wdev, u64 cookie, |
| 16382 | struct ieee80211_channel *chan, |
| 16383 | unsigned int duration, gfp_t gfp) |
| 16384 | { |
| 16385 | struct sk_buff *msg; |
| 16386 | void *hdr; |
| 16387 | |
| 16388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16389 | if (!msg) |
| 16390 | return; |
| 16391 | |
| 16392 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16393 | if (!hdr) { |
| 16394 | nlmsg_free(msg); |
| 16395 | return; |
| 16396 | } |
| 16397 | |
| 16398 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16399 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16400 | wdev->netdev->ifindex)) || |
| 16401 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16402 | NL80211_ATTR_PAD) || |
| 16403 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 16404 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 16405 | NL80211_CHAN_NO_HT) || |
| 16406 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16407 | NL80211_ATTR_PAD)) |
| 16408 | goto nla_put_failure; |
| 16409 | |
| 16410 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 16411 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 16412 | goto nla_put_failure; |
| 16413 | |
| 16414 | genlmsg_end(msg, hdr); |
| 16415 | |
| 16416 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16417 | NL80211_MCGRP_MLME, gfp); |
| 16418 | return; |
| 16419 | |
| 16420 | nla_put_failure: |
| 16421 | nlmsg_free(msg); |
| 16422 | } |
| 16423 | |
| 16424 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 16425 | struct ieee80211_channel *chan, |
| 16426 | unsigned int duration, gfp_t gfp) |
| 16427 | { |
| 16428 | struct wiphy *wiphy = wdev->wiphy; |
| 16429 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16430 | |
| 16431 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
| 16432 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 16433 | rdev, wdev, cookie, chan, |
| 16434 | duration, gfp); |
| 16435 | } |
| 16436 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
| 16437 | |
| 16438 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 16439 | struct ieee80211_channel *chan, |
| 16440 | gfp_t gfp) |
| 16441 | { |
| 16442 | struct wiphy *wiphy = wdev->wiphy; |
| 16443 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16444 | |
| 16445 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
| 16446 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 16447 | rdev, wdev, cookie, chan, 0, gfp); |
| 16448 | } |
| 16449 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
| 16450 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16451 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 16452 | struct ieee80211_channel *chan, |
| 16453 | gfp_t gfp) |
| 16454 | { |
| 16455 | struct wiphy *wiphy = wdev->wiphy; |
| 16456 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16457 | |
| 16458 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 16459 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 16460 | rdev, wdev, cookie, chan, 0, gfp); |
| 16461 | } |
| 16462 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 16463 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16464 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 16465 | struct station_info *sinfo, gfp_t gfp) |
| 16466 | { |
| 16467 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 16468 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16469 | struct sk_buff *msg; |
| 16470 | |
| 16471 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 16472 | |
| 16473 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16474 | if (!msg) |
| 16475 | return; |
| 16476 | |
| 16477 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
| 16478 | rdev, dev, mac_addr, sinfo) < 0) { |
| 16479 | nlmsg_free(msg); |
| 16480 | return; |
| 16481 | } |
| 16482 | |
| 16483 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16484 | NL80211_MCGRP_MLME, gfp); |
| 16485 | } |
| 16486 | EXPORT_SYMBOL(cfg80211_new_sta); |
| 16487 | |
| 16488 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 16489 | struct station_info *sinfo, gfp_t gfp) |
| 16490 | { |
| 16491 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 16492 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16493 | struct sk_buff *msg; |
| 16494 | struct station_info empty_sinfo = {}; |
| 16495 | |
| 16496 | if (!sinfo) |
| 16497 | sinfo = &empty_sinfo; |
| 16498 | |
| 16499 | trace_cfg80211_del_sta(dev, mac_addr); |
| 16500 | |
| 16501 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16502 | if (!msg) { |
| 16503 | cfg80211_sinfo_release_content(sinfo); |
| 16504 | return; |
| 16505 | } |
| 16506 | |
| 16507 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
| 16508 | rdev, dev, mac_addr, sinfo) < 0) { |
| 16509 | nlmsg_free(msg); |
| 16510 | return; |
| 16511 | } |
| 16512 | |
| 16513 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16514 | NL80211_MCGRP_MLME, gfp); |
| 16515 | } |
| 16516 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
| 16517 | |
| 16518 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 16519 | enum nl80211_connect_failed_reason reason, |
| 16520 | gfp_t gfp) |
| 16521 | { |
| 16522 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 16523 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16524 | struct sk_buff *msg; |
| 16525 | void *hdr; |
| 16526 | |
| 16527 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 16528 | if (!msg) |
| 16529 | return; |
| 16530 | |
| 16531 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 16532 | if (!hdr) { |
| 16533 | nlmsg_free(msg); |
| 16534 | return; |
| 16535 | } |
| 16536 | |
| 16537 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16538 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 16539 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 16540 | goto nla_put_failure; |
| 16541 | |
| 16542 | genlmsg_end(msg, hdr); |
| 16543 | |
| 16544 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16545 | NL80211_MCGRP_MLME, gfp); |
| 16546 | return; |
| 16547 | |
| 16548 | nla_put_failure: |
| 16549 | nlmsg_free(msg); |
| 16550 | } |
| 16551 | EXPORT_SYMBOL(cfg80211_conn_failed); |
| 16552 | |
| 16553 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 16554 | const u8 *addr, gfp_t gfp) |
| 16555 | { |
| 16556 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16557 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16558 | struct sk_buff *msg; |
| 16559 | void *hdr; |
| 16560 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
| 16561 | |
| 16562 | if (!nlportid) |
| 16563 | return false; |
| 16564 | |
| 16565 | msg = nlmsg_new(100, gfp); |
| 16566 | if (!msg) |
| 16567 | return true; |
| 16568 | |
| 16569 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16570 | if (!hdr) { |
| 16571 | nlmsg_free(msg); |
| 16572 | return true; |
| 16573 | } |
| 16574 | |
| 16575 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16576 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16577 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16578 | goto nla_put_failure; |
| 16579 | |
| 16580 | genlmsg_end(msg, hdr); |
| 16581 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16582 | return true; |
| 16583 | |
| 16584 | nla_put_failure: |
| 16585 | nlmsg_free(msg); |
| 16586 | return true; |
| 16587 | } |
| 16588 | |
| 16589 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 16590 | const u8 *addr, gfp_t gfp) |
| 16591 | { |
| 16592 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16593 | bool ret; |
| 16594 | |
| 16595 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 16596 | |
| 16597 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16598 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 16599 | trace_cfg80211_return_bool(false); |
| 16600 | return false; |
| 16601 | } |
| 16602 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 16603 | addr, gfp); |
| 16604 | trace_cfg80211_return_bool(ret); |
| 16605 | return ret; |
| 16606 | } |
| 16607 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 16608 | |
| 16609 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 16610 | const u8 *addr, gfp_t gfp) |
| 16611 | { |
| 16612 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16613 | bool ret; |
| 16614 | |
| 16615 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 16616 | |
| 16617 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16618 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 16619 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 16620 | trace_cfg80211_return_bool(false); |
| 16621 | return false; |
| 16622 | } |
| 16623 | ret = __nl80211_unexpected_frame(dev, |
| 16624 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 16625 | addr, gfp); |
| 16626 | trace_cfg80211_return_bool(ret); |
| 16627 | return ret; |
| 16628 | } |
| 16629 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
| 16630 | |
| 16631 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 16632 | struct wireless_dev *wdev, u32 nlportid, |
| 16633 | int freq, int sig_dbm, |
| 16634 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
| 16635 | { |
| 16636 | struct net_device *netdev = wdev->netdev; |
| 16637 | struct sk_buff *msg; |
| 16638 | void *hdr; |
| 16639 | |
| 16640 | msg = nlmsg_new(100 + len, gfp); |
| 16641 | if (!msg) |
| 16642 | return -ENOMEM; |
| 16643 | |
| 16644 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 16645 | if (!hdr) { |
| 16646 | nlmsg_free(msg); |
| 16647 | return -ENOMEM; |
| 16648 | } |
| 16649 | |
| 16650 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16651 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16652 | netdev->ifindex)) || |
| 16653 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16654 | NL80211_ATTR_PAD) || |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16655 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || |
| 16656 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16657 | (sig_dbm && |
| 16658 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 16659 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16660 | (flags && |
| 16661 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
| 16662 | goto nla_put_failure; |
| 16663 | |
| 16664 | genlmsg_end(msg, hdr); |
| 16665 | |
| 16666 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16667 | |
| 16668 | nla_put_failure: |
| 16669 | nlmsg_free(msg); |
| 16670 | return -ENOBUFS; |
| 16671 | } |
| 16672 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16673 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16674 | const u8 *buf, size_t len, bool ack, |
| 16675 | gfp_t gfp, enum nl80211_commands command) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16676 | { |
| 16677 | struct wiphy *wiphy = wdev->wiphy; |
| 16678 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16679 | struct net_device *netdev = wdev->netdev; |
| 16680 | struct sk_buff *msg; |
| 16681 | void *hdr; |
| 16682 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16683 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
| 16684 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 16685 | else |
| 16686 | trace_cfg80211_control_port_tx_status(wdev, cookie, ack); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16687 | |
| 16688 | msg = nlmsg_new(100 + len, gfp); |
| 16689 | if (!msg) |
| 16690 | return; |
| 16691 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16692 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16693 | if (!hdr) { |
| 16694 | nlmsg_free(msg); |
| 16695 | return; |
| 16696 | } |
| 16697 | |
| 16698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16699 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16700 | netdev->ifindex)) || |
| 16701 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16702 | NL80211_ATTR_PAD) || |
| 16703 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16704 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16705 | NL80211_ATTR_PAD) || |
| 16706 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 16707 | goto nla_put_failure; |
| 16708 | |
| 16709 | genlmsg_end(msg, hdr); |
| 16710 | |
| 16711 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16712 | NL80211_MCGRP_MLME, gfp); |
| 16713 | return; |
| 16714 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16715 | nla_put_failure: |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16716 | nlmsg_free(msg); |
| 16717 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16718 | |
| 16719 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16720 | const u8 *buf, size_t len, bool ack, |
| 16721 | gfp_t gfp) |
| 16722 | { |
| 16723 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16724 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
| 16725 | } |
| 16726 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); |
| 16727 | |
| 16728 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16729 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
| 16730 | { |
| 16731 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16732 | NL80211_CMD_FRAME_TX_STATUS); |
| 16733 | } |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16734 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
| 16735 | |
| 16736 | static int __nl80211_rx_control_port(struct net_device *dev, |
| 16737 | struct sk_buff *skb, |
| 16738 | bool unencrypted, gfp_t gfp) |
| 16739 | { |
| 16740 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16741 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16742 | struct ethhdr *ehdr = eth_hdr(skb); |
| 16743 | const u8 *addr = ehdr->h_source; |
| 16744 | u16 proto = be16_to_cpu(skb->protocol); |
| 16745 | struct sk_buff *msg; |
| 16746 | void *hdr; |
| 16747 | struct nlattr *frame; |
| 16748 | |
| 16749 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 16750 | |
| 16751 | if (!nlportid) |
| 16752 | return -ENOENT; |
| 16753 | |
| 16754 | msg = nlmsg_new(100 + skb->len, gfp); |
| 16755 | if (!msg) |
| 16756 | return -ENOMEM; |
| 16757 | |
| 16758 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 16759 | if (!hdr) { |
| 16760 | nlmsg_free(msg); |
| 16761 | return -ENOBUFS; |
| 16762 | } |
| 16763 | |
| 16764 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16765 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16766 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16767 | NL80211_ATTR_PAD) || |
| 16768 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 16769 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 16770 | (unencrypted && nla_put_flag(msg, |
| 16771 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 16772 | goto nla_put_failure; |
| 16773 | |
| 16774 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 16775 | if (!frame) |
| 16776 | goto nla_put_failure; |
| 16777 | |
| 16778 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
| 16779 | genlmsg_end(msg, hdr); |
| 16780 | |
| 16781 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16782 | |
| 16783 | nla_put_failure: |
| 16784 | nlmsg_free(msg); |
| 16785 | return -ENOBUFS; |
| 16786 | } |
| 16787 | |
| 16788 | bool cfg80211_rx_control_port(struct net_device *dev, |
| 16789 | struct sk_buff *skb, bool unencrypted) |
| 16790 | { |
| 16791 | int ret; |
| 16792 | |
| 16793 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 16794 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
| 16795 | trace_cfg80211_return_bool(ret == 0); |
| 16796 | return ret == 0; |
| 16797 | } |
| 16798 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 16799 | |
| 16800 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 16801 | const char *mac, gfp_t gfp) |
| 16802 | { |
| 16803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16804 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16805 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16806 | void **cb; |
| 16807 | |
| 16808 | if (!msg) |
| 16809 | return NULL; |
| 16810 | |
| 16811 | cb = (void **)msg->cb; |
| 16812 | |
| 16813 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 16814 | if (!cb[0]) { |
| 16815 | nlmsg_free(msg); |
| 16816 | return NULL; |
| 16817 | } |
| 16818 | |
| 16819 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16820 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 16821 | goto nla_put_failure; |
| 16822 | |
| 16823 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 16824 | goto nla_put_failure; |
| 16825 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16826 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16827 | if (!cb[1]) |
| 16828 | goto nla_put_failure; |
| 16829 | |
| 16830 | cb[2] = rdev; |
| 16831 | |
| 16832 | return msg; |
| 16833 | nla_put_failure: |
| 16834 | nlmsg_free(msg); |
| 16835 | return NULL; |
| 16836 | } |
| 16837 | |
| 16838 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 16839 | { |
| 16840 | void **cb = (void **)msg->cb; |
| 16841 | struct cfg80211_registered_device *rdev = cb[2]; |
| 16842 | |
| 16843 | nla_nest_end(msg, cb[1]); |
| 16844 | genlmsg_end(msg, cb[0]); |
| 16845 | |
| 16846 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 16847 | |
| 16848 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16849 | NL80211_MCGRP_MLME, gfp); |
| 16850 | } |
| 16851 | |
| 16852 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 16853 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 16854 | s32 rssi_level, gfp_t gfp) |
| 16855 | { |
| 16856 | struct sk_buff *msg; |
| 16857 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16858 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16859 | |
| 16860 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
| 16861 | |
| 16862 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 16863 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 16864 | return; |
| 16865 | |
| 16866 | if (wdev->cqm_config) { |
| 16867 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 16868 | |
| 16869 | cfg80211_cqm_rssi_update(rdev, dev); |
| 16870 | |
| 16871 | if (rssi_level == 0) |
| 16872 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 16873 | } |
| 16874 | |
| 16875 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16876 | if (!msg) |
| 16877 | return; |
| 16878 | |
| 16879 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 16880 | rssi_event)) |
| 16881 | goto nla_put_failure; |
| 16882 | |
| 16883 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 16884 | rssi_level)) |
| 16885 | goto nla_put_failure; |
| 16886 | |
| 16887 | cfg80211_send_cqm(msg, gfp); |
| 16888 | |
| 16889 | return; |
| 16890 | |
| 16891 | nla_put_failure: |
| 16892 | nlmsg_free(msg); |
| 16893 | } |
| 16894 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
| 16895 | |
| 16896 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 16897 | const u8 *peer, u32 num_packets, |
| 16898 | u32 rate, u32 intvl, gfp_t gfp) |
| 16899 | { |
| 16900 | struct sk_buff *msg; |
| 16901 | |
| 16902 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16903 | if (!msg) |
| 16904 | return; |
| 16905 | |
| 16906 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 16907 | goto nla_put_failure; |
| 16908 | |
| 16909 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 16910 | goto nla_put_failure; |
| 16911 | |
| 16912 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 16913 | goto nla_put_failure; |
| 16914 | |
| 16915 | cfg80211_send_cqm(msg, gfp); |
| 16916 | return; |
| 16917 | |
| 16918 | nla_put_failure: |
| 16919 | nlmsg_free(msg); |
| 16920 | } |
| 16921 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 16922 | |
| 16923 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 16924 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 16925 | { |
| 16926 | struct sk_buff *msg; |
| 16927 | |
| 16928 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 16929 | |
| 16930 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16931 | if (!msg) |
| 16932 | return; |
| 16933 | |
| 16934 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 16935 | goto nla_put_failure; |
| 16936 | |
| 16937 | cfg80211_send_cqm(msg, gfp); |
| 16938 | return; |
| 16939 | |
| 16940 | nla_put_failure: |
| 16941 | nlmsg_free(msg); |
| 16942 | } |
| 16943 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 16944 | |
| 16945 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 16946 | { |
| 16947 | struct sk_buff *msg; |
| 16948 | |
| 16949 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16950 | if (!msg) |
| 16951 | return; |
| 16952 | |
| 16953 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 16954 | goto nla_put_failure; |
| 16955 | |
| 16956 | cfg80211_send_cqm(msg, gfp); |
| 16957 | return; |
| 16958 | |
| 16959 | nla_put_failure: |
| 16960 | nlmsg_free(msg); |
| 16961 | } |
| 16962 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 16963 | |
| 16964 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 16965 | struct net_device *netdev, const u8 *bssid, |
| 16966 | const u8 *replay_ctr, gfp_t gfp) |
| 16967 | { |
| 16968 | struct sk_buff *msg; |
| 16969 | struct nlattr *rekey_attr; |
| 16970 | void *hdr; |
| 16971 | |
| 16972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16973 | if (!msg) |
| 16974 | return; |
| 16975 | |
| 16976 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 16977 | if (!hdr) { |
| 16978 | nlmsg_free(msg); |
| 16979 | return; |
| 16980 | } |
| 16981 | |
| 16982 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16983 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16984 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16985 | goto nla_put_failure; |
| 16986 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16987 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16988 | if (!rekey_attr) |
| 16989 | goto nla_put_failure; |
| 16990 | |
| 16991 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 16992 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 16993 | goto nla_put_failure; |
| 16994 | |
| 16995 | nla_nest_end(msg, rekey_attr); |
| 16996 | |
| 16997 | genlmsg_end(msg, hdr); |
| 16998 | |
| 16999 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17000 | NL80211_MCGRP_MLME, gfp); |
| 17001 | return; |
| 17002 | |
| 17003 | nla_put_failure: |
| 17004 | nlmsg_free(msg); |
| 17005 | } |
| 17006 | |
| 17007 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 17008 | const u8 *replay_ctr, gfp_t gfp) |
| 17009 | { |
| 17010 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17011 | struct wiphy *wiphy = wdev->wiphy; |
| 17012 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17013 | |
| 17014 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 17015 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 17016 | } |
| 17017 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 17018 | |
| 17019 | static void |
| 17020 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 17021 | struct net_device *netdev, int index, |
| 17022 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 17023 | { |
| 17024 | struct sk_buff *msg; |
| 17025 | struct nlattr *attr; |
| 17026 | void *hdr; |
| 17027 | |
| 17028 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17029 | if (!msg) |
| 17030 | return; |
| 17031 | |
| 17032 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 17033 | if (!hdr) { |
| 17034 | nlmsg_free(msg); |
| 17035 | return; |
| 17036 | } |
| 17037 | |
| 17038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17039 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17040 | goto nla_put_failure; |
| 17041 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17042 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17043 | if (!attr) |
| 17044 | goto nla_put_failure; |
| 17045 | |
| 17046 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 17047 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 17048 | (preauth && |
| 17049 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 17050 | goto nla_put_failure; |
| 17051 | |
| 17052 | nla_nest_end(msg, attr); |
| 17053 | |
| 17054 | genlmsg_end(msg, hdr); |
| 17055 | |
| 17056 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17057 | NL80211_MCGRP_MLME, gfp); |
| 17058 | return; |
| 17059 | |
| 17060 | nla_put_failure: |
| 17061 | nlmsg_free(msg); |
| 17062 | } |
| 17063 | |
| 17064 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 17065 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 17066 | { |
| 17067 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17068 | struct wiphy *wiphy = wdev->wiphy; |
| 17069 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17070 | |
| 17071 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 17072 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 17073 | } |
| 17074 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 17075 | |
| 17076 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 17077 | struct net_device *netdev, |
| 17078 | struct cfg80211_chan_def *chandef, |
| 17079 | gfp_t gfp, |
| 17080 | enum nl80211_commands notif, |
| 17081 | u8 count) |
| 17082 | { |
| 17083 | struct sk_buff *msg; |
| 17084 | void *hdr; |
| 17085 | |
| 17086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17087 | if (!msg) |
| 17088 | return; |
| 17089 | |
| 17090 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
| 17091 | if (!hdr) { |
| 17092 | nlmsg_free(msg); |
| 17093 | return; |
| 17094 | } |
| 17095 | |
| 17096 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17097 | goto nla_put_failure; |
| 17098 | |
| 17099 | if (nl80211_send_chandef(msg, chandef)) |
| 17100 | goto nla_put_failure; |
| 17101 | |
| 17102 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 17103 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 17104 | goto nla_put_failure; |
| 17105 | |
| 17106 | genlmsg_end(msg, hdr); |
| 17107 | |
| 17108 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17109 | NL80211_MCGRP_MLME, gfp); |
| 17110 | return; |
| 17111 | |
| 17112 | nla_put_failure: |
| 17113 | nlmsg_free(msg); |
| 17114 | } |
| 17115 | |
| 17116 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 17117 | struct cfg80211_chan_def *chandef) |
| 17118 | { |
| 17119 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17120 | struct wiphy *wiphy = wdev->wiphy; |
| 17121 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17122 | |
| 17123 | ASSERT_WDEV_LOCK(wdev); |
| 17124 | |
| 17125 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 17126 | |
| 17127 | wdev->chandef = *chandef; |
| 17128 | wdev->preset_chandef = *chandef; |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17129 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 17130 | if ((wdev->iftype == NL80211_IFTYPE_STATION || |
| 17131 | wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17132 | !WARN_ON(!wdev->current_bss)) |
| 17133 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
| 17134 | |
| 17135 | cfg80211_sched_dfs_chan_update(rdev); |
| 17136 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17137 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17138 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
| 17139 | } |
| 17140 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 17141 | |
| 17142 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 17143 | struct cfg80211_chan_def *chandef, |
| 17144 | u8 count) |
| 17145 | { |
| 17146 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17147 | struct wiphy *wiphy = wdev->wiphy; |
| 17148 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17149 | |
| 17150 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 17151 | |
| 17152 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17153 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 17154 | } |
| 17155 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 17156 | |
| 17157 | void |
| 17158 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 17159 | const struct cfg80211_chan_def *chandef, |
| 17160 | enum nl80211_radar_event event, |
| 17161 | struct net_device *netdev, gfp_t gfp) |
| 17162 | { |
| 17163 | struct sk_buff *msg; |
| 17164 | void *hdr; |
| 17165 | |
| 17166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17167 | if (!msg) |
| 17168 | return; |
| 17169 | |
| 17170 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 17171 | if (!hdr) { |
| 17172 | nlmsg_free(msg); |
| 17173 | return; |
| 17174 | } |
| 17175 | |
| 17176 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17177 | goto nla_put_failure; |
| 17178 | |
| 17179 | /* NOP and radar events don't need a netdev parameter */ |
| 17180 | if (netdev) { |
| 17181 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 17182 | |
| 17183 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17184 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17185 | NL80211_ATTR_PAD)) |
| 17186 | goto nla_put_failure; |
| 17187 | } |
| 17188 | |
| 17189 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 17190 | goto nla_put_failure; |
| 17191 | |
| 17192 | if (nl80211_send_chandef(msg, chandef)) |
| 17193 | goto nla_put_failure; |
| 17194 | |
| 17195 | genlmsg_end(msg, hdr); |
| 17196 | |
| 17197 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17198 | NL80211_MCGRP_MLME, gfp); |
| 17199 | return; |
| 17200 | |
| 17201 | nla_put_failure: |
| 17202 | nlmsg_free(msg); |
| 17203 | } |
| 17204 | |
| 17205 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 17206 | struct sta_opmode_info *sta_opmode, |
| 17207 | gfp_t gfp) |
| 17208 | { |
| 17209 | struct sk_buff *msg; |
| 17210 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17211 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17212 | void *hdr; |
| 17213 | |
| 17214 | if (WARN_ON(!mac)) |
| 17215 | return; |
| 17216 | |
| 17217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17218 | if (!msg) |
| 17219 | return; |
| 17220 | |
| 17221 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 17222 | if (!hdr) { |
| 17223 | nlmsg_free(msg); |
| 17224 | return; |
| 17225 | } |
| 17226 | |
| 17227 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17228 | goto nla_put_failure; |
| 17229 | |
| 17230 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 17231 | goto nla_put_failure; |
| 17232 | |
| 17233 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 17234 | goto nla_put_failure; |
| 17235 | |
| 17236 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 17237 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 17238 | goto nla_put_failure; |
| 17239 | |
| 17240 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
| Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 17241 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17242 | goto nla_put_failure; |
| 17243 | |
| 17244 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 17245 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 17246 | goto nla_put_failure; |
| 17247 | |
| 17248 | genlmsg_end(msg, hdr); |
| 17249 | |
| 17250 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17251 | NL80211_MCGRP_MLME, gfp); |
| 17252 | |
| 17253 | return; |
| 17254 | |
| 17255 | nla_put_failure: |
| 17256 | nlmsg_free(msg); |
| 17257 | } |
| 17258 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 17259 | |
| 17260 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 17261 | u64 cookie, bool acked, s32 ack_signal, |
| 17262 | bool is_valid_ack_signal, gfp_t gfp) |
| 17263 | { |
| 17264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17265 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17266 | struct sk_buff *msg; |
| 17267 | void *hdr; |
| 17268 | |
| 17269 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 17270 | |
| 17271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17272 | |
| 17273 | if (!msg) |
| 17274 | return; |
| 17275 | |
| 17276 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 17277 | if (!hdr) { |
| 17278 | nlmsg_free(msg); |
| 17279 | return; |
| 17280 | } |
| 17281 | |
| 17282 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17283 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17284 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 17285 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17286 | NL80211_ATTR_PAD) || |
| 17287 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 17288 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 17289 | ack_signal))) |
| 17290 | goto nla_put_failure; |
| 17291 | |
| 17292 | genlmsg_end(msg, hdr); |
| 17293 | |
| 17294 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17295 | NL80211_MCGRP_MLME, gfp); |
| 17296 | return; |
| 17297 | |
| 17298 | nla_put_failure: |
| 17299 | nlmsg_free(msg); |
| 17300 | } |
| 17301 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 17302 | |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 17303 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
| 17304 | size_t len, int freq, int sig_dbm) |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17305 | { |
| 17306 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17307 | struct sk_buff *msg; |
| 17308 | void *hdr; |
| 17309 | struct cfg80211_beacon_registration *reg; |
| 17310 | |
| 17311 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 17312 | |
| 17313 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17314 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 17315 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 17316 | if (!msg) { |
| 17317 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17318 | return; |
| 17319 | } |
| 17320 | |
| 17321 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 17322 | if (!hdr) |
| 17323 | goto nla_put_failure; |
| 17324 | |
| 17325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17326 | (freq && |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 17327 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 17328 | KHZ_TO_MHZ(freq)) || |
| 17329 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 17330 | freq % 1000))) || |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17331 | (sig_dbm && |
| 17332 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 17333 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 17334 | goto nla_put_failure; |
| 17335 | |
| 17336 | genlmsg_end(msg, hdr); |
| 17337 | |
| 17338 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
| 17339 | } |
| 17340 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17341 | return; |
| 17342 | |
| 17343 | nla_put_failure: |
| 17344 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17345 | nlmsg_free(msg); |
| 17346 | } |
| Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 17347 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17348 | |
| 17349 | #ifdef CONFIG_PM |
| 17350 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 17351 | struct cfg80211_wowlan_wakeup *wakeup) |
| 17352 | { |
| 17353 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 17354 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 17355 | int i, j; |
| 17356 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17357 | nl_results = nla_nest_start_noflag(msg, |
| 17358 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17359 | if (!nl_results) |
| 17360 | return -EMSGSIZE; |
| 17361 | |
| 17362 | for (i = 0; i < nd->n_matches; i++) { |
| 17363 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 17364 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17365 | nl_match = nla_nest_start_noflag(msg, i); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17366 | if (!nl_match) |
| 17367 | break; |
| 17368 | |
| 17369 | /* The SSID attribute is optional in nl80211, but for |
| 17370 | * simplicity reasons it's always present in the |
| 17371 | * cfg80211 structure. If a driver can't pass the |
| 17372 | * SSID, that needs to be changed. A zero length SSID |
| 17373 | * is still a valid SSID (wildcard), so it cannot be |
| 17374 | * used for this purpose. |
| 17375 | */ |
| 17376 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 17377 | match->ssid.ssid)) { |
| 17378 | nla_nest_cancel(msg, nl_match); |
| 17379 | goto out; |
| 17380 | } |
| 17381 | |
| 17382 | if (match->n_channels) { |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17383 | nl_freqs = nla_nest_start_noflag(msg, |
| 17384 | NL80211_ATTR_SCAN_FREQUENCIES); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17385 | if (!nl_freqs) { |
| 17386 | nla_nest_cancel(msg, nl_match); |
| 17387 | goto out; |
| 17388 | } |
| 17389 | |
| 17390 | for (j = 0; j < match->n_channels; j++) { |
| 17391 | if (nla_put_u32(msg, j, match->channels[j])) { |
| 17392 | nla_nest_cancel(msg, nl_freqs); |
| 17393 | nla_nest_cancel(msg, nl_match); |
| 17394 | goto out; |
| 17395 | } |
| 17396 | } |
| 17397 | |
| 17398 | nla_nest_end(msg, nl_freqs); |
| 17399 | } |
| 17400 | |
| 17401 | nla_nest_end(msg, nl_match); |
| 17402 | } |
| 17403 | |
| 17404 | out: |
| 17405 | nla_nest_end(msg, nl_results); |
| 17406 | return 0; |
| 17407 | } |
| 17408 | |
| 17409 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 17410 | struct cfg80211_wowlan_wakeup *wakeup, |
| 17411 | gfp_t gfp) |
| 17412 | { |
| 17413 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17414 | struct sk_buff *msg; |
| 17415 | void *hdr; |
| 17416 | int size = 200; |
| 17417 | |
| 17418 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 17419 | |
| 17420 | if (wakeup) |
| 17421 | size += wakeup->packet_present_len; |
| 17422 | |
| 17423 | msg = nlmsg_new(size, gfp); |
| 17424 | if (!msg) |
| 17425 | return; |
| 17426 | |
| 17427 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 17428 | if (!hdr) |
| 17429 | goto free_msg; |
| 17430 | |
| 17431 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17432 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17433 | NL80211_ATTR_PAD)) |
| 17434 | goto free_msg; |
| 17435 | |
| 17436 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17437 | wdev->netdev->ifindex)) |
| 17438 | goto free_msg; |
| 17439 | |
| 17440 | if (wakeup) { |
| 17441 | struct nlattr *reasons; |
| 17442 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17443 | reasons = nla_nest_start_noflag(msg, |
| 17444 | NL80211_ATTR_WOWLAN_TRIGGERS); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17445 | if (!reasons) |
| 17446 | goto free_msg; |
| 17447 | |
| 17448 | if (wakeup->disconnect && |
| 17449 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 17450 | goto free_msg; |
| 17451 | if (wakeup->magic_pkt && |
| 17452 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 17453 | goto free_msg; |
| 17454 | if (wakeup->gtk_rekey_failure && |
| 17455 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 17456 | goto free_msg; |
| 17457 | if (wakeup->eap_identity_req && |
| 17458 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 17459 | goto free_msg; |
| 17460 | if (wakeup->four_way_handshake && |
| 17461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 17462 | goto free_msg; |
| 17463 | if (wakeup->rfkill_release && |
| 17464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 17465 | goto free_msg; |
| 17466 | |
| 17467 | if (wakeup->pattern_idx >= 0 && |
| 17468 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 17469 | wakeup->pattern_idx)) |
| 17470 | goto free_msg; |
| 17471 | |
| 17472 | if (wakeup->tcp_match && |
| 17473 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 17474 | goto free_msg; |
| 17475 | |
| 17476 | if (wakeup->tcp_connlost && |
| 17477 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 17478 | goto free_msg; |
| 17479 | |
| 17480 | if (wakeup->tcp_nomoretokens && |
| 17481 | nla_put_flag(msg, |
| 17482 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 17483 | goto free_msg; |
| 17484 | |
| 17485 | if (wakeup->packet) { |
| 17486 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 17487 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 17488 | |
| 17489 | if (!wakeup->packet_80211) { |
| 17490 | pkt_attr = |
| 17491 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 17492 | len_attr = |
| 17493 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 17494 | } |
| 17495 | |
| 17496 | if (wakeup->packet_len && |
| 17497 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 17498 | goto free_msg; |
| 17499 | |
| 17500 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 17501 | wakeup->packet)) |
| 17502 | goto free_msg; |
| 17503 | } |
| 17504 | |
| 17505 | if (wakeup->net_detect && |
| 17506 | cfg80211_net_detect_results(msg, wakeup)) |
| 17507 | goto free_msg; |
| 17508 | |
| 17509 | nla_nest_end(msg, reasons); |
| 17510 | } |
| 17511 | |
| 17512 | genlmsg_end(msg, hdr); |
| 17513 | |
| 17514 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17515 | NL80211_MCGRP_MLME, gfp); |
| 17516 | return; |
| 17517 | |
| 17518 | free_msg: |
| 17519 | nlmsg_free(msg); |
| 17520 | } |
| 17521 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 17522 | #endif |
| 17523 | |
| 17524 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 17525 | enum nl80211_tdls_operation oper, |
| 17526 | u16 reason_code, gfp_t gfp) |
| 17527 | { |
| 17528 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17529 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17530 | struct sk_buff *msg; |
| 17531 | void *hdr; |
| 17532 | |
| 17533 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 17534 | reason_code); |
| 17535 | |
| 17536 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17537 | if (!msg) |
| 17538 | return; |
| 17539 | |
| 17540 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 17541 | if (!hdr) { |
| 17542 | nlmsg_free(msg); |
| 17543 | return; |
| 17544 | } |
| 17545 | |
| 17546 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17547 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17548 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 17549 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 17550 | (reason_code > 0 && |
| 17551 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 17552 | goto nla_put_failure; |
| 17553 | |
| 17554 | genlmsg_end(msg, hdr); |
| 17555 | |
| 17556 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17557 | NL80211_MCGRP_MLME, gfp); |
| 17558 | return; |
| 17559 | |
| 17560 | nla_put_failure: |
| 17561 | nlmsg_free(msg); |
| 17562 | } |
| 17563 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 17564 | |
| 17565 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 17566 | unsigned long state, |
| 17567 | void *_notify) |
| 17568 | { |
| 17569 | struct netlink_notify *notify = _notify; |
| 17570 | struct cfg80211_registered_device *rdev; |
| 17571 | struct wireless_dev *wdev; |
| 17572 | struct cfg80211_beacon_registration *reg, *tmp; |
| 17573 | |
| 17574 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
| 17575 | return NOTIFY_DONE; |
| 17576 | |
| 17577 | rcu_read_lock(); |
| 17578 | |
| 17579 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
| 17580 | struct cfg80211_sched_scan_request *sched_scan_req; |
| 17581 | |
| 17582 | list_for_each_entry_rcu(sched_scan_req, |
| 17583 | &rdev->sched_scan_req_list, |
| 17584 | list) { |
| 17585 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 17586 | sched_scan_req->nl_owner_dead = true; |
| 17587 | schedule_work(&rdev->sched_scan_stop_wk); |
| 17588 | } |
| 17589 | } |
| 17590 | |
| 17591 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
| 17592 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
| 17593 | |
| 17594 | if (wdev->owner_nlportid == notify->portid) { |
| 17595 | wdev->nl_owner_dead = true; |
| 17596 | schedule_work(&rdev->destroy_work); |
| 17597 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
| 17598 | schedule_work(&wdev->disconnect_wk); |
| 17599 | } |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17600 | |
| 17601 | cfg80211_release_pmsr(wdev, notify->portid); |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17602 | } |
| 17603 | |
| 17604 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17605 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 17606 | list) { |
| 17607 | if (reg->nlportid == notify->portid) { |
| 17608 | list_del(®->list); |
| 17609 | kfree(reg); |
| 17610 | break; |
| 17611 | } |
| 17612 | } |
| 17613 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17614 | } |
| 17615 | |
| 17616 | rcu_read_unlock(); |
| 17617 | |
| 17618 | /* |
| 17619 | * It is possible that the user space process that is controlling the |
| 17620 | * indoor setting disappeared, so notify the regulatory core. |
| 17621 | */ |
| 17622 | regulatory_netlink_notify(notify->portid); |
| 17623 | return NOTIFY_OK; |
| 17624 | } |
| 17625 | |
| 17626 | static struct notifier_block nl80211_netlink_notifier = { |
| 17627 | .notifier_call = nl80211_netlink_notify, |
| 17628 | }; |
| 17629 | |
| 17630 | void cfg80211_ft_event(struct net_device *netdev, |
| 17631 | struct cfg80211_ft_event_params *ft_event) |
| 17632 | { |
| 17633 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17634 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17635 | struct sk_buff *msg; |
| 17636 | void *hdr; |
| 17637 | |
| 17638 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 17639 | |
| 17640 | if (!ft_event->target_ap) |
| 17641 | return; |
| 17642 | |
| 17643 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 17644 | GFP_KERNEL); |
| 17645 | if (!msg) |
| 17646 | return; |
| 17647 | |
| 17648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 17649 | if (!hdr) |
| 17650 | goto out; |
| 17651 | |
| 17652 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17653 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17654 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 17655 | goto out; |
| 17656 | |
| 17657 | if (ft_event->ies && |
| 17658 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 17659 | goto out; |
| 17660 | if (ft_event->ric_ies && |
| 17661 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 17662 | ft_event->ric_ies)) |
| 17663 | goto out; |
| 17664 | |
| 17665 | genlmsg_end(msg, hdr); |
| 17666 | |
| 17667 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17668 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17669 | return; |
| 17670 | out: |
| 17671 | nlmsg_free(msg); |
| 17672 | } |
| 17673 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 17674 | |
| 17675 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 17676 | { |
| 17677 | struct cfg80211_registered_device *rdev; |
| 17678 | struct sk_buff *msg; |
| 17679 | void *hdr; |
| 17680 | u32 nlportid; |
| 17681 | |
| 17682 | rdev = wiphy_to_rdev(wdev->wiphy); |
| 17683 | if (!rdev->crit_proto_nlportid) |
| 17684 | return; |
| 17685 | |
| 17686 | nlportid = rdev->crit_proto_nlportid; |
| 17687 | rdev->crit_proto_nlportid = 0; |
| 17688 | |
| 17689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17690 | if (!msg) |
| 17691 | return; |
| 17692 | |
| 17693 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 17694 | if (!hdr) |
| 17695 | goto nla_put_failure; |
| 17696 | |
| 17697 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17698 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17699 | NL80211_ATTR_PAD)) |
| 17700 | goto nla_put_failure; |
| 17701 | |
| 17702 | genlmsg_end(msg, hdr); |
| 17703 | |
| 17704 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17705 | return; |
| 17706 | |
| 17707 | nla_put_failure: |
| 17708 | nlmsg_free(msg); |
| 17709 | } |
| 17710 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 17711 | |
| 17712 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 17713 | { |
| 17714 | struct wiphy *wiphy = wdev->wiphy; |
| 17715 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17716 | struct sk_buff *msg; |
| 17717 | void *hdr; |
| 17718 | |
| 17719 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 17720 | if (!msg) |
| 17721 | return; |
| 17722 | |
| 17723 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 17724 | if (!hdr) |
| 17725 | goto out; |
| 17726 | |
| 17727 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17728 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 17729 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17730 | NL80211_ATTR_PAD)) |
| 17731 | goto out; |
| 17732 | |
| 17733 | genlmsg_end(msg, hdr); |
| 17734 | |
| 17735 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 17736 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17737 | return; |
| 17738 | out: |
| 17739 | nlmsg_free(msg); |
| 17740 | } |
| 17741 | |
| 17742 | int cfg80211_external_auth_request(struct net_device *dev, |
| 17743 | struct cfg80211_external_auth_params *params, |
| 17744 | gfp_t gfp) |
| 17745 | { |
| 17746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17747 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17748 | struct sk_buff *msg; |
| 17749 | void *hdr; |
| 17750 | |
| 17751 | if (!wdev->conn_owner_nlportid) |
| 17752 | return -EINVAL; |
| 17753 | |
| 17754 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17755 | if (!msg) |
| 17756 | return -ENOMEM; |
| 17757 | |
| 17758 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 17759 | if (!hdr) |
| 17760 | goto nla_put_failure; |
| 17761 | |
| 17762 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17763 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17764 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 17765 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 17766 | params->action) || |
| 17767 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 17768 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 17769 | params->ssid.ssid)) |
| 17770 | goto nla_put_failure; |
| 17771 | |
| 17772 | genlmsg_end(msg, hdr); |
| 17773 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 17774 | wdev->conn_owner_nlportid); |
| 17775 | return 0; |
| 17776 | |
| 17777 | nla_put_failure: |
| 17778 | nlmsg_free(msg); |
| 17779 | return -ENOBUFS; |
| 17780 | } |
| 17781 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 17782 | |
| David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 17783 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 17784 | struct cfg80211_update_owe_info *owe_info, |
| 17785 | gfp_t gfp) |
| 17786 | { |
| 17787 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17788 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17789 | struct sk_buff *msg; |
| 17790 | void *hdr; |
| 17791 | |
| 17792 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 17793 | |
| 17794 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17795 | if (!msg) |
| 17796 | return; |
| 17797 | |
| 17798 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 17799 | if (!hdr) |
| 17800 | goto nla_put_failure; |
| 17801 | |
| 17802 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17803 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17804 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 17805 | goto nla_put_failure; |
| 17806 | |
| 17807 | if (!owe_info->ie_len || |
| 17808 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 17809 | goto nla_put_failure; |
| 17810 | |
| 17811 | genlmsg_end(msg, hdr); |
| 17812 | |
| 17813 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17814 | NL80211_MCGRP_MLME, gfp); |
| 17815 | return; |
| 17816 | |
| 17817 | nla_put_failure: |
| 17818 | genlmsg_cancel(msg, hdr); |
| 17819 | nlmsg_free(msg); |
| 17820 | } |
| 17821 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 17822 | |
| Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17823 | /* initialisation/exit functions */ |
| 17824 | |
| 17825 | int __init nl80211_init(void) |
| 17826 | { |
| 17827 | int err; |
| 17828 | |
| 17829 | err = genl_register_family(&nl80211_fam); |
| 17830 | if (err) |
| 17831 | return err; |
| 17832 | |
| 17833 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 17834 | if (err) |
| 17835 | goto err_out; |
| 17836 | |
| 17837 | return 0; |
| 17838 | err_out: |
| 17839 | genl_unregister_family(&nl80211_fam); |
| 17840 | return err; |
| 17841 | } |
| 17842 | |
| 17843 | void nl80211_exit(void) |
| 17844 | { |
| 17845 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
| 17846 | genl_unregister_family(&nl80211_fam); |
| 17847 | } |