1 // SPDX-License-Identifier: GPL-2.0-only 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 8 * Copyright (C) 2018-2023 Intel Corporation 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> 23 #include <linux/if_vlan.h> 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 cfg80211_registered_device *rdev, 68 struct net *netns, struct nlattr **attrs) 69 { 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 = 0; 74 int wiphy_idx = -1; 75 int ifidx = -1; 76 77 if (!have_ifidx && !have_wdev_id) 78 return ERR_PTR(-EINVAL); 79 80 if (have_ifidx) 81 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 82 if (have_wdev_id) { 83 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 84 wiphy_idx = wdev_id >> 32; 85 } 86 87 if (rdev) { 88 struct wireless_dev *wdev; 89 90 lockdep_assert_held(&rdev->wiphy.mtx); 91 92 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 93 if (have_ifidx && wdev->netdev && 94 wdev->netdev->ifindex == ifidx) { 95 result = wdev; 96 break; 97 } 98 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 99 result = wdev; 100 break; 101 } 102 } 103 104 return result ?: ERR_PTR(-ENODEV); 105 } 106 107 ASSERT_RTNL(); 108 109 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 110 struct wireless_dev *wdev; 111 112 if (wiphy_net(&rdev->wiphy) != netns) 113 continue; 114 115 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) 116 continue; 117 118 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 119 if (have_ifidx && wdev->netdev && 120 wdev->netdev->ifindex == ifidx) { 121 result = wdev; 122 break; 123 } 124 if (have_wdev_id && wdev->identifier == (u32)wdev_id) { 125 result = wdev; 126 break; 127 } 128 } 129 130 if (result) 131 break; 132 } 133 134 if (result) 135 return result; 136 return ERR_PTR(-ENODEV); 137 } 138 139 static struct cfg80211_registered_device * 140 __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) 141 { 142 struct cfg80211_registered_device *rdev = NULL, *tmp; 143 struct net_device *netdev; 144 145 ASSERT_RTNL(); 146 147 if (!attrs[NL80211_ATTR_WIPHY] && 148 !attrs[NL80211_ATTR_IFINDEX] && 149 !attrs[NL80211_ATTR_WDEV]) 150 return ERR_PTR(-EINVAL); 151 152 if (attrs[NL80211_ATTR_WIPHY]) 153 rdev = cfg80211_rdev_by_wiphy_idx( 154 nla_get_u32(attrs[NL80211_ATTR_WIPHY])); 155 156 if (attrs[NL80211_ATTR_WDEV]) { 157 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); 158 struct wireless_dev *wdev; 159 bool found = false; 160 161 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); 162 if (tmp) { 163 /* make sure wdev exists */ 164 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { 165 if (wdev->identifier != (u32)wdev_id) 166 continue; 167 found = true; 168 break; 169 } 170 171 if (!found) 172 tmp = NULL; 173 174 if (rdev && tmp != rdev) 175 return ERR_PTR(-EINVAL); 176 rdev = tmp; 177 } 178 } 179 180 if (attrs[NL80211_ATTR_IFINDEX]) { 181 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); 182 183 netdev = __dev_get_by_index(netns, ifindex); 184 if (netdev) { 185 if (netdev->ieee80211_ptr) 186 tmp = wiphy_to_rdev( 187 netdev->ieee80211_ptr->wiphy); 188 else 189 tmp = NULL; 190 191 /* not wireless device -- return error */ 192 if (!tmp) 193 return ERR_PTR(-EINVAL); 194 195 /* mismatch -- return error */ 196 if (rdev && tmp != rdev) 197 return ERR_PTR(-EINVAL); 198 199 rdev = tmp; 200 } 201 } 202 203 if (!rdev) 204 return ERR_PTR(-ENODEV); 205 206 if (netns != wiphy_net(&rdev->wiphy)) 207 return ERR_PTR(-ENODEV); 208 209 return rdev; 210 } 211 212 /* 213 * This function returns a pointer to the driver 214 * that the genl_info item that is passed refers to. 215 * 216 * The result of this can be a PTR_ERR and hence must 217 * be checked with IS_ERR() for errors. 218 */ 219 static struct cfg80211_registered_device * 220 cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) 221 { 222 return __cfg80211_rdev_from_attrs(netns, info->attrs); 223 } 224 225 static int validate_beacon_head(const struct nlattr *attr, 226 struct netlink_ext_ack *extack) 227 { 228 const u8 *data = nla_data(attr); 229 unsigned int len = nla_len(attr); 230 const struct element *elem; 231 const struct ieee80211_mgmt *mgmt = (void *)data; 232 unsigned int fixedlen, hdrlen; 233 bool s1g_bcn; 234 235 if (len < offsetofend(typeof(*mgmt), frame_control)) 236 goto err; 237 238 s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); 239 if (s1g_bcn) { 240 fixedlen = offsetof(struct ieee80211_ext, 241 u.s1g_beacon.variable); 242 hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); 243 } else { 244 fixedlen = offsetof(struct ieee80211_mgmt, 245 u.beacon.variable); 246 hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); 247 } 248 249 if (len < fixedlen) 250 goto err; 251 252 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) 253 goto err; 254 255 data += fixedlen; 256 len -= fixedlen; 257 258 for_each_element(elem, data, len) { 259 /* nothing */ 260 } 261 262 if (for_each_element_completed(elem, data, len)) 263 return 0; 264 265 err: 266 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); 267 return -EINVAL; 268 } 269 270 static int validate_ie_attr(const struct nlattr *attr, 271 struct netlink_ext_ack *extack) 272 { 273 const u8 *data = nla_data(attr); 274 unsigned int len = nla_len(attr); 275 const struct element *elem; 276 277 for_each_element(elem, data, len) { 278 /* nothing */ 279 } 280 281 if (for_each_element_completed(elem, data, len)) 282 return 0; 283 284 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); 285 return -EINVAL; 286 } 287 288 static int validate_he_capa(const struct nlattr *attr, 289 struct netlink_ext_ack *extack) 290 { 291 if (!ieee80211_he_capa_size_ok(nla_data(attr), nla_len(attr))) 292 return -EINVAL; 293 294 return 0; 295 } 296 297 /* policy for the attributes */ 298 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; 299 300 static const struct nla_policy 301 nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { 302 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, 303 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, 304 .len = U8_MAX }, 305 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, 306 .len = U8_MAX }, 307 }; 308 309 static const struct nla_policy 310 nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { 311 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, 312 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, 313 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = 314 NLA_POLICY_MAX(NLA_U8, 15), 315 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, 316 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = 317 NLA_POLICY_MAX(NLA_U8, 15), 318 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = 319 NLA_POLICY_MAX(NLA_U8, 31), 320 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, 321 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, 322 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, 323 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, 324 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, 325 [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG }, 326 [NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR] = { .type = NLA_U8 }, 327 }; 328 329 static const struct nla_policy 330 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { 331 [NL80211_PMSR_TYPE_FTM] = 332 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), 333 }; 334 335 static const struct nla_policy 336 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { 337 [NL80211_PMSR_REQ_ATTR_DATA] = 338 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), 339 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, 340 }; 341 342 static const struct nla_policy 343 nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { 344 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, 345 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), 346 [NL80211_PMSR_PEER_ATTR_REQ] = 347 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), 348 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, 349 }; 350 351 static const struct nla_policy 352 nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { 353 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, 354 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, 355 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, 356 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, 357 [NL80211_PMSR_ATTR_PEERS] = 358 NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy), 359 }; 360 361 static const struct nla_policy 362 he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { 363 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = 364 NLA_POLICY_RANGE(NLA_U8, 1, 20), 365 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = 366 NLA_POLICY_RANGE(NLA_U8, 1, 20), 367 [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = 368 NLA_POLICY_RANGE(NLA_U8, 1, 20), 369 [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = 370 NLA_POLICY_EXACT_LEN(8), 371 [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = 372 NLA_POLICY_EXACT_LEN(8), 373 [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, 374 }; 375 376 static const struct nla_policy 377 he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { 378 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), 379 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, 380 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, 381 }; 382 383 static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { 384 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, 385 .len = NL80211_MAX_SUPP_RATES }, 386 [NL80211_TXRATE_HT] = { .type = NLA_BINARY, 387 .len = NL80211_MAX_SUPP_HT_RATES }, 388 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), 389 [NL80211_TXRATE_GI] = { .type = NLA_U8 }, 390 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), 391 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, 392 NL80211_RATE_INFO_HE_GI_0_8, 393 NL80211_RATE_INFO_HE_GI_3_2), 394 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, 395 NL80211_RATE_INFO_HE_1XLTF, 396 NL80211_RATE_INFO_HE_4XLTF), 397 }; 398 399 static const struct nla_policy 400 nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { 401 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, 402 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, 403 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, 404 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), 405 [NL80211_TID_CONFIG_ATTR_NOACK] = 406 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 407 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 408 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 409 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = 410 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 411 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = 412 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 413 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = 414 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), 415 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = 416 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), 417 [NL80211_TID_CONFIG_ATTR_TX_RATE] = 418 NLA_POLICY_NESTED(nl80211_txattr_policy), 419 }; 420 421 static const struct nla_policy 422 nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { 423 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), 424 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), 425 [NL80211_FILS_DISCOVERY_ATTR_TMPL] = 426 NLA_POLICY_RANGE(NLA_BINARY, 427 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, 428 IEEE80211_MAX_DATA_LEN), 429 }; 430 431 static const struct nla_policy 432 nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { 433 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), 434 [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, 435 .len = IEEE80211_MAX_DATA_LEN } 436 }; 437 438 static const struct nla_policy 439 sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = { 440 [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 }, 441 [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 }, 442 }; 443 444 static const struct nla_policy 445 sar_policy[NL80211_SAR_ATTR_MAX + 1] = { 446 [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE), 447 [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy), 448 }; 449 450 static const struct nla_policy 451 nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = { 452 [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2), 453 [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] = 454 NLA_POLICY_MIN(NLA_U8, 1), 455 [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 }, 456 [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 }, 457 [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG }, 458 }; 459 460 static const struct nla_policy 461 nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { 462 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, 463 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, 464 }; 465 466 static struct netlink_range_validation nl80211_punct_bitmap_range = { 467 .min = 0, 468 .max = 0xffff, 469 }; 470 471 static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { 472 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, 473 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 474 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, 475 .len = 20-1 }, 476 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 477 478 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 479 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 480 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, 481 NL80211_EDMG_CHANNELS_MIN, 482 NL80211_EDMG_CHANNELS_MAX), 483 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, 484 NL80211_EDMG_BW_CONFIG_MIN, 485 NL80211_EDMG_BW_CONFIG_MAX), 486 487 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, 488 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, 489 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 490 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, 491 492 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), 493 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), 494 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, 495 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, 496 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, 497 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, 498 499 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), 500 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 501 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, 502 503 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 504 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 505 506 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, 507 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, 508 .len = WLAN_MAX_KEY_LEN }, 509 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), 510 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, 511 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, 512 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 513 [NL80211_ATTR_KEY_TYPE] = 514 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), 515 516 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, 517 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, 518 [NL80211_ATTR_BEACON_HEAD] = 519 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, 520 IEEE80211_MAX_DATA_LEN), 521 [NL80211_ATTR_BEACON_TAIL] = 522 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 523 IEEE80211_MAX_DATA_LEN), 524 [NL80211_ATTR_STA_AID] = 525 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 526 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, 527 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, 528 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, 529 .len = NL80211_MAX_SUPP_RATES }, 530 [NL80211_ATTR_STA_PLINK_ACTION] = 531 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), 532 [NL80211_ATTR_STA_TX_POWER_SETTING] = 533 NLA_POLICY_RANGE(NLA_U8, 534 NL80211_TX_POWER_AUTOMATIC, 535 NL80211_TX_POWER_FIXED), 536 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, 537 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, 538 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, 539 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, 540 .len = IEEE80211_MAX_MESH_ID_LEN }, 541 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, 542 543 /* allow 3 for NUL-termination, we used to declare this NLA_STRING */ 544 [NL80211_ATTR_REG_ALPHA2] = NLA_POLICY_RANGE(NLA_BINARY, 2, 3), 545 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, 546 547 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 548 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 549 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 550 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 551 .len = NL80211_MAX_SUPP_RATES }, 552 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, 553 554 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, 555 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, 556 557 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), 558 559 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, 560 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, 561 validate_ie_attr, 562 IEEE80211_MAX_DATA_LEN), 563 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, 564 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, 565 566 [NL80211_ATTR_SSID] = { .type = NLA_BINARY, 567 .len = IEEE80211_MAX_SSID_LEN }, 568 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 569 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 570 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, 571 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, 572 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, 573 NL80211_MFP_NO, 574 NL80211_MFP_OPTIONAL), 575 [NL80211_ATTR_STA_FLAGS2] = 576 NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_sta_flag_update)), 577 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, 578 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, 579 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, 580 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, 581 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, 582 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, 583 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, 584 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, 585 [NL80211_ATTR_PID] = { .type = NLA_U32 }, 586 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, 587 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), 588 [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, 589 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, 590 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, 591 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, 592 .len = IEEE80211_MAX_DATA_LEN }, 593 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, 594 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, 595 NL80211_PS_DISABLED, 596 NL80211_PS_ENABLED), 597 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, 598 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, 599 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, 600 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, 601 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, 602 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, 603 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, 604 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, 605 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, 606 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, 607 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 608 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, 609 [NL80211_ATTR_STA_PLINK_STATE] = 610 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), 611 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, 612 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, 613 [NL80211_ATTR_MESH_PEER_AID] = 614 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 615 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, 616 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, 617 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, 618 [NL80211_ATTR_HIDDEN_SSID] = 619 NLA_POLICY_RANGE(NLA_U32, 620 NL80211_HIDDEN_SSID_NOT_IN_USE, 621 NL80211_HIDDEN_SSID_ZERO_CONTENTS), 622 [NL80211_ATTR_IE_PROBE_RESP] = 623 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 624 IEEE80211_MAX_DATA_LEN), 625 [NL80211_ATTR_IE_ASSOC_RESP] = 626 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 627 IEEE80211_MAX_DATA_LEN), 628 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, 629 [NL80211_ATTR_STA_WME] = NLA_POLICY_NESTED(nl80211_sta_wme_policy), 630 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, 631 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, 632 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, 633 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, 634 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, 635 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, 636 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, 637 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, 638 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, 639 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, 640 .len = IEEE80211_MAX_DATA_LEN }, 641 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, 642 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, 643 [NL80211_ATTR_HT_CAPABILITY_MASK] = { 644 .len = NL80211_HT_CAPABILITY_LEN 645 }, 646 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, 647 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, 648 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, 649 [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, 650 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, 651 652 /* need to include at least Auth Transaction and Status Code */ 653 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), 654 655 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), 656 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, 657 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), 658 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), 659 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = 660 NLA_POLICY_RANGE(NLA_U32, 661 NL80211_MESH_POWER_UNKNOWN + 1, 662 NL80211_MESH_POWER_MAX), 663 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, 664 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, 665 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, 666 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, 667 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, 668 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, 669 [NL80211_ATTR_VHT_CAPABILITY_MASK] = { 670 .len = NL80211_VHT_CAPABILITY_LEN, 671 }, 672 [NL80211_ATTR_MDID] = { .type = NLA_U16 }, 673 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, 674 .len = IEEE80211_MAX_DATA_LEN }, 675 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, 676 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = 677 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), 678 [NL80211_ATTR_PEER_AID] = 679 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), 680 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, 681 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, 682 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, 683 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, 684 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, 685 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), 686 /* 687 * The value of the Length field of the Supported Operating 688 * Classes element is between 2 and 253. 689 */ 690 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = 691 NLA_POLICY_RANGE(NLA_BINARY, 2, 253), 692 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, 693 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, 694 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, 695 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, 696 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, 697 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, 698 IEEE80211_QOS_MAP_LEN_MIN, 699 IEEE80211_QOS_MAP_LEN_MAX), 700 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 701 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, 702 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, 703 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, 704 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, 705 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, 706 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), 707 [NL80211_ATTR_USER_PRIO] = 708 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), 709 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, 710 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, 711 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, 712 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 713 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, 714 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, 715 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, 716 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, 717 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, 718 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, 719 [NL80211_ATTR_STA_SUPPORT_P2P_PS] = 720 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), 721 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { 722 .len = VHT_MUMIMO_GROUPS_DATA_LEN 723 }, 724 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 725 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), 726 [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, 727 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, 728 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, 729 .len = FILS_MAX_KEK_LEN }, 730 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), 731 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, 732 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 733 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, 734 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { 735 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 736 }, 737 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, 738 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, 739 .len = FILS_ERP_MAX_USERNAME_LEN }, 740 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, 741 .len = FILS_ERP_MAX_REALM_LEN }, 742 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, 743 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, 744 .len = FILS_ERP_MAX_RRK_LEN }, 745 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), 746 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, 747 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), 748 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, 749 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, 750 751 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, 752 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, 753 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, 754 [NL80211_ATTR_HE_CAPABILITY] = 755 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_he_capa, 756 NL80211_HE_MAX_CAPABILITY_LEN), 757 [NL80211_ATTR_FTM_RESPONDER] = 758 NLA_POLICY_NESTED(nl80211_ftm_responder_policy), 759 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), 760 [NL80211_ATTR_PEER_MEASUREMENTS] = 761 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), 762 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), 763 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, 764 .len = SAE_PASSWORD_MAX_LEN }, 765 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, 766 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), 767 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), 768 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), 769 [NL80211_ATTR_TID_CONFIG] = 770 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), 771 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, 772 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), 773 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), 774 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, 775 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), 776 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, 777 [NL80211_ATTR_HE_6GHZ_CAPABILITY] = 778 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), 779 [NL80211_ATTR_FILS_DISCOVERY] = 780 NLA_POLICY_NESTED(nl80211_fils_discovery_policy), 781 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = 782 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), 783 [NL80211_ATTR_S1G_CAPABILITY] = 784 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 785 [NL80211_ATTR_S1G_CAPABILITY_MASK] = 786 NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), 787 [NL80211_ATTR_SAE_PWE] = 788 NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK, 789 NL80211_SAE_PWE_BOTH), 790 [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT }, 791 [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy), 792 [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG }, 793 [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 }, 794 [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 }, 795 [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 }, 796 [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy), 797 [NL80211_ATTR_MBSSID_CONFIG] = 798 NLA_POLICY_NESTED(nl80211_mbssid_config_policy), 799 [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED }, 800 [NL80211_ATTR_RADAR_BACKGROUND] = { .type = NLA_FLAG }, 801 [NL80211_ATTR_AP_SETTINGS_FLAGS] = { .type = NLA_U32 }, 802 [NL80211_ATTR_EHT_CAPABILITY] = 803 NLA_POLICY_RANGE(NLA_BINARY, 804 NL80211_EHT_MIN_CAPABILITY_LEN, 805 NL80211_EHT_MAX_CAPABILITY_LEN), 806 [NL80211_ATTR_DISABLE_EHT] = { .type = NLA_FLAG }, 807 [NL80211_ATTR_MLO_LINKS] = 808 NLA_POLICY_NESTED_ARRAY(nl80211_policy), 809 [NL80211_ATTR_MLO_LINK_ID] = 810 NLA_POLICY_RANGE(NLA_U8, 0, IEEE80211_MLD_MAX_NUM_LINKS), 811 [NL80211_ATTR_MLD_ADDR] = NLA_POLICY_EXACT_LEN(ETH_ALEN), 812 [NL80211_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG }, 813 [NL80211_ATTR_MAX_NUM_AKM_SUITES] = { .type = NLA_REJECT }, 814 [NL80211_ATTR_PUNCT_BITMAP] = 815 NLA_POLICY_FULL_RANGE(NLA_U32, &nl80211_punct_bitmap_range), 816 817 [NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS] = { .type = NLA_U16 }, 818 [NL80211_ATTR_HW_TIMESTAMP_ENABLED] = { .type = NLA_FLAG }, 819 [NL80211_ATTR_EMA_RNR_ELEMS] = { .type = NLA_NESTED }, 820 [NL80211_ATTR_MLO_LINK_DISABLED] = { .type = NLA_FLAG }, 821 }; 822 823 /* policy for the key attributes */ 824 static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { 825 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, 826 [NL80211_KEY_IDX] = { .type = NLA_U8 }, 827 [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, 828 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, 829 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, 830 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, 831 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), 832 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, 833 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), 834 }; 835 836 /* policy for the key default flags */ 837 static const struct nla_policy 838 nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { 839 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, 840 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, 841 }; 842 843 #ifdef CONFIG_PM 844 /* policy for WoWLAN attributes */ 845 static const struct nla_policy 846 nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { 847 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, 848 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, 849 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, 850 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, 851 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, 852 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, 853 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, 854 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, 855 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, 856 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, 857 }; 858 859 static const struct nla_policy 860 nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { 861 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, 862 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, 863 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 864 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, 865 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, 866 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 867 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { 868 .len = sizeof(struct nl80211_wowlan_tcp_data_seq) 869 }, 870 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { 871 .len = sizeof(struct nl80211_wowlan_tcp_data_token) 872 }, 873 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, 874 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), 875 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), 876 }; 877 #endif /* CONFIG_PM */ 878 879 /* policy for coalesce rule attributes */ 880 static const struct nla_policy 881 nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { 882 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, 883 [NL80211_ATTR_COALESCE_RULE_CONDITION] = 884 NLA_POLICY_RANGE(NLA_U32, 885 NL80211_COALESCE_CONDITION_MATCH, 886 NL80211_COALESCE_CONDITION_NO_MATCH), 887 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, 888 }; 889 890 /* policy for GTK rekey offload attributes */ 891 static const struct nla_policy 892 nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { 893 [NL80211_REKEY_DATA_KEK] = { 894 .type = NLA_BINARY, 895 .len = NL80211_KEK_EXT_LEN 896 }, 897 [NL80211_REKEY_DATA_KCK] = { 898 .type = NLA_BINARY, 899 .len = NL80211_KCK_EXT_LEN_32 900 }, 901 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), 902 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, 903 }; 904 905 static const struct nla_policy 906 nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { 907 [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, 908 [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, 909 [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, 910 [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, 911 [NL80211_BAND_LC] = { .type = NLA_S32 }, 912 }; 913 914 static const struct nla_policy 915 nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { 916 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, 917 .len = IEEE80211_MAX_SSID_LEN }, 918 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 919 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, 920 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = 921 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), 922 }; 923 924 static const struct nla_policy 925 nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { 926 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, 927 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, 928 }; 929 930 static const struct nla_policy 931 nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { 932 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, 933 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, 934 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { 935 .len = sizeof(struct nl80211_bss_select_rssi_adjust) 936 }, 937 }; 938 939 /* policy for NAN function attributes */ 940 static const struct nla_policy 941 nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { 942 [NL80211_NAN_FUNC_TYPE] = 943 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), 944 [NL80211_NAN_FUNC_SERVICE_ID] = { 945 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, 946 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, 947 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, 948 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, 949 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, 950 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, 951 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), 952 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, 953 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, 954 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, 955 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, 956 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, 957 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, 958 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, 959 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, 960 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, 961 }; 962 963 /* policy for Service Response Filter attributes */ 964 static const struct nla_policy 965 nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { 966 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, 967 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, 968 .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, 969 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, 970 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, 971 }; 972 973 /* policy for packet pattern attributes */ 974 static const struct nla_policy 975 nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { 976 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, 977 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, 978 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, 979 }; 980 981 static int nl80211_prepare_wdev_dump(struct netlink_callback *cb, 982 struct cfg80211_registered_device **rdev, 983 struct wireless_dev **wdev, 984 struct nlattr **attrbuf) 985 { 986 int err; 987 988 if (!cb->args[0]) { 989 struct nlattr **attrbuf_free = NULL; 990 991 if (!attrbuf) { 992 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 993 GFP_KERNEL); 994 if (!attrbuf) 995 return -ENOMEM; 996 attrbuf_free = attrbuf; 997 } 998 999 err = nlmsg_parse_deprecated(cb->nlh, 1000 GENL_HDRLEN + nl80211_fam.hdrsize, 1001 attrbuf, nl80211_fam.maxattr, 1002 nl80211_policy, NULL); 1003 if (err) { 1004 kfree(attrbuf_free); 1005 return err; 1006 } 1007 1008 rtnl_lock(); 1009 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), 1010 attrbuf); 1011 kfree(attrbuf_free); 1012 if (IS_ERR(*wdev)) { 1013 rtnl_unlock(); 1014 return PTR_ERR(*wdev); 1015 } 1016 *rdev = wiphy_to_rdev((*wdev)->wiphy); 1017 mutex_lock(&(*rdev)->wiphy.mtx); 1018 rtnl_unlock(); 1019 /* 0 is the first index - add 1 to parse only once */ 1020 cb->args[0] = (*rdev)->wiphy_idx + 1; 1021 cb->args[1] = (*wdev)->identifier; 1022 } else { 1023 /* subtract the 1 again here */ 1024 struct wiphy *wiphy; 1025 struct wireless_dev *tmp; 1026 1027 rtnl_lock(); 1028 wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 1029 if (!wiphy) { 1030 rtnl_unlock(); 1031 return -ENODEV; 1032 } 1033 *rdev = wiphy_to_rdev(wiphy); 1034 *wdev = NULL; 1035 1036 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { 1037 if (tmp->identifier == cb->args[1]) { 1038 *wdev = tmp; 1039 break; 1040 } 1041 } 1042 1043 if (!*wdev) { 1044 rtnl_unlock(); 1045 return -ENODEV; 1046 } 1047 mutex_lock(&(*rdev)->wiphy.mtx); 1048 rtnl_unlock(); 1049 } 1050 1051 return 0; 1052 } 1053 1054 /* message building helper */ 1055 void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, 1056 int flags, u8 cmd) 1057 { 1058 /* since there is no private header just add the generic one */ 1059 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); 1060 } 1061 1062 static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, 1063 const struct ieee80211_reg_rule *rule) 1064 { 1065 int j; 1066 struct nlattr *nl_wmm_rules = 1067 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); 1068 1069 if (!nl_wmm_rules) 1070 goto nla_put_failure; 1071 1072 for (j = 0; j < IEEE80211_NUM_ACS; j++) { 1073 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); 1074 1075 if (!nl_wmm_rule) 1076 goto nla_put_failure; 1077 1078 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, 1079 rule->wmm_rule.client[j].cw_min) || 1080 nla_put_u16(msg, NL80211_WMMR_CW_MAX, 1081 rule->wmm_rule.client[j].cw_max) || 1082 nla_put_u8(msg, NL80211_WMMR_AIFSN, 1083 rule->wmm_rule.client[j].aifsn) || 1084 nla_put_u16(msg, NL80211_WMMR_TXOP, 1085 rule->wmm_rule.client[j].cot)) 1086 goto nla_put_failure; 1087 1088 nla_nest_end(msg, nl_wmm_rule); 1089 } 1090 nla_nest_end(msg, nl_wmm_rules); 1091 1092 return 0; 1093 1094 nla_put_failure: 1095 return -ENOBUFS; 1096 } 1097 1098 static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, 1099 struct ieee80211_channel *chan, 1100 bool large) 1101 { 1102 /* Some channels must be completely excluded from the 1103 * list to protect old user-space tools from breaking 1104 */ 1105 if (!large && chan->flags & 1106 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) 1107 return 0; 1108 if (!large && chan->freq_offset) 1109 return 0; 1110 1111 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, 1112 chan->center_freq)) 1113 goto nla_put_failure; 1114 1115 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) 1116 goto nla_put_failure; 1117 1118 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 1119 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 1120 goto nla_put_failure; 1121 if (chan->flags & IEEE80211_CHAN_NO_IR) { 1122 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 1123 goto nla_put_failure; 1124 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 1125 goto nla_put_failure; 1126 } 1127 if (chan->flags & IEEE80211_CHAN_RADAR) { 1128 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 1129 goto nla_put_failure; 1130 if (large) { 1131 u32 time; 1132 1133 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 1134 1135 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 1136 chan->dfs_state)) 1137 goto nla_put_failure; 1138 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 1139 time)) 1140 goto nla_put_failure; 1141 if (nla_put_u32(msg, 1142 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 1143 chan->dfs_cac_ms)) 1144 goto nla_put_failure; 1145 } 1146 } 1147 1148 if (large) { 1149 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 1150 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 1151 goto nla_put_failure; 1152 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 1153 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 1154 goto nla_put_failure; 1155 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 1156 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 1157 goto nla_put_failure; 1158 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 1159 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 1160 goto nla_put_failure; 1161 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 1162 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 1163 goto nla_put_failure; 1164 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 1165 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 1166 goto nla_put_failure; 1167 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 1168 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 1169 goto nla_put_failure; 1170 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 1171 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 1172 goto nla_put_failure; 1173 if ((chan->flags & IEEE80211_CHAN_NO_HE) && 1174 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) 1175 goto nla_put_failure; 1176 if ((chan->flags & IEEE80211_CHAN_1MHZ) && 1177 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) 1178 goto nla_put_failure; 1179 if ((chan->flags & IEEE80211_CHAN_2MHZ) && 1180 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) 1181 goto nla_put_failure; 1182 if ((chan->flags & IEEE80211_CHAN_4MHZ) && 1183 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) 1184 goto nla_put_failure; 1185 if ((chan->flags & IEEE80211_CHAN_8MHZ) && 1186 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) 1187 goto nla_put_failure; 1188 if ((chan->flags & IEEE80211_CHAN_16MHZ) && 1189 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) 1190 goto nla_put_failure; 1191 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) && 1192 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ)) 1193 goto nla_put_failure; 1194 if ((chan->flags & IEEE80211_CHAN_NO_EHT) && 1195 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT)) 1196 goto nla_put_failure; 1197 } 1198 1199 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 1200 DBM_TO_MBM(chan->max_power))) 1201 goto nla_put_failure; 1202 1203 if (large) { 1204 const struct ieee80211_reg_rule *rule = 1205 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 1206 1207 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 1208 if (nl80211_msg_put_wmm_rules(msg, rule)) 1209 goto nla_put_failure; 1210 } 1211 } 1212 1213 return 0; 1214 1215 nla_put_failure: 1216 return -ENOBUFS; 1217 } 1218 1219 static bool nl80211_put_txq_stats(struct sk_buff *msg, 1220 struct cfg80211_txq_stats *txqstats, 1221 int attrtype) 1222 { 1223 struct nlattr *txqattr; 1224 1225 #define PUT_TXQVAL_U32(attr, memb) do { \ 1226 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 1227 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 1228 return false; \ 1229 } while (0) 1230 1231 txqattr = nla_nest_start_noflag(msg, attrtype); 1232 if (!txqattr) 1233 return false; 1234 1235 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 1236 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 1237 PUT_TXQVAL_U32(FLOWS, flows); 1238 PUT_TXQVAL_U32(DROPS, drops); 1239 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 1240 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 1241 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 1242 PUT_TXQVAL_U32(COLLISIONS, collisions); 1243 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 1244 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 1245 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 1246 nla_nest_end(msg, txqattr); 1247 1248 #undef PUT_TXQVAL_U32 1249 return true; 1250 } 1251 1252 /* netlink command implementations */ 1253 1254 /** 1255 * nl80211_link_id - return link ID 1256 * @attrs: attributes to look at 1257 * 1258 * Returns: the link ID or 0 if not given 1259 * 1260 * Note this function doesn't do any validation of the link 1261 * ID validity wrt. links that were actually added, so it must 1262 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID 1263 * or if additional validation is done. 1264 */ 1265 static unsigned int nl80211_link_id(struct nlattr **attrs) 1266 { 1267 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1268 1269 if (!linkid) 1270 return 0; 1271 1272 return nla_get_u8(linkid); 1273 } 1274 1275 static int nl80211_link_id_or_invalid(struct nlattr **attrs) 1276 { 1277 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1278 1279 if (!linkid) 1280 return -1; 1281 1282 return nla_get_u8(linkid); 1283 } 1284 1285 struct key_parse { 1286 struct key_params p; 1287 int idx; 1288 int type; 1289 bool def, defmgmt, defbeacon; 1290 bool def_uni, def_multi; 1291 }; 1292 1293 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 1294 struct key_parse *k) 1295 { 1296 struct nlattr *tb[NL80211_KEY_MAX + 1]; 1297 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 1298 nl80211_key_policy, 1299 info->extack); 1300 if (err) 1301 return err; 1302 1303 k->def = !!tb[NL80211_KEY_DEFAULT]; 1304 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 1305 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; 1306 1307 if (k->def) { 1308 k->def_uni = true; 1309 k->def_multi = true; 1310 } 1311 if (k->defmgmt || k->defbeacon) 1312 k->def_multi = true; 1313 1314 if (tb[NL80211_KEY_IDX]) 1315 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 1316 1317 if (tb[NL80211_KEY_DATA]) { 1318 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 1319 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 1320 } 1321 1322 if (tb[NL80211_KEY_SEQ]) { 1323 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1324 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1325 } 1326 1327 if (tb[NL80211_KEY_CIPHER]) 1328 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1329 1330 if (tb[NL80211_KEY_TYPE]) 1331 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1332 1333 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1334 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1335 1336 err = nla_parse_nested_deprecated(kdt, 1337 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1338 tb[NL80211_KEY_DEFAULT_TYPES], 1339 nl80211_key_default_policy, 1340 info->extack); 1341 if (err) 1342 return err; 1343 1344 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1345 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1346 } 1347 1348 if (tb[NL80211_KEY_MODE]) 1349 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1350 1351 return 0; 1352 } 1353 1354 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1355 { 1356 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1357 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1358 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1359 } 1360 1361 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1362 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1363 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1364 } 1365 1366 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1367 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1368 1369 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1370 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1371 1372 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1373 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1374 1375 if (k->def) { 1376 k->def_uni = true; 1377 k->def_multi = true; 1378 } 1379 if (k->defmgmt) 1380 k->def_multi = true; 1381 1382 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1383 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1384 1385 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1386 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1387 int err = nla_parse_nested_deprecated(kdt, 1388 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1389 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1390 nl80211_key_default_policy, 1391 info->extack); 1392 if (err) 1393 return err; 1394 1395 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1396 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1397 } 1398 1399 return 0; 1400 } 1401 1402 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1403 { 1404 int err; 1405 1406 memset(k, 0, sizeof(*k)); 1407 k->idx = -1; 1408 k->type = -1; 1409 1410 if (info->attrs[NL80211_ATTR_KEY]) 1411 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1412 else 1413 err = nl80211_parse_key_old(info, k); 1414 1415 if (err) 1416 return err; 1417 1418 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + 1419 (k->defbeacon ? 1 : 0) > 1) { 1420 GENL_SET_ERR_MSG(info, 1421 "key with multiple default flags is invalid"); 1422 return -EINVAL; 1423 } 1424 1425 if (k->defmgmt || k->defbeacon) { 1426 if (k->def_uni || !k->def_multi) { 1427 GENL_SET_ERR_MSG(info, 1428 "defmgmt/defbeacon key must be mcast"); 1429 return -EINVAL; 1430 } 1431 } 1432 1433 if (k->idx != -1) { 1434 if (k->defmgmt) { 1435 if (k->idx < 4 || k->idx > 5) { 1436 GENL_SET_ERR_MSG(info, 1437 "defmgmt key idx not 4 or 5"); 1438 return -EINVAL; 1439 } 1440 } else if (k->defbeacon) { 1441 if (k->idx < 6 || k->idx > 7) { 1442 GENL_SET_ERR_MSG(info, 1443 "defbeacon key idx not 6 or 7"); 1444 return -EINVAL; 1445 } 1446 } else if (k->def) { 1447 if (k->idx < 0 || k->idx > 3) { 1448 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1449 return -EINVAL; 1450 } 1451 } else { 1452 if (k->idx < 0 || k->idx > 7) { 1453 GENL_SET_ERR_MSG(info, "key idx not 0-7"); 1454 return -EINVAL; 1455 } 1456 } 1457 } 1458 1459 return 0; 1460 } 1461 1462 static struct cfg80211_cached_keys * 1463 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1464 struct genl_info *info, bool *no_ht) 1465 { 1466 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1467 struct key_parse parse; 1468 struct nlattr *key; 1469 struct cfg80211_cached_keys *result; 1470 int rem, err, def = 0; 1471 bool have_key = false; 1472 1473 nla_for_each_nested(key, keys, rem) { 1474 have_key = true; 1475 break; 1476 } 1477 1478 if (!have_key) 1479 return NULL; 1480 1481 result = kzalloc(sizeof(*result), GFP_KERNEL); 1482 if (!result) 1483 return ERR_PTR(-ENOMEM); 1484 1485 result->def = -1; 1486 1487 nla_for_each_nested(key, keys, rem) { 1488 memset(&parse, 0, sizeof(parse)); 1489 parse.idx = -1; 1490 1491 err = nl80211_parse_key_new(info, key, &parse); 1492 if (err) 1493 goto error; 1494 err = -EINVAL; 1495 if (!parse.p.key) 1496 goto error; 1497 if (parse.idx < 0 || parse.idx > 3) { 1498 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1499 goto error; 1500 } 1501 if (parse.def) { 1502 if (def) { 1503 GENL_SET_ERR_MSG(info, 1504 "only one key can be default"); 1505 goto error; 1506 } 1507 def = 1; 1508 result->def = parse.idx; 1509 if (!parse.def_uni || !parse.def_multi) 1510 goto error; 1511 } else if (parse.defmgmt) 1512 goto error; 1513 err = cfg80211_validate_key_settings(rdev, &parse.p, 1514 parse.idx, false, NULL); 1515 if (err) 1516 goto error; 1517 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1518 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1519 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1520 err = -EINVAL; 1521 goto error; 1522 } 1523 result->params[parse.idx].cipher = parse.p.cipher; 1524 result->params[parse.idx].key_len = parse.p.key_len; 1525 result->params[parse.idx].key = result->data[parse.idx]; 1526 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1527 1528 /* must be WEP key if we got here */ 1529 if (no_ht) 1530 *no_ht = true; 1531 } 1532 1533 if (result->def < 0) { 1534 err = -EINVAL; 1535 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1536 goto error; 1537 } 1538 1539 return result; 1540 error: 1541 kfree(result); 1542 return ERR_PTR(err); 1543 } 1544 1545 static int nl80211_key_allowed(struct wireless_dev *wdev) 1546 { 1547 ASSERT_WDEV_LOCK(wdev); 1548 1549 switch (wdev->iftype) { 1550 case NL80211_IFTYPE_AP: 1551 case NL80211_IFTYPE_AP_VLAN: 1552 case NL80211_IFTYPE_P2P_GO: 1553 case NL80211_IFTYPE_MESH_POINT: 1554 break; 1555 case NL80211_IFTYPE_ADHOC: 1556 if (wdev->u.ibss.current_bss) 1557 return 0; 1558 return -ENOLINK; 1559 case NL80211_IFTYPE_STATION: 1560 case NL80211_IFTYPE_P2P_CLIENT: 1561 if (wdev->connected) 1562 return 0; 1563 return -ENOLINK; 1564 case NL80211_IFTYPE_NAN: 1565 if (wiphy_ext_feature_isset(wdev->wiphy, 1566 NL80211_EXT_FEATURE_SECURE_NAN)) 1567 return 0; 1568 return -EINVAL; 1569 case NL80211_IFTYPE_UNSPECIFIED: 1570 case NL80211_IFTYPE_OCB: 1571 case NL80211_IFTYPE_MONITOR: 1572 case NL80211_IFTYPE_P2P_DEVICE: 1573 case NL80211_IFTYPE_WDS: 1574 case NUM_NL80211_IFTYPES: 1575 return -EINVAL; 1576 } 1577 1578 return 0; 1579 } 1580 1581 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1582 u32 freq) 1583 { 1584 struct ieee80211_channel *chan; 1585 1586 chan = ieee80211_get_channel_khz(wiphy, freq); 1587 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1588 return NULL; 1589 return chan; 1590 } 1591 1592 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1593 { 1594 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1595 int i; 1596 1597 if (!nl_modes) 1598 goto nla_put_failure; 1599 1600 i = 0; 1601 while (ifmodes) { 1602 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1603 goto nla_put_failure; 1604 ifmodes >>= 1; 1605 i++; 1606 } 1607 1608 nla_nest_end(msg, nl_modes); 1609 return 0; 1610 1611 nla_put_failure: 1612 return -ENOBUFS; 1613 } 1614 1615 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1616 struct sk_buff *msg, 1617 bool large) 1618 { 1619 struct nlattr *nl_combis; 1620 int i, j; 1621 1622 nl_combis = nla_nest_start_noflag(msg, 1623 NL80211_ATTR_INTERFACE_COMBINATIONS); 1624 if (!nl_combis) 1625 goto nla_put_failure; 1626 1627 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1628 const struct ieee80211_iface_combination *c; 1629 struct nlattr *nl_combi, *nl_limits; 1630 1631 c = &wiphy->iface_combinations[i]; 1632 1633 nl_combi = nla_nest_start_noflag(msg, i + 1); 1634 if (!nl_combi) 1635 goto nla_put_failure; 1636 1637 nl_limits = nla_nest_start_noflag(msg, 1638 NL80211_IFACE_COMB_LIMITS); 1639 if (!nl_limits) 1640 goto nla_put_failure; 1641 1642 for (j = 0; j < c->n_limits; j++) { 1643 struct nlattr *nl_limit; 1644 1645 nl_limit = nla_nest_start_noflag(msg, j + 1); 1646 if (!nl_limit) 1647 goto nla_put_failure; 1648 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1649 c->limits[j].max)) 1650 goto nla_put_failure; 1651 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1652 c->limits[j].types)) 1653 goto nla_put_failure; 1654 nla_nest_end(msg, nl_limit); 1655 } 1656 1657 nla_nest_end(msg, nl_limits); 1658 1659 if (c->beacon_int_infra_match && 1660 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1661 goto nla_put_failure; 1662 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1663 c->num_different_channels) || 1664 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1665 c->max_interfaces)) 1666 goto nla_put_failure; 1667 if (large && 1668 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1669 c->radar_detect_widths) || 1670 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1671 c->radar_detect_regions))) 1672 goto nla_put_failure; 1673 if (c->beacon_int_min_gcd && 1674 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1675 c->beacon_int_min_gcd)) 1676 goto nla_put_failure; 1677 1678 nla_nest_end(msg, nl_combi); 1679 } 1680 1681 nla_nest_end(msg, nl_combis); 1682 1683 return 0; 1684 nla_put_failure: 1685 return -ENOBUFS; 1686 } 1687 1688 #ifdef CONFIG_PM 1689 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1690 struct sk_buff *msg) 1691 { 1692 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1693 struct nlattr *nl_tcp; 1694 1695 if (!tcp) 1696 return 0; 1697 1698 nl_tcp = nla_nest_start_noflag(msg, 1699 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1700 if (!nl_tcp) 1701 return -ENOBUFS; 1702 1703 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1704 tcp->data_payload_max)) 1705 return -ENOBUFS; 1706 1707 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1708 tcp->data_payload_max)) 1709 return -ENOBUFS; 1710 1711 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1712 return -ENOBUFS; 1713 1714 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1715 sizeof(*tcp->tok), tcp->tok)) 1716 return -ENOBUFS; 1717 1718 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1719 tcp->data_interval_max)) 1720 return -ENOBUFS; 1721 1722 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1723 tcp->wake_payload_max)) 1724 return -ENOBUFS; 1725 1726 nla_nest_end(msg, nl_tcp); 1727 return 0; 1728 } 1729 1730 static int nl80211_send_wowlan(struct sk_buff *msg, 1731 struct cfg80211_registered_device *rdev, 1732 bool large) 1733 { 1734 struct nlattr *nl_wowlan; 1735 1736 if (!rdev->wiphy.wowlan) 1737 return 0; 1738 1739 nl_wowlan = nla_nest_start_noflag(msg, 1740 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1741 if (!nl_wowlan) 1742 return -ENOBUFS; 1743 1744 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1745 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1746 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1747 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1748 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1750 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1751 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1752 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1753 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1754 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1755 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1756 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1757 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1758 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1759 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1760 return -ENOBUFS; 1761 1762 if (rdev->wiphy.wowlan->n_patterns) { 1763 struct nl80211_pattern_support pat = { 1764 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1765 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1766 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1767 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1768 }; 1769 1770 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1771 sizeof(pat), &pat)) 1772 return -ENOBUFS; 1773 } 1774 1775 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1776 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1777 rdev->wiphy.wowlan->max_nd_match_sets)) 1778 return -ENOBUFS; 1779 1780 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1781 return -ENOBUFS; 1782 1783 nla_nest_end(msg, nl_wowlan); 1784 1785 return 0; 1786 } 1787 #endif 1788 1789 static int nl80211_send_coalesce(struct sk_buff *msg, 1790 struct cfg80211_registered_device *rdev) 1791 { 1792 struct nl80211_coalesce_rule_support rule; 1793 1794 if (!rdev->wiphy.coalesce) 1795 return 0; 1796 1797 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1798 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1799 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1800 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1801 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1802 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1803 1804 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1805 return -ENOBUFS; 1806 1807 return 0; 1808 } 1809 1810 static int 1811 nl80211_send_iftype_data(struct sk_buff *msg, 1812 const struct ieee80211_supported_band *sband, 1813 const struct ieee80211_sband_iftype_data *iftdata) 1814 { 1815 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1816 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap; 1817 1818 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1819 iftdata->types_mask)) 1820 return -ENOBUFS; 1821 1822 if (he_cap->has_he) { 1823 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1824 sizeof(he_cap->he_cap_elem.mac_cap_info), 1825 he_cap->he_cap_elem.mac_cap_info) || 1826 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1827 sizeof(he_cap->he_cap_elem.phy_cap_info), 1828 he_cap->he_cap_elem.phy_cap_info) || 1829 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1830 sizeof(he_cap->he_mcs_nss_supp), 1831 &he_cap->he_mcs_nss_supp) || 1832 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1833 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1834 return -ENOBUFS; 1835 } 1836 1837 if (eht_cap->has_eht && he_cap->has_he) { 1838 u8 mcs_nss_size, ppe_thresh_size; 1839 u16 ppe_thres_hdr; 1840 bool is_ap; 1841 1842 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) || 1843 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO); 1844 1845 mcs_nss_size = 1846 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem, 1847 &eht_cap->eht_cap_elem, 1848 is_ap); 1849 1850 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]); 1851 ppe_thresh_size = 1852 ieee80211_eht_ppe_size(ppe_thres_hdr, 1853 eht_cap->eht_cap_elem.phy_cap_info); 1854 1855 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC, 1856 sizeof(eht_cap->eht_cap_elem.mac_cap_info), 1857 eht_cap->eht_cap_elem.mac_cap_info) || 1858 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY, 1859 sizeof(eht_cap->eht_cap_elem.phy_cap_info), 1860 eht_cap->eht_cap_elem.phy_cap_info) || 1861 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET, 1862 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) || 1863 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE, 1864 ppe_thresh_size, eht_cap->eht_ppe_thres)) 1865 return -ENOBUFS; 1866 } 1867 1868 if (sband->band == NL80211_BAND_6GHZ && 1869 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, 1870 sizeof(iftdata->he_6ghz_capa), 1871 &iftdata->he_6ghz_capa)) 1872 return -ENOBUFS; 1873 1874 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len && 1875 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, 1876 iftdata->vendor_elems.len, iftdata->vendor_elems.data)) 1877 return -ENOBUFS; 1878 1879 return 0; 1880 } 1881 1882 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1883 struct ieee80211_supported_band *sband, 1884 bool large) 1885 { 1886 struct nlattr *nl_rates, *nl_rate; 1887 struct ieee80211_rate *rate; 1888 int i; 1889 1890 /* add HT info */ 1891 if (sband->ht_cap.ht_supported && 1892 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1893 sizeof(sband->ht_cap.mcs), 1894 &sband->ht_cap.mcs) || 1895 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1896 sband->ht_cap.cap) || 1897 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1898 sband->ht_cap.ampdu_factor) || 1899 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1900 sband->ht_cap.ampdu_density))) 1901 return -ENOBUFS; 1902 1903 /* add VHT info */ 1904 if (sband->vht_cap.vht_supported && 1905 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1906 sizeof(sband->vht_cap.vht_mcs), 1907 &sband->vht_cap.vht_mcs) || 1908 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1909 sband->vht_cap.cap))) 1910 return -ENOBUFS; 1911 1912 if (large && sband->n_iftype_data) { 1913 struct nlattr *nl_iftype_data = 1914 nla_nest_start_noflag(msg, 1915 NL80211_BAND_ATTR_IFTYPE_DATA); 1916 int err; 1917 1918 if (!nl_iftype_data) 1919 return -ENOBUFS; 1920 1921 for (i = 0; i < sband->n_iftype_data; i++) { 1922 struct nlattr *iftdata; 1923 1924 iftdata = nla_nest_start_noflag(msg, i + 1); 1925 if (!iftdata) 1926 return -ENOBUFS; 1927 1928 err = nl80211_send_iftype_data(msg, sband, 1929 &sband->iftype_data[i]); 1930 if (err) 1931 return err; 1932 1933 nla_nest_end(msg, iftdata); 1934 } 1935 1936 nla_nest_end(msg, nl_iftype_data); 1937 } 1938 1939 /* add EDMG info */ 1940 if (large && sband->edmg_cap.channels && 1941 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, 1942 sband->edmg_cap.channels) || 1943 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, 1944 sband->edmg_cap.bw_config))) 1945 1946 return -ENOBUFS; 1947 1948 /* add bitrates */ 1949 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1950 if (!nl_rates) 1951 return -ENOBUFS; 1952 1953 for (i = 0; i < sband->n_bitrates; i++) { 1954 nl_rate = nla_nest_start_noflag(msg, i); 1955 if (!nl_rate) 1956 return -ENOBUFS; 1957 1958 rate = &sband->bitrates[i]; 1959 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1960 rate->bitrate)) 1961 return -ENOBUFS; 1962 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1963 nla_put_flag(msg, 1964 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1965 return -ENOBUFS; 1966 1967 nla_nest_end(msg, nl_rate); 1968 } 1969 1970 nla_nest_end(msg, nl_rates); 1971 1972 /* S1G capabilities */ 1973 if (sband->band == NL80211_BAND_S1GHZ && sband->s1g_cap.s1g && 1974 (nla_put(msg, NL80211_BAND_ATTR_S1G_CAPA, 1975 sizeof(sband->s1g_cap.cap), 1976 sband->s1g_cap.cap) || 1977 nla_put(msg, NL80211_BAND_ATTR_S1G_MCS_NSS_SET, 1978 sizeof(sband->s1g_cap.nss_mcs), 1979 sband->s1g_cap.nss_mcs))) 1980 return -ENOBUFS; 1981 1982 return 0; 1983 } 1984 1985 static int 1986 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1987 const struct ieee80211_txrx_stypes *mgmt_stypes) 1988 { 1989 u16 stypes; 1990 struct nlattr *nl_ftypes, *nl_ifs; 1991 enum nl80211_iftype ift; 1992 int i; 1993 1994 if (!mgmt_stypes) 1995 return 0; 1996 1997 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 1998 if (!nl_ifs) 1999 return -ENOBUFS; 2000 2001 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 2002 nl_ftypes = nla_nest_start_noflag(msg, ift); 2003 if (!nl_ftypes) 2004 return -ENOBUFS; 2005 i = 0; 2006 stypes = mgmt_stypes[ift].tx; 2007 while (stypes) { 2008 if ((stypes & 1) && 2009 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 2010 (i << 4) | IEEE80211_FTYPE_MGMT)) 2011 return -ENOBUFS; 2012 stypes >>= 1; 2013 i++; 2014 } 2015 nla_nest_end(msg, nl_ftypes); 2016 } 2017 2018 nla_nest_end(msg, nl_ifs); 2019 2020 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 2021 if (!nl_ifs) 2022 return -ENOBUFS; 2023 2024 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 2025 nl_ftypes = nla_nest_start_noflag(msg, ift); 2026 if (!nl_ftypes) 2027 return -ENOBUFS; 2028 i = 0; 2029 stypes = mgmt_stypes[ift].rx; 2030 while (stypes) { 2031 if ((stypes & 1) && 2032 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 2033 (i << 4) | IEEE80211_FTYPE_MGMT)) 2034 return -ENOBUFS; 2035 stypes >>= 1; 2036 i++; 2037 } 2038 nla_nest_end(msg, nl_ftypes); 2039 } 2040 nla_nest_end(msg, nl_ifs); 2041 2042 return 0; 2043 } 2044 2045 #define CMD(op, n) \ 2046 do { \ 2047 if (rdev->ops->op) { \ 2048 i++; \ 2049 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 2050 goto nla_put_failure; \ 2051 } \ 2052 } while (0) 2053 2054 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 2055 struct sk_buff *msg) 2056 { 2057 int i = 0; 2058 2059 /* 2060 * do *NOT* add anything into this function, new things need to be 2061 * advertised only to new versions of userspace that can deal with 2062 * the split (and they can't possibly care about new features... 2063 */ 2064 CMD(add_virtual_intf, NEW_INTERFACE); 2065 CMD(change_virtual_intf, SET_INTERFACE); 2066 CMD(add_key, NEW_KEY); 2067 CMD(start_ap, START_AP); 2068 CMD(add_station, NEW_STATION); 2069 CMD(add_mpath, NEW_MPATH); 2070 CMD(update_mesh_config, SET_MESH_CONFIG); 2071 CMD(change_bss, SET_BSS); 2072 CMD(auth, AUTHENTICATE); 2073 CMD(assoc, ASSOCIATE); 2074 CMD(deauth, DEAUTHENTICATE); 2075 CMD(disassoc, DISASSOCIATE); 2076 CMD(join_ibss, JOIN_IBSS); 2077 CMD(join_mesh, JOIN_MESH); 2078 CMD(set_pmksa, SET_PMKSA); 2079 CMD(del_pmksa, DEL_PMKSA); 2080 CMD(flush_pmksa, FLUSH_PMKSA); 2081 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 2082 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 2083 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 2084 CMD(mgmt_tx, FRAME); 2085 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 2086 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 2087 i++; 2088 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 2089 goto nla_put_failure; 2090 } 2091 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 2092 rdev->ops->join_mesh) { 2093 i++; 2094 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 2095 goto nla_put_failure; 2096 } 2097 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 2098 CMD(tdls_mgmt, TDLS_MGMT); 2099 CMD(tdls_oper, TDLS_OPER); 2100 } 2101 if (rdev->wiphy.max_sched_scan_reqs) 2102 CMD(sched_scan_start, START_SCHED_SCAN); 2103 CMD(probe_client, PROBE_CLIENT); 2104 CMD(set_noack_map, SET_NOACK_MAP); 2105 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 2106 i++; 2107 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 2108 goto nla_put_failure; 2109 } 2110 CMD(start_p2p_device, START_P2P_DEVICE); 2111 CMD(set_mcast_rate, SET_MCAST_RATE); 2112 #ifdef CONFIG_NL80211_TESTMODE 2113 CMD(testmode_cmd, TESTMODE); 2114 #endif 2115 2116 if (rdev->ops->connect || rdev->ops->auth) { 2117 i++; 2118 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 2119 goto nla_put_failure; 2120 } 2121 2122 if (rdev->ops->disconnect || rdev->ops->deauth) { 2123 i++; 2124 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 2125 goto nla_put_failure; 2126 } 2127 2128 return i; 2129 nla_put_failure: 2130 return -ENOBUFS; 2131 } 2132 2133 static int 2134 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 2135 struct sk_buff *msg) 2136 { 2137 struct nlattr *ftm; 2138 2139 if (!cap->ftm.supported) 2140 return 0; 2141 2142 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 2143 if (!ftm) 2144 return -ENOBUFS; 2145 2146 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 2147 return -ENOBUFS; 2148 if (cap->ftm.non_asap && 2149 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 2150 return -ENOBUFS; 2151 if (cap->ftm.request_lci && 2152 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 2153 return -ENOBUFS; 2154 if (cap->ftm.request_civicloc && 2155 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 2156 return -ENOBUFS; 2157 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 2158 cap->ftm.preambles)) 2159 return -ENOBUFS; 2160 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 2161 cap->ftm.bandwidths)) 2162 return -ENOBUFS; 2163 if (cap->ftm.max_bursts_exponent >= 0 && 2164 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 2165 cap->ftm.max_bursts_exponent)) 2166 return -ENOBUFS; 2167 if (cap->ftm.max_ftms_per_burst && 2168 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 2169 cap->ftm.max_ftms_per_burst)) 2170 return -ENOBUFS; 2171 if (cap->ftm.trigger_based && 2172 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) 2173 return -ENOBUFS; 2174 if (cap->ftm.non_trigger_based && 2175 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) 2176 return -ENOBUFS; 2177 2178 nla_nest_end(msg, ftm); 2179 return 0; 2180 } 2181 2182 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 2183 struct sk_buff *msg) 2184 { 2185 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 2186 struct nlattr *pmsr, *caps; 2187 2188 if (!cap) 2189 return 0; 2190 2191 /* 2192 * we don't need to clean up anything here since the caller 2193 * will genlmsg_cancel() if we fail 2194 */ 2195 2196 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 2197 if (!pmsr) 2198 return -ENOBUFS; 2199 2200 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 2201 return -ENOBUFS; 2202 2203 if (cap->report_ap_tsf && 2204 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 2205 return -ENOBUFS; 2206 2207 if (cap->randomize_mac_addr && 2208 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 2209 return -ENOBUFS; 2210 2211 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 2212 if (!caps) 2213 return -ENOBUFS; 2214 2215 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 2216 return -ENOBUFS; 2217 2218 nla_nest_end(msg, caps); 2219 nla_nest_end(msg, pmsr); 2220 2221 return 0; 2222 } 2223 2224 static int 2225 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, 2226 struct sk_buff *msg) 2227 { 2228 int i; 2229 struct nlattr *nested, *nested_akms; 2230 const struct wiphy_iftype_akm_suites *iftype_akms; 2231 2232 if (!rdev->wiphy.num_iftype_akm_suites || 2233 !rdev->wiphy.iftype_akm_suites) 2234 return 0; 2235 2236 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); 2237 if (!nested) 2238 return -ENOBUFS; 2239 2240 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { 2241 nested_akms = nla_nest_start(msg, i + 1); 2242 if (!nested_akms) 2243 return -ENOBUFS; 2244 2245 iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; 2246 2247 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, 2248 iftype_akms->iftypes_mask)) 2249 return -ENOBUFS; 2250 2251 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, 2252 sizeof(u32) * iftype_akms->n_akm_suites, 2253 iftype_akms->akm_suites)) { 2254 return -ENOBUFS; 2255 } 2256 nla_nest_end(msg, nested_akms); 2257 } 2258 2259 nla_nest_end(msg, nested); 2260 2261 return 0; 2262 } 2263 2264 static int 2265 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, 2266 struct sk_buff *msg) 2267 { 2268 struct nlattr *supp; 2269 2270 if (!rdev->wiphy.tid_config_support.vif && 2271 !rdev->wiphy.tid_config_support.peer) 2272 return 0; 2273 2274 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); 2275 if (!supp) 2276 return -ENOSPC; 2277 2278 if (rdev->wiphy.tid_config_support.vif && 2279 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, 2280 rdev->wiphy.tid_config_support.vif, 2281 NL80211_TID_CONFIG_ATTR_PAD)) 2282 goto fail; 2283 2284 if (rdev->wiphy.tid_config_support.peer && 2285 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, 2286 rdev->wiphy.tid_config_support.peer, 2287 NL80211_TID_CONFIG_ATTR_PAD)) 2288 goto fail; 2289 2290 /* for now we just use the same value ... makes more sense */ 2291 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, 2292 rdev->wiphy.tid_config_support.max_retry)) 2293 goto fail; 2294 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, 2295 rdev->wiphy.tid_config_support.max_retry)) 2296 goto fail; 2297 2298 nla_nest_end(msg, supp); 2299 2300 return 0; 2301 fail: 2302 nla_nest_cancel(msg, supp); 2303 return -ENOBUFS; 2304 } 2305 2306 static int 2307 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, 2308 struct sk_buff *msg) 2309 { 2310 struct nlattr *sar_capa, *specs, *sub_freq_range; 2311 u8 num_freq_ranges; 2312 int i; 2313 2314 if (!rdev->wiphy.sar_capa) 2315 return 0; 2316 2317 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; 2318 2319 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); 2320 if (!sar_capa) 2321 return -ENOSPC; 2322 2323 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) 2324 goto fail; 2325 2326 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); 2327 if (!specs) 2328 goto fail; 2329 2330 /* report supported freq_ranges */ 2331 for (i = 0; i < num_freq_ranges; i++) { 2332 sub_freq_range = nla_nest_start(msg, i + 1); 2333 if (!sub_freq_range) 2334 goto fail; 2335 2336 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, 2337 rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) 2338 goto fail; 2339 2340 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, 2341 rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) 2342 goto fail; 2343 2344 nla_nest_end(msg, sub_freq_range); 2345 } 2346 2347 nla_nest_end(msg, specs); 2348 nla_nest_end(msg, sar_capa); 2349 2350 return 0; 2351 fail: 2352 nla_nest_cancel(msg, sar_capa); 2353 return -ENOBUFS; 2354 } 2355 2356 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg) 2357 { 2358 struct nlattr *config; 2359 2360 if (!wiphy->mbssid_max_interfaces) 2361 return 0; 2362 2363 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); 2364 if (!config) 2365 return -ENOBUFS; 2366 2367 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, 2368 wiphy->mbssid_max_interfaces)) 2369 goto fail; 2370 2371 if (wiphy->ema_max_profile_periodicity && 2372 nla_put_u8(msg, 2373 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, 2374 wiphy->ema_max_profile_periodicity)) 2375 goto fail; 2376 2377 nla_nest_end(msg, config); 2378 return 0; 2379 2380 fail: 2381 nla_nest_cancel(msg, config); 2382 return -ENOBUFS; 2383 } 2384 2385 struct nl80211_dump_wiphy_state { 2386 s64 filter_wiphy; 2387 long start; 2388 long split_start, band_start, chan_start, capa_start; 2389 bool split; 2390 }; 2391 2392 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 2393 enum nl80211_commands cmd, 2394 struct sk_buff *msg, u32 portid, u32 seq, 2395 int flags, struct nl80211_dump_wiphy_state *state) 2396 { 2397 void *hdr; 2398 struct nlattr *nl_bands, *nl_band; 2399 struct nlattr *nl_freqs, *nl_freq; 2400 struct nlattr *nl_cmds; 2401 enum nl80211_band band; 2402 struct ieee80211_channel *chan; 2403 int i; 2404 const struct ieee80211_txrx_stypes *mgmt_stypes = 2405 rdev->wiphy.mgmt_stypes; 2406 u32 features; 2407 2408 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 2409 if (!hdr) 2410 return -ENOBUFS; 2411 2412 if (WARN_ON(!state)) 2413 return -EINVAL; 2414 2415 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 2416 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 2417 wiphy_name(&rdev->wiphy)) || 2418 nla_put_u32(msg, NL80211_ATTR_GENERATION, 2419 cfg80211_rdev_list_generation)) 2420 goto nla_put_failure; 2421 2422 if (cmd != NL80211_CMD_NEW_WIPHY) 2423 goto finish; 2424 2425 switch (state->split_start) { 2426 case 0: 2427 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 2428 rdev->wiphy.retry_short) || 2429 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 2430 rdev->wiphy.retry_long) || 2431 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 2432 rdev->wiphy.frag_threshold) || 2433 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 2434 rdev->wiphy.rts_threshold) || 2435 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 2436 rdev->wiphy.coverage_class) || 2437 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 2438 rdev->wiphy.max_scan_ssids) || 2439 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 2440 rdev->wiphy.max_sched_scan_ssids) || 2441 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 2442 rdev->wiphy.max_scan_ie_len) || 2443 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 2444 rdev->wiphy.max_sched_scan_ie_len) || 2445 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 2446 rdev->wiphy.max_match_sets)) 2447 goto nla_put_failure; 2448 2449 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 2450 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 2451 goto nla_put_failure; 2452 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 2453 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 2454 goto nla_put_failure; 2455 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 2456 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 2457 goto nla_put_failure; 2458 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 2459 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 2460 goto nla_put_failure; 2461 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 2462 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 2463 goto nla_put_failure; 2464 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 2465 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 2466 goto nla_put_failure; 2467 state->split_start++; 2468 if (state->split) 2469 break; 2470 fallthrough; 2471 case 1: 2472 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 2473 sizeof(u32) * rdev->wiphy.n_cipher_suites, 2474 rdev->wiphy.cipher_suites)) 2475 goto nla_put_failure; 2476 2477 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 2478 rdev->wiphy.max_num_pmkids)) 2479 goto nla_put_failure; 2480 2481 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 2482 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 2483 goto nla_put_failure; 2484 2485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 2486 rdev->wiphy.available_antennas_tx) || 2487 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 2488 rdev->wiphy.available_antennas_rx)) 2489 goto nla_put_failure; 2490 2491 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 2492 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 2493 rdev->wiphy.probe_resp_offload)) 2494 goto nla_put_failure; 2495 2496 if ((rdev->wiphy.available_antennas_tx || 2497 rdev->wiphy.available_antennas_rx) && 2498 rdev->ops->get_antenna) { 2499 u32 tx_ant = 0, rx_ant = 0; 2500 int res; 2501 2502 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 2503 if (!res) { 2504 if (nla_put_u32(msg, 2505 NL80211_ATTR_WIPHY_ANTENNA_TX, 2506 tx_ant) || 2507 nla_put_u32(msg, 2508 NL80211_ATTR_WIPHY_ANTENNA_RX, 2509 rx_ant)) 2510 goto nla_put_failure; 2511 } 2512 } 2513 2514 state->split_start++; 2515 if (state->split) 2516 break; 2517 fallthrough; 2518 case 2: 2519 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 2520 rdev->wiphy.interface_modes)) 2521 goto nla_put_failure; 2522 state->split_start++; 2523 if (state->split) 2524 break; 2525 fallthrough; 2526 case 3: 2527 nl_bands = nla_nest_start_noflag(msg, 2528 NL80211_ATTR_WIPHY_BANDS); 2529 if (!nl_bands) 2530 goto nla_put_failure; 2531 2532 for (band = state->band_start; 2533 band < (state->split ? 2534 NUM_NL80211_BANDS : 2535 NL80211_BAND_60GHZ + 1); 2536 band++) { 2537 struct ieee80211_supported_band *sband; 2538 2539 /* omit higher bands for ancient software */ 2540 if (band > NL80211_BAND_5GHZ && !state->split) 2541 break; 2542 2543 sband = rdev->wiphy.bands[band]; 2544 2545 if (!sband) 2546 continue; 2547 2548 nl_band = nla_nest_start_noflag(msg, band); 2549 if (!nl_band) 2550 goto nla_put_failure; 2551 2552 switch (state->chan_start) { 2553 case 0: 2554 if (nl80211_send_band_rateinfo(msg, sband, 2555 state->split)) 2556 goto nla_put_failure; 2557 state->chan_start++; 2558 if (state->split) 2559 break; 2560 fallthrough; 2561 default: 2562 /* add frequencies */ 2563 nl_freqs = nla_nest_start_noflag(msg, 2564 NL80211_BAND_ATTR_FREQS); 2565 if (!nl_freqs) 2566 goto nla_put_failure; 2567 2568 for (i = state->chan_start - 1; 2569 i < sband->n_channels; 2570 i++) { 2571 nl_freq = nla_nest_start_noflag(msg, 2572 i); 2573 if (!nl_freq) 2574 goto nla_put_failure; 2575 2576 chan = &sband->channels[i]; 2577 2578 if (nl80211_msg_put_channel( 2579 msg, &rdev->wiphy, chan, 2580 state->split)) 2581 goto nla_put_failure; 2582 2583 nla_nest_end(msg, nl_freq); 2584 if (state->split) 2585 break; 2586 } 2587 if (i < sband->n_channels) 2588 state->chan_start = i + 2; 2589 else 2590 state->chan_start = 0; 2591 nla_nest_end(msg, nl_freqs); 2592 } 2593 2594 nla_nest_end(msg, nl_band); 2595 2596 if (state->split) { 2597 /* start again here */ 2598 if (state->chan_start) 2599 band--; 2600 break; 2601 } 2602 } 2603 nla_nest_end(msg, nl_bands); 2604 2605 if (band < NUM_NL80211_BANDS) 2606 state->band_start = band + 1; 2607 else 2608 state->band_start = 0; 2609 2610 /* if bands & channels are done, continue outside */ 2611 if (state->band_start == 0 && state->chan_start == 0) 2612 state->split_start++; 2613 if (state->split) 2614 break; 2615 fallthrough; 2616 case 4: 2617 nl_cmds = nla_nest_start_noflag(msg, 2618 NL80211_ATTR_SUPPORTED_COMMANDS); 2619 if (!nl_cmds) 2620 goto nla_put_failure; 2621 2622 i = nl80211_add_commands_unsplit(rdev, msg); 2623 if (i < 0) 2624 goto nla_put_failure; 2625 if (state->split) { 2626 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2627 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2628 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2629 CMD(channel_switch, CHANNEL_SWITCH); 2630 CMD(set_qos_map, SET_QOS_MAP); 2631 if (rdev->wiphy.features & 2632 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2633 CMD(add_tx_ts, ADD_TX_TS); 2634 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2635 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2636 CMD(update_ft_ies, UPDATE_FT_IES); 2637 if (rdev->wiphy.sar_capa) 2638 CMD(set_sar_specs, SET_SAR_SPECS); 2639 } 2640 #undef CMD 2641 2642 nla_nest_end(msg, nl_cmds); 2643 state->split_start++; 2644 if (state->split) 2645 break; 2646 fallthrough; 2647 case 5: 2648 if (rdev->ops->remain_on_channel && 2649 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2650 nla_put_u32(msg, 2651 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2652 rdev->wiphy.max_remain_on_channel_duration)) 2653 goto nla_put_failure; 2654 2655 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2656 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2657 goto nla_put_failure; 2658 2659 state->split_start++; 2660 if (state->split) 2661 break; 2662 fallthrough; 2663 case 6: 2664 #ifdef CONFIG_PM 2665 if (nl80211_send_wowlan(msg, rdev, state->split)) 2666 goto nla_put_failure; 2667 state->split_start++; 2668 if (state->split) 2669 break; 2670 #else 2671 state->split_start++; 2672 #endif 2673 fallthrough; 2674 case 7: 2675 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2676 rdev->wiphy.software_iftypes)) 2677 goto nla_put_failure; 2678 2679 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2680 state->split)) 2681 goto nla_put_failure; 2682 2683 state->split_start++; 2684 if (state->split) 2685 break; 2686 fallthrough; 2687 case 8: 2688 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2689 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2690 rdev->wiphy.ap_sme_capa)) 2691 goto nla_put_failure; 2692 2693 features = rdev->wiphy.features; 2694 /* 2695 * We can only add the per-channel limit information if the 2696 * dump is split, otherwise it makes it too big. Therefore 2697 * only advertise it in that case. 2698 */ 2699 if (state->split) 2700 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2701 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2702 goto nla_put_failure; 2703 2704 if (rdev->wiphy.ht_capa_mod_mask && 2705 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2706 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2707 rdev->wiphy.ht_capa_mod_mask)) 2708 goto nla_put_failure; 2709 2710 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2711 rdev->wiphy.max_acl_mac_addrs && 2712 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2713 rdev->wiphy.max_acl_mac_addrs)) 2714 goto nla_put_failure; 2715 2716 /* 2717 * Any information below this point is only available to 2718 * applications that can deal with it being split. This 2719 * helps ensure that newly added capabilities don't break 2720 * older tools by overrunning their buffers. 2721 * 2722 * We still increment split_start so that in the split 2723 * case we'll continue with more data in the next round, 2724 * but break unconditionally so unsplit data stops here. 2725 */ 2726 if (state->split) 2727 state->split_start++; 2728 else 2729 state->split_start = 0; 2730 break; 2731 case 9: 2732 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2733 goto nla_put_failure; 2734 2735 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 2736 rdev->wiphy.max_sched_scan_plans) || 2737 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 2738 rdev->wiphy.max_sched_scan_plan_interval) || 2739 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 2740 rdev->wiphy.max_sched_scan_plan_iterations)) 2741 goto nla_put_failure; 2742 2743 if (rdev->wiphy.extended_capabilities && 2744 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2745 rdev->wiphy.extended_capabilities_len, 2746 rdev->wiphy.extended_capabilities) || 2747 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2748 rdev->wiphy.extended_capabilities_len, 2749 rdev->wiphy.extended_capabilities_mask))) 2750 goto nla_put_failure; 2751 2752 if (rdev->wiphy.vht_capa_mod_mask && 2753 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2754 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2755 rdev->wiphy.vht_capa_mod_mask)) 2756 goto nla_put_failure; 2757 2758 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 2759 rdev->wiphy.perm_addr)) 2760 goto nla_put_failure; 2761 2762 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && 2763 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, 2764 rdev->wiphy.addr_mask)) 2765 goto nla_put_failure; 2766 2767 if (rdev->wiphy.n_addresses > 1) { 2768 void *attr; 2769 2770 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); 2771 if (!attr) 2772 goto nla_put_failure; 2773 2774 for (i = 0; i < rdev->wiphy.n_addresses; i++) 2775 if (nla_put(msg, i + 1, ETH_ALEN, 2776 rdev->wiphy.addresses[i].addr)) 2777 goto nla_put_failure; 2778 2779 nla_nest_end(msg, attr); 2780 } 2781 2782 state->split_start++; 2783 break; 2784 case 10: 2785 if (nl80211_send_coalesce(msg, rdev)) 2786 goto nla_put_failure; 2787 2788 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2789 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2790 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2791 goto nla_put_failure; 2792 2793 if (rdev->wiphy.max_ap_assoc_sta && 2794 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2795 rdev->wiphy.max_ap_assoc_sta)) 2796 goto nla_put_failure; 2797 2798 state->split_start++; 2799 break; 2800 case 11: 2801 if (rdev->wiphy.n_vendor_commands) { 2802 const struct nl80211_vendor_cmd_info *info; 2803 struct nlattr *nested; 2804 2805 nested = nla_nest_start_noflag(msg, 2806 NL80211_ATTR_VENDOR_DATA); 2807 if (!nested) 2808 goto nla_put_failure; 2809 2810 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2811 info = &rdev->wiphy.vendor_commands[i].info; 2812 if (nla_put(msg, i + 1, sizeof(*info), info)) 2813 goto nla_put_failure; 2814 } 2815 nla_nest_end(msg, nested); 2816 } 2817 2818 if (rdev->wiphy.n_vendor_events) { 2819 const struct nl80211_vendor_cmd_info *info; 2820 struct nlattr *nested; 2821 2822 nested = nla_nest_start_noflag(msg, 2823 NL80211_ATTR_VENDOR_EVENTS); 2824 if (!nested) 2825 goto nla_put_failure; 2826 2827 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2828 info = &rdev->wiphy.vendor_events[i]; 2829 if (nla_put(msg, i + 1, sizeof(*info), info)) 2830 goto nla_put_failure; 2831 } 2832 nla_nest_end(msg, nested); 2833 } 2834 state->split_start++; 2835 break; 2836 case 12: 2837 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2838 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2839 rdev->wiphy.max_num_csa_counters)) 2840 goto nla_put_failure; 2841 2842 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2843 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2844 goto nla_put_failure; 2845 2846 if (rdev->wiphy.max_sched_scan_reqs && 2847 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2848 rdev->wiphy.max_sched_scan_reqs)) 2849 goto nla_put_failure; 2850 2851 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2852 sizeof(rdev->wiphy.ext_features), 2853 rdev->wiphy.ext_features)) 2854 goto nla_put_failure; 2855 2856 if (rdev->wiphy.bss_select_support) { 2857 struct nlattr *nested; 2858 u32 bss_select_support = rdev->wiphy.bss_select_support; 2859 2860 nested = nla_nest_start_noflag(msg, 2861 NL80211_ATTR_BSS_SELECT); 2862 if (!nested) 2863 goto nla_put_failure; 2864 2865 i = 0; 2866 while (bss_select_support) { 2867 if ((bss_select_support & 1) && 2868 nla_put_flag(msg, i)) 2869 goto nla_put_failure; 2870 i++; 2871 bss_select_support >>= 1; 2872 } 2873 nla_nest_end(msg, nested); 2874 } 2875 2876 state->split_start++; 2877 break; 2878 case 13: 2879 if (rdev->wiphy.num_iftype_ext_capab && 2880 rdev->wiphy.iftype_ext_capab) { 2881 struct nlattr *nested_ext_capab, *nested; 2882 2883 nested = nla_nest_start_noflag(msg, 2884 NL80211_ATTR_IFTYPE_EXT_CAPA); 2885 if (!nested) 2886 goto nla_put_failure; 2887 2888 for (i = state->capa_start; 2889 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2890 const struct wiphy_iftype_ext_capab *capab; 2891 2892 capab = &rdev->wiphy.iftype_ext_capab[i]; 2893 2894 nested_ext_capab = nla_nest_start_noflag(msg, 2895 i); 2896 if (!nested_ext_capab || 2897 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2898 capab->iftype) || 2899 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2900 capab->extended_capabilities_len, 2901 capab->extended_capabilities) || 2902 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2903 capab->extended_capabilities_len, 2904 capab->extended_capabilities_mask)) 2905 goto nla_put_failure; 2906 2907 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO && 2908 (nla_put_u16(msg, 2909 NL80211_ATTR_EML_CAPABILITY, 2910 capab->eml_capabilities) || 2911 nla_put_u16(msg, 2912 NL80211_ATTR_MLD_CAPA_AND_OPS, 2913 capab->mld_capa_and_ops))) 2914 goto nla_put_failure; 2915 2916 nla_nest_end(msg, nested_ext_capab); 2917 if (state->split) 2918 break; 2919 } 2920 nla_nest_end(msg, nested); 2921 if (i < rdev->wiphy.num_iftype_ext_capab) { 2922 state->capa_start = i + 1; 2923 break; 2924 } 2925 } 2926 2927 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2928 rdev->wiphy.nan_supported_bands)) 2929 goto nla_put_failure; 2930 2931 if (wiphy_ext_feature_isset(&rdev->wiphy, 2932 NL80211_EXT_FEATURE_TXQS)) { 2933 struct cfg80211_txq_stats txqstats = {}; 2934 int res; 2935 2936 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2937 if (!res && 2938 !nl80211_put_txq_stats(msg, &txqstats, 2939 NL80211_ATTR_TXQ_STATS)) 2940 goto nla_put_failure; 2941 2942 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2943 rdev->wiphy.txq_limit)) 2944 goto nla_put_failure; 2945 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2946 rdev->wiphy.txq_memory_limit)) 2947 goto nla_put_failure; 2948 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2949 rdev->wiphy.txq_quantum)) 2950 goto nla_put_failure; 2951 } 2952 2953 state->split_start++; 2954 break; 2955 case 14: 2956 if (nl80211_send_pmsr_capa(rdev, msg)) 2957 goto nla_put_failure; 2958 2959 state->split_start++; 2960 break; 2961 case 15: 2962 if (rdev->wiphy.akm_suites && 2963 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2964 sizeof(u32) * rdev->wiphy.n_akm_suites, 2965 rdev->wiphy.akm_suites)) 2966 goto nla_put_failure; 2967 2968 if (nl80211_put_iftype_akm_suites(rdev, msg)) 2969 goto nla_put_failure; 2970 2971 if (nl80211_put_tid_config_support(rdev, msg)) 2972 goto nla_put_failure; 2973 state->split_start++; 2974 break; 2975 case 16: 2976 if (nl80211_put_sar_specs(rdev, msg)) 2977 goto nla_put_failure; 2978 2979 if (nl80211_put_mbssid_support(&rdev->wiphy, msg)) 2980 goto nla_put_failure; 2981 2982 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES, 2983 rdev->wiphy.max_num_akm_suites)) 2984 goto nla_put_failure; 2985 2986 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO) 2987 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT); 2988 2989 if (rdev->wiphy.hw_timestamp_max_peers && 2990 nla_put_u16(msg, NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS, 2991 rdev->wiphy.hw_timestamp_max_peers)) 2992 goto nla_put_failure; 2993 2994 /* done */ 2995 state->split_start = 0; 2996 break; 2997 } 2998 finish: 2999 genlmsg_end(msg, hdr); 3000 return 0; 3001 3002 nla_put_failure: 3003 genlmsg_cancel(msg, hdr); 3004 return -EMSGSIZE; 3005 } 3006 3007 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 3008 struct netlink_callback *cb, 3009 struct nl80211_dump_wiphy_state *state) 3010 { 3011 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 3012 int ret; 3013 3014 if (!tb) 3015 return -ENOMEM; 3016 3017 ret = nlmsg_parse_deprecated(cb->nlh, 3018 GENL_HDRLEN + nl80211_fam.hdrsize, 3019 tb, nl80211_fam.maxattr, 3020 nl80211_policy, NULL); 3021 /* ignore parse errors for backward compatibility */ 3022 if (ret) { 3023 ret = 0; 3024 goto out; 3025 } 3026 3027 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 3028 if (tb[NL80211_ATTR_WIPHY]) 3029 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 3030 if (tb[NL80211_ATTR_WDEV]) 3031 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 3032 if (tb[NL80211_ATTR_IFINDEX]) { 3033 struct net_device *netdev; 3034 struct cfg80211_registered_device *rdev; 3035 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 3036 3037 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 3038 if (!netdev) { 3039 ret = -ENODEV; 3040 goto out; 3041 } 3042 if (netdev->ieee80211_ptr) { 3043 rdev = wiphy_to_rdev( 3044 netdev->ieee80211_ptr->wiphy); 3045 state->filter_wiphy = rdev->wiphy_idx; 3046 } 3047 } 3048 3049 ret = 0; 3050 out: 3051 kfree(tb); 3052 return ret; 3053 } 3054 3055 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 3056 { 3057 int idx = 0, ret; 3058 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 3059 struct cfg80211_registered_device *rdev; 3060 3061 rtnl_lock(); 3062 if (!state) { 3063 state = kzalloc(sizeof(*state), GFP_KERNEL); 3064 if (!state) { 3065 rtnl_unlock(); 3066 return -ENOMEM; 3067 } 3068 state->filter_wiphy = -1; 3069 ret = nl80211_dump_wiphy_parse(skb, cb, state); 3070 if (ret) { 3071 kfree(state); 3072 rtnl_unlock(); 3073 return ret; 3074 } 3075 cb->args[0] = (long)state; 3076 } 3077 3078 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3079 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3080 continue; 3081 if (++idx <= state->start) 3082 continue; 3083 if (state->filter_wiphy != -1 && 3084 state->filter_wiphy != rdev->wiphy_idx) 3085 continue; 3086 wiphy_lock(&rdev->wiphy); 3087 /* attempt to fit multiple wiphy data chunks into the skb */ 3088 do { 3089 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 3090 skb, 3091 NETLINK_CB(cb->skb).portid, 3092 cb->nlh->nlmsg_seq, 3093 NLM_F_MULTI, state); 3094 if (ret < 0) { 3095 /* 3096 * If sending the wiphy data didn't fit (ENOBUFS 3097 * or EMSGSIZE returned), this SKB is still 3098 * empty (so it's not too big because another 3099 * wiphy dataset is already in the skb) and 3100 * we've not tried to adjust the dump allocation 3101 * yet ... then adjust the alloc size to be 3102 * bigger, and return 1 but with the empty skb. 3103 * This results in an empty message being RX'ed 3104 * in userspace, but that is ignored. 3105 * 3106 * We can then retry with the larger buffer. 3107 */ 3108 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 3109 !skb->len && !state->split && 3110 cb->min_dump_alloc < 4096) { 3111 cb->min_dump_alloc = 4096; 3112 state->split_start = 0; 3113 wiphy_unlock(&rdev->wiphy); 3114 rtnl_unlock(); 3115 return 1; 3116 } 3117 idx--; 3118 break; 3119 } 3120 } while (state->split_start > 0); 3121 wiphy_unlock(&rdev->wiphy); 3122 break; 3123 } 3124 rtnl_unlock(); 3125 3126 state->start = idx; 3127 3128 return skb->len; 3129 } 3130 3131 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 3132 { 3133 kfree((void *)cb->args[0]); 3134 return 0; 3135 } 3136 3137 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 3138 { 3139 struct sk_buff *msg; 3140 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3141 struct nl80211_dump_wiphy_state state = {}; 3142 3143 msg = nlmsg_new(4096, GFP_KERNEL); 3144 if (!msg) 3145 return -ENOMEM; 3146 3147 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 3148 info->snd_portid, info->snd_seq, 0, 3149 &state) < 0) { 3150 nlmsg_free(msg); 3151 return -ENOBUFS; 3152 } 3153 3154 return genlmsg_reply(msg, info); 3155 } 3156 3157 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 3158 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 3159 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 3160 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 3161 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 3162 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 3163 }; 3164 3165 static int parse_txq_params(struct nlattr *tb[], 3166 struct ieee80211_txq_params *txq_params) 3167 { 3168 u8 ac; 3169 3170 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 3171 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 3172 !tb[NL80211_TXQ_ATTR_AIFS]) 3173 return -EINVAL; 3174 3175 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 3176 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 3177 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 3178 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 3179 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 3180 3181 if (ac >= NL80211_NUM_ACS) 3182 return -EINVAL; 3183 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 3184 return 0; 3185 } 3186 3187 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 3188 { 3189 /* 3190 * You can only set the channel explicitly for some interfaces, 3191 * most have their channel managed via their respective 3192 * "establish a connection" command (connect, join, ...) 3193 * 3194 * For AP/GO and mesh mode, the channel can be set with the 3195 * channel userspace API, but is only stored and passed to the 3196 * low-level driver when the AP starts or the mesh is joined. 3197 * This is for backward compatibility, userspace can also give 3198 * the channel in the start-ap or join-mesh commands instead. 3199 * 3200 * Monitors are special as they are normally slaved to 3201 * whatever else is going on, so they have their own special 3202 * operation to set the monitor channel if possible. 3203 */ 3204 return !wdev || 3205 wdev->iftype == NL80211_IFTYPE_AP || 3206 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 3207 wdev->iftype == NL80211_IFTYPE_MONITOR || 3208 wdev->iftype == NL80211_IFTYPE_P2P_GO; 3209 } 3210 3211 static int nl80211_parse_punct_bitmap(struct cfg80211_registered_device *rdev, 3212 struct genl_info *info, 3213 const struct cfg80211_chan_def *chandef, 3214 u16 *punct_bitmap) 3215 { 3216 if (!wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_PUNCT)) 3217 return -EINVAL; 3218 3219 *punct_bitmap = nla_get_u32(info->attrs[NL80211_ATTR_PUNCT_BITMAP]); 3220 if (!cfg80211_valid_disable_subchannel_bitmap(punct_bitmap, chandef)) 3221 return -EINVAL; 3222 3223 return 0; 3224 } 3225 3226 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 3227 struct genl_info *info, 3228 struct cfg80211_chan_def *chandef) 3229 { 3230 struct netlink_ext_ack *extack = info->extack; 3231 struct nlattr **attrs = info->attrs; 3232 u32 control_freq; 3233 3234 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) { 3235 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3236 "Frequency is missing"); 3237 return -EINVAL; 3238 } 3239 3240 control_freq = MHZ_TO_KHZ( 3241 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3242 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 3243 control_freq += 3244 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 3245 3246 memset(chandef, 0, sizeof(*chandef)); 3247 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); 3248 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 3249 chandef->center_freq1 = KHZ_TO_MHZ(control_freq); 3250 chandef->freq1_offset = control_freq % 1000; 3251 chandef->center_freq2 = 0; 3252 3253 /* Primary channel not allowed */ 3254 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 3255 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3256 "Channel is disabled"); 3257 return -EINVAL; 3258 } 3259 3260 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 3261 enum nl80211_channel_type chantype; 3262 3263 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 3264 3265 switch (chantype) { 3266 case NL80211_CHAN_NO_HT: 3267 case NL80211_CHAN_HT20: 3268 case NL80211_CHAN_HT40PLUS: 3269 case NL80211_CHAN_HT40MINUS: 3270 cfg80211_chandef_create(chandef, chandef->chan, 3271 chantype); 3272 /* user input for center_freq is incorrect */ 3273 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 3274 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 3275 NL_SET_ERR_MSG_ATTR(extack, 3276 attrs[NL80211_ATTR_CENTER_FREQ1], 3277 "bad center frequency 1"); 3278 return -EINVAL; 3279 } 3280 /* center_freq2 must be zero */ 3281 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 3282 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 3283 NL_SET_ERR_MSG_ATTR(extack, 3284 attrs[NL80211_ATTR_CENTER_FREQ2], 3285 "center frequency 2 can't be used"); 3286 return -EINVAL; 3287 } 3288 break; 3289 default: 3290 NL_SET_ERR_MSG_ATTR(extack, 3291 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 3292 "invalid channel type"); 3293 return -EINVAL; 3294 } 3295 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 3296 chandef->width = 3297 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 3298 if (chandef->chan->band == NL80211_BAND_S1GHZ) { 3299 /* User input error for channel width doesn't match channel */ 3300 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) { 3301 NL_SET_ERR_MSG_ATTR(extack, 3302 attrs[NL80211_ATTR_CHANNEL_WIDTH], 3303 "bad channel width"); 3304 return -EINVAL; 3305 } 3306 } 3307 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 3308 chandef->center_freq1 = 3309 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 3310 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 3311 chandef->freq1_offset = nla_get_u32( 3312 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 3313 else 3314 chandef->freq1_offset = 0; 3315 } 3316 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 3317 chandef->center_freq2 = 3318 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 3319 } 3320 3321 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 3322 chandef->edmg.channels = 3323 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 3324 3325 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 3326 chandef->edmg.bw_config = 3327 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 3328 } else { 3329 chandef->edmg.bw_config = 0; 3330 chandef->edmg.channels = 0; 3331 } 3332 3333 if (!cfg80211_chandef_valid(chandef)) { 3334 NL_SET_ERR_MSG(extack, "invalid channel definition"); 3335 return -EINVAL; 3336 } 3337 3338 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 3339 IEEE80211_CHAN_DISABLED)) { 3340 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 3341 return -EINVAL; 3342 } 3343 3344 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 3345 chandef->width == NL80211_CHAN_WIDTH_10) && 3346 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 3347 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 3348 return -EINVAL; 3349 } 3350 3351 return 0; 3352 } 3353 3354 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 3355 struct net_device *dev, 3356 struct genl_info *info, 3357 int _link_id) 3358 { 3359 struct cfg80211_chan_def chandef; 3360 int result; 3361 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 3362 struct wireless_dev *wdev = NULL; 3363 int link_id = _link_id; 3364 3365 if (dev) 3366 wdev = dev->ieee80211_ptr; 3367 if (!nl80211_can_set_dev_channel(wdev)) 3368 return -EOPNOTSUPP; 3369 if (wdev) 3370 iftype = wdev->iftype; 3371 3372 if (link_id < 0) { 3373 if (wdev && wdev->valid_links) 3374 return -EINVAL; 3375 link_id = 0; 3376 } 3377 3378 result = nl80211_parse_chandef(rdev, info, &chandef); 3379 if (result) 3380 return result; 3381 3382 switch (iftype) { 3383 case NL80211_IFTYPE_AP: 3384 case NL80211_IFTYPE_P2P_GO: 3385 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 3386 iftype)) 3387 return -EINVAL; 3388 if (wdev->links[link_id].ap.beacon_interval) { 3389 struct ieee80211_channel *cur_chan; 3390 3391 if (!dev || !rdev->ops->set_ap_chanwidth || 3392 !(rdev->wiphy.features & 3393 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) 3394 return -EBUSY; 3395 3396 /* Only allow dynamic channel width changes */ 3397 cur_chan = wdev->links[link_id].ap.chandef.chan; 3398 if (chandef.chan != cur_chan) 3399 return -EBUSY; 3400 3401 result = rdev_set_ap_chanwidth(rdev, dev, link_id, 3402 &chandef); 3403 if (result) 3404 return result; 3405 wdev->links[link_id].ap.chandef = chandef; 3406 } else { 3407 wdev->u.ap.preset_chandef = chandef; 3408 } 3409 return 0; 3410 case NL80211_IFTYPE_MESH_POINT: 3411 return cfg80211_set_mesh_channel(rdev, wdev, &chandef); 3412 case NL80211_IFTYPE_MONITOR: 3413 return cfg80211_set_monitor_channel(rdev, &chandef); 3414 default: 3415 break; 3416 } 3417 3418 return -EINVAL; 3419 } 3420 3421 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 3422 { 3423 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3424 int link_id = nl80211_link_id_or_invalid(info->attrs); 3425 struct net_device *netdev = info->user_ptr[1]; 3426 int ret; 3427 3428 wdev_lock(netdev->ieee80211_ptr); 3429 ret = __nl80211_set_channel(rdev, netdev, info, link_id); 3430 wdev_unlock(netdev->ieee80211_ptr); 3431 3432 return ret; 3433 } 3434 3435 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 3436 { 3437 struct cfg80211_registered_device *rdev = NULL; 3438 struct net_device *netdev = NULL; 3439 struct wireless_dev *wdev; 3440 int result = 0, rem_txq_params = 0; 3441 struct nlattr *nl_txq_params; 3442 u32 changed; 3443 u8 retry_short = 0, retry_long = 0; 3444 u32 frag_threshold = 0, rts_threshold = 0; 3445 u8 coverage_class = 0; 3446 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 3447 3448 rtnl_lock(); 3449 /* 3450 * Try to find the wiphy and netdev. Normally this 3451 * function shouldn't need the netdev, but this is 3452 * done for backward compatibility -- previously 3453 * setting the channel was done per wiphy, but now 3454 * it is per netdev. Previous userland like hostapd 3455 * also passed a netdev to set_wiphy, so that it is 3456 * possible to let that go to the right netdev! 3457 */ 3458 3459 if (info->attrs[NL80211_ATTR_IFINDEX]) { 3460 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 3461 3462 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 3463 if (netdev && netdev->ieee80211_ptr) 3464 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 3465 else 3466 netdev = NULL; 3467 } 3468 3469 if (!netdev) { 3470 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 3471 info->attrs); 3472 if (IS_ERR(rdev)) { 3473 rtnl_unlock(); 3474 return PTR_ERR(rdev); 3475 } 3476 wdev = NULL; 3477 netdev = NULL; 3478 result = 0; 3479 } else 3480 wdev = netdev->ieee80211_ptr; 3481 3482 wiphy_lock(&rdev->wiphy); 3483 3484 /* 3485 * end workaround code, by now the rdev is available 3486 * and locked, and wdev may or may not be NULL. 3487 */ 3488 3489 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 3490 result = cfg80211_dev_rename( 3491 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 3492 rtnl_unlock(); 3493 3494 if (result) 3495 goto out; 3496 3497 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3498 struct ieee80211_txq_params txq_params; 3499 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3500 3501 if (!rdev->ops->set_txq_params) { 3502 result = -EOPNOTSUPP; 3503 goto out; 3504 } 3505 3506 if (!netdev) { 3507 result = -EINVAL; 3508 goto out; 3509 } 3510 3511 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3512 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 3513 result = -EINVAL; 3514 goto out; 3515 } 3516 3517 if (!netif_running(netdev)) { 3518 result = -ENETDOWN; 3519 goto out; 3520 } 3521 3522 nla_for_each_nested(nl_txq_params, 3523 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 3524 rem_txq_params) { 3525 result = nla_parse_nested_deprecated(tb, 3526 NL80211_TXQ_ATTR_MAX, 3527 nl_txq_params, 3528 txq_params_policy, 3529 info->extack); 3530 if (result) 3531 goto out; 3532 result = parse_txq_params(tb, &txq_params); 3533 if (result) 3534 goto out; 3535 3536 txq_params.link_id = 3537 nl80211_link_id_or_invalid(info->attrs); 3538 3539 wdev_lock(netdev->ieee80211_ptr); 3540 if (txq_params.link_id >= 0 && 3541 !(netdev->ieee80211_ptr->valid_links & 3542 BIT(txq_params.link_id))) 3543 result = -ENOLINK; 3544 else if (txq_params.link_id >= 0 && 3545 !netdev->ieee80211_ptr->valid_links) 3546 result = -EINVAL; 3547 else 3548 result = rdev_set_txq_params(rdev, netdev, 3549 &txq_params); 3550 wdev_unlock(netdev->ieee80211_ptr); 3551 if (result) 3552 goto out; 3553 } 3554 } 3555 3556 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3557 int link_id = nl80211_link_id_or_invalid(info->attrs); 3558 3559 if (wdev) { 3560 wdev_lock(wdev); 3561 result = __nl80211_set_channel( 3562 rdev, 3563 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 3564 info, link_id); 3565 wdev_unlock(wdev); 3566 } else { 3567 result = __nl80211_set_channel(rdev, netdev, info, link_id); 3568 } 3569 3570 if (result) 3571 goto out; 3572 } 3573 3574 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 3575 struct wireless_dev *txp_wdev = wdev; 3576 enum nl80211_tx_power_setting type; 3577 int idx, mbm = 0; 3578 3579 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3580 txp_wdev = NULL; 3581 3582 if (!rdev->ops->set_tx_power) { 3583 result = -EOPNOTSUPP; 3584 goto out; 3585 } 3586 3587 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3588 type = nla_get_u32(info->attrs[idx]); 3589 3590 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3591 (type != NL80211_TX_POWER_AUTOMATIC)) { 3592 result = -EINVAL; 3593 goto out; 3594 } 3595 3596 if (type != NL80211_TX_POWER_AUTOMATIC) { 3597 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 3598 mbm = nla_get_u32(info->attrs[idx]); 3599 } 3600 3601 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3602 if (result) 3603 goto out; 3604 } 3605 3606 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 3607 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 3608 u32 tx_ant, rx_ant; 3609 3610 if ((!rdev->wiphy.available_antennas_tx && 3611 !rdev->wiphy.available_antennas_rx) || 3612 !rdev->ops->set_antenna) { 3613 result = -EOPNOTSUPP; 3614 goto out; 3615 } 3616 3617 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3618 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 3619 3620 /* reject antenna configurations which don't match the 3621 * available antenna masks, except for the "all" mask */ 3622 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3623 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { 3624 result = -EINVAL; 3625 goto out; 3626 } 3627 3628 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3629 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3630 3631 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3632 if (result) 3633 goto out; 3634 } 3635 3636 changed = 0; 3637 3638 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 3639 retry_short = nla_get_u8( 3640 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 3641 3642 changed |= WIPHY_PARAM_RETRY_SHORT; 3643 } 3644 3645 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 3646 retry_long = nla_get_u8( 3647 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 3648 3649 changed |= WIPHY_PARAM_RETRY_LONG; 3650 } 3651 3652 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3653 frag_threshold = nla_get_u32( 3654 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3655 if (frag_threshold < 256) { 3656 result = -EINVAL; 3657 goto out; 3658 } 3659 3660 if (frag_threshold != (u32) -1) { 3661 /* 3662 * Fragments (apart from the last one) are required to 3663 * have even length. Make the fragmentation code 3664 * simpler by stripping LSB should someone try to use 3665 * odd threshold value. 3666 */ 3667 frag_threshold &= ~0x1; 3668 } 3669 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 3670 } 3671 3672 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 3673 rts_threshold = nla_get_u32( 3674 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 3675 changed |= WIPHY_PARAM_RTS_THRESHOLD; 3676 } 3677 3678 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3679 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3680 result = -EINVAL; 3681 goto out; 3682 } 3683 3684 coverage_class = nla_get_u8( 3685 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 3686 changed |= WIPHY_PARAM_COVERAGE_CLASS; 3687 } 3688 3689 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3690 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { 3691 result = -EOPNOTSUPP; 3692 goto out; 3693 } 3694 3695 changed |= WIPHY_PARAM_DYN_ACK; 3696 } 3697 3698 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3699 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3700 NL80211_EXT_FEATURE_TXQS)) { 3701 result = -EOPNOTSUPP; 3702 goto out; 3703 } 3704 txq_limit = nla_get_u32( 3705 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3706 changed |= WIPHY_PARAM_TXQ_LIMIT; 3707 } 3708 3709 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3710 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3711 NL80211_EXT_FEATURE_TXQS)) { 3712 result = -EOPNOTSUPP; 3713 goto out; 3714 } 3715 txq_memory_limit = nla_get_u32( 3716 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3717 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 3718 } 3719 3720 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3721 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3722 NL80211_EXT_FEATURE_TXQS)) { 3723 result = -EOPNOTSUPP; 3724 goto out; 3725 } 3726 txq_quantum = nla_get_u32( 3727 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3728 changed |= WIPHY_PARAM_TXQ_QUANTUM; 3729 } 3730 3731 if (changed) { 3732 u8 old_retry_short, old_retry_long; 3733 u32 old_frag_threshold, old_rts_threshold; 3734 u8 old_coverage_class; 3735 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3736 3737 if (!rdev->ops->set_wiphy_params) { 3738 result = -EOPNOTSUPP; 3739 goto out; 3740 } 3741 3742 old_retry_short = rdev->wiphy.retry_short; 3743 old_retry_long = rdev->wiphy.retry_long; 3744 old_frag_threshold = rdev->wiphy.frag_threshold; 3745 old_rts_threshold = rdev->wiphy.rts_threshold; 3746 old_coverage_class = rdev->wiphy.coverage_class; 3747 old_txq_limit = rdev->wiphy.txq_limit; 3748 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 3749 old_txq_quantum = rdev->wiphy.txq_quantum; 3750 3751 if (changed & WIPHY_PARAM_RETRY_SHORT) 3752 rdev->wiphy.retry_short = retry_short; 3753 if (changed & WIPHY_PARAM_RETRY_LONG) 3754 rdev->wiphy.retry_long = retry_long; 3755 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3756 rdev->wiphy.frag_threshold = frag_threshold; 3757 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3758 rdev->wiphy.rts_threshold = rts_threshold; 3759 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3760 rdev->wiphy.coverage_class = coverage_class; 3761 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3762 rdev->wiphy.txq_limit = txq_limit; 3763 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3764 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3765 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3766 rdev->wiphy.txq_quantum = txq_quantum; 3767 3768 result = rdev_set_wiphy_params(rdev, changed); 3769 if (result) { 3770 rdev->wiphy.retry_short = old_retry_short; 3771 rdev->wiphy.retry_long = old_retry_long; 3772 rdev->wiphy.frag_threshold = old_frag_threshold; 3773 rdev->wiphy.rts_threshold = old_rts_threshold; 3774 rdev->wiphy.coverage_class = old_coverage_class; 3775 rdev->wiphy.txq_limit = old_txq_limit; 3776 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3777 rdev->wiphy.txq_quantum = old_txq_quantum; 3778 goto out; 3779 } 3780 } 3781 3782 result = 0; 3783 3784 out: 3785 wiphy_unlock(&rdev->wiphy); 3786 return result; 3787 } 3788 3789 int nl80211_send_chandef(struct sk_buff *msg, const struct cfg80211_chan_def *chandef) 3790 { 3791 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3792 return -EINVAL; 3793 3794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3795 chandef->chan->center_freq)) 3796 return -ENOBUFS; 3797 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 3798 chandef->chan->freq_offset)) 3799 return -ENOBUFS; 3800 switch (chandef->width) { 3801 case NL80211_CHAN_WIDTH_20_NOHT: 3802 case NL80211_CHAN_WIDTH_20: 3803 case NL80211_CHAN_WIDTH_40: 3804 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3805 cfg80211_get_chandef_type(chandef))) 3806 return -ENOBUFS; 3807 break; 3808 default: 3809 break; 3810 } 3811 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3812 return -ENOBUFS; 3813 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3814 return -ENOBUFS; 3815 if (chandef->center_freq2 && 3816 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3817 return -ENOBUFS; 3818 return 0; 3819 } 3820 EXPORT_SYMBOL(nl80211_send_chandef); 3821 3822 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3823 struct cfg80211_registered_device *rdev, 3824 struct wireless_dev *wdev, 3825 enum nl80211_commands cmd) 3826 { 3827 struct net_device *dev = wdev->netdev; 3828 void *hdr; 3829 3830 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3831 cmd != NL80211_CMD_DEL_INTERFACE && 3832 cmd != NL80211_CMD_SET_INTERFACE); 3833 3834 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3835 if (!hdr) 3836 return -1; 3837 3838 if (dev && 3839 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3840 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3841 goto nla_put_failure; 3842 3843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3844 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3845 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3846 NL80211_ATTR_PAD) || 3847 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3848 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3849 rdev->devlist_generation ^ 3850 (cfg80211_rdev_list_generation << 2)) || 3851 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3852 goto nla_put_failure; 3853 3854 if (rdev->ops->get_channel && !wdev->valid_links) { 3855 struct cfg80211_chan_def chandef = {}; 3856 int ret; 3857 3858 ret = rdev_get_channel(rdev, wdev, 0, &chandef); 3859 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3860 goto nla_put_failure; 3861 } 3862 3863 if (rdev->ops->get_tx_power) { 3864 int dbm, ret; 3865 3866 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3867 if (ret == 0 && 3868 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3869 DBM_TO_MBM(dbm))) 3870 goto nla_put_failure; 3871 } 3872 3873 wdev_lock(wdev); 3874 switch (wdev->iftype) { 3875 case NL80211_IFTYPE_AP: 3876 case NL80211_IFTYPE_P2P_GO: 3877 if (wdev->u.ap.ssid_len && 3878 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, 3879 wdev->u.ap.ssid)) 3880 goto nla_put_failure_locked; 3881 break; 3882 case NL80211_IFTYPE_STATION: 3883 case NL80211_IFTYPE_P2P_CLIENT: 3884 if (wdev->u.client.ssid_len && 3885 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len, 3886 wdev->u.client.ssid)) 3887 goto nla_put_failure_locked; 3888 break; 3889 case NL80211_IFTYPE_ADHOC: 3890 if (wdev->u.ibss.ssid_len && 3891 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len, 3892 wdev->u.ibss.ssid)) 3893 goto nla_put_failure_locked; 3894 break; 3895 default: 3896 /* nothing */ 3897 break; 3898 } 3899 wdev_unlock(wdev); 3900 3901 if (rdev->ops->get_txq_stats) { 3902 struct cfg80211_txq_stats txqstats = {}; 3903 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3904 3905 if (ret == 0 && 3906 !nl80211_put_txq_stats(msg, &txqstats, 3907 NL80211_ATTR_TXQ_STATS)) 3908 goto nla_put_failure; 3909 } 3910 3911 if (wdev->valid_links) { 3912 unsigned int link_id; 3913 struct nlattr *links = nla_nest_start(msg, 3914 NL80211_ATTR_MLO_LINKS); 3915 3916 if (!links) 3917 goto nla_put_failure; 3918 3919 for_each_valid_link(wdev, link_id) { 3920 struct nlattr *link = nla_nest_start(msg, link_id + 1); 3921 struct cfg80211_chan_def chandef = {}; 3922 int ret; 3923 3924 if (!link) 3925 goto nla_put_failure; 3926 3927 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 3928 goto nla_put_failure; 3929 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 3930 wdev->links[link_id].addr)) 3931 goto nla_put_failure; 3932 3933 ret = rdev_get_channel(rdev, wdev, link_id, &chandef); 3934 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3935 goto nla_put_failure; 3936 3937 nla_nest_end(msg, link); 3938 } 3939 3940 nla_nest_end(msg, links); 3941 } 3942 3943 genlmsg_end(msg, hdr); 3944 return 0; 3945 3946 nla_put_failure_locked: 3947 wdev_unlock(wdev); 3948 nla_put_failure: 3949 genlmsg_cancel(msg, hdr); 3950 return -EMSGSIZE; 3951 } 3952 3953 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3954 { 3955 int wp_idx = 0; 3956 int if_idx = 0; 3957 int wp_start = cb->args[0]; 3958 int if_start = cb->args[1]; 3959 int filter_wiphy = -1; 3960 struct cfg80211_registered_device *rdev; 3961 struct wireless_dev *wdev; 3962 int ret; 3963 3964 rtnl_lock(); 3965 if (!cb->args[2]) { 3966 struct nl80211_dump_wiphy_state state = { 3967 .filter_wiphy = -1, 3968 }; 3969 3970 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3971 if (ret) 3972 goto out_unlock; 3973 3974 filter_wiphy = state.filter_wiphy; 3975 3976 /* 3977 * if filtering, set cb->args[2] to +1 since 0 is the default 3978 * value needed to determine that parsing is necessary. 3979 */ 3980 if (filter_wiphy >= 0) 3981 cb->args[2] = filter_wiphy + 1; 3982 else 3983 cb->args[2] = -1; 3984 } else if (cb->args[2] > 0) { 3985 filter_wiphy = cb->args[2] - 1; 3986 } 3987 3988 list_for_each_entry(rdev, &cfg80211_rdev_list, list) { 3989 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3990 continue; 3991 if (wp_idx < wp_start) { 3992 wp_idx++; 3993 continue; 3994 } 3995 3996 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3997 continue; 3998 3999 if_idx = 0; 4000 4001 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 4002 if (if_idx < if_start) { 4003 if_idx++; 4004 continue; 4005 } 4006 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 4007 cb->nlh->nlmsg_seq, NLM_F_MULTI, 4008 rdev, wdev, 4009 NL80211_CMD_NEW_INTERFACE) < 0) { 4010 goto out; 4011 } 4012 if_idx++; 4013 } 4014 4015 wp_idx++; 4016 } 4017 out: 4018 cb->args[0] = wp_idx; 4019 cb->args[1] = if_idx; 4020 4021 ret = skb->len; 4022 out_unlock: 4023 rtnl_unlock(); 4024 4025 return ret; 4026 } 4027 4028 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 4029 { 4030 struct sk_buff *msg; 4031 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4032 struct wireless_dev *wdev = info->user_ptr[1]; 4033 4034 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4035 if (!msg) 4036 return -ENOMEM; 4037 4038 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4039 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4040 nlmsg_free(msg); 4041 return -ENOBUFS; 4042 } 4043 4044 return genlmsg_reply(msg, info); 4045 } 4046 4047 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 4048 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 4049 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 4050 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 4051 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 4052 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 4053 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 4054 }; 4055 4056 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 4057 { 4058 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 4059 int flag; 4060 4061 *mntrflags = 0; 4062 4063 if (!nla) 4064 return -EINVAL; 4065 4066 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 4067 return -EINVAL; 4068 4069 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 4070 if (flags[flag]) 4071 *mntrflags |= (1<<flag); 4072 4073 *mntrflags |= MONITOR_FLAG_CHANGED; 4074 4075 return 0; 4076 } 4077 4078 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 4079 enum nl80211_iftype type, 4080 struct genl_info *info, 4081 struct vif_params *params) 4082 { 4083 bool change = false; 4084 int err; 4085 4086 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 4087 if (type != NL80211_IFTYPE_MONITOR) 4088 return -EINVAL; 4089 4090 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 4091 ¶ms->flags); 4092 if (err) 4093 return err; 4094 4095 change = true; 4096 } 4097 4098 if (params->flags & MONITOR_FLAG_ACTIVE && 4099 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 4100 return -EOPNOTSUPP; 4101 4102 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 4103 const u8 *mumimo_groups; 4104 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4105 4106 if (type != NL80211_IFTYPE_MONITOR) 4107 return -EINVAL; 4108 4109 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4110 return -EOPNOTSUPP; 4111 4112 mumimo_groups = 4113 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 4114 4115 /* bits 0 and 63 are reserved and must be zero */ 4116 if ((mumimo_groups[0] & BIT(0)) || 4117 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 4118 return -EINVAL; 4119 4120 params->vht_mumimo_groups = mumimo_groups; 4121 change = true; 4122 } 4123 4124 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 4125 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4126 4127 if (type != NL80211_IFTYPE_MONITOR) 4128 return -EINVAL; 4129 4130 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4131 return -EOPNOTSUPP; 4132 4133 params->vht_mumimo_follow_addr = 4134 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 4135 change = true; 4136 } 4137 4138 return change ? 1 : 0; 4139 } 4140 4141 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 4142 struct net_device *netdev, u8 use_4addr, 4143 enum nl80211_iftype iftype) 4144 { 4145 if (!use_4addr) { 4146 if (netdev && netif_is_bridge_port(netdev)) 4147 return -EBUSY; 4148 return 0; 4149 } 4150 4151 switch (iftype) { 4152 case NL80211_IFTYPE_AP_VLAN: 4153 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 4154 return 0; 4155 break; 4156 case NL80211_IFTYPE_STATION: 4157 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 4158 return 0; 4159 break; 4160 default: 4161 break; 4162 } 4163 4164 return -EOPNOTSUPP; 4165 } 4166 4167 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 4168 { 4169 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4170 struct vif_params params; 4171 int err; 4172 enum nl80211_iftype otype, ntype; 4173 struct net_device *dev = info->user_ptr[1]; 4174 bool change = false; 4175 4176 memset(¶ms, 0, sizeof(params)); 4177 4178 otype = ntype = dev->ieee80211_ptr->iftype; 4179 4180 if (info->attrs[NL80211_ATTR_IFTYPE]) { 4181 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4182 if (otype != ntype) 4183 change = true; 4184 } 4185 4186 if (info->attrs[NL80211_ATTR_MESH_ID]) { 4187 struct wireless_dev *wdev = dev->ieee80211_ptr; 4188 4189 if (ntype != NL80211_IFTYPE_MESH_POINT) 4190 return -EINVAL; 4191 if (netif_running(dev)) 4192 return -EBUSY; 4193 4194 wdev_lock(wdev); 4195 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4196 IEEE80211_MAX_MESH_ID_LEN); 4197 wdev->u.mesh.id_up_len = 4198 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4199 memcpy(wdev->u.mesh.id, 4200 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4201 wdev->u.mesh.id_up_len); 4202 wdev_unlock(wdev); 4203 } 4204 4205 if (info->attrs[NL80211_ATTR_4ADDR]) { 4206 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4207 change = true; 4208 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 4209 if (err) 4210 return err; 4211 } else { 4212 params.use_4addr = -1; 4213 } 4214 4215 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 4216 if (err < 0) 4217 return err; 4218 if (err > 0) 4219 change = true; 4220 4221 if (change) 4222 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 4223 else 4224 err = 0; 4225 4226 if (!err && params.use_4addr != -1) 4227 dev->ieee80211_ptr->use_4addr = params.use_4addr; 4228 4229 if (change && !err) { 4230 struct wireless_dev *wdev = dev->ieee80211_ptr; 4231 4232 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 4233 } 4234 4235 return err; 4236 } 4237 4238 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4239 { 4240 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4241 struct vif_params params; 4242 struct wireless_dev *wdev; 4243 struct sk_buff *msg; 4244 int err; 4245 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 4246 4247 memset(¶ms, 0, sizeof(params)); 4248 4249 if (!info->attrs[NL80211_ATTR_IFNAME]) 4250 return -EINVAL; 4251 4252 if (info->attrs[NL80211_ATTR_IFTYPE]) 4253 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4254 4255 if (!rdev->ops->add_virtual_intf) 4256 return -EOPNOTSUPP; 4257 4258 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 4259 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 4260 info->attrs[NL80211_ATTR_MAC]) { 4261 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 4262 ETH_ALEN); 4263 if (!is_valid_ether_addr(params.macaddr)) 4264 return -EADDRNOTAVAIL; 4265 } 4266 4267 if (info->attrs[NL80211_ATTR_4ADDR]) { 4268 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4269 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 4270 if (err) 4271 return err; 4272 } 4273 4274 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) 4275 return -EOPNOTSUPP; 4276 4277 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 4278 if (err < 0) 4279 return err; 4280 4281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4282 if (!msg) 4283 return -ENOMEM; 4284 4285 wdev = rdev_add_virtual_intf(rdev, 4286 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 4287 NET_NAME_USER, type, ¶ms); 4288 if (WARN_ON(!wdev)) { 4289 nlmsg_free(msg); 4290 return -EPROTO; 4291 } else if (IS_ERR(wdev)) { 4292 nlmsg_free(msg); 4293 return PTR_ERR(wdev); 4294 } 4295 4296 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 4297 wdev->owner_nlportid = info->snd_portid; 4298 4299 switch (type) { 4300 case NL80211_IFTYPE_MESH_POINT: 4301 if (!info->attrs[NL80211_ATTR_MESH_ID]) 4302 break; 4303 wdev_lock(wdev); 4304 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4305 IEEE80211_MAX_MESH_ID_LEN); 4306 wdev->u.mesh.id_up_len = 4307 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4308 memcpy(wdev->u.mesh.id, 4309 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4310 wdev->u.mesh.id_up_len); 4311 wdev_unlock(wdev); 4312 break; 4313 case NL80211_IFTYPE_NAN: 4314 case NL80211_IFTYPE_P2P_DEVICE: 4315 /* 4316 * P2P Device and NAN do not have a netdev, so don't go 4317 * through the netdev notifier and must be added here 4318 */ 4319 cfg80211_init_wdev(wdev); 4320 cfg80211_register_wdev(rdev, wdev); 4321 break; 4322 default: 4323 break; 4324 } 4325 4326 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4327 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4328 nlmsg_free(msg); 4329 return -ENOBUFS; 4330 } 4331 4332 return genlmsg_reply(msg, info); 4333 } 4334 4335 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4336 { 4337 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4338 int ret; 4339 4340 /* to avoid failing a new interface creation due to pending removal */ 4341 cfg80211_destroy_ifaces(rdev); 4342 4343 wiphy_lock(&rdev->wiphy); 4344 ret = _nl80211_new_interface(skb, info); 4345 wiphy_unlock(&rdev->wiphy); 4346 4347 return ret; 4348 } 4349 4350 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 4351 { 4352 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4353 struct wireless_dev *wdev = info->user_ptr[1]; 4354 4355 if (!rdev->ops->del_virtual_intf) 4356 return -EOPNOTSUPP; 4357 4358 /* 4359 * We hold RTNL, so this is safe, without RTNL opencount cannot 4360 * reach 0, and thus the rdev cannot be deleted. 4361 * 4362 * We need to do it for the dev_close(), since that will call 4363 * the netdev notifiers, and we need to acquire the mutex there 4364 * but don't know if we get there from here or from some other 4365 * place (e.g. "ip link set ... down"). 4366 */ 4367 mutex_unlock(&rdev->wiphy.mtx); 4368 4369 /* 4370 * If we remove a wireless device without a netdev then clear 4371 * user_ptr[1] so that nl80211_post_doit won't dereference it 4372 * to check if it needs to do dev_put(). Otherwise it crashes 4373 * since the wdev has been freed, unlike with a netdev where 4374 * we need the dev_put() for the netdev to really be freed. 4375 */ 4376 if (!wdev->netdev) 4377 info->user_ptr[1] = NULL; 4378 else 4379 dev_close(wdev->netdev); 4380 4381 mutex_lock(&rdev->wiphy.mtx); 4382 4383 return cfg80211_remove_virtual_intf(rdev, wdev); 4384 } 4385 4386 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 4387 { 4388 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4389 struct net_device *dev = info->user_ptr[1]; 4390 u16 noack_map; 4391 4392 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 4393 return -EINVAL; 4394 4395 if (!rdev->ops->set_noack_map) 4396 return -EOPNOTSUPP; 4397 4398 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 4399 4400 return rdev_set_noack_map(rdev, dev, noack_map); 4401 } 4402 4403 static int nl80211_validate_key_link_id(struct genl_info *info, 4404 struct wireless_dev *wdev, 4405 int link_id, bool pairwise) 4406 { 4407 if (pairwise) { 4408 if (link_id != -1) { 4409 GENL_SET_ERR_MSG(info, 4410 "link ID not allowed for pairwise key"); 4411 return -EINVAL; 4412 } 4413 4414 return 0; 4415 } 4416 4417 if (wdev->valid_links) { 4418 if (link_id == -1) { 4419 GENL_SET_ERR_MSG(info, 4420 "link ID must for MLO group key"); 4421 return -EINVAL; 4422 } 4423 if (!(wdev->valid_links & BIT(link_id))) { 4424 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key"); 4425 return -EINVAL; 4426 } 4427 } else if (link_id != -1) { 4428 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key"); 4429 return -EINVAL; 4430 } 4431 4432 return 0; 4433 } 4434 4435 struct get_key_cookie { 4436 struct sk_buff *msg; 4437 int error; 4438 int idx; 4439 }; 4440 4441 static void get_key_callback(void *c, struct key_params *params) 4442 { 4443 struct nlattr *key; 4444 struct get_key_cookie *cookie = c; 4445 4446 if ((params->key && 4447 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 4448 params->key_len, params->key)) || 4449 (params->seq && 4450 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 4451 params->seq_len, params->seq)) || 4452 (params->cipher && 4453 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 4454 params->cipher))) 4455 goto nla_put_failure; 4456 4457 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 4458 if (!key) 4459 goto nla_put_failure; 4460 4461 if ((params->key && 4462 nla_put(cookie->msg, NL80211_KEY_DATA, 4463 params->key_len, params->key)) || 4464 (params->seq && 4465 nla_put(cookie->msg, NL80211_KEY_SEQ, 4466 params->seq_len, params->seq)) || 4467 (params->cipher && 4468 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 4469 params->cipher))) 4470 goto nla_put_failure; 4471 4472 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 4473 goto nla_put_failure; 4474 4475 nla_nest_end(cookie->msg, key); 4476 4477 return; 4478 nla_put_failure: 4479 cookie->error = 1; 4480 } 4481 4482 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 4483 { 4484 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4485 int err; 4486 struct net_device *dev = info->user_ptr[1]; 4487 u8 key_idx = 0; 4488 const u8 *mac_addr = NULL; 4489 bool pairwise; 4490 struct get_key_cookie cookie = { 4491 .error = 0, 4492 }; 4493 void *hdr; 4494 struct sk_buff *msg; 4495 bool bigtk_support = false; 4496 int link_id = nl80211_link_id_or_invalid(info->attrs); 4497 struct wireless_dev *wdev = dev->ieee80211_ptr; 4498 4499 if (wiphy_ext_feature_isset(&rdev->wiphy, 4500 NL80211_EXT_FEATURE_BEACON_PROTECTION)) 4501 bigtk_support = true; 4502 4503 if ((wdev->iftype == NL80211_IFTYPE_STATION || 4504 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && 4505 wiphy_ext_feature_isset(&rdev->wiphy, 4506 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) 4507 bigtk_support = true; 4508 4509 if (info->attrs[NL80211_ATTR_KEY_IDX]) { 4510 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 4511 4512 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { 4513 GENL_SET_ERR_MSG(info, "BIGTK not supported"); 4514 return -EINVAL; 4515 } 4516 } 4517 4518 if (info->attrs[NL80211_ATTR_MAC]) 4519 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4520 4521 pairwise = !!mac_addr; 4522 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 4523 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 4524 4525 if (kt != NL80211_KEYTYPE_GROUP && 4526 kt != NL80211_KEYTYPE_PAIRWISE) 4527 return -EINVAL; 4528 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 4529 } 4530 4531 if (!rdev->ops->get_key) 4532 return -EOPNOTSUPP; 4533 4534 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4535 return -ENOENT; 4536 4537 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4538 if (!msg) 4539 return -ENOMEM; 4540 4541 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 4542 NL80211_CMD_NEW_KEY); 4543 if (!hdr) 4544 goto nla_put_failure; 4545 4546 cookie.msg = msg; 4547 cookie.idx = key_idx; 4548 4549 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 4550 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 4551 goto nla_put_failure; 4552 if (mac_addr && 4553 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 4554 goto nla_put_failure; 4555 4556 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise); 4557 if (err) 4558 goto free_msg; 4559 4560 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr, 4561 &cookie, get_key_callback); 4562 4563 if (err) 4564 goto free_msg; 4565 4566 if (cookie.error) 4567 goto nla_put_failure; 4568 4569 genlmsg_end(msg, hdr); 4570 return genlmsg_reply(msg, info); 4571 4572 nla_put_failure: 4573 err = -ENOBUFS; 4574 free_msg: 4575 nlmsg_free(msg); 4576 return err; 4577 } 4578 4579 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 4580 { 4581 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4582 struct key_parse key; 4583 int err; 4584 struct net_device *dev = info->user_ptr[1]; 4585 int link_id = nl80211_link_id_or_invalid(info->attrs); 4586 struct wireless_dev *wdev = dev->ieee80211_ptr; 4587 4588 err = nl80211_parse_key(info, &key); 4589 if (err) 4590 return err; 4591 4592 if (key.idx < 0) 4593 return -EINVAL; 4594 4595 /* Only support setting default key and 4596 * Extended Key ID action NL80211_KEY_SET_TX. 4597 */ 4598 if (!key.def && !key.defmgmt && !key.defbeacon && 4599 !(key.p.mode == NL80211_KEY_SET_TX)) 4600 return -EINVAL; 4601 4602 wdev_lock(wdev); 4603 4604 if (key.def) { 4605 if (!rdev->ops->set_default_key) { 4606 err = -EOPNOTSUPP; 4607 goto out; 4608 } 4609 4610 err = nl80211_key_allowed(wdev); 4611 if (err) 4612 goto out; 4613 4614 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4615 if (err) 4616 goto out; 4617 4618 err = rdev_set_default_key(rdev, dev, link_id, key.idx, 4619 key.def_uni, key.def_multi); 4620 4621 if (err) 4622 goto out; 4623 4624 #ifdef CONFIG_CFG80211_WEXT 4625 wdev->wext.default_key = key.idx; 4626 #endif 4627 } else if (key.defmgmt) { 4628 if (key.def_uni || !key.def_multi) { 4629 err = -EINVAL; 4630 goto out; 4631 } 4632 4633 if (!rdev->ops->set_default_mgmt_key) { 4634 err = -EOPNOTSUPP; 4635 goto out; 4636 } 4637 4638 err = nl80211_key_allowed(wdev); 4639 if (err) 4640 goto out; 4641 4642 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4643 if (err) 4644 goto out; 4645 4646 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx); 4647 if (err) 4648 goto out; 4649 4650 #ifdef CONFIG_CFG80211_WEXT 4651 wdev->wext.default_mgmt_key = key.idx; 4652 #endif 4653 } else if (key.defbeacon) { 4654 if (key.def_uni || !key.def_multi) { 4655 err = -EINVAL; 4656 goto out; 4657 } 4658 4659 if (!rdev->ops->set_default_beacon_key) { 4660 err = -EOPNOTSUPP; 4661 goto out; 4662 } 4663 4664 err = nl80211_key_allowed(wdev); 4665 if (err) 4666 goto out; 4667 4668 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4669 if (err) 4670 goto out; 4671 4672 err = rdev_set_default_beacon_key(rdev, dev, link_id, key.idx); 4673 if (err) 4674 goto out; 4675 } else if (key.p.mode == NL80211_KEY_SET_TX && 4676 wiphy_ext_feature_isset(&rdev->wiphy, 4677 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 4678 u8 *mac_addr = NULL; 4679 4680 if (info->attrs[NL80211_ATTR_MAC]) 4681 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4682 4683 if (!mac_addr || key.idx < 0 || key.idx > 1) { 4684 err = -EINVAL; 4685 goto out; 4686 } 4687 4688 err = nl80211_validate_key_link_id(info, wdev, link_id, true); 4689 if (err) 4690 goto out; 4691 4692 err = rdev_add_key(rdev, dev, link_id, key.idx, 4693 NL80211_KEYTYPE_PAIRWISE, 4694 mac_addr, &key.p); 4695 } else { 4696 err = -EINVAL; 4697 } 4698 out: 4699 wdev_unlock(wdev); 4700 4701 return err; 4702 } 4703 4704 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 4705 { 4706 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4707 int err; 4708 struct net_device *dev = info->user_ptr[1]; 4709 struct key_parse key; 4710 const u8 *mac_addr = NULL; 4711 int link_id = nl80211_link_id_or_invalid(info->attrs); 4712 struct wireless_dev *wdev = dev->ieee80211_ptr; 4713 4714 err = nl80211_parse_key(info, &key); 4715 if (err) 4716 return err; 4717 4718 if (!key.p.key) { 4719 GENL_SET_ERR_MSG(info, "no key"); 4720 return -EINVAL; 4721 } 4722 4723 if (info->attrs[NL80211_ATTR_MAC]) 4724 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4725 4726 if (key.type == -1) { 4727 if (mac_addr) 4728 key.type = NL80211_KEYTYPE_PAIRWISE; 4729 else 4730 key.type = NL80211_KEYTYPE_GROUP; 4731 } 4732 4733 /* for now */ 4734 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4735 key.type != NL80211_KEYTYPE_GROUP) { 4736 GENL_SET_ERR_MSG(info, "key type not pairwise or group"); 4737 return -EINVAL; 4738 } 4739 4740 if (key.type == NL80211_KEYTYPE_GROUP && 4741 info->attrs[NL80211_ATTR_VLAN_ID]) 4742 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 4743 4744 if (!rdev->ops->add_key) 4745 return -EOPNOTSUPP; 4746 4747 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 4748 key.type == NL80211_KEYTYPE_PAIRWISE, 4749 mac_addr)) { 4750 GENL_SET_ERR_MSG(info, "key setting validation failed"); 4751 return -EINVAL; 4752 } 4753 4754 wdev_lock(wdev); 4755 err = nl80211_key_allowed(wdev); 4756 if (err) 4757 GENL_SET_ERR_MSG(info, "key not allowed"); 4758 4759 if (!err) 4760 err = nl80211_validate_key_link_id(info, wdev, link_id, 4761 key.type == NL80211_KEYTYPE_PAIRWISE); 4762 4763 if (!err) { 4764 err = rdev_add_key(rdev, dev, link_id, key.idx, 4765 key.type == NL80211_KEYTYPE_PAIRWISE, 4766 mac_addr, &key.p); 4767 if (err) 4768 GENL_SET_ERR_MSG(info, "key addition failed"); 4769 } 4770 wdev_unlock(wdev); 4771 4772 return err; 4773 } 4774 4775 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 4776 { 4777 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4778 int err; 4779 struct net_device *dev = info->user_ptr[1]; 4780 u8 *mac_addr = NULL; 4781 struct key_parse key; 4782 int link_id = nl80211_link_id_or_invalid(info->attrs); 4783 struct wireless_dev *wdev = dev->ieee80211_ptr; 4784 4785 err = nl80211_parse_key(info, &key); 4786 if (err) 4787 return err; 4788 4789 if (info->attrs[NL80211_ATTR_MAC]) 4790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4791 4792 if (key.type == -1) { 4793 if (mac_addr) 4794 key.type = NL80211_KEYTYPE_PAIRWISE; 4795 else 4796 key.type = NL80211_KEYTYPE_GROUP; 4797 } 4798 4799 /* for now */ 4800 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4801 key.type != NL80211_KEYTYPE_GROUP) 4802 return -EINVAL; 4803 4804 if (!cfg80211_valid_key_idx(rdev, key.idx, 4805 key.type == NL80211_KEYTYPE_PAIRWISE)) 4806 return -EINVAL; 4807 4808 if (!rdev->ops->del_key) 4809 return -EOPNOTSUPP; 4810 4811 wdev_lock(wdev); 4812 err = nl80211_key_allowed(wdev); 4813 4814 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 4815 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4816 err = -ENOENT; 4817 4818 if (!err) 4819 err = nl80211_validate_key_link_id(info, wdev, link_id, 4820 key.type == NL80211_KEYTYPE_PAIRWISE); 4821 4822 if (!err) 4823 err = rdev_del_key(rdev, dev, link_id, key.idx, 4824 key.type == NL80211_KEYTYPE_PAIRWISE, 4825 mac_addr); 4826 4827 #ifdef CONFIG_CFG80211_WEXT 4828 if (!err) { 4829 if (key.idx == wdev->wext.default_key) 4830 wdev->wext.default_key = -1; 4831 else if (key.idx == wdev->wext.default_mgmt_key) 4832 wdev->wext.default_mgmt_key = -1; 4833 } 4834 #endif 4835 wdev_unlock(wdev); 4836 4837 return err; 4838 } 4839 4840 /* This function returns an error or the number of nested attributes */ 4841 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 4842 { 4843 struct nlattr *attr; 4844 int n_entries = 0, tmp; 4845 4846 nla_for_each_nested(attr, nl_attr, tmp) { 4847 if (nla_len(attr) != ETH_ALEN) 4848 return -EINVAL; 4849 4850 n_entries++; 4851 } 4852 4853 return n_entries; 4854 } 4855 4856 /* 4857 * This function parses ACL information and allocates memory for ACL data. 4858 * On successful return, the calling function is responsible to free the 4859 * ACL buffer returned by this function. 4860 */ 4861 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 4862 struct genl_info *info) 4863 { 4864 enum nl80211_acl_policy acl_policy; 4865 struct nlattr *attr; 4866 struct cfg80211_acl_data *acl; 4867 int i = 0, n_entries, tmp; 4868 4869 if (!wiphy->max_acl_mac_addrs) 4870 return ERR_PTR(-EOPNOTSUPP); 4871 4872 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 4873 return ERR_PTR(-EINVAL); 4874 4875 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 4876 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 4877 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 4878 return ERR_PTR(-EINVAL); 4879 4880 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 4881 return ERR_PTR(-EINVAL); 4882 4883 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 4884 if (n_entries < 0) 4885 return ERR_PTR(n_entries); 4886 4887 if (n_entries > wiphy->max_acl_mac_addrs) 4888 return ERR_PTR(-ENOTSUPP); 4889 4890 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 4891 if (!acl) 4892 return ERR_PTR(-ENOMEM); 4893 acl->n_acl_entries = n_entries; 4894 4895 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 4896 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 4897 i++; 4898 } 4899 acl->acl_policy = acl_policy; 4900 4901 return acl; 4902 } 4903 4904 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 4905 { 4906 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4907 struct net_device *dev = info->user_ptr[1]; 4908 struct cfg80211_acl_data *acl; 4909 int err; 4910 4911 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4912 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4913 return -EOPNOTSUPP; 4914 4915 if (!dev->ieee80211_ptr->links[0].ap.beacon_interval) 4916 return -EINVAL; 4917 4918 acl = parse_acl_data(&rdev->wiphy, info); 4919 if (IS_ERR(acl)) 4920 return PTR_ERR(acl); 4921 4922 err = rdev_set_mac_acl(rdev, dev, acl); 4923 4924 kfree(acl); 4925 4926 return err; 4927 } 4928 4929 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4930 u8 *rates, u8 rates_len) 4931 { 4932 u8 i; 4933 u32 mask = 0; 4934 4935 for (i = 0; i < rates_len; i++) { 4936 int rate = (rates[i] & 0x7f) * 5; 4937 int ridx; 4938 4939 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4940 struct ieee80211_rate *srate = 4941 &sband->bitrates[ridx]; 4942 if (rate == srate->bitrate) { 4943 mask |= 1 << ridx; 4944 break; 4945 } 4946 } 4947 if (ridx == sband->n_bitrates) 4948 return 0; /* rate not found */ 4949 } 4950 4951 return mask; 4952 } 4953 4954 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4955 u8 *rates, u8 rates_len, 4956 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4957 { 4958 u8 i; 4959 4960 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4961 4962 for (i = 0; i < rates_len; i++) { 4963 int ridx, rbit; 4964 4965 ridx = rates[i] / 8; 4966 rbit = BIT(rates[i] % 8); 4967 4968 /* check validity */ 4969 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4970 return false; 4971 4972 /* check availability */ 4973 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4974 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4975 mcs[ridx] |= rbit; 4976 else 4977 return false; 4978 } 4979 4980 return true; 4981 } 4982 4983 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4984 { 4985 u16 mcs_mask = 0; 4986 4987 switch (vht_mcs_map) { 4988 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4989 break; 4990 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4991 mcs_mask = 0x00FF; 4992 break; 4993 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4994 mcs_mask = 0x01FF; 4995 break; 4996 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4997 mcs_mask = 0x03FF; 4998 break; 4999 default: 5000 break; 5001 } 5002 5003 return mcs_mask; 5004 } 5005 5006 static void vht_build_mcs_mask(u16 vht_mcs_map, 5007 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 5008 { 5009 u8 nss; 5010 5011 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 5012 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 5013 vht_mcs_map >>= 2; 5014 } 5015 } 5016 5017 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 5018 struct nl80211_txrate_vht *txrate, 5019 u16 mcs[NL80211_VHT_NSS_MAX]) 5020 { 5021 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 5022 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 5023 u8 i; 5024 5025 if (!sband->vht_cap.vht_supported) 5026 return false; 5027 5028 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 5029 5030 /* Build vht_mcs_mask from VHT capabilities */ 5031 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 5032 5033 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 5034 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 5035 mcs[i] = txrate->mcs[i]; 5036 else 5037 return false; 5038 } 5039 5040 return true; 5041 } 5042 5043 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) 5044 { 5045 switch (he_mcs_map) { 5046 case IEEE80211_HE_MCS_NOT_SUPPORTED: 5047 return 0; 5048 case IEEE80211_HE_MCS_SUPPORT_0_7: 5049 return 0x00FF; 5050 case IEEE80211_HE_MCS_SUPPORT_0_9: 5051 return 0x03FF; 5052 case IEEE80211_HE_MCS_SUPPORT_0_11: 5053 return 0xFFF; 5054 default: 5055 break; 5056 } 5057 return 0; 5058 } 5059 5060 static void he_build_mcs_mask(u16 he_mcs_map, 5061 u16 he_mcs_mask[NL80211_HE_NSS_MAX]) 5062 { 5063 u8 nss; 5064 5065 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { 5066 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); 5067 he_mcs_map >>= 2; 5068 } 5069 } 5070 5071 static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id, 5072 const struct ieee80211_sta_he_cap *he_cap) 5073 { 5074 struct net_device *dev = info->user_ptr[1]; 5075 struct wireless_dev *wdev = dev->ieee80211_ptr; 5076 struct cfg80211_chan_def *chandef; 5077 __le16 tx_mcs; 5078 5079 chandef = wdev_chandef(wdev, link_id); 5080 if (!chandef) { 5081 /* 5082 * This is probably broken, but we never maintained 5083 * a chandef in these cases, so it always was. 5084 */ 5085 return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); 5086 } 5087 5088 switch (chandef->width) { 5089 case NL80211_CHAN_WIDTH_80P80: 5090 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; 5091 break; 5092 case NL80211_CHAN_WIDTH_160: 5093 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; 5094 break; 5095 default: 5096 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; 5097 break; 5098 } 5099 5100 return le16_to_cpu(tx_mcs); 5101 } 5102 5103 static bool he_set_mcs_mask(struct genl_info *info, 5104 struct wireless_dev *wdev, 5105 struct ieee80211_supported_band *sband, 5106 struct nl80211_txrate_he *txrate, 5107 u16 mcs[NL80211_HE_NSS_MAX], 5108 unsigned int link_id) 5109 { 5110 const struct ieee80211_sta_he_cap *he_cap; 5111 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; 5112 u16 tx_mcs_map = 0; 5113 u8 i; 5114 5115 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5116 if (!he_cap) 5117 return false; 5118 5119 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); 5120 5121 tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5122 5123 /* Build he_mcs_mask from HE capabilities */ 5124 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 5125 5126 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5127 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 5128 mcs[i] = txrate->mcs[i]; 5129 else 5130 return false; 5131 } 5132 5133 return true; 5134 } 5135 5136 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 5137 struct nlattr *attrs[], 5138 enum nl80211_attrs attr, 5139 struct cfg80211_bitrate_mask *mask, 5140 struct net_device *dev, 5141 bool default_all_enabled, 5142 unsigned int link_id) 5143 { 5144 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 5145 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5146 struct wireless_dev *wdev = dev->ieee80211_ptr; 5147 int rem, i; 5148 struct nlattr *tx_rates; 5149 struct ieee80211_supported_band *sband; 5150 u16 vht_tx_mcs_map, he_tx_mcs_map; 5151 5152 memset(mask, 0, sizeof(*mask)); 5153 /* Default to all rates enabled */ 5154 for (i = 0; i < NUM_NL80211_BANDS; i++) { 5155 const struct ieee80211_sta_he_cap *he_cap; 5156 5157 if (!default_all_enabled) 5158 break; 5159 5160 sband = rdev->wiphy.bands[i]; 5161 5162 if (!sband) 5163 continue; 5164 5165 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 5166 memcpy(mask->control[i].ht_mcs, 5167 sband->ht_cap.mcs.rx_mask, 5168 sizeof(mask->control[i].ht_mcs)); 5169 5170 if (sband->vht_cap.vht_supported) { 5171 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 5172 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 5173 } 5174 5175 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5176 if (!he_cap) 5177 continue; 5178 5179 he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5180 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); 5181 5182 mask->control[i].he_gi = 0xFF; 5183 mask->control[i].he_ltf = 0xFF; 5184 } 5185 5186 /* if no rates are given set it back to the defaults */ 5187 if (!attrs[attr]) 5188 goto out; 5189 5190 /* The nested attribute uses enum nl80211_band as the index. This maps 5191 * directly to the enum nl80211_band values used in cfg80211. 5192 */ 5193 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 5194 nla_for_each_nested(tx_rates, attrs[attr], rem) { 5195 enum nl80211_band band = nla_type(tx_rates); 5196 int err; 5197 5198 if (band < 0 || band >= NUM_NL80211_BANDS) 5199 return -EINVAL; 5200 sband = rdev->wiphy.bands[band]; 5201 if (sband == NULL) 5202 return -EINVAL; 5203 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 5204 tx_rates, 5205 nl80211_txattr_policy, 5206 info->extack); 5207 if (err) 5208 return err; 5209 if (tb[NL80211_TXRATE_LEGACY]) { 5210 mask->control[band].legacy = rateset_to_mask( 5211 sband, 5212 nla_data(tb[NL80211_TXRATE_LEGACY]), 5213 nla_len(tb[NL80211_TXRATE_LEGACY])); 5214 if ((mask->control[band].legacy == 0) && 5215 nla_len(tb[NL80211_TXRATE_LEGACY])) 5216 return -EINVAL; 5217 } 5218 if (tb[NL80211_TXRATE_HT]) { 5219 if (!ht_rateset_to_mask( 5220 sband, 5221 nla_data(tb[NL80211_TXRATE_HT]), 5222 nla_len(tb[NL80211_TXRATE_HT]), 5223 mask->control[band].ht_mcs)) 5224 return -EINVAL; 5225 } 5226 5227 if (tb[NL80211_TXRATE_VHT]) { 5228 if (!vht_set_mcs_mask( 5229 sband, 5230 nla_data(tb[NL80211_TXRATE_VHT]), 5231 mask->control[band].vht_mcs)) 5232 return -EINVAL; 5233 } 5234 5235 if (tb[NL80211_TXRATE_GI]) { 5236 mask->control[band].gi = 5237 nla_get_u8(tb[NL80211_TXRATE_GI]); 5238 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 5239 return -EINVAL; 5240 } 5241 if (tb[NL80211_TXRATE_HE] && 5242 !he_set_mcs_mask(info, wdev, sband, 5243 nla_data(tb[NL80211_TXRATE_HE]), 5244 mask->control[band].he_mcs, 5245 link_id)) 5246 return -EINVAL; 5247 5248 if (tb[NL80211_TXRATE_HE_GI]) 5249 mask->control[band].he_gi = 5250 nla_get_u8(tb[NL80211_TXRATE_HE_GI]); 5251 if (tb[NL80211_TXRATE_HE_LTF]) 5252 mask->control[band].he_ltf = 5253 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); 5254 5255 if (mask->control[band].legacy == 0) { 5256 /* don't allow empty legacy rates if HT, VHT or HE 5257 * are not even supported. 5258 */ 5259 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 5260 rdev->wiphy.bands[band]->vht_cap.vht_supported || 5261 ieee80211_get_he_iftype_cap(sband, wdev->iftype))) 5262 return -EINVAL; 5263 5264 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 5265 if (mask->control[band].ht_mcs[i]) 5266 goto out; 5267 5268 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 5269 if (mask->control[band].vht_mcs[i]) 5270 goto out; 5271 5272 for (i = 0; i < NL80211_HE_NSS_MAX; i++) 5273 if (mask->control[band].he_mcs[i]) 5274 goto out; 5275 5276 /* legacy and mcs rates may not be both empty */ 5277 return -EINVAL; 5278 } 5279 } 5280 5281 out: 5282 return 0; 5283 } 5284 5285 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 5286 enum nl80211_band band, 5287 struct cfg80211_bitrate_mask *beacon_rate) 5288 { 5289 u32 count_ht, count_vht, count_he, i; 5290 u32 rate = beacon_rate->control[band].legacy; 5291 5292 /* Allow only one rate */ 5293 if (hweight32(rate) > 1) 5294 return -EINVAL; 5295 5296 count_ht = 0; 5297 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 5298 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 5299 return -EINVAL; 5300 } else if (beacon_rate->control[band].ht_mcs[i]) { 5301 count_ht++; 5302 if (count_ht > 1) 5303 return -EINVAL; 5304 } 5305 if (count_ht && rate) 5306 return -EINVAL; 5307 } 5308 5309 count_vht = 0; 5310 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 5311 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 5312 return -EINVAL; 5313 } else if (beacon_rate->control[band].vht_mcs[i]) { 5314 count_vht++; 5315 if (count_vht > 1) 5316 return -EINVAL; 5317 } 5318 if (count_vht && rate) 5319 return -EINVAL; 5320 } 5321 5322 count_he = 0; 5323 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5324 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { 5325 return -EINVAL; 5326 } else if (beacon_rate->control[band].he_mcs[i]) { 5327 count_he++; 5328 if (count_he > 1) 5329 return -EINVAL; 5330 } 5331 if (count_he && rate) 5332 return -EINVAL; 5333 } 5334 5335 if ((count_ht && count_vht && count_he) || 5336 (!rate && !count_ht && !count_vht && !count_he)) 5337 return -EINVAL; 5338 5339 if (rate && 5340 !wiphy_ext_feature_isset(&rdev->wiphy, 5341 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 5342 return -EINVAL; 5343 if (count_ht && 5344 !wiphy_ext_feature_isset(&rdev->wiphy, 5345 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 5346 return -EINVAL; 5347 if (count_vht && 5348 !wiphy_ext_feature_isset(&rdev->wiphy, 5349 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 5350 return -EINVAL; 5351 if (count_he && 5352 !wiphy_ext_feature_isset(&rdev->wiphy, 5353 NL80211_EXT_FEATURE_BEACON_RATE_HE)) 5354 return -EINVAL; 5355 5356 return 0; 5357 } 5358 5359 static int nl80211_parse_mbssid_config(struct wiphy *wiphy, 5360 struct net_device *dev, 5361 struct nlattr *attrs, 5362 struct cfg80211_mbssid_config *config, 5363 u8 num_elems) 5364 { 5365 struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1]; 5366 5367 if (!wiphy->mbssid_max_interfaces) 5368 return -EOPNOTSUPP; 5369 5370 if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL, 5371 NULL) || 5372 !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]) 5373 return -EINVAL; 5374 5375 config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]); 5376 if (config->ema) { 5377 if (!wiphy->ema_max_profile_periodicity) 5378 return -EOPNOTSUPP; 5379 5380 if (num_elems > wiphy->ema_max_profile_periodicity) 5381 return -EINVAL; 5382 } 5383 5384 config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]); 5385 if (config->index >= wiphy->mbssid_max_interfaces || 5386 (!config->index && !num_elems)) 5387 return -EINVAL; 5388 5389 if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) { 5390 u32 tx_ifindex = 5391 nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]); 5392 5393 if ((!config->index && tx_ifindex != dev->ifindex) || 5394 (config->index && tx_ifindex == dev->ifindex)) 5395 return -EINVAL; 5396 5397 if (tx_ifindex != dev->ifindex) { 5398 struct net_device *tx_netdev = 5399 dev_get_by_index(wiphy_net(wiphy), tx_ifindex); 5400 5401 if (!tx_netdev || !tx_netdev->ieee80211_ptr || 5402 tx_netdev->ieee80211_ptr->wiphy != wiphy || 5403 tx_netdev->ieee80211_ptr->iftype != 5404 NL80211_IFTYPE_AP) { 5405 dev_put(tx_netdev); 5406 return -EINVAL; 5407 } 5408 5409 config->tx_wdev = tx_netdev->ieee80211_ptr; 5410 } else { 5411 config->tx_wdev = dev->ieee80211_ptr; 5412 } 5413 } else if (!config->index) { 5414 config->tx_wdev = dev->ieee80211_ptr; 5415 } else { 5416 return -EINVAL; 5417 } 5418 5419 return 0; 5420 } 5421 5422 static struct cfg80211_mbssid_elems * 5423 nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs) 5424 { 5425 struct nlattr *nl_elems; 5426 struct cfg80211_mbssid_elems *elems; 5427 int rem_elems; 5428 u8 i = 0, num_elems = 0; 5429 5430 if (!wiphy->mbssid_max_interfaces) 5431 return ERR_PTR(-EINVAL); 5432 5433 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5434 if (num_elems >= 255) 5435 return ERR_PTR(-EINVAL); 5436 num_elems++; 5437 } 5438 5439 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); 5440 if (!elems) 5441 return ERR_PTR(-ENOMEM); 5442 elems->cnt = num_elems; 5443 5444 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5445 elems->elem[i].data = nla_data(nl_elems); 5446 elems->elem[i].len = nla_len(nl_elems); 5447 i++; 5448 } 5449 return elems; 5450 } 5451 5452 static struct cfg80211_rnr_elems * 5453 nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs, 5454 struct netlink_ext_ack *extack) 5455 { 5456 struct nlattr *nl_elems; 5457 struct cfg80211_rnr_elems *elems; 5458 int rem_elems; 5459 u8 i = 0, num_elems = 0; 5460 5461 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5462 int ret; 5463 5464 ret = validate_ie_attr(nl_elems, extack); 5465 if (ret) 5466 return ERR_PTR(ret); 5467 5468 num_elems++; 5469 } 5470 5471 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); 5472 if (!elems) 5473 return ERR_PTR(-ENOMEM); 5474 elems->cnt = num_elems; 5475 5476 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5477 elems->elem[i].data = nla_data(nl_elems); 5478 elems->elem[i].len = nla_len(nl_elems); 5479 i++; 5480 } 5481 return elems; 5482 } 5483 5484 static int nl80211_parse_he_bss_color(struct nlattr *attrs, 5485 struct cfg80211_he_bss_color *he_bss_color) 5486 { 5487 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; 5488 int err; 5489 5490 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, 5491 he_bss_color_policy, NULL); 5492 if (err) 5493 return err; 5494 5495 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) 5496 return -EINVAL; 5497 5498 he_bss_color->color = 5499 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); 5500 he_bss_color->enabled = 5501 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); 5502 he_bss_color->partial = 5503 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); 5504 5505 return 0; 5506 } 5507 5508 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 5509 struct nlattr *attrs[], 5510 struct cfg80211_beacon_data *bcn, 5511 struct netlink_ext_ack *extack) 5512 { 5513 bool haveinfo = false; 5514 int err; 5515 5516 memset(bcn, 0, sizeof(*bcn)); 5517 5518 bcn->link_id = nl80211_link_id(attrs); 5519 5520 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 5521 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 5522 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 5523 if (!bcn->head_len) 5524 return -EINVAL; 5525 haveinfo = true; 5526 } 5527 5528 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 5529 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 5530 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 5531 haveinfo = true; 5532 } 5533 5534 if (!haveinfo) 5535 return -EINVAL; 5536 5537 if (attrs[NL80211_ATTR_IE]) { 5538 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 5539 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 5540 } 5541 5542 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 5543 bcn->proberesp_ies = 5544 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5545 bcn->proberesp_ies_len = 5546 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5547 } 5548 5549 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 5550 bcn->assocresp_ies = 5551 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5552 bcn->assocresp_ies_len = 5553 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5554 } 5555 5556 if (attrs[NL80211_ATTR_PROBE_RESP]) { 5557 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 5558 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 5559 } 5560 5561 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 5562 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 5563 5564 err = nla_parse_nested_deprecated(tb, 5565 NL80211_FTM_RESP_ATTR_MAX, 5566 attrs[NL80211_ATTR_FTM_RESPONDER], 5567 NULL, NULL); 5568 if (err) 5569 return err; 5570 5571 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 5572 wiphy_ext_feature_isset(&rdev->wiphy, 5573 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 5574 bcn->ftm_responder = 1; 5575 else 5576 return -EOPNOTSUPP; 5577 5578 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 5579 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 5580 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 5581 } 5582 5583 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 5584 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5585 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5586 } 5587 } else { 5588 bcn->ftm_responder = -1; 5589 } 5590 5591 if (attrs[NL80211_ATTR_HE_BSS_COLOR]) { 5592 err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR], 5593 &bcn->he_bss_color); 5594 if (err) 5595 return err; 5596 bcn->he_bss_color_valid = true; 5597 } 5598 5599 if (attrs[NL80211_ATTR_MBSSID_ELEMS]) { 5600 struct cfg80211_mbssid_elems *mbssid = 5601 nl80211_parse_mbssid_elems(&rdev->wiphy, 5602 attrs[NL80211_ATTR_MBSSID_ELEMS]); 5603 5604 if (IS_ERR(mbssid)) 5605 return PTR_ERR(mbssid); 5606 5607 bcn->mbssid_ies = mbssid; 5608 5609 if (bcn->mbssid_ies && attrs[NL80211_ATTR_EMA_RNR_ELEMS]) { 5610 struct cfg80211_rnr_elems *rnr = 5611 nl80211_parse_rnr_elems(&rdev->wiphy, 5612 attrs[NL80211_ATTR_EMA_RNR_ELEMS], 5613 extack); 5614 5615 if (IS_ERR(rnr)) 5616 return PTR_ERR(rnr); 5617 5618 if (rnr && rnr->cnt < bcn->mbssid_ies->cnt) 5619 return -EINVAL; 5620 5621 bcn->rnr_ies = rnr; 5622 } 5623 } 5624 5625 return 0; 5626 } 5627 5628 static int nl80211_parse_he_obss_pd(struct nlattr *attrs, 5629 struct ieee80211_he_obss_pd *he_obss_pd) 5630 { 5631 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; 5632 int err; 5633 5634 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, 5635 he_obss_pd_policy, NULL); 5636 if (err) 5637 return err; 5638 5639 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) 5640 return -EINVAL; 5641 5642 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); 5643 5644 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) 5645 he_obss_pd->min_offset = 5646 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); 5647 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) 5648 he_obss_pd->max_offset = 5649 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); 5650 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) 5651 he_obss_pd->non_srg_max_offset = 5652 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); 5653 5654 if (he_obss_pd->min_offset > he_obss_pd->max_offset) 5655 return -EINVAL; 5656 5657 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) 5658 memcpy(he_obss_pd->bss_color_bitmap, 5659 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), 5660 sizeof(he_obss_pd->bss_color_bitmap)); 5661 5662 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) 5663 memcpy(he_obss_pd->partial_bssid_bitmap, 5664 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), 5665 sizeof(he_obss_pd->partial_bssid_bitmap)); 5666 5667 he_obss_pd->enable = true; 5668 5669 return 0; 5670 } 5671 5672 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, 5673 struct nlattr *attrs, 5674 struct cfg80211_ap_settings *params) 5675 { 5676 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; 5677 int ret; 5678 struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; 5679 5680 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5681 NL80211_EXT_FEATURE_FILS_DISCOVERY)) 5682 return -EINVAL; 5683 5684 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, 5685 NULL, NULL); 5686 if (ret) 5687 return ret; 5688 5689 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || 5690 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || 5691 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) 5692 return -EINVAL; 5693 5694 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5695 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5696 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); 5697 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); 5698 5699 return 0; 5700 } 5701 5702 static int 5703 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, 5704 struct nlattr *attrs, 5705 struct cfg80211_ap_settings *params) 5706 { 5707 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; 5708 int ret; 5709 struct cfg80211_unsol_bcast_probe_resp *presp = 5710 ¶ms->unsol_bcast_probe_resp; 5711 5712 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5713 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) 5714 return -EINVAL; 5715 5716 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, 5717 attrs, NULL, NULL); 5718 if (ret) 5719 return ret; 5720 5721 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || 5722 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) 5723 return -EINVAL; 5724 5725 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5726 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5727 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); 5728 return 0; 5729 } 5730 5731 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 5732 const struct element *rates) 5733 { 5734 int i; 5735 5736 if (!rates) 5737 return; 5738 5739 for (i = 0; i < rates->datalen; i++) { 5740 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 5741 params->ht_required = true; 5742 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 5743 params->vht_required = true; 5744 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) 5745 params->he_required = true; 5746 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) 5747 params->sae_h2e_required = true; 5748 } 5749 } 5750 5751 /* 5752 * Since the nl80211 API didn't include, from the beginning, attributes about 5753 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 5754 * benefit of drivers that rebuild IEs in the firmware. 5755 */ 5756 static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 5757 { 5758 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 5759 size_t ies_len = bcn->tail_len; 5760 const u8 *ies = bcn->tail; 5761 const struct element *rates; 5762 const struct element *cap; 5763 5764 rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len); 5765 nl80211_check_ap_rate_selectors(params, rates); 5766 5767 rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 5768 nl80211_check_ap_rate_selectors(params, rates); 5769 5770 cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len); 5771 if (cap && cap->datalen >= sizeof(*params->ht_cap)) 5772 params->ht_cap = (void *)cap->data; 5773 cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 5774 if (cap && cap->datalen >= sizeof(*params->vht_cap)) 5775 params->vht_cap = (void *)cap->data; 5776 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 5777 if (cap && cap->datalen >= sizeof(*params->he_cap) + 1) 5778 params->he_cap = (void *)(cap->data + 1); 5779 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); 5780 if (cap && cap->datalen >= sizeof(*params->he_oper) + 1) 5781 params->he_oper = (void *)(cap->data + 1); 5782 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len); 5783 if (cap) { 5784 if (!cap->datalen) 5785 return -EINVAL; 5786 params->eht_cap = (void *)(cap->data + 1); 5787 if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap, 5788 (const u8 *)params->eht_cap, 5789 cap->datalen - 1, true)) 5790 return -EINVAL; 5791 } 5792 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len); 5793 if (cap) { 5794 if (!cap->datalen) 5795 return -EINVAL; 5796 params->eht_oper = (void *)(cap->data + 1); 5797 if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper, 5798 cap->datalen - 1)) 5799 return -EINVAL; 5800 } 5801 return 0; 5802 } 5803 5804 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 5805 struct cfg80211_ap_settings *params) 5806 { 5807 struct wireless_dev *wdev; 5808 5809 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 5810 if (wdev->iftype != NL80211_IFTYPE_AP && 5811 wdev->iftype != NL80211_IFTYPE_P2P_GO) 5812 continue; 5813 5814 if (!wdev->u.ap.preset_chandef.chan) 5815 continue; 5816 5817 params->chandef = wdev->u.ap.preset_chandef; 5818 return true; 5819 } 5820 5821 return false; 5822 } 5823 5824 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 5825 enum nl80211_auth_type auth_type, 5826 enum nl80211_commands cmd) 5827 { 5828 if (auth_type > NL80211_AUTHTYPE_MAX) 5829 return false; 5830 5831 switch (cmd) { 5832 case NL80211_CMD_AUTHENTICATE: 5833 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5834 auth_type == NL80211_AUTHTYPE_SAE) 5835 return false; 5836 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5837 NL80211_EXT_FEATURE_FILS_STA) && 5838 (auth_type == NL80211_AUTHTYPE_FILS_SK || 5839 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5840 auth_type == NL80211_AUTHTYPE_FILS_PK)) 5841 return false; 5842 return true; 5843 case NL80211_CMD_CONNECT: 5844 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5845 !wiphy_ext_feature_isset(&rdev->wiphy, 5846 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 5847 auth_type == NL80211_AUTHTYPE_SAE) 5848 return false; 5849 5850 /* FILS with SK PFS or PK not supported yet */ 5851 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5852 auth_type == NL80211_AUTHTYPE_FILS_PK) 5853 return false; 5854 if (!wiphy_ext_feature_isset( 5855 &rdev->wiphy, 5856 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 5857 auth_type == NL80211_AUTHTYPE_FILS_SK) 5858 return false; 5859 return true; 5860 case NL80211_CMD_START_AP: 5861 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5862 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && 5863 auth_type == NL80211_AUTHTYPE_SAE) 5864 return false; 5865 /* FILS not supported yet */ 5866 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 5867 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5868 auth_type == NL80211_AUTHTYPE_FILS_PK) 5869 return false; 5870 return true; 5871 default: 5872 return false; 5873 } 5874 } 5875 5876 static void nl80211_send_ap_started(struct wireless_dev *wdev, 5877 unsigned int link_id) 5878 { 5879 struct wiphy *wiphy = wdev->wiphy; 5880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 5881 struct sk_buff *msg; 5882 void *hdr; 5883 5884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 5885 if (!msg) 5886 return; 5887 5888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_START_AP); 5889 if (!hdr) 5890 goto out; 5891 5892 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 5893 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 5894 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 5895 NL80211_ATTR_PAD) || 5896 (wdev->u.ap.ssid_len && 5897 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, 5898 wdev->u.ap.ssid)) || 5899 (wdev->valid_links && 5900 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) 5901 goto out; 5902 5903 genlmsg_end(msg, hdr); 5904 5905 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 5906 NL80211_MCGRP_MLME, GFP_KERNEL); 5907 return; 5908 out: 5909 nlmsg_free(msg); 5910 } 5911 5912 static int nl80211_validate_ap_phy_operation(struct cfg80211_ap_settings *params) 5913 { 5914 struct ieee80211_channel *channel = params->chandef.chan; 5915 5916 if ((params->he_cap || params->he_oper) && 5917 (channel->flags & IEEE80211_CHAN_NO_HE)) 5918 return -EOPNOTSUPP; 5919 5920 if ((params->eht_cap || params->eht_oper) && 5921 (channel->flags & IEEE80211_CHAN_NO_EHT)) 5922 return -EOPNOTSUPP; 5923 5924 return 0; 5925 } 5926 5927 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 5928 { 5929 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5930 unsigned int link_id = nl80211_link_id(info->attrs); 5931 struct net_device *dev = info->user_ptr[1]; 5932 struct wireless_dev *wdev = dev->ieee80211_ptr; 5933 struct cfg80211_ap_settings *params; 5934 int err; 5935 5936 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5938 return -EOPNOTSUPP; 5939 5940 if (!rdev->ops->start_ap) 5941 return -EOPNOTSUPP; 5942 5943 if (wdev->links[link_id].ap.beacon_interval) 5944 return -EALREADY; 5945 5946 /* these are required for START_AP */ 5947 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 5948 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 5949 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 5950 return -EINVAL; 5951 5952 params = kzalloc(sizeof(*params), GFP_KERNEL); 5953 if (!params) 5954 return -ENOMEM; 5955 5956 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon, 5957 info->extack); 5958 if (err) 5959 goto out; 5960 5961 params->beacon_interval = 5962 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 5963 params->dtim_period = 5964 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 5965 5966 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 5967 params->beacon_interval); 5968 if (err) 5969 goto out; 5970 5971 /* 5972 * In theory, some of these attributes should be required here 5973 * but since they were not used when the command was originally 5974 * added, keep them optional for old user space programs to let 5975 * them continue to work with drivers that do not need the 5976 * additional information -- drivers must check! 5977 */ 5978 if (info->attrs[NL80211_ATTR_SSID]) { 5979 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 5980 params->ssid_len = 5981 nla_len(info->attrs[NL80211_ATTR_SSID]); 5982 if (params->ssid_len == 0) { 5983 err = -EINVAL; 5984 goto out; 5985 } 5986 5987 if (wdev->u.ap.ssid_len && 5988 (wdev->u.ap.ssid_len != params->ssid_len || 5989 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) { 5990 /* require identical SSID for MLO */ 5991 err = -EINVAL; 5992 goto out; 5993 } 5994 } else if (wdev->valid_links) { 5995 /* require SSID for MLO */ 5996 err = -EINVAL; 5997 goto out; 5998 } 5999 6000 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 6001 params->hidden_ssid = nla_get_u32( 6002 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 6003 6004 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 6005 6006 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 6007 params->auth_type = nla_get_u32( 6008 info->attrs[NL80211_ATTR_AUTH_TYPE]); 6009 if (!nl80211_valid_auth_type(rdev, params->auth_type, 6010 NL80211_CMD_START_AP)) { 6011 err = -EINVAL; 6012 goto out; 6013 } 6014 } else 6015 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC; 6016 6017 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto, 6018 NL80211_MAX_NR_CIPHER_SUITES); 6019 if (err) 6020 goto out; 6021 6022 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 6023 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) { 6024 err = -EOPNOTSUPP; 6025 goto out; 6026 } 6027 params->inactivity_timeout = nla_get_u16( 6028 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 6029 } 6030 6031 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 6032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6033 err = -EINVAL; 6034 goto out; 6035 } 6036 params->p2p_ctwindow = 6037 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 6038 if (params->p2p_ctwindow != 0 && 6039 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) { 6040 err = -EINVAL; 6041 goto out; 6042 } 6043 } 6044 6045 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 6046 u8 tmp; 6047 6048 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6049 err = -EINVAL; 6050 goto out; 6051 } 6052 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 6053 params->p2p_opp_ps = tmp; 6054 if (params->p2p_opp_ps != 0 && 6055 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) { 6056 err = -EINVAL; 6057 goto out; 6058 } 6059 } 6060 6061 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 6062 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef); 6063 if (err) 6064 goto out; 6065 } else if (wdev->valid_links) { 6066 /* with MLD need to specify the channel configuration */ 6067 err = -EINVAL; 6068 goto out; 6069 } else if (wdev->u.ap.preset_chandef.chan) { 6070 params->chandef = wdev->u.ap.preset_chandef; 6071 } else if (!nl80211_get_ap_channel(rdev, params)) { 6072 err = -EINVAL; 6073 goto out; 6074 } 6075 6076 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) { 6077 err = nl80211_parse_punct_bitmap(rdev, info, 6078 ¶ms->chandef, 6079 ¶ms->punct_bitmap); 6080 if (err) 6081 goto out; 6082 } 6083 6084 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef, 6085 wdev->iftype)) { 6086 err = -EINVAL; 6087 goto out; 6088 } 6089 6090 wdev_lock(wdev); 6091 6092 if (info->attrs[NL80211_ATTR_TX_RATES]) { 6093 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 6094 NL80211_ATTR_TX_RATES, 6095 ¶ms->beacon_rate, 6096 dev, false, link_id); 6097 if (err) 6098 goto out_unlock; 6099 6100 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band, 6101 ¶ms->beacon_rate); 6102 if (err) 6103 goto out_unlock; 6104 } 6105 6106 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 6107 params->smps_mode = 6108 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 6109 switch (params->smps_mode) { 6110 case NL80211_SMPS_OFF: 6111 break; 6112 case NL80211_SMPS_STATIC: 6113 if (!(rdev->wiphy.features & 6114 NL80211_FEATURE_STATIC_SMPS)) { 6115 err = -EINVAL; 6116 goto out_unlock; 6117 } 6118 break; 6119 case NL80211_SMPS_DYNAMIC: 6120 if (!(rdev->wiphy.features & 6121 NL80211_FEATURE_DYNAMIC_SMPS)) { 6122 err = -EINVAL; 6123 goto out_unlock; 6124 } 6125 break; 6126 default: 6127 err = -EINVAL; 6128 goto out_unlock; 6129 } 6130 } else { 6131 params->smps_mode = NL80211_SMPS_OFF; 6132 } 6133 6134 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 6135 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 6136 err = -EOPNOTSUPP; 6137 goto out_unlock; 6138 } 6139 6140 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 6141 params->acl = parse_acl_data(&rdev->wiphy, info); 6142 if (IS_ERR(params->acl)) { 6143 err = PTR_ERR(params->acl); 6144 params->acl = NULL; 6145 goto out_unlock; 6146 } 6147 } 6148 6149 params->twt_responder = 6150 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 6151 6152 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { 6153 err = nl80211_parse_he_obss_pd( 6154 info->attrs[NL80211_ATTR_HE_OBSS_PD], 6155 ¶ms->he_obss_pd); 6156 if (err) 6157 goto out_unlock; 6158 } 6159 6160 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { 6161 err = nl80211_parse_fils_discovery(rdev, 6162 info->attrs[NL80211_ATTR_FILS_DISCOVERY], 6163 params); 6164 if (err) 6165 goto out_unlock; 6166 } 6167 6168 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { 6169 err = nl80211_parse_unsol_bcast_probe_resp( 6170 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], 6171 params); 6172 if (err) 6173 goto out_unlock; 6174 } 6175 6176 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) { 6177 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev, 6178 info->attrs[NL80211_ATTR_MBSSID_CONFIG], 6179 ¶ms->mbssid_config, 6180 params->beacon.mbssid_ies ? 6181 params->beacon.mbssid_ies->cnt : 6182 0); 6183 if (err) 6184 goto out_unlock; 6185 } 6186 6187 if (!params->mbssid_config.ema && params->beacon.rnr_ies) { 6188 err = -EINVAL; 6189 goto out_unlock; 6190 } 6191 6192 err = nl80211_calculate_ap_params(params); 6193 if (err) 6194 goto out_unlock; 6195 6196 err = nl80211_validate_ap_phy_operation(params); 6197 if (err) 6198 goto out_unlock; 6199 6200 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]) 6201 params->flags = nla_get_u32( 6202 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]); 6203 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 6204 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 6205 6206 if (wdev->conn_owner_nlportid && 6207 info->attrs[NL80211_ATTR_SOCKET_OWNER] && 6208 wdev->conn_owner_nlportid != info->snd_portid) { 6209 err = -EINVAL; 6210 goto out_unlock; 6211 } 6212 6213 /* FIXME: validate MLO/link-id against driver capabilities */ 6214 6215 err = rdev_start_ap(rdev, dev, params); 6216 if (!err) { 6217 wdev->links[link_id].ap.beacon_interval = params->beacon_interval; 6218 wdev->links[link_id].ap.chandef = params->chandef; 6219 wdev->u.ap.ssid_len = params->ssid_len; 6220 memcpy(wdev->u.ap.ssid, params->ssid, 6221 params->ssid_len); 6222 6223 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 6224 wdev->conn_owner_nlportid = info->snd_portid; 6225 6226 nl80211_send_ap_started(wdev, link_id); 6227 } 6228 out_unlock: 6229 wdev_unlock(wdev); 6230 out: 6231 kfree(params->acl); 6232 kfree(params->beacon.mbssid_ies); 6233 if (params->mbssid_config.tx_wdev && 6234 params->mbssid_config.tx_wdev->netdev && 6235 params->mbssid_config.tx_wdev->netdev != dev) 6236 dev_put(params->mbssid_config.tx_wdev->netdev); 6237 kfree(params->beacon.rnr_ies); 6238 kfree(params); 6239 6240 return err; 6241 } 6242 6243 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 6244 { 6245 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6246 unsigned int link_id = nl80211_link_id(info->attrs); 6247 struct net_device *dev = info->user_ptr[1]; 6248 struct wireless_dev *wdev = dev->ieee80211_ptr; 6249 struct cfg80211_beacon_data params; 6250 int err; 6251 6252 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6253 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6254 return -EOPNOTSUPP; 6255 6256 if (!rdev->ops->change_beacon) 6257 return -EOPNOTSUPP; 6258 6259 if (!wdev->links[link_id].ap.beacon_interval) 6260 return -EINVAL; 6261 6262 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms, info->extack); 6263 if (err) 6264 goto out; 6265 6266 wdev_lock(wdev); 6267 err = rdev_change_beacon(rdev, dev, ¶ms); 6268 wdev_unlock(wdev); 6269 6270 out: 6271 kfree(params.mbssid_ies); 6272 kfree(params.rnr_ies); 6273 return err; 6274 } 6275 6276 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 6277 { 6278 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6279 unsigned int link_id = nl80211_link_id(info->attrs); 6280 struct net_device *dev = info->user_ptr[1]; 6281 6282 return cfg80211_stop_ap(rdev, dev, link_id, false); 6283 } 6284 6285 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 6286 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 6287 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 6288 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 6289 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 6290 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 6291 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 6292 }; 6293 6294 static int parse_station_flags(struct genl_info *info, 6295 enum nl80211_iftype iftype, 6296 struct station_parameters *params) 6297 { 6298 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 6299 struct nlattr *nla; 6300 int flag; 6301 6302 /* 6303 * Try parsing the new attribute first so userspace 6304 * can specify both for older kernels. 6305 */ 6306 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 6307 if (nla) { 6308 struct nl80211_sta_flag_update *sta_flags; 6309 6310 sta_flags = nla_data(nla); 6311 params->sta_flags_mask = sta_flags->mask; 6312 params->sta_flags_set = sta_flags->set; 6313 params->sta_flags_set &= params->sta_flags_mask; 6314 if ((params->sta_flags_mask | 6315 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 6316 return -EINVAL; 6317 return 0; 6318 } 6319 6320 /* if present, parse the old attribute */ 6321 6322 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 6323 if (!nla) 6324 return 0; 6325 6326 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 6327 return -EINVAL; 6328 6329 /* 6330 * Only allow certain flags for interface types so that 6331 * other attributes are silently ignored. Remember that 6332 * this is backward compatibility code with old userspace 6333 * and shouldn't be hit in other cases anyway. 6334 */ 6335 switch (iftype) { 6336 case NL80211_IFTYPE_AP: 6337 case NL80211_IFTYPE_AP_VLAN: 6338 case NL80211_IFTYPE_P2P_GO: 6339 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6340 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6341 BIT(NL80211_STA_FLAG_WME) | 6342 BIT(NL80211_STA_FLAG_MFP); 6343 break; 6344 case NL80211_IFTYPE_P2P_CLIENT: 6345 case NL80211_IFTYPE_STATION: 6346 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6347 BIT(NL80211_STA_FLAG_TDLS_PEER); 6348 break; 6349 case NL80211_IFTYPE_MESH_POINT: 6350 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6351 BIT(NL80211_STA_FLAG_MFP) | 6352 BIT(NL80211_STA_FLAG_AUTHORIZED); 6353 break; 6354 default: 6355 return -EINVAL; 6356 } 6357 6358 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 6359 if (flags[flag]) { 6360 params->sta_flags_set |= (1<<flag); 6361 6362 /* no longer support new API additions in old API */ 6363 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 6364 return -EINVAL; 6365 } 6366 } 6367 6368 return 0; 6369 } 6370 6371 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 6372 { 6373 struct nlattr *rate; 6374 u32 bitrate; 6375 u16 bitrate_compat; 6376 enum nl80211_rate_info rate_flg; 6377 6378 rate = nla_nest_start_noflag(msg, attr); 6379 if (!rate) 6380 return false; 6381 6382 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 6383 bitrate = cfg80211_calculate_bitrate(info); 6384 /* report 16-bit bitrate only if we can */ 6385 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 6386 if (bitrate > 0 && 6387 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 6388 return false; 6389 if (bitrate_compat > 0 && 6390 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 6391 return false; 6392 6393 switch (info->bw) { 6394 case RATE_INFO_BW_1: 6395 rate_flg = NL80211_RATE_INFO_1_MHZ_WIDTH; 6396 break; 6397 case RATE_INFO_BW_2: 6398 rate_flg = NL80211_RATE_INFO_2_MHZ_WIDTH; 6399 break; 6400 case RATE_INFO_BW_4: 6401 rate_flg = NL80211_RATE_INFO_4_MHZ_WIDTH; 6402 break; 6403 case RATE_INFO_BW_5: 6404 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 6405 break; 6406 case RATE_INFO_BW_8: 6407 rate_flg = NL80211_RATE_INFO_8_MHZ_WIDTH; 6408 break; 6409 case RATE_INFO_BW_10: 6410 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 6411 break; 6412 case RATE_INFO_BW_16: 6413 rate_flg = NL80211_RATE_INFO_16_MHZ_WIDTH; 6414 break; 6415 default: 6416 WARN_ON(1); 6417 fallthrough; 6418 case RATE_INFO_BW_20: 6419 rate_flg = 0; 6420 break; 6421 case RATE_INFO_BW_40: 6422 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 6423 break; 6424 case RATE_INFO_BW_80: 6425 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 6426 break; 6427 case RATE_INFO_BW_160: 6428 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 6429 break; 6430 case RATE_INFO_BW_HE_RU: 6431 rate_flg = 0; 6432 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 6433 break; 6434 case RATE_INFO_BW_320: 6435 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH; 6436 break; 6437 case RATE_INFO_BW_EHT_RU: 6438 rate_flg = 0; 6439 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS)); 6440 break; 6441 } 6442 6443 if (rate_flg && nla_put_flag(msg, rate_flg)) 6444 return false; 6445 6446 if (info->flags & RATE_INFO_FLAGS_MCS) { 6447 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 6448 return false; 6449 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6450 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6451 return false; 6452 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 6453 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 6454 return false; 6455 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 6456 return false; 6457 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6458 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6459 return false; 6460 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 6461 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 6462 return false; 6463 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 6464 return false; 6465 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 6466 return false; 6467 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 6468 return false; 6469 if (info->bw == RATE_INFO_BW_HE_RU && 6470 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 6471 info->he_ru_alloc)) 6472 return false; 6473 } else if (info->flags & RATE_INFO_FLAGS_S1G_MCS) { 6474 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_MCS, info->mcs)) 6475 return false; 6476 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_NSS, info->nss)) 6477 return false; 6478 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6479 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6480 return false; 6481 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) { 6482 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs)) 6483 return false; 6484 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss)) 6485 return false; 6486 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi)) 6487 return false; 6488 if (info->bw == RATE_INFO_BW_EHT_RU && 6489 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC, 6490 info->eht_ru_alloc)) 6491 return false; 6492 } 6493 6494 nla_nest_end(msg, rate); 6495 return true; 6496 } 6497 6498 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 6499 int id) 6500 { 6501 void *attr; 6502 int i = 0; 6503 6504 if (!mask) 6505 return true; 6506 6507 attr = nla_nest_start_noflag(msg, id); 6508 if (!attr) 6509 return false; 6510 6511 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 6512 if (!(mask & BIT(i))) 6513 continue; 6514 6515 if (nla_put_u8(msg, i, signal[i])) 6516 return false; 6517 } 6518 6519 nla_nest_end(msg, attr); 6520 6521 return true; 6522 } 6523 6524 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 6525 u32 seq, int flags, 6526 struct cfg80211_registered_device *rdev, 6527 struct net_device *dev, 6528 const u8 *mac_addr, struct station_info *sinfo) 6529 { 6530 void *hdr; 6531 struct nlattr *sinfoattr, *bss_param; 6532 6533 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 6534 if (!hdr) { 6535 cfg80211_sinfo_release_content(sinfo); 6536 return -1; 6537 } 6538 6539 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 6541 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 6542 goto nla_put_failure; 6543 6544 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 6545 if (!sinfoattr) 6546 goto nla_put_failure; 6547 6548 #define PUT_SINFO(attr, memb, type) do { \ 6549 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 6550 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6551 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 6552 sinfo->memb)) \ 6553 goto nla_put_failure; \ 6554 } while (0) 6555 #define PUT_SINFO_U64(attr, memb) do { \ 6556 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6557 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 6558 sinfo->memb, NL80211_STA_INFO_PAD)) \ 6559 goto nla_put_failure; \ 6560 } while (0) 6561 6562 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 6563 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 6564 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); 6565 6566 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 6567 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 6568 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 6569 (u32)sinfo->rx_bytes)) 6570 goto nla_put_failure; 6571 6572 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 6573 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 6574 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 6575 (u32)sinfo->tx_bytes)) 6576 goto nla_put_failure; 6577 6578 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 6579 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 6580 PUT_SINFO(LLID, llid, u16); 6581 PUT_SINFO(PLID, plid, u16); 6582 PUT_SINFO(PLINK_STATE, plink_state, u8); 6583 PUT_SINFO_U64(RX_DURATION, rx_duration); 6584 PUT_SINFO_U64(TX_DURATION, tx_duration); 6585 6586 if (wiphy_ext_feature_isset(&rdev->wiphy, 6587 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6588 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 6589 6590 switch (rdev->wiphy.signal_type) { 6591 case CFG80211_SIGNAL_TYPE_MBM: 6592 PUT_SINFO(SIGNAL, signal, u8); 6593 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 6594 break; 6595 default: 6596 break; 6597 } 6598 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 6599 if (!nl80211_put_signal(msg, sinfo->chains, 6600 sinfo->chain_signal, 6601 NL80211_STA_INFO_CHAIN_SIGNAL)) 6602 goto nla_put_failure; 6603 } 6604 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 6605 if (!nl80211_put_signal(msg, sinfo->chains, 6606 sinfo->chain_signal_avg, 6607 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 6608 goto nla_put_failure; 6609 } 6610 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 6611 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 6612 NL80211_STA_INFO_TX_BITRATE)) 6613 goto nla_put_failure; 6614 } 6615 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 6616 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 6617 NL80211_STA_INFO_RX_BITRATE)) 6618 goto nla_put_failure; 6619 } 6620 6621 PUT_SINFO(RX_PACKETS, rx_packets, u32); 6622 PUT_SINFO(TX_PACKETS, tx_packets, u32); 6623 PUT_SINFO(TX_RETRIES, tx_retries, u32); 6624 PUT_SINFO(TX_FAILED, tx_failed, u32); 6625 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 6626 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 6627 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 6628 PUT_SINFO(LOCAL_PM, local_pm, u32); 6629 PUT_SINFO(PEER_PM, peer_pm, u32); 6630 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 6631 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 6632 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); 6633 6634 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 6635 bss_param = nla_nest_start_noflag(msg, 6636 NL80211_STA_INFO_BSS_PARAM); 6637 if (!bss_param) 6638 goto nla_put_failure; 6639 6640 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 6641 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 6642 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 6643 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 6644 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 6645 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 6646 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 6647 sinfo->bss_param.dtim_period) || 6648 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 6649 sinfo->bss_param.beacon_interval)) 6650 goto nla_put_failure; 6651 6652 nla_nest_end(msg, bss_param); 6653 } 6654 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 6655 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 6656 sizeof(struct nl80211_sta_flag_update), 6657 &sinfo->sta_flags)) 6658 goto nla_put_failure; 6659 6660 PUT_SINFO_U64(T_OFFSET, t_offset); 6661 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 6662 PUT_SINFO_U64(BEACON_RX, rx_beacon); 6663 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 6664 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 6665 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 6666 if (wiphy_ext_feature_isset(&rdev->wiphy, 6667 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 6668 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 6669 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 6670 } 6671 6672 #undef PUT_SINFO 6673 #undef PUT_SINFO_U64 6674 6675 if (sinfo->pertid) { 6676 struct nlattr *tidsattr; 6677 int tid; 6678 6679 tidsattr = nla_nest_start_noflag(msg, 6680 NL80211_STA_INFO_TID_STATS); 6681 if (!tidsattr) 6682 goto nla_put_failure; 6683 6684 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 6685 struct cfg80211_tid_stats *tidstats; 6686 struct nlattr *tidattr; 6687 6688 tidstats = &sinfo->pertid[tid]; 6689 6690 if (!tidstats->filled) 6691 continue; 6692 6693 tidattr = nla_nest_start_noflag(msg, tid + 1); 6694 if (!tidattr) 6695 goto nla_put_failure; 6696 6697 #define PUT_TIDVAL_U64(attr, memb) do { \ 6698 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 6699 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 6700 tidstats->memb, NL80211_TID_STATS_PAD)) \ 6701 goto nla_put_failure; \ 6702 } while (0) 6703 6704 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 6705 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 6706 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 6707 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 6708 6709 #undef PUT_TIDVAL_U64 6710 if ((tidstats->filled & 6711 BIT(NL80211_TID_STATS_TXQ_STATS)) && 6712 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 6713 NL80211_TID_STATS_TXQ_STATS)) 6714 goto nla_put_failure; 6715 6716 nla_nest_end(msg, tidattr); 6717 } 6718 6719 nla_nest_end(msg, tidsattr); 6720 } 6721 6722 nla_nest_end(msg, sinfoattr); 6723 6724 if (sinfo->assoc_req_ies_len && 6725 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 6726 sinfo->assoc_req_ies)) 6727 goto nla_put_failure; 6728 6729 if (sinfo->assoc_resp_ies_len && 6730 nla_put(msg, NL80211_ATTR_RESP_IE, sinfo->assoc_resp_ies_len, 6731 sinfo->assoc_resp_ies)) 6732 goto nla_put_failure; 6733 6734 if (sinfo->mlo_params_valid) { 6735 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, 6736 sinfo->assoc_link_id)) 6737 goto nla_put_failure; 6738 6739 if (!is_zero_ether_addr(sinfo->mld_addr) && 6740 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, 6741 sinfo->mld_addr)) 6742 goto nla_put_failure; 6743 } 6744 6745 cfg80211_sinfo_release_content(sinfo); 6746 genlmsg_end(msg, hdr); 6747 return 0; 6748 6749 nla_put_failure: 6750 cfg80211_sinfo_release_content(sinfo); 6751 genlmsg_cancel(msg, hdr); 6752 return -EMSGSIZE; 6753 } 6754 6755 static int nl80211_dump_station(struct sk_buff *skb, 6756 struct netlink_callback *cb) 6757 { 6758 struct station_info sinfo; 6759 struct cfg80211_registered_device *rdev; 6760 struct wireless_dev *wdev; 6761 u8 mac_addr[ETH_ALEN]; 6762 int sta_idx = cb->args[2]; 6763 int err; 6764 6765 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 6766 if (err) 6767 return err; 6768 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 6769 __acquire(&rdev->wiphy.mtx); 6770 6771 if (!wdev->netdev) { 6772 err = -EINVAL; 6773 goto out_err; 6774 } 6775 6776 if (!rdev->ops->dump_station) { 6777 err = -EOPNOTSUPP; 6778 goto out_err; 6779 } 6780 6781 while (1) { 6782 memset(&sinfo, 0, sizeof(sinfo)); 6783 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 6784 mac_addr, &sinfo); 6785 if (err == -ENOENT) 6786 break; 6787 if (err) 6788 goto out_err; 6789 6790 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 6791 NETLINK_CB(cb->skb).portid, 6792 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6793 rdev, wdev->netdev, mac_addr, 6794 &sinfo) < 0) 6795 goto out; 6796 6797 sta_idx++; 6798 } 6799 6800 out: 6801 cb->args[2] = sta_idx; 6802 err = skb->len; 6803 out_err: 6804 wiphy_unlock(&rdev->wiphy); 6805 6806 return err; 6807 } 6808 6809 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 6810 { 6811 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6812 struct net_device *dev = info->user_ptr[1]; 6813 struct station_info sinfo; 6814 struct sk_buff *msg; 6815 u8 *mac_addr = NULL; 6816 int err; 6817 6818 memset(&sinfo, 0, sizeof(sinfo)); 6819 6820 if (!info->attrs[NL80211_ATTR_MAC]) 6821 return -EINVAL; 6822 6823 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6824 6825 if (!rdev->ops->get_station) 6826 return -EOPNOTSUPP; 6827 6828 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 6829 if (err) 6830 return err; 6831 6832 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6833 if (!msg) { 6834 cfg80211_sinfo_release_content(&sinfo); 6835 return -ENOMEM; 6836 } 6837 6838 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 6839 info->snd_portid, info->snd_seq, 0, 6840 rdev, dev, mac_addr, &sinfo) < 0) { 6841 nlmsg_free(msg); 6842 return -ENOBUFS; 6843 } 6844 6845 return genlmsg_reply(msg, info); 6846 } 6847 6848 int cfg80211_check_station_change(struct wiphy *wiphy, 6849 struct station_parameters *params, 6850 enum cfg80211_station_type statype) 6851 { 6852 if (params->listen_interval != -1 && 6853 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6854 return -EINVAL; 6855 6856 if (params->support_p2p_ps != -1 && 6857 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6858 return -EINVAL; 6859 6860 if (params->aid && 6861 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 6862 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6863 return -EINVAL; 6864 6865 /* When you run into this, adjust the code below for the new flag */ 6866 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6867 6868 switch (statype) { 6869 case CFG80211_STA_MESH_PEER_KERNEL: 6870 case CFG80211_STA_MESH_PEER_USER: 6871 /* 6872 * No ignoring the TDLS flag here -- the userspace mesh 6873 * code doesn't have the bug of including TDLS in the 6874 * mask everywhere. 6875 */ 6876 if (params->sta_flags_mask & 6877 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6878 BIT(NL80211_STA_FLAG_MFP) | 6879 BIT(NL80211_STA_FLAG_AUTHORIZED))) 6880 return -EINVAL; 6881 break; 6882 case CFG80211_STA_TDLS_PEER_SETUP: 6883 case CFG80211_STA_TDLS_PEER_ACTIVE: 6884 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6885 return -EINVAL; 6886 /* ignore since it can't change */ 6887 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6888 break; 6889 default: 6890 /* disallow mesh-specific things */ 6891 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 6892 return -EINVAL; 6893 if (params->local_pm) 6894 return -EINVAL; 6895 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6896 return -EINVAL; 6897 } 6898 6899 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6900 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 6901 /* TDLS can't be set, ... */ 6902 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 6903 return -EINVAL; 6904 /* 6905 * ... but don't bother the driver with it. This works around 6906 * a hostapd/wpa_supplicant issue -- it always includes the 6907 * TLDS_PEER flag in the mask even for AP mode. 6908 */ 6909 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6910 } 6911 6912 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6913 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6914 /* reject other things that can't change */ 6915 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 6916 return -EINVAL; 6917 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 6918 return -EINVAL; 6919 if (params->link_sta_params.supported_rates) 6920 return -EINVAL; 6921 if (params->ext_capab || params->link_sta_params.ht_capa || 6922 params->link_sta_params.vht_capa || 6923 params->link_sta_params.he_capa || 6924 params->link_sta_params.eht_capa) 6925 return -EINVAL; 6926 } 6927 6928 if (statype != CFG80211_STA_AP_CLIENT && 6929 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6930 if (params->vlan) 6931 return -EINVAL; 6932 } 6933 6934 switch (statype) { 6935 case CFG80211_STA_AP_MLME_CLIENT: 6936 /* Use this only for authorizing/unauthorizing a station */ 6937 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 6938 return -EOPNOTSUPP; 6939 break; 6940 case CFG80211_STA_AP_CLIENT: 6941 case CFG80211_STA_AP_CLIENT_UNASSOC: 6942 /* accept only the listed bits */ 6943 if (params->sta_flags_mask & 6944 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6945 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6946 BIT(NL80211_STA_FLAG_ASSOCIATED) | 6947 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6948 BIT(NL80211_STA_FLAG_WME) | 6949 BIT(NL80211_STA_FLAG_MFP))) 6950 return -EINVAL; 6951 6952 /* but authenticated/associated only if driver handles it */ 6953 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6954 params->sta_flags_mask & 6955 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6956 BIT(NL80211_STA_FLAG_ASSOCIATED))) 6957 return -EINVAL; 6958 break; 6959 case CFG80211_STA_IBSS: 6960 case CFG80211_STA_AP_STA: 6961 /* reject any changes other than AUTHORIZED */ 6962 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 6963 return -EINVAL; 6964 break; 6965 case CFG80211_STA_TDLS_PEER_SETUP: 6966 /* reject any changes other than AUTHORIZED or WME */ 6967 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6968 BIT(NL80211_STA_FLAG_WME))) 6969 return -EINVAL; 6970 /* force (at least) rates when authorizing */ 6971 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 6972 !params->link_sta_params.supported_rates) 6973 return -EINVAL; 6974 break; 6975 case CFG80211_STA_TDLS_PEER_ACTIVE: 6976 /* reject any changes */ 6977 return -EINVAL; 6978 case CFG80211_STA_MESH_PEER_KERNEL: 6979 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6980 return -EINVAL; 6981 break; 6982 case CFG80211_STA_MESH_PEER_USER: 6983 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 6984 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 6985 return -EINVAL; 6986 break; 6987 } 6988 6989 /* 6990 * Older kernel versions ignored this attribute entirely, so don't 6991 * reject attempts to update it but mark it as unused instead so the 6992 * driver won't look at the data. 6993 */ 6994 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 6995 statype != CFG80211_STA_TDLS_PEER_SETUP) 6996 params->link_sta_params.opmode_notif_used = false; 6997 6998 return 0; 6999 } 7000 EXPORT_SYMBOL(cfg80211_check_station_change); 7001 7002 /* 7003 * Get vlan interface making sure it is running and on the right wiphy. 7004 */ 7005 static struct net_device *get_vlan(struct genl_info *info, 7006 struct cfg80211_registered_device *rdev) 7007 { 7008 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 7009 struct net_device *v; 7010 int ret; 7011 7012 if (!vlanattr) 7013 return NULL; 7014 7015 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 7016 if (!v) 7017 return ERR_PTR(-ENODEV); 7018 7019 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 7020 ret = -EINVAL; 7021 goto error; 7022 } 7023 7024 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 7025 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 7026 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 7027 ret = -EINVAL; 7028 goto error; 7029 } 7030 7031 if (!netif_running(v)) { 7032 ret = -ENETDOWN; 7033 goto error; 7034 } 7035 7036 return v; 7037 error: 7038 dev_put(v); 7039 return ERR_PTR(ret); 7040 } 7041 7042 static int nl80211_parse_sta_wme(struct genl_info *info, 7043 struct station_parameters *params) 7044 { 7045 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 7046 struct nlattr *nla; 7047 int err; 7048 7049 /* parse WME attributes if present */ 7050 if (!info->attrs[NL80211_ATTR_STA_WME]) 7051 return 0; 7052 7053 nla = info->attrs[NL80211_ATTR_STA_WME]; 7054 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 7055 nl80211_sta_wme_policy, 7056 info->extack); 7057 if (err) 7058 return err; 7059 7060 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 7061 params->uapsd_queues = nla_get_u8( 7062 tb[NL80211_STA_WME_UAPSD_QUEUES]); 7063 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 7064 return -EINVAL; 7065 7066 if (tb[NL80211_STA_WME_MAX_SP]) 7067 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 7068 7069 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 7070 return -EINVAL; 7071 7072 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 7073 7074 return 0; 7075 } 7076 7077 static int nl80211_parse_sta_channel_info(struct genl_info *info, 7078 struct station_parameters *params) 7079 { 7080 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 7081 params->supported_channels = 7082 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 7083 params->supported_channels_len = 7084 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 7085 /* 7086 * Need to include at least one (first channel, number of 7087 * channels) tuple for each subband (checked in policy), 7088 * and must have proper tuples for the rest of the data as well. 7089 */ 7090 if (params->supported_channels_len % 2) 7091 return -EINVAL; 7092 } 7093 7094 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 7095 params->supported_oper_classes = 7096 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 7097 params->supported_oper_classes_len = 7098 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 7099 } 7100 return 0; 7101 } 7102 7103 static int nl80211_set_station_tdls(struct genl_info *info, 7104 struct station_parameters *params) 7105 { 7106 int err; 7107 /* Dummy STA entry gets updated once the peer capabilities are known */ 7108 if (info->attrs[NL80211_ATTR_PEER_AID]) 7109 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 7110 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 7111 params->link_sta_params.ht_capa = 7112 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 7113 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 7114 params->link_sta_params.vht_capa = 7115 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 7116 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 7117 params->link_sta_params.he_capa = 7118 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7119 params->link_sta_params.he_capa_len = 7120 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7121 7122 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 7123 params->link_sta_params.eht_capa = 7124 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7125 params->link_sta_params.eht_capa_len = 7126 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7127 7128 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa, 7129 (const u8 *)params->link_sta_params.eht_capa, 7130 params->link_sta_params.eht_capa_len, 7131 false)) 7132 return -EINVAL; 7133 } 7134 } 7135 7136 err = nl80211_parse_sta_channel_info(info, params); 7137 if (err) 7138 return err; 7139 7140 return nl80211_parse_sta_wme(info, params); 7141 } 7142 7143 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 7144 struct sta_txpwr *txpwr, 7145 bool *txpwr_set) 7146 { 7147 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7148 int idx; 7149 7150 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 7151 if (!rdev->ops->set_tx_power || 7152 !wiphy_ext_feature_isset(&rdev->wiphy, 7153 NL80211_EXT_FEATURE_STA_TX_PWR)) 7154 return -EOPNOTSUPP; 7155 7156 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 7157 txpwr->type = nla_get_u8(info->attrs[idx]); 7158 7159 if (txpwr->type == NL80211_TX_POWER_LIMITED) { 7160 idx = NL80211_ATTR_STA_TX_POWER; 7161 7162 if (info->attrs[idx]) 7163 txpwr->power = nla_get_s16(info->attrs[idx]); 7164 else 7165 return -EINVAL; 7166 } 7167 7168 *txpwr_set = true; 7169 } else { 7170 *txpwr_set = false; 7171 } 7172 7173 return 0; 7174 } 7175 7176 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 7177 { 7178 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7179 struct net_device *dev = info->user_ptr[1]; 7180 struct station_parameters params; 7181 u8 *mac_addr; 7182 int err; 7183 7184 memset(¶ms, 0, sizeof(params)); 7185 7186 if (!rdev->ops->change_station) 7187 return -EOPNOTSUPP; 7188 7189 /* 7190 * AID and listen_interval properties can be set only for unassociated 7191 * station. Include these parameters here and will check them in 7192 * cfg80211_check_station_change(). 7193 */ 7194 if (info->attrs[NL80211_ATTR_STA_AID]) 7195 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 7196 7197 if (info->attrs[NL80211_ATTR_VLAN_ID]) 7198 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 7199 7200 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 7201 params.listen_interval = 7202 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 7203 else 7204 params.listen_interval = -1; 7205 7206 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 7207 params.support_p2p_ps = 7208 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 7209 else 7210 params.support_p2p_ps = -1; 7211 7212 if (!info->attrs[NL80211_ATTR_MAC]) 7213 return -EINVAL; 7214 7215 params.link_sta_params.link_id = 7216 nl80211_link_id_or_invalid(info->attrs); 7217 7218 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7219 /* If MLD_ADDR attribute is set then this is an MLD station 7220 * and the MLD_ADDR attribute holds the MLD address and the 7221 * MAC attribute holds for the LINK address. 7222 * In that case, the link_id is also expected to be valid. 7223 */ 7224 if (params.link_sta_params.link_id < 0) 7225 return -EINVAL; 7226 7227 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7228 params.link_sta_params.mld_mac = mac_addr; 7229 params.link_sta_params.link_mac = 7230 nla_data(info->attrs[NL80211_ATTR_MAC]); 7231 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7232 return -EINVAL; 7233 } else { 7234 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7235 } 7236 7237 7238 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 7239 params.link_sta_params.supported_rates = 7240 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7241 params.link_sta_params.supported_rates_len = 7242 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7243 } 7244 7245 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7246 params.capability = 7247 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7248 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7249 } 7250 7251 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7252 params.ext_capab = 7253 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7254 params.ext_capab_len = 7255 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7256 } 7257 7258 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7259 return -EINVAL; 7260 7261 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7262 params.plink_action = 7263 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7264 7265 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 7266 params.plink_state = 7267 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 7268 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 7269 params.peer_aid = nla_get_u16( 7270 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 7271 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 7272 } 7273 7274 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 7275 params.local_pm = nla_get_u32( 7276 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 7277 7278 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7279 params.link_sta_params.opmode_notif_used = true; 7280 params.link_sta_params.opmode_notif = 7281 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7282 } 7283 7284 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7285 params.link_sta_params.he_6ghz_capa = 7286 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7287 7288 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7289 params.airtime_weight = 7290 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7291 7292 if (params.airtime_weight && 7293 !wiphy_ext_feature_isset(&rdev->wiphy, 7294 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7295 return -EOPNOTSUPP; 7296 7297 err = nl80211_parse_sta_txpower_setting(info, 7298 ¶ms.link_sta_params.txpwr, 7299 ¶ms.link_sta_params.txpwr_set); 7300 if (err) 7301 return err; 7302 7303 /* Include parameters for TDLS peer (will check later) */ 7304 err = nl80211_set_station_tdls(info, ¶ms); 7305 if (err) 7306 return err; 7307 7308 params.vlan = get_vlan(info, rdev); 7309 if (IS_ERR(params.vlan)) 7310 return PTR_ERR(params.vlan); 7311 7312 switch (dev->ieee80211_ptr->iftype) { 7313 case NL80211_IFTYPE_AP: 7314 case NL80211_IFTYPE_AP_VLAN: 7315 case NL80211_IFTYPE_P2P_GO: 7316 case NL80211_IFTYPE_P2P_CLIENT: 7317 case NL80211_IFTYPE_STATION: 7318 case NL80211_IFTYPE_ADHOC: 7319 case NL80211_IFTYPE_MESH_POINT: 7320 break; 7321 default: 7322 err = -EOPNOTSUPP; 7323 goto out_put_vlan; 7324 } 7325 7326 /* driver will call cfg80211_check_station_change() */ 7327 wdev_lock(dev->ieee80211_ptr); 7328 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 7329 wdev_unlock(dev->ieee80211_ptr); 7330 7331 out_put_vlan: 7332 dev_put(params.vlan); 7333 7334 return err; 7335 } 7336 7337 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 7338 { 7339 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7340 int err; 7341 struct net_device *dev = info->user_ptr[1]; 7342 struct wireless_dev *wdev = dev->ieee80211_ptr; 7343 struct station_parameters params; 7344 u8 *mac_addr = NULL; 7345 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 7346 BIT(NL80211_STA_FLAG_ASSOCIATED); 7347 7348 memset(¶ms, 0, sizeof(params)); 7349 7350 if (!rdev->ops->add_station) 7351 return -EOPNOTSUPP; 7352 7353 if (!info->attrs[NL80211_ATTR_MAC]) 7354 return -EINVAL; 7355 7356 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 7357 return -EINVAL; 7358 7359 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 7360 return -EINVAL; 7361 7362 if (!info->attrs[NL80211_ATTR_STA_AID] && 7363 !info->attrs[NL80211_ATTR_PEER_AID]) 7364 return -EINVAL; 7365 7366 params.link_sta_params.link_id = 7367 nl80211_link_id_or_invalid(info->attrs); 7368 7369 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7370 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7371 params.link_sta_params.mld_mac = mac_addr; 7372 params.link_sta_params.link_mac = 7373 nla_data(info->attrs[NL80211_ATTR_MAC]); 7374 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7375 return -EINVAL; 7376 } else { 7377 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7378 } 7379 7380 params.link_sta_params.supported_rates = 7381 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7382 params.link_sta_params.supported_rates_len = 7383 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7384 params.listen_interval = 7385 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 7386 7387 if (info->attrs[NL80211_ATTR_VLAN_ID]) 7388 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 7389 7390 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 7391 params.support_p2p_ps = 7392 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 7393 } else { 7394 /* 7395 * if not specified, assume it's supported for P2P GO interface, 7396 * and is NOT supported for AP interface 7397 */ 7398 params.support_p2p_ps = 7399 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 7400 } 7401 7402 if (info->attrs[NL80211_ATTR_PEER_AID]) 7403 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 7404 else 7405 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 7406 7407 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7408 params.capability = 7409 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7410 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7411 } 7412 7413 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7414 params.ext_capab = 7415 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7416 params.ext_capab_len = 7417 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7418 } 7419 7420 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 7421 params.link_sta_params.ht_capa = 7422 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 7423 7424 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 7425 params.link_sta_params.vht_capa = 7426 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 7427 7428 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 7429 params.link_sta_params.he_capa = 7430 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7431 params.link_sta_params.he_capa_len = 7432 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7433 7434 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 7435 params.link_sta_params.eht_capa = 7436 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7437 params.link_sta_params.eht_capa_len = 7438 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7439 7440 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa, 7441 (const u8 *)params.link_sta_params.eht_capa, 7442 params.link_sta_params.eht_capa_len, 7443 false)) 7444 return -EINVAL; 7445 } 7446 } 7447 7448 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7449 params.link_sta_params.he_6ghz_capa = 7450 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7451 7452 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7453 params.link_sta_params.opmode_notif_used = true; 7454 params.link_sta_params.opmode_notif = 7455 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7456 } 7457 7458 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7459 params.plink_action = 7460 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7461 7462 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7463 params.airtime_weight = 7464 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7465 7466 if (params.airtime_weight && 7467 !wiphy_ext_feature_isset(&rdev->wiphy, 7468 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7469 return -EOPNOTSUPP; 7470 7471 err = nl80211_parse_sta_txpower_setting(info, 7472 ¶ms.link_sta_params.txpwr, 7473 ¶ms.link_sta_params.txpwr_set); 7474 if (err) 7475 return err; 7476 7477 err = nl80211_parse_sta_channel_info(info, ¶ms); 7478 if (err) 7479 return err; 7480 7481 err = nl80211_parse_sta_wme(info, ¶ms); 7482 if (err) 7483 return err; 7484 7485 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7486 return -EINVAL; 7487 7488 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 7489 * as userspace might just pass through the capabilities from the IEs 7490 * directly, rather than enforcing this restriction and returning an 7491 * error in this case. 7492 */ 7493 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 7494 params.link_sta_params.ht_capa = NULL; 7495 params.link_sta_params.vht_capa = NULL; 7496 7497 /* HE and EHT require WME */ 7498 if (params.link_sta_params.he_capa_len || 7499 params.link_sta_params.he_6ghz_capa || 7500 params.link_sta_params.eht_capa_len) 7501 return -EINVAL; 7502 } 7503 7504 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ 7505 if (params.link_sta_params.he_6ghz_capa && 7506 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa)) 7507 return -EINVAL; 7508 7509 /* When you run into this, adjust the code below for the new flag */ 7510 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 7511 7512 switch (dev->ieee80211_ptr->iftype) { 7513 case NL80211_IFTYPE_AP: 7514 case NL80211_IFTYPE_AP_VLAN: 7515 case NL80211_IFTYPE_P2P_GO: 7516 /* ignore WME attributes if iface/sta is not capable */ 7517 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 7518 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 7519 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7520 7521 /* TDLS peers cannot be added */ 7522 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7523 info->attrs[NL80211_ATTR_PEER_AID]) 7524 return -EINVAL; 7525 /* but don't bother the driver with it */ 7526 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 7527 7528 /* allow authenticated/associated only if driver handles it */ 7529 if (!(rdev->wiphy.features & 7530 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 7531 params.sta_flags_mask & auth_assoc) 7532 return -EINVAL; 7533 7534 /* Older userspace, or userspace wanting to be compatible with 7535 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 7536 * and assoc flags in the mask, but assumes the station will be 7537 * added as associated anyway since this was the required driver 7538 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 7539 * introduced. 7540 * In order to not bother drivers with this quirk in the API 7541 * set the flags in both the mask and set for new stations in 7542 * this case. 7543 */ 7544 if (!(params.sta_flags_mask & auth_assoc)) { 7545 params.sta_flags_mask |= auth_assoc; 7546 params.sta_flags_set |= auth_assoc; 7547 } 7548 7549 /* must be last in here for error handling */ 7550 params.vlan = get_vlan(info, rdev); 7551 if (IS_ERR(params.vlan)) 7552 return PTR_ERR(params.vlan); 7553 break; 7554 case NL80211_IFTYPE_MESH_POINT: 7555 /* ignore uAPSD data */ 7556 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7557 7558 /* associated is disallowed */ 7559 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 7560 return -EINVAL; 7561 /* TDLS peers cannot be added */ 7562 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7563 info->attrs[NL80211_ATTR_PEER_AID]) 7564 return -EINVAL; 7565 break; 7566 case NL80211_IFTYPE_STATION: 7567 case NL80211_IFTYPE_P2P_CLIENT: 7568 /* ignore uAPSD data */ 7569 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7570 7571 /* these are disallowed */ 7572 if (params.sta_flags_mask & 7573 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 7574 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 7575 return -EINVAL; 7576 /* Only TDLS peers can be added */ 7577 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 7578 return -EINVAL; 7579 /* Can only add if TDLS ... */ 7580 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 7581 return -EOPNOTSUPP; 7582 /* ... with external setup is supported */ 7583 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 7584 return -EOPNOTSUPP; 7585 /* 7586 * Older wpa_supplicant versions always mark the TDLS peer 7587 * as authorized, but it shouldn't yet be. 7588 */ 7589 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 7590 break; 7591 default: 7592 return -EOPNOTSUPP; 7593 } 7594 7595 /* be aware of params.vlan when changing code here */ 7596 7597 wdev_lock(dev->ieee80211_ptr); 7598 if (wdev->valid_links) { 7599 if (params.link_sta_params.link_id < 0) { 7600 err = -EINVAL; 7601 goto out; 7602 } 7603 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) { 7604 err = -ENOLINK; 7605 goto out; 7606 } 7607 } else { 7608 if (params.link_sta_params.link_id >= 0) { 7609 err = -EINVAL; 7610 goto out; 7611 } 7612 } 7613 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 7614 out: 7615 wdev_unlock(dev->ieee80211_ptr); 7616 dev_put(params.vlan); 7617 return err; 7618 } 7619 7620 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 7621 { 7622 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7623 struct net_device *dev = info->user_ptr[1]; 7624 struct station_del_parameters params; 7625 int ret; 7626 7627 memset(¶ms, 0, sizeof(params)); 7628 7629 if (info->attrs[NL80211_ATTR_MAC]) 7630 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 7631 7632 switch (dev->ieee80211_ptr->iftype) { 7633 case NL80211_IFTYPE_AP: 7634 case NL80211_IFTYPE_AP_VLAN: 7635 case NL80211_IFTYPE_MESH_POINT: 7636 case NL80211_IFTYPE_P2P_GO: 7637 /* always accept these */ 7638 break; 7639 case NL80211_IFTYPE_ADHOC: 7640 /* conditionally accept */ 7641 if (wiphy_ext_feature_isset(&rdev->wiphy, 7642 NL80211_EXT_FEATURE_DEL_IBSS_STA)) 7643 break; 7644 return -EINVAL; 7645 default: 7646 return -EINVAL; 7647 } 7648 7649 if (!rdev->ops->del_station) 7650 return -EOPNOTSUPP; 7651 7652 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 7653 params.subtype = 7654 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 7655 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 7656 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 7657 return -EINVAL; 7658 } else { 7659 /* Default to Deauthentication frame */ 7660 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 7661 } 7662 7663 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 7664 params.reason_code = 7665 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 7666 if (params.reason_code == 0) 7667 return -EINVAL; /* 0 is reserved */ 7668 } else { 7669 /* Default to reason code 2 */ 7670 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 7671 } 7672 7673 wdev_lock(dev->ieee80211_ptr); 7674 ret = rdev_del_station(rdev, dev, ¶ms); 7675 wdev_unlock(dev->ieee80211_ptr); 7676 7677 return ret; 7678 } 7679 7680 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 7681 int flags, struct net_device *dev, 7682 u8 *dst, u8 *next_hop, 7683 struct mpath_info *pinfo) 7684 { 7685 void *hdr; 7686 struct nlattr *pinfoattr; 7687 7688 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 7689 if (!hdr) 7690 return -1; 7691 7692 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 7693 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 7694 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 7695 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 7696 goto nla_put_failure; 7697 7698 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 7699 if (!pinfoattr) 7700 goto nla_put_failure; 7701 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 7702 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 7703 pinfo->frame_qlen)) 7704 goto nla_put_failure; 7705 if (((pinfo->filled & MPATH_INFO_SN) && 7706 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 7707 ((pinfo->filled & MPATH_INFO_METRIC) && 7708 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 7709 pinfo->metric)) || 7710 ((pinfo->filled & MPATH_INFO_EXPTIME) && 7711 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 7712 pinfo->exptime)) || 7713 ((pinfo->filled & MPATH_INFO_FLAGS) && 7714 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 7715 pinfo->flags)) || 7716 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 7717 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 7718 pinfo->discovery_timeout)) || 7719 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 7720 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 7721 pinfo->discovery_retries)) || 7722 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 7723 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 7724 pinfo->hop_count)) || 7725 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 7726 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 7727 pinfo->path_change_count))) 7728 goto nla_put_failure; 7729 7730 nla_nest_end(msg, pinfoattr); 7731 7732 genlmsg_end(msg, hdr); 7733 return 0; 7734 7735 nla_put_failure: 7736 genlmsg_cancel(msg, hdr); 7737 return -EMSGSIZE; 7738 } 7739 7740 static int nl80211_dump_mpath(struct sk_buff *skb, 7741 struct netlink_callback *cb) 7742 { 7743 struct mpath_info pinfo; 7744 struct cfg80211_registered_device *rdev; 7745 struct wireless_dev *wdev; 7746 u8 dst[ETH_ALEN]; 7747 u8 next_hop[ETH_ALEN]; 7748 int path_idx = cb->args[2]; 7749 int err; 7750 7751 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7752 if (err) 7753 return err; 7754 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7755 __acquire(&rdev->wiphy.mtx); 7756 7757 if (!rdev->ops->dump_mpath) { 7758 err = -EOPNOTSUPP; 7759 goto out_err; 7760 } 7761 7762 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7763 err = -EOPNOTSUPP; 7764 goto out_err; 7765 } 7766 7767 while (1) { 7768 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 7769 next_hop, &pinfo); 7770 if (err == -ENOENT) 7771 break; 7772 if (err) 7773 goto out_err; 7774 7775 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7776 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7777 wdev->netdev, dst, next_hop, 7778 &pinfo) < 0) 7779 goto out; 7780 7781 path_idx++; 7782 } 7783 7784 out: 7785 cb->args[2] = path_idx; 7786 err = skb->len; 7787 out_err: 7788 wiphy_unlock(&rdev->wiphy); 7789 return err; 7790 } 7791 7792 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 7793 { 7794 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7795 int err; 7796 struct net_device *dev = info->user_ptr[1]; 7797 struct mpath_info pinfo; 7798 struct sk_buff *msg; 7799 u8 *dst = NULL; 7800 u8 next_hop[ETH_ALEN]; 7801 7802 memset(&pinfo, 0, sizeof(pinfo)); 7803 7804 if (!info->attrs[NL80211_ATTR_MAC]) 7805 return -EINVAL; 7806 7807 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7808 7809 if (!rdev->ops->get_mpath) 7810 return -EOPNOTSUPP; 7811 7812 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7813 return -EOPNOTSUPP; 7814 7815 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 7816 if (err) 7817 return err; 7818 7819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7820 if (!msg) 7821 return -ENOMEM; 7822 7823 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7824 dev, dst, next_hop, &pinfo) < 0) { 7825 nlmsg_free(msg); 7826 return -ENOBUFS; 7827 } 7828 7829 return genlmsg_reply(msg, info); 7830 } 7831 7832 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 7833 { 7834 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7835 struct net_device *dev = info->user_ptr[1]; 7836 u8 *dst = NULL; 7837 u8 *next_hop = NULL; 7838 7839 if (!info->attrs[NL80211_ATTR_MAC]) 7840 return -EINVAL; 7841 7842 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7843 return -EINVAL; 7844 7845 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7846 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7847 7848 if (!rdev->ops->change_mpath) 7849 return -EOPNOTSUPP; 7850 7851 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7852 return -EOPNOTSUPP; 7853 7854 return rdev_change_mpath(rdev, dev, dst, next_hop); 7855 } 7856 7857 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 7858 { 7859 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7860 struct net_device *dev = info->user_ptr[1]; 7861 u8 *dst = NULL; 7862 u8 *next_hop = NULL; 7863 7864 if (!info->attrs[NL80211_ATTR_MAC]) 7865 return -EINVAL; 7866 7867 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7868 return -EINVAL; 7869 7870 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7871 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7872 7873 if (!rdev->ops->add_mpath) 7874 return -EOPNOTSUPP; 7875 7876 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7877 return -EOPNOTSUPP; 7878 7879 return rdev_add_mpath(rdev, dev, dst, next_hop); 7880 } 7881 7882 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 7883 { 7884 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7885 struct net_device *dev = info->user_ptr[1]; 7886 u8 *dst = NULL; 7887 7888 if (info->attrs[NL80211_ATTR_MAC]) 7889 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7890 7891 if (!rdev->ops->del_mpath) 7892 return -EOPNOTSUPP; 7893 7894 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7895 return -EOPNOTSUPP; 7896 7897 return rdev_del_mpath(rdev, dev, dst); 7898 } 7899 7900 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 7901 { 7902 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7903 int err; 7904 struct net_device *dev = info->user_ptr[1]; 7905 struct mpath_info pinfo; 7906 struct sk_buff *msg; 7907 u8 *dst = NULL; 7908 u8 mpp[ETH_ALEN]; 7909 7910 memset(&pinfo, 0, sizeof(pinfo)); 7911 7912 if (!info->attrs[NL80211_ATTR_MAC]) 7913 return -EINVAL; 7914 7915 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7916 7917 if (!rdev->ops->get_mpp) 7918 return -EOPNOTSUPP; 7919 7920 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7921 return -EOPNOTSUPP; 7922 7923 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 7924 if (err) 7925 return err; 7926 7927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7928 if (!msg) 7929 return -ENOMEM; 7930 7931 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7932 dev, dst, mpp, &pinfo) < 0) { 7933 nlmsg_free(msg); 7934 return -ENOBUFS; 7935 } 7936 7937 return genlmsg_reply(msg, info); 7938 } 7939 7940 static int nl80211_dump_mpp(struct sk_buff *skb, 7941 struct netlink_callback *cb) 7942 { 7943 struct mpath_info pinfo; 7944 struct cfg80211_registered_device *rdev; 7945 struct wireless_dev *wdev; 7946 u8 dst[ETH_ALEN]; 7947 u8 mpp[ETH_ALEN]; 7948 int path_idx = cb->args[2]; 7949 int err; 7950 7951 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7952 if (err) 7953 return err; 7954 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7955 __acquire(&rdev->wiphy.mtx); 7956 7957 if (!rdev->ops->dump_mpp) { 7958 err = -EOPNOTSUPP; 7959 goto out_err; 7960 } 7961 7962 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7963 err = -EOPNOTSUPP; 7964 goto out_err; 7965 } 7966 7967 while (1) { 7968 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 7969 mpp, &pinfo); 7970 if (err == -ENOENT) 7971 break; 7972 if (err) 7973 goto out_err; 7974 7975 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7976 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7977 wdev->netdev, dst, mpp, 7978 &pinfo) < 0) 7979 goto out; 7980 7981 path_idx++; 7982 } 7983 7984 out: 7985 cb->args[2] = path_idx; 7986 err = skb->len; 7987 out_err: 7988 wiphy_unlock(&rdev->wiphy); 7989 return err; 7990 } 7991 7992 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 7993 { 7994 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7995 struct net_device *dev = info->user_ptr[1]; 7996 struct wireless_dev *wdev = dev->ieee80211_ptr; 7997 struct bss_parameters params; 7998 int err; 7999 8000 memset(¶ms, 0, sizeof(params)); 8001 params.link_id = nl80211_link_id_or_invalid(info->attrs); 8002 /* default to not changing parameters */ 8003 params.use_cts_prot = -1; 8004 params.use_short_preamble = -1; 8005 params.use_short_slot_time = -1; 8006 params.ap_isolate = -1; 8007 params.ht_opmode = -1; 8008 params.p2p_ctwindow = -1; 8009 params.p2p_opp_ps = -1; 8010 8011 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 8012 params.use_cts_prot = 8013 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 8014 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 8015 params.use_short_preamble = 8016 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 8017 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 8018 params.use_short_slot_time = 8019 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 8020 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 8021 params.basic_rates = 8022 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 8023 params.basic_rates_len = 8024 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 8025 } 8026 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 8027 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 8028 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 8029 params.ht_opmode = 8030 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 8031 8032 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 8033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8034 return -EINVAL; 8035 params.p2p_ctwindow = 8036 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 8037 if (params.p2p_ctwindow != 0 && 8038 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 8039 return -EINVAL; 8040 } 8041 8042 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 8043 u8 tmp; 8044 8045 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8046 return -EINVAL; 8047 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 8048 params.p2p_opp_ps = tmp; 8049 if (params.p2p_opp_ps && 8050 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 8051 return -EINVAL; 8052 } 8053 8054 if (!rdev->ops->change_bss) 8055 return -EOPNOTSUPP; 8056 8057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 8058 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8059 return -EOPNOTSUPP; 8060 8061 wdev_lock(wdev); 8062 err = rdev_change_bss(rdev, dev, ¶ms); 8063 wdev_unlock(wdev); 8064 8065 return err; 8066 } 8067 8068 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 8069 { 8070 char *data = NULL; 8071 bool is_indoor; 8072 enum nl80211_user_reg_hint_type user_reg_hint_type; 8073 u32 owner_nlportid; 8074 8075 /* 8076 * You should only get this when cfg80211 hasn't yet initialized 8077 * completely when built-in to the kernel right between the time 8078 * window between nl80211_init() and regulatory_init(), if that is 8079 * even possible. 8080 */ 8081 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 8082 return -EINPROGRESS; 8083 8084 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 8085 user_reg_hint_type = 8086 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 8087 else 8088 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 8089 8090 switch (user_reg_hint_type) { 8091 case NL80211_USER_REG_HINT_USER: 8092 case NL80211_USER_REG_HINT_CELL_BASE: 8093 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 8094 return -EINVAL; 8095 8096 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 8097 return regulatory_hint_user(data, user_reg_hint_type); 8098 case NL80211_USER_REG_HINT_INDOOR: 8099 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 8100 owner_nlportid = info->snd_portid; 8101 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 8102 } else { 8103 owner_nlportid = 0; 8104 is_indoor = true; 8105 } 8106 8107 return regulatory_hint_indoor(is_indoor, owner_nlportid); 8108 default: 8109 return -EINVAL; 8110 } 8111 } 8112 8113 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 8114 { 8115 return reg_reload_regdb(); 8116 } 8117 8118 static int nl80211_get_mesh_config(struct sk_buff *skb, 8119 struct genl_info *info) 8120 { 8121 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8122 struct net_device *dev = info->user_ptr[1]; 8123 struct wireless_dev *wdev = dev->ieee80211_ptr; 8124 struct mesh_config cur_params; 8125 int err = 0; 8126 void *hdr; 8127 struct nlattr *pinfoattr; 8128 struct sk_buff *msg; 8129 8130 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 8131 return -EOPNOTSUPP; 8132 8133 if (!rdev->ops->get_mesh_config) 8134 return -EOPNOTSUPP; 8135 8136 wdev_lock(wdev); 8137 /* If not connected, get default parameters */ 8138 if (!wdev->u.mesh.id_len) 8139 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 8140 else 8141 err = rdev_get_mesh_config(rdev, dev, &cur_params); 8142 wdev_unlock(wdev); 8143 8144 if (err) 8145 return err; 8146 8147 /* Draw up a netlink message to send back */ 8148 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 8149 if (!msg) 8150 return -ENOMEM; 8151 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 8152 NL80211_CMD_GET_MESH_CONFIG); 8153 if (!hdr) 8154 goto out; 8155 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 8156 if (!pinfoattr) 8157 goto nla_put_failure; 8158 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 8159 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 8160 cur_params.dot11MeshRetryTimeout) || 8161 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 8162 cur_params.dot11MeshConfirmTimeout) || 8163 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 8164 cur_params.dot11MeshHoldingTimeout) || 8165 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 8166 cur_params.dot11MeshMaxPeerLinks) || 8167 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 8168 cur_params.dot11MeshMaxRetries) || 8169 nla_put_u8(msg, NL80211_MESHCONF_TTL, 8170 cur_params.dot11MeshTTL) || 8171 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 8172 cur_params.element_ttl) || 8173 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 8174 cur_params.auto_open_plinks) || 8175 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 8176 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 8177 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 8178 cur_params.dot11MeshHWMPmaxPREQretries) || 8179 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 8180 cur_params.path_refresh_time) || 8181 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 8182 cur_params.min_discovery_timeout) || 8183 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 8184 cur_params.dot11MeshHWMPactivePathTimeout) || 8185 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 8186 cur_params.dot11MeshHWMPpreqMinInterval) || 8187 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 8188 cur_params.dot11MeshHWMPperrMinInterval) || 8189 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 8190 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 8191 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 8192 cur_params.dot11MeshHWMPRootMode) || 8193 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 8194 cur_params.dot11MeshHWMPRannInterval) || 8195 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 8196 cur_params.dot11MeshGateAnnouncementProtocol) || 8197 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 8198 cur_params.dot11MeshForwarding) || 8199 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 8200 cur_params.rssi_threshold) || 8201 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 8202 cur_params.ht_opmode) || 8203 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 8204 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 8205 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 8206 cur_params.dot11MeshHWMProotInterval) || 8207 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 8208 cur_params.dot11MeshHWMPconfirmationInterval) || 8209 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 8210 cur_params.power_mode) || 8211 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 8212 cur_params.dot11MeshAwakeWindowDuration) || 8213 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 8214 cur_params.plink_timeout) || 8215 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 8216 cur_params.dot11MeshConnectedToMeshGate) || 8217 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, 8218 cur_params.dot11MeshNolearn) || 8219 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, 8220 cur_params.dot11MeshConnectedToAuthServer)) 8221 goto nla_put_failure; 8222 nla_nest_end(msg, pinfoattr); 8223 genlmsg_end(msg, hdr); 8224 return genlmsg_reply(msg, info); 8225 8226 nla_put_failure: 8227 out: 8228 nlmsg_free(msg); 8229 return -ENOBUFS; 8230 } 8231 8232 static const struct nla_policy 8233 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 8234 [NL80211_MESHCONF_RETRY_TIMEOUT] = 8235 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8236 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 8237 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8238 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 8239 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8240 [NL80211_MESHCONF_MAX_PEER_LINKS] = 8241 NLA_POLICY_RANGE(NLA_U16, 0, 255), 8242 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 8243 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8244 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8245 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 8246 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 8247 NLA_POLICY_RANGE(NLA_U32, 1, 255), 8248 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 8249 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 8250 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 8251 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 8252 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 8253 NLA_POLICY_MIN(NLA_U16, 1), 8254 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 8255 NLA_POLICY_MIN(NLA_U16, 1), 8256 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 8257 NLA_POLICY_MIN(NLA_U16, 1), 8258 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 8259 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 8260 NLA_POLICY_MIN(NLA_U16, 1), 8261 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 8262 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 8263 [NL80211_MESHCONF_RSSI_THRESHOLD] = 8264 NLA_POLICY_RANGE(NLA_S32, -255, 0), 8265 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 8266 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 8267 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 8268 NLA_POLICY_MIN(NLA_U16, 1), 8269 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 8270 NLA_POLICY_MIN(NLA_U16, 1), 8271 [NL80211_MESHCONF_POWER_MODE] = 8272 NLA_POLICY_RANGE(NLA_U32, 8273 NL80211_MESH_POWER_ACTIVE, 8274 NL80211_MESH_POWER_MAX), 8275 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 8276 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 8277 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8278 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8279 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8280 }; 8281 8282 static const struct nla_policy 8283 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 8284 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 8285 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 8286 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 8287 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 8288 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 8289 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 8290 [NL80211_MESH_SETUP_IE] = 8291 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 8292 IEEE80211_MAX_DATA_LEN), 8293 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 8294 }; 8295 8296 static int nl80211_parse_mesh_config(struct genl_info *info, 8297 struct mesh_config *cfg, 8298 u32 *mask_out) 8299 { 8300 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 8301 u32 mask = 0; 8302 u16 ht_opmode; 8303 8304 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 8305 do { \ 8306 if (tb[attr]) { \ 8307 cfg->param = fn(tb[attr]); \ 8308 mask |= BIT((attr) - 1); \ 8309 } \ 8310 } while (0) 8311 8312 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 8313 return -EINVAL; 8314 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 8315 return -EINVAL; 8316 8317 /* This makes sure that there aren't more than 32 mesh config 8318 * parameters (otherwise our bitfield scheme would not work.) */ 8319 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 8320 8321 /* Fill in the params struct */ 8322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 8323 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 8324 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 8325 NL80211_MESHCONF_CONFIRM_TIMEOUT, 8326 nla_get_u16); 8327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 8328 NL80211_MESHCONF_HOLDING_TIMEOUT, 8329 nla_get_u16); 8330 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 8331 NL80211_MESHCONF_MAX_PEER_LINKS, 8332 nla_get_u16); 8333 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 8334 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 8335 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 8336 NL80211_MESHCONF_TTL, nla_get_u8); 8337 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 8338 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 8339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 8340 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 8341 nla_get_u8); 8342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 8343 mask, 8344 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 8345 nla_get_u32); 8346 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 8347 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 8348 nla_get_u8); 8349 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 8350 NL80211_MESHCONF_PATH_REFRESH_TIME, 8351 nla_get_u32); 8352 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 8353 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 8354 return -EINVAL; 8355 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 8356 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 8357 nla_get_u16); 8358 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 8359 mask, 8360 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 8361 nla_get_u32); 8362 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 8363 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 8364 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 8365 return -EINVAL; 8366 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 8367 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 8368 nla_get_u16); 8369 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 8370 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 8371 nla_get_u16); 8372 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8373 dot11MeshHWMPnetDiameterTraversalTime, mask, 8374 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 8375 nla_get_u16); 8376 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 8377 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 8378 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 8379 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 8380 nla_get_u16); 8381 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 8382 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 8383 nla_get_u8); 8384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 8385 NL80211_MESHCONF_FORWARDING, nla_get_u8); 8386 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 8387 NL80211_MESHCONF_RSSI_THRESHOLD, 8388 nla_get_s32); 8389 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 8390 NL80211_MESHCONF_CONNECTED_TO_GATE, 8391 nla_get_u8); 8392 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, 8393 NL80211_MESHCONF_CONNECTED_TO_AS, 8394 nla_get_u8); 8395 /* 8396 * Check HT operation mode based on 8397 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 8398 */ 8399 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 8400 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 8401 8402 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 8403 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 8404 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 8405 return -EINVAL; 8406 8407 /* NON_HT_STA bit is reserved, but some programs set it */ 8408 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 8409 8410 cfg->ht_opmode = ht_opmode; 8411 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 8412 } 8413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8414 dot11MeshHWMPactivePathToRootTimeout, mask, 8415 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 8416 nla_get_u32); 8417 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 8418 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 8419 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 8420 return -EINVAL; 8421 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 8422 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 8423 nla_get_u16); 8424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 8425 mask, 8426 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 8427 nla_get_u16); 8428 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 8429 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 8430 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 8431 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 8432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 8433 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 8434 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, 8435 NL80211_MESHCONF_NOLEARN, nla_get_u8); 8436 if (mask_out) 8437 *mask_out = mask; 8438 8439 return 0; 8440 8441 #undef FILL_IN_MESH_PARAM_IF_SET 8442 } 8443 8444 static int nl80211_parse_mesh_setup(struct genl_info *info, 8445 struct mesh_setup *setup) 8446 { 8447 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8448 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 8449 8450 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 8451 return -EINVAL; 8452 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 8453 return -EINVAL; 8454 8455 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 8456 setup->sync_method = 8457 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 8458 IEEE80211_SYNC_METHOD_VENDOR : 8459 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 8460 8461 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 8462 setup->path_sel_proto = 8463 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 8464 IEEE80211_PATH_PROTOCOL_VENDOR : 8465 IEEE80211_PATH_PROTOCOL_HWMP; 8466 8467 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 8468 setup->path_metric = 8469 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 8470 IEEE80211_PATH_METRIC_VENDOR : 8471 IEEE80211_PATH_METRIC_AIRTIME; 8472 8473 if (tb[NL80211_MESH_SETUP_IE]) { 8474 struct nlattr *ieattr = 8475 tb[NL80211_MESH_SETUP_IE]; 8476 setup->ie = nla_data(ieattr); 8477 setup->ie_len = nla_len(ieattr); 8478 } 8479 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 8480 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 8481 return -EINVAL; 8482 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 8483 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 8484 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 8485 if (setup->is_secure) 8486 setup->user_mpm = true; 8487 8488 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 8489 if (!setup->user_mpm) 8490 return -EINVAL; 8491 setup->auth_id = 8492 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 8493 } 8494 8495 return 0; 8496 } 8497 8498 static int nl80211_update_mesh_config(struct sk_buff *skb, 8499 struct genl_info *info) 8500 { 8501 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8502 struct net_device *dev = info->user_ptr[1]; 8503 struct wireless_dev *wdev = dev->ieee80211_ptr; 8504 struct mesh_config cfg; 8505 u32 mask; 8506 int err; 8507 8508 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 8509 return -EOPNOTSUPP; 8510 8511 if (!rdev->ops->update_mesh_config) 8512 return -EOPNOTSUPP; 8513 8514 err = nl80211_parse_mesh_config(info, &cfg, &mask); 8515 if (err) 8516 return err; 8517 8518 wdev_lock(wdev); 8519 if (!wdev->u.mesh.id_len) 8520 err = -ENOLINK; 8521 8522 if (!err) 8523 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 8524 8525 wdev_unlock(wdev); 8526 8527 return err; 8528 } 8529 8530 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 8531 struct sk_buff *msg) 8532 { 8533 struct nlattr *nl_reg_rules; 8534 unsigned int i; 8535 8536 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 8537 (regdom->dfs_region && 8538 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 8539 goto nla_put_failure; 8540 8541 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 8542 if (!nl_reg_rules) 8543 goto nla_put_failure; 8544 8545 for (i = 0; i < regdom->n_reg_rules; i++) { 8546 struct nlattr *nl_reg_rule; 8547 const struct ieee80211_reg_rule *reg_rule; 8548 const struct ieee80211_freq_range *freq_range; 8549 const struct ieee80211_power_rule *power_rule; 8550 unsigned int max_bandwidth_khz; 8551 8552 reg_rule = ®dom->reg_rules[i]; 8553 freq_range = ®_rule->freq_range; 8554 power_rule = ®_rule->power_rule; 8555 8556 nl_reg_rule = nla_nest_start_noflag(msg, i); 8557 if (!nl_reg_rule) 8558 goto nla_put_failure; 8559 8560 max_bandwidth_khz = freq_range->max_bandwidth_khz; 8561 if (!max_bandwidth_khz) 8562 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 8563 reg_rule); 8564 8565 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 8566 reg_rule->flags) || 8567 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 8568 freq_range->start_freq_khz) || 8569 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 8570 freq_range->end_freq_khz) || 8571 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 8572 max_bandwidth_khz) || 8573 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 8574 power_rule->max_antenna_gain) || 8575 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 8576 power_rule->max_eirp) || 8577 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 8578 reg_rule->dfs_cac_ms)) 8579 goto nla_put_failure; 8580 8581 nla_nest_end(msg, nl_reg_rule); 8582 } 8583 8584 nla_nest_end(msg, nl_reg_rules); 8585 return 0; 8586 8587 nla_put_failure: 8588 return -EMSGSIZE; 8589 } 8590 8591 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 8592 { 8593 const struct ieee80211_regdomain *regdom = NULL; 8594 struct cfg80211_registered_device *rdev; 8595 struct wiphy *wiphy = NULL; 8596 struct sk_buff *msg; 8597 int err = -EMSGSIZE; 8598 void *hdr; 8599 8600 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 8601 if (!msg) 8602 return -ENOBUFS; 8603 8604 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 8605 NL80211_CMD_GET_REG); 8606 if (!hdr) 8607 goto put_failure; 8608 8609 rtnl_lock(); 8610 8611 if (info->attrs[NL80211_ATTR_WIPHY]) { 8612 bool self_managed; 8613 8614 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 8615 if (IS_ERR(rdev)) { 8616 err = PTR_ERR(rdev); 8617 goto nla_put_failure; 8618 } 8619 8620 wiphy = &rdev->wiphy; 8621 self_managed = wiphy->regulatory_flags & 8622 REGULATORY_WIPHY_SELF_MANAGED; 8623 8624 rcu_read_lock(); 8625 8626 regdom = get_wiphy_regdom(wiphy); 8627 8628 /* a self-managed-reg device must have a private regdom */ 8629 if (WARN_ON(!regdom && self_managed)) { 8630 err = -EINVAL; 8631 goto nla_put_failure_rcu; 8632 } 8633 8634 if (regdom && 8635 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8636 goto nla_put_failure_rcu; 8637 } else { 8638 rcu_read_lock(); 8639 } 8640 8641 if (!wiphy && reg_last_request_cell_base() && 8642 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8643 NL80211_USER_REG_HINT_CELL_BASE)) 8644 goto nla_put_failure_rcu; 8645 8646 if (!regdom) 8647 regdom = rcu_dereference(cfg80211_regdomain); 8648 8649 if (nl80211_put_regdom(regdom, msg)) 8650 goto nla_put_failure_rcu; 8651 8652 rcu_read_unlock(); 8653 8654 genlmsg_end(msg, hdr); 8655 rtnl_unlock(); 8656 return genlmsg_reply(msg, info); 8657 8658 nla_put_failure_rcu: 8659 rcu_read_unlock(); 8660 nla_put_failure: 8661 rtnl_unlock(); 8662 put_failure: 8663 nlmsg_free(msg); 8664 return err; 8665 } 8666 8667 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 8668 u32 seq, int flags, struct wiphy *wiphy, 8669 const struct ieee80211_regdomain *regdom) 8670 { 8671 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 8672 NL80211_CMD_GET_REG); 8673 8674 if (!hdr) 8675 return -1; 8676 8677 genl_dump_check_consistent(cb, hdr); 8678 8679 if (nl80211_put_regdom(regdom, msg)) 8680 goto nla_put_failure; 8681 8682 if (!wiphy && reg_last_request_cell_base() && 8683 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8684 NL80211_USER_REG_HINT_CELL_BASE)) 8685 goto nla_put_failure; 8686 8687 if (wiphy && 8688 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8689 goto nla_put_failure; 8690 8691 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 8692 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 8693 goto nla_put_failure; 8694 8695 genlmsg_end(msg, hdr); 8696 return 0; 8697 8698 nla_put_failure: 8699 genlmsg_cancel(msg, hdr); 8700 return -EMSGSIZE; 8701 } 8702 8703 static int nl80211_get_reg_dump(struct sk_buff *skb, 8704 struct netlink_callback *cb) 8705 { 8706 const struct ieee80211_regdomain *regdom = NULL; 8707 struct cfg80211_registered_device *rdev; 8708 int err, reg_idx, start = cb->args[2]; 8709 8710 rcu_read_lock(); 8711 8712 if (cfg80211_regdomain && start == 0) { 8713 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8714 NLM_F_MULTI, NULL, 8715 rcu_dereference(cfg80211_regdomain)); 8716 if (err < 0) 8717 goto out_err; 8718 } 8719 8720 /* the global regdom is idx 0 */ 8721 reg_idx = 1; 8722 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 8723 regdom = get_wiphy_regdom(&rdev->wiphy); 8724 if (!regdom) 8725 continue; 8726 8727 if (++reg_idx <= start) 8728 continue; 8729 8730 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8731 NLM_F_MULTI, &rdev->wiphy, regdom); 8732 if (err < 0) { 8733 reg_idx--; 8734 break; 8735 } 8736 } 8737 8738 cb->args[2] = reg_idx; 8739 err = skb->len; 8740 out_err: 8741 rcu_read_unlock(); 8742 return err; 8743 } 8744 8745 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 8746 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 8747 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 8748 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 8749 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 8750 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 8751 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 8752 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 8753 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 8754 }; 8755 8756 static int parse_reg_rule(struct nlattr *tb[], 8757 struct ieee80211_reg_rule *reg_rule) 8758 { 8759 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 8760 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 8761 8762 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 8763 return -EINVAL; 8764 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 8765 return -EINVAL; 8766 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 8767 return -EINVAL; 8768 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 8769 return -EINVAL; 8770 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 8771 return -EINVAL; 8772 8773 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 8774 8775 freq_range->start_freq_khz = 8776 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 8777 freq_range->end_freq_khz = 8778 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 8779 freq_range->max_bandwidth_khz = 8780 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 8781 8782 power_rule->max_eirp = 8783 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 8784 8785 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 8786 power_rule->max_antenna_gain = 8787 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 8788 8789 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 8790 reg_rule->dfs_cac_ms = 8791 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 8792 8793 return 0; 8794 } 8795 8796 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 8797 { 8798 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 8799 struct nlattr *nl_reg_rule; 8800 char *alpha2; 8801 int rem_reg_rules, r; 8802 u32 num_rules = 0, rule_idx = 0; 8803 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 8804 struct ieee80211_regdomain *rd; 8805 8806 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 8807 return -EINVAL; 8808 8809 if (!info->attrs[NL80211_ATTR_REG_RULES]) 8810 return -EINVAL; 8811 8812 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 8813 8814 if (info->attrs[NL80211_ATTR_DFS_REGION]) 8815 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 8816 8817 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8818 rem_reg_rules) { 8819 num_rules++; 8820 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 8821 return -EINVAL; 8822 } 8823 8824 rtnl_lock(); 8825 if (!reg_is_valid_request(alpha2)) { 8826 r = -EINVAL; 8827 goto out; 8828 } 8829 8830 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 8831 if (!rd) { 8832 r = -ENOMEM; 8833 goto out; 8834 } 8835 8836 rd->n_reg_rules = num_rules; 8837 rd->alpha2[0] = alpha2[0]; 8838 rd->alpha2[1] = alpha2[1]; 8839 8840 /* 8841 * Disable DFS master mode if the DFS region was 8842 * not supported or known on this kernel. 8843 */ 8844 if (reg_supported_dfs_region(dfs_region)) 8845 rd->dfs_region = dfs_region; 8846 8847 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8848 rem_reg_rules) { 8849 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 8850 nl_reg_rule, reg_rule_policy, 8851 info->extack); 8852 if (r) 8853 goto bad_reg; 8854 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 8855 if (r) 8856 goto bad_reg; 8857 8858 rule_idx++; 8859 8860 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 8861 r = -EINVAL; 8862 goto bad_reg; 8863 } 8864 } 8865 8866 r = set_regdom(rd, REGD_SOURCE_CRDA); 8867 /* set_regdom takes ownership of rd */ 8868 rd = NULL; 8869 bad_reg: 8870 kfree(rd); 8871 out: 8872 rtnl_unlock(); 8873 return r; 8874 } 8875 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 8876 8877 static int validate_scan_freqs(struct nlattr *freqs) 8878 { 8879 struct nlattr *attr1, *attr2; 8880 int n_channels = 0, tmp1, tmp2; 8881 8882 nla_for_each_nested(attr1, freqs, tmp1) 8883 if (nla_len(attr1) != sizeof(u32)) 8884 return 0; 8885 8886 nla_for_each_nested(attr1, freqs, tmp1) { 8887 n_channels++; 8888 /* 8889 * Some hardware has a limited channel list for 8890 * scanning, and it is pretty much nonsensical 8891 * to scan for a channel twice, so disallow that 8892 * and don't require drivers to check that the 8893 * channel list they get isn't longer than what 8894 * they can scan, as long as they can scan all 8895 * the channels they registered at once. 8896 */ 8897 nla_for_each_nested(attr2, freqs, tmp2) 8898 if (attr1 != attr2 && 8899 nla_get_u32(attr1) == nla_get_u32(attr2)) 8900 return 0; 8901 } 8902 8903 return n_channels; 8904 } 8905 8906 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 8907 { 8908 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 8909 } 8910 8911 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 8912 struct cfg80211_bss_selection *bss_select) 8913 { 8914 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 8915 struct nlattr *nest; 8916 int err; 8917 bool found = false; 8918 int i; 8919 8920 /* only process one nested attribute */ 8921 nest = nla_data(nla); 8922 if (!nla_ok(nest, nla_len(nest))) 8923 return -EINVAL; 8924 8925 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 8926 nest, nl80211_bss_select_policy, 8927 NULL); 8928 if (err) 8929 return err; 8930 8931 /* only one attribute may be given */ 8932 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 8933 if (attr[i]) { 8934 if (found) 8935 return -EINVAL; 8936 found = true; 8937 } 8938 } 8939 8940 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 8941 8942 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 8943 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 8944 8945 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 8946 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 8947 bss_select->param.band_pref = 8948 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 8949 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 8950 return -EINVAL; 8951 } 8952 8953 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 8954 struct nl80211_bss_select_rssi_adjust *adj_param; 8955 8956 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 8957 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 8958 bss_select->param.adjust.band = adj_param->band; 8959 bss_select->param.adjust.delta = adj_param->delta; 8960 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 8961 return -EINVAL; 8962 } 8963 8964 /* user-space did not provide behaviour attribute */ 8965 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 8966 return -EINVAL; 8967 8968 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 8969 return -EINVAL; 8970 8971 return 0; 8972 } 8973 8974 int nl80211_parse_random_mac(struct nlattr **attrs, 8975 u8 *mac_addr, u8 *mac_addr_mask) 8976 { 8977 int i; 8978 8979 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 8980 eth_zero_addr(mac_addr); 8981 eth_zero_addr(mac_addr_mask); 8982 mac_addr[0] = 0x2; 8983 mac_addr_mask[0] = 0x3; 8984 8985 return 0; 8986 } 8987 8988 /* need both or none */ 8989 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 8990 return -EINVAL; 8991 8992 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 8993 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 8994 8995 /* don't allow or configure an mcast address */ 8996 if (!is_multicast_ether_addr(mac_addr_mask) || 8997 is_multicast_ether_addr(mac_addr)) 8998 return -EINVAL; 8999 9000 /* 9001 * allow users to pass a MAC address that has bits set outside 9002 * of the mask, but don't bother drivers with having to deal 9003 * with such bits 9004 */ 9005 for (i = 0; i < ETH_ALEN; i++) 9006 mac_addr[i] &= mac_addr_mask[i]; 9007 9008 return 0; 9009 } 9010 9011 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev, 9012 struct ieee80211_channel *chan) 9013 { 9014 unsigned int link_id; 9015 bool all_ok = true; 9016 9017 ASSERT_WDEV_LOCK(wdev); 9018 9019 if (!cfg80211_beaconing_iface_active(wdev)) 9020 return true; 9021 9022 /* 9023 * FIXME: check if we have a free HW resource/link for chan 9024 * 9025 * This, as well as the FIXME below, requires knowing the link 9026 * capabilities of the hardware. 9027 */ 9028 9029 /* we cannot leave radar channels */ 9030 for_each_valid_link(wdev, link_id) { 9031 struct cfg80211_chan_def *chandef; 9032 9033 chandef = wdev_chandef(wdev, link_id); 9034 if (!chandef || !chandef->chan) 9035 continue; 9036 9037 /* 9038 * FIXME: don't require all_ok, but rather check only the 9039 * correct HW resource/link onto which 'chan' falls, 9040 * as only that link leaves the channel for doing 9041 * the off-channel operation. 9042 */ 9043 9044 if (chandef->chan->flags & IEEE80211_CHAN_RADAR) 9045 all_ok = false; 9046 } 9047 9048 if (all_ok) 9049 return true; 9050 9051 return regulatory_pre_cac_allowed(wdev->wiphy); 9052 } 9053 9054 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 9055 enum nl80211_ext_feature_index feat) 9056 { 9057 if (!(flags & flag)) 9058 return true; 9059 if (wiphy_ext_feature_isset(wiphy, feat)) 9060 return true; 9061 return false; 9062 } 9063 9064 static int 9065 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 9066 void *request, struct nlattr **attrs, 9067 bool is_sched_scan) 9068 { 9069 u8 *mac_addr, *mac_addr_mask; 9070 u32 *flags; 9071 enum nl80211_feature_flags randomness_flag; 9072 9073 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 9074 return 0; 9075 9076 if (is_sched_scan) { 9077 struct cfg80211_sched_scan_request *req = request; 9078 9079 randomness_flag = wdev ? 9080 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 9081 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 9082 flags = &req->flags; 9083 mac_addr = req->mac_addr; 9084 mac_addr_mask = req->mac_addr_mask; 9085 } else { 9086 struct cfg80211_scan_request *req = request; 9087 9088 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 9089 flags = &req->flags; 9090 mac_addr = req->mac_addr; 9091 mac_addr_mask = req->mac_addr_mask; 9092 } 9093 9094 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 9095 9096 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 9097 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 9098 !nl80211_check_scan_feat(wiphy, *flags, 9099 NL80211_SCAN_FLAG_LOW_SPAN, 9100 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 9101 !nl80211_check_scan_feat(wiphy, *flags, 9102 NL80211_SCAN_FLAG_LOW_POWER, 9103 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 9104 !nl80211_check_scan_feat(wiphy, *flags, 9105 NL80211_SCAN_FLAG_HIGH_ACCURACY, 9106 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 9107 !nl80211_check_scan_feat(wiphy, *flags, 9108 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 9109 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 9110 !nl80211_check_scan_feat(wiphy, *flags, 9111 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 9112 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 9113 !nl80211_check_scan_feat(wiphy, *flags, 9114 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 9115 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 9116 !nl80211_check_scan_feat(wiphy, *flags, 9117 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 9118 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 9119 !nl80211_check_scan_feat(wiphy, *flags, 9120 NL80211_SCAN_FLAG_RANDOM_SN, 9121 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 9122 !nl80211_check_scan_feat(wiphy, *flags, 9123 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 9124 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 9125 return -EOPNOTSUPP; 9126 9127 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 9128 int err; 9129 9130 if (!(wiphy->features & randomness_flag) || 9131 (wdev && wdev->connected)) 9132 return -EOPNOTSUPP; 9133 9134 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 9135 if (err) 9136 return err; 9137 } 9138 9139 return 0; 9140 } 9141 9142 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 9143 { 9144 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9145 struct wireless_dev *wdev = info->user_ptr[1]; 9146 struct cfg80211_scan_request *request; 9147 struct nlattr *scan_freqs = NULL; 9148 bool scan_freqs_khz = false; 9149 struct nlattr *attr; 9150 struct wiphy *wiphy; 9151 int err, tmp, n_ssids = 0, n_channels, i; 9152 size_t ie_len, size; 9153 9154 wiphy = &rdev->wiphy; 9155 9156 if (wdev->iftype == NL80211_IFTYPE_NAN) 9157 return -EOPNOTSUPP; 9158 9159 if (!rdev->ops->scan) 9160 return -EOPNOTSUPP; 9161 9162 if (rdev->scan_req || rdev->scan_msg) 9163 return -EBUSY; 9164 9165 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { 9166 if (!wiphy_ext_feature_isset(wiphy, 9167 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) 9168 return -EOPNOTSUPP; 9169 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; 9170 scan_freqs_khz = true; 9171 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) 9172 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; 9173 9174 if (scan_freqs) { 9175 n_channels = validate_scan_freqs(scan_freqs); 9176 if (!n_channels) 9177 return -EINVAL; 9178 } else { 9179 n_channels = ieee80211_get_num_supported_channels(wiphy); 9180 } 9181 9182 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 9183 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 9184 n_ssids++; 9185 9186 if (n_ssids > wiphy->max_scan_ssids) 9187 return -EINVAL; 9188 9189 if (info->attrs[NL80211_ATTR_IE]) 9190 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9191 else 9192 ie_len = 0; 9193 9194 if (ie_len > wiphy->max_scan_ie_len) 9195 return -EINVAL; 9196 9197 size = struct_size(request, channels, n_channels); 9198 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids)); 9199 size = size_add(size, ie_len); 9200 request = kzalloc(size, GFP_KERNEL); 9201 if (!request) 9202 return -ENOMEM; 9203 9204 if (n_ssids) 9205 request->ssids = (void *)&request->channels[n_channels]; 9206 request->n_ssids = n_ssids; 9207 if (ie_len) { 9208 if (n_ssids) 9209 request->ie = (void *)(request->ssids + n_ssids); 9210 else 9211 request->ie = (void *)(request->channels + n_channels); 9212 } 9213 9214 i = 0; 9215 if (scan_freqs) { 9216 /* user specified, bail out if channel not found */ 9217 nla_for_each_nested(attr, scan_freqs, tmp) { 9218 struct ieee80211_channel *chan; 9219 int freq = nla_get_u32(attr); 9220 9221 if (!scan_freqs_khz) 9222 freq = MHZ_TO_KHZ(freq); 9223 9224 chan = ieee80211_get_channel_khz(wiphy, freq); 9225 if (!chan) { 9226 err = -EINVAL; 9227 goto out_free; 9228 } 9229 9230 /* ignore disabled channels */ 9231 if (chan->flags & IEEE80211_CHAN_DISABLED) 9232 continue; 9233 9234 request->channels[i] = chan; 9235 i++; 9236 } 9237 } else { 9238 enum nl80211_band band; 9239 9240 /* all channels */ 9241 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9242 int j; 9243 9244 if (!wiphy->bands[band]) 9245 continue; 9246 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9247 struct ieee80211_channel *chan; 9248 9249 chan = &wiphy->bands[band]->channels[j]; 9250 9251 if (chan->flags & IEEE80211_CHAN_DISABLED) 9252 continue; 9253 9254 request->channels[i] = chan; 9255 i++; 9256 } 9257 } 9258 } 9259 9260 if (!i) { 9261 err = -EINVAL; 9262 goto out_free; 9263 } 9264 9265 request->n_channels = i; 9266 9267 wdev_lock(wdev); 9268 for (i = 0; i < request->n_channels; i++) { 9269 struct ieee80211_channel *chan = request->channels[i]; 9270 9271 /* if we can go off-channel to the target channel we're good */ 9272 if (cfg80211_off_channel_oper_allowed(wdev, chan)) 9273 continue; 9274 9275 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) { 9276 wdev_unlock(wdev); 9277 err = -EBUSY; 9278 goto out_free; 9279 } 9280 } 9281 wdev_unlock(wdev); 9282 9283 i = 0; 9284 if (n_ssids) { 9285 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 9286 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9287 err = -EINVAL; 9288 goto out_free; 9289 } 9290 request->ssids[i].ssid_len = nla_len(attr); 9291 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 9292 i++; 9293 } 9294 } 9295 9296 if (info->attrs[NL80211_ATTR_IE]) { 9297 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9298 memcpy((void *)request->ie, 9299 nla_data(info->attrs[NL80211_ATTR_IE]), 9300 request->ie_len); 9301 } 9302 9303 for (i = 0; i < NUM_NL80211_BANDS; i++) 9304 if (wiphy->bands[i]) 9305 request->rates[i] = 9306 (1 << wiphy->bands[i]->n_bitrates) - 1; 9307 9308 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 9309 nla_for_each_nested(attr, 9310 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 9311 tmp) { 9312 enum nl80211_band band = nla_type(attr); 9313 9314 if (band < 0 || band >= NUM_NL80211_BANDS) { 9315 err = -EINVAL; 9316 goto out_free; 9317 } 9318 9319 if (!wiphy->bands[band]) 9320 continue; 9321 9322 err = ieee80211_get_ratemask(wiphy->bands[band], 9323 nla_data(attr), 9324 nla_len(attr), 9325 &request->rates[band]); 9326 if (err) 9327 goto out_free; 9328 } 9329 } 9330 9331 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 9332 request->duration = 9333 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 9334 request->duration_mandatory = 9335 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 9336 } 9337 9338 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 9339 false); 9340 if (err) 9341 goto out_free; 9342 9343 request->no_cck = 9344 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 9345 9346 /* Initial implementation used NL80211_ATTR_MAC to set the specific 9347 * BSSID to scan for. This was problematic because that same attribute 9348 * was already used for another purpose (local random MAC address). The 9349 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 9350 * compatibility with older userspace components, also use the 9351 * NL80211_ATTR_MAC value here if it can be determined to be used for 9352 * the specific BSSID use case instead of the random MAC address 9353 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 9354 */ 9355 if (info->attrs[NL80211_ATTR_BSSID]) 9356 memcpy(request->bssid, 9357 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 9358 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 9359 info->attrs[NL80211_ATTR_MAC]) 9360 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 9361 ETH_ALEN); 9362 else 9363 eth_broadcast_addr(request->bssid); 9364 9365 request->wdev = wdev; 9366 request->wiphy = &rdev->wiphy; 9367 request->scan_start = jiffies; 9368 9369 rdev->scan_req = request; 9370 err = cfg80211_scan(rdev); 9371 9372 if (err) 9373 goto out_free; 9374 9375 nl80211_send_scan_start(rdev, wdev); 9376 dev_hold(wdev->netdev); 9377 9378 return 0; 9379 9380 out_free: 9381 rdev->scan_req = NULL; 9382 kfree(request); 9383 9384 return err; 9385 } 9386 9387 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 9388 { 9389 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9390 struct wireless_dev *wdev = info->user_ptr[1]; 9391 9392 if (!rdev->ops->abort_scan) 9393 return -EOPNOTSUPP; 9394 9395 if (rdev->scan_msg) 9396 return 0; 9397 9398 if (!rdev->scan_req) 9399 return -ENOENT; 9400 9401 rdev_abort_scan(rdev, wdev); 9402 return 0; 9403 } 9404 9405 static int 9406 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 9407 struct cfg80211_sched_scan_request *request, 9408 struct nlattr **attrs) 9409 { 9410 int tmp, err, i = 0; 9411 struct nlattr *attr; 9412 9413 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9414 u32 interval; 9415 9416 /* 9417 * If scan plans are not specified, 9418 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 9419 * case one scan plan will be set with the specified scan 9420 * interval and infinite number of iterations. 9421 */ 9422 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 9423 if (!interval) 9424 return -EINVAL; 9425 9426 request->scan_plans[0].interval = 9427 DIV_ROUND_UP(interval, MSEC_PER_SEC); 9428 if (!request->scan_plans[0].interval) 9429 return -EINVAL; 9430 9431 if (request->scan_plans[0].interval > 9432 wiphy->max_sched_scan_plan_interval) 9433 request->scan_plans[0].interval = 9434 wiphy->max_sched_scan_plan_interval; 9435 9436 return 0; 9437 } 9438 9439 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 9440 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 9441 9442 if (WARN_ON(i >= n_plans)) 9443 return -EINVAL; 9444 9445 err = nla_parse_nested_deprecated(plan, 9446 NL80211_SCHED_SCAN_PLAN_MAX, 9447 attr, nl80211_plan_policy, 9448 NULL); 9449 if (err) 9450 return err; 9451 9452 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 9453 return -EINVAL; 9454 9455 request->scan_plans[i].interval = 9456 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 9457 if (!request->scan_plans[i].interval || 9458 request->scan_plans[i].interval > 9459 wiphy->max_sched_scan_plan_interval) 9460 return -EINVAL; 9461 9462 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 9463 request->scan_plans[i].iterations = 9464 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 9465 if (!request->scan_plans[i].iterations || 9466 (request->scan_plans[i].iterations > 9467 wiphy->max_sched_scan_plan_iterations)) 9468 return -EINVAL; 9469 } else if (i < n_plans - 1) { 9470 /* 9471 * All scan plans but the last one must specify 9472 * a finite number of iterations 9473 */ 9474 return -EINVAL; 9475 } 9476 9477 i++; 9478 } 9479 9480 /* 9481 * The last scan plan must not specify the number of 9482 * iterations, it is supposed to run infinitely 9483 */ 9484 if (request->scan_plans[n_plans - 1].iterations) 9485 return -EINVAL; 9486 9487 return 0; 9488 } 9489 9490 static int 9491 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 9492 struct cfg80211_match_set *match_sets, 9493 struct nlattr *tb_band_rssi, 9494 s32 rssi_thold) 9495 { 9496 struct nlattr *attr; 9497 int i, tmp, ret = 0; 9498 9499 if (!wiphy_ext_feature_isset(wiphy, 9500 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 9501 if (tb_band_rssi) 9502 ret = -EOPNOTSUPP; 9503 else 9504 for (i = 0; i < NUM_NL80211_BANDS; i++) 9505 match_sets->per_band_rssi_thold[i] = 9506 NL80211_SCAN_RSSI_THOLD_OFF; 9507 return ret; 9508 } 9509 9510 for (i = 0; i < NUM_NL80211_BANDS; i++) 9511 match_sets->per_band_rssi_thold[i] = rssi_thold; 9512 9513 nla_for_each_nested(attr, tb_band_rssi, tmp) { 9514 enum nl80211_band band = nla_type(attr); 9515 9516 if (band < 0 || band >= NUM_NL80211_BANDS) 9517 return -EINVAL; 9518 9519 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 9520 } 9521 9522 return 0; 9523 } 9524 9525 static struct cfg80211_sched_scan_request * 9526 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 9527 struct nlattr **attrs, int max_match_sets) 9528 { 9529 struct cfg80211_sched_scan_request *request; 9530 struct nlattr *attr; 9531 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 9532 enum nl80211_band band; 9533 size_t ie_len, size; 9534 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 9535 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 9536 9537 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9538 n_channels = validate_scan_freqs( 9539 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 9540 if (!n_channels) 9541 return ERR_PTR(-EINVAL); 9542 } else { 9543 n_channels = ieee80211_get_num_supported_channels(wiphy); 9544 } 9545 9546 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 9547 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9548 tmp) 9549 n_ssids++; 9550 9551 if (n_ssids > wiphy->max_sched_scan_ssids) 9552 return ERR_PTR(-EINVAL); 9553 9554 /* 9555 * First, count the number of 'real' matchsets. Due to an issue with 9556 * the old implementation, matchsets containing only the RSSI attribute 9557 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 9558 * RSSI for all matchsets, rather than their own matchset for reporting 9559 * all APs with a strong RSSI. This is needed to be compatible with 9560 * older userspace that treated a matchset with only the RSSI as the 9561 * global RSSI for all other matchsets - if there are other matchsets. 9562 */ 9563 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9564 nla_for_each_nested(attr, 9565 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9566 tmp) { 9567 struct nlattr *rssi; 9568 9569 err = nla_parse_nested_deprecated(tb, 9570 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9571 attr, 9572 nl80211_match_policy, 9573 NULL); 9574 if (err) 9575 return ERR_PTR(err); 9576 9577 /* SSID and BSSID are mutually exclusive */ 9578 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 9579 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 9580 return ERR_PTR(-EINVAL); 9581 9582 /* add other standalone attributes here */ 9583 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 9584 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 9585 n_match_sets++; 9586 continue; 9587 } 9588 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9589 if (rssi) 9590 default_match_rssi = nla_get_s32(rssi); 9591 } 9592 } 9593 9594 /* However, if there's no other matchset, add the RSSI one */ 9595 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 9596 n_match_sets = 1; 9597 9598 if (n_match_sets > max_match_sets) 9599 return ERR_PTR(-EINVAL); 9600 9601 if (attrs[NL80211_ATTR_IE]) 9602 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 9603 else 9604 ie_len = 0; 9605 9606 if (ie_len > wiphy->max_sched_scan_ie_len) 9607 return ERR_PTR(-EINVAL); 9608 9609 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9610 /* 9611 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 9612 * each scan plan already specifies its own interval 9613 */ 9614 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9615 return ERR_PTR(-EINVAL); 9616 9617 nla_for_each_nested(attr, 9618 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 9619 n_plans++; 9620 } else { 9621 /* 9622 * The scan interval attribute is kept for backward 9623 * compatibility. If no scan plans are specified and sched scan 9624 * interval is specified, one scan plan will be set with this 9625 * scan interval and infinite number of iterations. 9626 */ 9627 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9628 return ERR_PTR(-EINVAL); 9629 9630 n_plans = 1; 9631 } 9632 9633 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 9634 return ERR_PTR(-EINVAL); 9635 9636 if (!wiphy_ext_feature_isset( 9637 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 9638 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 9639 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 9640 return ERR_PTR(-EINVAL); 9641 9642 size = struct_size(request, channels, n_channels); 9643 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids)); 9644 size = size_add(size, array_size(sizeof(*request->match_sets), 9645 n_match_sets)); 9646 size = size_add(size, array_size(sizeof(*request->scan_plans), 9647 n_plans)); 9648 size = size_add(size, ie_len); 9649 request = kzalloc(size, GFP_KERNEL); 9650 if (!request) 9651 return ERR_PTR(-ENOMEM); 9652 9653 if (n_ssids) 9654 request->ssids = (void *)&request->channels[n_channels]; 9655 request->n_ssids = n_ssids; 9656 if (ie_len) { 9657 if (n_ssids) 9658 request->ie = (void *)(request->ssids + n_ssids); 9659 else 9660 request->ie = (void *)(request->channels + n_channels); 9661 } 9662 9663 if (n_match_sets) { 9664 if (request->ie) 9665 request->match_sets = (void *)(request->ie + ie_len); 9666 else if (n_ssids) 9667 request->match_sets = 9668 (void *)(request->ssids + n_ssids); 9669 else 9670 request->match_sets = 9671 (void *)(request->channels + n_channels); 9672 } 9673 request->n_match_sets = n_match_sets; 9674 9675 if (n_match_sets) 9676 request->scan_plans = (void *)(request->match_sets + 9677 n_match_sets); 9678 else if (request->ie) 9679 request->scan_plans = (void *)(request->ie + ie_len); 9680 else if (n_ssids) 9681 request->scan_plans = (void *)(request->ssids + n_ssids); 9682 else 9683 request->scan_plans = (void *)(request->channels + n_channels); 9684 9685 request->n_scan_plans = n_plans; 9686 9687 i = 0; 9688 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9689 /* user specified, bail out if channel not found */ 9690 nla_for_each_nested(attr, 9691 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 9692 tmp) { 9693 struct ieee80211_channel *chan; 9694 9695 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 9696 9697 if (!chan) { 9698 err = -EINVAL; 9699 goto out_free; 9700 } 9701 9702 /* ignore disabled channels */ 9703 if (chan->flags & IEEE80211_CHAN_DISABLED) 9704 continue; 9705 9706 request->channels[i] = chan; 9707 i++; 9708 } 9709 } else { 9710 /* all channels */ 9711 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9712 int j; 9713 9714 if (!wiphy->bands[band]) 9715 continue; 9716 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9717 struct ieee80211_channel *chan; 9718 9719 chan = &wiphy->bands[band]->channels[j]; 9720 9721 if (chan->flags & IEEE80211_CHAN_DISABLED) 9722 continue; 9723 9724 request->channels[i] = chan; 9725 i++; 9726 } 9727 } 9728 } 9729 9730 if (!i) { 9731 err = -EINVAL; 9732 goto out_free; 9733 } 9734 9735 request->n_channels = i; 9736 9737 i = 0; 9738 if (n_ssids) { 9739 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9740 tmp) { 9741 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9742 err = -EINVAL; 9743 goto out_free; 9744 } 9745 request->ssids[i].ssid_len = nla_len(attr); 9746 memcpy(request->ssids[i].ssid, nla_data(attr), 9747 nla_len(attr)); 9748 i++; 9749 } 9750 } 9751 9752 i = 0; 9753 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9754 nla_for_each_nested(attr, 9755 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9756 tmp) { 9757 struct nlattr *ssid, *bssid, *rssi; 9758 9759 err = nla_parse_nested_deprecated(tb, 9760 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9761 attr, 9762 nl80211_match_policy, 9763 NULL); 9764 if (err) 9765 goto out_free; 9766 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 9767 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 9768 9769 if (!ssid && !bssid) { 9770 i++; 9771 continue; 9772 } 9773 9774 if (WARN_ON(i >= n_match_sets)) { 9775 /* this indicates a programming error, 9776 * the loop above should have verified 9777 * things properly 9778 */ 9779 err = -EINVAL; 9780 goto out_free; 9781 } 9782 9783 if (ssid) { 9784 memcpy(request->match_sets[i].ssid.ssid, 9785 nla_data(ssid), nla_len(ssid)); 9786 request->match_sets[i].ssid.ssid_len = 9787 nla_len(ssid); 9788 } 9789 if (bssid) 9790 memcpy(request->match_sets[i].bssid, 9791 nla_data(bssid), ETH_ALEN); 9792 9793 /* special attribute - old implementation w/a */ 9794 request->match_sets[i].rssi_thold = default_match_rssi; 9795 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9796 if (rssi) 9797 request->match_sets[i].rssi_thold = 9798 nla_get_s32(rssi); 9799 9800 /* Parse per band RSSI attribute */ 9801 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 9802 &request->match_sets[i], 9803 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 9804 request->match_sets[i].rssi_thold); 9805 if (err) 9806 goto out_free; 9807 9808 i++; 9809 } 9810 9811 /* there was no other matchset, so the RSSI one is alone */ 9812 if (i == 0 && n_match_sets) 9813 request->match_sets[0].rssi_thold = default_match_rssi; 9814 9815 request->min_rssi_thold = INT_MAX; 9816 for (i = 0; i < n_match_sets; i++) 9817 request->min_rssi_thold = 9818 min(request->match_sets[i].rssi_thold, 9819 request->min_rssi_thold); 9820 } else { 9821 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 9822 } 9823 9824 if (ie_len) { 9825 request->ie_len = ie_len; 9826 memcpy((void *)request->ie, 9827 nla_data(attrs[NL80211_ATTR_IE]), 9828 request->ie_len); 9829 } 9830 9831 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 9832 if (err) 9833 goto out_free; 9834 9835 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 9836 request->delay = 9837 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 9838 9839 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 9840 request->relative_rssi = nla_get_s8( 9841 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 9842 request->relative_rssi_set = true; 9843 } 9844 9845 if (request->relative_rssi_set && 9846 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 9847 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 9848 9849 rssi_adjust = nla_data( 9850 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 9851 request->rssi_adjust.band = rssi_adjust->band; 9852 request->rssi_adjust.delta = rssi_adjust->delta; 9853 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 9854 err = -EINVAL; 9855 goto out_free; 9856 } 9857 } 9858 9859 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 9860 if (err) 9861 goto out_free; 9862 9863 request->scan_start = jiffies; 9864 9865 return request; 9866 9867 out_free: 9868 kfree(request); 9869 return ERR_PTR(err); 9870 } 9871 9872 static int nl80211_start_sched_scan(struct sk_buff *skb, 9873 struct genl_info *info) 9874 { 9875 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9876 struct net_device *dev = info->user_ptr[1]; 9877 struct wireless_dev *wdev = dev->ieee80211_ptr; 9878 struct cfg80211_sched_scan_request *sched_scan_req; 9879 bool want_multi; 9880 int err; 9881 9882 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 9883 return -EOPNOTSUPP; 9884 9885 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 9886 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 9887 if (err) 9888 return err; 9889 9890 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 9891 info->attrs, 9892 rdev->wiphy.max_match_sets); 9893 9894 err = PTR_ERR_OR_ZERO(sched_scan_req); 9895 if (err) 9896 goto out_err; 9897 9898 /* leave request id zero for legacy request 9899 * or if driver does not support multi-scheduled scan 9900 */ 9901 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) 9902 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 9903 9904 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 9905 if (err) 9906 goto out_free; 9907 9908 sched_scan_req->dev = dev; 9909 sched_scan_req->wiphy = &rdev->wiphy; 9910 9911 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9912 sched_scan_req->owner_nlportid = info->snd_portid; 9913 9914 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 9915 9916 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 9917 return 0; 9918 9919 out_free: 9920 kfree(sched_scan_req); 9921 out_err: 9922 return err; 9923 } 9924 9925 static int nl80211_stop_sched_scan(struct sk_buff *skb, 9926 struct genl_info *info) 9927 { 9928 struct cfg80211_sched_scan_request *req; 9929 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9930 u64 cookie; 9931 9932 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 9933 return -EOPNOTSUPP; 9934 9935 if (info->attrs[NL80211_ATTR_COOKIE]) { 9936 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 9937 return __cfg80211_stop_sched_scan(rdev, cookie, false); 9938 } 9939 9940 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 9941 struct cfg80211_sched_scan_request, 9942 list); 9943 if (!req || req->reqid || 9944 (req->owner_nlportid && 9945 req->owner_nlportid != info->snd_portid)) 9946 return -ENOENT; 9947 9948 return cfg80211_stop_sched_scan_req(rdev, req, false); 9949 } 9950 9951 static int nl80211_start_radar_detection(struct sk_buff *skb, 9952 struct genl_info *info) 9953 { 9954 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9955 struct net_device *dev = info->user_ptr[1]; 9956 struct wireless_dev *wdev = dev->ieee80211_ptr; 9957 struct wiphy *wiphy = wdev->wiphy; 9958 struct cfg80211_chan_def chandef; 9959 enum nl80211_dfs_regions dfs_region; 9960 unsigned int cac_time_ms; 9961 int err = -EINVAL; 9962 9963 flush_delayed_work(&rdev->dfs_update_channels_wk); 9964 9965 wiphy_lock(wiphy); 9966 9967 dfs_region = reg_get_dfs_region(wiphy); 9968 if (dfs_region == NL80211_DFS_UNSET) 9969 goto unlock; 9970 9971 err = nl80211_parse_chandef(rdev, info, &chandef); 9972 if (err) 9973 goto unlock; 9974 9975 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9976 if (err < 0) 9977 goto unlock; 9978 9979 if (err == 0) { 9980 err = -EINVAL; 9981 goto unlock; 9982 } 9983 9984 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) { 9985 err = -EINVAL; 9986 goto unlock; 9987 } 9988 9989 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) { 9990 err = cfg80211_start_background_radar_detection(rdev, wdev, 9991 &chandef); 9992 goto unlock; 9993 } 9994 9995 if (netif_carrier_ok(dev)) { 9996 err = -EBUSY; 9997 goto unlock; 9998 } 9999 10000 if (wdev->cac_started) { 10001 err = -EBUSY; 10002 goto unlock; 10003 } 10004 10005 /* CAC start is offloaded to HW and can't be started manually */ 10006 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) { 10007 err = -EOPNOTSUPP; 10008 goto unlock; 10009 } 10010 10011 if (!rdev->ops->start_radar_detection) { 10012 err = -EOPNOTSUPP; 10013 goto unlock; 10014 } 10015 10016 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 10017 if (WARN_ON(!cac_time_ms)) 10018 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 10019 10020 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 10021 if (!err) { 10022 wdev->links[0].ap.chandef = chandef; 10023 wdev->cac_started = true; 10024 wdev->cac_start_time = jiffies; 10025 wdev->cac_time_ms = cac_time_ms; 10026 } 10027 unlock: 10028 wiphy_unlock(wiphy); 10029 10030 return err; 10031 } 10032 10033 static int nl80211_notify_radar_detection(struct sk_buff *skb, 10034 struct genl_info *info) 10035 { 10036 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10037 struct net_device *dev = info->user_ptr[1]; 10038 struct wireless_dev *wdev = dev->ieee80211_ptr; 10039 struct wiphy *wiphy = wdev->wiphy; 10040 struct cfg80211_chan_def chandef; 10041 enum nl80211_dfs_regions dfs_region; 10042 int err; 10043 10044 dfs_region = reg_get_dfs_region(wiphy); 10045 if (dfs_region == NL80211_DFS_UNSET) { 10046 GENL_SET_ERR_MSG(info, 10047 "DFS Region is not set. Unexpected Radar indication"); 10048 return -EINVAL; 10049 } 10050 10051 err = nl80211_parse_chandef(rdev, info, &chandef); 10052 if (err) { 10053 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 10054 return err; 10055 } 10056 10057 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 10058 if (err < 0) { 10059 GENL_SET_ERR_MSG(info, "chandef is invalid"); 10060 return err; 10061 } 10062 10063 if (err == 0) { 10064 GENL_SET_ERR_MSG(info, 10065 "Unexpected Radar indication for chandef/iftype"); 10066 return -EINVAL; 10067 } 10068 10069 /* Do not process this notification if radar is already detected 10070 * by kernel on this channel, and return success. 10071 */ 10072 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 10073 return 0; 10074 10075 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 10076 10077 cfg80211_sched_dfs_chan_update(rdev); 10078 10079 rdev->radar_chandef = chandef; 10080 10081 /* Propagate this notification to other radios as well */ 10082 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 10083 10084 return 0; 10085 } 10086 10087 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 10088 { 10089 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10090 unsigned int link_id = nl80211_link_id(info->attrs); 10091 struct net_device *dev = info->user_ptr[1]; 10092 struct wireless_dev *wdev = dev->ieee80211_ptr; 10093 struct cfg80211_csa_settings params; 10094 struct nlattr **csa_attrs = NULL; 10095 int err; 10096 bool need_new_beacon = false; 10097 bool need_handle_dfs_flag = true; 10098 int len, i; 10099 u32 cs_count; 10100 10101 if (!rdev->ops->channel_switch || 10102 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 10103 return -EOPNOTSUPP; 10104 10105 switch (dev->ieee80211_ptr->iftype) { 10106 case NL80211_IFTYPE_AP: 10107 case NL80211_IFTYPE_P2P_GO: 10108 need_new_beacon = true; 10109 /* For all modes except AP the handle_dfs flag needs to be 10110 * supplied to tell the kernel that userspace will handle radar 10111 * events when they happen. Otherwise a switch to a channel 10112 * requiring DFS will be rejected. 10113 */ 10114 need_handle_dfs_flag = false; 10115 10116 /* useless if AP is not running */ 10117 if (!wdev->links[link_id].ap.beacon_interval) 10118 return -ENOTCONN; 10119 break; 10120 case NL80211_IFTYPE_ADHOC: 10121 if (!wdev->u.ibss.ssid_len) 10122 return -ENOTCONN; 10123 break; 10124 case NL80211_IFTYPE_MESH_POINT: 10125 if (!wdev->u.mesh.id_len) 10126 return -ENOTCONN; 10127 break; 10128 default: 10129 return -EOPNOTSUPP; 10130 } 10131 10132 memset(¶ms, 0, sizeof(params)); 10133 params.beacon_csa.ftm_responder = -1; 10134 10135 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 10136 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 10137 return -EINVAL; 10138 10139 /* only important for AP, IBSS and mesh create IEs internally */ 10140 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 10141 return -EINVAL; 10142 10143 /* Even though the attribute is u32, the specification says 10144 * u8, so let's make sure we don't overflow. 10145 */ 10146 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 10147 if (cs_count > 255) 10148 return -EINVAL; 10149 10150 params.count = cs_count; 10151 10152 if (!need_new_beacon) 10153 goto skip_beacons; 10154 10155 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after, 10156 info->extack); 10157 if (err) 10158 goto free; 10159 10160 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), 10161 GFP_KERNEL); 10162 if (!csa_attrs) { 10163 err = -ENOMEM; 10164 goto free; 10165 } 10166 10167 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 10168 info->attrs[NL80211_ATTR_CSA_IES], 10169 nl80211_policy, info->extack); 10170 if (err) 10171 goto free; 10172 10173 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa, 10174 info->extack); 10175 if (err) 10176 goto free; 10177 10178 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 10179 err = -EINVAL; 10180 goto free; 10181 } 10182 10183 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 10184 if (!len || (len % sizeof(u16))) { 10185 err = -EINVAL; 10186 goto free; 10187 } 10188 10189 params.n_counter_offsets_beacon = len / sizeof(u16); 10190 if (rdev->wiphy.max_num_csa_counters && 10191 (params.n_counter_offsets_beacon > 10192 rdev->wiphy.max_num_csa_counters)) { 10193 err = -EINVAL; 10194 goto free; 10195 } 10196 10197 params.counter_offsets_beacon = 10198 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 10199 10200 /* sanity checks - counters should fit and be the same */ 10201 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 10202 u16 offset = params.counter_offsets_beacon[i]; 10203 10204 if (offset >= params.beacon_csa.tail_len) { 10205 err = -EINVAL; 10206 goto free; 10207 } 10208 10209 if (params.beacon_csa.tail[offset] != params.count) { 10210 err = -EINVAL; 10211 goto free; 10212 } 10213 } 10214 10215 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 10216 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 10217 if (!len || (len % sizeof(u16))) { 10218 err = -EINVAL; 10219 goto free; 10220 } 10221 10222 params.n_counter_offsets_presp = len / sizeof(u16); 10223 if (rdev->wiphy.max_num_csa_counters && 10224 (params.n_counter_offsets_presp > 10225 rdev->wiphy.max_num_csa_counters)) { 10226 err = -EINVAL; 10227 goto free; 10228 } 10229 10230 params.counter_offsets_presp = 10231 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 10232 10233 /* sanity checks - counters should fit and be the same */ 10234 for (i = 0; i < params.n_counter_offsets_presp; i++) { 10235 u16 offset = params.counter_offsets_presp[i]; 10236 10237 if (offset >= params.beacon_csa.probe_resp_len) { 10238 err = -EINVAL; 10239 goto free; 10240 } 10241 10242 if (params.beacon_csa.probe_resp[offset] != 10243 params.count) { 10244 err = -EINVAL; 10245 goto free; 10246 } 10247 } 10248 } 10249 10250 skip_beacons: 10251 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 10252 if (err) 10253 goto free; 10254 10255 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 10256 wdev->iftype)) { 10257 err = -EINVAL; 10258 goto free; 10259 } 10260 10261 err = cfg80211_chandef_dfs_required(wdev->wiphy, 10262 ¶ms.chandef, 10263 wdev->iftype); 10264 if (err < 0) 10265 goto free; 10266 10267 if (err > 0) { 10268 params.radar_required = true; 10269 if (need_handle_dfs_flag && 10270 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 10271 err = -EINVAL; 10272 goto free; 10273 } 10274 } 10275 10276 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 10277 params.block_tx = true; 10278 10279 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) { 10280 err = nl80211_parse_punct_bitmap(rdev, info, 10281 ¶ms.chandef, 10282 ¶ms.punct_bitmap); 10283 if (err) 10284 goto free; 10285 } 10286 10287 wdev_lock(wdev); 10288 err = rdev_channel_switch(rdev, dev, ¶ms); 10289 wdev_unlock(wdev); 10290 10291 free: 10292 kfree(params.beacon_after.mbssid_ies); 10293 kfree(params.beacon_csa.mbssid_ies); 10294 kfree(params.beacon_after.rnr_ies); 10295 kfree(params.beacon_csa.rnr_ies); 10296 kfree(csa_attrs); 10297 return err; 10298 } 10299 10300 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 10301 u32 seq, int flags, 10302 struct cfg80211_registered_device *rdev, 10303 struct wireless_dev *wdev, 10304 struct cfg80211_internal_bss *intbss) 10305 { 10306 struct cfg80211_bss *res = &intbss->pub; 10307 const struct cfg80211_bss_ies *ies; 10308 unsigned int link_id; 10309 void *hdr; 10310 struct nlattr *bss; 10311 10312 ASSERT_WDEV_LOCK(wdev); 10313 10314 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 10315 NL80211_CMD_NEW_SCAN_RESULTS); 10316 if (!hdr) 10317 return -1; 10318 10319 genl_dump_check_consistent(cb, hdr); 10320 10321 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 10322 goto nla_put_failure; 10323 if (wdev->netdev && 10324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 10325 goto nla_put_failure; 10326 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 10327 NL80211_ATTR_PAD)) 10328 goto nla_put_failure; 10329 10330 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 10331 if (!bss) 10332 goto nla_put_failure; 10333 if ((!is_zero_ether_addr(res->bssid) && 10334 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 10335 goto nla_put_failure; 10336 10337 rcu_read_lock(); 10338 /* indicate whether we have probe response data or not */ 10339 if (rcu_access_pointer(res->proberesp_ies) && 10340 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 10341 goto fail_unlock_rcu; 10342 10343 /* this pointer prefers to be pointed to probe response data 10344 * but is always valid 10345 */ 10346 ies = rcu_dereference(res->ies); 10347 if (ies) { 10348 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 10349 NL80211_BSS_PAD)) 10350 goto fail_unlock_rcu; 10351 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 10352 ies->len, ies->data)) 10353 goto fail_unlock_rcu; 10354 } 10355 10356 /* and this pointer is always (unless driver didn't know) beacon data */ 10357 ies = rcu_dereference(res->beacon_ies); 10358 if (ies && ies->from_beacon) { 10359 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 10360 NL80211_BSS_PAD)) 10361 goto fail_unlock_rcu; 10362 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 10363 ies->len, ies->data)) 10364 goto fail_unlock_rcu; 10365 } 10366 rcu_read_unlock(); 10367 10368 if (res->beacon_interval && 10369 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 10370 goto nla_put_failure; 10371 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 10372 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 10373 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, 10374 res->channel->freq_offset) || 10375 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || 10376 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 10377 jiffies_to_msecs(jiffies - intbss->ts))) 10378 goto nla_put_failure; 10379 10380 if (intbss->parent_tsf && 10381 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 10382 intbss->parent_tsf, NL80211_BSS_PAD) || 10383 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 10384 intbss->parent_bssid))) 10385 goto nla_put_failure; 10386 10387 if (intbss->ts_boottime && 10388 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 10389 intbss->ts_boottime, NL80211_BSS_PAD)) 10390 goto nla_put_failure; 10391 10392 if (!nl80211_put_signal(msg, intbss->pub.chains, 10393 intbss->pub.chain_signal, 10394 NL80211_BSS_CHAIN_SIGNAL)) 10395 goto nla_put_failure; 10396 10397 switch (rdev->wiphy.signal_type) { 10398 case CFG80211_SIGNAL_TYPE_MBM: 10399 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 10400 goto nla_put_failure; 10401 break; 10402 case CFG80211_SIGNAL_TYPE_UNSPEC: 10403 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 10404 goto nla_put_failure; 10405 break; 10406 default: 10407 break; 10408 } 10409 10410 switch (wdev->iftype) { 10411 case NL80211_IFTYPE_P2P_CLIENT: 10412 case NL80211_IFTYPE_STATION: 10413 for_each_valid_link(wdev, link_id) { 10414 if (intbss == wdev->links[link_id].client.current_bss && 10415 (nla_put_u32(msg, NL80211_BSS_STATUS, 10416 NL80211_BSS_STATUS_ASSOCIATED) || 10417 (wdev->valid_links && 10418 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID, 10419 link_id) || 10420 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN, 10421 wdev->u.client.connected_addr))))) 10422 goto nla_put_failure; 10423 } 10424 break; 10425 case NL80211_IFTYPE_ADHOC: 10426 if (intbss == wdev->u.ibss.current_bss && 10427 nla_put_u32(msg, NL80211_BSS_STATUS, 10428 NL80211_BSS_STATUS_IBSS_JOINED)) 10429 goto nla_put_failure; 10430 break; 10431 default: 10432 break; 10433 } 10434 10435 nla_nest_end(msg, bss); 10436 10437 genlmsg_end(msg, hdr); 10438 return 0; 10439 10440 fail_unlock_rcu: 10441 rcu_read_unlock(); 10442 nla_put_failure: 10443 genlmsg_cancel(msg, hdr); 10444 return -EMSGSIZE; 10445 } 10446 10447 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 10448 { 10449 struct cfg80211_registered_device *rdev; 10450 struct cfg80211_internal_bss *scan; 10451 struct wireless_dev *wdev; 10452 int start = cb->args[2], idx = 0; 10453 int err; 10454 10455 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 10456 if (err) 10457 return err; 10458 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10459 __acquire(&rdev->wiphy.mtx); 10460 10461 wdev_lock(wdev); 10462 spin_lock_bh(&rdev->bss_lock); 10463 10464 /* 10465 * dump_scan will be called multiple times to break up the scan results 10466 * into multiple messages. It is unlikely that any more bss-es will be 10467 * expired after the first call, so only call only call this on the 10468 * first dump_scan invocation. 10469 */ 10470 if (start == 0) 10471 cfg80211_bss_expire(rdev); 10472 10473 cb->seq = rdev->bss_generation; 10474 10475 list_for_each_entry(scan, &rdev->bss_list, list) { 10476 if (++idx <= start) 10477 continue; 10478 if (nl80211_send_bss(skb, cb, 10479 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10480 rdev, wdev, scan) < 0) { 10481 idx--; 10482 break; 10483 } 10484 } 10485 10486 spin_unlock_bh(&rdev->bss_lock); 10487 wdev_unlock(wdev); 10488 10489 cb->args[2] = idx; 10490 wiphy_unlock(&rdev->wiphy); 10491 10492 return skb->len; 10493 } 10494 10495 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 10496 int flags, struct net_device *dev, 10497 bool allow_radio_stats, 10498 struct survey_info *survey) 10499 { 10500 void *hdr; 10501 struct nlattr *infoattr; 10502 10503 /* skip radio stats if userspace didn't request them */ 10504 if (!survey->channel && !allow_radio_stats) 10505 return 0; 10506 10507 hdr = nl80211hdr_put(msg, portid, seq, flags, 10508 NL80211_CMD_NEW_SURVEY_RESULTS); 10509 if (!hdr) 10510 return -ENOMEM; 10511 10512 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 10513 goto nla_put_failure; 10514 10515 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 10516 if (!infoattr) 10517 goto nla_put_failure; 10518 10519 if (survey->channel && 10520 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 10521 survey->channel->center_freq)) 10522 goto nla_put_failure; 10523 10524 if (survey->channel && survey->channel->freq_offset && 10525 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, 10526 survey->channel->freq_offset)) 10527 goto nla_put_failure; 10528 10529 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 10530 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 10531 goto nla_put_failure; 10532 if ((survey->filled & SURVEY_INFO_IN_USE) && 10533 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 10534 goto nla_put_failure; 10535 if ((survey->filled & SURVEY_INFO_TIME) && 10536 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 10537 survey->time, NL80211_SURVEY_INFO_PAD)) 10538 goto nla_put_failure; 10539 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 10540 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 10541 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 10542 goto nla_put_failure; 10543 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 10544 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 10545 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 10546 goto nla_put_failure; 10547 if ((survey->filled & SURVEY_INFO_TIME_RX) && 10548 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 10549 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 10550 goto nla_put_failure; 10551 if ((survey->filled & SURVEY_INFO_TIME_TX) && 10552 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 10553 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 10554 goto nla_put_failure; 10555 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 10556 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 10557 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 10558 goto nla_put_failure; 10559 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && 10560 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, 10561 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) 10562 goto nla_put_failure; 10563 10564 nla_nest_end(msg, infoattr); 10565 10566 genlmsg_end(msg, hdr); 10567 return 0; 10568 10569 nla_put_failure: 10570 genlmsg_cancel(msg, hdr); 10571 return -EMSGSIZE; 10572 } 10573 10574 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 10575 { 10576 struct nlattr **attrbuf; 10577 struct survey_info survey; 10578 struct cfg80211_registered_device *rdev; 10579 struct wireless_dev *wdev; 10580 int survey_idx = cb->args[2]; 10581 int res; 10582 bool radio_stats; 10583 10584 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 10585 if (!attrbuf) 10586 return -ENOMEM; 10587 10588 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); 10589 if (res) { 10590 kfree(attrbuf); 10591 return res; 10592 } 10593 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10594 __acquire(&rdev->wiphy.mtx); 10595 10596 /* prepare_wdev_dump parsed the attributes */ 10597 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 10598 10599 if (!wdev->netdev) { 10600 res = -EINVAL; 10601 goto out_err; 10602 } 10603 10604 if (!rdev->ops->dump_survey) { 10605 res = -EOPNOTSUPP; 10606 goto out_err; 10607 } 10608 10609 while (1) { 10610 wdev_lock(wdev); 10611 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 10612 wdev_unlock(wdev); 10613 if (res == -ENOENT) 10614 break; 10615 if (res) 10616 goto out_err; 10617 10618 /* don't send disabled channels, but do send non-channel data */ 10619 if (survey.channel && 10620 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 10621 survey_idx++; 10622 continue; 10623 } 10624 10625 if (nl80211_send_survey(skb, 10626 NETLINK_CB(cb->skb).portid, 10627 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10628 wdev->netdev, radio_stats, &survey) < 0) 10629 goto out; 10630 survey_idx++; 10631 } 10632 10633 out: 10634 cb->args[2] = survey_idx; 10635 res = skb->len; 10636 out_err: 10637 kfree(attrbuf); 10638 wiphy_unlock(&rdev->wiphy); 10639 return res; 10640 } 10641 10642 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 10643 { 10644 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 10645 NL80211_WPA_VERSION_2 | 10646 NL80211_WPA_VERSION_3)); 10647 } 10648 10649 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 10650 { 10651 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10652 struct net_device *dev = info->user_ptr[1]; 10653 struct ieee80211_channel *chan; 10654 const u8 *bssid, *ssid; 10655 int err, ssid_len; 10656 enum nl80211_auth_type auth_type; 10657 struct key_parse key; 10658 bool local_state_change; 10659 struct cfg80211_auth_request req = {}; 10660 u32 freq; 10661 10662 if (!info->attrs[NL80211_ATTR_MAC]) 10663 return -EINVAL; 10664 10665 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 10666 return -EINVAL; 10667 10668 if (!info->attrs[NL80211_ATTR_SSID]) 10669 return -EINVAL; 10670 10671 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10672 return -EINVAL; 10673 10674 err = nl80211_parse_key(info, &key); 10675 if (err) 10676 return err; 10677 10678 if (key.idx >= 0) { 10679 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 10680 return -EINVAL; 10681 if (!key.p.key || !key.p.key_len) 10682 return -EINVAL; 10683 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 10684 key.p.key_len != WLAN_KEY_LEN_WEP40) && 10685 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 10686 key.p.key_len != WLAN_KEY_LEN_WEP104)) 10687 return -EINVAL; 10688 if (key.idx > 3) 10689 return -EINVAL; 10690 } else { 10691 key.p.key_len = 0; 10692 key.p.key = NULL; 10693 } 10694 10695 if (key.idx >= 0) { 10696 int i; 10697 bool ok = false; 10698 10699 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 10700 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 10701 ok = true; 10702 break; 10703 } 10704 } 10705 if (!ok) 10706 return -EINVAL; 10707 } 10708 10709 if (!rdev->ops->auth) 10710 return -EOPNOTSUPP; 10711 10712 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10713 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10714 return -EOPNOTSUPP; 10715 10716 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10717 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 10718 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10719 freq += 10720 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10721 10722 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10723 if (!chan) 10724 return -EINVAL; 10725 10726 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10727 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10728 10729 if (info->attrs[NL80211_ATTR_IE]) { 10730 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10731 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10732 } 10733 10734 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10735 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 10736 return -EINVAL; 10737 10738 if ((auth_type == NL80211_AUTHTYPE_SAE || 10739 auth_type == NL80211_AUTHTYPE_FILS_SK || 10740 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 10741 auth_type == NL80211_AUTHTYPE_FILS_PK) && 10742 !info->attrs[NL80211_ATTR_AUTH_DATA]) 10743 return -EINVAL; 10744 10745 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 10746 if (auth_type != NL80211_AUTHTYPE_SAE && 10747 auth_type != NL80211_AUTHTYPE_FILS_SK && 10748 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 10749 auth_type != NL80211_AUTHTYPE_FILS_PK) 10750 return -EINVAL; 10751 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 10752 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 10753 } 10754 10755 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 10756 10757 /* 10758 * Since we no longer track auth state, ignore 10759 * requests to only change local state. 10760 */ 10761 if (local_state_change) 10762 return 0; 10763 10764 req.auth_type = auth_type; 10765 req.key = key.p.key; 10766 req.key_len = key.p.key_len; 10767 req.key_idx = key.idx; 10768 req.link_id = nl80211_link_id_or_invalid(info->attrs); 10769 if (req.link_id >= 0) { 10770 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 10771 return -EINVAL; 10772 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 10773 return -EINVAL; 10774 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 10775 if (!is_valid_ether_addr(req.ap_mld_addr)) 10776 return -EINVAL; 10777 } 10778 10779 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, 10780 IEEE80211_BSS_TYPE_ESS, 10781 IEEE80211_PRIVACY_ANY); 10782 if (!req.bss) 10783 return -ENOENT; 10784 10785 wdev_lock(dev->ieee80211_ptr); 10786 err = cfg80211_mlme_auth(rdev, dev, &req); 10787 wdev_unlock(dev->ieee80211_ptr); 10788 10789 cfg80211_put_bss(&rdev->wiphy, req.bss); 10790 10791 return err; 10792 } 10793 10794 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 10795 struct genl_info *info) 10796 { 10797 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10798 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 10799 return -EINVAL; 10800 } 10801 10802 if (!rdev->ops->tx_control_port || 10803 !wiphy_ext_feature_isset(&rdev->wiphy, 10804 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 10805 return -EOPNOTSUPP; 10806 10807 return 0; 10808 } 10809 10810 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 10811 struct genl_info *info, 10812 struct cfg80211_crypto_settings *settings, 10813 int cipher_limit) 10814 { 10815 memset(settings, 0, sizeof(*settings)); 10816 10817 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 10818 10819 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 10820 u16 proto; 10821 10822 proto = nla_get_u16( 10823 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 10824 settings->control_port_ethertype = cpu_to_be16(proto); 10825 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 10826 proto != ETH_P_PAE) 10827 return -EINVAL; 10828 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 10829 settings->control_port_no_encrypt = true; 10830 } else 10831 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 10832 10833 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 10834 int r = validate_pae_over_nl80211(rdev, info); 10835 10836 if (r < 0) 10837 return r; 10838 10839 settings->control_port_over_nl80211 = true; 10840 10841 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) 10842 settings->control_port_no_preauth = true; 10843 } 10844 10845 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 10846 void *data; 10847 int len, i; 10848 10849 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10850 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10851 settings->n_ciphers_pairwise = len / sizeof(u32); 10852 10853 if (len % sizeof(u32)) 10854 return -EINVAL; 10855 10856 if (settings->n_ciphers_pairwise > cipher_limit) 10857 return -EINVAL; 10858 10859 memcpy(settings->ciphers_pairwise, data, len); 10860 10861 for (i = 0; i < settings->n_ciphers_pairwise; i++) 10862 if (!cfg80211_supported_cipher_suite( 10863 &rdev->wiphy, 10864 settings->ciphers_pairwise[i])) 10865 return -EINVAL; 10866 } 10867 10868 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 10869 settings->cipher_group = 10870 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 10871 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 10872 settings->cipher_group)) 10873 return -EINVAL; 10874 } 10875 10876 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 10877 settings->wpa_versions = 10878 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 10879 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 10880 return -EINVAL; 10881 } 10882 10883 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 10884 void *data; 10885 int len; 10886 10887 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 10888 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 10889 settings->n_akm_suites = len / sizeof(u32); 10890 10891 if (len % sizeof(u32)) 10892 return -EINVAL; 10893 10894 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites) 10895 return -EINVAL; 10896 10897 memcpy(settings->akm_suites, data, len); 10898 } 10899 10900 if (info->attrs[NL80211_ATTR_PMK]) { 10901 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 10902 return -EINVAL; 10903 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10904 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && 10905 !wiphy_ext_feature_isset(&rdev->wiphy, 10906 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) 10907 return -EINVAL; 10908 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 10909 } 10910 10911 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 10912 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10913 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 10914 !wiphy_ext_feature_isset(&rdev->wiphy, 10915 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) 10916 return -EINVAL; 10917 settings->sae_pwd = 10918 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10919 settings->sae_pwd_len = 10920 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10921 } 10922 10923 if (info->attrs[NL80211_ATTR_SAE_PWE]) 10924 settings->sae_pwe = 10925 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); 10926 else 10927 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; 10928 10929 return 0; 10930 } 10931 10932 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev, 10933 const u8 *ssid, int ssid_len, 10934 struct nlattr **attrs) 10935 { 10936 struct ieee80211_channel *chan; 10937 struct cfg80211_bss *bss; 10938 const u8 *bssid; 10939 u32 freq; 10940 10941 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ]) 10942 return ERR_PTR(-EINVAL); 10943 10944 bssid = nla_data(attrs[NL80211_ATTR_MAC]); 10945 10946 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ])); 10947 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10948 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10949 10950 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10951 if (!chan) 10952 return ERR_PTR(-EINVAL); 10953 10954 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, 10955 ssid, ssid_len, 10956 IEEE80211_BSS_TYPE_ESS, 10957 IEEE80211_PRIVACY_ANY); 10958 if (!bss) 10959 return ERR_PTR(-ENOENT); 10960 10961 return bss; 10962 } 10963 10964 static int nl80211_associate(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 struct cfg80211_assoc_request req = {}; 10969 struct nlattr **attrs = NULL; 10970 const u8 *ap_addr, *ssid; 10971 unsigned int link_id; 10972 int err, ssid_len; 10973 10974 if (dev->ieee80211_ptr->conn_owner_nlportid && 10975 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10976 return -EPERM; 10977 10978 if (!info->attrs[NL80211_ATTR_SSID]) 10979 return -EINVAL; 10980 10981 if (!rdev->ops->assoc) 10982 return -EOPNOTSUPP; 10983 10984 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10985 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10986 return -EOPNOTSUPP; 10987 10988 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10989 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10990 10991 if (info->attrs[NL80211_ATTR_IE]) { 10992 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10993 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10994 10995 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 10996 req.ie, req.ie_len)) { 10997 GENL_SET_ERR_MSG(info, 10998 "non-inheritance makes no sense"); 10999 return -EINVAL; 11000 } 11001 } 11002 11003 if (info->attrs[NL80211_ATTR_USE_MFP]) { 11004 enum nl80211_mfp mfp = 11005 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 11006 if (mfp == NL80211_MFP_REQUIRED) 11007 req.use_mfp = true; 11008 else if (mfp != NL80211_MFP_NO) 11009 return -EINVAL; 11010 } 11011 11012 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 11013 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 11014 11015 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 11016 req.flags |= ASSOC_REQ_DISABLE_HT; 11017 11018 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11019 memcpy(&req.ht_capa_mask, 11020 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11021 sizeof(req.ht_capa_mask)); 11022 11023 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11024 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11025 return -EINVAL; 11026 memcpy(&req.ht_capa, 11027 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11028 sizeof(req.ht_capa)); 11029 } 11030 11031 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 11032 req.flags |= ASSOC_REQ_DISABLE_VHT; 11033 11034 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 11035 req.flags |= ASSOC_REQ_DISABLE_HE; 11036 11037 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 11038 req.flags |= ASSOC_REQ_DISABLE_EHT; 11039 11040 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11041 memcpy(&req.vht_capa_mask, 11042 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 11043 sizeof(req.vht_capa_mask)); 11044 11045 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 11046 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11047 return -EINVAL; 11048 memcpy(&req.vht_capa, 11049 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 11050 sizeof(req.vht_capa)); 11051 } 11052 11053 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 11054 if (!((rdev->wiphy.features & 11055 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 11056 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 11057 !wiphy_ext_feature_isset(&rdev->wiphy, 11058 NL80211_EXT_FEATURE_RRM)) 11059 return -EINVAL; 11060 req.flags |= ASSOC_REQ_USE_RRM; 11061 } 11062 11063 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 11064 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 11065 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 11066 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 11067 return -EINVAL; 11068 req.fils_nonces = 11069 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 11070 } 11071 11072 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { 11073 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) 11074 return -EINVAL; 11075 memcpy(&req.s1g_capa_mask, 11076 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), 11077 sizeof(req.s1g_capa_mask)); 11078 } 11079 11080 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { 11081 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) 11082 return -EINVAL; 11083 memcpy(&req.s1g_capa, 11084 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), 11085 sizeof(req.s1g_capa)); 11086 } 11087 11088 req.link_id = nl80211_link_id_or_invalid(info->attrs); 11089 11090 if (info->attrs[NL80211_ATTR_MLO_LINKS]) { 11091 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs); 11092 struct nlattr *link; 11093 int rem = 0; 11094 11095 if (req.link_id < 0) 11096 return -EINVAL; 11097 11098 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 11099 return -EINVAL; 11100 11101 if (info->attrs[NL80211_ATTR_MAC] || 11102 info->attrs[NL80211_ATTR_WIPHY_FREQ] || 11103 !info->attrs[NL80211_ATTR_MLD_ADDR]) 11104 return -EINVAL; 11105 11106 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 11107 ap_addr = req.ap_mld_addr; 11108 11109 attrs = kzalloc(attrsize, GFP_KERNEL); 11110 if (!attrs) 11111 return -ENOMEM; 11112 11113 nla_for_each_nested(link, 11114 info->attrs[NL80211_ATTR_MLO_LINKS], 11115 rem) { 11116 memset(attrs, 0, attrsize); 11117 11118 nla_parse_nested(attrs, NL80211_ATTR_MAX, 11119 link, NULL, NULL); 11120 11121 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) { 11122 err = -EINVAL; 11123 goto free; 11124 } 11125 11126 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]); 11127 /* cannot use the same link ID again */ 11128 if (req.links[link_id].bss) { 11129 err = -EINVAL; 11130 goto free; 11131 } 11132 req.links[link_id].bss = 11133 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs); 11134 if (IS_ERR(req.links[link_id].bss)) { 11135 err = PTR_ERR(req.links[link_id].bss); 11136 req.links[link_id].bss = NULL; 11137 goto free; 11138 } 11139 11140 if (attrs[NL80211_ATTR_IE]) { 11141 req.links[link_id].elems = 11142 nla_data(attrs[NL80211_ATTR_IE]); 11143 req.links[link_id].elems_len = 11144 nla_len(attrs[NL80211_ATTR_IE]); 11145 11146 if (cfg80211_find_elem(WLAN_EID_FRAGMENT, 11147 req.links[link_id].elems, 11148 req.links[link_id].elems_len)) { 11149 GENL_SET_ERR_MSG(info, 11150 "cannot deal with fragmentation"); 11151 err = -EINVAL; 11152 goto free; 11153 } 11154 11155 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 11156 req.links[link_id].elems, 11157 req.links[link_id].elems_len)) { 11158 GENL_SET_ERR_MSG(info, 11159 "cannot deal with non-inheritance"); 11160 err = -EINVAL; 11161 goto free; 11162 } 11163 } 11164 11165 req.links[link_id].disabled = 11166 nla_get_flag(attrs[NL80211_ATTR_MLO_LINK_DISABLED]); 11167 } 11168 11169 if (!req.links[req.link_id].bss) { 11170 err = -EINVAL; 11171 goto free; 11172 } 11173 11174 if (req.links[req.link_id].elems_len) { 11175 GENL_SET_ERR_MSG(info, 11176 "cannot have per-link elems on assoc link"); 11177 err = -EINVAL; 11178 goto free; 11179 } 11180 11181 if (req.links[req.link_id].disabled) { 11182 GENL_SET_ERR_MSG(info, 11183 "cannot have assoc link disabled"); 11184 err = -EINVAL; 11185 goto free; 11186 } 11187 11188 kfree(attrs); 11189 attrs = NULL; 11190 } else { 11191 if (req.link_id >= 0) 11192 return -EINVAL; 11193 11194 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs); 11195 if (IS_ERR(req.bss)) 11196 return PTR_ERR(req.bss); 11197 ap_addr = req.bss->bssid; 11198 } 11199 11200 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 11201 if (!err) { 11202 wdev_lock(dev->ieee80211_ptr); 11203 11204 err = cfg80211_mlme_assoc(rdev, dev, &req); 11205 11206 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 11207 dev->ieee80211_ptr->conn_owner_nlportid = 11208 info->snd_portid; 11209 memcpy(dev->ieee80211_ptr->disconnect_bssid, 11210 ap_addr, ETH_ALEN); 11211 } 11212 11213 wdev_unlock(dev->ieee80211_ptr); 11214 } 11215 11216 free: 11217 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++) 11218 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss); 11219 cfg80211_put_bss(&rdev->wiphy, req.bss); 11220 kfree(attrs); 11221 11222 return err; 11223 } 11224 11225 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 11226 { 11227 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11228 struct net_device *dev = info->user_ptr[1]; 11229 const u8 *ie = NULL, *bssid; 11230 int ie_len = 0, err; 11231 u16 reason_code; 11232 bool local_state_change; 11233 11234 if (dev->ieee80211_ptr->conn_owner_nlportid && 11235 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11236 return -EPERM; 11237 11238 if (!info->attrs[NL80211_ATTR_MAC]) 11239 return -EINVAL; 11240 11241 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11242 return -EINVAL; 11243 11244 if (!rdev->ops->deauth) 11245 return -EOPNOTSUPP; 11246 11247 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11248 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11249 return -EOPNOTSUPP; 11250 11251 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11252 11253 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11254 if (reason_code == 0) { 11255 /* Reason Code 0 is reserved */ 11256 return -EINVAL; 11257 } 11258 11259 if (info->attrs[NL80211_ATTR_IE]) { 11260 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11261 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11262 } 11263 11264 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11265 11266 wdev_lock(dev->ieee80211_ptr); 11267 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 11268 local_state_change); 11269 wdev_unlock(dev->ieee80211_ptr); 11270 return err; 11271 } 11272 11273 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 11274 { 11275 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11276 struct net_device *dev = info->user_ptr[1]; 11277 const u8 *ie = NULL, *bssid; 11278 int ie_len = 0, err; 11279 u16 reason_code; 11280 bool local_state_change; 11281 11282 if (dev->ieee80211_ptr->conn_owner_nlportid && 11283 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11284 return -EPERM; 11285 11286 if (!info->attrs[NL80211_ATTR_MAC]) 11287 return -EINVAL; 11288 11289 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11290 return -EINVAL; 11291 11292 if (!rdev->ops->disassoc) 11293 return -EOPNOTSUPP; 11294 11295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11297 return -EOPNOTSUPP; 11298 11299 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11300 11301 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11302 if (reason_code == 0) { 11303 /* Reason Code 0 is reserved */ 11304 return -EINVAL; 11305 } 11306 11307 if (info->attrs[NL80211_ATTR_IE]) { 11308 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11309 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11310 } 11311 11312 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11313 11314 wdev_lock(dev->ieee80211_ptr); 11315 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 11316 local_state_change); 11317 wdev_unlock(dev->ieee80211_ptr); 11318 return err; 11319 } 11320 11321 static bool 11322 nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, 11323 int mcast_rate[NUM_NL80211_BANDS], 11324 int rateval) 11325 { 11326 struct wiphy *wiphy = &rdev->wiphy; 11327 bool found = false; 11328 int band, i; 11329 11330 for (band = 0; band < NUM_NL80211_BANDS; band++) { 11331 struct ieee80211_supported_band *sband; 11332 11333 sband = wiphy->bands[band]; 11334 if (!sband) 11335 continue; 11336 11337 for (i = 0; i < sband->n_bitrates; i++) { 11338 if (sband->bitrates[i].bitrate == rateval) { 11339 mcast_rate[band] = i + 1; 11340 found = true; 11341 break; 11342 } 11343 } 11344 } 11345 11346 return found; 11347 } 11348 11349 static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) 11350 { 11351 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11352 struct net_device *dev = info->user_ptr[1]; 11353 struct cfg80211_ibss_params ibss; 11354 struct wiphy *wiphy; 11355 struct cfg80211_cached_keys *connkeys = NULL; 11356 int err; 11357 11358 memset(&ibss, 0, sizeof(ibss)); 11359 11360 if (!info->attrs[NL80211_ATTR_SSID] || 11361 !nla_len(info->attrs[NL80211_ATTR_SSID])) 11362 return -EINVAL; 11363 11364 ibss.beacon_interval = 100; 11365 11366 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) 11367 ibss.beacon_interval = 11368 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 11369 11370 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, 11371 ibss.beacon_interval); 11372 if (err) 11373 return err; 11374 11375 if (!rdev->ops->join_ibss) 11376 return -EOPNOTSUPP; 11377 11378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 11379 return -EOPNOTSUPP; 11380 11381 wiphy = &rdev->wiphy; 11382 11383 if (info->attrs[NL80211_ATTR_MAC]) { 11384 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11385 11386 if (!is_valid_ether_addr(ibss.bssid)) 11387 return -EINVAL; 11388 } 11389 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11390 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11391 11392 if (info->attrs[NL80211_ATTR_IE]) { 11393 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11394 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11395 } 11396 11397 err = nl80211_parse_chandef(rdev, info, &ibss.chandef); 11398 if (err) 11399 return err; 11400 11401 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, 11402 NL80211_IFTYPE_ADHOC)) 11403 return -EINVAL; 11404 11405 switch (ibss.chandef.width) { 11406 case NL80211_CHAN_WIDTH_5: 11407 case NL80211_CHAN_WIDTH_10: 11408 case NL80211_CHAN_WIDTH_20_NOHT: 11409 break; 11410 case NL80211_CHAN_WIDTH_20: 11411 case NL80211_CHAN_WIDTH_40: 11412 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 11413 return -EINVAL; 11414 break; 11415 case NL80211_CHAN_WIDTH_80: 11416 case NL80211_CHAN_WIDTH_80P80: 11417 case NL80211_CHAN_WIDTH_160: 11418 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) 11419 return -EINVAL; 11420 if (!wiphy_ext_feature_isset(&rdev->wiphy, 11421 NL80211_EXT_FEATURE_VHT_IBSS)) 11422 return -EINVAL; 11423 break; 11424 case NL80211_CHAN_WIDTH_320: 11425 return -EINVAL; 11426 default: 11427 return -EINVAL; 11428 } 11429 11430 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 11431 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 11432 11433 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 11434 u8 *rates = 11435 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11436 int n_rates = 11437 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 11438 struct ieee80211_supported_band *sband = 11439 wiphy->bands[ibss.chandef.chan->band]; 11440 11441 err = ieee80211_get_ratemask(sband, rates, n_rates, 11442 &ibss.basic_rates); 11443 if (err) 11444 return err; 11445 } 11446 11447 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11448 memcpy(&ibss.ht_capa_mask, 11449 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11450 sizeof(ibss.ht_capa_mask)); 11451 11452 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11453 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11454 return -EINVAL; 11455 memcpy(&ibss.ht_capa, 11456 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11457 sizeof(ibss.ht_capa)); 11458 } 11459 11460 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 11461 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, 11462 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 11463 return -EINVAL; 11464 11465 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { 11466 bool no_ht = false; 11467 11468 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); 11469 if (IS_ERR(connkeys)) 11470 return PTR_ERR(connkeys); 11471 11472 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && 11473 no_ht) { 11474 kfree_sensitive(connkeys); 11475 return -EINVAL; 11476 } 11477 } 11478 11479 ibss.control_port = 11480 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); 11481 11482 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 11483 int r = validate_pae_over_nl80211(rdev, info); 11484 11485 if (r < 0) { 11486 kfree_sensitive(connkeys); 11487 return r; 11488 } 11489 11490 ibss.control_port_over_nl80211 = true; 11491 } 11492 11493 ibss.userspace_handles_dfs = 11494 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 11495 11496 wdev_lock(dev->ieee80211_ptr); 11497 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 11498 if (err) 11499 kfree_sensitive(connkeys); 11500 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 11501 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11502 wdev_unlock(dev->ieee80211_ptr); 11503 11504 return err; 11505 } 11506 11507 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 11508 { 11509 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11510 struct net_device *dev = info->user_ptr[1]; 11511 11512 if (!rdev->ops->leave_ibss) 11513 return -EOPNOTSUPP; 11514 11515 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 11516 return -EOPNOTSUPP; 11517 11518 return cfg80211_leave_ibss(rdev, dev, false); 11519 } 11520 11521 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 11522 { 11523 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11524 struct net_device *dev = info->user_ptr[1]; 11525 int mcast_rate[NUM_NL80211_BANDS]; 11526 u32 nla_rate; 11527 11528 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 11529 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 11530 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 11531 return -EOPNOTSUPP; 11532 11533 if (!rdev->ops->set_mcast_rate) 11534 return -EOPNOTSUPP; 11535 11536 memset(mcast_rate, 0, sizeof(mcast_rate)); 11537 11538 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 11539 return -EINVAL; 11540 11541 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 11542 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 11543 return -EINVAL; 11544 11545 return rdev_set_mcast_rate(rdev, dev, mcast_rate); 11546 } 11547 11548 static struct sk_buff * 11549 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 11550 struct wireless_dev *wdev, int approxlen, 11551 u32 portid, u32 seq, enum nl80211_commands cmd, 11552 enum nl80211_attrs attr, 11553 const struct nl80211_vendor_cmd_info *info, 11554 gfp_t gfp) 11555 { 11556 struct sk_buff *skb; 11557 void *hdr; 11558 struct nlattr *data; 11559 11560 skb = nlmsg_new(approxlen + 100, gfp); 11561 if (!skb) 11562 return NULL; 11563 11564 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 11565 if (!hdr) { 11566 kfree_skb(skb); 11567 return NULL; 11568 } 11569 11570 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 11571 goto nla_put_failure; 11572 11573 if (info) { 11574 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 11575 info->vendor_id)) 11576 goto nla_put_failure; 11577 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 11578 info->subcmd)) 11579 goto nla_put_failure; 11580 } 11581 11582 if (wdev) { 11583 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 11584 wdev_id(wdev), NL80211_ATTR_PAD)) 11585 goto nla_put_failure; 11586 if (wdev->netdev && 11587 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 11588 wdev->netdev->ifindex)) 11589 goto nla_put_failure; 11590 } 11591 11592 data = nla_nest_start_noflag(skb, attr); 11593 if (!data) 11594 goto nla_put_failure; 11595 11596 ((void **)skb->cb)[0] = rdev; 11597 ((void **)skb->cb)[1] = hdr; 11598 ((void **)skb->cb)[2] = data; 11599 11600 return skb; 11601 11602 nla_put_failure: 11603 kfree_skb(skb); 11604 return NULL; 11605 } 11606 11607 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 11608 struct wireless_dev *wdev, 11609 enum nl80211_commands cmd, 11610 enum nl80211_attrs attr, 11611 unsigned int portid, 11612 int vendor_event_idx, 11613 int approxlen, gfp_t gfp) 11614 { 11615 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 11616 const struct nl80211_vendor_cmd_info *info; 11617 11618 switch (cmd) { 11619 case NL80211_CMD_TESTMODE: 11620 if (WARN_ON(vendor_event_idx != -1)) 11621 return NULL; 11622 info = NULL; 11623 break; 11624 case NL80211_CMD_VENDOR: 11625 if (WARN_ON(vendor_event_idx < 0 || 11626 vendor_event_idx >= wiphy->n_vendor_events)) 11627 return NULL; 11628 info = &wiphy->vendor_events[vendor_event_idx]; 11629 break; 11630 default: 11631 WARN_ON(1); 11632 return NULL; 11633 } 11634 11635 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 11636 cmd, attr, info, gfp); 11637 } 11638 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 11639 11640 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 11641 { 11642 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 11643 void *hdr = ((void **)skb->cb)[1]; 11644 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 11645 struct nlattr *data = ((void **)skb->cb)[2]; 11646 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 11647 11648 /* clear CB data for netlink core to own from now on */ 11649 memset(skb->cb, 0, sizeof(skb->cb)); 11650 11651 nla_nest_end(skb, data); 11652 genlmsg_end(skb, hdr); 11653 11654 if (nlhdr->nlmsg_pid) { 11655 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 11656 nlhdr->nlmsg_pid); 11657 } else { 11658 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 11659 mcgrp = NL80211_MCGRP_VENDOR; 11660 11661 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 11662 skb, 0, mcgrp, gfp); 11663 } 11664 } 11665 EXPORT_SYMBOL(__cfg80211_send_event_skb); 11666 11667 #ifdef CONFIG_NL80211_TESTMODE 11668 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 11669 { 11670 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11671 struct wireless_dev *wdev; 11672 int err; 11673 11674 lockdep_assert_held(&rdev->wiphy.mtx); 11675 11676 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 11677 info->attrs); 11678 11679 if (!rdev->ops->testmode_cmd) 11680 return -EOPNOTSUPP; 11681 11682 if (IS_ERR(wdev)) { 11683 err = PTR_ERR(wdev); 11684 if (err != -EINVAL) 11685 return err; 11686 wdev = NULL; 11687 } else if (wdev->wiphy != &rdev->wiphy) { 11688 return -EINVAL; 11689 } 11690 11691 if (!info->attrs[NL80211_ATTR_TESTDATA]) 11692 return -EINVAL; 11693 11694 rdev->cur_cmd_info = info; 11695 err = rdev_testmode_cmd(rdev, wdev, 11696 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 11697 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 11698 rdev->cur_cmd_info = NULL; 11699 11700 return err; 11701 } 11702 11703 static int nl80211_testmode_dump(struct sk_buff *skb, 11704 struct netlink_callback *cb) 11705 { 11706 struct cfg80211_registered_device *rdev; 11707 struct nlattr **attrbuf = NULL; 11708 int err; 11709 long phy_idx; 11710 void *data = NULL; 11711 int data_len = 0; 11712 11713 rtnl_lock(); 11714 11715 if (cb->args[0]) { 11716 /* 11717 * 0 is a valid index, but not valid for args[0], 11718 * so we need to offset by 1. 11719 */ 11720 phy_idx = cb->args[0] - 1; 11721 11722 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 11723 if (!rdev) { 11724 err = -ENOENT; 11725 goto out_err; 11726 } 11727 } else { 11728 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 11729 GFP_KERNEL); 11730 if (!attrbuf) { 11731 err = -ENOMEM; 11732 goto out_err; 11733 } 11734 11735 err = nlmsg_parse_deprecated(cb->nlh, 11736 GENL_HDRLEN + nl80211_fam.hdrsize, 11737 attrbuf, nl80211_fam.maxattr, 11738 nl80211_policy, NULL); 11739 if (err) 11740 goto out_err; 11741 11742 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 11743 if (IS_ERR(rdev)) { 11744 err = PTR_ERR(rdev); 11745 goto out_err; 11746 } 11747 phy_idx = rdev->wiphy_idx; 11748 11749 if (attrbuf[NL80211_ATTR_TESTDATA]) 11750 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 11751 } 11752 11753 if (cb->args[1]) { 11754 data = nla_data((void *)cb->args[1]); 11755 data_len = nla_len((void *)cb->args[1]); 11756 } 11757 11758 if (!rdev->ops->testmode_dump) { 11759 err = -EOPNOTSUPP; 11760 goto out_err; 11761 } 11762 11763 while (1) { 11764 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 11765 cb->nlh->nlmsg_seq, NLM_F_MULTI, 11766 NL80211_CMD_TESTMODE); 11767 struct nlattr *tmdata; 11768 11769 if (!hdr) 11770 break; 11771 11772 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 11773 genlmsg_cancel(skb, hdr); 11774 break; 11775 } 11776 11777 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 11778 if (!tmdata) { 11779 genlmsg_cancel(skb, hdr); 11780 break; 11781 } 11782 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 11783 nla_nest_end(skb, tmdata); 11784 11785 if (err == -ENOBUFS || err == -ENOENT) { 11786 genlmsg_cancel(skb, hdr); 11787 break; 11788 } else if (err) { 11789 genlmsg_cancel(skb, hdr); 11790 goto out_err; 11791 } 11792 11793 genlmsg_end(skb, hdr); 11794 } 11795 11796 err = skb->len; 11797 /* see above */ 11798 cb->args[0] = phy_idx + 1; 11799 out_err: 11800 kfree(attrbuf); 11801 rtnl_unlock(); 11802 return err; 11803 } 11804 #endif 11805 11806 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 11807 { 11808 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11809 struct net_device *dev = info->user_ptr[1]; 11810 struct cfg80211_connect_params connect; 11811 struct wiphy *wiphy; 11812 struct cfg80211_cached_keys *connkeys = NULL; 11813 u32 freq = 0; 11814 int err; 11815 11816 memset(&connect, 0, sizeof(connect)); 11817 11818 if (!info->attrs[NL80211_ATTR_SSID] || 11819 !nla_len(info->attrs[NL80211_ATTR_SSID])) 11820 return -EINVAL; 11821 11822 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 11823 connect.auth_type = 11824 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 11825 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 11826 NL80211_CMD_CONNECT)) 11827 return -EINVAL; 11828 } else 11829 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 11830 11831 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 11832 11833 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 11834 !wiphy_ext_feature_isset(&rdev->wiphy, 11835 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 11836 return -EINVAL; 11837 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 11838 11839 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 11840 NL80211_MAX_NR_CIPHER_SUITES); 11841 if (err) 11842 return err; 11843 11844 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11845 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11846 return -EOPNOTSUPP; 11847 11848 wiphy = &rdev->wiphy; 11849 11850 connect.bg_scan_period = -1; 11851 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 11852 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 11853 connect.bg_scan_period = 11854 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 11855 } 11856 11857 if (info->attrs[NL80211_ATTR_MAC]) 11858 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11859 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 11860 connect.bssid_hint = 11861 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 11862 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11863 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11864 11865 if (info->attrs[NL80211_ATTR_IE]) { 11866 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11867 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11868 } 11869 11870 if (info->attrs[NL80211_ATTR_USE_MFP]) { 11871 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 11872 if (connect.mfp == NL80211_MFP_OPTIONAL && 11873 !wiphy_ext_feature_isset(&rdev->wiphy, 11874 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 11875 return -EOPNOTSUPP; 11876 } else { 11877 connect.mfp = NL80211_MFP_NO; 11878 } 11879 11880 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 11881 connect.prev_bssid = 11882 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 11883 11884 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) 11885 freq = MHZ_TO_KHZ(nla_get_u32( 11886 info->attrs[NL80211_ATTR_WIPHY_FREQ])); 11887 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 11888 freq += 11889 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 11890 11891 if (freq) { 11892 connect.channel = nl80211_get_valid_chan(wiphy, freq); 11893 if (!connect.channel) 11894 return -EINVAL; 11895 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 11896 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 11897 freq = MHZ_TO_KHZ(freq); 11898 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); 11899 if (!connect.channel_hint) 11900 return -EINVAL; 11901 } 11902 11903 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 11904 connect.edmg.channels = 11905 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 11906 11907 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 11908 connect.edmg.bw_config = 11909 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 11910 } 11911 11912 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 11913 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 11914 if (IS_ERR(connkeys)) 11915 return PTR_ERR(connkeys); 11916 } 11917 11918 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 11919 connect.flags |= ASSOC_REQ_DISABLE_HT; 11920 11921 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11922 memcpy(&connect.ht_capa_mask, 11923 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11924 sizeof(connect.ht_capa_mask)); 11925 11926 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11927 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 11928 kfree_sensitive(connkeys); 11929 return -EINVAL; 11930 } 11931 memcpy(&connect.ht_capa, 11932 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11933 sizeof(connect.ht_capa)); 11934 } 11935 11936 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 11937 connect.flags |= ASSOC_REQ_DISABLE_VHT; 11938 11939 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 11940 connect.flags |= ASSOC_REQ_DISABLE_HE; 11941 11942 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 11943 connect.flags |= ASSOC_REQ_DISABLE_EHT; 11944 11945 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11946 memcpy(&connect.vht_capa_mask, 11947 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 11948 sizeof(connect.vht_capa_mask)); 11949 11950 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 11951 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 11952 kfree_sensitive(connkeys); 11953 return -EINVAL; 11954 } 11955 memcpy(&connect.vht_capa, 11956 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 11957 sizeof(connect.vht_capa)); 11958 } 11959 11960 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 11961 if (!((rdev->wiphy.features & 11962 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 11963 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 11964 !wiphy_ext_feature_isset(&rdev->wiphy, 11965 NL80211_EXT_FEATURE_RRM)) { 11966 kfree_sensitive(connkeys); 11967 return -EINVAL; 11968 } 11969 connect.flags |= ASSOC_REQ_USE_RRM; 11970 } 11971 11972 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 11973 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 11974 kfree_sensitive(connkeys); 11975 return -EOPNOTSUPP; 11976 } 11977 11978 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 11979 /* bss selection makes no sense if bssid is set */ 11980 if (connect.bssid) { 11981 kfree_sensitive(connkeys); 11982 return -EINVAL; 11983 } 11984 11985 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 11986 wiphy, &connect.bss_select); 11987 if (err) { 11988 kfree_sensitive(connkeys); 11989 return err; 11990 } 11991 } 11992 11993 if (wiphy_ext_feature_isset(&rdev->wiphy, 11994 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 11995 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 11996 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 11997 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 11998 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11999 connect.fils_erp_username = 12000 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12001 connect.fils_erp_username_len = 12002 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12003 connect.fils_erp_realm = 12004 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12005 connect.fils_erp_realm_len = 12006 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12007 connect.fils_erp_next_seq_num = 12008 nla_get_u16( 12009 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 12010 connect.fils_erp_rrk = 12011 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12012 connect.fils_erp_rrk_len = 12013 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12014 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 12015 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 12016 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 12017 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12018 kfree_sensitive(connkeys); 12019 return -EINVAL; 12020 } 12021 12022 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 12023 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 12024 kfree_sensitive(connkeys); 12025 GENL_SET_ERR_MSG(info, 12026 "external auth requires connection ownership"); 12027 return -EINVAL; 12028 } 12029 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 12030 } 12031 12032 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT])) 12033 connect.flags |= CONNECT_REQ_MLO_SUPPORT; 12034 12035 wdev_lock(dev->ieee80211_ptr); 12036 12037 err = cfg80211_connect(rdev, dev, &connect, connkeys, 12038 connect.prev_bssid); 12039 if (err) 12040 kfree_sensitive(connkeys); 12041 12042 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 12043 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 12044 if (connect.bssid) 12045 memcpy(dev->ieee80211_ptr->disconnect_bssid, 12046 connect.bssid, ETH_ALEN); 12047 else 12048 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); 12049 } 12050 12051 wdev_unlock(dev->ieee80211_ptr); 12052 12053 return err; 12054 } 12055 12056 static int nl80211_update_connect_params(struct sk_buff *skb, 12057 struct genl_info *info) 12058 { 12059 struct cfg80211_connect_params connect = {}; 12060 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12061 struct net_device *dev = info->user_ptr[1]; 12062 struct wireless_dev *wdev = dev->ieee80211_ptr; 12063 bool fils_sk_offload; 12064 u32 auth_type; 12065 u32 changed = 0; 12066 int ret; 12067 12068 if (!rdev->ops->update_connect_params) 12069 return -EOPNOTSUPP; 12070 12071 if (info->attrs[NL80211_ATTR_IE]) { 12072 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 12073 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 12074 changed |= UPDATE_ASSOC_IES; 12075 } 12076 12077 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 12078 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 12079 12080 /* 12081 * when driver supports fils-sk offload all attributes must be 12082 * provided. So the else covers "fils-sk-not-all" and 12083 * "no-fils-sk-any". 12084 */ 12085 if (fils_sk_offload && 12086 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 12087 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 12088 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 12089 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12090 connect.fils_erp_username = 12091 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12092 connect.fils_erp_username_len = 12093 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12094 connect.fils_erp_realm = 12095 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12096 connect.fils_erp_realm_len = 12097 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12098 connect.fils_erp_next_seq_num = 12099 nla_get_u16( 12100 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 12101 connect.fils_erp_rrk = 12102 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12103 connect.fils_erp_rrk_len = 12104 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12105 changed |= UPDATE_FILS_ERP_INFO; 12106 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 12107 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 12108 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 12109 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12110 return -EINVAL; 12111 } 12112 12113 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 12114 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 12115 if (!nl80211_valid_auth_type(rdev, auth_type, 12116 NL80211_CMD_CONNECT)) 12117 return -EINVAL; 12118 12119 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 12120 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 12121 return -EINVAL; 12122 12123 connect.auth_type = auth_type; 12124 changed |= UPDATE_AUTH_TYPE; 12125 } 12126 12127 wdev_lock(dev->ieee80211_ptr); 12128 if (!wdev->connected) 12129 ret = -ENOLINK; 12130 else 12131 ret = rdev_update_connect_params(rdev, dev, &connect, changed); 12132 wdev_unlock(dev->ieee80211_ptr); 12133 12134 return ret; 12135 } 12136 12137 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 12138 { 12139 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12140 struct net_device *dev = info->user_ptr[1]; 12141 u16 reason; 12142 int ret; 12143 12144 if (dev->ieee80211_ptr->conn_owner_nlportid && 12145 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 12146 return -EPERM; 12147 12148 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 12149 reason = WLAN_REASON_DEAUTH_LEAVING; 12150 else 12151 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 12152 12153 if (reason == 0) 12154 return -EINVAL; 12155 12156 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12157 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 12158 return -EOPNOTSUPP; 12159 12160 wdev_lock(dev->ieee80211_ptr); 12161 ret = cfg80211_disconnect(rdev, dev, reason, true); 12162 wdev_unlock(dev->ieee80211_ptr); 12163 return ret; 12164 } 12165 12166 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 12167 { 12168 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12169 struct net *net; 12170 int err; 12171 12172 if (info->attrs[NL80211_ATTR_PID]) { 12173 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 12174 12175 net = get_net_ns_by_pid(pid); 12176 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 12177 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 12178 12179 net = get_net_ns_by_fd(fd); 12180 } else { 12181 return -EINVAL; 12182 } 12183 12184 if (IS_ERR(net)) 12185 return PTR_ERR(net); 12186 12187 err = 0; 12188 12189 /* check if anything to do */ 12190 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 12191 err = cfg80211_switch_netns(rdev, net); 12192 12193 put_net(net); 12194 return err; 12195 } 12196 12197 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 12198 { 12199 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12200 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 12201 struct cfg80211_pmksa *pmksa) = NULL; 12202 struct net_device *dev = info->user_ptr[1]; 12203 struct cfg80211_pmksa pmksa; 12204 12205 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 12206 12207 if (!info->attrs[NL80211_ATTR_PMKID]) 12208 return -EINVAL; 12209 12210 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 12211 12212 if (info->attrs[NL80211_ATTR_MAC]) { 12213 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 12214 } else if (info->attrs[NL80211_ATTR_SSID] && 12215 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 12216 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 12217 info->attrs[NL80211_ATTR_PMK])) { 12218 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 12219 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 12220 pmksa.cache_id = 12221 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 12222 } else { 12223 return -EINVAL; 12224 } 12225 if (info->attrs[NL80211_ATTR_PMK]) { 12226 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 12227 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 12228 } 12229 12230 if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) 12231 pmksa.pmk_lifetime = 12232 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); 12233 12234 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) 12235 pmksa.pmk_reauth_threshold = 12236 nla_get_u8( 12237 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); 12238 12239 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 12241 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 12242 wiphy_ext_feature_isset(&rdev->wiphy, 12243 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 12244 return -EOPNOTSUPP; 12245 12246 switch (info->genlhdr->cmd) { 12247 case NL80211_CMD_SET_PMKSA: 12248 rdev_ops = rdev->ops->set_pmksa; 12249 break; 12250 case NL80211_CMD_DEL_PMKSA: 12251 rdev_ops = rdev->ops->del_pmksa; 12252 break; 12253 default: 12254 WARN_ON(1); 12255 break; 12256 } 12257 12258 if (!rdev_ops) 12259 return -EOPNOTSUPP; 12260 12261 return rdev_ops(&rdev->wiphy, dev, &pmksa); 12262 } 12263 12264 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 12265 { 12266 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12267 struct net_device *dev = info->user_ptr[1]; 12268 12269 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12270 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 12271 return -EOPNOTSUPP; 12272 12273 if (!rdev->ops->flush_pmksa) 12274 return -EOPNOTSUPP; 12275 12276 return rdev_flush_pmksa(rdev, dev); 12277 } 12278 12279 static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) 12280 { 12281 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12282 struct net_device *dev = info->user_ptr[1]; 12283 u8 action_code, dialog_token; 12284 u32 peer_capability = 0; 12285 u16 status_code; 12286 u8 *peer; 12287 int link_id; 12288 bool initiator; 12289 12290 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12291 !rdev->ops->tdls_mgmt) 12292 return -EOPNOTSUPP; 12293 12294 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 12295 !info->attrs[NL80211_ATTR_STATUS_CODE] || 12296 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 12297 !info->attrs[NL80211_ATTR_IE] || 12298 !info->attrs[NL80211_ATTR_MAC]) 12299 return -EINVAL; 12300 12301 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12302 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 12303 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 12304 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 12305 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 12306 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 12307 peer_capability = 12308 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 12309 link_id = nl80211_link_id_or_invalid(info->attrs); 12310 12311 return rdev_tdls_mgmt(rdev, dev, peer, link_id, action_code, 12312 dialog_token, status_code, peer_capability, 12313 initiator, 12314 nla_data(info->attrs[NL80211_ATTR_IE]), 12315 nla_len(info->attrs[NL80211_ATTR_IE])); 12316 } 12317 12318 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 12319 { 12320 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12321 struct net_device *dev = info->user_ptr[1]; 12322 enum nl80211_tdls_operation operation; 12323 u8 *peer; 12324 12325 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12326 !rdev->ops->tdls_oper) 12327 return -EOPNOTSUPP; 12328 12329 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 12330 !info->attrs[NL80211_ATTR_MAC]) 12331 return -EINVAL; 12332 12333 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 12334 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12335 12336 return rdev_tdls_oper(rdev, dev, peer, operation); 12337 } 12338 12339 static int nl80211_remain_on_channel(struct sk_buff *skb, 12340 struct genl_info *info) 12341 { 12342 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12343 unsigned int link_id = nl80211_link_id(info->attrs); 12344 struct wireless_dev *wdev = info->user_ptr[1]; 12345 struct cfg80211_chan_def chandef; 12346 struct sk_buff *msg; 12347 void *hdr; 12348 u64 cookie; 12349 u32 duration; 12350 int err; 12351 12352 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 12353 !info->attrs[NL80211_ATTR_DURATION]) 12354 return -EINVAL; 12355 12356 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12357 12358 if (!rdev->ops->remain_on_channel || 12359 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 12360 return -EOPNOTSUPP; 12361 12362 /* 12363 * We should be on that channel for at least a minimum amount of 12364 * time (10ms) but no longer than the driver supports. 12365 */ 12366 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12367 duration > rdev->wiphy.max_remain_on_channel_duration) 12368 return -EINVAL; 12369 12370 err = nl80211_parse_chandef(rdev, info, &chandef); 12371 if (err) 12372 return err; 12373 12374 wdev_lock(wdev); 12375 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { 12376 const struct cfg80211_chan_def *oper_chandef, *compat_chandef; 12377 12378 oper_chandef = wdev_chandef(wdev, link_id); 12379 12380 if (WARN_ON(!oper_chandef)) { 12381 /* cannot happen since we must beacon to get here */ 12382 WARN_ON(1); 12383 wdev_unlock(wdev); 12384 return -EBUSY; 12385 } 12386 12387 /* note: returns first one if identical chandefs */ 12388 compat_chandef = cfg80211_chandef_compatible(&chandef, 12389 oper_chandef); 12390 12391 if (compat_chandef != &chandef) { 12392 wdev_unlock(wdev); 12393 return -EBUSY; 12394 } 12395 } 12396 wdev_unlock(wdev); 12397 12398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12399 if (!msg) 12400 return -ENOMEM; 12401 12402 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12403 NL80211_CMD_REMAIN_ON_CHANNEL); 12404 if (!hdr) { 12405 err = -ENOBUFS; 12406 goto free_msg; 12407 } 12408 12409 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 12410 duration, &cookie); 12411 12412 if (err) 12413 goto free_msg; 12414 12415 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12416 NL80211_ATTR_PAD)) 12417 goto nla_put_failure; 12418 12419 genlmsg_end(msg, hdr); 12420 12421 return genlmsg_reply(msg, info); 12422 12423 nla_put_failure: 12424 err = -ENOBUFS; 12425 free_msg: 12426 nlmsg_free(msg); 12427 return err; 12428 } 12429 12430 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 12431 struct genl_info *info) 12432 { 12433 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12434 struct wireless_dev *wdev = info->user_ptr[1]; 12435 u64 cookie; 12436 12437 if (!info->attrs[NL80211_ATTR_COOKIE]) 12438 return -EINVAL; 12439 12440 if (!rdev->ops->cancel_remain_on_channel) 12441 return -EOPNOTSUPP; 12442 12443 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12444 12445 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 12446 } 12447 12448 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 12449 struct genl_info *info) 12450 { 12451 struct cfg80211_bitrate_mask mask; 12452 unsigned int link_id = nl80211_link_id(info->attrs); 12453 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12454 struct net_device *dev = info->user_ptr[1]; 12455 struct wireless_dev *wdev = dev->ieee80211_ptr; 12456 int err; 12457 12458 if (!rdev->ops->set_bitrate_mask) 12459 return -EOPNOTSUPP; 12460 12461 wdev_lock(wdev); 12462 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 12463 NL80211_ATTR_TX_RATES, &mask, 12464 dev, true, link_id); 12465 if (err) 12466 goto out; 12467 12468 err = rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask); 12469 out: 12470 wdev_unlock(wdev); 12471 return err; 12472 } 12473 12474 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 12475 { 12476 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12477 struct wireless_dev *wdev = info->user_ptr[1]; 12478 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 12479 12480 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 12481 return -EINVAL; 12482 12483 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 12484 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 12485 12486 switch (wdev->iftype) { 12487 case NL80211_IFTYPE_STATION: 12488 case NL80211_IFTYPE_ADHOC: 12489 case NL80211_IFTYPE_P2P_CLIENT: 12490 case NL80211_IFTYPE_AP: 12491 case NL80211_IFTYPE_AP_VLAN: 12492 case NL80211_IFTYPE_MESH_POINT: 12493 case NL80211_IFTYPE_P2P_GO: 12494 case NL80211_IFTYPE_P2P_DEVICE: 12495 break; 12496 case NL80211_IFTYPE_NAN: 12497 if (!wiphy_ext_feature_isset(wdev->wiphy, 12498 NL80211_EXT_FEATURE_SECURE_NAN)) 12499 return -EOPNOTSUPP; 12500 break; 12501 default: 12502 return -EOPNOTSUPP; 12503 } 12504 12505 /* not much point in registering if we can't reply */ 12506 if (!rdev->ops->mgmt_tx) 12507 return -EOPNOTSUPP; 12508 12509 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && 12510 !wiphy_ext_feature_isset(&rdev->wiphy, 12511 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { 12512 GENL_SET_ERR_MSG(info, 12513 "multicast RX registrations are not supported"); 12514 return -EOPNOTSUPP; 12515 } 12516 12517 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 12518 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12519 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12520 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], 12521 info->extack); 12522 } 12523 12524 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 12525 { 12526 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12527 struct wireless_dev *wdev = info->user_ptr[1]; 12528 struct cfg80211_chan_def chandef; 12529 int err; 12530 void *hdr = NULL; 12531 u64 cookie; 12532 struct sk_buff *msg = NULL; 12533 struct cfg80211_mgmt_tx_params params = { 12534 .dont_wait_for_ack = 12535 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 12536 }; 12537 12538 if (!info->attrs[NL80211_ATTR_FRAME]) 12539 return -EINVAL; 12540 12541 if (!rdev->ops->mgmt_tx) 12542 return -EOPNOTSUPP; 12543 12544 switch (wdev->iftype) { 12545 case NL80211_IFTYPE_P2P_DEVICE: 12546 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 12547 return -EINVAL; 12548 break; 12549 case NL80211_IFTYPE_STATION: 12550 case NL80211_IFTYPE_ADHOC: 12551 case NL80211_IFTYPE_P2P_CLIENT: 12552 case NL80211_IFTYPE_AP: 12553 case NL80211_IFTYPE_AP_VLAN: 12554 case NL80211_IFTYPE_MESH_POINT: 12555 case NL80211_IFTYPE_P2P_GO: 12556 break; 12557 case NL80211_IFTYPE_NAN: 12558 if (!wiphy_ext_feature_isset(wdev->wiphy, 12559 NL80211_EXT_FEATURE_SECURE_NAN)) 12560 return -EOPNOTSUPP; 12561 break; 12562 default: 12563 return -EOPNOTSUPP; 12564 } 12565 12566 if (info->attrs[NL80211_ATTR_DURATION]) { 12567 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12568 return -EINVAL; 12569 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12570 12571 /* 12572 * We should wait on the channel for at least a minimum amount 12573 * of time (10ms) but no longer than the driver supports. 12574 */ 12575 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12576 params.wait > rdev->wiphy.max_remain_on_channel_duration) 12577 return -EINVAL; 12578 } 12579 12580 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 12581 12582 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12583 return -EINVAL; 12584 12585 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 12586 12587 /* get the channel if any has been specified, otherwise pass NULL to 12588 * the driver. The latter will use the current one 12589 */ 12590 chandef.chan = NULL; 12591 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 12592 err = nl80211_parse_chandef(rdev, info, &chandef); 12593 if (err) 12594 return err; 12595 } 12596 12597 if (!chandef.chan && params.offchan) 12598 return -EINVAL; 12599 12600 wdev_lock(wdev); 12601 if (params.offchan && 12602 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { 12603 wdev_unlock(wdev); 12604 return -EBUSY; 12605 } 12606 12607 params.link_id = nl80211_link_id_or_invalid(info->attrs); 12608 /* 12609 * This now races due to the unlock, but we cannot check 12610 * the valid links for the _station_ anyway, so that's up 12611 * to the driver. 12612 */ 12613 if (params.link_id >= 0 && 12614 !(wdev->valid_links & BIT(params.link_id))) { 12615 wdev_unlock(wdev); 12616 return -EINVAL; 12617 } 12618 wdev_unlock(wdev); 12619 12620 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 12621 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 12622 12623 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 12624 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12625 int i; 12626 12627 if (len % sizeof(u16)) 12628 return -EINVAL; 12629 12630 params.n_csa_offsets = len / sizeof(u16); 12631 params.csa_offsets = 12632 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12633 12634 /* check that all the offsets fit the frame */ 12635 for (i = 0; i < params.n_csa_offsets; i++) { 12636 if (params.csa_offsets[i] >= params.len) 12637 return -EINVAL; 12638 } 12639 } 12640 12641 if (!params.dont_wait_for_ack) { 12642 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12643 if (!msg) 12644 return -ENOMEM; 12645 12646 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12647 NL80211_CMD_FRAME); 12648 if (!hdr) { 12649 err = -ENOBUFS; 12650 goto free_msg; 12651 } 12652 } 12653 12654 params.chan = chandef.chan; 12655 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 12656 if (err) 12657 goto free_msg; 12658 12659 if (msg) { 12660 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12661 NL80211_ATTR_PAD)) 12662 goto nla_put_failure; 12663 12664 genlmsg_end(msg, hdr); 12665 return genlmsg_reply(msg, info); 12666 } 12667 12668 return 0; 12669 12670 nla_put_failure: 12671 err = -ENOBUFS; 12672 free_msg: 12673 nlmsg_free(msg); 12674 return err; 12675 } 12676 12677 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 12678 { 12679 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12680 struct wireless_dev *wdev = info->user_ptr[1]; 12681 u64 cookie; 12682 12683 if (!info->attrs[NL80211_ATTR_COOKIE]) 12684 return -EINVAL; 12685 12686 if (!rdev->ops->mgmt_tx_cancel_wait) 12687 return -EOPNOTSUPP; 12688 12689 switch (wdev->iftype) { 12690 case NL80211_IFTYPE_STATION: 12691 case NL80211_IFTYPE_ADHOC: 12692 case NL80211_IFTYPE_P2P_CLIENT: 12693 case NL80211_IFTYPE_AP: 12694 case NL80211_IFTYPE_AP_VLAN: 12695 case NL80211_IFTYPE_P2P_GO: 12696 case NL80211_IFTYPE_P2P_DEVICE: 12697 break; 12698 case NL80211_IFTYPE_NAN: 12699 if (!wiphy_ext_feature_isset(wdev->wiphy, 12700 NL80211_EXT_FEATURE_SECURE_NAN)) 12701 return -EOPNOTSUPP; 12702 break; 12703 default: 12704 return -EOPNOTSUPP; 12705 } 12706 12707 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12708 12709 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 12710 } 12711 12712 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 12713 { 12714 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12715 struct wireless_dev *wdev; 12716 struct net_device *dev = info->user_ptr[1]; 12717 u8 ps_state; 12718 bool state; 12719 int err; 12720 12721 if (!info->attrs[NL80211_ATTR_PS_STATE]) 12722 return -EINVAL; 12723 12724 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 12725 12726 wdev = dev->ieee80211_ptr; 12727 12728 if (!rdev->ops->set_power_mgmt) 12729 return -EOPNOTSUPP; 12730 12731 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 12732 12733 if (state == wdev->ps) 12734 return 0; 12735 12736 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 12737 if (!err) 12738 wdev->ps = state; 12739 return err; 12740 } 12741 12742 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 12743 { 12744 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12745 enum nl80211_ps_state ps_state; 12746 struct wireless_dev *wdev; 12747 struct net_device *dev = info->user_ptr[1]; 12748 struct sk_buff *msg; 12749 void *hdr; 12750 int err; 12751 12752 wdev = dev->ieee80211_ptr; 12753 12754 if (!rdev->ops->set_power_mgmt) 12755 return -EOPNOTSUPP; 12756 12757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12758 if (!msg) 12759 return -ENOMEM; 12760 12761 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12762 NL80211_CMD_GET_POWER_SAVE); 12763 if (!hdr) { 12764 err = -ENOBUFS; 12765 goto free_msg; 12766 } 12767 12768 if (wdev->ps) 12769 ps_state = NL80211_PS_ENABLED; 12770 else 12771 ps_state = NL80211_PS_DISABLED; 12772 12773 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 12774 goto nla_put_failure; 12775 12776 genlmsg_end(msg, hdr); 12777 return genlmsg_reply(msg, info); 12778 12779 nla_put_failure: 12780 err = -ENOBUFS; 12781 free_msg: 12782 nlmsg_free(msg); 12783 return err; 12784 } 12785 12786 static const struct nla_policy 12787 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 12788 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 12789 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 12790 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 12791 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 12792 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 12793 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 12794 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 12795 }; 12796 12797 static int nl80211_set_cqm_txe(struct genl_info *info, 12798 u32 rate, u32 pkts, u32 intvl) 12799 { 12800 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12801 struct net_device *dev = info->user_ptr[1]; 12802 struct wireless_dev *wdev = dev->ieee80211_ptr; 12803 12804 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 12805 return -EINVAL; 12806 12807 if (!rdev->ops->set_cqm_txe_config) 12808 return -EOPNOTSUPP; 12809 12810 if (wdev->iftype != NL80211_IFTYPE_STATION && 12811 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12812 return -EOPNOTSUPP; 12813 12814 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 12815 } 12816 12817 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 12818 struct net_device *dev) 12819 { 12820 struct wireless_dev *wdev = dev->ieee80211_ptr; 12821 s32 last, low, high; 12822 u32 hyst; 12823 int i, n, low_index; 12824 int err; 12825 12826 /* RSSI reporting disabled? */ 12827 if (!wdev->cqm_config) 12828 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 12829 12830 /* 12831 * Obtain current RSSI value if possible, if not and no RSSI threshold 12832 * event has been received yet, we should receive an event after a 12833 * connection is established and enough beacons received to calculate 12834 * the average. 12835 */ 12836 if (!wdev->cqm_config->last_rssi_event_value && 12837 wdev->links[0].client.current_bss && 12838 rdev->ops->get_station) { 12839 struct station_info sinfo = {}; 12840 u8 *mac_addr; 12841 12842 mac_addr = wdev->links[0].client.current_bss->pub.bssid; 12843 12844 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 12845 if (err) 12846 return err; 12847 12848 cfg80211_sinfo_release_content(&sinfo); 12849 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 12850 wdev->cqm_config->last_rssi_event_value = 12851 (s8) sinfo.rx_beacon_signal_avg; 12852 } 12853 12854 last = wdev->cqm_config->last_rssi_event_value; 12855 hyst = wdev->cqm_config->rssi_hyst; 12856 n = wdev->cqm_config->n_rssi_thresholds; 12857 12858 for (i = 0; i < n; i++) { 12859 i = array_index_nospec(i, n); 12860 if (last < wdev->cqm_config->rssi_thresholds[i]) 12861 break; 12862 } 12863 12864 low_index = i - 1; 12865 if (low_index >= 0) { 12866 low_index = array_index_nospec(low_index, n); 12867 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; 12868 } else { 12869 low = S32_MIN; 12870 } 12871 if (i < n) { 12872 i = array_index_nospec(i, n); 12873 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; 12874 } else { 12875 high = S32_MAX; 12876 } 12877 12878 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 12879 } 12880 12881 static int nl80211_set_cqm_rssi(struct genl_info *info, 12882 const s32 *thresholds, int n_thresholds, 12883 u32 hysteresis) 12884 { 12885 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12886 struct net_device *dev = info->user_ptr[1]; 12887 struct wireless_dev *wdev = dev->ieee80211_ptr; 12888 int i, err; 12889 s32 prev = S32_MIN; 12890 12891 /* Check all values negative and sorted */ 12892 for (i = 0; i < n_thresholds; i++) { 12893 if (thresholds[i] > 0 || thresholds[i] <= prev) 12894 return -EINVAL; 12895 12896 prev = thresholds[i]; 12897 } 12898 12899 if (wdev->iftype != NL80211_IFTYPE_STATION && 12900 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12901 return -EOPNOTSUPP; 12902 12903 wdev_lock(wdev); 12904 cfg80211_cqm_config_free(wdev); 12905 wdev_unlock(wdev); 12906 12907 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { 12908 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ 12909 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 12910 12911 return rdev_set_cqm_rssi_config(rdev, dev, 12912 thresholds[0], hysteresis); 12913 } 12914 12915 if (!wiphy_ext_feature_isset(&rdev->wiphy, 12916 NL80211_EXT_FEATURE_CQM_RSSI_LIST)) 12917 return -EOPNOTSUPP; 12918 12919 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 12920 n_thresholds = 0; 12921 12922 wdev_lock(wdev); 12923 if (n_thresholds) { 12924 struct cfg80211_cqm_config *cqm_config; 12925 12926 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, 12927 n_thresholds), 12928 GFP_KERNEL); 12929 if (!cqm_config) { 12930 err = -ENOMEM; 12931 goto unlock; 12932 } 12933 12934 cqm_config->rssi_hyst = hysteresis; 12935 cqm_config->n_rssi_thresholds = n_thresholds; 12936 memcpy(cqm_config->rssi_thresholds, thresholds, 12937 flex_array_size(cqm_config, rssi_thresholds, 12938 n_thresholds)); 12939 12940 wdev->cqm_config = cqm_config; 12941 } 12942 12943 err = cfg80211_cqm_rssi_update(rdev, dev); 12944 12945 unlock: 12946 wdev_unlock(wdev); 12947 12948 return err; 12949 } 12950 12951 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 12952 { 12953 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 12954 struct nlattr *cqm; 12955 int err; 12956 12957 cqm = info->attrs[NL80211_ATTR_CQM]; 12958 if (!cqm) 12959 return -EINVAL; 12960 12961 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 12962 nl80211_attr_cqm_policy, 12963 info->extack); 12964 if (err) 12965 return err; 12966 12967 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 12968 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 12969 const s32 *thresholds = 12970 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12971 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12972 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 12973 12974 if (len % 4) 12975 return -EINVAL; 12976 12977 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 12978 hysteresis); 12979 } 12980 12981 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 12982 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 12983 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 12984 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 12985 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 12986 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 12987 12988 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 12989 } 12990 12991 return -EINVAL; 12992 } 12993 12994 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 12995 { 12996 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12997 struct net_device *dev = info->user_ptr[1]; 12998 struct ocb_setup setup = {}; 12999 int err; 13000 13001 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 13002 if (err) 13003 return err; 13004 13005 return cfg80211_join_ocb(rdev, dev, &setup); 13006 } 13007 13008 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 13009 { 13010 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13011 struct net_device *dev = info->user_ptr[1]; 13012 13013 return cfg80211_leave_ocb(rdev, dev); 13014 } 13015 13016 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 13017 { 13018 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13019 struct net_device *dev = info->user_ptr[1]; 13020 struct mesh_config cfg; 13021 struct mesh_setup setup; 13022 int err; 13023 13024 /* start with default */ 13025 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 13026 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 13027 13028 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 13029 /* and parse parameters if given */ 13030 err = nl80211_parse_mesh_config(info, &cfg, NULL); 13031 if (err) 13032 return err; 13033 } 13034 13035 if (!info->attrs[NL80211_ATTR_MESH_ID] || 13036 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 13037 return -EINVAL; 13038 13039 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 13040 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 13041 13042 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 13043 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 13044 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 13045 return -EINVAL; 13046 13047 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 13048 setup.beacon_interval = 13049 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 13050 13051 err = cfg80211_validate_beacon_int(rdev, 13052 NL80211_IFTYPE_MESH_POINT, 13053 setup.beacon_interval); 13054 if (err) 13055 return err; 13056 } 13057 13058 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 13059 setup.dtim_period = 13060 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 13061 if (setup.dtim_period < 1 || setup.dtim_period > 100) 13062 return -EINVAL; 13063 } 13064 13065 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 13066 /* parse additional setup parameters if given */ 13067 err = nl80211_parse_mesh_setup(info, &setup); 13068 if (err) 13069 return err; 13070 } 13071 13072 if (setup.user_mpm) 13073 cfg.auto_open_plinks = false; 13074 13075 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 13076 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 13077 if (err) 13078 return err; 13079 } else { 13080 /* __cfg80211_join_mesh() will sort it out */ 13081 setup.chandef.chan = NULL; 13082 } 13083 13084 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 13085 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 13086 int n_rates = 13087 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 13088 struct ieee80211_supported_band *sband; 13089 13090 if (!setup.chandef.chan) 13091 return -EINVAL; 13092 13093 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 13094 13095 err = ieee80211_get_ratemask(sband, rates, n_rates, 13096 &setup.basic_rates); 13097 if (err) 13098 return err; 13099 } 13100 13101 if (info->attrs[NL80211_ATTR_TX_RATES]) { 13102 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 13103 NL80211_ATTR_TX_RATES, 13104 &setup.beacon_rate, 13105 dev, false, 0); 13106 if (err) 13107 return err; 13108 13109 if (!setup.chandef.chan) 13110 return -EINVAL; 13111 13112 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 13113 &setup.beacon_rate); 13114 if (err) 13115 return err; 13116 } 13117 13118 setup.userspace_handles_dfs = 13119 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 13120 13121 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 13122 int r = validate_pae_over_nl80211(rdev, info); 13123 13124 if (r < 0) 13125 return r; 13126 13127 setup.control_port_over_nl80211 = true; 13128 } 13129 13130 wdev_lock(dev->ieee80211_ptr); 13131 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 13132 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 13133 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 13134 wdev_unlock(dev->ieee80211_ptr); 13135 13136 return err; 13137 } 13138 13139 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 13140 { 13141 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13142 struct net_device *dev = info->user_ptr[1]; 13143 13144 return cfg80211_leave_mesh(rdev, dev); 13145 } 13146 13147 #ifdef CONFIG_PM 13148 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 13149 struct cfg80211_registered_device *rdev) 13150 { 13151 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 13152 struct nlattr *nl_pats, *nl_pat; 13153 int i, pat_len; 13154 13155 if (!wowlan->n_patterns) 13156 return 0; 13157 13158 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 13159 if (!nl_pats) 13160 return -ENOBUFS; 13161 13162 for (i = 0; i < wowlan->n_patterns; i++) { 13163 nl_pat = nla_nest_start_noflag(msg, i + 1); 13164 if (!nl_pat) 13165 return -ENOBUFS; 13166 pat_len = wowlan->patterns[i].pattern_len; 13167 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 13168 wowlan->patterns[i].mask) || 13169 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 13170 wowlan->patterns[i].pattern) || 13171 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 13172 wowlan->patterns[i].pkt_offset)) 13173 return -ENOBUFS; 13174 nla_nest_end(msg, nl_pat); 13175 } 13176 nla_nest_end(msg, nl_pats); 13177 13178 return 0; 13179 } 13180 13181 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 13182 struct cfg80211_wowlan_tcp *tcp) 13183 { 13184 struct nlattr *nl_tcp; 13185 13186 if (!tcp) 13187 return 0; 13188 13189 nl_tcp = nla_nest_start_noflag(msg, 13190 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 13191 if (!nl_tcp) 13192 return -ENOBUFS; 13193 13194 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 13195 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 13196 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 13197 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 13198 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 13199 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 13200 tcp->payload_len, tcp->payload) || 13201 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 13202 tcp->data_interval) || 13203 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 13204 tcp->wake_len, tcp->wake_data) || 13205 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 13206 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 13207 return -ENOBUFS; 13208 13209 if (tcp->payload_seq.len && 13210 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 13211 sizeof(tcp->payload_seq), &tcp->payload_seq)) 13212 return -ENOBUFS; 13213 13214 if (tcp->payload_tok.len && 13215 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 13216 sizeof(tcp->payload_tok) + tcp->tokens_size, 13217 &tcp->payload_tok)) 13218 return -ENOBUFS; 13219 13220 nla_nest_end(msg, nl_tcp); 13221 13222 return 0; 13223 } 13224 13225 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 13226 struct cfg80211_sched_scan_request *req) 13227 { 13228 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 13229 int i; 13230 13231 if (!req) 13232 return 0; 13233 13234 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 13235 if (!nd) 13236 return -ENOBUFS; 13237 13238 if (req->n_scan_plans == 1 && 13239 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 13240 req->scan_plans[0].interval * 1000)) 13241 return -ENOBUFS; 13242 13243 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 13244 return -ENOBUFS; 13245 13246 if (req->relative_rssi_set) { 13247 struct nl80211_bss_select_rssi_adjust rssi_adjust; 13248 13249 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 13250 req->relative_rssi)) 13251 return -ENOBUFS; 13252 13253 rssi_adjust.band = req->rssi_adjust.band; 13254 rssi_adjust.delta = req->rssi_adjust.delta; 13255 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 13256 sizeof(rssi_adjust), &rssi_adjust)) 13257 return -ENOBUFS; 13258 } 13259 13260 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 13261 if (!freqs) 13262 return -ENOBUFS; 13263 13264 for (i = 0; i < req->n_channels; i++) { 13265 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 13266 return -ENOBUFS; 13267 } 13268 13269 nla_nest_end(msg, freqs); 13270 13271 if (req->n_match_sets) { 13272 matches = nla_nest_start_noflag(msg, 13273 NL80211_ATTR_SCHED_SCAN_MATCH); 13274 if (!matches) 13275 return -ENOBUFS; 13276 13277 for (i = 0; i < req->n_match_sets; i++) { 13278 match = nla_nest_start_noflag(msg, i); 13279 if (!match) 13280 return -ENOBUFS; 13281 13282 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 13283 req->match_sets[i].ssid.ssid_len, 13284 req->match_sets[i].ssid.ssid)) 13285 return -ENOBUFS; 13286 nla_nest_end(msg, match); 13287 } 13288 nla_nest_end(msg, matches); 13289 } 13290 13291 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 13292 if (!scan_plans) 13293 return -ENOBUFS; 13294 13295 for (i = 0; i < req->n_scan_plans; i++) { 13296 scan_plan = nla_nest_start_noflag(msg, i + 1); 13297 if (!scan_plan) 13298 return -ENOBUFS; 13299 13300 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 13301 req->scan_plans[i].interval) || 13302 (req->scan_plans[i].iterations && 13303 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 13304 req->scan_plans[i].iterations))) 13305 return -ENOBUFS; 13306 nla_nest_end(msg, scan_plan); 13307 } 13308 nla_nest_end(msg, scan_plans); 13309 13310 nla_nest_end(msg, nd); 13311 13312 return 0; 13313 } 13314 13315 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 13316 { 13317 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13318 struct sk_buff *msg; 13319 void *hdr; 13320 u32 size = NLMSG_DEFAULT_SIZE; 13321 13322 if (!rdev->wiphy.wowlan) 13323 return -EOPNOTSUPP; 13324 13325 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 13326 /* adjust size to have room for all the data */ 13327 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 13328 rdev->wiphy.wowlan_config->tcp->payload_len + 13329 rdev->wiphy.wowlan_config->tcp->wake_len + 13330 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 13331 } 13332 13333 msg = nlmsg_new(size, GFP_KERNEL); 13334 if (!msg) 13335 return -ENOMEM; 13336 13337 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13338 NL80211_CMD_GET_WOWLAN); 13339 if (!hdr) 13340 goto nla_put_failure; 13341 13342 if (rdev->wiphy.wowlan_config) { 13343 struct nlattr *nl_wowlan; 13344 13345 nl_wowlan = nla_nest_start_noflag(msg, 13346 NL80211_ATTR_WOWLAN_TRIGGERS); 13347 if (!nl_wowlan) 13348 goto nla_put_failure; 13349 13350 if ((rdev->wiphy.wowlan_config->any && 13351 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 13352 (rdev->wiphy.wowlan_config->disconnect && 13353 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 13354 (rdev->wiphy.wowlan_config->magic_pkt && 13355 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 13356 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 13357 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 13358 (rdev->wiphy.wowlan_config->eap_identity_req && 13359 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 13360 (rdev->wiphy.wowlan_config->four_way_handshake && 13361 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 13362 (rdev->wiphy.wowlan_config->rfkill_release && 13363 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 13364 goto nla_put_failure; 13365 13366 if (nl80211_send_wowlan_patterns(msg, rdev)) 13367 goto nla_put_failure; 13368 13369 if (nl80211_send_wowlan_tcp(msg, 13370 rdev->wiphy.wowlan_config->tcp)) 13371 goto nla_put_failure; 13372 13373 if (nl80211_send_wowlan_nd( 13374 msg, 13375 rdev->wiphy.wowlan_config->nd_config)) 13376 goto nla_put_failure; 13377 13378 nla_nest_end(msg, nl_wowlan); 13379 } 13380 13381 genlmsg_end(msg, hdr); 13382 return genlmsg_reply(msg, info); 13383 13384 nla_put_failure: 13385 nlmsg_free(msg); 13386 return -ENOBUFS; 13387 } 13388 13389 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 13390 struct nlattr *attr, 13391 struct cfg80211_wowlan *trig) 13392 { 13393 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 13394 struct cfg80211_wowlan_tcp *cfg; 13395 struct nl80211_wowlan_tcp_data_token *tok = NULL; 13396 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 13397 u32 size; 13398 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 13399 int err, port; 13400 13401 if (!rdev->wiphy.wowlan->tcp) 13402 return -EINVAL; 13403 13404 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 13405 nl80211_wowlan_tcp_policy, NULL); 13406 if (err) 13407 return err; 13408 13409 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 13410 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 13411 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 13412 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 13413 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 13414 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 13415 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 13416 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 13417 return -EINVAL; 13418 13419 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 13420 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 13421 return -EINVAL; 13422 13423 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 13424 rdev->wiphy.wowlan->tcp->data_interval_max || 13425 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 13426 return -EINVAL; 13427 13428 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 13429 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 13430 return -EINVAL; 13431 13432 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 13433 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 13434 return -EINVAL; 13435 13436 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 13437 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13438 13439 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13440 tokens_size = tokln - sizeof(*tok); 13441 13442 if (!tok->len || tokens_size % tok->len) 13443 return -EINVAL; 13444 if (!rdev->wiphy.wowlan->tcp->tok) 13445 return -EINVAL; 13446 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 13447 return -EINVAL; 13448 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 13449 return -EINVAL; 13450 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 13451 return -EINVAL; 13452 if (tok->offset + tok->len > data_size) 13453 return -EINVAL; 13454 } 13455 13456 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 13457 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 13458 if (!rdev->wiphy.wowlan->tcp->seq) 13459 return -EINVAL; 13460 if (seq->len == 0 || seq->len > 4) 13461 return -EINVAL; 13462 if (seq->len + seq->offset > data_size) 13463 return -EINVAL; 13464 } 13465 13466 size = sizeof(*cfg); 13467 size += data_size; 13468 size += wake_size + wake_mask_size; 13469 size += tokens_size; 13470 13471 cfg = kzalloc(size, GFP_KERNEL); 13472 if (!cfg) 13473 return -ENOMEM; 13474 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 13475 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 13476 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 13477 ETH_ALEN); 13478 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 13479 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 13480 else 13481 port = 0; 13482 #ifdef CONFIG_INET 13483 /* allocate a socket and port for it and use it */ 13484 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 13485 IPPROTO_TCP, &cfg->sock, 1); 13486 if (err) { 13487 kfree(cfg); 13488 return err; 13489 } 13490 if (inet_csk_get_port(cfg->sock->sk, port)) { 13491 sock_release(cfg->sock); 13492 kfree(cfg); 13493 return -EADDRINUSE; 13494 } 13495 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 13496 #else 13497 if (!port) { 13498 kfree(cfg); 13499 return -EINVAL; 13500 } 13501 cfg->src_port = port; 13502 #endif 13503 13504 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 13505 cfg->payload_len = data_size; 13506 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 13507 memcpy((void *)cfg->payload, 13508 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 13509 data_size); 13510 if (seq) 13511 cfg->payload_seq = *seq; 13512 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 13513 cfg->wake_len = wake_size; 13514 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 13515 memcpy((void *)cfg->wake_data, 13516 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 13517 wake_size); 13518 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 13519 data_size + wake_size; 13520 memcpy((void *)cfg->wake_mask, 13521 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 13522 wake_mask_size); 13523 if (tok) { 13524 cfg->tokens_size = tokens_size; 13525 cfg->payload_tok = *tok; 13526 memcpy(cfg->payload_tok.token_stream, tok->token_stream, 13527 tokens_size); 13528 } 13529 13530 trig->tcp = cfg; 13531 13532 return 0; 13533 } 13534 13535 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 13536 const struct wiphy_wowlan_support *wowlan, 13537 struct nlattr *attr, 13538 struct cfg80211_wowlan *trig) 13539 { 13540 struct nlattr **tb; 13541 int err; 13542 13543 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 13544 if (!tb) 13545 return -ENOMEM; 13546 13547 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 13548 err = -EOPNOTSUPP; 13549 goto out; 13550 } 13551 13552 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 13553 nl80211_policy, NULL); 13554 if (err) 13555 goto out; 13556 13557 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 13558 wowlan->max_nd_match_sets); 13559 err = PTR_ERR_OR_ZERO(trig->nd_config); 13560 if (err) 13561 trig->nd_config = NULL; 13562 13563 out: 13564 kfree(tb); 13565 return err; 13566 } 13567 13568 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 13569 { 13570 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13571 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 13572 struct cfg80211_wowlan new_triggers = {}; 13573 struct cfg80211_wowlan *ntrig; 13574 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 13575 int err, i; 13576 bool prev_enabled = rdev->wiphy.wowlan_config; 13577 bool regular = false; 13578 13579 if (!wowlan) 13580 return -EOPNOTSUPP; 13581 13582 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 13583 cfg80211_rdev_free_wowlan(rdev); 13584 rdev->wiphy.wowlan_config = NULL; 13585 goto set_wakeup; 13586 } 13587 13588 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 13589 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 13590 nl80211_wowlan_policy, info->extack); 13591 if (err) 13592 return err; 13593 13594 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 13595 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 13596 return -EINVAL; 13597 new_triggers.any = true; 13598 } 13599 13600 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 13601 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 13602 return -EINVAL; 13603 new_triggers.disconnect = true; 13604 regular = true; 13605 } 13606 13607 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 13608 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 13609 return -EINVAL; 13610 new_triggers.magic_pkt = true; 13611 regular = true; 13612 } 13613 13614 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 13615 return -EINVAL; 13616 13617 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 13618 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 13619 return -EINVAL; 13620 new_triggers.gtk_rekey_failure = true; 13621 regular = true; 13622 } 13623 13624 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 13625 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 13626 return -EINVAL; 13627 new_triggers.eap_identity_req = true; 13628 regular = true; 13629 } 13630 13631 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 13632 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 13633 return -EINVAL; 13634 new_triggers.four_way_handshake = true; 13635 regular = true; 13636 } 13637 13638 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 13639 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 13640 return -EINVAL; 13641 new_triggers.rfkill_release = true; 13642 regular = true; 13643 } 13644 13645 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 13646 struct nlattr *pat; 13647 int n_patterns = 0; 13648 int rem, pat_len, mask_len, pkt_offset; 13649 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13650 13651 regular = true; 13652 13653 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13654 rem) 13655 n_patterns++; 13656 if (n_patterns > wowlan->n_patterns) 13657 return -EINVAL; 13658 13659 new_triggers.patterns = kcalloc(n_patterns, 13660 sizeof(new_triggers.patterns[0]), 13661 GFP_KERNEL); 13662 if (!new_triggers.patterns) 13663 return -ENOMEM; 13664 13665 new_triggers.n_patterns = n_patterns; 13666 i = 0; 13667 13668 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13669 rem) { 13670 u8 *mask_pat; 13671 13672 err = nla_parse_nested_deprecated(pat_tb, 13673 MAX_NL80211_PKTPAT, 13674 pat, 13675 nl80211_packet_pattern_policy, 13676 info->extack); 13677 if (err) 13678 goto error; 13679 13680 err = -EINVAL; 13681 if (!pat_tb[NL80211_PKTPAT_MASK] || 13682 !pat_tb[NL80211_PKTPAT_PATTERN]) 13683 goto error; 13684 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13685 mask_len = DIV_ROUND_UP(pat_len, 8); 13686 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13687 goto error; 13688 if (pat_len > wowlan->pattern_max_len || 13689 pat_len < wowlan->pattern_min_len) 13690 goto error; 13691 13692 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13693 pkt_offset = 0; 13694 else 13695 pkt_offset = nla_get_u32( 13696 pat_tb[NL80211_PKTPAT_OFFSET]); 13697 if (pkt_offset > wowlan->max_pkt_offset) 13698 goto error; 13699 new_triggers.patterns[i].pkt_offset = pkt_offset; 13700 13701 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13702 if (!mask_pat) { 13703 err = -ENOMEM; 13704 goto error; 13705 } 13706 new_triggers.patterns[i].mask = mask_pat; 13707 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13708 mask_len); 13709 mask_pat += mask_len; 13710 new_triggers.patterns[i].pattern = mask_pat; 13711 new_triggers.patterns[i].pattern_len = pat_len; 13712 memcpy(mask_pat, 13713 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13714 pat_len); 13715 i++; 13716 } 13717 } 13718 13719 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 13720 regular = true; 13721 err = nl80211_parse_wowlan_tcp( 13722 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 13723 &new_triggers); 13724 if (err) 13725 goto error; 13726 } 13727 13728 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 13729 regular = true; 13730 err = nl80211_parse_wowlan_nd( 13731 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 13732 &new_triggers); 13733 if (err) 13734 goto error; 13735 } 13736 13737 /* The 'any' trigger means the device continues operating more or less 13738 * as in its normal operation mode and wakes up the host on most of the 13739 * normal interrupts (like packet RX, ...) 13740 * It therefore makes little sense to combine with the more constrained 13741 * wakeup trigger modes. 13742 */ 13743 if (new_triggers.any && regular) { 13744 err = -EINVAL; 13745 goto error; 13746 } 13747 13748 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 13749 if (!ntrig) { 13750 err = -ENOMEM; 13751 goto error; 13752 } 13753 cfg80211_rdev_free_wowlan(rdev); 13754 rdev->wiphy.wowlan_config = ntrig; 13755 13756 set_wakeup: 13757 if (rdev->ops->set_wakeup && 13758 prev_enabled != !!rdev->wiphy.wowlan_config) 13759 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 13760 13761 return 0; 13762 error: 13763 for (i = 0; i < new_triggers.n_patterns; i++) 13764 kfree(new_triggers.patterns[i].mask); 13765 kfree(new_triggers.patterns); 13766 if (new_triggers.tcp && new_triggers.tcp->sock) 13767 sock_release(new_triggers.tcp->sock); 13768 kfree(new_triggers.tcp); 13769 kfree(new_triggers.nd_config); 13770 return err; 13771 } 13772 #endif 13773 13774 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 13775 struct cfg80211_registered_device *rdev) 13776 { 13777 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 13778 int i, j, pat_len; 13779 struct cfg80211_coalesce_rules *rule; 13780 13781 if (!rdev->coalesce->n_rules) 13782 return 0; 13783 13784 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 13785 if (!nl_rules) 13786 return -ENOBUFS; 13787 13788 for (i = 0; i < rdev->coalesce->n_rules; i++) { 13789 nl_rule = nla_nest_start_noflag(msg, i + 1); 13790 if (!nl_rule) 13791 return -ENOBUFS; 13792 13793 rule = &rdev->coalesce->rules[i]; 13794 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 13795 rule->delay)) 13796 return -ENOBUFS; 13797 13798 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 13799 rule->condition)) 13800 return -ENOBUFS; 13801 13802 nl_pats = nla_nest_start_noflag(msg, 13803 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 13804 if (!nl_pats) 13805 return -ENOBUFS; 13806 13807 for (j = 0; j < rule->n_patterns; j++) { 13808 nl_pat = nla_nest_start_noflag(msg, j + 1); 13809 if (!nl_pat) 13810 return -ENOBUFS; 13811 pat_len = rule->patterns[j].pattern_len; 13812 if (nla_put(msg, NL80211_PKTPAT_MASK, 13813 DIV_ROUND_UP(pat_len, 8), 13814 rule->patterns[j].mask) || 13815 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 13816 rule->patterns[j].pattern) || 13817 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 13818 rule->patterns[j].pkt_offset)) 13819 return -ENOBUFS; 13820 nla_nest_end(msg, nl_pat); 13821 } 13822 nla_nest_end(msg, nl_pats); 13823 nla_nest_end(msg, nl_rule); 13824 } 13825 nla_nest_end(msg, nl_rules); 13826 13827 return 0; 13828 } 13829 13830 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 13831 { 13832 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13833 struct sk_buff *msg; 13834 void *hdr; 13835 13836 if (!rdev->wiphy.coalesce) 13837 return -EOPNOTSUPP; 13838 13839 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13840 if (!msg) 13841 return -ENOMEM; 13842 13843 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13844 NL80211_CMD_GET_COALESCE); 13845 if (!hdr) 13846 goto nla_put_failure; 13847 13848 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 13849 goto nla_put_failure; 13850 13851 genlmsg_end(msg, hdr); 13852 return genlmsg_reply(msg, info); 13853 13854 nla_put_failure: 13855 nlmsg_free(msg); 13856 return -ENOBUFS; 13857 } 13858 13859 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 13860 { 13861 struct cfg80211_coalesce *coalesce = rdev->coalesce; 13862 int i, j; 13863 struct cfg80211_coalesce_rules *rule; 13864 13865 if (!coalesce) 13866 return; 13867 13868 for (i = 0; i < coalesce->n_rules; i++) { 13869 rule = &coalesce->rules[i]; 13870 for (j = 0; j < rule->n_patterns; j++) 13871 kfree(rule->patterns[j].mask); 13872 kfree(rule->patterns); 13873 } 13874 kfree(coalesce->rules); 13875 kfree(coalesce); 13876 rdev->coalesce = NULL; 13877 } 13878 13879 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 13880 struct nlattr *rule, 13881 struct cfg80211_coalesce_rules *new_rule) 13882 { 13883 int err, i; 13884 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13885 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 13886 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 13887 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13888 13889 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 13890 rule, nl80211_coalesce_policy, NULL); 13891 if (err) 13892 return err; 13893 13894 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 13895 new_rule->delay = 13896 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 13897 if (new_rule->delay > coalesce->max_delay) 13898 return -EINVAL; 13899 13900 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 13901 new_rule->condition = 13902 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 13903 13904 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 13905 return -EINVAL; 13906 13907 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13908 rem) 13909 n_patterns++; 13910 if (n_patterns > coalesce->n_patterns) 13911 return -EINVAL; 13912 13913 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 13914 GFP_KERNEL); 13915 if (!new_rule->patterns) 13916 return -ENOMEM; 13917 13918 new_rule->n_patterns = n_patterns; 13919 i = 0; 13920 13921 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13922 rem) { 13923 u8 *mask_pat; 13924 13925 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 13926 pat, 13927 nl80211_packet_pattern_policy, 13928 NULL); 13929 if (err) 13930 return err; 13931 13932 if (!pat_tb[NL80211_PKTPAT_MASK] || 13933 !pat_tb[NL80211_PKTPAT_PATTERN]) 13934 return -EINVAL; 13935 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13936 mask_len = DIV_ROUND_UP(pat_len, 8); 13937 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13938 return -EINVAL; 13939 if (pat_len > coalesce->pattern_max_len || 13940 pat_len < coalesce->pattern_min_len) 13941 return -EINVAL; 13942 13943 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13944 pkt_offset = 0; 13945 else 13946 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 13947 if (pkt_offset > coalesce->max_pkt_offset) 13948 return -EINVAL; 13949 new_rule->patterns[i].pkt_offset = pkt_offset; 13950 13951 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13952 if (!mask_pat) 13953 return -ENOMEM; 13954 13955 new_rule->patterns[i].mask = mask_pat; 13956 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13957 mask_len); 13958 13959 mask_pat += mask_len; 13960 new_rule->patterns[i].pattern = mask_pat; 13961 new_rule->patterns[i].pattern_len = pat_len; 13962 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13963 pat_len); 13964 i++; 13965 } 13966 13967 return 0; 13968 } 13969 13970 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 13971 { 13972 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13973 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13974 struct cfg80211_coalesce new_coalesce = {}; 13975 struct cfg80211_coalesce *n_coalesce; 13976 int err, rem_rule, n_rules = 0, i, j; 13977 struct nlattr *rule; 13978 struct cfg80211_coalesce_rules *tmp_rule; 13979 13980 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 13981 return -EOPNOTSUPP; 13982 13983 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 13984 cfg80211_rdev_free_coalesce(rdev); 13985 rdev_set_coalesce(rdev, NULL); 13986 return 0; 13987 } 13988 13989 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 13990 rem_rule) 13991 n_rules++; 13992 if (n_rules > coalesce->n_rules) 13993 return -EINVAL; 13994 13995 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 13996 GFP_KERNEL); 13997 if (!new_coalesce.rules) 13998 return -ENOMEM; 13999 14000 new_coalesce.n_rules = n_rules; 14001 i = 0; 14002 14003 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 14004 rem_rule) { 14005 err = nl80211_parse_coalesce_rule(rdev, rule, 14006 &new_coalesce.rules[i]); 14007 if (err) 14008 goto error; 14009 14010 i++; 14011 } 14012 14013 err = rdev_set_coalesce(rdev, &new_coalesce); 14014 if (err) 14015 goto error; 14016 14017 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 14018 if (!n_coalesce) { 14019 err = -ENOMEM; 14020 goto error; 14021 } 14022 cfg80211_rdev_free_coalesce(rdev); 14023 rdev->coalesce = n_coalesce; 14024 14025 return 0; 14026 error: 14027 for (i = 0; i < new_coalesce.n_rules; i++) { 14028 tmp_rule = &new_coalesce.rules[i]; 14029 for (j = 0; j < tmp_rule->n_patterns; j++) 14030 kfree(tmp_rule->patterns[j].mask); 14031 kfree(tmp_rule->patterns); 14032 } 14033 kfree(new_coalesce.rules); 14034 14035 return err; 14036 } 14037 14038 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 14039 { 14040 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14041 struct net_device *dev = info->user_ptr[1]; 14042 struct wireless_dev *wdev = dev->ieee80211_ptr; 14043 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 14044 struct cfg80211_gtk_rekey_data rekey_data = {}; 14045 int err; 14046 14047 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 14048 return -EINVAL; 14049 14050 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 14051 info->attrs[NL80211_ATTR_REKEY_DATA], 14052 nl80211_rekey_policy, info->extack); 14053 if (err) 14054 return err; 14055 14056 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 14057 !tb[NL80211_REKEY_DATA_KCK]) 14058 return -EINVAL; 14059 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && 14060 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 14061 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) 14062 return -ERANGE; 14063 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && 14064 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 14065 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN) && 14066 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KCK_32 && 14067 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN_32)) 14068 return -ERANGE; 14069 14070 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 14071 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 14072 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 14073 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); 14074 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); 14075 if (tb[NL80211_REKEY_DATA_AKM]) 14076 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); 14077 14078 wdev_lock(wdev); 14079 if (!wdev->connected) { 14080 err = -ENOTCONN; 14081 goto out; 14082 } 14083 14084 if (!rdev->ops->set_rekey_data) { 14085 err = -EOPNOTSUPP; 14086 goto out; 14087 } 14088 14089 err = rdev_set_rekey_data(rdev, dev, &rekey_data); 14090 out: 14091 wdev_unlock(wdev); 14092 return err; 14093 } 14094 14095 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 14096 struct genl_info *info) 14097 { 14098 struct net_device *dev = info->user_ptr[1]; 14099 struct wireless_dev *wdev = dev->ieee80211_ptr; 14100 14101 if (wdev->iftype != NL80211_IFTYPE_AP && 14102 wdev->iftype != NL80211_IFTYPE_P2P_GO) 14103 return -EINVAL; 14104 14105 if (wdev->ap_unexpected_nlportid) 14106 return -EBUSY; 14107 14108 wdev->ap_unexpected_nlportid = info->snd_portid; 14109 return 0; 14110 } 14111 14112 static int nl80211_probe_client(struct sk_buff *skb, 14113 struct genl_info *info) 14114 { 14115 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14116 struct net_device *dev = info->user_ptr[1]; 14117 struct wireless_dev *wdev = dev->ieee80211_ptr; 14118 struct sk_buff *msg; 14119 void *hdr; 14120 const u8 *addr; 14121 u64 cookie; 14122 int err; 14123 14124 if (wdev->iftype != NL80211_IFTYPE_AP && 14125 wdev->iftype != NL80211_IFTYPE_P2P_GO) 14126 return -EOPNOTSUPP; 14127 14128 if (!info->attrs[NL80211_ATTR_MAC]) 14129 return -EINVAL; 14130 14131 if (!rdev->ops->probe_client) 14132 return -EOPNOTSUPP; 14133 14134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14135 if (!msg) 14136 return -ENOMEM; 14137 14138 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14139 NL80211_CMD_PROBE_CLIENT); 14140 if (!hdr) { 14141 err = -ENOBUFS; 14142 goto free_msg; 14143 } 14144 14145 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 14146 14147 err = rdev_probe_client(rdev, dev, addr, &cookie); 14148 if (err) 14149 goto free_msg; 14150 14151 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 14152 NL80211_ATTR_PAD)) 14153 goto nla_put_failure; 14154 14155 genlmsg_end(msg, hdr); 14156 14157 return genlmsg_reply(msg, info); 14158 14159 nla_put_failure: 14160 err = -ENOBUFS; 14161 free_msg: 14162 nlmsg_free(msg); 14163 return err; 14164 } 14165 14166 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 14167 { 14168 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14169 struct cfg80211_beacon_registration *reg, *nreg; 14170 int rv; 14171 14172 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 14173 return -EOPNOTSUPP; 14174 14175 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 14176 if (!nreg) 14177 return -ENOMEM; 14178 14179 /* First, check if already registered. */ 14180 spin_lock_bh(&rdev->beacon_registrations_lock); 14181 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 14182 if (reg->nlportid == info->snd_portid) { 14183 rv = -EALREADY; 14184 goto out_err; 14185 } 14186 } 14187 /* Add it to the list */ 14188 nreg->nlportid = info->snd_portid; 14189 list_add(&nreg->list, &rdev->beacon_registrations); 14190 14191 spin_unlock_bh(&rdev->beacon_registrations_lock); 14192 14193 return 0; 14194 out_err: 14195 spin_unlock_bh(&rdev->beacon_registrations_lock); 14196 kfree(nreg); 14197 return rv; 14198 } 14199 14200 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 14201 { 14202 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14203 struct wireless_dev *wdev = info->user_ptr[1]; 14204 int err; 14205 14206 if (!rdev->ops->start_p2p_device) 14207 return -EOPNOTSUPP; 14208 14209 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 14210 return -EOPNOTSUPP; 14211 14212 if (wdev_running(wdev)) 14213 return 0; 14214 14215 if (rfkill_blocked(rdev->wiphy.rfkill)) 14216 return -ERFKILL; 14217 14218 err = rdev_start_p2p_device(rdev, wdev); 14219 if (err) 14220 return err; 14221 14222 wdev->is_running = true; 14223 rdev->opencount++; 14224 14225 return 0; 14226 } 14227 14228 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 14229 { 14230 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14231 struct wireless_dev *wdev = info->user_ptr[1]; 14232 14233 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 14234 return -EOPNOTSUPP; 14235 14236 if (!rdev->ops->stop_p2p_device) 14237 return -EOPNOTSUPP; 14238 14239 cfg80211_stop_p2p_device(rdev, wdev); 14240 14241 return 0; 14242 } 14243 14244 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 14245 { 14246 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14247 struct wireless_dev *wdev = info->user_ptr[1]; 14248 struct cfg80211_nan_conf conf = {}; 14249 int err; 14250 14251 if (wdev->iftype != NL80211_IFTYPE_NAN) 14252 return -EOPNOTSUPP; 14253 14254 if (wdev_running(wdev)) 14255 return -EEXIST; 14256 14257 if (rfkill_blocked(rdev->wiphy.rfkill)) 14258 return -ERFKILL; 14259 14260 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 14261 return -EINVAL; 14262 14263 conf.master_pref = 14264 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14265 14266 if (info->attrs[NL80211_ATTR_BANDS]) { 14267 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14268 14269 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14270 return -EOPNOTSUPP; 14271 14272 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14273 return -EINVAL; 14274 14275 conf.bands = bands; 14276 } 14277 14278 err = rdev_start_nan(rdev, wdev, &conf); 14279 if (err) 14280 return err; 14281 14282 wdev->is_running = true; 14283 rdev->opencount++; 14284 14285 return 0; 14286 } 14287 14288 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 14289 { 14290 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14291 struct wireless_dev *wdev = info->user_ptr[1]; 14292 14293 if (wdev->iftype != NL80211_IFTYPE_NAN) 14294 return -EOPNOTSUPP; 14295 14296 cfg80211_stop_nan(rdev, wdev); 14297 14298 return 0; 14299 } 14300 14301 static int validate_nan_filter(struct nlattr *filter_attr) 14302 { 14303 struct nlattr *attr; 14304 int len = 0, n_entries = 0, rem; 14305 14306 nla_for_each_nested(attr, filter_attr, rem) { 14307 len += nla_len(attr); 14308 n_entries++; 14309 } 14310 14311 if (len >= U8_MAX) 14312 return -EINVAL; 14313 14314 return n_entries; 14315 } 14316 14317 static int handle_nan_filter(struct nlattr *attr_filter, 14318 struct cfg80211_nan_func *func, 14319 bool tx) 14320 { 14321 struct nlattr *attr; 14322 int n_entries, rem, i; 14323 struct cfg80211_nan_func_filter *filter; 14324 14325 n_entries = validate_nan_filter(attr_filter); 14326 if (n_entries < 0) 14327 return n_entries; 14328 14329 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 14330 14331 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 14332 if (!filter) 14333 return -ENOMEM; 14334 14335 i = 0; 14336 nla_for_each_nested(attr, attr_filter, rem) { 14337 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 14338 if (!filter[i].filter) 14339 goto err; 14340 14341 filter[i].len = nla_len(attr); 14342 i++; 14343 } 14344 if (tx) { 14345 func->num_tx_filters = n_entries; 14346 func->tx_filters = filter; 14347 } else { 14348 func->num_rx_filters = n_entries; 14349 func->rx_filters = filter; 14350 } 14351 14352 return 0; 14353 14354 err: 14355 i = 0; 14356 nla_for_each_nested(attr, attr_filter, rem) { 14357 kfree(filter[i].filter); 14358 i++; 14359 } 14360 kfree(filter); 14361 return -ENOMEM; 14362 } 14363 14364 static int nl80211_nan_add_func(struct sk_buff *skb, 14365 struct genl_info *info) 14366 { 14367 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14368 struct wireless_dev *wdev = info->user_ptr[1]; 14369 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 14370 struct cfg80211_nan_func *func; 14371 struct sk_buff *msg = NULL; 14372 void *hdr = NULL; 14373 int err = 0; 14374 14375 if (wdev->iftype != NL80211_IFTYPE_NAN) 14376 return -EOPNOTSUPP; 14377 14378 if (!wdev_running(wdev)) 14379 return -ENOTCONN; 14380 14381 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 14382 return -EINVAL; 14383 14384 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 14385 info->attrs[NL80211_ATTR_NAN_FUNC], 14386 nl80211_nan_func_policy, 14387 info->extack); 14388 if (err) 14389 return err; 14390 14391 func = kzalloc(sizeof(*func), GFP_KERNEL); 14392 if (!func) 14393 return -ENOMEM; 14394 14395 func->cookie = cfg80211_assign_cookie(rdev); 14396 14397 if (!tb[NL80211_NAN_FUNC_TYPE]) { 14398 err = -EINVAL; 14399 goto out; 14400 } 14401 14402 14403 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 14404 14405 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 14406 err = -EINVAL; 14407 goto out; 14408 } 14409 14410 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 14411 sizeof(func->service_id)); 14412 14413 func->close_range = 14414 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 14415 14416 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 14417 func->serv_spec_info_len = 14418 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 14419 func->serv_spec_info = 14420 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 14421 func->serv_spec_info_len, 14422 GFP_KERNEL); 14423 if (!func->serv_spec_info) { 14424 err = -ENOMEM; 14425 goto out; 14426 } 14427 } 14428 14429 if (tb[NL80211_NAN_FUNC_TTL]) 14430 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 14431 14432 switch (func->type) { 14433 case NL80211_NAN_FUNC_PUBLISH: 14434 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 14435 err = -EINVAL; 14436 goto out; 14437 } 14438 14439 func->publish_type = 14440 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 14441 func->publish_bcast = 14442 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 14443 14444 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 14445 func->publish_bcast) { 14446 err = -EINVAL; 14447 goto out; 14448 } 14449 break; 14450 case NL80211_NAN_FUNC_SUBSCRIBE: 14451 func->subscribe_active = 14452 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 14453 break; 14454 case NL80211_NAN_FUNC_FOLLOW_UP: 14455 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 14456 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 14457 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 14458 err = -EINVAL; 14459 goto out; 14460 } 14461 14462 func->followup_id = 14463 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 14464 func->followup_reqid = 14465 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 14466 memcpy(func->followup_dest.addr, 14467 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 14468 sizeof(func->followup_dest.addr)); 14469 if (func->ttl) { 14470 err = -EINVAL; 14471 goto out; 14472 } 14473 break; 14474 default: 14475 err = -EINVAL; 14476 goto out; 14477 } 14478 14479 if (tb[NL80211_NAN_FUNC_SRF]) { 14480 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 14481 14482 err = nla_parse_nested_deprecated(srf_tb, 14483 NL80211_NAN_SRF_ATTR_MAX, 14484 tb[NL80211_NAN_FUNC_SRF], 14485 nl80211_nan_srf_policy, 14486 info->extack); 14487 if (err) 14488 goto out; 14489 14490 func->srf_include = 14491 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 14492 14493 if (srf_tb[NL80211_NAN_SRF_BF]) { 14494 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 14495 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 14496 err = -EINVAL; 14497 goto out; 14498 } 14499 14500 func->srf_bf_len = 14501 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 14502 func->srf_bf = 14503 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 14504 func->srf_bf_len, GFP_KERNEL); 14505 if (!func->srf_bf) { 14506 err = -ENOMEM; 14507 goto out; 14508 } 14509 14510 func->srf_bf_idx = 14511 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 14512 } else { 14513 struct nlattr *attr, *mac_attr = 14514 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 14515 int n_entries, rem, i = 0; 14516 14517 if (!mac_attr) { 14518 err = -EINVAL; 14519 goto out; 14520 } 14521 14522 n_entries = validate_acl_mac_addrs(mac_attr); 14523 if (n_entries <= 0) { 14524 err = -EINVAL; 14525 goto out; 14526 } 14527 14528 func->srf_num_macs = n_entries; 14529 func->srf_macs = 14530 kcalloc(n_entries, sizeof(*func->srf_macs), 14531 GFP_KERNEL); 14532 if (!func->srf_macs) { 14533 err = -ENOMEM; 14534 goto out; 14535 } 14536 14537 nla_for_each_nested(attr, mac_attr, rem) 14538 memcpy(func->srf_macs[i++].addr, nla_data(attr), 14539 sizeof(*func->srf_macs)); 14540 } 14541 } 14542 14543 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 14544 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 14545 func, true); 14546 if (err) 14547 goto out; 14548 } 14549 14550 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 14551 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 14552 func, false); 14553 if (err) 14554 goto out; 14555 } 14556 14557 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14558 if (!msg) { 14559 err = -ENOMEM; 14560 goto out; 14561 } 14562 14563 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14564 NL80211_CMD_ADD_NAN_FUNCTION); 14565 /* This can't really happen - we just allocated 4KB */ 14566 if (WARN_ON(!hdr)) { 14567 err = -ENOMEM; 14568 goto out; 14569 } 14570 14571 err = rdev_add_nan_func(rdev, wdev, func); 14572 out: 14573 if (err < 0) { 14574 cfg80211_free_nan_func(func); 14575 nlmsg_free(msg); 14576 return err; 14577 } 14578 14579 /* propagate the instance id and cookie to userspace */ 14580 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 14581 NL80211_ATTR_PAD)) 14582 goto nla_put_failure; 14583 14584 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14585 if (!func_attr) 14586 goto nla_put_failure; 14587 14588 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 14589 func->instance_id)) 14590 goto nla_put_failure; 14591 14592 nla_nest_end(msg, func_attr); 14593 14594 genlmsg_end(msg, hdr); 14595 return genlmsg_reply(msg, info); 14596 14597 nla_put_failure: 14598 nlmsg_free(msg); 14599 return -ENOBUFS; 14600 } 14601 14602 static int nl80211_nan_del_func(struct sk_buff *skb, 14603 struct genl_info *info) 14604 { 14605 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14606 struct wireless_dev *wdev = info->user_ptr[1]; 14607 u64 cookie; 14608 14609 if (wdev->iftype != NL80211_IFTYPE_NAN) 14610 return -EOPNOTSUPP; 14611 14612 if (!wdev_running(wdev)) 14613 return -ENOTCONN; 14614 14615 if (!info->attrs[NL80211_ATTR_COOKIE]) 14616 return -EINVAL; 14617 14618 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 14619 14620 rdev_del_nan_func(rdev, wdev, cookie); 14621 14622 return 0; 14623 } 14624 14625 static int nl80211_nan_change_config(struct sk_buff *skb, 14626 struct genl_info *info) 14627 { 14628 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14629 struct wireless_dev *wdev = info->user_ptr[1]; 14630 struct cfg80211_nan_conf conf = {}; 14631 u32 changed = 0; 14632 14633 if (wdev->iftype != NL80211_IFTYPE_NAN) 14634 return -EOPNOTSUPP; 14635 14636 if (!wdev_running(wdev)) 14637 return -ENOTCONN; 14638 14639 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 14640 conf.master_pref = 14641 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14642 if (conf.master_pref <= 1 || conf.master_pref == 255) 14643 return -EINVAL; 14644 14645 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 14646 } 14647 14648 if (info->attrs[NL80211_ATTR_BANDS]) { 14649 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14650 14651 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14652 return -EOPNOTSUPP; 14653 14654 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14655 return -EINVAL; 14656 14657 conf.bands = bands; 14658 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 14659 } 14660 14661 if (!changed) 14662 return -EINVAL; 14663 14664 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 14665 } 14666 14667 void cfg80211_nan_match(struct wireless_dev *wdev, 14668 struct cfg80211_nan_match_params *match, gfp_t gfp) 14669 { 14670 struct wiphy *wiphy = wdev->wiphy; 14671 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14672 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 14673 struct sk_buff *msg; 14674 void *hdr; 14675 14676 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 14677 return; 14678 14679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14680 if (!msg) 14681 return; 14682 14683 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 14684 if (!hdr) { 14685 nlmsg_free(msg); 14686 return; 14687 } 14688 14689 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14690 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14691 wdev->netdev->ifindex)) || 14692 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14693 NL80211_ATTR_PAD)) 14694 goto nla_put_failure; 14695 14696 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 14697 NL80211_ATTR_PAD) || 14698 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 14699 goto nla_put_failure; 14700 14701 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 14702 if (!match_attr) 14703 goto nla_put_failure; 14704 14705 local_func_attr = nla_nest_start_noflag(msg, 14706 NL80211_NAN_MATCH_FUNC_LOCAL); 14707 if (!local_func_attr) 14708 goto nla_put_failure; 14709 14710 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 14711 goto nla_put_failure; 14712 14713 nla_nest_end(msg, local_func_attr); 14714 14715 peer_func_attr = nla_nest_start_noflag(msg, 14716 NL80211_NAN_MATCH_FUNC_PEER); 14717 if (!peer_func_attr) 14718 goto nla_put_failure; 14719 14720 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 14721 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 14722 goto nla_put_failure; 14723 14724 if (match->info && match->info_len && 14725 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 14726 match->info)) 14727 goto nla_put_failure; 14728 14729 nla_nest_end(msg, peer_func_attr); 14730 nla_nest_end(msg, match_attr); 14731 genlmsg_end(msg, hdr); 14732 14733 if (!wdev->owner_nlportid) 14734 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14735 msg, 0, NL80211_MCGRP_NAN, gfp); 14736 else 14737 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14738 wdev->owner_nlportid); 14739 14740 return; 14741 14742 nla_put_failure: 14743 nlmsg_free(msg); 14744 } 14745 EXPORT_SYMBOL(cfg80211_nan_match); 14746 14747 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 14748 u8 inst_id, 14749 enum nl80211_nan_func_term_reason reason, 14750 u64 cookie, gfp_t gfp) 14751 { 14752 struct wiphy *wiphy = wdev->wiphy; 14753 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14754 struct sk_buff *msg; 14755 struct nlattr *func_attr; 14756 void *hdr; 14757 14758 if (WARN_ON(!inst_id)) 14759 return; 14760 14761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14762 if (!msg) 14763 return; 14764 14765 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 14766 if (!hdr) { 14767 nlmsg_free(msg); 14768 return; 14769 } 14770 14771 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14772 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14773 wdev->netdev->ifindex)) || 14774 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14775 NL80211_ATTR_PAD)) 14776 goto nla_put_failure; 14777 14778 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 14779 NL80211_ATTR_PAD)) 14780 goto nla_put_failure; 14781 14782 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14783 if (!func_attr) 14784 goto nla_put_failure; 14785 14786 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 14787 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 14788 goto nla_put_failure; 14789 14790 nla_nest_end(msg, func_attr); 14791 genlmsg_end(msg, hdr); 14792 14793 if (!wdev->owner_nlportid) 14794 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14795 msg, 0, NL80211_MCGRP_NAN, gfp); 14796 else 14797 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14798 wdev->owner_nlportid); 14799 14800 return; 14801 14802 nla_put_failure: 14803 nlmsg_free(msg); 14804 } 14805 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 14806 14807 static int nl80211_get_protocol_features(struct sk_buff *skb, 14808 struct genl_info *info) 14809 { 14810 void *hdr; 14811 struct sk_buff *msg; 14812 14813 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14814 if (!msg) 14815 return -ENOMEM; 14816 14817 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14818 NL80211_CMD_GET_PROTOCOL_FEATURES); 14819 if (!hdr) 14820 goto nla_put_failure; 14821 14822 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 14823 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 14824 goto nla_put_failure; 14825 14826 genlmsg_end(msg, hdr); 14827 return genlmsg_reply(msg, info); 14828 14829 nla_put_failure: 14830 kfree_skb(msg); 14831 return -ENOBUFS; 14832 } 14833 14834 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 14835 { 14836 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14837 struct cfg80211_update_ft_ies_params ft_params; 14838 struct net_device *dev = info->user_ptr[1]; 14839 14840 if (!rdev->ops->update_ft_ies) 14841 return -EOPNOTSUPP; 14842 14843 if (!info->attrs[NL80211_ATTR_MDID] || 14844 !info->attrs[NL80211_ATTR_IE]) 14845 return -EINVAL; 14846 14847 memset(&ft_params, 0, sizeof(ft_params)); 14848 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 14849 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 14850 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 14851 14852 return rdev_update_ft_ies(rdev, dev, &ft_params); 14853 } 14854 14855 static int nl80211_crit_protocol_start(struct sk_buff *skb, 14856 struct genl_info *info) 14857 { 14858 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14859 struct wireless_dev *wdev = info->user_ptr[1]; 14860 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 14861 u16 duration; 14862 int ret; 14863 14864 if (!rdev->ops->crit_proto_start) 14865 return -EOPNOTSUPP; 14866 14867 if (WARN_ON(!rdev->ops->crit_proto_stop)) 14868 return -EINVAL; 14869 14870 if (rdev->crit_proto_nlportid) 14871 return -EBUSY; 14872 14873 /* determine protocol if provided */ 14874 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 14875 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 14876 14877 if (proto >= NUM_NL80211_CRIT_PROTO) 14878 return -EINVAL; 14879 14880 /* timeout must be provided */ 14881 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 14882 return -EINVAL; 14883 14884 duration = 14885 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 14886 14887 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 14888 if (!ret) 14889 rdev->crit_proto_nlportid = info->snd_portid; 14890 14891 return ret; 14892 } 14893 14894 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 14895 struct genl_info *info) 14896 { 14897 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14898 struct wireless_dev *wdev = info->user_ptr[1]; 14899 14900 if (!rdev->ops->crit_proto_stop) 14901 return -EOPNOTSUPP; 14902 14903 if (rdev->crit_proto_nlportid) { 14904 rdev->crit_proto_nlportid = 0; 14905 rdev_crit_proto_stop(rdev, wdev); 14906 } 14907 return 0; 14908 } 14909 14910 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 14911 struct nlattr *attr, 14912 struct netlink_ext_ack *extack) 14913 { 14914 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 14915 if (attr->nla_type & NLA_F_NESTED) { 14916 NL_SET_ERR_MSG_ATTR(extack, attr, 14917 "unexpected nested data"); 14918 return -EINVAL; 14919 } 14920 14921 return 0; 14922 } 14923 14924 if (!(attr->nla_type & NLA_F_NESTED)) { 14925 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 14926 return -EINVAL; 14927 } 14928 14929 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); 14930 } 14931 14932 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 14933 { 14934 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14935 struct wireless_dev *wdev = 14936 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 14937 info->attrs); 14938 int i, err; 14939 u32 vid, subcmd; 14940 14941 if (!rdev->wiphy.vendor_commands) 14942 return -EOPNOTSUPP; 14943 14944 if (IS_ERR(wdev)) { 14945 err = PTR_ERR(wdev); 14946 if (err != -EINVAL) 14947 return err; 14948 wdev = NULL; 14949 } else if (wdev->wiphy != &rdev->wiphy) { 14950 return -EINVAL; 14951 } 14952 14953 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 14954 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 14955 return -EINVAL; 14956 14957 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 14958 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 14959 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 14960 const struct wiphy_vendor_command *vcmd; 14961 void *data = NULL; 14962 int len = 0; 14963 14964 vcmd = &rdev->wiphy.vendor_commands[i]; 14965 14966 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 14967 continue; 14968 14969 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 14970 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 14971 if (!wdev) 14972 return -EINVAL; 14973 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 14974 !wdev->netdev) 14975 return -EINVAL; 14976 14977 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 14978 if (!wdev_running(wdev)) 14979 return -ENETDOWN; 14980 } 14981 } else { 14982 wdev = NULL; 14983 } 14984 14985 if (!vcmd->doit) 14986 return -EOPNOTSUPP; 14987 14988 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 14989 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14990 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14991 14992 err = nl80211_vendor_check_policy(vcmd, 14993 info->attrs[NL80211_ATTR_VENDOR_DATA], 14994 info->extack); 14995 if (err) 14996 return err; 14997 } 14998 14999 rdev->cur_cmd_info = info; 15000 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 15001 rdev->cur_cmd_info = NULL; 15002 return err; 15003 } 15004 15005 return -EOPNOTSUPP; 15006 } 15007 15008 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 15009 struct netlink_callback *cb, 15010 struct cfg80211_registered_device **rdev, 15011 struct wireless_dev **wdev) 15012 { 15013 struct nlattr **attrbuf; 15014 u32 vid, subcmd; 15015 unsigned int i; 15016 int vcmd_idx = -1; 15017 int err; 15018 void *data = NULL; 15019 unsigned int data_len = 0; 15020 15021 if (cb->args[0]) { 15022 /* subtract the 1 again here */ 15023 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 15024 struct wireless_dev *tmp; 15025 15026 if (!wiphy) 15027 return -ENODEV; 15028 *rdev = wiphy_to_rdev(wiphy); 15029 *wdev = NULL; 15030 15031 if (cb->args[1]) { 15032 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 15033 if (tmp->identifier == cb->args[1] - 1) { 15034 *wdev = tmp; 15035 break; 15036 } 15037 } 15038 } 15039 15040 /* keep rtnl locked in successful case */ 15041 return 0; 15042 } 15043 15044 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 15045 if (!attrbuf) 15046 return -ENOMEM; 15047 15048 err = nlmsg_parse_deprecated(cb->nlh, 15049 GENL_HDRLEN + nl80211_fam.hdrsize, 15050 attrbuf, nl80211_fam.maxattr, 15051 nl80211_policy, NULL); 15052 if (err) 15053 goto out; 15054 15055 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 15056 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { 15057 err = -EINVAL; 15058 goto out; 15059 } 15060 15061 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); 15062 if (IS_ERR(*wdev)) 15063 *wdev = NULL; 15064 15065 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 15066 if (IS_ERR(*rdev)) { 15067 err = PTR_ERR(*rdev); 15068 goto out; 15069 } 15070 15071 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 15072 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 15073 15074 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 15075 const struct wiphy_vendor_command *vcmd; 15076 15077 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 15078 15079 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 15080 continue; 15081 15082 if (!vcmd->dumpit) { 15083 err = -EOPNOTSUPP; 15084 goto out; 15085 } 15086 15087 vcmd_idx = i; 15088 break; 15089 } 15090 15091 if (vcmd_idx < 0) { 15092 err = -EOPNOTSUPP; 15093 goto out; 15094 } 15095 15096 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 15097 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 15098 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 15099 15100 err = nl80211_vendor_check_policy( 15101 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 15102 attrbuf[NL80211_ATTR_VENDOR_DATA], 15103 cb->extack); 15104 if (err) 15105 goto out; 15106 } 15107 15108 /* 0 is the first index - add 1 to parse only once */ 15109 cb->args[0] = (*rdev)->wiphy_idx + 1; 15110 /* add 1 to know if it was NULL */ 15111 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 15112 cb->args[2] = vcmd_idx; 15113 cb->args[3] = (unsigned long)data; 15114 cb->args[4] = data_len; 15115 15116 /* keep rtnl locked in successful case */ 15117 err = 0; 15118 out: 15119 kfree(attrbuf); 15120 return err; 15121 } 15122 15123 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 15124 struct netlink_callback *cb) 15125 { 15126 struct cfg80211_registered_device *rdev; 15127 struct wireless_dev *wdev; 15128 unsigned int vcmd_idx; 15129 const struct wiphy_vendor_command *vcmd; 15130 void *data; 15131 int data_len; 15132 int err; 15133 struct nlattr *vendor_data; 15134 15135 rtnl_lock(); 15136 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 15137 if (err) 15138 goto out; 15139 15140 vcmd_idx = cb->args[2]; 15141 data = (void *)cb->args[3]; 15142 data_len = cb->args[4]; 15143 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 15144 15145 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 15146 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 15147 if (!wdev) { 15148 err = -EINVAL; 15149 goto out; 15150 } 15151 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 15152 !wdev->netdev) { 15153 err = -EINVAL; 15154 goto out; 15155 } 15156 15157 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 15158 if (!wdev_running(wdev)) { 15159 err = -ENETDOWN; 15160 goto out; 15161 } 15162 } 15163 } 15164 15165 while (1) { 15166 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 15167 cb->nlh->nlmsg_seq, NLM_F_MULTI, 15168 NL80211_CMD_VENDOR); 15169 if (!hdr) 15170 break; 15171 15172 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15173 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 15174 wdev_id(wdev), 15175 NL80211_ATTR_PAD))) { 15176 genlmsg_cancel(skb, hdr); 15177 break; 15178 } 15179 15180 vendor_data = nla_nest_start_noflag(skb, 15181 NL80211_ATTR_VENDOR_DATA); 15182 if (!vendor_data) { 15183 genlmsg_cancel(skb, hdr); 15184 break; 15185 } 15186 15187 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 15188 (unsigned long *)&cb->args[5]); 15189 nla_nest_end(skb, vendor_data); 15190 15191 if (err == -ENOBUFS || err == -ENOENT) { 15192 genlmsg_cancel(skb, hdr); 15193 break; 15194 } else if (err <= 0) { 15195 genlmsg_cancel(skb, hdr); 15196 goto out; 15197 } 15198 15199 genlmsg_end(skb, hdr); 15200 } 15201 15202 err = skb->len; 15203 out: 15204 rtnl_unlock(); 15205 return err; 15206 } 15207 15208 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 15209 enum nl80211_commands cmd, 15210 enum nl80211_attrs attr, 15211 int approxlen) 15212 { 15213 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15214 15215 if (WARN_ON(!rdev->cur_cmd_info)) 15216 return NULL; 15217 15218 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 15219 rdev->cur_cmd_info->snd_portid, 15220 rdev->cur_cmd_info->snd_seq, 15221 cmd, attr, NULL, GFP_KERNEL); 15222 } 15223 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 15224 15225 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 15226 { 15227 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 15228 void *hdr = ((void **)skb->cb)[1]; 15229 struct nlattr *data = ((void **)skb->cb)[2]; 15230 15231 /* clear CB data for netlink core to own from now on */ 15232 memset(skb->cb, 0, sizeof(skb->cb)); 15233 15234 if (WARN_ON(!rdev->cur_cmd_info)) { 15235 kfree_skb(skb); 15236 return -EINVAL; 15237 } 15238 15239 nla_nest_end(skb, data); 15240 genlmsg_end(skb, hdr); 15241 return genlmsg_reply(skb, rdev->cur_cmd_info); 15242 } 15243 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 15244 15245 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 15246 { 15247 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15248 15249 if (WARN_ON(!rdev->cur_cmd_info)) 15250 return 0; 15251 15252 return rdev->cur_cmd_info->snd_portid; 15253 } 15254 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 15255 15256 static int nl80211_set_qos_map(struct sk_buff *skb, 15257 struct genl_info *info) 15258 { 15259 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15260 struct cfg80211_qos_map *qos_map = NULL; 15261 struct net_device *dev = info->user_ptr[1]; 15262 u8 *pos, len, num_des, des_len, des; 15263 int ret; 15264 15265 if (!rdev->ops->set_qos_map) 15266 return -EOPNOTSUPP; 15267 15268 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 15269 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 15270 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 15271 15272 if (len % 2) 15273 return -EINVAL; 15274 15275 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 15276 if (!qos_map) 15277 return -ENOMEM; 15278 15279 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 15280 if (num_des) { 15281 des_len = num_des * 15282 sizeof(struct cfg80211_dscp_exception); 15283 memcpy(qos_map->dscp_exception, pos, des_len); 15284 qos_map->num_des = num_des; 15285 for (des = 0; des < num_des; des++) { 15286 if (qos_map->dscp_exception[des].up > 7) { 15287 kfree(qos_map); 15288 return -EINVAL; 15289 } 15290 } 15291 pos += des_len; 15292 } 15293 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 15294 } 15295 15296 wdev_lock(dev->ieee80211_ptr); 15297 ret = nl80211_key_allowed(dev->ieee80211_ptr); 15298 if (!ret) 15299 ret = rdev_set_qos_map(rdev, dev, qos_map); 15300 wdev_unlock(dev->ieee80211_ptr); 15301 15302 kfree(qos_map); 15303 return ret; 15304 } 15305 15306 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 15307 { 15308 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15309 struct net_device *dev = info->user_ptr[1]; 15310 struct wireless_dev *wdev = dev->ieee80211_ptr; 15311 const u8 *peer; 15312 u8 tsid, up; 15313 u16 admitted_time = 0; 15314 int err; 15315 15316 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 15317 return -EOPNOTSUPP; 15318 15319 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 15320 !info->attrs[NL80211_ATTR_USER_PRIO]) 15321 return -EINVAL; 15322 15323 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15324 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 15325 15326 /* WMM uses TIDs 0-7 even for TSPEC */ 15327 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 15328 /* TODO: handle 802.11 TSPEC/admission control 15329 * need more attributes for that (e.g. BA session requirement); 15330 * change the WMM adminssion test above to allow both then 15331 */ 15332 return -EINVAL; 15333 } 15334 15335 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15336 15337 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 15338 admitted_time = 15339 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 15340 if (!admitted_time) 15341 return -EINVAL; 15342 } 15343 15344 wdev_lock(wdev); 15345 switch (wdev->iftype) { 15346 case NL80211_IFTYPE_STATION: 15347 case NL80211_IFTYPE_P2P_CLIENT: 15348 if (wdev->connected) 15349 break; 15350 err = -ENOTCONN; 15351 goto out; 15352 default: 15353 err = -EOPNOTSUPP; 15354 goto out; 15355 } 15356 15357 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 15358 15359 out: 15360 wdev_unlock(wdev); 15361 return err; 15362 } 15363 15364 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 15365 { 15366 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15367 struct net_device *dev = info->user_ptr[1]; 15368 struct wireless_dev *wdev = dev->ieee80211_ptr; 15369 const u8 *peer; 15370 u8 tsid; 15371 int err; 15372 15373 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 15374 return -EINVAL; 15375 15376 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15377 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15378 15379 wdev_lock(wdev); 15380 err = rdev_del_tx_ts(rdev, dev, tsid, peer); 15381 wdev_unlock(wdev); 15382 15383 return err; 15384 } 15385 15386 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 15387 struct genl_info *info) 15388 { 15389 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15390 struct net_device *dev = info->user_ptr[1]; 15391 struct wireless_dev *wdev = dev->ieee80211_ptr; 15392 struct cfg80211_chan_def chandef = {}; 15393 const u8 *addr; 15394 u8 oper_class; 15395 int err; 15396 15397 if (!rdev->ops->tdls_channel_switch || 15398 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15399 return -EOPNOTSUPP; 15400 15401 switch (dev->ieee80211_ptr->iftype) { 15402 case NL80211_IFTYPE_STATION: 15403 case NL80211_IFTYPE_P2P_CLIENT: 15404 break; 15405 default: 15406 return -EOPNOTSUPP; 15407 } 15408 15409 if (!info->attrs[NL80211_ATTR_MAC] || 15410 !info->attrs[NL80211_ATTR_OPER_CLASS]) 15411 return -EINVAL; 15412 15413 err = nl80211_parse_chandef(rdev, info, &chandef); 15414 if (err) 15415 return err; 15416 15417 /* 15418 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 15419 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 15420 * specification is not defined for them. 15421 */ 15422 if (chandef.chan->band == NL80211_BAND_2GHZ && 15423 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 15424 chandef.width != NL80211_CHAN_WIDTH_20) 15425 return -EINVAL; 15426 15427 /* we will be active on the TDLS link */ 15428 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 15429 wdev->iftype)) 15430 return -EINVAL; 15431 15432 /* don't allow switching to DFS channels */ 15433 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 15434 return -EINVAL; 15435 15436 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15437 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 15438 15439 wdev_lock(wdev); 15440 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 15441 wdev_unlock(wdev); 15442 15443 return err; 15444 } 15445 15446 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 15447 struct genl_info *info) 15448 { 15449 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15450 struct net_device *dev = info->user_ptr[1]; 15451 struct wireless_dev *wdev = dev->ieee80211_ptr; 15452 const u8 *addr; 15453 15454 if (!rdev->ops->tdls_channel_switch || 15455 !rdev->ops->tdls_cancel_channel_switch || 15456 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15457 return -EOPNOTSUPP; 15458 15459 switch (dev->ieee80211_ptr->iftype) { 15460 case NL80211_IFTYPE_STATION: 15461 case NL80211_IFTYPE_P2P_CLIENT: 15462 break; 15463 default: 15464 return -EOPNOTSUPP; 15465 } 15466 15467 if (!info->attrs[NL80211_ATTR_MAC]) 15468 return -EINVAL; 15469 15470 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15471 15472 wdev_lock(wdev); 15473 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 15474 wdev_unlock(wdev); 15475 15476 return 0; 15477 } 15478 15479 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 15480 struct genl_info *info) 15481 { 15482 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15483 struct net_device *dev = info->user_ptr[1]; 15484 struct wireless_dev *wdev = dev->ieee80211_ptr; 15485 const struct nlattr *nla; 15486 bool enabled; 15487 15488 if (!rdev->ops->set_multicast_to_unicast) 15489 return -EOPNOTSUPP; 15490 15491 if (wdev->iftype != NL80211_IFTYPE_AP && 15492 wdev->iftype != NL80211_IFTYPE_P2P_GO) 15493 return -EOPNOTSUPP; 15494 15495 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 15496 enabled = nla_get_flag(nla); 15497 15498 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 15499 } 15500 15501 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 15502 { 15503 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15504 struct net_device *dev = info->user_ptr[1]; 15505 struct wireless_dev *wdev = dev->ieee80211_ptr; 15506 struct cfg80211_pmk_conf pmk_conf = {}; 15507 int ret; 15508 15509 if (wdev->iftype != NL80211_IFTYPE_STATION && 15510 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15511 return -EOPNOTSUPP; 15512 15513 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15514 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15515 return -EOPNOTSUPP; 15516 15517 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 15518 return -EINVAL; 15519 15520 wdev_lock(wdev); 15521 if (!wdev->connected) { 15522 ret = -ENOTCONN; 15523 goto out; 15524 } 15525 15526 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15527 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) { 15528 ret = -EINVAL; 15529 goto out; 15530 } 15531 15532 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 15533 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 15534 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 15535 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { 15536 ret = -EINVAL; 15537 goto out; 15538 } 15539 15540 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) 15541 pmk_conf.pmk_r0_name = 15542 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 15543 15544 ret = rdev_set_pmk(rdev, dev, &pmk_conf); 15545 out: 15546 wdev_unlock(wdev); 15547 return ret; 15548 } 15549 15550 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 15551 { 15552 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15553 struct net_device *dev = info->user_ptr[1]; 15554 struct wireless_dev *wdev = dev->ieee80211_ptr; 15555 const u8 *aa; 15556 int ret; 15557 15558 if (wdev->iftype != NL80211_IFTYPE_STATION && 15559 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15560 return -EOPNOTSUPP; 15561 15562 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15563 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15564 return -EOPNOTSUPP; 15565 15566 if (!info->attrs[NL80211_ATTR_MAC]) 15567 return -EINVAL; 15568 15569 wdev_lock(wdev); 15570 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15571 ret = rdev_del_pmk(rdev, dev, aa); 15572 wdev_unlock(wdev); 15573 15574 return ret; 15575 } 15576 15577 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 15578 { 15579 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15580 struct net_device *dev = info->user_ptr[1]; 15581 struct cfg80211_external_auth_params params; 15582 15583 if (!rdev->ops->external_auth) 15584 return -EOPNOTSUPP; 15585 15586 if (!info->attrs[NL80211_ATTR_SSID] && 15587 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 15588 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 15589 return -EINVAL; 15590 15591 if (!info->attrs[NL80211_ATTR_BSSID]) 15592 return -EINVAL; 15593 15594 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 15595 return -EINVAL; 15596 15597 memset(¶ms, 0, sizeof(params)); 15598 15599 if (info->attrs[NL80211_ATTR_SSID]) { 15600 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 15601 if (params.ssid.ssid_len == 0) 15602 return -EINVAL; 15603 memcpy(params.ssid.ssid, 15604 nla_data(info->attrs[NL80211_ATTR_SSID]), 15605 params.ssid.ssid_len); 15606 } 15607 15608 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 15609 ETH_ALEN); 15610 15611 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15612 15613 if (info->attrs[NL80211_ATTR_PMKID]) 15614 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 15615 15616 return rdev_external_auth(rdev, dev, ¶ms); 15617 } 15618 15619 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 15620 { 15621 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; 15622 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15623 struct net_device *dev = info->user_ptr[1]; 15624 struct wireless_dev *wdev = dev->ieee80211_ptr; 15625 const u8 *buf; 15626 size_t len; 15627 u8 *dest; 15628 u16 proto; 15629 bool noencrypt; 15630 u64 cookie = 0; 15631 int link_id; 15632 int err; 15633 15634 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15635 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 15636 return -EOPNOTSUPP; 15637 15638 if (!rdev->ops->tx_control_port) 15639 return -EOPNOTSUPP; 15640 15641 if (!info->attrs[NL80211_ATTR_FRAME] || 15642 !info->attrs[NL80211_ATTR_MAC] || 15643 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 15644 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 15645 return -EINVAL; 15646 } 15647 15648 wdev_lock(wdev); 15649 15650 switch (wdev->iftype) { 15651 case NL80211_IFTYPE_AP: 15652 case NL80211_IFTYPE_P2P_GO: 15653 case NL80211_IFTYPE_MESH_POINT: 15654 break; 15655 case NL80211_IFTYPE_ADHOC: 15656 if (wdev->u.ibss.current_bss) 15657 break; 15658 err = -ENOTCONN; 15659 goto out; 15660 case NL80211_IFTYPE_STATION: 15661 case NL80211_IFTYPE_P2P_CLIENT: 15662 if (wdev->connected) 15663 break; 15664 err = -ENOTCONN; 15665 goto out; 15666 default: 15667 err = -EOPNOTSUPP; 15668 goto out; 15669 } 15670 15671 wdev_unlock(wdev); 15672 15673 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15674 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15675 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15676 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 15677 noencrypt = 15678 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 15679 15680 link_id = nl80211_link_id_or_invalid(info->attrs); 15681 15682 err = rdev_tx_control_port(rdev, dev, buf, len, 15683 dest, cpu_to_be16(proto), noencrypt, link_id, 15684 dont_wait_for_ack ? NULL : &cookie); 15685 if (!err && !dont_wait_for_ack) 15686 nl_set_extack_cookie_u64(info->extack, cookie); 15687 return err; 15688 out: 15689 wdev_unlock(wdev); 15690 return err; 15691 } 15692 15693 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 15694 struct genl_info *info) 15695 { 15696 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15697 struct net_device *dev = info->user_ptr[1]; 15698 struct wireless_dev *wdev = dev->ieee80211_ptr; 15699 struct cfg80211_ftm_responder_stats ftm_stats = {}; 15700 unsigned int link_id = nl80211_link_id(info->attrs); 15701 struct sk_buff *msg; 15702 void *hdr; 15703 struct nlattr *ftm_stats_attr; 15704 int err; 15705 15706 if (wdev->iftype != NL80211_IFTYPE_AP || 15707 !wdev->links[link_id].ap.beacon_interval) 15708 return -EOPNOTSUPP; 15709 15710 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 15711 if (err) 15712 return err; 15713 15714 if (!ftm_stats.filled) 15715 return -ENODATA; 15716 15717 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15718 if (!msg) 15719 return -ENOMEM; 15720 15721 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 15722 NL80211_CMD_GET_FTM_RESPONDER_STATS); 15723 if (!hdr) 15724 goto nla_put_failure; 15725 15726 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 15727 goto nla_put_failure; 15728 15729 ftm_stats_attr = nla_nest_start_noflag(msg, 15730 NL80211_ATTR_FTM_RESPONDER_STATS); 15731 if (!ftm_stats_attr) 15732 goto nla_put_failure; 15733 15734 #define SET_FTM(field, name, type) \ 15735 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15736 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 15737 ftm_stats.field)) \ 15738 goto nla_put_failure; } while (0) 15739 #define SET_FTM_U64(field, name) \ 15740 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15741 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 15742 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 15743 goto nla_put_failure; } while (0) 15744 15745 SET_FTM(success_num, SUCCESS_NUM, u32); 15746 SET_FTM(partial_num, PARTIAL_NUM, u32); 15747 SET_FTM(failed_num, FAILED_NUM, u32); 15748 SET_FTM(asap_num, ASAP_NUM, u32); 15749 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 15750 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 15751 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 15752 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 15753 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 15754 #undef SET_FTM 15755 15756 nla_nest_end(msg, ftm_stats_attr); 15757 15758 genlmsg_end(msg, hdr); 15759 return genlmsg_reply(msg, info); 15760 15761 nla_put_failure: 15762 nlmsg_free(msg); 15763 return -ENOBUFS; 15764 } 15765 15766 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 15767 { 15768 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15769 struct cfg80211_update_owe_info owe_info; 15770 struct net_device *dev = info->user_ptr[1]; 15771 15772 if (!rdev->ops->update_owe_info) 15773 return -EOPNOTSUPP; 15774 15775 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 15776 !info->attrs[NL80211_ATTR_MAC]) 15777 return -EINVAL; 15778 15779 memset(&owe_info, 0, sizeof(owe_info)); 15780 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15781 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 15782 15783 if (info->attrs[NL80211_ATTR_IE]) { 15784 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 15785 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 15786 } 15787 15788 return rdev_update_owe_info(rdev, dev, &owe_info); 15789 } 15790 15791 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 15792 { 15793 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15794 struct net_device *dev = info->user_ptr[1]; 15795 struct wireless_dev *wdev = dev->ieee80211_ptr; 15796 struct station_info sinfo = {}; 15797 const u8 *buf; 15798 size_t len; 15799 u8 *dest; 15800 int err; 15801 15802 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 15803 return -EOPNOTSUPP; 15804 15805 if (!info->attrs[NL80211_ATTR_MAC] || 15806 !info->attrs[NL80211_ATTR_FRAME]) { 15807 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 15808 return -EINVAL; 15809 } 15810 15811 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 15812 return -EOPNOTSUPP; 15813 15814 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15815 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15816 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15817 15818 if (len < sizeof(struct ethhdr)) 15819 return -EINVAL; 15820 15821 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 15822 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 15823 return -EINVAL; 15824 15825 err = rdev_get_station(rdev, dev, dest, &sinfo); 15826 if (err) 15827 return err; 15828 15829 cfg80211_sinfo_release_content(&sinfo); 15830 15831 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 15832 } 15833 15834 static int parse_tid_conf(struct cfg80211_registered_device *rdev, 15835 struct nlattr *attrs[], struct net_device *dev, 15836 struct cfg80211_tid_cfg *tid_conf, 15837 struct genl_info *info, const u8 *peer, 15838 unsigned int link_id) 15839 { 15840 struct netlink_ext_ack *extack = info->extack; 15841 u64 mask; 15842 int err; 15843 15844 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) 15845 return -EINVAL; 15846 15847 tid_conf->config_override = 15848 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); 15849 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); 15850 15851 if (tid_conf->config_override) { 15852 if (rdev->ops->reset_tid_config) { 15853 err = rdev_reset_tid_config(rdev, dev, peer, 15854 tid_conf->tids); 15855 if (err) 15856 return err; 15857 } else { 15858 return -EINVAL; 15859 } 15860 } 15861 15862 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { 15863 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); 15864 tid_conf->noack = 15865 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); 15866 } 15867 15868 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { 15869 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); 15870 tid_conf->retry_short = 15871 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); 15872 15873 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) 15874 return -EINVAL; 15875 } 15876 15877 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { 15878 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); 15879 tid_conf->retry_long = 15880 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); 15881 15882 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) 15883 return -EINVAL; 15884 } 15885 15886 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { 15887 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); 15888 tid_conf->ampdu = 15889 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); 15890 } 15891 15892 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { 15893 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); 15894 tid_conf->rtscts = 15895 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); 15896 } 15897 15898 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { 15899 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); 15900 tid_conf->amsdu = 15901 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); 15902 } 15903 15904 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { 15905 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; 15906 15907 tid_conf->txrate_type = nla_get_u8(attrs[idx]); 15908 15909 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { 15910 attr = NL80211_TID_CONFIG_ATTR_TX_RATE; 15911 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, 15912 &tid_conf->txrate_mask, dev, 15913 true, link_id); 15914 if (err) 15915 return err; 15916 15917 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); 15918 } 15919 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); 15920 } 15921 15922 if (peer) 15923 mask = rdev->wiphy.tid_config_support.peer; 15924 else 15925 mask = rdev->wiphy.tid_config_support.vif; 15926 15927 if (tid_conf->mask & ~mask) { 15928 NL_SET_ERR_MSG(extack, "unsupported TID configuration"); 15929 return -ENOTSUPP; 15930 } 15931 15932 return 0; 15933 } 15934 15935 static int nl80211_set_tid_config(struct sk_buff *skb, 15936 struct genl_info *info) 15937 { 15938 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15939 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; 15940 unsigned int link_id = nl80211_link_id(info->attrs); 15941 struct net_device *dev = info->user_ptr[1]; 15942 struct cfg80211_tid_config *tid_config; 15943 struct nlattr *tid; 15944 int conf_idx = 0, rem_conf; 15945 int ret = -EINVAL; 15946 u32 num_conf = 0; 15947 15948 if (!info->attrs[NL80211_ATTR_TID_CONFIG]) 15949 return -EINVAL; 15950 15951 if (!rdev->ops->set_tid_config) 15952 return -EOPNOTSUPP; 15953 15954 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15955 rem_conf) 15956 num_conf++; 15957 15958 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), 15959 GFP_KERNEL); 15960 if (!tid_config) 15961 return -ENOMEM; 15962 15963 tid_config->n_tid_conf = num_conf; 15964 15965 if (info->attrs[NL80211_ATTR_MAC]) 15966 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15967 15968 wdev_lock(dev->ieee80211_ptr); 15969 15970 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15971 rem_conf) { 15972 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, 15973 tid, NULL, NULL); 15974 15975 if (ret) 15976 goto bad_tid_conf; 15977 15978 ret = parse_tid_conf(rdev, attrs, dev, 15979 &tid_config->tid_conf[conf_idx], 15980 info, tid_config->peer, link_id); 15981 if (ret) 15982 goto bad_tid_conf; 15983 15984 conf_idx++; 15985 } 15986 15987 ret = rdev_set_tid_config(rdev, dev, tid_config); 15988 15989 bad_tid_conf: 15990 kfree(tid_config); 15991 wdev_unlock(dev->ieee80211_ptr); 15992 return ret; 15993 } 15994 15995 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) 15996 { 15997 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15998 struct cfg80211_color_change_settings params = {}; 15999 struct net_device *dev = info->user_ptr[1]; 16000 struct wireless_dev *wdev = dev->ieee80211_ptr; 16001 struct nlattr **tb; 16002 u16 offset; 16003 int err; 16004 16005 if (!rdev->ops->color_change) 16006 return -EOPNOTSUPP; 16007 16008 if (!wiphy_ext_feature_isset(&rdev->wiphy, 16009 NL80211_EXT_FEATURE_BSS_COLOR)) 16010 return -EOPNOTSUPP; 16011 16012 if (wdev->iftype != NL80211_IFTYPE_AP) 16013 return -EOPNOTSUPP; 16014 16015 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] || 16016 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] || 16017 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS]) 16018 return -EINVAL; 16019 16020 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]); 16021 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]); 16022 16023 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next, 16024 info->extack); 16025 if (err) 16026 return err; 16027 16028 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL); 16029 if (!tb) 16030 return -ENOMEM; 16031 16032 err = nla_parse_nested(tb, NL80211_ATTR_MAX, 16033 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS], 16034 nl80211_policy, info->extack); 16035 if (err) 16036 goto out; 16037 16038 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change, 16039 info->extack); 16040 if (err) 16041 goto out; 16042 16043 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 16044 err = -EINVAL; 16045 goto out; 16046 } 16047 16048 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) { 16049 err = -EINVAL; 16050 goto out; 16051 } 16052 16053 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 16054 if (offset >= params.beacon_color_change.tail_len) { 16055 err = -EINVAL; 16056 goto out; 16057 } 16058 16059 if (params.beacon_color_change.tail[offset] != params.count) { 16060 err = -EINVAL; 16061 goto out; 16062 } 16063 16064 params.counter_offset_beacon = offset; 16065 16066 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 16067 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) != 16068 sizeof(u16)) { 16069 err = -EINVAL; 16070 goto out; 16071 } 16072 16073 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 16074 if (offset >= params.beacon_color_change.probe_resp_len) { 16075 err = -EINVAL; 16076 goto out; 16077 } 16078 16079 if (params.beacon_color_change.probe_resp[offset] != 16080 params.count) { 16081 err = -EINVAL; 16082 goto out; 16083 } 16084 16085 params.counter_offset_presp = offset; 16086 } 16087 16088 wdev_lock(wdev); 16089 err = rdev_color_change(rdev, dev, ¶ms); 16090 wdev_unlock(wdev); 16091 16092 out: 16093 kfree(params.beacon_next.mbssid_ies); 16094 kfree(params.beacon_color_change.mbssid_ies); 16095 kfree(params.beacon_next.rnr_ies); 16096 kfree(params.beacon_color_change.rnr_ies); 16097 kfree(tb); 16098 return err; 16099 } 16100 16101 static int nl80211_set_fils_aad(struct sk_buff *skb, 16102 struct genl_info *info) 16103 { 16104 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16105 struct net_device *dev = info->user_ptr[1]; 16106 struct cfg80211_fils_aad fils_aad = {}; 16107 u8 *nonces; 16108 16109 if (!info->attrs[NL80211_ATTR_MAC] || 16110 !info->attrs[NL80211_ATTR_FILS_KEK] || 16111 !info->attrs[NL80211_ATTR_FILS_NONCES]) 16112 return -EINVAL; 16113 16114 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); 16115 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 16116 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 16117 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 16118 fils_aad.snonce = nonces; 16119 fils_aad.anonce = nonces + FILS_NONCE_LEN; 16120 16121 return rdev_set_fils_aad(rdev, dev, &fils_aad); 16122 } 16123 16124 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info) 16125 { 16126 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16127 unsigned int link_id = nl80211_link_id(info->attrs); 16128 struct net_device *dev = info->user_ptr[1]; 16129 struct wireless_dev *wdev = dev->ieee80211_ptr; 16130 int ret; 16131 16132 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) 16133 return -EINVAL; 16134 16135 switch (wdev->iftype) { 16136 case NL80211_IFTYPE_AP: 16137 break; 16138 default: 16139 return -EINVAL; 16140 } 16141 16142 if (!info->attrs[NL80211_ATTR_MAC] || 16143 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC]))) 16144 return -EINVAL; 16145 16146 wdev_lock(wdev); 16147 wdev->valid_links |= BIT(link_id); 16148 ether_addr_copy(wdev->links[link_id].addr, 16149 nla_data(info->attrs[NL80211_ATTR_MAC])); 16150 16151 ret = rdev_add_intf_link(rdev, wdev, link_id); 16152 if (ret) { 16153 wdev->valid_links &= ~BIT(link_id); 16154 eth_zero_addr(wdev->links[link_id].addr); 16155 } 16156 wdev_unlock(wdev); 16157 16158 return ret; 16159 } 16160 16161 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info) 16162 { 16163 unsigned int link_id = nl80211_link_id(info->attrs); 16164 struct net_device *dev = info->user_ptr[1]; 16165 struct wireless_dev *wdev = dev->ieee80211_ptr; 16166 16167 /* cannot remove if there's no link */ 16168 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16169 return -EINVAL; 16170 16171 switch (wdev->iftype) { 16172 case NL80211_IFTYPE_AP: 16173 break; 16174 default: 16175 return -EINVAL; 16176 } 16177 16178 wdev_lock(wdev); 16179 cfg80211_remove_link(wdev, link_id); 16180 wdev_unlock(wdev); 16181 16182 return 0; 16183 } 16184 16185 static int 16186 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info, 16187 bool add) 16188 { 16189 struct link_station_parameters params = {}; 16190 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16191 struct net_device *dev = info->user_ptr[1]; 16192 int err; 16193 16194 if ((add && !rdev->ops->add_link_station) || 16195 (!add && !rdev->ops->mod_link_station)) 16196 return -EOPNOTSUPP; 16197 16198 if (add && !info->attrs[NL80211_ATTR_MAC]) 16199 return -EINVAL; 16200 16201 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 16202 return -EINVAL; 16203 16204 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 16205 return -EINVAL; 16206 16207 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 16208 16209 if (info->attrs[NL80211_ATTR_MAC]) { 16210 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 16211 if (!is_valid_ether_addr(params.link_mac)) 16212 return -EINVAL; 16213 } 16214 16215 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16216 return -EINVAL; 16217 16218 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 16219 16220 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 16221 params.supported_rates = 16222 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 16223 params.supported_rates_len = 16224 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 16225 } 16226 16227 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 16228 params.ht_capa = 16229 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 16230 16231 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 16232 params.vht_capa = 16233 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 16234 16235 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 16236 params.he_capa = 16237 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 16238 params.he_capa_len = 16239 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 16240 16241 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 16242 params.eht_capa = 16243 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 16244 params.eht_capa_len = 16245 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 16246 16247 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa, 16248 (const u8 *)params.eht_capa, 16249 params.eht_capa_len, 16250 false)) 16251 return -EINVAL; 16252 } 16253 } 16254 16255 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 16256 params.he_6ghz_capa = 16257 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 16258 16259 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 16260 params.opmode_notif_used = true; 16261 params.opmode_notif = 16262 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 16263 } 16264 16265 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr, 16266 ¶ms.txpwr_set); 16267 if (err) 16268 return err; 16269 16270 wdev_lock(dev->ieee80211_ptr); 16271 if (add) 16272 err = rdev_add_link_station(rdev, dev, ¶ms); 16273 else 16274 err = rdev_mod_link_station(rdev, dev, ¶ms); 16275 wdev_unlock(dev->ieee80211_ptr); 16276 16277 return err; 16278 } 16279 16280 static int 16281 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info) 16282 { 16283 return nl80211_add_mod_link_station(skb, info, true); 16284 } 16285 16286 static int 16287 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info) 16288 { 16289 return nl80211_add_mod_link_station(skb, info, false); 16290 } 16291 16292 static int 16293 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info) 16294 { 16295 struct link_station_del_parameters params = {}; 16296 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16297 struct net_device *dev = info->user_ptr[1]; 16298 int ret; 16299 16300 if (!rdev->ops->del_link_station) 16301 return -EOPNOTSUPP; 16302 16303 if (!info->attrs[NL80211_ATTR_MLD_ADDR] || 16304 !info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16305 return -EINVAL; 16306 16307 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 16308 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 16309 16310 wdev_lock(dev->ieee80211_ptr); 16311 ret = rdev_del_link_station(rdev, dev, ¶ms); 16312 wdev_unlock(dev->ieee80211_ptr); 16313 16314 return ret; 16315 } 16316 16317 static int nl80211_set_hw_timestamp(struct sk_buff *skb, 16318 struct genl_info *info) 16319 { 16320 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16321 struct net_device *dev = info->user_ptr[1]; 16322 struct cfg80211_set_hw_timestamp hwts = {}; 16323 16324 if (!rdev->wiphy.hw_timestamp_max_peers) 16325 return -EOPNOTSUPP; 16326 16327 if (!info->attrs[NL80211_ATTR_MAC] && 16328 rdev->wiphy.hw_timestamp_max_peers != CFG80211_HW_TIMESTAMP_ALL_PEERS) 16329 return -EOPNOTSUPP; 16330 16331 if (info->attrs[NL80211_ATTR_MAC]) 16332 hwts.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); 16333 16334 hwts.enable = 16335 nla_get_flag(info->attrs[NL80211_ATTR_HW_TIMESTAMP_ENABLED]); 16336 16337 return rdev_set_hw_timestamp(rdev, dev, &hwts); 16338 } 16339 16340 #define NL80211_FLAG_NEED_WIPHY 0x01 16341 #define NL80211_FLAG_NEED_NETDEV 0x02 16342 #define NL80211_FLAG_NEED_RTNL 0x04 16343 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 16344 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 16345 NL80211_FLAG_CHECK_NETDEV_UP) 16346 #define NL80211_FLAG_NEED_WDEV 0x10 16347 /* If a netdev is associated, it must be UP, P2P must be started */ 16348 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 16349 NL80211_FLAG_CHECK_NETDEV_UP) 16350 #define NL80211_FLAG_CLEAR_SKB 0x20 16351 #define NL80211_FLAG_NO_WIPHY_MTX 0x40 16352 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80 16353 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100 16354 16355 #define INTERNAL_FLAG_SELECTORS(__sel) \ 16356 SELECTOR(__sel, NONE, 0) /* must be first */ \ 16357 SELECTOR(__sel, WIPHY, \ 16358 NL80211_FLAG_NEED_WIPHY) \ 16359 SELECTOR(__sel, WDEV, \ 16360 NL80211_FLAG_NEED_WDEV) \ 16361 SELECTOR(__sel, NETDEV, \ 16362 NL80211_FLAG_NEED_NETDEV) \ 16363 SELECTOR(__sel, NETDEV_LINK, \ 16364 NL80211_FLAG_NEED_NETDEV | \ 16365 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16366 SELECTOR(__sel, NETDEV_NO_MLO, \ 16367 NL80211_FLAG_NEED_NETDEV | \ 16368 NL80211_FLAG_MLO_UNSUPPORTED) \ 16369 SELECTOR(__sel, WIPHY_RTNL, \ 16370 NL80211_FLAG_NEED_WIPHY | \ 16371 NL80211_FLAG_NEED_RTNL) \ 16372 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \ 16373 NL80211_FLAG_NEED_WIPHY | \ 16374 NL80211_FLAG_NEED_RTNL | \ 16375 NL80211_FLAG_NO_WIPHY_MTX) \ 16376 SELECTOR(__sel, WDEV_RTNL, \ 16377 NL80211_FLAG_NEED_WDEV | \ 16378 NL80211_FLAG_NEED_RTNL) \ 16379 SELECTOR(__sel, NETDEV_RTNL, \ 16380 NL80211_FLAG_NEED_NETDEV | \ 16381 NL80211_FLAG_NEED_RTNL) \ 16382 SELECTOR(__sel, NETDEV_UP, \ 16383 NL80211_FLAG_NEED_NETDEV_UP) \ 16384 SELECTOR(__sel, NETDEV_UP_LINK, \ 16385 NL80211_FLAG_NEED_NETDEV_UP | \ 16386 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16387 SELECTOR(__sel, NETDEV_UP_NO_MLO, \ 16388 NL80211_FLAG_NEED_NETDEV_UP | \ 16389 NL80211_FLAG_MLO_UNSUPPORTED) \ 16390 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \ 16391 NL80211_FLAG_NEED_NETDEV_UP | \ 16392 NL80211_FLAG_CLEAR_SKB | \ 16393 NL80211_FLAG_MLO_UNSUPPORTED) \ 16394 SELECTOR(__sel, NETDEV_UP_NOTMX, \ 16395 NL80211_FLAG_NEED_NETDEV_UP | \ 16396 NL80211_FLAG_NO_WIPHY_MTX) \ 16397 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \ 16398 NL80211_FLAG_NEED_NETDEV_UP | \ 16399 NL80211_FLAG_NO_WIPHY_MTX | \ 16400 NL80211_FLAG_MLO_UNSUPPORTED) \ 16401 SELECTOR(__sel, NETDEV_UP_CLEAR, \ 16402 NL80211_FLAG_NEED_NETDEV_UP | \ 16403 NL80211_FLAG_CLEAR_SKB) \ 16404 SELECTOR(__sel, WDEV_UP, \ 16405 NL80211_FLAG_NEED_WDEV_UP) \ 16406 SELECTOR(__sel, WDEV_UP_LINK, \ 16407 NL80211_FLAG_NEED_WDEV_UP | \ 16408 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16409 SELECTOR(__sel, WDEV_UP_RTNL, \ 16410 NL80211_FLAG_NEED_WDEV_UP | \ 16411 NL80211_FLAG_NEED_RTNL) \ 16412 SELECTOR(__sel, WIPHY_CLEAR, \ 16413 NL80211_FLAG_NEED_WIPHY | \ 16414 NL80211_FLAG_CLEAR_SKB) 16415 16416 enum nl80211_internal_flags_selector { 16417 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name, 16418 INTERNAL_FLAG_SELECTORS(_) 16419 #undef SELECTOR 16420 }; 16421 16422 static u32 nl80211_internal_flags[] = { 16423 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value, 16424 INTERNAL_FLAG_SELECTORS(_) 16425 #undef SELECTOR 16426 }; 16427 16428 static int nl80211_pre_doit(const struct genl_split_ops *ops, 16429 struct sk_buff *skb, 16430 struct genl_info *info) 16431 { 16432 struct cfg80211_registered_device *rdev = NULL; 16433 struct wireless_dev *wdev = NULL; 16434 struct net_device *dev = NULL; 16435 u32 internal_flags; 16436 int err; 16437 16438 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags))) 16439 return -EINVAL; 16440 16441 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16442 16443 rtnl_lock(); 16444 if (internal_flags & NL80211_FLAG_NEED_WIPHY) { 16445 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 16446 if (IS_ERR(rdev)) { 16447 err = PTR_ERR(rdev); 16448 goto out_unlock; 16449 } 16450 info->user_ptr[0] = rdev; 16451 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV || 16452 internal_flags & NL80211_FLAG_NEED_WDEV) { 16453 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), 16454 info->attrs); 16455 if (IS_ERR(wdev)) { 16456 err = PTR_ERR(wdev); 16457 goto out_unlock; 16458 } 16459 16460 dev = wdev->netdev; 16461 dev_hold(dev); 16462 rdev = wiphy_to_rdev(wdev->wiphy); 16463 16464 if (internal_flags & NL80211_FLAG_NEED_NETDEV) { 16465 if (!dev) { 16466 err = -EINVAL; 16467 goto out_unlock; 16468 } 16469 16470 info->user_ptr[1] = dev; 16471 } else { 16472 info->user_ptr[1] = wdev; 16473 } 16474 16475 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 16476 !wdev_running(wdev)) { 16477 err = -ENETDOWN; 16478 goto out_unlock; 16479 } 16480 16481 info->user_ptr[0] = rdev; 16482 } 16483 16484 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) { 16485 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID]; 16486 16487 if (!wdev) { 16488 err = -EINVAL; 16489 goto out_unlock; 16490 } 16491 16492 /* MLO -> require valid link ID */ 16493 if (wdev->valid_links && 16494 (!link_id || 16495 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) { 16496 err = -EINVAL; 16497 goto out_unlock; 16498 } 16499 16500 /* non-MLO -> no link ID attribute accepted */ 16501 if (!wdev->valid_links && link_id) { 16502 err = -EINVAL; 16503 goto out_unlock; 16504 } 16505 } 16506 16507 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) { 16508 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] || 16509 (wdev && wdev->valid_links)) { 16510 err = -EINVAL; 16511 goto out_unlock; 16512 } 16513 } 16514 16515 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16516 wiphy_lock(&rdev->wiphy); 16517 /* we keep the mutex locked until post_doit */ 16518 __release(&rdev->wiphy.mtx); 16519 } 16520 if (!(internal_flags & NL80211_FLAG_NEED_RTNL)) 16521 rtnl_unlock(); 16522 16523 return 0; 16524 out_unlock: 16525 rtnl_unlock(); 16526 dev_put(dev); 16527 return err; 16528 } 16529 16530 static void nl80211_post_doit(const struct genl_split_ops *ops, 16531 struct sk_buff *skb, 16532 struct genl_info *info) 16533 { 16534 u32 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16535 16536 if (info->user_ptr[1]) { 16537 if (internal_flags & NL80211_FLAG_NEED_WDEV) { 16538 struct wireless_dev *wdev = info->user_ptr[1]; 16539 16540 dev_put(wdev->netdev); 16541 } else { 16542 dev_put(info->user_ptr[1]); 16543 } 16544 } 16545 16546 if (info->user_ptr[0] && 16547 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16548 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16549 16550 /* we kept the mutex locked since pre_doit */ 16551 __acquire(&rdev->wiphy.mtx); 16552 wiphy_unlock(&rdev->wiphy); 16553 } 16554 16555 if (internal_flags & NL80211_FLAG_NEED_RTNL) 16556 rtnl_unlock(); 16557 16558 /* If needed, clear the netlink message payload from the SKB 16559 * as it might contain key data that shouldn't stick around on 16560 * the heap after the SKB is freed. The netlink message header 16561 * is still needed for further processing, so leave it intact. 16562 */ 16563 if (internal_flags & NL80211_FLAG_CLEAR_SKB) { 16564 struct nlmsghdr *nlh = nlmsg_hdr(skb); 16565 16566 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 16567 } 16568 } 16569 16570 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, 16571 struct cfg80211_sar_specs *sar_specs, 16572 struct nlattr *spec[], int index) 16573 { 16574 u32 range_index, i; 16575 16576 if (!sar_specs || !spec) 16577 return -EINVAL; 16578 16579 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || 16580 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) 16581 return -EINVAL; 16582 16583 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); 16584 16585 /* check if range_index exceeds num_freq_ranges */ 16586 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) 16587 return -EINVAL; 16588 16589 /* check if range_index duplicates */ 16590 for (i = 0; i < index; i++) { 16591 if (sar_specs->sub_specs[i].freq_range_index == range_index) 16592 return -EINVAL; 16593 } 16594 16595 sar_specs->sub_specs[index].power = 16596 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); 16597 16598 sar_specs->sub_specs[index].freq_range_index = range_index; 16599 16600 return 0; 16601 } 16602 16603 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) 16604 { 16605 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16606 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; 16607 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; 16608 struct cfg80211_sar_specs *sar_spec; 16609 enum nl80211_sar_type type; 16610 struct nlattr *spec_list; 16611 u32 specs; 16612 int rem, err; 16613 16614 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) 16615 return -EOPNOTSUPP; 16616 16617 if (!info->attrs[NL80211_ATTR_SAR_SPEC]) 16618 return -EINVAL; 16619 16620 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, 16621 info->attrs[NL80211_ATTR_SAR_SPEC], 16622 NULL, NULL); 16623 16624 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) 16625 return -EINVAL; 16626 16627 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); 16628 if (type != rdev->wiphy.sar_capa->type) 16629 return -EINVAL; 16630 16631 specs = 0; 16632 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) 16633 specs++; 16634 16635 if (specs > rdev->wiphy.sar_capa->num_freq_ranges) 16636 return -EINVAL; 16637 16638 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL); 16639 if (!sar_spec) 16640 return -ENOMEM; 16641 16642 sar_spec->type = type; 16643 specs = 0; 16644 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { 16645 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, 16646 spec_list, NULL, NULL); 16647 16648 switch (type) { 16649 case NL80211_SAR_TYPE_POWER: 16650 if (nl80211_set_sar_sub_specs(rdev, sar_spec, 16651 spec, specs)) { 16652 err = -EINVAL; 16653 goto error; 16654 } 16655 break; 16656 default: 16657 err = -EINVAL; 16658 goto error; 16659 } 16660 specs++; 16661 } 16662 16663 sar_spec->num_sub_specs = specs; 16664 16665 rdev->cur_cmd_info = info; 16666 err = rdev_set_sar_specs(rdev, sar_spec); 16667 rdev->cur_cmd_info = NULL; 16668 error: 16669 kfree(sar_spec); 16670 return err; 16671 } 16672 16673 #define SELECTOR(__sel, name, value) \ 16674 ((__sel) == (value)) ? NL80211_IFL_SEL_##name : 16675 int __missing_selector(void); 16676 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector() 16677 16678 static const struct genl_ops nl80211_ops[] = { 16679 { 16680 .cmd = NL80211_CMD_GET_WIPHY, 16681 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16682 .doit = nl80211_get_wiphy, 16683 .dumpit = nl80211_dump_wiphy, 16684 .done = nl80211_dump_wiphy_done, 16685 /* can be retrieved by unprivileged users */ 16686 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16687 }, 16688 }; 16689 16690 static const struct genl_small_ops nl80211_small_ops[] = { 16691 { 16692 .cmd = NL80211_CMD_SET_WIPHY, 16693 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16694 .doit = nl80211_set_wiphy, 16695 .flags = GENL_UNS_ADMIN_PERM, 16696 }, 16697 { 16698 .cmd = NL80211_CMD_GET_INTERFACE, 16699 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16700 .doit = nl80211_get_interface, 16701 .dumpit = nl80211_dump_interface, 16702 /* can be retrieved by unprivileged users */ 16703 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 16704 }, 16705 { 16706 .cmd = NL80211_CMD_SET_INTERFACE, 16707 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16708 .doit = nl80211_set_interface, 16709 .flags = GENL_UNS_ADMIN_PERM, 16710 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16711 NL80211_FLAG_NEED_RTNL), 16712 }, 16713 { 16714 .cmd = NL80211_CMD_NEW_INTERFACE, 16715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16716 .doit = nl80211_new_interface, 16717 .flags = GENL_UNS_ADMIN_PERM, 16718 .internal_flags = 16719 IFLAGS(NL80211_FLAG_NEED_WIPHY | 16720 NL80211_FLAG_NEED_RTNL | 16721 /* we take the wiphy mutex later ourselves */ 16722 NL80211_FLAG_NO_WIPHY_MTX), 16723 }, 16724 { 16725 .cmd = NL80211_CMD_DEL_INTERFACE, 16726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16727 .doit = nl80211_del_interface, 16728 .flags = GENL_UNS_ADMIN_PERM, 16729 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 16730 NL80211_FLAG_NEED_RTNL), 16731 }, 16732 { 16733 .cmd = NL80211_CMD_GET_KEY, 16734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16735 .doit = nl80211_get_key, 16736 .flags = GENL_UNS_ADMIN_PERM, 16737 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16738 }, 16739 { 16740 .cmd = NL80211_CMD_SET_KEY, 16741 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16742 .doit = nl80211_set_key, 16743 .flags = GENL_UNS_ADMIN_PERM, 16744 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */ 16745 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16746 NL80211_FLAG_CLEAR_SKB), 16747 }, 16748 { 16749 .cmd = NL80211_CMD_NEW_KEY, 16750 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16751 .doit = nl80211_new_key, 16752 .flags = GENL_UNS_ADMIN_PERM, 16753 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16754 NL80211_FLAG_CLEAR_SKB), 16755 }, 16756 { 16757 .cmd = NL80211_CMD_DEL_KEY, 16758 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16759 .doit = nl80211_del_key, 16760 .flags = GENL_UNS_ADMIN_PERM, 16761 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16762 }, 16763 { 16764 .cmd = NL80211_CMD_SET_BEACON, 16765 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16766 .flags = GENL_UNS_ADMIN_PERM, 16767 .doit = nl80211_set_beacon, 16768 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16769 NL80211_FLAG_MLO_VALID_LINK_ID), 16770 }, 16771 { 16772 .cmd = NL80211_CMD_START_AP, 16773 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16774 .flags = GENL_UNS_ADMIN_PERM, 16775 .doit = nl80211_start_ap, 16776 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16777 NL80211_FLAG_MLO_VALID_LINK_ID), 16778 }, 16779 { 16780 .cmd = NL80211_CMD_STOP_AP, 16781 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16782 .flags = GENL_UNS_ADMIN_PERM, 16783 .doit = nl80211_stop_ap, 16784 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16785 NL80211_FLAG_MLO_VALID_LINK_ID), 16786 }, 16787 { 16788 .cmd = NL80211_CMD_GET_STATION, 16789 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16790 .doit = nl80211_get_station, 16791 .dumpit = nl80211_dump_station, 16792 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16793 }, 16794 { 16795 .cmd = NL80211_CMD_SET_STATION, 16796 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16797 .doit = nl80211_set_station, 16798 .flags = GENL_UNS_ADMIN_PERM, 16799 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16800 }, 16801 { 16802 .cmd = NL80211_CMD_NEW_STATION, 16803 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16804 .doit = nl80211_new_station, 16805 .flags = GENL_UNS_ADMIN_PERM, 16806 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16807 }, 16808 { 16809 .cmd = NL80211_CMD_DEL_STATION, 16810 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16811 .doit = nl80211_del_station, 16812 .flags = GENL_UNS_ADMIN_PERM, 16813 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16814 }, 16815 { 16816 .cmd = NL80211_CMD_GET_MPATH, 16817 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16818 .doit = nl80211_get_mpath, 16819 .dumpit = nl80211_dump_mpath, 16820 .flags = GENL_UNS_ADMIN_PERM, 16821 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16822 }, 16823 { 16824 .cmd = NL80211_CMD_GET_MPP, 16825 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16826 .doit = nl80211_get_mpp, 16827 .dumpit = nl80211_dump_mpp, 16828 .flags = GENL_UNS_ADMIN_PERM, 16829 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16830 }, 16831 { 16832 .cmd = NL80211_CMD_SET_MPATH, 16833 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16834 .doit = nl80211_set_mpath, 16835 .flags = GENL_UNS_ADMIN_PERM, 16836 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16837 }, 16838 { 16839 .cmd = NL80211_CMD_NEW_MPATH, 16840 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16841 .doit = nl80211_new_mpath, 16842 .flags = GENL_UNS_ADMIN_PERM, 16843 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16844 }, 16845 { 16846 .cmd = NL80211_CMD_DEL_MPATH, 16847 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16848 .doit = nl80211_del_mpath, 16849 .flags = GENL_UNS_ADMIN_PERM, 16850 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16851 }, 16852 { 16853 .cmd = NL80211_CMD_SET_BSS, 16854 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16855 .doit = nl80211_set_bss, 16856 .flags = GENL_UNS_ADMIN_PERM, 16857 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16858 NL80211_FLAG_MLO_VALID_LINK_ID), 16859 }, 16860 { 16861 .cmd = NL80211_CMD_GET_REG, 16862 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16863 .doit = nl80211_get_reg_do, 16864 .dumpit = nl80211_get_reg_dump, 16865 /* can be retrieved by unprivileged users */ 16866 }, 16867 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 16868 { 16869 .cmd = NL80211_CMD_SET_REG, 16870 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16871 .doit = nl80211_set_reg, 16872 .flags = GENL_ADMIN_PERM, 16873 }, 16874 #endif 16875 { 16876 .cmd = NL80211_CMD_REQ_SET_REG, 16877 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16878 .doit = nl80211_req_set_reg, 16879 .flags = GENL_ADMIN_PERM, 16880 }, 16881 { 16882 .cmd = NL80211_CMD_RELOAD_REGDB, 16883 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16884 .doit = nl80211_reload_regdb, 16885 .flags = GENL_ADMIN_PERM, 16886 }, 16887 { 16888 .cmd = NL80211_CMD_GET_MESH_CONFIG, 16889 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16890 .doit = nl80211_get_mesh_config, 16891 /* can be retrieved by unprivileged users */ 16892 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16893 }, 16894 { 16895 .cmd = NL80211_CMD_SET_MESH_CONFIG, 16896 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16897 .doit = nl80211_update_mesh_config, 16898 .flags = GENL_UNS_ADMIN_PERM, 16899 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16900 }, 16901 { 16902 .cmd = NL80211_CMD_TRIGGER_SCAN, 16903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16904 .doit = nl80211_trigger_scan, 16905 .flags = GENL_UNS_ADMIN_PERM, 16906 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16907 }, 16908 { 16909 .cmd = NL80211_CMD_ABORT_SCAN, 16910 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16911 .doit = nl80211_abort_scan, 16912 .flags = GENL_UNS_ADMIN_PERM, 16913 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16914 }, 16915 { 16916 .cmd = NL80211_CMD_GET_SCAN, 16917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16918 .dumpit = nl80211_dump_scan, 16919 }, 16920 { 16921 .cmd = NL80211_CMD_START_SCHED_SCAN, 16922 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16923 .doit = nl80211_start_sched_scan, 16924 .flags = GENL_UNS_ADMIN_PERM, 16925 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16926 }, 16927 { 16928 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 16929 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16930 .doit = nl80211_stop_sched_scan, 16931 .flags = GENL_UNS_ADMIN_PERM, 16932 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16933 }, 16934 { 16935 .cmd = NL80211_CMD_AUTHENTICATE, 16936 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16937 .doit = nl80211_authenticate, 16938 .flags = GENL_UNS_ADMIN_PERM, 16939 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16940 NL80211_FLAG_CLEAR_SKB), 16941 }, 16942 { 16943 .cmd = NL80211_CMD_ASSOCIATE, 16944 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16945 .doit = nl80211_associate, 16946 .flags = GENL_UNS_ADMIN_PERM, 16947 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16948 NL80211_FLAG_CLEAR_SKB), 16949 }, 16950 { 16951 .cmd = NL80211_CMD_DEAUTHENTICATE, 16952 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16953 .doit = nl80211_deauthenticate, 16954 .flags = GENL_UNS_ADMIN_PERM, 16955 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16956 }, 16957 { 16958 .cmd = NL80211_CMD_DISASSOCIATE, 16959 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16960 .doit = nl80211_disassociate, 16961 .flags = GENL_UNS_ADMIN_PERM, 16962 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16963 }, 16964 { 16965 .cmd = NL80211_CMD_JOIN_IBSS, 16966 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16967 .doit = nl80211_join_ibss, 16968 .flags = GENL_UNS_ADMIN_PERM, 16969 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16970 }, 16971 { 16972 .cmd = NL80211_CMD_LEAVE_IBSS, 16973 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16974 .doit = nl80211_leave_ibss, 16975 .flags = GENL_UNS_ADMIN_PERM, 16976 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16977 }, 16978 #ifdef CONFIG_NL80211_TESTMODE 16979 { 16980 .cmd = NL80211_CMD_TESTMODE, 16981 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16982 .doit = nl80211_testmode_do, 16983 .dumpit = nl80211_testmode_dump, 16984 .flags = GENL_UNS_ADMIN_PERM, 16985 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16986 }, 16987 #endif 16988 { 16989 .cmd = NL80211_CMD_CONNECT, 16990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16991 .doit = nl80211_connect, 16992 .flags = GENL_UNS_ADMIN_PERM, 16993 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16994 NL80211_FLAG_CLEAR_SKB), 16995 }, 16996 { 16997 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 16998 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16999 .doit = nl80211_update_connect_params, 17000 .flags = GENL_ADMIN_PERM, 17001 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17002 NL80211_FLAG_CLEAR_SKB), 17003 }, 17004 { 17005 .cmd = NL80211_CMD_DISCONNECT, 17006 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17007 .doit = nl80211_disconnect, 17008 .flags = GENL_UNS_ADMIN_PERM, 17009 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17010 }, 17011 { 17012 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 17013 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17014 .doit = nl80211_wiphy_netns, 17015 .flags = GENL_UNS_ADMIN_PERM, 17016 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17017 NL80211_FLAG_NEED_RTNL | 17018 NL80211_FLAG_NO_WIPHY_MTX), 17019 }, 17020 { 17021 .cmd = NL80211_CMD_GET_SURVEY, 17022 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17023 .dumpit = nl80211_dump_survey, 17024 }, 17025 { 17026 .cmd = NL80211_CMD_SET_PMKSA, 17027 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17028 .doit = nl80211_setdel_pmksa, 17029 .flags = GENL_UNS_ADMIN_PERM, 17030 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17031 NL80211_FLAG_CLEAR_SKB), 17032 }, 17033 { 17034 .cmd = NL80211_CMD_DEL_PMKSA, 17035 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17036 .doit = nl80211_setdel_pmksa, 17037 .flags = GENL_UNS_ADMIN_PERM, 17038 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17039 }, 17040 { 17041 .cmd = NL80211_CMD_FLUSH_PMKSA, 17042 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17043 .doit = nl80211_flush_pmksa, 17044 .flags = GENL_UNS_ADMIN_PERM, 17045 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17046 }, 17047 { 17048 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 17049 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17050 .doit = nl80211_remain_on_channel, 17051 .flags = GENL_UNS_ADMIN_PERM, 17052 /* FIXME: requiring a link ID here is probably not good */ 17053 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 17054 NL80211_FLAG_MLO_VALID_LINK_ID), 17055 }, 17056 { 17057 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 17058 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17059 .doit = nl80211_cancel_remain_on_channel, 17060 .flags = GENL_UNS_ADMIN_PERM, 17061 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17062 }, 17063 { 17064 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 17065 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17066 .doit = nl80211_set_tx_bitrate_mask, 17067 .flags = GENL_UNS_ADMIN_PERM, 17068 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17069 NL80211_FLAG_MLO_VALID_LINK_ID), 17070 }, 17071 { 17072 .cmd = NL80211_CMD_REGISTER_FRAME, 17073 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17074 .doit = nl80211_register_mgmt, 17075 .flags = GENL_UNS_ADMIN_PERM, 17076 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 17077 }, 17078 { 17079 .cmd = NL80211_CMD_FRAME, 17080 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17081 .doit = nl80211_tx_mgmt, 17082 .flags = GENL_UNS_ADMIN_PERM, 17083 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17084 }, 17085 { 17086 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 17087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17088 .doit = nl80211_tx_mgmt_cancel_wait, 17089 .flags = GENL_UNS_ADMIN_PERM, 17090 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17091 }, 17092 { 17093 .cmd = NL80211_CMD_SET_POWER_SAVE, 17094 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17095 .doit = nl80211_set_power_save, 17096 .flags = GENL_UNS_ADMIN_PERM, 17097 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17098 }, 17099 { 17100 .cmd = NL80211_CMD_GET_POWER_SAVE, 17101 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17102 .doit = nl80211_get_power_save, 17103 /* can be retrieved by unprivileged users */ 17104 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17105 }, 17106 { 17107 .cmd = NL80211_CMD_SET_CQM, 17108 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17109 .doit = nl80211_set_cqm, 17110 .flags = GENL_UNS_ADMIN_PERM, 17111 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17112 }, 17113 { 17114 .cmd = NL80211_CMD_SET_CHANNEL, 17115 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17116 .doit = nl80211_set_channel, 17117 .flags = GENL_UNS_ADMIN_PERM, 17118 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17119 NL80211_FLAG_MLO_VALID_LINK_ID), 17120 }, 17121 { 17122 .cmd = NL80211_CMD_JOIN_MESH, 17123 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17124 .doit = nl80211_join_mesh, 17125 .flags = GENL_UNS_ADMIN_PERM, 17126 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17127 }, 17128 { 17129 .cmd = NL80211_CMD_LEAVE_MESH, 17130 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17131 .doit = nl80211_leave_mesh, 17132 .flags = GENL_UNS_ADMIN_PERM, 17133 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17134 }, 17135 { 17136 .cmd = NL80211_CMD_JOIN_OCB, 17137 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17138 .doit = nl80211_join_ocb, 17139 .flags = GENL_UNS_ADMIN_PERM, 17140 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17141 }, 17142 { 17143 .cmd = NL80211_CMD_LEAVE_OCB, 17144 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17145 .doit = nl80211_leave_ocb, 17146 .flags = GENL_UNS_ADMIN_PERM, 17147 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17148 }, 17149 #ifdef CONFIG_PM 17150 { 17151 .cmd = NL80211_CMD_GET_WOWLAN, 17152 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17153 .doit = nl80211_get_wowlan, 17154 /* can be retrieved by unprivileged users */ 17155 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17156 }, 17157 { 17158 .cmd = NL80211_CMD_SET_WOWLAN, 17159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17160 .doit = nl80211_set_wowlan, 17161 .flags = GENL_UNS_ADMIN_PERM, 17162 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17163 }, 17164 #endif 17165 { 17166 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 17167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17168 .doit = nl80211_set_rekey_data, 17169 .flags = GENL_UNS_ADMIN_PERM, 17170 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17171 NL80211_FLAG_CLEAR_SKB), 17172 }, 17173 { 17174 .cmd = NL80211_CMD_TDLS_MGMT, 17175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17176 .doit = nl80211_tdls_mgmt, 17177 .flags = GENL_UNS_ADMIN_PERM, 17178 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17179 NL80211_FLAG_MLO_VALID_LINK_ID), 17180 }, 17181 { 17182 .cmd = NL80211_CMD_TDLS_OPER, 17183 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17184 .doit = nl80211_tdls_oper, 17185 .flags = GENL_UNS_ADMIN_PERM, 17186 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17187 }, 17188 { 17189 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 17190 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17191 .doit = nl80211_register_unexpected_frame, 17192 .flags = GENL_UNS_ADMIN_PERM, 17193 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17194 }, 17195 { 17196 .cmd = NL80211_CMD_PROBE_CLIENT, 17197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17198 .doit = nl80211_probe_client, 17199 .flags = GENL_UNS_ADMIN_PERM, 17200 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17201 }, 17202 { 17203 .cmd = NL80211_CMD_REGISTER_BEACONS, 17204 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17205 .doit = nl80211_register_beacons, 17206 .flags = GENL_UNS_ADMIN_PERM, 17207 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17208 }, 17209 { 17210 .cmd = NL80211_CMD_SET_NOACK_MAP, 17211 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17212 .doit = nl80211_set_noack_map, 17213 .flags = GENL_UNS_ADMIN_PERM, 17214 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17215 }, 17216 { 17217 .cmd = NL80211_CMD_START_P2P_DEVICE, 17218 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17219 .doit = nl80211_start_p2p_device, 17220 .flags = GENL_UNS_ADMIN_PERM, 17221 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 17222 NL80211_FLAG_NEED_RTNL), 17223 }, 17224 { 17225 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 17226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17227 .doit = nl80211_stop_p2p_device, 17228 .flags = GENL_UNS_ADMIN_PERM, 17229 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 17230 NL80211_FLAG_NEED_RTNL), 17231 }, 17232 { 17233 .cmd = NL80211_CMD_START_NAN, 17234 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17235 .doit = nl80211_start_nan, 17236 .flags = GENL_ADMIN_PERM, 17237 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 17238 NL80211_FLAG_NEED_RTNL), 17239 }, 17240 { 17241 .cmd = NL80211_CMD_STOP_NAN, 17242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17243 .doit = nl80211_stop_nan, 17244 .flags = GENL_ADMIN_PERM, 17245 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 17246 NL80211_FLAG_NEED_RTNL), 17247 }, 17248 { 17249 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 17250 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17251 .doit = nl80211_nan_add_func, 17252 .flags = GENL_ADMIN_PERM, 17253 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17254 }, 17255 { 17256 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 17257 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17258 .doit = nl80211_nan_del_func, 17259 .flags = GENL_ADMIN_PERM, 17260 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17261 }, 17262 { 17263 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 17264 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17265 .doit = nl80211_nan_change_config, 17266 .flags = GENL_ADMIN_PERM, 17267 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17268 }, 17269 { 17270 .cmd = NL80211_CMD_SET_MCAST_RATE, 17271 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17272 .doit = nl80211_set_mcast_rate, 17273 .flags = GENL_UNS_ADMIN_PERM, 17274 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17275 }, 17276 { 17277 .cmd = NL80211_CMD_SET_MAC_ACL, 17278 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17279 .doit = nl80211_set_mac_acl, 17280 .flags = GENL_UNS_ADMIN_PERM, 17281 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17282 NL80211_FLAG_MLO_UNSUPPORTED), 17283 }, 17284 { 17285 .cmd = NL80211_CMD_RADAR_DETECT, 17286 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17287 .doit = nl80211_start_radar_detection, 17288 .flags = GENL_UNS_ADMIN_PERM, 17289 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17290 NL80211_FLAG_NO_WIPHY_MTX | 17291 NL80211_FLAG_MLO_UNSUPPORTED), 17292 }, 17293 { 17294 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 17295 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17296 .doit = nl80211_get_protocol_features, 17297 }, 17298 { 17299 .cmd = NL80211_CMD_UPDATE_FT_IES, 17300 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17301 .doit = nl80211_update_ft_ies, 17302 .flags = GENL_UNS_ADMIN_PERM, 17303 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17304 }, 17305 { 17306 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 17307 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17308 .doit = nl80211_crit_protocol_start, 17309 .flags = GENL_UNS_ADMIN_PERM, 17310 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17311 }, 17312 { 17313 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 17314 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17315 .doit = nl80211_crit_protocol_stop, 17316 .flags = GENL_UNS_ADMIN_PERM, 17317 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17318 }, 17319 { 17320 .cmd = NL80211_CMD_GET_COALESCE, 17321 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17322 .doit = nl80211_get_coalesce, 17323 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17324 }, 17325 { 17326 .cmd = NL80211_CMD_SET_COALESCE, 17327 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17328 .doit = nl80211_set_coalesce, 17329 .flags = GENL_UNS_ADMIN_PERM, 17330 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17331 }, 17332 { 17333 .cmd = NL80211_CMD_CHANNEL_SWITCH, 17334 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17335 .doit = nl80211_channel_switch, 17336 .flags = GENL_UNS_ADMIN_PERM, 17337 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17338 NL80211_FLAG_MLO_VALID_LINK_ID), 17339 }, 17340 { 17341 .cmd = NL80211_CMD_VENDOR, 17342 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17343 .doit = nl80211_vendor_cmd, 17344 .dumpit = nl80211_vendor_cmd_dump, 17345 .flags = GENL_UNS_ADMIN_PERM, 17346 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17347 NL80211_FLAG_CLEAR_SKB), 17348 }, 17349 { 17350 .cmd = NL80211_CMD_SET_QOS_MAP, 17351 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17352 .doit = nl80211_set_qos_map, 17353 .flags = GENL_UNS_ADMIN_PERM, 17354 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17355 }, 17356 { 17357 .cmd = NL80211_CMD_ADD_TX_TS, 17358 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17359 .doit = nl80211_add_tx_ts, 17360 .flags = GENL_UNS_ADMIN_PERM, 17361 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17362 NL80211_FLAG_MLO_UNSUPPORTED), 17363 }, 17364 { 17365 .cmd = NL80211_CMD_DEL_TX_TS, 17366 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17367 .doit = nl80211_del_tx_ts, 17368 .flags = GENL_UNS_ADMIN_PERM, 17369 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17370 }, 17371 { 17372 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 17373 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17374 .doit = nl80211_tdls_channel_switch, 17375 .flags = GENL_UNS_ADMIN_PERM, 17376 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17377 }, 17378 { 17379 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 17380 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17381 .doit = nl80211_tdls_cancel_channel_switch, 17382 .flags = GENL_UNS_ADMIN_PERM, 17383 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17384 }, 17385 { 17386 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 17387 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17388 .doit = nl80211_set_multicast_to_unicast, 17389 .flags = GENL_UNS_ADMIN_PERM, 17390 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17391 }, 17392 { 17393 .cmd = NL80211_CMD_SET_PMK, 17394 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17395 .doit = nl80211_set_pmk, 17396 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17397 NL80211_FLAG_CLEAR_SKB), 17398 }, 17399 { 17400 .cmd = NL80211_CMD_DEL_PMK, 17401 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17402 .doit = nl80211_del_pmk, 17403 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17404 }, 17405 { 17406 .cmd = NL80211_CMD_EXTERNAL_AUTH, 17407 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17408 .doit = nl80211_external_auth, 17409 .flags = GENL_ADMIN_PERM, 17410 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17411 }, 17412 { 17413 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 17414 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17415 .doit = nl80211_tx_control_port, 17416 .flags = GENL_UNS_ADMIN_PERM, 17417 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17418 }, 17419 { 17420 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 17421 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17422 .doit = nl80211_get_ftm_responder_stats, 17423 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17424 NL80211_FLAG_MLO_VALID_LINK_ID), 17425 }, 17426 { 17427 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 17428 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17429 .doit = nl80211_pmsr_start, 17430 .flags = GENL_UNS_ADMIN_PERM, 17431 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17432 }, 17433 { 17434 .cmd = NL80211_CMD_NOTIFY_RADAR, 17435 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17436 .doit = nl80211_notify_radar_detection, 17437 .flags = GENL_UNS_ADMIN_PERM, 17438 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17439 }, 17440 { 17441 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 17442 .doit = nl80211_update_owe_info, 17443 .flags = GENL_ADMIN_PERM, 17444 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17445 }, 17446 { 17447 .cmd = NL80211_CMD_PROBE_MESH_LINK, 17448 .doit = nl80211_probe_mesh_link, 17449 .flags = GENL_UNS_ADMIN_PERM, 17450 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17451 }, 17452 { 17453 .cmd = NL80211_CMD_SET_TID_CONFIG, 17454 .doit = nl80211_set_tid_config, 17455 .flags = GENL_UNS_ADMIN_PERM, 17456 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17457 NL80211_FLAG_MLO_VALID_LINK_ID), 17458 }, 17459 { 17460 .cmd = NL80211_CMD_SET_SAR_SPECS, 17461 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17462 .doit = nl80211_set_sar_specs, 17463 .flags = GENL_UNS_ADMIN_PERM, 17464 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17465 NL80211_FLAG_NEED_RTNL), 17466 }, 17467 { 17468 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, 17469 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17470 .doit = nl80211_color_change, 17471 .flags = GENL_UNS_ADMIN_PERM, 17472 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17473 }, 17474 { 17475 .cmd = NL80211_CMD_SET_FILS_AAD, 17476 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17477 .doit = nl80211_set_fils_aad, 17478 .flags = GENL_UNS_ADMIN_PERM, 17479 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17480 }, 17481 { 17482 .cmd = NL80211_CMD_ADD_LINK, 17483 .doit = nl80211_add_link, 17484 .flags = GENL_UNS_ADMIN_PERM, 17485 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17486 }, 17487 { 17488 .cmd = NL80211_CMD_REMOVE_LINK, 17489 .doit = nl80211_remove_link, 17490 .flags = GENL_UNS_ADMIN_PERM, 17491 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17492 NL80211_FLAG_MLO_VALID_LINK_ID), 17493 }, 17494 { 17495 .cmd = NL80211_CMD_ADD_LINK_STA, 17496 .doit = nl80211_add_link_station, 17497 .flags = GENL_UNS_ADMIN_PERM, 17498 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17499 NL80211_FLAG_MLO_VALID_LINK_ID), 17500 }, 17501 { 17502 .cmd = NL80211_CMD_MODIFY_LINK_STA, 17503 .doit = nl80211_modify_link_station, 17504 .flags = GENL_UNS_ADMIN_PERM, 17505 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17506 NL80211_FLAG_MLO_VALID_LINK_ID), 17507 }, 17508 { 17509 .cmd = NL80211_CMD_REMOVE_LINK_STA, 17510 .doit = nl80211_remove_link_station, 17511 .flags = GENL_UNS_ADMIN_PERM, 17512 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17513 NL80211_FLAG_MLO_VALID_LINK_ID), 17514 }, 17515 { 17516 .cmd = NL80211_CMD_SET_HW_TIMESTAMP, 17517 .doit = nl80211_set_hw_timestamp, 17518 .flags = GENL_UNS_ADMIN_PERM, 17519 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17520 }, 17521 }; 17522 17523 static struct genl_family nl80211_fam __ro_after_init = { 17524 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 17525 .hdrsize = 0, /* no private header */ 17526 .version = 1, /* no particular meaning now */ 17527 .maxattr = NL80211_ATTR_MAX, 17528 .policy = nl80211_policy, 17529 .netnsok = true, 17530 .pre_doit = nl80211_pre_doit, 17531 .post_doit = nl80211_post_doit, 17532 .module = THIS_MODULE, 17533 .ops = nl80211_ops, 17534 .n_ops = ARRAY_SIZE(nl80211_ops), 17535 .small_ops = nl80211_small_ops, 17536 .n_small_ops = ARRAY_SIZE(nl80211_small_ops), 17537 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1, 17538 .mcgrps = nl80211_mcgrps, 17539 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 17540 .parallel_ops = true, 17541 }; 17542 17543 /* notification functions */ 17544 17545 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 17546 enum nl80211_commands cmd) 17547 { 17548 struct sk_buff *msg; 17549 struct nl80211_dump_wiphy_state state = {}; 17550 17551 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 17552 cmd != NL80211_CMD_DEL_WIPHY); 17553 17554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17555 if (!msg) 17556 return; 17557 17558 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 17559 nlmsg_free(msg); 17560 return; 17561 } 17562 17563 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17564 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17565 } 17566 17567 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 17568 struct wireless_dev *wdev, 17569 enum nl80211_commands cmd) 17570 { 17571 struct sk_buff *msg; 17572 17573 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17574 if (!msg) 17575 return; 17576 17577 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 17578 nlmsg_free(msg); 17579 return; 17580 } 17581 17582 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17583 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17584 } 17585 17586 static int nl80211_add_scan_req(struct sk_buff *msg, 17587 struct cfg80211_registered_device *rdev) 17588 { 17589 struct cfg80211_scan_request *req = rdev->scan_req; 17590 struct nlattr *nest; 17591 int i; 17592 struct cfg80211_scan_info *info; 17593 17594 if (WARN_ON(!req)) 17595 return 0; 17596 17597 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 17598 if (!nest) 17599 goto nla_put_failure; 17600 for (i = 0; i < req->n_ssids; i++) { 17601 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 17602 goto nla_put_failure; 17603 } 17604 nla_nest_end(msg, nest); 17605 17606 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { 17607 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); 17608 if (!nest) 17609 goto nla_put_failure; 17610 for (i = 0; i < req->n_channels; i++) { 17611 if (nla_put_u32(msg, i, 17612 ieee80211_channel_to_khz(req->channels[i]))) 17613 goto nla_put_failure; 17614 } 17615 nla_nest_end(msg, nest); 17616 } else { 17617 nest = nla_nest_start_noflag(msg, 17618 NL80211_ATTR_SCAN_FREQUENCIES); 17619 if (!nest) 17620 goto nla_put_failure; 17621 for (i = 0; i < req->n_channels; i++) { 17622 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 17623 goto nla_put_failure; 17624 } 17625 nla_nest_end(msg, nest); 17626 } 17627 17628 if (req->ie && 17629 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 17630 goto nla_put_failure; 17631 17632 if (req->flags && 17633 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 17634 goto nla_put_failure; 17635 17636 info = rdev->int_scan_req ? &rdev->int_scan_req->info : 17637 &rdev->scan_req->info; 17638 if (info->scan_start_tsf && 17639 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 17640 info->scan_start_tsf, NL80211_BSS_PAD) || 17641 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 17642 info->tsf_bssid))) 17643 goto nla_put_failure; 17644 17645 return 0; 17646 nla_put_failure: 17647 return -ENOBUFS; 17648 } 17649 17650 static int nl80211_prep_scan_msg(struct sk_buff *msg, 17651 struct cfg80211_registered_device *rdev, 17652 struct wireless_dev *wdev, 17653 u32 portid, u32 seq, int flags, 17654 u32 cmd) 17655 { 17656 void *hdr; 17657 17658 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 17659 if (!hdr) 17660 return -1; 17661 17662 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17663 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 17664 wdev->netdev->ifindex)) || 17665 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17666 NL80211_ATTR_PAD)) 17667 goto nla_put_failure; 17668 17669 /* ignore errors and send incomplete event anyway */ 17670 nl80211_add_scan_req(msg, rdev); 17671 17672 genlmsg_end(msg, hdr); 17673 return 0; 17674 17675 nla_put_failure: 17676 genlmsg_cancel(msg, hdr); 17677 return -EMSGSIZE; 17678 } 17679 17680 static int 17681 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 17682 struct cfg80211_sched_scan_request *req, u32 cmd) 17683 { 17684 void *hdr; 17685 17686 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17687 if (!hdr) 17688 return -1; 17689 17690 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 17691 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 17692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 17693 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 17694 NL80211_ATTR_PAD)) 17695 goto nla_put_failure; 17696 17697 genlmsg_end(msg, hdr); 17698 return 0; 17699 17700 nla_put_failure: 17701 genlmsg_cancel(msg, hdr); 17702 return -EMSGSIZE; 17703 } 17704 17705 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 17706 struct wireless_dev *wdev) 17707 { 17708 struct sk_buff *msg; 17709 17710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17711 if (!msg) 17712 return; 17713 17714 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17715 NL80211_CMD_TRIGGER_SCAN) < 0) { 17716 nlmsg_free(msg); 17717 return; 17718 } 17719 17720 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17721 NL80211_MCGRP_SCAN, GFP_KERNEL); 17722 } 17723 17724 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 17725 struct wireless_dev *wdev, bool aborted) 17726 { 17727 struct sk_buff *msg; 17728 17729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17730 if (!msg) 17731 return NULL; 17732 17733 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17734 aborted ? NL80211_CMD_SCAN_ABORTED : 17735 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 17736 nlmsg_free(msg); 17737 return NULL; 17738 } 17739 17740 return msg; 17741 } 17742 17743 /* send message created by nl80211_build_scan_msg() */ 17744 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 17745 struct sk_buff *msg) 17746 { 17747 if (!msg) 17748 return; 17749 17750 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17751 NL80211_MCGRP_SCAN, GFP_KERNEL); 17752 } 17753 17754 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 17755 { 17756 struct sk_buff *msg; 17757 17758 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17759 if (!msg) 17760 return; 17761 17762 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 17763 nlmsg_free(msg); 17764 return; 17765 } 17766 17767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 17768 NL80211_MCGRP_SCAN, GFP_KERNEL); 17769 } 17770 17771 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 17772 struct regulatory_request *request) 17773 { 17774 /* Userspace can always count this one always being set */ 17775 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 17776 goto nla_put_failure; 17777 17778 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 17779 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17780 NL80211_REGDOM_TYPE_WORLD)) 17781 goto nla_put_failure; 17782 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 17783 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17784 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 17785 goto nla_put_failure; 17786 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 17787 request->intersect) { 17788 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17789 NL80211_REGDOM_TYPE_INTERSECTION)) 17790 goto nla_put_failure; 17791 } else { 17792 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17793 NL80211_REGDOM_TYPE_COUNTRY) || 17794 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 17795 request->alpha2)) 17796 goto nla_put_failure; 17797 } 17798 17799 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 17800 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 17801 17802 if (wiphy && 17803 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 17804 goto nla_put_failure; 17805 17806 if (wiphy && 17807 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 17808 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 17809 goto nla_put_failure; 17810 } 17811 17812 return true; 17813 17814 nla_put_failure: 17815 return false; 17816 } 17817 17818 /* 17819 * This can happen on global regulatory changes or device specific settings 17820 * based on custom regulatory domains. 17821 */ 17822 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 17823 struct regulatory_request *request) 17824 { 17825 struct sk_buff *msg; 17826 void *hdr; 17827 17828 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17829 if (!msg) 17830 return; 17831 17832 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 17833 if (!hdr) 17834 goto nla_put_failure; 17835 17836 if (!nl80211_reg_change_event_fill(msg, request)) 17837 goto nla_put_failure; 17838 17839 genlmsg_end(msg, hdr); 17840 17841 rcu_read_lock(); 17842 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 17843 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 17844 rcu_read_unlock(); 17845 17846 return; 17847 17848 nla_put_failure: 17849 nlmsg_free(msg); 17850 } 17851 17852 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 17853 struct net_device *netdev, 17854 const u8 *buf, size_t len, 17855 enum nl80211_commands cmd, gfp_t gfp, 17856 int uapsd_queues, const u8 *req_ies, 17857 size_t req_ies_len, bool reconnect) 17858 { 17859 struct sk_buff *msg; 17860 void *hdr; 17861 17862 msg = nlmsg_new(100 + len + req_ies_len, gfp); 17863 if (!msg) 17864 return; 17865 17866 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17867 if (!hdr) { 17868 nlmsg_free(msg); 17869 return; 17870 } 17871 17872 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17873 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17874 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 17875 (req_ies && 17876 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 17877 goto nla_put_failure; 17878 17879 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) 17880 goto nla_put_failure; 17881 17882 if (uapsd_queues >= 0) { 17883 struct nlattr *nla_wmm = 17884 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 17885 if (!nla_wmm) 17886 goto nla_put_failure; 17887 17888 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 17889 uapsd_queues)) 17890 goto nla_put_failure; 17891 17892 nla_nest_end(msg, nla_wmm); 17893 } 17894 17895 genlmsg_end(msg, hdr); 17896 17897 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17898 NL80211_MCGRP_MLME, gfp); 17899 return; 17900 17901 nla_put_failure: 17902 nlmsg_free(msg); 17903 } 17904 17905 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 17906 struct net_device *netdev, const u8 *buf, 17907 size_t len, gfp_t gfp) 17908 { 17909 nl80211_send_mlme_event(rdev, netdev, buf, len, 17910 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, 17911 false); 17912 } 17913 17914 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 17915 struct net_device *netdev, 17916 struct cfg80211_rx_assoc_resp *data) 17917 { 17918 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len, 17919 NL80211_CMD_ASSOCIATE, GFP_KERNEL, 17920 data->uapsd_queues, 17921 data->req_ies, data->req_ies_len, false); 17922 } 17923 17924 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 17925 struct net_device *netdev, const u8 *buf, 17926 size_t len, bool reconnect, gfp_t gfp) 17927 { 17928 nl80211_send_mlme_event(rdev, netdev, buf, len, 17929 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, 17930 reconnect); 17931 } 17932 17933 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 17934 struct net_device *netdev, const u8 *buf, 17935 size_t len, bool reconnect, gfp_t gfp) 17936 { 17937 nl80211_send_mlme_event(rdev, netdev, buf, len, 17938 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, 17939 reconnect); 17940 } 17941 17942 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 17943 size_t len) 17944 { 17945 struct wireless_dev *wdev = dev->ieee80211_ptr; 17946 struct wiphy *wiphy = wdev->wiphy; 17947 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17948 const struct ieee80211_mgmt *mgmt = (void *)buf; 17949 u32 cmd; 17950 17951 if (WARN_ON(len < 2)) 17952 return; 17953 17954 if (ieee80211_is_deauth(mgmt->frame_control)) { 17955 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 17956 } else if (ieee80211_is_disassoc(mgmt->frame_control)) { 17957 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 17958 } else if (ieee80211_is_beacon(mgmt->frame_control)) { 17959 if (wdev->unprot_beacon_reported && 17960 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) 17961 return; 17962 cmd = NL80211_CMD_UNPROT_BEACON; 17963 wdev->unprot_beacon_reported = jiffies; 17964 } else { 17965 return; 17966 } 17967 17968 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 17969 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 17970 NULL, 0, false); 17971 } 17972 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 17973 17974 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 17975 struct net_device *netdev, int cmd, 17976 const u8 *addr, gfp_t gfp) 17977 { 17978 struct sk_buff *msg; 17979 void *hdr; 17980 17981 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17982 if (!msg) 17983 return; 17984 17985 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17986 if (!hdr) { 17987 nlmsg_free(msg); 17988 return; 17989 } 17990 17991 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17992 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17993 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 17994 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 17995 goto nla_put_failure; 17996 17997 genlmsg_end(msg, hdr); 17998 17999 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18000 NL80211_MCGRP_MLME, gfp); 18001 return; 18002 18003 nla_put_failure: 18004 nlmsg_free(msg); 18005 } 18006 18007 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 18008 struct net_device *netdev, const u8 *addr, 18009 gfp_t gfp) 18010 { 18011 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 18012 addr, gfp); 18013 } 18014 18015 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 18016 struct net_device *netdev, const u8 *addr, 18017 gfp_t gfp) 18018 { 18019 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 18020 addr, gfp); 18021 } 18022 18023 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 18024 struct net_device *netdev, 18025 struct cfg80211_connect_resp_params *cr, 18026 gfp_t gfp) 18027 { 18028 struct sk_buff *msg; 18029 void *hdr; 18030 unsigned int link; 18031 size_t link_info_size = 0; 18032 const u8 *connected_addr = cr->valid_links ? 18033 cr->ap_mld_addr : cr->links[0].bssid; 18034 18035 if (cr->valid_links) { 18036 for_each_valid_link(cr, link) { 18037 /* Nested attribute header */ 18038 link_info_size += NLA_HDRLEN; 18039 /* Link ID */ 18040 link_info_size += nla_total_size(sizeof(u8)); 18041 link_info_size += cr->links[link].addr ? 18042 nla_total_size(ETH_ALEN) : 0; 18043 link_info_size += (cr->links[link].bssid || 18044 cr->links[link].bss) ? 18045 nla_total_size(ETH_ALEN) : 0; 18046 link_info_size += nla_total_size(sizeof(u16)); 18047 } 18048 } 18049 18050 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 18051 cr->fils.kek_len + cr->fils.pmk_len + 18052 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size, 18053 gfp); 18054 if (!msg) 18055 return; 18056 18057 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 18058 if (!hdr) { 18059 nlmsg_free(msg); 18060 return; 18061 } 18062 18063 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18064 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18065 (connected_addr && 18066 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) || 18067 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 18068 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 18069 cr->status) || 18070 (cr->status < 0 && 18071 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 18072 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 18073 cr->timeout_reason))) || 18074 (cr->req_ie && 18075 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 18076 (cr->resp_ie && 18077 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 18078 cr->resp_ie)) || 18079 (cr->fils.update_erp_next_seq_num && 18080 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 18081 cr->fils.erp_next_seq_num)) || 18082 (cr->status == WLAN_STATUS_SUCCESS && 18083 ((cr->fils.kek && 18084 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 18085 cr->fils.kek)) || 18086 (cr->fils.pmk && 18087 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 18088 (cr->fils.pmkid && 18089 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 18090 goto nla_put_failure; 18091 18092 if (cr->valid_links) { 18093 int i = 1; 18094 struct nlattr *nested; 18095 18096 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18097 if (!nested) 18098 goto nla_put_failure; 18099 18100 for_each_valid_link(cr, link) { 18101 struct nlattr *nested_mlo_links; 18102 const u8 *bssid = cr->links[link].bss ? 18103 cr->links[link].bss->bssid : 18104 cr->links[link].bssid; 18105 18106 nested_mlo_links = nla_nest_start(msg, i); 18107 if (!nested_mlo_links) 18108 goto nla_put_failure; 18109 18110 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 18111 (bssid && 18112 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 18113 (cr->links[link].addr && 18114 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 18115 cr->links[link].addr)) || 18116 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 18117 cr->links[link].status)) 18118 goto nla_put_failure; 18119 18120 nla_nest_end(msg, nested_mlo_links); 18121 i++; 18122 } 18123 nla_nest_end(msg, nested); 18124 } 18125 18126 genlmsg_end(msg, hdr); 18127 18128 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18129 NL80211_MCGRP_MLME, gfp); 18130 return; 18131 18132 nla_put_failure: 18133 nlmsg_free(msg); 18134 } 18135 18136 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 18137 struct net_device *netdev, 18138 struct cfg80211_roam_info *info, gfp_t gfp) 18139 { 18140 struct sk_buff *msg; 18141 void *hdr; 18142 size_t link_info_size = 0; 18143 unsigned int link; 18144 const u8 *connected_addr = info->ap_mld_addr ? 18145 info->ap_mld_addr : 18146 (info->links[0].bss ? 18147 info->links[0].bss->bssid : 18148 info->links[0].bssid); 18149 18150 if (info->valid_links) { 18151 for_each_valid_link(info, link) { 18152 /* Nested attribute header */ 18153 link_info_size += NLA_HDRLEN; 18154 /* Link ID */ 18155 link_info_size += nla_total_size(sizeof(u8)); 18156 link_info_size += info->links[link].addr ? 18157 nla_total_size(ETH_ALEN) : 0; 18158 link_info_size += (info->links[link].bssid || 18159 info->links[link].bss) ? 18160 nla_total_size(ETH_ALEN) : 0; 18161 } 18162 } 18163 18164 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 18165 info->fils.kek_len + info->fils.pmk_len + 18166 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) + 18167 link_info_size, gfp); 18168 if (!msg) 18169 return; 18170 18171 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 18172 if (!hdr) { 18173 nlmsg_free(msg); 18174 return; 18175 } 18176 18177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || 18180 (info->req_ie && 18181 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 18182 info->req_ie)) || 18183 (info->resp_ie && 18184 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 18185 info->resp_ie)) || 18186 (info->fils.update_erp_next_seq_num && 18187 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 18188 info->fils.erp_next_seq_num)) || 18189 (info->fils.kek && 18190 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 18191 info->fils.kek)) || 18192 (info->fils.pmk && 18193 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 18194 (info->fils.pmkid && 18195 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 18196 goto nla_put_failure; 18197 18198 if (info->valid_links) { 18199 int i = 1; 18200 struct nlattr *nested; 18201 18202 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18203 if (!nested) 18204 goto nla_put_failure; 18205 18206 for_each_valid_link(info, link) { 18207 struct nlattr *nested_mlo_links; 18208 const u8 *bssid = info->links[link].bss ? 18209 info->links[link].bss->bssid : 18210 info->links[link].bssid; 18211 18212 nested_mlo_links = nla_nest_start(msg, i); 18213 if (!nested_mlo_links) 18214 goto nla_put_failure; 18215 18216 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 18217 (bssid && 18218 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 18219 (info->links[link].addr && 18220 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 18221 info->links[link].addr))) 18222 goto nla_put_failure; 18223 18224 nla_nest_end(msg, nested_mlo_links); 18225 i++; 18226 } 18227 nla_nest_end(msg, nested); 18228 } 18229 18230 genlmsg_end(msg, hdr); 18231 18232 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18233 NL80211_MCGRP_MLME, gfp); 18234 return; 18235 18236 nla_put_failure: 18237 nlmsg_free(msg); 18238 } 18239 18240 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 18241 struct net_device *netdev, const u8 *bssid, 18242 const u8 *td_bitmap, u8 td_bitmap_len) 18243 { 18244 struct sk_buff *msg; 18245 void *hdr; 18246 18247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18248 if (!msg) 18249 return; 18250 18251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 18252 if (!hdr) { 18253 nlmsg_free(msg); 18254 return; 18255 } 18256 18257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18258 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 18260 goto nla_put_failure; 18261 18262 if ((td_bitmap_len > 0) && td_bitmap) 18263 if (nla_put(msg, NL80211_ATTR_TD_BITMAP, 18264 td_bitmap_len, td_bitmap)) 18265 goto nla_put_failure; 18266 18267 genlmsg_end(msg, hdr); 18268 18269 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18270 NL80211_MCGRP_MLME, GFP_KERNEL); 18271 return; 18272 18273 nla_put_failure: 18274 nlmsg_free(msg); 18275 } 18276 18277 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 18278 struct net_device *netdev, u16 reason, 18279 const u8 *ie, size_t ie_len, bool from_ap) 18280 { 18281 struct sk_buff *msg; 18282 void *hdr; 18283 18284 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 18285 if (!msg) 18286 return; 18287 18288 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 18289 if (!hdr) { 18290 nlmsg_free(msg); 18291 return; 18292 } 18293 18294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18295 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18296 (reason && 18297 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 18298 (from_ap && 18299 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 18300 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 18301 goto nla_put_failure; 18302 18303 genlmsg_end(msg, hdr); 18304 18305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18306 NL80211_MCGRP_MLME, GFP_KERNEL); 18307 return; 18308 18309 nla_put_failure: 18310 nlmsg_free(msg); 18311 } 18312 18313 void cfg80211_links_removed(struct net_device *dev, u16 link_mask) 18314 { 18315 struct wireless_dev *wdev = dev->ieee80211_ptr; 18316 struct wiphy *wiphy = wdev->wiphy; 18317 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18318 struct sk_buff *msg; 18319 struct nlattr *links; 18320 void *hdr; 18321 18322 ASSERT_WDEV_LOCK(wdev); 18323 trace_cfg80211_links_removed(dev, link_mask); 18324 18325 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && 18326 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) 18327 return; 18328 18329 if (WARN_ON(!wdev->valid_links || !link_mask || 18330 (wdev->valid_links & link_mask) != link_mask || 18331 wdev->valid_links == link_mask)) 18332 return; 18333 18334 cfg80211_wdev_release_link_bsses(wdev, link_mask); 18335 wdev->valid_links &= ~link_mask; 18336 18337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18338 if (!msg) 18339 return; 18340 18341 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_LINKS_REMOVED); 18342 if (!hdr) { 18343 nlmsg_free(msg); 18344 return; 18345 } 18346 18347 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18348 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 18349 goto nla_put_failure; 18350 18351 links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18352 if (!links) 18353 goto nla_put_failure; 18354 18355 while (link_mask) { 18356 struct nlattr *link; 18357 int link_id = __ffs(link_mask); 18358 18359 link = nla_nest_start(msg, link_id + 1); 18360 if (!link) 18361 goto nla_put_failure; 18362 18363 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 18364 goto nla_put_failure; 18365 18366 nla_nest_end(msg, link); 18367 link_mask &= ~(1 << link_id); 18368 } 18369 18370 nla_nest_end(msg, links); 18371 18372 genlmsg_end(msg, hdr); 18373 18374 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18375 NL80211_MCGRP_MLME, GFP_KERNEL); 18376 return; 18377 18378 nla_put_failure: 18379 nlmsg_free(msg); 18380 } 18381 EXPORT_SYMBOL(cfg80211_links_removed); 18382 18383 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 18384 struct net_device *netdev, const u8 *bssid, 18385 gfp_t gfp) 18386 { 18387 struct sk_buff *msg; 18388 void *hdr; 18389 18390 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18391 if (!msg) 18392 return; 18393 18394 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 18395 if (!hdr) { 18396 nlmsg_free(msg); 18397 return; 18398 } 18399 18400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18401 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18402 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 18403 goto nla_put_failure; 18404 18405 genlmsg_end(msg, hdr); 18406 18407 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18408 NL80211_MCGRP_MLME, gfp); 18409 return; 18410 18411 nla_put_failure: 18412 nlmsg_free(msg); 18413 } 18414 18415 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 18416 const u8 *ie, u8 ie_len, 18417 int sig_dbm, gfp_t gfp) 18418 { 18419 struct wireless_dev *wdev = dev->ieee80211_ptr; 18420 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18421 struct sk_buff *msg; 18422 void *hdr; 18423 18424 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 18425 return; 18426 18427 trace_cfg80211_notify_new_peer_candidate(dev, addr); 18428 18429 msg = nlmsg_new(100 + ie_len, gfp); 18430 if (!msg) 18431 return; 18432 18433 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 18434 if (!hdr) { 18435 nlmsg_free(msg); 18436 return; 18437 } 18438 18439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18440 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18441 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 18442 (ie_len && ie && 18443 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 18444 (sig_dbm && 18445 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 18446 goto nla_put_failure; 18447 18448 genlmsg_end(msg, hdr); 18449 18450 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18451 NL80211_MCGRP_MLME, gfp); 18452 return; 18453 18454 nla_put_failure: 18455 nlmsg_free(msg); 18456 } 18457 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 18458 18459 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 18460 struct net_device *netdev, const u8 *addr, 18461 enum nl80211_key_type key_type, int key_id, 18462 const u8 *tsc, gfp_t gfp) 18463 { 18464 struct sk_buff *msg; 18465 void *hdr; 18466 18467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18468 if (!msg) 18469 return; 18470 18471 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 18472 if (!hdr) { 18473 nlmsg_free(msg); 18474 return; 18475 } 18476 18477 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18478 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18479 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 18480 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 18481 (key_id != -1 && 18482 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 18483 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 18484 goto nla_put_failure; 18485 18486 genlmsg_end(msg, hdr); 18487 18488 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18489 NL80211_MCGRP_MLME, gfp); 18490 return; 18491 18492 nla_put_failure: 18493 nlmsg_free(msg); 18494 } 18495 18496 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 18497 struct ieee80211_channel *channel_before, 18498 struct ieee80211_channel *channel_after) 18499 { 18500 struct sk_buff *msg; 18501 void *hdr; 18502 struct nlattr *nl_freq; 18503 18504 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 18505 if (!msg) 18506 return; 18507 18508 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 18509 if (!hdr) { 18510 nlmsg_free(msg); 18511 return; 18512 } 18513 18514 /* 18515 * Since we are applying the beacon hint to a wiphy we know its 18516 * wiphy_idx is valid 18517 */ 18518 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 18519 goto nla_put_failure; 18520 18521 /* Before */ 18522 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 18523 if (!nl_freq) 18524 goto nla_put_failure; 18525 18526 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 18527 goto nla_put_failure; 18528 nla_nest_end(msg, nl_freq); 18529 18530 /* After */ 18531 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 18532 if (!nl_freq) 18533 goto nla_put_failure; 18534 18535 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 18536 goto nla_put_failure; 18537 nla_nest_end(msg, nl_freq); 18538 18539 genlmsg_end(msg, hdr); 18540 18541 rcu_read_lock(); 18542 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 18543 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 18544 rcu_read_unlock(); 18545 18546 return; 18547 18548 nla_put_failure: 18549 nlmsg_free(msg); 18550 } 18551 18552 static void nl80211_send_remain_on_chan_event( 18553 int cmd, struct cfg80211_registered_device *rdev, 18554 struct wireless_dev *wdev, u64 cookie, 18555 struct ieee80211_channel *chan, 18556 unsigned int duration, gfp_t gfp) 18557 { 18558 struct sk_buff *msg; 18559 void *hdr; 18560 18561 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18562 if (!msg) 18563 return; 18564 18565 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18566 if (!hdr) { 18567 nlmsg_free(msg); 18568 return; 18569 } 18570 18571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18572 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18573 wdev->netdev->ifindex)) || 18574 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18575 NL80211_ATTR_PAD) || 18576 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 18577 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 18578 NL80211_CHAN_NO_HT) || 18579 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 18580 NL80211_ATTR_PAD)) 18581 goto nla_put_failure; 18582 18583 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 18584 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 18585 goto nla_put_failure; 18586 18587 genlmsg_end(msg, hdr); 18588 18589 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18590 NL80211_MCGRP_MLME, gfp); 18591 return; 18592 18593 nla_put_failure: 18594 nlmsg_free(msg); 18595 } 18596 18597 void cfg80211_assoc_comeback(struct net_device *netdev, 18598 const u8 *ap_addr, u32 timeout) 18599 { 18600 struct wireless_dev *wdev = netdev->ieee80211_ptr; 18601 struct wiphy *wiphy = wdev->wiphy; 18602 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18603 struct sk_buff *msg; 18604 void *hdr; 18605 18606 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout); 18607 18608 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18609 if (!msg) 18610 return; 18611 18612 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK); 18613 if (!hdr) { 18614 nlmsg_free(msg); 18615 return; 18616 } 18617 18618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18620 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) || 18621 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout)) 18622 goto nla_put_failure; 18623 18624 genlmsg_end(msg, hdr); 18625 18626 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18627 NL80211_MCGRP_MLME, GFP_KERNEL); 18628 return; 18629 18630 nla_put_failure: 18631 nlmsg_free(msg); 18632 } 18633 EXPORT_SYMBOL(cfg80211_assoc_comeback); 18634 18635 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 18636 struct ieee80211_channel *chan, 18637 unsigned int duration, gfp_t gfp) 18638 { 18639 struct wiphy *wiphy = wdev->wiphy; 18640 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18641 18642 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 18643 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 18644 rdev, wdev, cookie, chan, 18645 duration, gfp); 18646 } 18647 EXPORT_SYMBOL(cfg80211_ready_on_channel); 18648 18649 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 18650 struct ieee80211_channel *chan, 18651 gfp_t gfp) 18652 { 18653 struct wiphy *wiphy = wdev->wiphy; 18654 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18655 18656 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 18657 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 18658 rdev, wdev, cookie, chan, 0, gfp); 18659 } 18660 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 18661 18662 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 18663 struct ieee80211_channel *chan, 18664 gfp_t gfp) 18665 { 18666 struct wiphy *wiphy = wdev->wiphy; 18667 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18668 18669 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 18670 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 18671 rdev, wdev, cookie, chan, 0, gfp); 18672 } 18673 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 18674 18675 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 18676 struct station_info *sinfo, gfp_t gfp) 18677 { 18678 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18679 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18680 struct sk_buff *msg; 18681 18682 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 18683 18684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18685 if (!msg) 18686 return; 18687 18688 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 18689 rdev, dev, mac_addr, sinfo) < 0) { 18690 nlmsg_free(msg); 18691 return; 18692 } 18693 18694 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18695 NL80211_MCGRP_MLME, gfp); 18696 } 18697 EXPORT_SYMBOL(cfg80211_new_sta); 18698 18699 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 18700 struct station_info *sinfo, gfp_t gfp) 18701 { 18702 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18703 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18704 struct sk_buff *msg; 18705 struct station_info empty_sinfo = {}; 18706 18707 if (!sinfo) 18708 sinfo = &empty_sinfo; 18709 18710 trace_cfg80211_del_sta(dev, mac_addr); 18711 18712 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18713 if (!msg) { 18714 cfg80211_sinfo_release_content(sinfo); 18715 return; 18716 } 18717 18718 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 18719 rdev, dev, mac_addr, sinfo) < 0) { 18720 nlmsg_free(msg); 18721 return; 18722 } 18723 18724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18725 NL80211_MCGRP_MLME, gfp); 18726 } 18727 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 18728 18729 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 18730 enum nl80211_connect_failed_reason reason, 18731 gfp_t gfp) 18732 { 18733 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18734 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18735 struct sk_buff *msg; 18736 void *hdr; 18737 18738 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 18739 if (!msg) 18740 return; 18741 18742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 18743 if (!hdr) { 18744 nlmsg_free(msg); 18745 return; 18746 } 18747 18748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 18750 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 18751 goto nla_put_failure; 18752 18753 genlmsg_end(msg, hdr); 18754 18755 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18756 NL80211_MCGRP_MLME, gfp); 18757 return; 18758 18759 nla_put_failure: 18760 nlmsg_free(msg); 18761 } 18762 EXPORT_SYMBOL(cfg80211_conn_failed); 18763 18764 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 18765 const u8 *addr, gfp_t gfp) 18766 { 18767 struct wireless_dev *wdev = dev->ieee80211_ptr; 18768 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18769 struct sk_buff *msg; 18770 void *hdr; 18771 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 18772 18773 if (!nlportid) 18774 return false; 18775 18776 msg = nlmsg_new(100, gfp); 18777 if (!msg) 18778 return true; 18779 18780 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18781 if (!hdr) { 18782 nlmsg_free(msg); 18783 return true; 18784 } 18785 18786 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18787 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18788 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 18789 goto nla_put_failure; 18790 18791 genlmsg_end(msg, hdr); 18792 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18793 return true; 18794 18795 nla_put_failure: 18796 nlmsg_free(msg); 18797 return true; 18798 } 18799 18800 bool cfg80211_rx_spurious_frame(struct net_device *dev, 18801 const u8 *addr, gfp_t gfp) 18802 { 18803 struct wireless_dev *wdev = dev->ieee80211_ptr; 18804 bool ret; 18805 18806 trace_cfg80211_rx_spurious_frame(dev, addr); 18807 18808 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18809 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 18810 trace_cfg80211_return_bool(false); 18811 return false; 18812 } 18813 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 18814 addr, gfp); 18815 trace_cfg80211_return_bool(ret); 18816 return ret; 18817 } 18818 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 18819 18820 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 18821 const u8 *addr, gfp_t gfp) 18822 { 18823 struct wireless_dev *wdev = dev->ieee80211_ptr; 18824 bool ret; 18825 18826 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 18827 18828 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18829 wdev->iftype != NL80211_IFTYPE_P2P_GO && 18830 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 18831 trace_cfg80211_return_bool(false); 18832 return false; 18833 } 18834 ret = __nl80211_unexpected_frame(dev, 18835 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 18836 addr, gfp); 18837 trace_cfg80211_return_bool(ret); 18838 return ret; 18839 } 18840 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 18841 18842 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 18843 struct wireless_dev *wdev, u32 nlportid, 18844 struct cfg80211_rx_info *info, gfp_t gfp) 18845 { 18846 struct net_device *netdev = wdev->netdev; 18847 struct sk_buff *msg; 18848 void *hdr; 18849 18850 msg = nlmsg_new(100 + info->len, gfp); 18851 if (!msg) 18852 return -ENOMEM; 18853 18854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 18855 if (!hdr) { 18856 nlmsg_free(msg); 18857 return -ENOMEM; 18858 } 18859 18860 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18861 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18862 netdev->ifindex)) || 18863 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18864 NL80211_ATTR_PAD) || 18865 (info->have_link_id && 18866 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) || 18867 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) || 18868 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) || 18869 (info->sig_dbm && 18870 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) || 18871 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) || 18872 (info->flags && 18873 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) || 18874 (info->rx_tstamp && nla_put_u64_64bit(msg, 18875 NL80211_ATTR_RX_HW_TIMESTAMP, 18876 info->rx_tstamp, 18877 NL80211_ATTR_PAD)) || 18878 (info->ack_tstamp && nla_put_u64_64bit(msg, 18879 NL80211_ATTR_TX_HW_TIMESTAMP, 18880 info->ack_tstamp, 18881 NL80211_ATTR_PAD))) 18882 goto nla_put_failure; 18883 18884 genlmsg_end(msg, hdr); 18885 18886 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18887 18888 nla_put_failure: 18889 nlmsg_free(msg); 18890 return -ENOBUFS; 18891 } 18892 18893 static void nl80211_frame_tx_status(struct wireless_dev *wdev, 18894 struct cfg80211_tx_status *status, 18895 gfp_t gfp, enum nl80211_commands command) 18896 { 18897 struct wiphy *wiphy = wdev->wiphy; 18898 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18899 struct net_device *netdev = wdev->netdev; 18900 struct sk_buff *msg; 18901 void *hdr; 18902 18903 if (command == NL80211_CMD_FRAME_TX_STATUS) 18904 trace_cfg80211_mgmt_tx_status(wdev, status->cookie, 18905 status->ack); 18906 else 18907 trace_cfg80211_control_port_tx_status(wdev, status->cookie, 18908 status->ack); 18909 18910 msg = nlmsg_new(100 + status->len, gfp); 18911 if (!msg) 18912 return; 18913 18914 hdr = nl80211hdr_put(msg, 0, 0, 0, command); 18915 if (!hdr) { 18916 nlmsg_free(msg); 18917 return; 18918 } 18919 18920 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18921 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18922 netdev->ifindex)) || 18923 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18924 NL80211_ATTR_PAD) || 18925 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) || 18926 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie, 18927 NL80211_ATTR_PAD) || 18928 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) || 18929 (status->tx_tstamp && 18930 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP, 18931 status->tx_tstamp, NL80211_ATTR_PAD)) || 18932 (status->ack_tstamp && 18933 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP, 18934 status->ack_tstamp, NL80211_ATTR_PAD))) 18935 goto nla_put_failure; 18936 18937 genlmsg_end(msg, hdr); 18938 18939 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18940 NL80211_MCGRP_MLME, gfp); 18941 return; 18942 18943 nla_put_failure: 18944 nlmsg_free(msg); 18945 } 18946 18947 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, 18948 const u8 *buf, size_t len, bool ack, 18949 gfp_t gfp) 18950 { 18951 struct cfg80211_tx_status status = { 18952 .cookie = cookie, 18953 .buf = buf, 18954 .len = len, 18955 .ack = ack 18956 }; 18957 18958 nl80211_frame_tx_status(wdev, &status, gfp, 18959 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); 18960 } 18961 EXPORT_SYMBOL(cfg80211_control_port_tx_status); 18962 18963 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev, 18964 struct cfg80211_tx_status *status, gfp_t gfp) 18965 { 18966 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS); 18967 } 18968 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext); 18969 18970 static int __nl80211_rx_control_port(struct net_device *dev, 18971 struct sk_buff *skb, 18972 bool unencrypted, 18973 int link_id, 18974 gfp_t gfp) 18975 { 18976 struct wireless_dev *wdev = dev->ieee80211_ptr; 18977 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18978 struct ethhdr *ehdr = eth_hdr(skb); 18979 const u8 *addr = ehdr->h_source; 18980 u16 proto = be16_to_cpu(skb->protocol); 18981 struct sk_buff *msg; 18982 void *hdr; 18983 struct nlattr *frame; 18984 18985 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 18986 18987 if (!nlportid) 18988 return -ENOENT; 18989 18990 msg = nlmsg_new(100 + skb->len, gfp); 18991 if (!msg) 18992 return -ENOMEM; 18993 18994 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 18995 if (!hdr) { 18996 nlmsg_free(msg); 18997 return -ENOBUFS; 18998 } 18999 19000 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19001 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19002 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19003 NL80211_ATTR_PAD) || 19004 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 19005 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 19006 (link_id >= 0 && 19007 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || 19008 (unencrypted && nla_put_flag(msg, 19009 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 19010 goto nla_put_failure; 19011 19012 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 19013 if (!frame) 19014 goto nla_put_failure; 19015 19016 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 19017 genlmsg_end(msg, hdr); 19018 19019 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 19020 19021 nla_put_failure: 19022 nlmsg_free(msg); 19023 return -ENOBUFS; 19024 } 19025 19026 bool cfg80211_rx_control_port(struct net_device *dev, struct sk_buff *skb, 19027 bool unencrypted, int link_id) 19028 { 19029 int ret; 19030 19031 trace_cfg80211_rx_control_port(dev, skb, unencrypted, link_id); 19032 ret = __nl80211_rx_control_port(dev, skb, unencrypted, link_id, 19033 GFP_ATOMIC); 19034 trace_cfg80211_return_bool(ret == 0); 19035 return ret == 0; 19036 } 19037 EXPORT_SYMBOL(cfg80211_rx_control_port); 19038 19039 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 19040 const char *mac, gfp_t gfp) 19041 { 19042 struct wireless_dev *wdev = dev->ieee80211_ptr; 19043 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19044 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19045 void **cb; 19046 19047 if (!msg) 19048 return NULL; 19049 19050 cb = (void **)msg->cb; 19051 19052 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 19053 if (!cb[0]) { 19054 nlmsg_free(msg); 19055 return NULL; 19056 } 19057 19058 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19059 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19060 goto nla_put_failure; 19061 19062 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 19063 goto nla_put_failure; 19064 19065 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 19066 if (!cb[1]) 19067 goto nla_put_failure; 19068 19069 cb[2] = rdev; 19070 19071 return msg; 19072 nla_put_failure: 19073 nlmsg_free(msg); 19074 return NULL; 19075 } 19076 19077 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 19078 { 19079 void **cb = (void **)msg->cb; 19080 struct cfg80211_registered_device *rdev = cb[2]; 19081 19082 nla_nest_end(msg, cb[1]); 19083 genlmsg_end(msg, cb[0]); 19084 19085 memset(msg->cb, 0, sizeof(msg->cb)); 19086 19087 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19088 NL80211_MCGRP_MLME, gfp); 19089 } 19090 19091 void cfg80211_cqm_rssi_notify(struct net_device *dev, 19092 enum nl80211_cqm_rssi_threshold_event rssi_event, 19093 s32 rssi_level, gfp_t gfp) 19094 { 19095 struct sk_buff *msg; 19096 struct wireless_dev *wdev = dev->ieee80211_ptr; 19097 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19098 19099 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 19100 19101 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 19102 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 19103 return; 19104 19105 if (wdev->cqm_config) { 19106 wdev->cqm_config->last_rssi_event_value = rssi_level; 19107 19108 cfg80211_cqm_rssi_update(rdev, dev); 19109 19110 if (rssi_level == 0) 19111 rssi_level = wdev->cqm_config->last_rssi_event_value; 19112 } 19113 19114 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 19115 if (!msg) 19116 return; 19117 19118 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 19119 rssi_event)) 19120 goto nla_put_failure; 19121 19122 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 19123 rssi_level)) 19124 goto nla_put_failure; 19125 19126 cfg80211_send_cqm(msg, gfp); 19127 19128 return; 19129 19130 nla_put_failure: 19131 nlmsg_free(msg); 19132 } 19133 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 19134 19135 void cfg80211_cqm_txe_notify(struct net_device *dev, 19136 const u8 *peer, u32 num_packets, 19137 u32 rate, u32 intvl, gfp_t gfp) 19138 { 19139 struct sk_buff *msg; 19140 19141 msg = cfg80211_prepare_cqm(dev, peer, gfp); 19142 if (!msg) 19143 return; 19144 19145 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 19146 goto nla_put_failure; 19147 19148 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 19149 goto nla_put_failure; 19150 19151 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 19152 goto nla_put_failure; 19153 19154 cfg80211_send_cqm(msg, gfp); 19155 return; 19156 19157 nla_put_failure: 19158 nlmsg_free(msg); 19159 } 19160 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 19161 19162 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 19163 const u8 *peer, u32 num_packets, gfp_t gfp) 19164 { 19165 struct sk_buff *msg; 19166 19167 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 19168 19169 msg = cfg80211_prepare_cqm(dev, peer, gfp); 19170 if (!msg) 19171 return; 19172 19173 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 19174 goto nla_put_failure; 19175 19176 cfg80211_send_cqm(msg, gfp); 19177 return; 19178 19179 nla_put_failure: 19180 nlmsg_free(msg); 19181 } 19182 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 19183 19184 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 19185 { 19186 struct sk_buff *msg; 19187 19188 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 19189 if (!msg) 19190 return; 19191 19192 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 19193 goto nla_put_failure; 19194 19195 cfg80211_send_cqm(msg, gfp); 19196 return; 19197 19198 nla_put_failure: 19199 nlmsg_free(msg); 19200 } 19201 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 19202 19203 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 19204 struct net_device *netdev, const u8 *bssid, 19205 const u8 *replay_ctr, gfp_t gfp) 19206 { 19207 struct sk_buff *msg; 19208 struct nlattr *rekey_attr; 19209 void *hdr; 19210 19211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19212 if (!msg) 19213 return; 19214 19215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 19216 if (!hdr) { 19217 nlmsg_free(msg); 19218 return; 19219 } 19220 19221 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19222 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 19224 goto nla_put_failure; 19225 19226 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 19227 if (!rekey_attr) 19228 goto nla_put_failure; 19229 19230 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 19231 NL80211_REPLAY_CTR_LEN, replay_ctr)) 19232 goto nla_put_failure; 19233 19234 nla_nest_end(msg, rekey_attr); 19235 19236 genlmsg_end(msg, hdr); 19237 19238 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19239 NL80211_MCGRP_MLME, gfp); 19240 return; 19241 19242 nla_put_failure: 19243 nlmsg_free(msg); 19244 } 19245 19246 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 19247 const u8 *replay_ctr, gfp_t gfp) 19248 { 19249 struct wireless_dev *wdev = dev->ieee80211_ptr; 19250 struct wiphy *wiphy = wdev->wiphy; 19251 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19252 19253 trace_cfg80211_gtk_rekey_notify(dev, bssid); 19254 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 19255 } 19256 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 19257 19258 static void 19259 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 19260 struct net_device *netdev, int index, 19261 const u8 *bssid, bool preauth, gfp_t gfp) 19262 { 19263 struct sk_buff *msg; 19264 struct nlattr *attr; 19265 void *hdr; 19266 19267 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19268 if (!msg) 19269 return; 19270 19271 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 19272 if (!hdr) { 19273 nlmsg_free(msg); 19274 return; 19275 } 19276 19277 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 19279 goto nla_put_failure; 19280 19281 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 19282 if (!attr) 19283 goto nla_put_failure; 19284 19285 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 19286 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 19287 (preauth && 19288 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 19289 goto nla_put_failure; 19290 19291 nla_nest_end(msg, attr); 19292 19293 genlmsg_end(msg, hdr); 19294 19295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19296 NL80211_MCGRP_MLME, gfp); 19297 return; 19298 19299 nla_put_failure: 19300 nlmsg_free(msg); 19301 } 19302 19303 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 19304 const u8 *bssid, bool preauth, gfp_t gfp) 19305 { 19306 struct wireless_dev *wdev = dev->ieee80211_ptr; 19307 struct wiphy *wiphy = wdev->wiphy; 19308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19309 19310 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 19311 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 19312 } 19313 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 19314 19315 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 19316 struct net_device *netdev, 19317 unsigned int link_id, 19318 struct cfg80211_chan_def *chandef, 19319 gfp_t gfp, 19320 enum nl80211_commands notif, 19321 u8 count, bool quiet, u16 punct_bitmap) 19322 { 19323 struct wireless_dev *wdev = netdev->ieee80211_ptr; 19324 struct sk_buff *msg; 19325 void *hdr; 19326 19327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19328 if (!msg) 19329 return; 19330 19331 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 19332 if (!hdr) { 19333 nlmsg_free(msg); 19334 return; 19335 } 19336 19337 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 19338 goto nla_put_failure; 19339 19340 if (wdev->valid_links && 19341 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 19342 goto nla_put_failure; 19343 19344 if (nl80211_send_chandef(msg, chandef)) 19345 goto nla_put_failure; 19346 19347 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { 19348 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) 19349 goto nla_put_failure; 19350 if (quiet && 19351 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) 19352 goto nla_put_failure; 19353 } 19354 19355 if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, punct_bitmap)) 19356 goto nla_put_failure; 19357 19358 genlmsg_end(msg, hdr); 19359 19360 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19361 NL80211_MCGRP_MLME, gfp); 19362 return; 19363 19364 nla_put_failure: 19365 nlmsg_free(msg); 19366 } 19367 19368 void cfg80211_ch_switch_notify(struct net_device *dev, 19369 struct cfg80211_chan_def *chandef, 19370 unsigned int link_id, u16 punct_bitmap) 19371 { 19372 struct wireless_dev *wdev = dev->ieee80211_ptr; 19373 struct wiphy *wiphy = wdev->wiphy; 19374 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19375 19376 ASSERT_WDEV_LOCK(wdev); 19377 WARN_INVALID_LINK_ID(wdev, link_id); 19378 19379 trace_cfg80211_ch_switch_notify(dev, chandef, link_id, punct_bitmap); 19380 19381 switch (wdev->iftype) { 19382 case NL80211_IFTYPE_STATION: 19383 case NL80211_IFTYPE_P2P_CLIENT: 19384 if (!WARN_ON(!wdev->links[link_id].client.current_bss)) 19385 cfg80211_update_assoc_bss_entry(wdev, link_id, 19386 chandef->chan); 19387 break; 19388 case NL80211_IFTYPE_MESH_POINT: 19389 wdev->u.mesh.chandef = *chandef; 19390 wdev->u.mesh.preset_chandef = *chandef; 19391 break; 19392 case NL80211_IFTYPE_AP: 19393 case NL80211_IFTYPE_P2P_GO: 19394 wdev->links[link_id].ap.chandef = *chandef; 19395 break; 19396 case NL80211_IFTYPE_ADHOC: 19397 wdev->u.ibss.chandef = *chandef; 19398 break; 19399 default: 19400 WARN_ON(1); 19401 break; 19402 } 19403 19404 cfg80211_sched_dfs_chan_update(rdev); 19405 19406 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19407 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false, 19408 punct_bitmap); 19409 } 19410 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 19411 19412 void cfg80211_ch_switch_started_notify(struct net_device *dev, 19413 struct cfg80211_chan_def *chandef, 19414 unsigned int link_id, u8 count, 19415 bool quiet, u16 punct_bitmap) 19416 { 19417 struct wireless_dev *wdev = dev->ieee80211_ptr; 19418 struct wiphy *wiphy = wdev->wiphy; 19419 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19420 19421 ASSERT_WDEV_LOCK(wdev); 19422 WARN_INVALID_LINK_ID(wdev, link_id); 19423 19424 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id, 19425 punct_bitmap); 19426 19427 19428 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19429 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, 19430 count, quiet, punct_bitmap); 19431 } 19432 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 19433 19434 int cfg80211_bss_color_notify(struct net_device *dev, 19435 enum nl80211_commands cmd, u8 count, 19436 u64 color_bitmap) 19437 { 19438 struct wireless_dev *wdev = dev->ieee80211_ptr; 19439 struct wiphy *wiphy = wdev->wiphy; 19440 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19441 struct sk_buff *msg; 19442 void *hdr; 19443 19444 ASSERT_WDEV_LOCK(wdev); 19445 19446 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap); 19447 19448 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 19449 if (!msg) 19450 return -ENOMEM; 19451 19452 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 19453 if (!hdr) 19454 goto nla_put_failure; 19455 19456 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19457 goto nla_put_failure; 19458 19459 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED && 19460 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count)) 19461 goto nla_put_failure; 19462 19463 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION && 19464 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP, 19465 color_bitmap, NL80211_ATTR_PAD)) 19466 goto nla_put_failure; 19467 19468 genlmsg_end(msg, hdr); 19469 19470 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 19471 msg, 0, NL80211_MCGRP_MLME, GFP_KERNEL); 19472 19473 nla_put_failure: 19474 nlmsg_free(msg); 19475 return -EINVAL; 19476 } 19477 EXPORT_SYMBOL(cfg80211_bss_color_notify); 19478 19479 void 19480 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 19481 const struct cfg80211_chan_def *chandef, 19482 enum nl80211_radar_event event, 19483 struct net_device *netdev, gfp_t gfp) 19484 { 19485 struct sk_buff *msg; 19486 void *hdr; 19487 19488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19489 if (!msg) 19490 return; 19491 19492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 19493 if (!hdr) { 19494 nlmsg_free(msg); 19495 return; 19496 } 19497 19498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19499 goto nla_put_failure; 19500 19501 /* NOP and radar events don't need a netdev parameter */ 19502 if (netdev) { 19503 struct wireless_dev *wdev = netdev->ieee80211_ptr; 19504 19505 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19506 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19507 NL80211_ATTR_PAD)) 19508 goto nla_put_failure; 19509 } 19510 19511 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 19512 goto nla_put_failure; 19513 19514 if (nl80211_send_chandef(msg, chandef)) 19515 goto nla_put_failure; 19516 19517 genlmsg_end(msg, hdr); 19518 19519 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19520 NL80211_MCGRP_MLME, gfp); 19521 return; 19522 19523 nla_put_failure: 19524 nlmsg_free(msg); 19525 } 19526 19527 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 19528 struct sta_opmode_info *sta_opmode, 19529 gfp_t gfp) 19530 { 19531 struct sk_buff *msg; 19532 struct wireless_dev *wdev = dev->ieee80211_ptr; 19533 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19534 void *hdr; 19535 19536 if (WARN_ON(!mac)) 19537 return; 19538 19539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19540 if (!msg) 19541 return; 19542 19543 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 19544 if (!hdr) { 19545 nlmsg_free(msg); 19546 return; 19547 } 19548 19549 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19550 goto nla_put_failure; 19551 19552 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19553 goto nla_put_failure; 19554 19555 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 19556 goto nla_put_failure; 19557 19558 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 19559 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 19560 goto nla_put_failure; 19561 19562 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 19563 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 19564 goto nla_put_failure; 19565 19566 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 19567 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 19568 goto nla_put_failure; 19569 19570 genlmsg_end(msg, hdr); 19571 19572 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19573 NL80211_MCGRP_MLME, gfp); 19574 19575 return; 19576 19577 nla_put_failure: 19578 nlmsg_free(msg); 19579 } 19580 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 19581 19582 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 19583 u64 cookie, bool acked, s32 ack_signal, 19584 bool is_valid_ack_signal, gfp_t gfp) 19585 { 19586 struct wireless_dev *wdev = dev->ieee80211_ptr; 19587 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19588 struct sk_buff *msg; 19589 void *hdr; 19590 19591 trace_cfg80211_probe_status(dev, addr, cookie, acked); 19592 19593 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19594 19595 if (!msg) 19596 return; 19597 19598 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 19599 if (!hdr) { 19600 nlmsg_free(msg); 19601 return; 19602 } 19603 19604 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19605 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19606 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 19607 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 19608 NL80211_ATTR_PAD) || 19609 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 19610 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 19611 ack_signal))) 19612 goto nla_put_failure; 19613 19614 genlmsg_end(msg, hdr); 19615 19616 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19617 NL80211_MCGRP_MLME, gfp); 19618 return; 19619 19620 nla_put_failure: 19621 nlmsg_free(msg); 19622 } 19623 EXPORT_SYMBOL(cfg80211_probe_status); 19624 19625 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, 19626 size_t len, int freq, int sig_dbm) 19627 { 19628 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19629 struct sk_buff *msg; 19630 void *hdr; 19631 struct cfg80211_beacon_registration *reg; 19632 19633 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 19634 19635 spin_lock_bh(&rdev->beacon_registrations_lock); 19636 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 19637 msg = nlmsg_new(len + 100, GFP_ATOMIC); 19638 if (!msg) { 19639 spin_unlock_bh(&rdev->beacon_registrations_lock); 19640 return; 19641 } 19642 19643 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 19644 if (!hdr) 19645 goto nla_put_failure; 19646 19647 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19648 (freq && 19649 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 19650 KHZ_TO_MHZ(freq)) || 19651 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 19652 freq % 1000))) || 19653 (sig_dbm && 19654 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 19655 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 19656 goto nla_put_failure; 19657 19658 genlmsg_end(msg, hdr); 19659 19660 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 19661 } 19662 spin_unlock_bh(&rdev->beacon_registrations_lock); 19663 return; 19664 19665 nla_put_failure: 19666 spin_unlock_bh(&rdev->beacon_registrations_lock); 19667 nlmsg_free(msg); 19668 } 19669 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); 19670 19671 #ifdef CONFIG_PM 19672 static int cfg80211_net_detect_results(struct sk_buff *msg, 19673 struct cfg80211_wowlan_wakeup *wakeup) 19674 { 19675 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 19676 struct nlattr *nl_results, *nl_match, *nl_freqs; 19677 int i, j; 19678 19679 nl_results = nla_nest_start_noflag(msg, 19680 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 19681 if (!nl_results) 19682 return -EMSGSIZE; 19683 19684 for (i = 0; i < nd->n_matches; i++) { 19685 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 19686 19687 nl_match = nla_nest_start_noflag(msg, i); 19688 if (!nl_match) 19689 break; 19690 19691 /* The SSID attribute is optional in nl80211, but for 19692 * simplicity reasons it's always present in the 19693 * cfg80211 structure. If a driver can't pass the 19694 * SSID, that needs to be changed. A zero length SSID 19695 * is still a valid SSID (wildcard), so it cannot be 19696 * used for this purpose. 19697 */ 19698 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 19699 match->ssid.ssid)) { 19700 nla_nest_cancel(msg, nl_match); 19701 goto out; 19702 } 19703 19704 if (match->n_channels) { 19705 nl_freqs = nla_nest_start_noflag(msg, 19706 NL80211_ATTR_SCAN_FREQUENCIES); 19707 if (!nl_freqs) { 19708 nla_nest_cancel(msg, nl_match); 19709 goto out; 19710 } 19711 19712 for (j = 0; j < match->n_channels; j++) { 19713 if (nla_put_u32(msg, j, match->channels[j])) { 19714 nla_nest_cancel(msg, nl_freqs); 19715 nla_nest_cancel(msg, nl_match); 19716 goto out; 19717 } 19718 } 19719 19720 nla_nest_end(msg, nl_freqs); 19721 } 19722 19723 nla_nest_end(msg, nl_match); 19724 } 19725 19726 out: 19727 nla_nest_end(msg, nl_results); 19728 return 0; 19729 } 19730 19731 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 19732 struct cfg80211_wowlan_wakeup *wakeup, 19733 gfp_t gfp) 19734 { 19735 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19736 struct sk_buff *msg; 19737 void *hdr; 19738 int size = 200; 19739 19740 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 19741 19742 if (wakeup) 19743 size += wakeup->packet_present_len; 19744 19745 msg = nlmsg_new(size, gfp); 19746 if (!msg) 19747 return; 19748 19749 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 19750 if (!hdr) 19751 goto free_msg; 19752 19753 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19754 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19755 NL80211_ATTR_PAD)) 19756 goto free_msg; 19757 19758 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 19759 wdev->netdev->ifindex)) 19760 goto free_msg; 19761 19762 if (wakeup) { 19763 struct nlattr *reasons; 19764 19765 reasons = nla_nest_start_noflag(msg, 19766 NL80211_ATTR_WOWLAN_TRIGGERS); 19767 if (!reasons) 19768 goto free_msg; 19769 19770 if (wakeup->disconnect && 19771 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 19772 goto free_msg; 19773 if (wakeup->magic_pkt && 19774 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 19775 goto free_msg; 19776 if (wakeup->gtk_rekey_failure && 19777 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 19778 goto free_msg; 19779 if (wakeup->eap_identity_req && 19780 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 19781 goto free_msg; 19782 if (wakeup->four_way_handshake && 19783 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 19784 goto free_msg; 19785 if (wakeup->rfkill_release && 19786 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 19787 goto free_msg; 19788 19789 if (wakeup->pattern_idx >= 0 && 19790 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 19791 wakeup->pattern_idx)) 19792 goto free_msg; 19793 19794 if (wakeup->tcp_match && 19795 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 19796 goto free_msg; 19797 19798 if (wakeup->tcp_connlost && 19799 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 19800 goto free_msg; 19801 19802 if (wakeup->tcp_nomoretokens && 19803 nla_put_flag(msg, 19804 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 19805 goto free_msg; 19806 19807 if (wakeup->packet) { 19808 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 19809 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 19810 19811 if (!wakeup->packet_80211) { 19812 pkt_attr = 19813 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 19814 len_attr = 19815 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 19816 } 19817 19818 if (wakeup->packet_len && 19819 nla_put_u32(msg, len_attr, wakeup->packet_len)) 19820 goto free_msg; 19821 19822 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 19823 wakeup->packet)) 19824 goto free_msg; 19825 } 19826 19827 if (wakeup->net_detect && 19828 cfg80211_net_detect_results(msg, wakeup)) 19829 goto free_msg; 19830 19831 nla_nest_end(msg, reasons); 19832 } 19833 19834 genlmsg_end(msg, hdr); 19835 19836 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19837 NL80211_MCGRP_MLME, gfp); 19838 return; 19839 19840 free_msg: 19841 nlmsg_free(msg); 19842 } 19843 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 19844 #endif 19845 19846 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 19847 enum nl80211_tdls_operation oper, 19848 u16 reason_code, gfp_t gfp) 19849 { 19850 struct wireless_dev *wdev = dev->ieee80211_ptr; 19851 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19852 struct sk_buff *msg; 19853 void *hdr; 19854 19855 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 19856 reason_code); 19857 19858 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19859 if (!msg) 19860 return; 19861 19862 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 19863 if (!hdr) { 19864 nlmsg_free(msg); 19865 return; 19866 } 19867 19868 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19869 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19870 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 19871 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 19872 (reason_code > 0 && 19873 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 19874 goto nla_put_failure; 19875 19876 genlmsg_end(msg, hdr); 19877 19878 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19879 NL80211_MCGRP_MLME, gfp); 19880 return; 19881 19882 nla_put_failure: 19883 nlmsg_free(msg); 19884 } 19885 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 19886 19887 static int nl80211_netlink_notify(struct notifier_block * nb, 19888 unsigned long state, 19889 void *_notify) 19890 { 19891 struct netlink_notify *notify = _notify; 19892 struct cfg80211_registered_device *rdev; 19893 struct wireless_dev *wdev; 19894 struct cfg80211_beacon_registration *reg, *tmp; 19895 19896 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 19897 return NOTIFY_DONE; 19898 19899 rcu_read_lock(); 19900 19901 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 19902 struct cfg80211_sched_scan_request *sched_scan_req; 19903 19904 list_for_each_entry_rcu(sched_scan_req, 19905 &rdev->sched_scan_req_list, 19906 list) { 19907 if (sched_scan_req->owner_nlportid == notify->portid) { 19908 sched_scan_req->nl_owner_dead = true; 19909 wiphy_work_queue(&rdev->wiphy, 19910 &rdev->sched_scan_stop_wk); 19911 } 19912 } 19913 19914 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 19915 cfg80211_mlme_unregister_socket(wdev, notify->portid); 19916 19917 if (wdev->owner_nlportid == notify->portid) { 19918 wdev->nl_owner_dead = true; 19919 schedule_work(&rdev->destroy_work); 19920 } else if (wdev->conn_owner_nlportid == notify->portid) { 19921 schedule_work(&wdev->disconnect_wk); 19922 } 19923 19924 cfg80211_release_pmsr(wdev, notify->portid); 19925 } 19926 19927 spin_lock_bh(&rdev->beacon_registrations_lock); 19928 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 19929 list) { 19930 if (reg->nlportid == notify->portid) { 19931 list_del(®->list); 19932 kfree(reg); 19933 break; 19934 } 19935 } 19936 spin_unlock_bh(&rdev->beacon_registrations_lock); 19937 } 19938 19939 rcu_read_unlock(); 19940 19941 /* 19942 * It is possible that the user space process that is controlling the 19943 * indoor setting disappeared, so notify the regulatory core. 19944 */ 19945 regulatory_netlink_notify(notify->portid); 19946 return NOTIFY_OK; 19947 } 19948 19949 static struct notifier_block nl80211_netlink_notifier = { 19950 .notifier_call = nl80211_netlink_notify, 19951 }; 19952 19953 void cfg80211_ft_event(struct net_device *netdev, 19954 struct cfg80211_ft_event_params *ft_event) 19955 { 19956 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 19957 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19958 struct sk_buff *msg; 19959 void *hdr; 19960 19961 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 19962 19963 if (!ft_event->target_ap) 19964 return; 19965 19966 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 19967 GFP_KERNEL); 19968 if (!msg) 19969 return; 19970 19971 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 19972 if (!hdr) 19973 goto out; 19974 19975 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19976 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19977 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 19978 goto out; 19979 19980 if (ft_event->ies && 19981 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 19982 goto out; 19983 if (ft_event->ric_ies && 19984 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 19985 ft_event->ric_ies)) 19986 goto out; 19987 19988 genlmsg_end(msg, hdr); 19989 19990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19991 NL80211_MCGRP_MLME, GFP_KERNEL); 19992 return; 19993 out: 19994 nlmsg_free(msg); 19995 } 19996 EXPORT_SYMBOL(cfg80211_ft_event); 19997 19998 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 19999 { 20000 struct cfg80211_registered_device *rdev; 20001 struct sk_buff *msg; 20002 void *hdr; 20003 u32 nlportid; 20004 20005 rdev = wiphy_to_rdev(wdev->wiphy); 20006 if (!rdev->crit_proto_nlportid) 20007 return; 20008 20009 nlportid = rdev->crit_proto_nlportid; 20010 rdev->crit_proto_nlportid = 0; 20011 20012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 20013 if (!msg) 20014 return; 20015 20016 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 20017 if (!hdr) 20018 goto nla_put_failure; 20019 20020 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20021 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 20022 NL80211_ATTR_PAD)) 20023 goto nla_put_failure; 20024 20025 genlmsg_end(msg, hdr); 20026 20027 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 20028 return; 20029 20030 nla_put_failure: 20031 nlmsg_free(msg); 20032 } 20033 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 20034 20035 void nl80211_send_ap_stopped(struct wireless_dev *wdev, unsigned int link_id) 20036 { 20037 struct wiphy *wiphy = wdev->wiphy; 20038 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 20039 struct sk_buff *msg; 20040 void *hdr; 20041 20042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 20043 if (!msg) 20044 return; 20045 20046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 20047 if (!hdr) 20048 goto out; 20049 20050 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 20052 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 20053 NL80211_ATTR_PAD) || 20054 (wdev->valid_links && 20055 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) 20056 goto out; 20057 20058 genlmsg_end(msg, hdr); 20059 20060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 20061 NL80211_MCGRP_MLME, GFP_KERNEL); 20062 return; 20063 out: 20064 nlmsg_free(msg); 20065 } 20066 20067 int cfg80211_external_auth_request(struct net_device *dev, 20068 struct cfg80211_external_auth_params *params, 20069 gfp_t gfp) 20070 { 20071 struct wireless_dev *wdev = dev->ieee80211_ptr; 20072 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 20073 struct sk_buff *msg; 20074 void *hdr; 20075 20076 if (!wdev->conn_owner_nlportid) 20077 return -EINVAL; 20078 20079 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 20080 if (!msg) 20081 return -ENOMEM; 20082 20083 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 20084 if (!hdr) 20085 goto nla_put_failure; 20086 20087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20088 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 20089 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 20090 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 20091 params->action) || 20092 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 20093 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 20094 params->ssid.ssid) || 20095 (!is_zero_ether_addr(params->mld_addr) && 20096 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, params->mld_addr))) 20097 goto nla_put_failure; 20098 20099 genlmsg_end(msg, hdr); 20100 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 20101 wdev->conn_owner_nlportid); 20102 return 0; 20103 20104 nla_put_failure: 20105 nlmsg_free(msg); 20106 return -ENOBUFS; 20107 } 20108 EXPORT_SYMBOL(cfg80211_external_auth_request); 20109 20110 void cfg80211_update_owe_info_event(struct net_device *netdev, 20111 struct cfg80211_update_owe_info *owe_info, 20112 gfp_t gfp) 20113 { 20114 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 20115 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 20116 struct sk_buff *msg; 20117 void *hdr; 20118 20119 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 20120 20121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 20122 if (!msg) 20123 return; 20124 20125 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 20126 if (!hdr) 20127 goto nla_put_failure; 20128 20129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20130 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 20131 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 20132 goto nla_put_failure; 20133 20134 if (!owe_info->ie_len || 20135 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 20136 goto nla_put_failure; 20137 20138 if (owe_info->assoc_link_id != -1) { 20139 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, 20140 owe_info->assoc_link_id)) 20141 goto nla_put_failure; 20142 20143 if (!is_zero_ether_addr(owe_info->peer_mld_addr) && 20144 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, 20145 owe_info->peer_mld_addr)) 20146 goto nla_put_failure; 20147 } 20148 20149 genlmsg_end(msg, hdr); 20150 20151 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 20152 NL80211_MCGRP_MLME, gfp); 20153 return; 20154 20155 nla_put_failure: 20156 genlmsg_cancel(msg, hdr); 20157 nlmsg_free(msg); 20158 } 20159 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 20160 20161 /* initialisation/exit functions */ 20162 20163 int __init nl80211_init(void) 20164 { 20165 int err; 20166 20167 err = genl_register_family(&nl80211_fam); 20168 if (err) 20169 return err; 20170 20171 err = netlink_register_notifier(&nl80211_netlink_notifier); 20172 if (err) 20173 goto err_out; 20174 20175 return 0; 20176 err_out: 20177 genl_unregister_family(&nl80211_fam); 20178 return err; 20179 } 20180 20181 void nl80211_exit(void) 20182 { 20183 netlink_unregister_notifier(&nl80211_netlink_notifier); 20184 genl_unregister_family(&nl80211_fam); 20185 } 20186