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 for_each_rdev(rdev) { 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 const 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_PSD) && 1119 nla_put_s8(msg, NL80211_FREQUENCY_ATTR_PSD, chan->psd)) 1120 goto nla_put_failure; 1121 1122 if ((chan->flags & IEEE80211_CHAN_DISABLED) && 1123 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) 1124 goto nla_put_failure; 1125 if (chan->flags & IEEE80211_CHAN_NO_IR) { 1126 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) 1127 goto nla_put_failure; 1128 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) 1129 goto nla_put_failure; 1130 } 1131 if (chan->flags & IEEE80211_CHAN_RADAR) { 1132 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) 1133 goto nla_put_failure; 1134 if (large) { 1135 u32 time; 1136 1137 time = elapsed_jiffies_msecs(chan->dfs_state_entered); 1138 1139 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, 1140 chan->dfs_state)) 1141 goto nla_put_failure; 1142 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, 1143 time)) 1144 goto nla_put_failure; 1145 if (nla_put_u32(msg, 1146 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, 1147 chan->dfs_cac_ms)) 1148 goto nla_put_failure; 1149 } 1150 } 1151 1152 if (large) { 1153 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && 1154 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) 1155 goto nla_put_failure; 1156 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && 1157 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) 1158 goto nla_put_failure; 1159 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && 1160 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) 1161 goto nla_put_failure; 1162 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && 1163 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) 1164 goto nla_put_failure; 1165 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && 1166 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) 1167 goto nla_put_failure; 1168 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && 1169 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) 1170 goto nla_put_failure; 1171 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && 1172 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) 1173 goto nla_put_failure; 1174 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && 1175 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) 1176 goto nla_put_failure; 1177 if ((chan->flags & IEEE80211_CHAN_NO_HE) && 1178 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) 1179 goto nla_put_failure; 1180 if ((chan->flags & IEEE80211_CHAN_1MHZ) && 1181 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) 1182 goto nla_put_failure; 1183 if ((chan->flags & IEEE80211_CHAN_2MHZ) && 1184 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) 1185 goto nla_put_failure; 1186 if ((chan->flags & IEEE80211_CHAN_4MHZ) && 1187 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) 1188 goto nla_put_failure; 1189 if ((chan->flags & IEEE80211_CHAN_8MHZ) && 1190 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) 1191 goto nla_put_failure; 1192 if ((chan->flags & IEEE80211_CHAN_16MHZ) && 1193 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) 1194 goto nla_put_failure; 1195 if ((chan->flags & IEEE80211_CHAN_NO_320MHZ) && 1196 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_320MHZ)) 1197 goto nla_put_failure; 1198 if ((chan->flags & IEEE80211_CHAN_NO_EHT) && 1199 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_EHT)) 1200 goto nla_put_failure; 1201 } 1202 1203 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 1204 DBM_TO_MBM(chan->max_power))) 1205 goto nla_put_failure; 1206 1207 if (large) { 1208 const struct ieee80211_reg_rule *rule = 1209 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); 1210 1211 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { 1212 if (nl80211_msg_put_wmm_rules(msg, rule)) 1213 goto nla_put_failure; 1214 } 1215 } 1216 1217 return 0; 1218 1219 nla_put_failure: 1220 return -ENOBUFS; 1221 } 1222 1223 static bool nl80211_put_txq_stats(struct sk_buff *msg, 1224 struct cfg80211_txq_stats *txqstats, 1225 int attrtype) 1226 { 1227 struct nlattr *txqattr; 1228 1229 #define PUT_TXQVAL_U32(attr, memb) do { \ 1230 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ 1231 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ 1232 return false; \ 1233 } while (0) 1234 1235 txqattr = nla_nest_start_noflag(msg, attrtype); 1236 if (!txqattr) 1237 return false; 1238 1239 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); 1240 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); 1241 PUT_TXQVAL_U32(FLOWS, flows); 1242 PUT_TXQVAL_U32(DROPS, drops); 1243 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); 1244 PUT_TXQVAL_U32(OVERLIMIT, overlimit); 1245 PUT_TXQVAL_U32(OVERMEMORY, overmemory); 1246 PUT_TXQVAL_U32(COLLISIONS, collisions); 1247 PUT_TXQVAL_U32(TX_BYTES, tx_bytes); 1248 PUT_TXQVAL_U32(TX_PACKETS, tx_packets); 1249 PUT_TXQVAL_U32(MAX_FLOWS, max_flows); 1250 nla_nest_end(msg, txqattr); 1251 1252 #undef PUT_TXQVAL_U32 1253 return true; 1254 } 1255 1256 /* netlink command implementations */ 1257 1258 /** 1259 * nl80211_link_id - return link ID 1260 * @attrs: attributes to look at 1261 * 1262 * Returns: the link ID or 0 if not given 1263 * 1264 * Note this function doesn't do any validation of the link 1265 * ID validity wrt. links that were actually added, so it must 1266 * be called only from ops with %NL80211_FLAG_MLO_VALID_LINK_ID 1267 * or if additional validation is done. 1268 */ 1269 static unsigned int nl80211_link_id(struct nlattr **attrs) 1270 { 1271 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1272 1273 if (!linkid) 1274 return 0; 1275 1276 return nla_get_u8(linkid); 1277 } 1278 1279 static int nl80211_link_id_or_invalid(struct nlattr **attrs) 1280 { 1281 struct nlattr *linkid = attrs[NL80211_ATTR_MLO_LINK_ID]; 1282 1283 if (!linkid) 1284 return -1; 1285 1286 return nla_get_u8(linkid); 1287 } 1288 1289 struct key_parse { 1290 struct key_params p; 1291 int idx; 1292 int type; 1293 bool def, defmgmt, defbeacon; 1294 bool def_uni, def_multi; 1295 }; 1296 1297 static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, 1298 struct key_parse *k) 1299 { 1300 struct nlattr *tb[NL80211_KEY_MAX + 1]; 1301 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, 1302 nl80211_key_policy, 1303 info->extack); 1304 if (err) 1305 return err; 1306 1307 k->def = !!tb[NL80211_KEY_DEFAULT]; 1308 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; 1309 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; 1310 1311 if (k->def) { 1312 k->def_uni = true; 1313 k->def_multi = true; 1314 } 1315 if (k->defmgmt || k->defbeacon) 1316 k->def_multi = true; 1317 1318 if (tb[NL80211_KEY_IDX]) 1319 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); 1320 1321 if (tb[NL80211_KEY_DATA]) { 1322 k->p.key = nla_data(tb[NL80211_KEY_DATA]); 1323 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); 1324 } 1325 1326 if (tb[NL80211_KEY_SEQ]) { 1327 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); 1328 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); 1329 } 1330 1331 if (tb[NL80211_KEY_CIPHER]) 1332 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); 1333 1334 if (tb[NL80211_KEY_TYPE]) 1335 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); 1336 1337 if (tb[NL80211_KEY_DEFAULT_TYPES]) { 1338 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1339 1340 err = nla_parse_nested_deprecated(kdt, 1341 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1342 tb[NL80211_KEY_DEFAULT_TYPES], 1343 nl80211_key_default_policy, 1344 info->extack); 1345 if (err) 1346 return err; 1347 1348 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1349 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1350 } 1351 1352 if (tb[NL80211_KEY_MODE]) 1353 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); 1354 1355 return 0; 1356 } 1357 1358 static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) 1359 { 1360 if (info->attrs[NL80211_ATTR_KEY_DATA]) { 1361 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); 1362 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); 1363 } 1364 1365 if (info->attrs[NL80211_ATTR_KEY_SEQ]) { 1366 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); 1367 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); 1368 } 1369 1370 if (info->attrs[NL80211_ATTR_KEY_IDX]) 1371 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 1372 1373 if (info->attrs[NL80211_ATTR_KEY_CIPHER]) 1374 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); 1375 1376 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; 1377 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; 1378 1379 if (k->def) { 1380 k->def_uni = true; 1381 k->def_multi = true; 1382 } 1383 if (k->defmgmt) 1384 k->def_multi = true; 1385 1386 if (info->attrs[NL80211_ATTR_KEY_TYPE]) 1387 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 1388 1389 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { 1390 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; 1391 int err = nla_parse_nested_deprecated(kdt, 1392 NUM_NL80211_KEY_DEFAULT_TYPES - 1, 1393 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], 1394 nl80211_key_default_policy, 1395 info->extack); 1396 if (err) 1397 return err; 1398 1399 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; 1400 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; 1401 } 1402 1403 return 0; 1404 } 1405 1406 static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) 1407 { 1408 int err; 1409 1410 memset(k, 0, sizeof(*k)); 1411 k->idx = -1; 1412 k->type = -1; 1413 1414 if (info->attrs[NL80211_ATTR_KEY]) 1415 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); 1416 else 1417 err = nl80211_parse_key_old(info, k); 1418 1419 if (err) 1420 return err; 1421 1422 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + 1423 (k->defbeacon ? 1 : 0) > 1) { 1424 GENL_SET_ERR_MSG(info, 1425 "key with multiple default flags is invalid"); 1426 return -EINVAL; 1427 } 1428 1429 if (k->defmgmt || k->defbeacon) { 1430 if (k->def_uni || !k->def_multi) { 1431 GENL_SET_ERR_MSG(info, 1432 "defmgmt/defbeacon key must be mcast"); 1433 return -EINVAL; 1434 } 1435 } 1436 1437 if (k->idx != -1) { 1438 if (k->defmgmt) { 1439 if (k->idx < 4 || k->idx > 5) { 1440 GENL_SET_ERR_MSG(info, 1441 "defmgmt key idx not 4 or 5"); 1442 return -EINVAL; 1443 } 1444 } else if (k->defbeacon) { 1445 if (k->idx < 6 || k->idx > 7) { 1446 GENL_SET_ERR_MSG(info, 1447 "defbeacon key idx not 6 or 7"); 1448 return -EINVAL; 1449 } 1450 } else if (k->def) { 1451 if (k->idx < 0 || k->idx > 3) { 1452 GENL_SET_ERR_MSG(info, "def key idx not 0-3"); 1453 return -EINVAL; 1454 } 1455 } else { 1456 if (k->idx < 0 || k->idx > 7) { 1457 GENL_SET_ERR_MSG(info, "key idx not 0-7"); 1458 return -EINVAL; 1459 } 1460 } 1461 } 1462 1463 return 0; 1464 } 1465 1466 static struct cfg80211_cached_keys * 1467 nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, 1468 struct genl_info *info, bool *no_ht) 1469 { 1470 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; 1471 struct key_parse parse; 1472 struct nlattr *key; 1473 struct cfg80211_cached_keys *result; 1474 int rem, err, def = 0; 1475 bool have_key = false; 1476 1477 nla_for_each_nested(key, keys, rem) { 1478 have_key = true; 1479 break; 1480 } 1481 1482 if (!have_key) 1483 return NULL; 1484 1485 result = kzalloc(sizeof(*result), GFP_KERNEL); 1486 if (!result) 1487 return ERR_PTR(-ENOMEM); 1488 1489 result->def = -1; 1490 1491 nla_for_each_nested(key, keys, rem) { 1492 memset(&parse, 0, sizeof(parse)); 1493 parse.idx = -1; 1494 1495 err = nl80211_parse_key_new(info, key, &parse); 1496 if (err) 1497 goto error; 1498 err = -EINVAL; 1499 if (!parse.p.key) 1500 goto error; 1501 if (parse.idx < 0 || parse.idx > 3) { 1502 GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); 1503 goto error; 1504 } 1505 if (parse.def) { 1506 if (def) { 1507 GENL_SET_ERR_MSG(info, 1508 "only one key can be default"); 1509 goto error; 1510 } 1511 def = 1; 1512 result->def = parse.idx; 1513 if (!parse.def_uni || !parse.def_multi) 1514 goto error; 1515 } else if (parse.defmgmt) 1516 goto error; 1517 err = cfg80211_validate_key_settings(rdev, &parse.p, 1518 parse.idx, false, NULL); 1519 if (err) 1520 goto error; 1521 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && 1522 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { 1523 GENL_SET_ERR_MSG(info, "connect key must be WEP"); 1524 err = -EINVAL; 1525 goto error; 1526 } 1527 result->params[parse.idx].cipher = parse.p.cipher; 1528 result->params[parse.idx].key_len = parse.p.key_len; 1529 result->params[parse.idx].key = result->data[parse.idx]; 1530 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); 1531 1532 /* must be WEP key if we got here */ 1533 if (no_ht) 1534 *no_ht = true; 1535 } 1536 1537 if (result->def < 0) { 1538 err = -EINVAL; 1539 GENL_SET_ERR_MSG(info, "need a default/TX key"); 1540 goto error; 1541 } 1542 1543 return result; 1544 error: 1545 kfree(result); 1546 return ERR_PTR(err); 1547 } 1548 1549 static int nl80211_key_allowed(struct wireless_dev *wdev) 1550 { 1551 lockdep_assert_wiphy(wdev->wiphy); 1552 1553 switch (wdev->iftype) { 1554 case NL80211_IFTYPE_AP: 1555 case NL80211_IFTYPE_AP_VLAN: 1556 case NL80211_IFTYPE_P2P_GO: 1557 case NL80211_IFTYPE_MESH_POINT: 1558 break; 1559 case NL80211_IFTYPE_ADHOC: 1560 if (wdev->u.ibss.current_bss) 1561 return 0; 1562 return -ENOLINK; 1563 case NL80211_IFTYPE_STATION: 1564 case NL80211_IFTYPE_P2P_CLIENT: 1565 if (wdev->connected) 1566 return 0; 1567 return -ENOLINK; 1568 case NL80211_IFTYPE_NAN: 1569 if (wiphy_ext_feature_isset(wdev->wiphy, 1570 NL80211_EXT_FEATURE_SECURE_NAN)) 1571 return 0; 1572 return -EINVAL; 1573 case NL80211_IFTYPE_UNSPECIFIED: 1574 case NL80211_IFTYPE_OCB: 1575 case NL80211_IFTYPE_MONITOR: 1576 case NL80211_IFTYPE_P2P_DEVICE: 1577 case NL80211_IFTYPE_WDS: 1578 case NUM_NL80211_IFTYPES: 1579 return -EINVAL; 1580 } 1581 1582 return 0; 1583 } 1584 1585 static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, 1586 u32 freq) 1587 { 1588 struct ieee80211_channel *chan; 1589 1590 chan = ieee80211_get_channel_khz(wiphy, freq); 1591 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) 1592 return NULL; 1593 return chan; 1594 } 1595 1596 static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) 1597 { 1598 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); 1599 int i; 1600 1601 if (!nl_modes) 1602 goto nla_put_failure; 1603 1604 i = 0; 1605 while (ifmodes) { 1606 if ((ifmodes & 1) && nla_put_flag(msg, i)) 1607 goto nla_put_failure; 1608 ifmodes >>= 1; 1609 i++; 1610 } 1611 1612 nla_nest_end(msg, nl_modes); 1613 return 0; 1614 1615 nla_put_failure: 1616 return -ENOBUFS; 1617 } 1618 1619 static int nl80211_put_iface_combinations(struct wiphy *wiphy, 1620 struct sk_buff *msg, 1621 bool large) 1622 { 1623 struct nlattr *nl_combis; 1624 int i, j; 1625 1626 nl_combis = nla_nest_start_noflag(msg, 1627 NL80211_ATTR_INTERFACE_COMBINATIONS); 1628 if (!nl_combis) 1629 goto nla_put_failure; 1630 1631 for (i = 0; i < wiphy->n_iface_combinations; i++) { 1632 const struct ieee80211_iface_combination *c; 1633 struct nlattr *nl_combi, *nl_limits; 1634 1635 c = &wiphy->iface_combinations[i]; 1636 1637 nl_combi = nla_nest_start_noflag(msg, i + 1); 1638 if (!nl_combi) 1639 goto nla_put_failure; 1640 1641 nl_limits = nla_nest_start_noflag(msg, 1642 NL80211_IFACE_COMB_LIMITS); 1643 if (!nl_limits) 1644 goto nla_put_failure; 1645 1646 for (j = 0; j < c->n_limits; j++) { 1647 struct nlattr *nl_limit; 1648 1649 nl_limit = nla_nest_start_noflag(msg, j + 1); 1650 if (!nl_limit) 1651 goto nla_put_failure; 1652 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, 1653 c->limits[j].max)) 1654 goto nla_put_failure; 1655 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, 1656 c->limits[j].types)) 1657 goto nla_put_failure; 1658 nla_nest_end(msg, nl_limit); 1659 } 1660 1661 nla_nest_end(msg, nl_limits); 1662 1663 if (c->beacon_int_infra_match && 1664 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) 1665 goto nla_put_failure; 1666 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, 1667 c->num_different_channels) || 1668 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, 1669 c->max_interfaces)) 1670 goto nla_put_failure; 1671 if (large && 1672 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, 1673 c->radar_detect_widths) || 1674 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, 1675 c->radar_detect_regions))) 1676 goto nla_put_failure; 1677 if (c->beacon_int_min_gcd && 1678 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, 1679 c->beacon_int_min_gcd)) 1680 goto nla_put_failure; 1681 1682 nla_nest_end(msg, nl_combi); 1683 } 1684 1685 nla_nest_end(msg, nl_combis); 1686 1687 return 0; 1688 nla_put_failure: 1689 return -ENOBUFS; 1690 } 1691 1692 #ifdef CONFIG_PM 1693 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, 1694 struct sk_buff *msg) 1695 { 1696 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; 1697 struct nlattr *nl_tcp; 1698 1699 if (!tcp) 1700 return 0; 1701 1702 nl_tcp = nla_nest_start_noflag(msg, 1703 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 1704 if (!nl_tcp) 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 (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 1712 tcp->data_payload_max)) 1713 return -ENOBUFS; 1714 1715 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) 1716 return -ENOBUFS; 1717 1718 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 1719 sizeof(*tcp->tok), tcp->tok)) 1720 return -ENOBUFS; 1721 1722 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 1723 tcp->data_interval_max)) 1724 return -ENOBUFS; 1725 1726 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 1727 tcp->wake_payload_max)) 1728 return -ENOBUFS; 1729 1730 nla_nest_end(msg, nl_tcp); 1731 return 0; 1732 } 1733 1734 static int nl80211_send_wowlan(struct sk_buff *msg, 1735 struct cfg80211_registered_device *rdev, 1736 bool large) 1737 { 1738 struct nlattr *nl_wowlan; 1739 1740 if (!rdev->wiphy.wowlan) 1741 return 0; 1742 1743 nl_wowlan = nla_nest_start_noflag(msg, 1744 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); 1745 if (!nl_wowlan) 1746 return -ENOBUFS; 1747 1748 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && 1749 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 1750 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && 1751 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 1752 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && 1753 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 1754 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && 1755 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || 1756 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && 1757 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 1758 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && 1759 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 1760 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && 1761 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 1762 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && 1763 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 1764 return -ENOBUFS; 1765 1766 if (rdev->wiphy.wowlan->n_patterns) { 1767 struct nl80211_pattern_support pat = { 1768 .max_patterns = rdev->wiphy.wowlan->n_patterns, 1769 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, 1770 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, 1771 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, 1772 }; 1773 1774 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 1775 sizeof(pat), &pat)) 1776 return -ENOBUFS; 1777 } 1778 1779 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && 1780 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, 1781 rdev->wiphy.wowlan->max_nd_match_sets)) 1782 return -ENOBUFS; 1783 1784 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) 1785 return -ENOBUFS; 1786 1787 nla_nest_end(msg, nl_wowlan); 1788 1789 return 0; 1790 } 1791 #endif 1792 1793 static int nl80211_send_coalesce(struct sk_buff *msg, 1794 struct cfg80211_registered_device *rdev) 1795 { 1796 struct nl80211_coalesce_rule_support rule; 1797 1798 if (!rdev->wiphy.coalesce) 1799 return 0; 1800 1801 rule.max_rules = rdev->wiphy.coalesce->n_rules; 1802 rule.max_delay = rdev->wiphy.coalesce->max_delay; 1803 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; 1804 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; 1805 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; 1806 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; 1807 1808 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) 1809 return -ENOBUFS; 1810 1811 return 0; 1812 } 1813 1814 static int 1815 nl80211_send_iftype_data(struct sk_buff *msg, 1816 const struct ieee80211_supported_band *sband, 1817 const struct ieee80211_sband_iftype_data *iftdata) 1818 { 1819 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; 1820 const struct ieee80211_sta_eht_cap *eht_cap = &iftdata->eht_cap; 1821 1822 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, 1823 iftdata->types_mask)) 1824 return -ENOBUFS; 1825 1826 if (he_cap->has_he) { 1827 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, 1828 sizeof(he_cap->he_cap_elem.mac_cap_info), 1829 he_cap->he_cap_elem.mac_cap_info) || 1830 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, 1831 sizeof(he_cap->he_cap_elem.phy_cap_info), 1832 he_cap->he_cap_elem.phy_cap_info) || 1833 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, 1834 sizeof(he_cap->he_mcs_nss_supp), 1835 &he_cap->he_mcs_nss_supp) || 1836 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, 1837 sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) 1838 return -ENOBUFS; 1839 } 1840 1841 if (eht_cap->has_eht && he_cap->has_he) { 1842 u8 mcs_nss_size, ppe_thresh_size; 1843 u16 ppe_thres_hdr; 1844 bool is_ap; 1845 1846 is_ap = iftdata->types_mask & BIT(NL80211_IFTYPE_AP) || 1847 iftdata->types_mask & BIT(NL80211_IFTYPE_P2P_GO); 1848 1849 mcs_nss_size = 1850 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem, 1851 &eht_cap->eht_cap_elem, 1852 is_ap); 1853 1854 ppe_thres_hdr = get_unaligned_le16(&eht_cap->eht_ppe_thres[0]); 1855 ppe_thresh_size = 1856 ieee80211_eht_ppe_size(ppe_thres_hdr, 1857 eht_cap->eht_cap_elem.phy_cap_info); 1858 1859 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MAC, 1860 sizeof(eht_cap->eht_cap_elem.mac_cap_info), 1861 eht_cap->eht_cap_elem.mac_cap_info) || 1862 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PHY, 1863 sizeof(eht_cap->eht_cap_elem.phy_cap_info), 1864 eht_cap->eht_cap_elem.phy_cap_info) || 1865 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_MCS_SET, 1866 mcs_nss_size, &eht_cap->eht_mcs_nss_supp) || 1867 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE, 1868 ppe_thresh_size, eht_cap->eht_ppe_thres)) 1869 return -ENOBUFS; 1870 } 1871 1872 if (sband->band == NL80211_BAND_6GHZ && 1873 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, 1874 sizeof(iftdata->he_6ghz_capa), 1875 &iftdata->he_6ghz_capa)) 1876 return -ENOBUFS; 1877 1878 if (iftdata->vendor_elems.data && iftdata->vendor_elems.len && 1879 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, 1880 iftdata->vendor_elems.len, iftdata->vendor_elems.data)) 1881 return -ENOBUFS; 1882 1883 return 0; 1884 } 1885 1886 static int nl80211_send_band_rateinfo(struct sk_buff *msg, 1887 struct ieee80211_supported_band *sband, 1888 bool large) 1889 { 1890 struct nlattr *nl_rates, *nl_rate; 1891 struct ieee80211_rate *rate; 1892 int i; 1893 1894 /* add HT info */ 1895 if (sband->ht_cap.ht_supported && 1896 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, 1897 sizeof(sband->ht_cap.mcs), 1898 &sband->ht_cap.mcs) || 1899 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, 1900 sband->ht_cap.cap) || 1901 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, 1902 sband->ht_cap.ampdu_factor) || 1903 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, 1904 sband->ht_cap.ampdu_density))) 1905 return -ENOBUFS; 1906 1907 /* add VHT info */ 1908 if (sband->vht_cap.vht_supported && 1909 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, 1910 sizeof(sband->vht_cap.vht_mcs), 1911 &sband->vht_cap.vht_mcs) || 1912 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, 1913 sband->vht_cap.cap))) 1914 return -ENOBUFS; 1915 1916 if (large && sband->n_iftype_data) { 1917 struct nlattr *nl_iftype_data = 1918 nla_nest_start_noflag(msg, 1919 NL80211_BAND_ATTR_IFTYPE_DATA); 1920 const struct ieee80211_sband_iftype_data *iftd; 1921 int err; 1922 1923 if (!nl_iftype_data) 1924 return -ENOBUFS; 1925 1926 for_each_sband_iftype_data(sband, i, iftd) { 1927 struct nlattr *iftdata; 1928 1929 iftdata = nla_nest_start_noflag(msg, i + 1); 1930 if (!iftdata) 1931 return -ENOBUFS; 1932 1933 err = nl80211_send_iftype_data(msg, sband, iftd); 1934 if (err) 1935 return err; 1936 1937 nla_nest_end(msg, iftdata); 1938 } 1939 1940 nla_nest_end(msg, nl_iftype_data); 1941 } 1942 1943 /* add EDMG info */ 1944 if (large && sband->edmg_cap.channels && 1945 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, 1946 sband->edmg_cap.channels) || 1947 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, 1948 sband->edmg_cap.bw_config))) 1949 1950 return -ENOBUFS; 1951 1952 /* add bitrates */ 1953 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); 1954 if (!nl_rates) 1955 return -ENOBUFS; 1956 1957 for (i = 0; i < sband->n_bitrates; i++) { 1958 nl_rate = nla_nest_start_noflag(msg, i); 1959 if (!nl_rate) 1960 return -ENOBUFS; 1961 1962 rate = &sband->bitrates[i]; 1963 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, 1964 rate->bitrate)) 1965 return -ENOBUFS; 1966 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && 1967 nla_put_flag(msg, 1968 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) 1969 return -ENOBUFS; 1970 1971 nla_nest_end(msg, nl_rate); 1972 } 1973 1974 nla_nest_end(msg, nl_rates); 1975 1976 /* S1G capabilities */ 1977 if (sband->band == NL80211_BAND_S1GHZ && sband->s1g_cap.s1g && 1978 (nla_put(msg, NL80211_BAND_ATTR_S1G_CAPA, 1979 sizeof(sband->s1g_cap.cap), 1980 sband->s1g_cap.cap) || 1981 nla_put(msg, NL80211_BAND_ATTR_S1G_MCS_NSS_SET, 1982 sizeof(sband->s1g_cap.nss_mcs), 1983 sband->s1g_cap.nss_mcs))) 1984 return -ENOBUFS; 1985 1986 return 0; 1987 } 1988 1989 static int 1990 nl80211_send_mgmt_stypes(struct sk_buff *msg, 1991 const struct ieee80211_txrx_stypes *mgmt_stypes) 1992 { 1993 u16 stypes; 1994 struct nlattr *nl_ftypes, *nl_ifs; 1995 enum nl80211_iftype ift; 1996 int i; 1997 1998 if (!mgmt_stypes) 1999 return 0; 2000 2001 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); 2002 if (!nl_ifs) 2003 return -ENOBUFS; 2004 2005 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 2006 nl_ftypes = nla_nest_start_noflag(msg, ift); 2007 if (!nl_ftypes) 2008 return -ENOBUFS; 2009 i = 0; 2010 stypes = mgmt_stypes[ift].tx; 2011 while (stypes) { 2012 if ((stypes & 1) && 2013 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 2014 (i << 4) | IEEE80211_FTYPE_MGMT)) 2015 return -ENOBUFS; 2016 stypes >>= 1; 2017 i++; 2018 } 2019 nla_nest_end(msg, nl_ftypes); 2020 } 2021 2022 nla_nest_end(msg, nl_ifs); 2023 2024 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); 2025 if (!nl_ifs) 2026 return -ENOBUFS; 2027 2028 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { 2029 nl_ftypes = nla_nest_start_noflag(msg, ift); 2030 if (!nl_ftypes) 2031 return -ENOBUFS; 2032 i = 0; 2033 stypes = mgmt_stypes[ift].rx; 2034 while (stypes) { 2035 if ((stypes & 1) && 2036 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, 2037 (i << 4) | IEEE80211_FTYPE_MGMT)) 2038 return -ENOBUFS; 2039 stypes >>= 1; 2040 i++; 2041 } 2042 nla_nest_end(msg, nl_ftypes); 2043 } 2044 nla_nest_end(msg, nl_ifs); 2045 2046 return 0; 2047 } 2048 2049 #define CMD(op, n) \ 2050 do { \ 2051 if (rdev->ops->op) { \ 2052 i++; \ 2053 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ 2054 goto nla_put_failure; \ 2055 } \ 2056 } while (0) 2057 2058 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, 2059 struct sk_buff *msg) 2060 { 2061 int i = 0; 2062 2063 /* 2064 * do *NOT* add anything into this function, new things need to be 2065 * advertised only to new versions of userspace that can deal with 2066 * the split (and they can't possibly care about new features... 2067 */ 2068 CMD(add_virtual_intf, NEW_INTERFACE); 2069 CMD(change_virtual_intf, SET_INTERFACE); 2070 CMD(add_key, NEW_KEY); 2071 CMD(start_ap, START_AP); 2072 CMD(add_station, NEW_STATION); 2073 CMD(add_mpath, NEW_MPATH); 2074 CMD(update_mesh_config, SET_MESH_CONFIG); 2075 CMD(change_bss, SET_BSS); 2076 CMD(auth, AUTHENTICATE); 2077 CMD(assoc, ASSOCIATE); 2078 CMD(deauth, DEAUTHENTICATE); 2079 CMD(disassoc, DISASSOCIATE); 2080 CMD(join_ibss, JOIN_IBSS); 2081 CMD(join_mesh, JOIN_MESH); 2082 CMD(set_pmksa, SET_PMKSA); 2083 CMD(del_pmksa, DEL_PMKSA); 2084 CMD(flush_pmksa, FLUSH_PMKSA); 2085 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) 2086 CMD(remain_on_channel, REMAIN_ON_CHANNEL); 2087 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); 2088 CMD(mgmt_tx, FRAME); 2089 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); 2090 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { 2091 i++; 2092 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 2093 goto nla_put_failure; 2094 } 2095 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || 2096 rdev->ops->join_mesh) { 2097 i++; 2098 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) 2099 goto nla_put_failure; 2100 } 2101 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 2102 CMD(tdls_mgmt, TDLS_MGMT); 2103 CMD(tdls_oper, TDLS_OPER); 2104 } 2105 if (rdev->wiphy.max_sched_scan_reqs) 2106 CMD(sched_scan_start, START_SCHED_SCAN); 2107 CMD(probe_client, PROBE_CLIENT); 2108 CMD(set_noack_map, SET_NOACK_MAP); 2109 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { 2110 i++; 2111 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) 2112 goto nla_put_failure; 2113 } 2114 CMD(start_p2p_device, START_P2P_DEVICE); 2115 CMD(set_mcast_rate, SET_MCAST_RATE); 2116 #ifdef CONFIG_NL80211_TESTMODE 2117 CMD(testmode_cmd, TESTMODE); 2118 #endif 2119 2120 if (rdev->ops->connect || rdev->ops->auth) { 2121 i++; 2122 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) 2123 goto nla_put_failure; 2124 } 2125 2126 if (rdev->ops->disconnect || rdev->ops->deauth) { 2127 i++; 2128 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) 2129 goto nla_put_failure; 2130 } 2131 2132 return i; 2133 nla_put_failure: 2134 return -ENOBUFS; 2135 } 2136 2137 static int 2138 nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, 2139 struct sk_buff *msg) 2140 { 2141 struct nlattr *ftm; 2142 2143 if (!cap->ftm.supported) 2144 return 0; 2145 2146 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); 2147 if (!ftm) 2148 return -ENOBUFS; 2149 2150 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) 2151 return -ENOBUFS; 2152 if (cap->ftm.non_asap && 2153 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) 2154 return -ENOBUFS; 2155 if (cap->ftm.request_lci && 2156 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) 2157 return -ENOBUFS; 2158 if (cap->ftm.request_civicloc && 2159 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) 2160 return -ENOBUFS; 2161 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, 2162 cap->ftm.preambles)) 2163 return -ENOBUFS; 2164 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, 2165 cap->ftm.bandwidths)) 2166 return -ENOBUFS; 2167 if (cap->ftm.max_bursts_exponent >= 0 && 2168 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, 2169 cap->ftm.max_bursts_exponent)) 2170 return -ENOBUFS; 2171 if (cap->ftm.max_ftms_per_burst && 2172 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, 2173 cap->ftm.max_ftms_per_burst)) 2174 return -ENOBUFS; 2175 if (cap->ftm.trigger_based && 2176 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) 2177 return -ENOBUFS; 2178 if (cap->ftm.non_trigger_based && 2179 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) 2180 return -ENOBUFS; 2181 2182 nla_nest_end(msg, ftm); 2183 return 0; 2184 } 2185 2186 static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, 2187 struct sk_buff *msg) 2188 { 2189 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; 2190 struct nlattr *pmsr, *caps; 2191 2192 if (!cap) 2193 return 0; 2194 2195 /* 2196 * we don't need to clean up anything here since the caller 2197 * will genlmsg_cancel() if we fail 2198 */ 2199 2200 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); 2201 if (!pmsr) 2202 return -ENOBUFS; 2203 2204 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) 2205 return -ENOBUFS; 2206 2207 if (cap->report_ap_tsf && 2208 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) 2209 return -ENOBUFS; 2210 2211 if (cap->randomize_mac_addr && 2212 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) 2213 return -ENOBUFS; 2214 2215 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); 2216 if (!caps) 2217 return -ENOBUFS; 2218 2219 if (nl80211_send_pmsr_ftm_capa(cap, msg)) 2220 return -ENOBUFS; 2221 2222 nla_nest_end(msg, caps); 2223 nla_nest_end(msg, pmsr); 2224 2225 return 0; 2226 } 2227 2228 static int 2229 nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, 2230 struct sk_buff *msg) 2231 { 2232 int i; 2233 struct nlattr *nested, *nested_akms; 2234 const struct wiphy_iftype_akm_suites *iftype_akms; 2235 2236 if (!rdev->wiphy.num_iftype_akm_suites || 2237 !rdev->wiphy.iftype_akm_suites) 2238 return 0; 2239 2240 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); 2241 if (!nested) 2242 return -ENOBUFS; 2243 2244 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { 2245 nested_akms = nla_nest_start(msg, i + 1); 2246 if (!nested_akms) 2247 return -ENOBUFS; 2248 2249 iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; 2250 2251 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, 2252 iftype_akms->iftypes_mask)) 2253 return -ENOBUFS; 2254 2255 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, 2256 sizeof(u32) * iftype_akms->n_akm_suites, 2257 iftype_akms->akm_suites)) { 2258 return -ENOBUFS; 2259 } 2260 nla_nest_end(msg, nested_akms); 2261 } 2262 2263 nla_nest_end(msg, nested); 2264 2265 return 0; 2266 } 2267 2268 static int 2269 nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, 2270 struct sk_buff *msg) 2271 { 2272 struct nlattr *supp; 2273 2274 if (!rdev->wiphy.tid_config_support.vif && 2275 !rdev->wiphy.tid_config_support.peer) 2276 return 0; 2277 2278 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); 2279 if (!supp) 2280 return -ENOSPC; 2281 2282 if (rdev->wiphy.tid_config_support.vif && 2283 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, 2284 rdev->wiphy.tid_config_support.vif, 2285 NL80211_TID_CONFIG_ATTR_PAD)) 2286 goto fail; 2287 2288 if (rdev->wiphy.tid_config_support.peer && 2289 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, 2290 rdev->wiphy.tid_config_support.peer, 2291 NL80211_TID_CONFIG_ATTR_PAD)) 2292 goto fail; 2293 2294 /* for now we just use the same value ... makes more sense */ 2295 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, 2296 rdev->wiphy.tid_config_support.max_retry)) 2297 goto fail; 2298 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, 2299 rdev->wiphy.tid_config_support.max_retry)) 2300 goto fail; 2301 2302 nla_nest_end(msg, supp); 2303 2304 return 0; 2305 fail: 2306 nla_nest_cancel(msg, supp); 2307 return -ENOBUFS; 2308 } 2309 2310 static int 2311 nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, 2312 struct sk_buff *msg) 2313 { 2314 struct nlattr *sar_capa, *specs, *sub_freq_range; 2315 u8 num_freq_ranges; 2316 int i; 2317 2318 if (!rdev->wiphy.sar_capa) 2319 return 0; 2320 2321 num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; 2322 2323 sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); 2324 if (!sar_capa) 2325 return -ENOSPC; 2326 2327 if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) 2328 goto fail; 2329 2330 specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); 2331 if (!specs) 2332 goto fail; 2333 2334 /* report supported freq_ranges */ 2335 for (i = 0; i < num_freq_ranges; i++) { 2336 sub_freq_range = nla_nest_start(msg, i + 1); 2337 if (!sub_freq_range) 2338 goto fail; 2339 2340 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, 2341 rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) 2342 goto fail; 2343 2344 if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, 2345 rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) 2346 goto fail; 2347 2348 nla_nest_end(msg, sub_freq_range); 2349 } 2350 2351 nla_nest_end(msg, specs); 2352 nla_nest_end(msg, sar_capa); 2353 2354 return 0; 2355 fail: 2356 nla_nest_cancel(msg, sar_capa); 2357 return -ENOBUFS; 2358 } 2359 2360 static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg) 2361 { 2362 struct nlattr *config; 2363 2364 if (!wiphy->mbssid_max_interfaces) 2365 return 0; 2366 2367 config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); 2368 if (!config) 2369 return -ENOBUFS; 2370 2371 if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, 2372 wiphy->mbssid_max_interfaces)) 2373 goto fail; 2374 2375 if (wiphy->ema_max_profile_periodicity && 2376 nla_put_u8(msg, 2377 NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, 2378 wiphy->ema_max_profile_periodicity)) 2379 goto fail; 2380 2381 nla_nest_end(msg, config); 2382 return 0; 2383 2384 fail: 2385 nla_nest_cancel(msg, config); 2386 return -ENOBUFS; 2387 } 2388 2389 struct nl80211_dump_wiphy_state { 2390 s64 filter_wiphy; 2391 long start; 2392 long split_start, band_start, chan_start, capa_start; 2393 bool split; 2394 }; 2395 2396 static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 2397 enum nl80211_commands cmd, 2398 struct sk_buff *msg, u32 portid, u32 seq, 2399 int flags, struct nl80211_dump_wiphy_state *state) 2400 { 2401 void *hdr; 2402 struct nlattr *nl_bands, *nl_band; 2403 struct nlattr *nl_freqs, *nl_freq; 2404 struct nlattr *nl_cmds; 2405 enum nl80211_band band; 2406 struct ieee80211_channel *chan; 2407 int i; 2408 const struct ieee80211_txrx_stypes *mgmt_stypes = 2409 rdev->wiphy.mgmt_stypes; 2410 u32 features; 2411 2412 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 2413 if (!hdr) 2414 return -ENOBUFS; 2415 2416 if (WARN_ON(!state)) 2417 return -EINVAL; 2418 2419 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 2420 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, 2421 wiphy_name(&rdev->wiphy)) || 2422 nla_put_u32(msg, NL80211_ATTR_GENERATION, 2423 cfg80211_rdev_list_generation)) 2424 goto nla_put_failure; 2425 2426 if (cmd != NL80211_CMD_NEW_WIPHY) 2427 goto finish; 2428 2429 switch (state->split_start) { 2430 case 0: 2431 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 2432 rdev->wiphy.retry_short) || 2433 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, 2434 rdev->wiphy.retry_long) || 2435 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, 2436 rdev->wiphy.frag_threshold) || 2437 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, 2438 rdev->wiphy.rts_threshold) || 2439 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, 2440 rdev->wiphy.coverage_class) || 2441 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 2442 rdev->wiphy.max_scan_ssids) || 2443 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, 2444 rdev->wiphy.max_sched_scan_ssids) || 2445 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, 2446 rdev->wiphy.max_scan_ie_len) || 2447 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, 2448 rdev->wiphy.max_sched_scan_ie_len) || 2449 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, 2450 rdev->wiphy.max_match_sets)) 2451 goto nla_put_failure; 2452 2453 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && 2454 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) 2455 goto nla_put_failure; 2456 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && 2457 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) 2458 goto nla_put_failure; 2459 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && 2460 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) 2461 goto nla_put_failure; 2462 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && 2463 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) 2464 goto nla_put_failure; 2465 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && 2466 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) 2467 goto nla_put_failure; 2468 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && 2469 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) 2470 goto nla_put_failure; 2471 state->split_start++; 2472 if (state->split) 2473 break; 2474 fallthrough; 2475 case 1: 2476 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, 2477 sizeof(u32) * rdev->wiphy.n_cipher_suites, 2478 rdev->wiphy.cipher_suites)) 2479 goto nla_put_failure; 2480 2481 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, 2482 rdev->wiphy.max_num_pmkids)) 2483 goto nla_put_failure; 2484 2485 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 2486 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) 2487 goto nla_put_failure; 2488 2489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, 2490 rdev->wiphy.available_antennas_tx) || 2491 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, 2492 rdev->wiphy.available_antennas_rx)) 2493 goto nla_put_failure; 2494 2495 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && 2496 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, 2497 rdev->wiphy.probe_resp_offload)) 2498 goto nla_put_failure; 2499 2500 if ((rdev->wiphy.available_antennas_tx || 2501 rdev->wiphy.available_antennas_rx) && 2502 rdev->ops->get_antenna) { 2503 u32 tx_ant = 0, rx_ant = 0; 2504 int res; 2505 2506 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); 2507 if (!res) { 2508 if (nla_put_u32(msg, 2509 NL80211_ATTR_WIPHY_ANTENNA_TX, 2510 tx_ant) || 2511 nla_put_u32(msg, 2512 NL80211_ATTR_WIPHY_ANTENNA_RX, 2513 rx_ant)) 2514 goto nla_put_failure; 2515 } 2516 } 2517 2518 state->split_start++; 2519 if (state->split) 2520 break; 2521 fallthrough; 2522 case 2: 2523 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, 2524 rdev->wiphy.interface_modes)) 2525 goto nla_put_failure; 2526 state->split_start++; 2527 if (state->split) 2528 break; 2529 fallthrough; 2530 case 3: 2531 nl_bands = nla_nest_start_noflag(msg, 2532 NL80211_ATTR_WIPHY_BANDS); 2533 if (!nl_bands) 2534 goto nla_put_failure; 2535 2536 for (band = state->band_start; 2537 band < (state->split ? 2538 NUM_NL80211_BANDS : 2539 NL80211_BAND_60GHZ + 1); 2540 band++) { 2541 struct ieee80211_supported_band *sband; 2542 2543 /* omit higher bands for ancient software */ 2544 if (band > NL80211_BAND_5GHZ && !state->split) 2545 break; 2546 2547 sband = rdev->wiphy.bands[band]; 2548 2549 if (!sband) 2550 continue; 2551 2552 nl_band = nla_nest_start_noflag(msg, band); 2553 if (!nl_band) 2554 goto nla_put_failure; 2555 2556 switch (state->chan_start) { 2557 case 0: 2558 if (nl80211_send_band_rateinfo(msg, sband, 2559 state->split)) 2560 goto nla_put_failure; 2561 state->chan_start++; 2562 if (state->split) 2563 break; 2564 fallthrough; 2565 default: 2566 /* add frequencies */ 2567 nl_freqs = nla_nest_start_noflag(msg, 2568 NL80211_BAND_ATTR_FREQS); 2569 if (!nl_freqs) 2570 goto nla_put_failure; 2571 2572 for (i = state->chan_start - 1; 2573 i < sband->n_channels; 2574 i++) { 2575 nl_freq = nla_nest_start_noflag(msg, 2576 i); 2577 if (!nl_freq) 2578 goto nla_put_failure; 2579 2580 chan = &sband->channels[i]; 2581 2582 if (nl80211_msg_put_channel( 2583 msg, &rdev->wiphy, chan, 2584 state->split)) 2585 goto nla_put_failure; 2586 2587 nla_nest_end(msg, nl_freq); 2588 if (state->split) 2589 break; 2590 } 2591 if (i < sband->n_channels) 2592 state->chan_start = i + 2; 2593 else 2594 state->chan_start = 0; 2595 nla_nest_end(msg, nl_freqs); 2596 } 2597 2598 nla_nest_end(msg, nl_band); 2599 2600 if (state->split) { 2601 /* start again here */ 2602 if (state->chan_start) 2603 band--; 2604 break; 2605 } 2606 } 2607 nla_nest_end(msg, nl_bands); 2608 2609 if (band < NUM_NL80211_BANDS) 2610 state->band_start = band + 1; 2611 else 2612 state->band_start = 0; 2613 2614 /* if bands & channels are done, continue outside */ 2615 if (state->band_start == 0 && state->chan_start == 0) 2616 state->split_start++; 2617 if (state->split) 2618 break; 2619 fallthrough; 2620 case 4: 2621 nl_cmds = nla_nest_start_noflag(msg, 2622 NL80211_ATTR_SUPPORTED_COMMANDS); 2623 if (!nl_cmds) 2624 goto nla_put_failure; 2625 2626 i = nl80211_add_commands_unsplit(rdev, msg); 2627 if (i < 0) 2628 goto nla_put_failure; 2629 if (state->split) { 2630 CMD(crit_proto_start, CRIT_PROTOCOL_START); 2631 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); 2632 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) 2633 CMD(channel_switch, CHANNEL_SWITCH); 2634 CMD(set_qos_map, SET_QOS_MAP); 2635 if (rdev->wiphy.features & 2636 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) 2637 CMD(add_tx_ts, ADD_TX_TS); 2638 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); 2639 CMD(update_connect_params, UPDATE_CONNECT_PARAMS); 2640 CMD(update_ft_ies, UPDATE_FT_IES); 2641 if (rdev->wiphy.sar_capa) 2642 CMD(set_sar_specs, SET_SAR_SPECS); 2643 } 2644 #undef CMD 2645 2646 nla_nest_end(msg, nl_cmds); 2647 state->split_start++; 2648 if (state->split) 2649 break; 2650 fallthrough; 2651 case 5: 2652 if (rdev->ops->remain_on_channel && 2653 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && 2654 nla_put_u32(msg, 2655 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, 2656 rdev->wiphy.max_remain_on_channel_duration)) 2657 goto nla_put_failure; 2658 2659 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && 2660 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) 2661 goto nla_put_failure; 2662 2663 state->split_start++; 2664 if (state->split) 2665 break; 2666 fallthrough; 2667 case 6: 2668 #ifdef CONFIG_PM 2669 if (nl80211_send_wowlan(msg, rdev, state->split)) 2670 goto nla_put_failure; 2671 state->split_start++; 2672 if (state->split) 2673 break; 2674 #else 2675 state->split_start++; 2676 #endif 2677 fallthrough; 2678 case 7: 2679 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, 2680 rdev->wiphy.software_iftypes)) 2681 goto nla_put_failure; 2682 2683 if (nl80211_put_iface_combinations(&rdev->wiphy, msg, 2684 state->split)) 2685 goto nla_put_failure; 2686 2687 state->split_start++; 2688 if (state->split) 2689 break; 2690 fallthrough; 2691 case 8: 2692 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && 2693 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, 2694 rdev->wiphy.ap_sme_capa)) 2695 goto nla_put_failure; 2696 2697 features = rdev->wiphy.features; 2698 /* 2699 * We can only add the per-channel limit information if the 2700 * dump is split, otherwise it makes it too big. Therefore 2701 * only advertise it in that case. 2702 */ 2703 if (state->split) 2704 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; 2705 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) 2706 goto nla_put_failure; 2707 2708 if (rdev->wiphy.ht_capa_mod_mask && 2709 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, 2710 sizeof(*rdev->wiphy.ht_capa_mod_mask), 2711 rdev->wiphy.ht_capa_mod_mask)) 2712 goto nla_put_failure; 2713 2714 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && 2715 rdev->wiphy.max_acl_mac_addrs && 2716 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, 2717 rdev->wiphy.max_acl_mac_addrs)) 2718 goto nla_put_failure; 2719 2720 /* 2721 * Any information below this point is only available to 2722 * applications that can deal with it being split. This 2723 * helps ensure that newly added capabilities don't break 2724 * older tools by overrunning their buffers. 2725 * 2726 * We still increment split_start so that in the split 2727 * case we'll continue with more data in the next round, 2728 * but break unconditionally so unsplit data stops here. 2729 */ 2730 if (state->split) 2731 state->split_start++; 2732 else 2733 state->split_start = 0; 2734 break; 2735 case 9: 2736 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) 2737 goto nla_put_failure; 2738 2739 if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, 2740 rdev->wiphy.max_sched_scan_plans) || 2741 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, 2742 rdev->wiphy.max_sched_scan_plan_interval) || 2743 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, 2744 rdev->wiphy.max_sched_scan_plan_iterations)) 2745 goto nla_put_failure; 2746 2747 if (rdev->wiphy.extended_capabilities && 2748 (nla_put(msg, NL80211_ATTR_EXT_CAPA, 2749 rdev->wiphy.extended_capabilities_len, 2750 rdev->wiphy.extended_capabilities) || 2751 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2752 rdev->wiphy.extended_capabilities_len, 2753 rdev->wiphy.extended_capabilities_mask))) 2754 goto nla_put_failure; 2755 2756 if (rdev->wiphy.vht_capa_mod_mask && 2757 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, 2758 sizeof(*rdev->wiphy.vht_capa_mod_mask), 2759 rdev->wiphy.vht_capa_mod_mask)) 2760 goto nla_put_failure; 2761 2762 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 2763 rdev->wiphy.perm_addr)) 2764 goto nla_put_failure; 2765 2766 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && 2767 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, 2768 rdev->wiphy.addr_mask)) 2769 goto nla_put_failure; 2770 2771 if (rdev->wiphy.n_addresses > 1) { 2772 void *attr; 2773 2774 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); 2775 if (!attr) 2776 goto nla_put_failure; 2777 2778 for (i = 0; i < rdev->wiphy.n_addresses; i++) 2779 if (nla_put(msg, i + 1, ETH_ALEN, 2780 rdev->wiphy.addresses[i].addr)) 2781 goto nla_put_failure; 2782 2783 nla_nest_end(msg, attr); 2784 } 2785 2786 state->split_start++; 2787 break; 2788 case 10: 2789 if (nl80211_send_coalesce(msg, rdev)) 2790 goto nla_put_failure; 2791 2792 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && 2793 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || 2794 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) 2795 goto nla_put_failure; 2796 2797 if (rdev->wiphy.max_ap_assoc_sta && 2798 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, 2799 rdev->wiphy.max_ap_assoc_sta)) 2800 goto nla_put_failure; 2801 2802 state->split_start++; 2803 break; 2804 case 11: 2805 if (rdev->wiphy.n_vendor_commands) { 2806 const struct nl80211_vendor_cmd_info *info; 2807 struct nlattr *nested; 2808 2809 nested = nla_nest_start_noflag(msg, 2810 NL80211_ATTR_VENDOR_DATA); 2811 if (!nested) 2812 goto nla_put_failure; 2813 2814 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 2815 info = &rdev->wiphy.vendor_commands[i].info; 2816 if (nla_put(msg, i + 1, sizeof(*info), info)) 2817 goto nla_put_failure; 2818 } 2819 nla_nest_end(msg, nested); 2820 } 2821 2822 if (rdev->wiphy.n_vendor_events) { 2823 const struct nl80211_vendor_cmd_info *info; 2824 struct nlattr *nested; 2825 2826 nested = nla_nest_start_noflag(msg, 2827 NL80211_ATTR_VENDOR_EVENTS); 2828 if (!nested) 2829 goto nla_put_failure; 2830 2831 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { 2832 info = &rdev->wiphy.vendor_events[i]; 2833 if (nla_put(msg, i + 1, sizeof(*info), info)) 2834 goto nla_put_failure; 2835 } 2836 nla_nest_end(msg, nested); 2837 } 2838 state->split_start++; 2839 break; 2840 case 12: 2841 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && 2842 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, 2843 rdev->wiphy.max_num_csa_counters)) 2844 goto nla_put_failure; 2845 2846 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 2847 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 2848 goto nla_put_failure; 2849 2850 if (rdev->wiphy.max_sched_scan_reqs && 2851 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, 2852 rdev->wiphy.max_sched_scan_reqs)) 2853 goto nla_put_failure; 2854 2855 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, 2856 sizeof(rdev->wiphy.ext_features), 2857 rdev->wiphy.ext_features)) 2858 goto nla_put_failure; 2859 2860 if (rdev->wiphy.bss_select_support) { 2861 struct nlattr *nested; 2862 u32 bss_select_support = rdev->wiphy.bss_select_support; 2863 2864 nested = nla_nest_start_noflag(msg, 2865 NL80211_ATTR_BSS_SELECT); 2866 if (!nested) 2867 goto nla_put_failure; 2868 2869 i = 0; 2870 while (bss_select_support) { 2871 if ((bss_select_support & 1) && 2872 nla_put_flag(msg, i)) 2873 goto nla_put_failure; 2874 i++; 2875 bss_select_support >>= 1; 2876 } 2877 nla_nest_end(msg, nested); 2878 } 2879 2880 state->split_start++; 2881 break; 2882 case 13: 2883 if (rdev->wiphy.num_iftype_ext_capab && 2884 rdev->wiphy.iftype_ext_capab) { 2885 struct nlattr *nested_ext_capab, *nested; 2886 2887 nested = nla_nest_start_noflag(msg, 2888 NL80211_ATTR_IFTYPE_EXT_CAPA); 2889 if (!nested) 2890 goto nla_put_failure; 2891 2892 for (i = state->capa_start; 2893 i < rdev->wiphy.num_iftype_ext_capab; i++) { 2894 const struct wiphy_iftype_ext_capab *capab; 2895 2896 capab = &rdev->wiphy.iftype_ext_capab[i]; 2897 2898 nested_ext_capab = nla_nest_start_noflag(msg, 2899 i); 2900 if (!nested_ext_capab || 2901 nla_put_u32(msg, NL80211_ATTR_IFTYPE, 2902 capab->iftype) || 2903 nla_put(msg, NL80211_ATTR_EXT_CAPA, 2904 capab->extended_capabilities_len, 2905 capab->extended_capabilities) || 2906 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, 2907 capab->extended_capabilities_len, 2908 capab->extended_capabilities_mask)) 2909 goto nla_put_failure; 2910 2911 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO && 2912 (nla_put_u16(msg, 2913 NL80211_ATTR_EML_CAPABILITY, 2914 capab->eml_capabilities) || 2915 nla_put_u16(msg, 2916 NL80211_ATTR_MLD_CAPA_AND_OPS, 2917 capab->mld_capa_and_ops))) 2918 goto nla_put_failure; 2919 2920 nla_nest_end(msg, nested_ext_capab); 2921 if (state->split) 2922 break; 2923 } 2924 nla_nest_end(msg, nested); 2925 if (i < rdev->wiphy.num_iftype_ext_capab) { 2926 state->capa_start = i + 1; 2927 break; 2928 } 2929 } 2930 2931 if (nla_put_u32(msg, NL80211_ATTR_BANDS, 2932 rdev->wiphy.nan_supported_bands)) 2933 goto nla_put_failure; 2934 2935 if (wiphy_ext_feature_isset(&rdev->wiphy, 2936 NL80211_EXT_FEATURE_TXQS)) { 2937 struct cfg80211_txq_stats txqstats = {}; 2938 int res; 2939 2940 res = rdev_get_txq_stats(rdev, NULL, &txqstats); 2941 if (!res && 2942 !nl80211_put_txq_stats(msg, &txqstats, 2943 NL80211_ATTR_TXQ_STATS)) 2944 goto nla_put_failure; 2945 2946 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, 2947 rdev->wiphy.txq_limit)) 2948 goto nla_put_failure; 2949 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, 2950 rdev->wiphy.txq_memory_limit)) 2951 goto nla_put_failure; 2952 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, 2953 rdev->wiphy.txq_quantum)) 2954 goto nla_put_failure; 2955 } 2956 2957 state->split_start++; 2958 break; 2959 case 14: 2960 if (nl80211_send_pmsr_capa(rdev, msg)) 2961 goto nla_put_failure; 2962 2963 state->split_start++; 2964 break; 2965 case 15: 2966 if (rdev->wiphy.akm_suites && 2967 nla_put(msg, NL80211_ATTR_AKM_SUITES, 2968 sizeof(u32) * rdev->wiphy.n_akm_suites, 2969 rdev->wiphy.akm_suites)) 2970 goto nla_put_failure; 2971 2972 if (nl80211_put_iftype_akm_suites(rdev, msg)) 2973 goto nla_put_failure; 2974 2975 if (nl80211_put_tid_config_support(rdev, msg)) 2976 goto nla_put_failure; 2977 state->split_start++; 2978 break; 2979 case 16: 2980 if (nl80211_put_sar_specs(rdev, msg)) 2981 goto nla_put_failure; 2982 2983 if (nl80211_put_mbssid_support(&rdev->wiphy, msg)) 2984 goto nla_put_failure; 2985 2986 if (nla_put_u16(msg, NL80211_ATTR_MAX_NUM_AKM_SUITES, 2987 rdev->wiphy.max_num_akm_suites)) 2988 goto nla_put_failure; 2989 2990 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO) 2991 nla_put_flag(msg, NL80211_ATTR_MLO_SUPPORT); 2992 2993 if (rdev->wiphy.hw_timestamp_max_peers && 2994 nla_put_u16(msg, NL80211_ATTR_MAX_HW_TIMESTAMP_PEERS, 2995 rdev->wiphy.hw_timestamp_max_peers)) 2996 goto nla_put_failure; 2997 2998 /* done */ 2999 state->split_start = 0; 3000 break; 3001 } 3002 finish: 3003 genlmsg_end(msg, hdr); 3004 return 0; 3005 3006 nla_put_failure: 3007 genlmsg_cancel(msg, hdr); 3008 return -EMSGSIZE; 3009 } 3010 3011 static int nl80211_dump_wiphy_parse(struct sk_buff *skb, 3012 struct netlink_callback *cb, 3013 struct nl80211_dump_wiphy_state *state) 3014 { 3015 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 3016 int ret; 3017 3018 if (!tb) 3019 return -ENOMEM; 3020 3021 ret = nlmsg_parse_deprecated(cb->nlh, 3022 GENL_HDRLEN + nl80211_fam.hdrsize, 3023 tb, nl80211_fam.maxattr, 3024 nl80211_policy, NULL); 3025 /* ignore parse errors for backward compatibility */ 3026 if (ret) { 3027 ret = 0; 3028 goto out; 3029 } 3030 3031 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; 3032 if (tb[NL80211_ATTR_WIPHY]) 3033 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); 3034 if (tb[NL80211_ATTR_WDEV]) 3035 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; 3036 if (tb[NL80211_ATTR_IFINDEX]) { 3037 struct net_device *netdev; 3038 struct cfg80211_registered_device *rdev; 3039 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); 3040 3041 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); 3042 if (!netdev) { 3043 ret = -ENODEV; 3044 goto out; 3045 } 3046 if (netdev->ieee80211_ptr) { 3047 rdev = wiphy_to_rdev( 3048 netdev->ieee80211_ptr->wiphy); 3049 state->filter_wiphy = rdev->wiphy_idx; 3050 } 3051 } 3052 3053 ret = 0; 3054 out: 3055 kfree(tb); 3056 return ret; 3057 } 3058 3059 static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) 3060 { 3061 int idx = 0, ret; 3062 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; 3063 struct cfg80211_registered_device *rdev; 3064 3065 rtnl_lock(); 3066 if (!state) { 3067 state = kzalloc(sizeof(*state), GFP_KERNEL); 3068 if (!state) { 3069 rtnl_unlock(); 3070 return -ENOMEM; 3071 } 3072 state->filter_wiphy = -1; 3073 ret = nl80211_dump_wiphy_parse(skb, cb, state); 3074 if (ret) { 3075 kfree(state); 3076 rtnl_unlock(); 3077 return ret; 3078 } 3079 cb->args[0] = (long)state; 3080 } 3081 3082 for_each_rdev(rdev) { 3083 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3084 continue; 3085 if (++idx <= state->start) 3086 continue; 3087 if (state->filter_wiphy != -1 && 3088 state->filter_wiphy != rdev->wiphy_idx) 3089 continue; 3090 wiphy_lock(&rdev->wiphy); 3091 /* attempt to fit multiple wiphy data chunks into the skb */ 3092 do { 3093 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, 3094 skb, 3095 NETLINK_CB(cb->skb).portid, 3096 cb->nlh->nlmsg_seq, 3097 NLM_F_MULTI, state); 3098 if (ret < 0) { 3099 /* 3100 * If sending the wiphy data didn't fit (ENOBUFS 3101 * or EMSGSIZE returned), this SKB is still 3102 * empty (so it's not too big because another 3103 * wiphy dataset is already in the skb) and 3104 * we've not tried to adjust the dump allocation 3105 * yet ... then adjust the alloc size to be 3106 * bigger, and return 1 but with the empty skb. 3107 * This results in an empty message being RX'ed 3108 * in userspace, but that is ignored. 3109 * 3110 * We can then retry with the larger buffer. 3111 */ 3112 if ((ret == -ENOBUFS || ret == -EMSGSIZE) && 3113 !skb->len && !state->split && 3114 cb->min_dump_alloc < 4096) { 3115 cb->min_dump_alloc = 4096; 3116 state->split_start = 0; 3117 wiphy_unlock(&rdev->wiphy); 3118 rtnl_unlock(); 3119 return 1; 3120 } 3121 idx--; 3122 break; 3123 } 3124 } while (state->split_start > 0); 3125 wiphy_unlock(&rdev->wiphy); 3126 break; 3127 } 3128 rtnl_unlock(); 3129 3130 state->start = idx; 3131 3132 return skb->len; 3133 } 3134 3135 static int nl80211_dump_wiphy_done(struct netlink_callback *cb) 3136 { 3137 kfree((void *)cb->args[0]); 3138 return 0; 3139 } 3140 3141 static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) 3142 { 3143 struct sk_buff *msg; 3144 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3145 struct nl80211_dump_wiphy_state state = {}; 3146 3147 msg = nlmsg_new(4096, GFP_KERNEL); 3148 if (!msg) 3149 return -ENOMEM; 3150 3151 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, 3152 info->snd_portid, info->snd_seq, 0, 3153 &state) < 0) { 3154 nlmsg_free(msg); 3155 return -ENOBUFS; 3156 } 3157 3158 return genlmsg_reply(msg, info); 3159 } 3160 3161 static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { 3162 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, 3163 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, 3164 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, 3165 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, 3166 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, 3167 }; 3168 3169 static int parse_txq_params(struct nlattr *tb[], 3170 struct ieee80211_txq_params *txq_params) 3171 { 3172 u8 ac; 3173 3174 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || 3175 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || 3176 !tb[NL80211_TXQ_ATTR_AIFS]) 3177 return -EINVAL; 3178 3179 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); 3180 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); 3181 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); 3182 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); 3183 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); 3184 3185 if (ac >= NL80211_NUM_ACS) 3186 return -EINVAL; 3187 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); 3188 return 0; 3189 } 3190 3191 static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 3192 { 3193 /* 3194 * You can only set the channel explicitly for some interfaces, 3195 * most have their channel managed via their respective 3196 * "establish a connection" command (connect, join, ...) 3197 * 3198 * For AP/GO and mesh mode, the channel can be set with the 3199 * channel userspace API, but is only stored and passed to the 3200 * low-level driver when the AP starts or the mesh is joined. 3201 * This is for backward compatibility, userspace can also give 3202 * the channel in the start-ap or join-mesh commands instead. 3203 * 3204 * Monitors are special as they are normally slaved to 3205 * whatever else is going on, so they have their own special 3206 * operation to set the monitor channel if possible. 3207 */ 3208 return !wdev || 3209 wdev->iftype == NL80211_IFTYPE_AP || 3210 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 3211 wdev->iftype == NL80211_IFTYPE_MONITOR || 3212 wdev->iftype == NL80211_IFTYPE_P2P_GO; 3213 } 3214 3215 static int nl80211_parse_punct_bitmap(struct cfg80211_registered_device *rdev, 3216 struct genl_info *info, 3217 const struct cfg80211_chan_def *chandef, 3218 u16 *punct_bitmap) 3219 { 3220 if (!wiphy_ext_feature_isset(&rdev->wiphy, NL80211_EXT_FEATURE_PUNCT)) 3221 return -EINVAL; 3222 3223 *punct_bitmap = nla_get_u32(info->attrs[NL80211_ATTR_PUNCT_BITMAP]); 3224 if (!cfg80211_valid_disable_subchannel_bitmap(punct_bitmap, chandef)) 3225 return -EINVAL; 3226 3227 return 0; 3228 } 3229 3230 int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, 3231 struct genl_info *info, 3232 struct cfg80211_chan_def *chandef) 3233 { 3234 struct netlink_ext_ack *extack = info->extack; 3235 struct nlattr **attrs = info->attrs; 3236 u32 control_freq; 3237 3238 if (!attrs[NL80211_ATTR_WIPHY_FREQ]) { 3239 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3240 "Frequency is missing"); 3241 return -EINVAL; 3242 } 3243 3244 control_freq = MHZ_TO_KHZ( 3245 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 3246 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 3247 control_freq += 3248 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 3249 3250 memset(chandef, 0, sizeof(*chandef)); 3251 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); 3252 chandef->width = NL80211_CHAN_WIDTH_20_NOHT; 3253 chandef->center_freq1 = KHZ_TO_MHZ(control_freq); 3254 chandef->freq1_offset = control_freq % 1000; 3255 chandef->center_freq2 = 0; 3256 3257 /* Primary channel not allowed */ 3258 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { 3259 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], 3260 "Channel is disabled"); 3261 return -EINVAL; 3262 } 3263 3264 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 3265 enum nl80211_channel_type chantype; 3266 3267 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); 3268 3269 switch (chantype) { 3270 case NL80211_CHAN_NO_HT: 3271 case NL80211_CHAN_HT20: 3272 case NL80211_CHAN_HT40PLUS: 3273 case NL80211_CHAN_HT40MINUS: 3274 cfg80211_chandef_create(chandef, chandef->chan, 3275 chantype); 3276 /* user input for center_freq is incorrect */ 3277 if (attrs[NL80211_ATTR_CENTER_FREQ1] && 3278 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { 3279 NL_SET_ERR_MSG_ATTR(extack, 3280 attrs[NL80211_ATTR_CENTER_FREQ1], 3281 "bad center frequency 1"); 3282 return -EINVAL; 3283 } 3284 /* center_freq2 must be zero */ 3285 if (attrs[NL80211_ATTR_CENTER_FREQ2] && 3286 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { 3287 NL_SET_ERR_MSG_ATTR(extack, 3288 attrs[NL80211_ATTR_CENTER_FREQ2], 3289 "center frequency 2 can't be used"); 3290 return -EINVAL; 3291 } 3292 break; 3293 default: 3294 NL_SET_ERR_MSG_ATTR(extack, 3295 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], 3296 "invalid channel type"); 3297 return -EINVAL; 3298 } 3299 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { 3300 chandef->width = 3301 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); 3302 if (chandef->chan->band == NL80211_BAND_S1GHZ) { 3303 /* User input error for channel width doesn't match channel */ 3304 if (chandef->width != ieee80211_s1g_channel_width(chandef->chan)) { 3305 NL_SET_ERR_MSG_ATTR(extack, 3306 attrs[NL80211_ATTR_CHANNEL_WIDTH], 3307 "bad channel width"); 3308 return -EINVAL; 3309 } 3310 } 3311 if (attrs[NL80211_ATTR_CENTER_FREQ1]) { 3312 chandef->center_freq1 = 3313 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); 3314 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) 3315 chandef->freq1_offset = nla_get_u32( 3316 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); 3317 else 3318 chandef->freq1_offset = 0; 3319 } 3320 if (attrs[NL80211_ATTR_CENTER_FREQ2]) 3321 chandef->center_freq2 = 3322 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); 3323 } 3324 3325 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 3326 chandef->edmg.channels = 3327 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 3328 3329 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 3330 chandef->edmg.bw_config = 3331 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 3332 } else { 3333 chandef->edmg.bw_config = 0; 3334 chandef->edmg.channels = 0; 3335 } 3336 3337 if (!cfg80211_chandef_valid(chandef)) { 3338 NL_SET_ERR_MSG(extack, "invalid channel definition"); 3339 return -EINVAL; 3340 } 3341 3342 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, 3343 IEEE80211_CHAN_DISABLED)) { 3344 NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); 3345 return -EINVAL; 3346 } 3347 3348 if ((chandef->width == NL80211_CHAN_WIDTH_5 || 3349 chandef->width == NL80211_CHAN_WIDTH_10) && 3350 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { 3351 NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); 3352 return -EINVAL; 3353 } 3354 3355 return 0; 3356 } 3357 3358 static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, 3359 struct net_device *dev, 3360 struct genl_info *info, 3361 int _link_id) 3362 { 3363 struct cfg80211_chan_def chandef; 3364 int result; 3365 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; 3366 struct wireless_dev *wdev = NULL; 3367 int link_id = _link_id; 3368 3369 if (dev) 3370 wdev = dev->ieee80211_ptr; 3371 if (!nl80211_can_set_dev_channel(wdev)) 3372 return -EOPNOTSUPP; 3373 if (wdev) 3374 iftype = wdev->iftype; 3375 3376 if (link_id < 0) { 3377 if (wdev && wdev->valid_links) 3378 return -EINVAL; 3379 link_id = 0; 3380 } 3381 3382 result = nl80211_parse_chandef(rdev, info, &chandef); 3383 if (result) 3384 return result; 3385 3386 switch (iftype) { 3387 case NL80211_IFTYPE_AP: 3388 case NL80211_IFTYPE_P2P_GO: 3389 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 3390 iftype)) 3391 return -EINVAL; 3392 if (wdev->links[link_id].ap.beacon_interval) { 3393 struct ieee80211_channel *cur_chan; 3394 3395 if (!dev || !rdev->ops->set_ap_chanwidth || 3396 !(rdev->wiphy.features & 3397 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) 3398 return -EBUSY; 3399 3400 /* Only allow dynamic channel width changes */ 3401 cur_chan = wdev->links[link_id].ap.chandef.chan; 3402 if (chandef.chan != cur_chan) 3403 return -EBUSY; 3404 3405 result = rdev_set_ap_chanwidth(rdev, dev, link_id, 3406 &chandef); 3407 if (result) 3408 return result; 3409 wdev->links[link_id].ap.chandef = chandef; 3410 } else { 3411 wdev->u.ap.preset_chandef = chandef; 3412 } 3413 return 0; 3414 case NL80211_IFTYPE_MESH_POINT: 3415 return cfg80211_set_mesh_channel(rdev, wdev, &chandef); 3416 case NL80211_IFTYPE_MONITOR: 3417 return cfg80211_set_monitor_channel(rdev, &chandef); 3418 default: 3419 break; 3420 } 3421 3422 return -EINVAL; 3423 } 3424 3425 static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) 3426 { 3427 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 3428 int link_id = nl80211_link_id_or_invalid(info->attrs); 3429 struct net_device *netdev = info->user_ptr[1]; 3430 3431 return __nl80211_set_channel(rdev, netdev, info, link_id); 3432 } 3433 3434 static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) 3435 { 3436 struct cfg80211_registered_device *rdev = NULL; 3437 struct net_device *netdev = NULL; 3438 struct wireless_dev *wdev; 3439 int result = 0, rem_txq_params = 0; 3440 struct nlattr *nl_txq_params; 3441 u32 changed; 3442 u8 retry_short = 0, retry_long = 0; 3443 u32 frag_threshold = 0, rts_threshold = 0; 3444 u8 coverage_class = 0; 3445 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; 3446 3447 rtnl_lock(); 3448 /* 3449 * Try to find the wiphy and netdev. Normally this 3450 * function shouldn't need the netdev, but this is 3451 * done for backward compatibility -- previously 3452 * setting the channel was done per wiphy, but now 3453 * it is per netdev. Previous userland like hostapd 3454 * also passed a netdev to set_wiphy, so that it is 3455 * possible to let that go to the right netdev! 3456 */ 3457 3458 if (info->attrs[NL80211_ATTR_IFINDEX]) { 3459 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 3460 3461 netdev = __dev_get_by_index(genl_info_net(info), ifindex); 3462 if (netdev && netdev->ieee80211_ptr) 3463 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); 3464 else 3465 netdev = NULL; 3466 } 3467 3468 if (!netdev) { 3469 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), 3470 info->attrs); 3471 if (IS_ERR(rdev)) { 3472 rtnl_unlock(); 3473 return PTR_ERR(rdev); 3474 } 3475 wdev = NULL; 3476 netdev = NULL; 3477 result = 0; 3478 } else 3479 wdev = netdev->ieee80211_ptr; 3480 3481 wiphy_lock(&rdev->wiphy); 3482 3483 /* 3484 * end workaround code, by now the rdev is available 3485 * and locked, and wdev may or may not be NULL. 3486 */ 3487 3488 if (info->attrs[NL80211_ATTR_WIPHY_NAME]) 3489 result = cfg80211_dev_rename( 3490 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); 3491 rtnl_unlock(); 3492 3493 if (result) 3494 goto out; 3495 3496 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { 3497 struct ieee80211_txq_params txq_params; 3498 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; 3499 3500 if (!rdev->ops->set_txq_params) { 3501 result = -EOPNOTSUPP; 3502 goto out; 3503 } 3504 3505 if (!netdev) { 3506 result = -EINVAL; 3507 goto out; 3508 } 3509 3510 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 3511 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 3512 result = -EINVAL; 3513 goto out; 3514 } 3515 3516 if (!netif_running(netdev)) { 3517 result = -ENETDOWN; 3518 goto out; 3519 } 3520 3521 nla_for_each_nested(nl_txq_params, 3522 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], 3523 rem_txq_params) { 3524 result = nla_parse_nested_deprecated(tb, 3525 NL80211_TXQ_ATTR_MAX, 3526 nl_txq_params, 3527 txq_params_policy, 3528 info->extack); 3529 if (result) 3530 goto out; 3531 result = parse_txq_params(tb, &txq_params); 3532 if (result) 3533 goto out; 3534 3535 txq_params.link_id = 3536 nl80211_link_id_or_invalid(info->attrs); 3537 3538 if (txq_params.link_id >= 0 && 3539 !(netdev->ieee80211_ptr->valid_links & 3540 BIT(txq_params.link_id))) 3541 result = -ENOLINK; 3542 else if (txq_params.link_id >= 0 && 3543 !netdev->ieee80211_ptr->valid_links) 3544 result = -EINVAL; 3545 else 3546 result = rdev_set_txq_params(rdev, netdev, 3547 &txq_params); 3548 if (result) 3549 goto out; 3550 } 3551 } 3552 3553 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 3554 int link_id = nl80211_link_id_or_invalid(info->attrs); 3555 3556 if (wdev) { 3557 result = __nl80211_set_channel( 3558 rdev, 3559 nl80211_can_set_dev_channel(wdev) ? netdev : NULL, 3560 info, link_id); 3561 } else { 3562 result = __nl80211_set_channel(rdev, netdev, info, link_id); 3563 } 3564 3565 if (result) 3566 goto out; 3567 } 3568 3569 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { 3570 struct wireless_dev *txp_wdev = wdev; 3571 enum nl80211_tx_power_setting type; 3572 int idx, mbm = 0; 3573 3574 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) 3575 txp_wdev = NULL; 3576 3577 if (!rdev->ops->set_tx_power) { 3578 result = -EOPNOTSUPP; 3579 goto out; 3580 } 3581 3582 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; 3583 type = nla_get_u32(info->attrs[idx]); 3584 3585 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && 3586 (type != NL80211_TX_POWER_AUTOMATIC)) { 3587 result = -EINVAL; 3588 goto out; 3589 } 3590 3591 if (type != NL80211_TX_POWER_AUTOMATIC) { 3592 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; 3593 mbm = nla_get_u32(info->attrs[idx]); 3594 } 3595 3596 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); 3597 if (result) 3598 goto out; 3599 } 3600 3601 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && 3602 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { 3603 u32 tx_ant, rx_ant; 3604 3605 if ((!rdev->wiphy.available_antennas_tx && 3606 !rdev->wiphy.available_antennas_rx) || 3607 !rdev->ops->set_antenna) { 3608 result = -EOPNOTSUPP; 3609 goto out; 3610 } 3611 3612 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); 3613 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); 3614 3615 /* reject antenna configurations which don't match the 3616 * available antenna masks, except for the "all" mask */ 3617 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || 3618 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { 3619 result = -EINVAL; 3620 goto out; 3621 } 3622 3623 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; 3624 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; 3625 3626 result = rdev_set_antenna(rdev, tx_ant, rx_ant); 3627 if (result) 3628 goto out; 3629 } 3630 3631 changed = 0; 3632 3633 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { 3634 retry_short = nla_get_u8( 3635 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); 3636 3637 changed |= WIPHY_PARAM_RETRY_SHORT; 3638 } 3639 3640 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { 3641 retry_long = nla_get_u8( 3642 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); 3643 3644 changed |= WIPHY_PARAM_RETRY_LONG; 3645 } 3646 3647 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { 3648 frag_threshold = nla_get_u32( 3649 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); 3650 if (frag_threshold < 256) { 3651 result = -EINVAL; 3652 goto out; 3653 } 3654 3655 if (frag_threshold != (u32) -1) { 3656 /* 3657 * Fragments (apart from the last one) are required to 3658 * have even length. Make the fragmentation code 3659 * simpler by stripping LSB should someone try to use 3660 * odd threshold value. 3661 */ 3662 frag_threshold &= ~0x1; 3663 } 3664 changed |= WIPHY_PARAM_FRAG_THRESHOLD; 3665 } 3666 3667 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { 3668 rts_threshold = nla_get_u32( 3669 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); 3670 changed |= WIPHY_PARAM_RTS_THRESHOLD; 3671 } 3672 3673 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { 3674 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3675 result = -EINVAL; 3676 goto out; 3677 } 3678 3679 coverage_class = nla_get_u8( 3680 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); 3681 changed |= WIPHY_PARAM_COVERAGE_CLASS; 3682 } 3683 3684 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { 3685 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { 3686 result = -EOPNOTSUPP; 3687 goto out; 3688 } 3689 3690 changed |= WIPHY_PARAM_DYN_ACK; 3691 } 3692 3693 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { 3694 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3695 NL80211_EXT_FEATURE_TXQS)) { 3696 result = -EOPNOTSUPP; 3697 goto out; 3698 } 3699 txq_limit = nla_get_u32( 3700 info->attrs[NL80211_ATTR_TXQ_LIMIT]); 3701 changed |= WIPHY_PARAM_TXQ_LIMIT; 3702 } 3703 3704 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { 3705 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3706 NL80211_EXT_FEATURE_TXQS)) { 3707 result = -EOPNOTSUPP; 3708 goto out; 3709 } 3710 txq_memory_limit = nla_get_u32( 3711 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); 3712 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; 3713 } 3714 3715 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { 3716 if (!wiphy_ext_feature_isset(&rdev->wiphy, 3717 NL80211_EXT_FEATURE_TXQS)) { 3718 result = -EOPNOTSUPP; 3719 goto out; 3720 } 3721 txq_quantum = nla_get_u32( 3722 info->attrs[NL80211_ATTR_TXQ_QUANTUM]); 3723 changed |= WIPHY_PARAM_TXQ_QUANTUM; 3724 } 3725 3726 if (changed) { 3727 u8 old_retry_short, old_retry_long; 3728 u32 old_frag_threshold, old_rts_threshold; 3729 u8 old_coverage_class; 3730 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; 3731 3732 if (!rdev->ops->set_wiphy_params) { 3733 result = -EOPNOTSUPP; 3734 goto out; 3735 } 3736 3737 old_retry_short = rdev->wiphy.retry_short; 3738 old_retry_long = rdev->wiphy.retry_long; 3739 old_frag_threshold = rdev->wiphy.frag_threshold; 3740 old_rts_threshold = rdev->wiphy.rts_threshold; 3741 old_coverage_class = rdev->wiphy.coverage_class; 3742 old_txq_limit = rdev->wiphy.txq_limit; 3743 old_txq_memory_limit = rdev->wiphy.txq_memory_limit; 3744 old_txq_quantum = rdev->wiphy.txq_quantum; 3745 3746 if (changed & WIPHY_PARAM_RETRY_SHORT) 3747 rdev->wiphy.retry_short = retry_short; 3748 if (changed & WIPHY_PARAM_RETRY_LONG) 3749 rdev->wiphy.retry_long = retry_long; 3750 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) 3751 rdev->wiphy.frag_threshold = frag_threshold; 3752 if (changed & WIPHY_PARAM_RTS_THRESHOLD) 3753 rdev->wiphy.rts_threshold = rts_threshold; 3754 if (changed & WIPHY_PARAM_COVERAGE_CLASS) 3755 rdev->wiphy.coverage_class = coverage_class; 3756 if (changed & WIPHY_PARAM_TXQ_LIMIT) 3757 rdev->wiphy.txq_limit = txq_limit; 3758 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) 3759 rdev->wiphy.txq_memory_limit = txq_memory_limit; 3760 if (changed & WIPHY_PARAM_TXQ_QUANTUM) 3761 rdev->wiphy.txq_quantum = txq_quantum; 3762 3763 result = rdev_set_wiphy_params(rdev, changed); 3764 if (result) { 3765 rdev->wiphy.retry_short = old_retry_short; 3766 rdev->wiphy.retry_long = old_retry_long; 3767 rdev->wiphy.frag_threshold = old_frag_threshold; 3768 rdev->wiphy.rts_threshold = old_rts_threshold; 3769 rdev->wiphy.coverage_class = old_coverage_class; 3770 rdev->wiphy.txq_limit = old_txq_limit; 3771 rdev->wiphy.txq_memory_limit = old_txq_memory_limit; 3772 rdev->wiphy.txq_quantum = old_txq_quantum; 3773 goto out; 3774 } 3775 } 3776 3777 result = 0; 3778 3779 out: 3780 wiphy_unlock(&rdev->wiphy); 3781 return result; 3782 } 3783 3784 int nl80211_send_chandef(struct sk_buff *msg, const struct cfg80211_chan_def *chandef) 3785 { 3786 if (WARN_ON(!cfg80211_chandef_valid(chandef))) 3787 return -EINVAL; 3788 3789 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 3790 chandef->chan->center_freq)) 3791 return -ENOBUFS; 3792 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 3793 chandef->chan->freq_offset)) 3794 return -ENOBUFS; 3795 switch (chandef->width) { 3796 case NL80211_CHAN_WIDTH_20_NOHT: 3797 case NL80211_CHAN_WIDTH_20: 3798 case NL80211_CHAN_WIDTH_40: 3799 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 3800 cfg80211_get_chandef_type(chandef))) 3801 return -ENOBUFS; 3802 break; 3803 default: 3804 break; 3805 } 3806 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) 3807 return -ENOBUFS; 3808 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) 3809 return -ENOBUFS; 3810 if (chandef->center_freq2 && 3811 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) 3812 return -ENOBUFS; 3813 return 0; 3814 } 3815 EXPORT_SYMBOL(nl80211_send_chandef); 3816 3817 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, 3818 struct cfg80211_registered_device *rdev, 3819 struct wireless_dev *wdev, 3820 enum nl80211_commands cmd) 3821 { 3822 struct net_device *dev = wdev->netdev; 3823 void *hdr; 3824 3825 lockdep_assert_wiphy(&rdev->wiphy); 3826 3827 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && 3828 cmd != NL80211_CMD_DEL_INTERFACE && 3829 cmd != NL80211_CMD_SET_INTERFACE); 3830 3831 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 3832 if (!hdr) 3833 return -1; 3834 3835 if (dev && 3836 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 3837 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) 3838 goto nla_put_failure; 3839 3840 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 3841 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || 3842 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 3843 NL80211_ATTR_PAD) || 3844 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || 3845 nla_put_u32(msg, NL80211_ATTR_GENERATION, 3846 rdev->devlist_generation ^ 3847 (cfg80211_rdev_list_generation << 2)) || 3848 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) 3849 goto nla_put_failure; 3850 3851 if (rdev->ops->get_channel && !wdev->valid_links) { 3852 struct cfg80211_chan_def chandef = {}; 3853 int ret; 3854 3855 ret = rdev_get_channel(rdev, wdev, 0, &chandef); 3856 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3857 goto nla_put_failure; 3858 } 3859 3860 if (rdev->ops->get_tx_power) { 3861 int dbm, ret; 3862 3863 ret = rdev_get_tx_power(rdev, wdev, &dbm); 3864 if (ret == 0 && 3865 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, 3866 DBM_TO_MBM(dbm))) 3867 goto nla_put_failure; 3868 } 3869 3870 switch (wdev->iftype) { 3871 case NL80211_IFTYPE_AP: 3872 case NL80211_IFTYPE_P2P_GO: 3873 if (wdev->u.ap.ssid_len && 3874 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, 3875 wdev->u.ap.ssid)) 3876 goto nla_put_failure; 3877 break; 3878 case NL80211_IFTYPE_STATION: 3879 case NL80211_IFTYPE_P2P_CLIENT: 3880 if (wdev->u.client.ssid_len && 3881 nla_put(msg, NL80211_ATTR_SSID, wdev->u.client.ssid_len, 3882 wdev->u.client.ssid)) 3883 goto nla_put_failure; 3884 break; 3885 case NL80211_IFTYPE_ADHOC: 3886 if (wdev->u.ibss.ssid_len && 3887 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ibss.ssid_len, 3888 wdev->u.ibss.ssid)) 3889 goto nla_put_failure; 3890 break; 3891 default: 3892 /* nothing */ 3893 break; 3894 } 3895 3896 if (rdev->ops->get_txq_stats) { 3897 struct cfg80211_txq_stats txqstats = {}; 3898 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); 3899 3900 if (ret == 0 && 3901 !nl80211_put_txq_stats(msg, &txqstats, 3902 NL80211_ATTR_TXQ_STATS)) 3903 goto nla_put_failure; 3904 } 3905 3906 if (wdev->valid_links) { 3907 unsigned int link_id; 3908 struct nlattr *links = nla_nest_start(msg, 3909 NL80211_ATTR_MLO_LINKS); 3910 3911 if (!links) 3912 goto nla_put_failure; 3913 3914 for_each_valid_link(wdev, link_id) { 3915 struct nlattr *link = nla_nest_start(msg, link_id + 1); 3916 struct cfg80211_chan_def chandef = {}; 3917 int ret; 3918 3919 if (!link) 3920 goto nla_put_failure; 3921 3922 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 3923 goto nla_put_failure; 3924 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 3925 wdev->links[link_id].addr)) 3926 goto nla_put_failure; 3927 3928 ret = rdev_get_channel(rdev, wdev, link_id, &chandef); 3929 if (ret == 0 && nl80211_send_chandef(msg, &chandef)) 3930 goto nla_put_failure; 3931 3932 nla_nest_end(msg, link); 3933 } 3934 3935 nla_nest_end(msg, links); 3936 } 3937 3938 genlmsg_end(msg, hdr); 3939 return 0; 3940 3941 nla_put_failure: 3942 genlmsg_cancel(msg, hdr); 3943 return -EMSGSIZE; 3944 } 3945 3946 static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) 3947 { 3948 int wp_idx = 0; 3949 int if_idx = 0; 3950 int wp_start = cb->args[0]; 3951 int if_start = cb->args[1]; 3952 int filter_wiphy = -1; 3953 struct cfg80211_registered_device *rdev; 3954 struct wireless_dev *wdev; 3955 int ret; 3956 3957 rtnl_lock(); 3958 if (!cb->args[2]) { 3959 struct nl80211_dump_wiphy_state state = { 3960 .filter_wiphy = -1, 3961 }; 3962 3963 ret = nl80211_dump_wiphy_parse(skb, cb, &state); 3964 if (ret) 3965 goto out_unlock; 3966 3967 filter_wiphy = state.filter_wiphy; 3968 3969 /* 3970 * if filtering, set cb->args[2] to +1 since 0 is the default 3971 * value needed to determine that parsing is necessary. 3972 */ 3973 if (filter_wiphy >= 0) 3974 cb->args[2] = filter_wiphy + 1; 3975 else 3976 cb->args[2] = -1; 3977 } else if (cb->args[2] > 0) { 3978 filter_wiphy = cb->args[2] - 1; 3979 } 3980 3981 for_each_rdev(rdev) { 3982 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) 3983 continue; 3984 if (wp_idx < wp_start) { 3985 wp_idx++; 3986 continue; 3987 } 3988 3989 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) 3990 continue; 3991 3992 if_idx = 0; 3993 3994 wiphy_lock(&rdev->wiphy); 3995 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 3996 if (if_idx < if_start) { 3997 if_idx++; 3998 continue; 3999 } 4000 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, 4001 cb->nlh->nlmsg_seq, NLM_F_MULTI, 4002 rdev, wdev, 4003 NL80211_CMD_NEW_INTERFACE) < 0) { 4004 wiphy_unlock(&rdev->wiphy); 4005 goto out; 4006 } 4007 if_idx++; 4008 } 4009 wiphy_unlock(&rdev->wiphy); 4010 4011 wp_idx++; 4012 } 4013 out: 4014 cb->args[0] = wp_idx; 4015 cb->args[1] = if_idx; 4016 4017 ret = skb->len; 4018 out_unlock: 4019 rtnl_unlock(); 4020 4021 return ret; 4022 } 4023 4024 static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) 4025 { 4026 struct sk_buff *msg; 4027 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4028 struct wireless_dev *wdev = info->user_ptr[1]; 4029 4030 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4031 if (!msg) 4032 return -ENOMEM; 4033 4034 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4035 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4036 nlmsg_free(msg); 4037 return -ENOBUFS; 4038 } 4039 4040 return genlmsg_reply(msg, info); 4041 } 4042 4043 static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { 4044 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, 4045 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, 4046 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, 4047 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, 4048 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, 4049 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, 4050 }; 4051 4052 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) 4053 { 4054 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; 4055 int flag; 4056 4057 *mntrflags = 0; 4058 4059 if (!nla) 4060 return -EINVAL; 4061 4062 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) 4063 return -EINVAL; 4064 4065 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) 4066 if (flags[flag]) 4067 *mntrflags |= (1<<flag); 4068 4069 *mntrflags |= MONITOR_FLAG_CHANGED; 4070 4071 return 0; 4072 } 4073 4074 static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, 4075 enum nl80211_iftype type, 4076 struct genl_info *info, 4077 struct vif_params *params) 4078 { 4079 bool change = false; 4080 int err; 4081 4082 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 4083 if (type != NL80211_IFTYPE_MONITOR) 4084 return -EINVAL; 4085 4086 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], 4087 ¶ms->flags); 4088 if (err) 4089 return err; 4090 4091 change = true; 4092 } 4093 4094 if (params->flags & MONITOR_FLAG_ACTIVE && 4095 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) 4096 return -EOPNOTSUPP; 4097 4098 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { 4099 const u8 *mumimo_groups; 4100 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4101 4102 if (type != NL80211_IFTYPE_MONITOR) 4103 return -EINVAL; 4104 4105 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4106 return -EOPNOTSUPP; 4107 4108 mumimo_groups = 4109 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); 4110 4111 /* bits 0 and 63 are reserved and must be zero */ 4112 if ((mumimo_groups[0] & BIT(0)) || 4113 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) 4114 return -EINVAL; 4115 4116 params->vht_mumimo_groups = mumimo_groups; 4117 change = true; 4118 } 4119 4120 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { 4121 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; 4122 4123 if (type != NL80211_IFTYPE_MONITOR) 4124 return -EINVAL; 4125 4126 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) 4127 return -EOPNOTSUPP; 4128 4129 params->vht_mumimo_follow_addr = 4130 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); 4131 change = true; 4132 } 4133 4134 return change ? 1 : 0; 4135 } 4136 4137 static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, 4138 struct net_device *netdev, u8 use_4addr, 4139 enum nl80211_iftype iftype) 4140 { 4141 if (!use_4addr) { 4142 if (netdev && netif_is_bridge_port(netdev)) 4143 return -EBUSY; 4144 return 0; 4145 } 4146 4147 switch (iftype) { 4148 case NL80211_IFTYPE_AP_VLAN: 4149 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) 4150 return 0; 4151 break; 4152 case NL80211_IFTYPE_STATION: 4153 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) 4154 return 0; 4155 break; 4156 default: 4157 break; 4158 } 4159 4160 return -EOPNOTSUPP; 4161 } 4162 4163 static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) 4164 { 4165 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4166 struct vif_params params; 4167 int err; 4168 enum nl80211_iftype otype, ntype; 4169 struct net_device *dev = info->user_ptr[1]; 4170 bool change = false; 4171 4172 memset(¶ms, 0, sizeof(params)); 4173 4174 otype = ntype = dev->ieee80211_ptr->iftype; 4175 4176 if (info->attrs[NL80211_ATTR_IFTYPE]) { 4177 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4178 if (otype != ntype) 4179 change = true; 4180 } 4181 4182 if (info->attrs[NL80211_ATTR_MESH_ID]) { 4183 struct wireless_dev *wdev = dev->ieee80211_ptr; 4184 4185 if (ntype != NL80211_IFTYPE_MESH_POINT) 4186 return -EINVAL; 4187 if (netif_running(dev)) 4188 return -EBUSY; 4189 4190 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4191 IEEE80211_MAX_MESH_ID_LEN); 4192 wdev->u.mesh.id_up_len = 4193 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4194 memcpy(wdev->u.mesh.id, 4195 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4196 wdev->u.mesh.id_up_len); 4197 } 4198 4199 if (info->attrs[NL80211_ATTR_4ADDR]) { 4200 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4201 change = true; 4202 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); 4203 if (err) 4204 return err; 4205 } else { 4206 params.use_4addr = -1; 4207 } 4208 4209 err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); 4210 if (err < 0) 4211 return err; 4212 if (err > 0) 4213 change = true; 4214 4215 if (change) 4216 err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); 4217 else 4218 err = 0; 4219 4220 if (!err && params.use_4addr != -1) 4221 dev->ieee80211_ptr->use_4addr = params.use_4addr; 4222 4223 if (change && !err) { 4224 struct wireless_dev *wdev = dev->ieee80211_ptr; 4225 4226 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); 4227 } 4228 4229 return err; 4230 } 4231 4232 static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4233 { 4234 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4235 struct vif_params params; 4236 struct wireless_dev *wdev; 4237 struct sk_buff *msg; 4238 int err; 4239 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 4240 4241 memset(¶ms, 0, sizeof(params)); 4242 4243 if (!info->attrs[NL80211_ATTR_IFNAME]) 4244 return -EINVAL; 4245 4246 if (info->attrs[NL80211_ATTR_IFTYPE]) 4247 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 4248 4249 if (!rdev->ops->add_virtual_intf) 4250 return -EOPNOTSUPP; 4251 4252 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || 4253 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && 4254 info->attrs[NL80211_ATTR_MAC]) { 4255 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], 4256 ETH_ALEN); 4257 if (!is_valid_ether_addr(params.macaddr)) 4258 return -EADDRNOTAVAIL; 4259 } 4260 4261 if (info->attrs[NL80211_ATTR_4ADDR]) { 4262 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 4263 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 4264 if (err) 4265 return err; 4266 } 4267 4268 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) 4269 return -EOPNOTSUPP; 4270 4271 err = nl80211_parse_mon_options(rdev, type, info, ¶ms); 4272 if (err < 0) 4273 return err; 4274 4275 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4276 if (!msg) 4277 return -ENOMEM; 4278 4279 wdev = rdev_add_virtual_intf(rdev, 4280 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 4281 NET_NAME_USER, type, ¶ms); 4282 if (WARN_ON(!wdev)) { 4283 nlmsg_free(msg); 4284 return -EPROTO; 4285 } else if (IS_ERR(wdev)) { 4286 nlmsg_free(msg); 4287 return PTR_ERR(wdev); 4288 } 4289 4290 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 4291 wdev->owner_nlportid = info->snd_portid; 4292 4293 switch (type) { 4294 case NL80211_IFTYPE_MESH_POINT: 4295 if (!info->attrs[NL80211_ATTR_MESH_ID]) 4296 break; 4297 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != 4298 IEEE80211_MAX_MESH_ID_LEN); 4299 wdev->u.mesh.id_up_len = 4300 nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 4301 memcpy(wdev->u.mesh.id, 4302 nla_data(info->attrs[NL80211_ATTR_MESH_ID]), 4303 wdev->u.mesh.id_up_len); 4304 break; 4305 case NL80211_IFTYPE_NAN: 4306 case NL80211_IFTYPE_P2P_DEVICE: 4307 /* 4308 * P2P Device and NAN do not have a netdev, so don't go 4309 * through the netdev notifier and must be added here 4310 */ 4311 cfg80211_init_wdev(wdev); 4312 cfg80211_register_wdev(rdev, wdev); 4313 break; 4314 default: 4315 break; 4316 } 4317 4318 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, 4319 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { 4320 nlmsg_free(msg); 4321 return -ENOBUFS; 4322 } 4323 4324 return genlmsg_reply(msg, info); 4325 } 4326 4327 static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) 4328 { 4329 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4330 int ret; 4331 4332 /* to avoid failing a new interface creation due to pending removal */ 4333 cfg80211_destroy_ifaces(rdev); 4334 4335 wiphy_lock(&rdev->wiphy); 4336 ret = _nl80211_new_interface(skb, info); 4337 wiphy_unlock(&rdev->wiphy); 4338 4339 return ret; 4340 } 4341 4342 static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 4343 { 4344 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4345 struct wireless_dev *wdev = info->user_ptr[1]; 4346 4347 if (!rdev->ops->del_virtual_intf) 4348 return -EOPNOTSUPP; 4349 4350 /* 4351 * We hold RTNL, so this is safe, without RTNL opencount cannot 4352 * reach 0, and thus the rdev cannot be deleted. 4353 * 4354 * We need to do it for the dev_close(), since that will call 4355 * the netdev notifiers, and we need to acquire the mutex there 4356 * but don't know if we get there from here or from some other 4357 * place (e.g. "ip link set ... down"). 4358 */ 4359 mutex_unlock(&rdev->wiphy.mtx); 4360 4361 /* 4362 * If we remove a wireless device without a netdev then clear 4363 * user_ptr[1] so that nl80211_post_doit won't dereference it 4364 * to check if it needs to do dev_put(). Otherwise it crashes 4365 * since the wdev has been freed, unlike with a netdev where 4366 * we need the dev_put() for the netdev to really be freed. 4367 */ 4368 if (!wdev->netdev) 4369 info->user_ptr[1] = NULL; 4370 else 4371 dev_close(wdev->netdev); 4372 4373 mutex_lock(&rdev->wiphy.mtx); 4374 4375 return cfg80211_remove_virtual_intf(rdev, wdev); 4376 } 4377 4378 static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) 4379 { 4380 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4381 struct net_device *dev = info->user_ptr[1]; 4382 u16 noack_map; 4383 4384 if (!info->attrs[NL80211_ATTR_NOACK_MAP]) 4385 return -EINVAL; 4386 4387 if (!rdev->ops->set_noack_map) 4388 return -EOPNOTSUPP; 4389 4390 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); 4391 4392 return rdev_set_noack_map(rdev, dev, noack_map); 4393 } 4394 4395 static int nl80211_validate_key_link_id(struct genl_info *info, 4396 struct wireless_dev *wdev, 4397 int link_id, bool pairwise) 4398 { 4399 if (pairwise) { 4400 if (link_id != -1) { 4401 GENL_SET_ERR_MSG(info, 4402 "link ID not allowed for pairwise key"); 4403 return -EINVAL; 4404 } 4405 4406 return 0; 4407 } 4408 4409 if (wdev->valid_links) { 4410 if (link_id == -1) { 4411 GENL_SET_ERR_MSG(info, 4412 "link ID must for MLO group key"); 4413 return -EINVAL; 4414 } 4415 if (!(wdev->valid_links & BIT(link_id))) { 4416 GENL_SET_ERR_MSG(info, "invalid link ID for MLO group key"); 4417 return -EINVAL; 4418 } 4419 } else if (link_id != -1) { 4420 GENL_SET_ERR_MSG(info, "link ID not allowed for non-MLO group key"); 4421 return -EINVAL; 4422 } 4423 4424 return 0; 4425 } 4426 4427 struct get_key_cookie { 4428 struct sk_buff *msg; 4429 int error; 4430 int idx; 4431 }; 4432 4433 static void get_key_callback(void *c, struct key_params *params) 4434 { 4435 struct nlattr *key; 4436 struct get_key_cookie *cookie = c; 4437 4438 if ((params->key && 4439 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, 4440 params->key_len, params->key)) || 4441 (params->seq && 4442 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, 4443 params->seq_len, params->seq)) || 4444 (params->cipher && 4445 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, 4446 params->cipher))) 4447 goto nla_put_failure; 4448 4449 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); 4450 if (!key) 4451 goto nla_put_failure; 4452 4453 if ((params->key && 4454 nla_put(cookie->msg, NL80211_KEY_DATA, 4455 params->key_len, params->key)) || 4456 (params->seq && 4457 nla_put(cookie->msg, NL80211_KEY_SEQ, 4458 params->seq_len, params->seq)) || 4459 (params->cipher && 4460 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, 4461 params->cipher))) 4462 goto nla_put_failure; 4463 4464 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) 4465 goto nla_put_failure; 4466 4467 nla_nest_end(cookie->msg, key); 4468 4469 return; 4470 nla_put_failure: 4471 cookie->error = 1; 4472 } 4473 4474 static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) 4475 { 4476 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4477 int err; 4478 struct net_device *dev = info->user_ptr[1]; 4479 u8 key_idx = 0; 4480 const u8 *mac_addr = NULL; 4481 bool pairwise; 4482 struct get_key_cookie cookie = { 4483 .error = 0, 4484 }; 4485 void *hdr; 4486 struct sk_buff *msg; 4487 bool bigtk_support = false; 4488 int link_id = nl80211_link_id_or_invalid(info->attrs); 4489 struct wireless_dev *wdev = dev->ieee80211_ptr; 4490 4491 if (wiphy_ext_feature_isset(&rdev->wiphy, 4492 NL80211_EXT_FEATURE_BEACON_PROTECTION)) 4493 bigtk_support = true; 4494 4495 if ((wdev->iftype == NL80211_IFTYPE_STATION || 4496 wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) && 4497 wiphy_ext_feature_isset(&rdev->wiphy, 4498 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) 4499 bigtk_support = true; 4500 4501 if (info->attrs[NL80211_ATTR_KEY_IDX]) { 4502 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); 4503 4504 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { 4505 GENL_SET_ERR_MSG(info, "BIGTK not supported"); 4506 return -EINVAL; 4507 } 4508 } 4509 4510 if (info->attrs[NL80211_ATTR_MAC]) 4511 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4512 4513 pairwise = !!mac_addr; 4514 if (info->attrs[NL80211_ATTR_KEY_TYPE]) { 4515 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); 4516 4517 if (kt != NL80211_KEYTYPE_GROUP && 4518 kt != NL80211_KEYTYPE_PAIRWISE) 4519 return -EINVAL; 4520 pairwise = kt == NL80211_KEYTYPE_PAIRWISE; 4521 } 4522 4523 if (!rdev->ops->get_key) 4524 return -EOPNOTSUPP; 4525 4526 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4527 return -ENOENT; 4528 4529 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 4530 if (!msg) 4531 return -ENOMEM; 4532 4533 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 4534 NL80211_CMD_NEW_KEY); 4535 if (!hdr) 4536 goto nla_put_failure; 4537 4538 cookie.msg = msg; 4539 cookie.idx = key_idx; 4540 4541 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 4542 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) 4543 goto nla_put_failure; 4544 if (mac_addr && 4545 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) 4546 goto nla_put_failure; 4547 4548 err = nl80211_validate_key_link_id(info, wdev, link_id, pairwise); 4549 if (err) 4550 goto free_msg; 4551 4552 err = rdev_get_key(rdev, dev, link_id, key_idx, pairwise, mac_addr, 4553 &cookie, get_key_callback); 4554 4555 if (err) 4556 goto free_msg; 4557 4558 if (cookie.error) 4559 goto nla_put_failure; 4560 4561 genlmsg_end(msg, hdr); 4562 return genlmsg_reply(msg, info); 4563 4564 nla_put_failure: 4565 err = -ENOBUFS; 4566 free_msg: 4567 nlmsg_free(msg); 4568 return err; 4569 } 4570 4571 static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) 4572 { 4573 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4574 struct key_parse key; 4575 int err; 4576 struct net_device *dev = info->user_ptr[1]; 4577 int link_id = nl80211_link_id_or_invalid(info->attrs); 4578 struct wireless_dev *wdev = dev->ieee80211_ptr; 4579 4580 err = nl80211_parse_key(info, &key); 4581 if (err) 4582 return err; 4583 4584 if (key.idx < 0) 4585 return -EINVAL; 4586 4587 /* Only support setting default key and 4588 * Extended Key ID action NL80211_KEY_SET_TX. 4589 */ 4590 if (!key.def && !key.defmgmt && !key.defbeacon && 4591 !(key.p.mode == NL80211_KEY_SET_TX)) 4592 return -EINVAL; 4593 4594 if (key.def) { 4595 if (!rdev->ops->set_default_key) 4596 return -EOPNOTSUPP; 4597 4598 err = nl80211_key_allowed(wdev); 4599 if (err) 4600 return err; 4601 4602 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4603 if (err) 4604 return err; 4605 4606 err = rdev_set_default_key(rdev, dev, link_id, key.idx, 4607 key.def_uni, key.def_multi); 4608 4609 if (err) 4610 return err; 4611 4612 #ifdef CONFIG_CFG80211_WEXT 4613 wdev->wext.default_key = key.idx; 4614 #endif 4615 return 0; 4616 } else if (key.defmgmt) { 4617 if (key.def_uni || !key.def_multi) 4618 return -EINVAL; 4619 4620 if (!rdev->ops->set_default_mgmt_key) 4621 return -EOPNOTSUPP; 4622 4623 err = nl80211_key_allowed(wdev); 4624 if (err) 4625 return err; 4626 4627 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4628 if (err) 4629 return err; 4630 4631 err = rdev_set_default_mgmt_key(rdev, dev, link_id, key.idx); 4632 if (err) 4633 return err; 4634 4635 #ifdef CONFIG_CFG80211_WEXT 4636 wdev->wext.default_mgmt_key = key.idx; 4637 #endif 4638 return 0; 4639 } else if (key.defbeacon) { 4640 if (key.def_uni || !key.def_multi) 4641 return -EINVAL; 4642 4643 if (!rdev->ops->set_default_beacon_key) 4644 return -EOPNOTSUPP; 4645 4646 err = nl80211_key_allowed(wdev); 4647 if (err) 4648 return err; 4649 4650 err = nl80211_validate_key_link_id(info, wdev, link_id, false); 4651 if (err) 4652 return err; 4653 4654 return rdev_set_default_beacon_key(rdev, dev, link_id, key.idx); 4655 } else if (key.p.mode == NL80211_KEY_SET_TX && 4656 wiphy_ext_feature_isset(&rdev->wiphy, 4657 NL80211_EXT_FEATURE_EXT_KEY_ID)) { 4658 u8 *mac_addr = NULL; 4659 4660 if (info->attrs[NL80211_ATTR_MAC]) 4661 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4662 4663 if (!mac_addr || key.idx < 0 || key.idx > 1) 4664 return -EINVAL; 4665 4666 err = nl80211_validate_key_link_id(info, wdev, link_id, true); 4667 if (err) 4668 return err; 4669 4670 return rdev_add_key(rdev, dev, link_id, key.idx, 4671 NL80211_KEYTYPE_PAIRWISE, 4672 mac_addr, &key.p); 4673 } 4674 4675 return -EINVAL; 4676 } 4677 4678 static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 4679 { 4680 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4681 int err; 4682 struct net_device *dev = info->user_ptr[1]; 4683 struct key_parse key; 4684 const u8 *mac_addr = NULL; 4685 int link_id = nl80211_link_id_or_invalid(info->attrs); 4686 struct wireless_dev *wdev = dev->ieee80211_ptr; 4687 4688 err = nl80211_parse_key(info, &key); 4689 if (err) 4690 return err; 4691 4692 if (!key.p.key) { 4693 GENL_SET_ERR_MSG(info, "no key"); 4694 return -EINVAL; 4695 } 4696 4697 if (info->attrs[NL80211_ATTR_MAC]) 4698 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4699 4700 if (key.type == -1) { 4701 if (mac_addr) 4702 key.type = NL80211_KEYTYPE_PAIRWISE; 4703 else 4704 key.type = NL80211_KEYTYPE_GROUP; 4705 } 4706 4707 /* for now */ 4708 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4709 key.type != NL80211_KEYTYPE_GROUP) { 4710 GENL_SET_ERR_MSG(info, "key type not pairwise or group"); 4711 return -EINVAL; 4712 } 4713 4714 if (key.type == NL80211_KEYTYPE_GROUP && 4715 info->attrs[NL80211_ATTR_VLAN_ID]) 4716 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 4717 4718 if (!rdev->ops->add_key) 4719 return -EOPNOTSUPP; 4720 4721 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, 4722 key.type == NL80211_KEYTYPE_PAIRWISE, 4723 mac_addr)) { 4724 GENL_SET_ERR_MSG(info, "key setting validation failed"); 4725 return -EINVAL; 4726 } 4727 4728 err = nl80211_key_allowed(wdev); 4729 if (err) 4730 GENL_SET_ERR_MSG(info, "key not allowed"); 4731 4732 if (!err) 4733 err = nl80211_validate_key_link_id(info, wdev, link_id, 4734 key.type == NL80211_KEYTYPE_PAIRWISE); 4735 4736 if (!err) { 4737 err = rdev_add_key(rdev, dev, link_id, key.idx, 4738 key.type == NL80211_KEYTYPE_PAIRWISE, 4739 mac_addr, &key.p); 4740 if (err) 4741 GENL_SET_ERR_MSG(info, "key addition failed"); 4742 } 4743 4744 return err; 4745 } 4746 4747 static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) 4748 { 4749 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4750 int err; 4751 struct net_device *dev = info->user_ptr[1]; 4752 u8 *mac_addr = NULL; 4753 struct key_parse key; 4754 int link_id = nl80211_link_id_or_invalid(info->attrs); 4755 struct wireless_dev *wdev = dev->ieee80211_ptr; 4756 4757 err = nl80211_parse_key(info, &key); 4758 if (err) 4759 return err; 4760 4761 if (info->attrs[NL80211_ATTR_MAC]) 4762 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 4763 4764 if (key.type == -1) { 4765 if (mac_addr) 4766 key.type = NL80211_KEYTYPE_PAIRWISE; 4767 else 4768 key.type = NL80211_KEYTYPE_GROUP; 4769 } 4770 4771 /* for now */ 4772 if (key.type != NL80211_KEYTYPE_PAIRWISE && 4773 key.type != NL80211_KEYTYPE_GROUP) 4774 return -EINVAL; 4775 4776 if (!cfg80211_valid_key_idx(rdev, key.idx, 4777 key.type == NL80211_KEYTYPE_PAIRWISE)) 4778 return -EINVAL; 4779 4780 if (!rdev->ops->del_key) 4781 return -EOPNOTSUPP; 4782 4783 err = nl80211_key_allowed(wdev); 4784 4785 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && 4786 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) 4787 err = -ENOENT; 4788 4789 if (!err) 4790 err = nl80211_validate_key_link_id(info, wdev, link_id, 4791 key.type == NL80211_KEYTYPE_PAIRWISE); 4792 4793 if (!err) 4794 err = rdev_del_key(rdev, dev, link_id, key.idx, 4795 key.type == NL80211_KEYTYPE_PAIRWISE, 4796 mac_addr); 4797 4798 #ifdef CONFIG_CFG80211_WEXT 4799 if (!err) { 4800 if (key.idx == wdev->wext.default_key) 4801 wdev->wext.default_key = -1; 4802 else if (key.idx == wdev->wext.default_mgmt_key) 4803 wdev->wext.default_mgmt_key = -1; 4804 } 4805 #endif 4806 4807 return err; 4808 } 4809 4810 /* This function returns an error or the number of nested attributes */ 4811 static int validate_acl_mac_addrs(struct nlattr *nl_attr) 4812 { 4813 struct nlattr *attr; 4814 int n_entries = 0, tmp; 4815 4816 nla_for_each_nested(attr, nl_attr, tmp) { 4817 if (nla_len(attr) != ETH_ALEN) 4818 return -EINVAL; 4819 4820 n_entries++; 4821 } 4822 4823 return n_entries; 4824 } 4825 4826 /* 4827 * This function parses ACL information and allocates memory for ACL data. 4828 * On successful return, the calling function is responsible to free the 4829 * ACL buffer returned by this function. 4830 */ 4831 static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, 4832 struct genl_info *info) 4833 { 4834 enum nl80211_acl_policy acl_policy; 4835 struct nlattr *attr; 4836 struct cfg80211_acl_data *acl; 4837 int i = 0, n_entries, tmp; 4838 4839 if (!wiphy->max_acl_mac_addrs) 4840 return ERR_PTR(-EOPNOTSUPP); 4841 4842 if (!info->attrs[NL80211_ATTR_ACL_POLICY]) 4843 return ERR_PTR(-EINVAL); 4844 4845 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); 4846 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && 4847 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) 4848 return ERR_PTR(-EINVAL); 4849 4850 if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) 4851 return ERR_PTR(-EINVAL); 4852 4853 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); 4854 if (n_entries < 0) 4855 return ERR_PTR(n_entries); 4856 4857 if (n_entries > wiphy->max_acl_mac_addrs) 4858 return ERR_PTR(-ENOTSUPP); 4859 4860 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); 4861 if (!acl) 4862 return ERR_PTR(-ENOMEM); 4863 acl->n_acl_entries = n_entries; 4864 4865 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { 4866 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); 4867 i++; 4868 } 4869 acl->acl_policy = acl_policy; 4870 4871 return acl; 4872 } 4873 4874 static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) 4875 { 4876 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 4877 struct net_device *dev = info->user_ptr[1]; 4878 struct cfg80211_acl_data *acl; 4879 int err; 4880 4881 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 4882 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 4883 return -EOPNOTSUPP; 4884 4885 if (!dev->ieee80211_ptr->links[0].ap.beacon_interval) 4886 return -EINVAL; 4887 4888 acl = parse_acl_data(&rdev->wiphy, info); 4889 if (IS_ERR(acl)) 4890 return PTR_ERR(acl); 4891 4892 err = rdev_set_mac_acl(rdev, dev, acl); 4893 4894 kfree(acl); 4895 4896 return err; 4897 } 4898 4899 static u32 rateset_to_mask(struct ieee80211_supported_band *sband, 4900 u8 *rates, u8 rates_len) 4901 { 4902 u8 i; 4903 u32 mask = 0; 4904 4905 for (i = 0; i < rates_len; i++) { 4906 int rate = (rates[i] & 0x7f) * 5; 4907 int ridx; 4908 4909 for (ridx = 0; ridx < sband->n_bitrates; ridx++) { 4910 struct ieee80211_rate *srate = 4911 &sband->bitrates[ridx]; 4912 if (rate == srate->bitrate) { 4913 mask |= 1 << ridx; 4914 break; 4915 } 4916 } 4917 if (ridx == sband->n_bitrates) 4918 return 0; /* rate not found */ 4919 } 4920 4921 return mask; 4922 } 4923 4924 static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, 4925 u8 *rates, u8 rates_len, 4926 u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) 4927 { 4928 u8 i; 4929 4930 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); 4931 4932 for (i = 0; i < rates_len; i++) { 4933 int ridx, rbit; 4934 4935 ridx = rates[i] / 8; 4936 rbit = BIT(rates[i] % 8); 4937 4938 /* check validity */ 4939 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) 4940 return false; 4941 4942 /* check availability */ 4943 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); 4944 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) 4945 mcs[ridx] |= rbit; 4946 else 4947 return false; 4948 } 4949 4950 return true; 4951 } 4952 4953 static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) 4954 { 4955 u16 mcs_mask = 0; 4956 4957 switch (vht_mcs_map) { 4958 case IEEE80211_VHT_MCS_NOT_SUPPORTED: 4959 break; 4960 case IEEE80211_VHT_MCS_SUPPORT_0_7: 4961 mcs_mask = 0x00FF; 4962 break; 4963 case IEEE80211_VHT_MCS_SUPPORT_0_8: 4964 mcs_mask = 0x01FF; 4965 break; 4966 case IEEE80211_VHT_MCS_SUPPORT_0_9: 4967 mcs_mask = 0x03FF; 4968 break; 4969 default: 4970 break; 4971 } 4972 4973 return mcs_mask; 4974 } 4975 4976 static void vht_build_mcs_mask(u16 vht_mcs_map, 4977 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) 4978 { 4979 u8 nss; 4980 4981 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { 4982 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); 4983 vht_mcs_map >>= 2; 4984 } 4985 } 4986 4987 static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, 4988 struct nl80211_txrate_vht *txrate, 4989 u16 mcs[NL80211_VHT_NSS_MAX]) 4990 { 4991 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 4992 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; 4993 u8 i; 4994 4995 if (!sband->vht_cap.vht_supported) 4996 return false; 4997 4998 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); 4999 5000 /* Build vht_mcs_mask from VHT capabilities */ 5001 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 5002 5003 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 5004 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 5005 mcs[i] = txrate->mcs[i]; 5006 else 5007 return false; 5008 } 5009 5010 return true; 5011 } 5012 5013 static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) 5014 { 5015 switch (he_mcs_map) { 5016 case IEEE80211_HE_MCS_NOT_SUPPORTED: 5017 return 0; 5018 case IEEE80211_HE_MCS_SUPPORT_0_7: 5019 return 0x00FF; 5020 case IEEE80211_HE_MCS_SUPPORT_0_9: 5021 return 0x03FF; 5022 case IEEE80211_HE_MCS_SUPPORT_0_11: 5023 return 0xFFF; 5024 default: 5025 break; 5026 } 5027 return 0; 5028 } 5029 5030 static void he_build_mcs_mask(u16 he_mcs_map, 5031 u16 he_mcs_mask[NL80211_HE_NSS_MAX]) 5032 { 5033 u8 nss; 5034 5035 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { 5036 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); 5037 he_mcs_map >>= 2; 5038 } 5039 } 5040 5041 static u16 he_get_txmcsmap(struct genl_info *info, unsigned int link_id, 5042 const struct ieee80211_sta_he_cap *he_cap) 5043 { 5044 struct net_device *dev = info->user_ptr[1]; 5045 struct wireless_dev *wdev = dev->ieee80211_ptr; 5046 struct cfg80211_chan_def *chandef; 5047 __le16 tx_mcs; 5048 5049 chandef = wdev_chandef(wdev, link_id); 5050 if (!chandef) { 5051 /* 5052 * This is probably broken, but we never maintained 5053 * a chandef in these cases, so it always was. 5054 */ 5055 return le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80); 5056 } 5057 5058 switch (chandef->width) { 5059 case NL80211_CHAN_WIDTH_80P80: 5060 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; 5061 break; 5062 case NL80211_CHAN_WIDTH_160: 5063 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; 5064 break; 5065 default: 5066 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; 5067 break; 5068 } 5069 5070 return le16_to_cpu(tx_mcs); 5071 } 5072 5073 static bool he_set_mcs_mask(struct genl_info *info, 5074 struct wireless_dev *wdev, 5075 struct ieee80211_supported_band *sband, 5076 struct nl80211_txrate_he *txrate, 5077 u16 mcs[NL80211_HE_NSS_MAX], 5078 unsigned int link_id) 5079 { 5080 const struct ieee80211_sta_he_cap *he_cap; 5081 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; 5082 u16 tx_mcs_map = 0; 5083 u8 i; 5084 5085 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5086 if (!he_cap) 5087 return false; 5088 5089 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); 5090 5091 tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5092 5093 /* Build he_mcs_mask from HE capabilities */ 5094 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); 5095 5096 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5097 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) 5098 mcs[i] = txrate->mcs[i]; 5099 else 5100 return false; 5101 } 5102 5103 return true; 5104 } 5105 5106 static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, 5107 struct nlattr *attrs[], 5108 enum nl80211_attrs attr, 5109 struct cfg80211_bitrate_mask *mask, 5110 struct net_device *dev, 5111 bool default_all_enabled, 5112 unsigned int link_id) 5113 { 5114 struct nlattr *tb[NL80211_TXRATE_MAX + 1]; 5115 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5116 struct wireless_dev *wdev = dev->ieee80211_ptr; 5117 int rem, i; 5118 struct nlattr *tx_rates; 5119 struct ieee80211_supported_band *sband; 5120 u16 vht_tx_mcs_map, he_tx_mcs_map; 5121 5122 memset(mask, 0, sizeof(*mask)); 5123 /* Default to all rates enabled */ 5124 for (i = 0; i < NUM_NL80211_BANDS; i++) { 5125 const struct ieee80211_sta_he_cap *he_cap; 5126 5127 if (!default_all_enabled) 5128 break; 5129 5130 sband = rdev->wiphy.bands[i]; 5131 5132 if (!sband) 5133 continue; 5134 5135 mask->control[i].legacy = (1 << sband->n_bitrates) - 1; 5136 memcpy(mask->control[i].ht_mcs, 5137 sband->ht_cap.mcs.rx_mask, 5138 sizeof(mask->control[i].ht_mcs)); 5139 5140 if (sband->vht_cap.vht_supported) { 5141 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); 5142 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); 5143 } 5144 5145 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); 5146 if (!he_cap) 5147 continue; 5148 5149 he_tx_mcs_map = he_get_txmcsmap(info, link_id, he_cap); 5150 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); 5151 5152 mask->control[i].he_gi = 0xFF; 5153 mask->control[i].he_ltf = 0xFF; 5154 } 5155 5156 /* if no rates are given set it back to the defaults */ 5157 if (!attrs[attr]) 5158 goto out; 5159 5160 /* The nested attribute uses enum nl80211_band as the index. This maps 5161 * directly to the enum nl80211_band values used in cfg80211. 5162 */ 5163 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); 5164 nla_for_each_nested(tx_rates, attrs[attr], rem) { 5165 enum nl80211_band band = nla_type(tx_rates); 5166 int err; 5167 5168 if (band < 0 || band >= NUM_NL80211_BANDS) 5169 return -EINVAL; 5170 sband = rdev->wiphy.bands[band]; 5171 if (sband == NULL) 5172 return -EINVAL; 5173 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, 5174 tx_rates, 5175 nl80211_txattr_policy, 5176 info->extack); 5177 if (err) 5178 return err; 5179 if (tb[NL80211_TXRATE_LEGACY]) { 5180 mask->control[band].legacy = rateset_to_mask( 5181 sband, 5182 nla_data(tb[NL80211_TXRATE_LEGACY]), 5183 nla_len(tb[NL80211_TXRATE_LEGACY])); 5184 if ((mask->control[band].legacy == 0) && 5185 nla_len(tb[NL80211_TXRATE_LEGACY])) 5186 return -EINVAL; 5187 } 5188 if (tb[NL80211_TXRATE_HT]) { 5189 if (!ht_rateset_to_mask( 5190 sband, 5191 nla_data(tb[NL80211_TXRATE_HT]), 5192 nla_len(tb[NL80211_TXRATE_HT]), 5193 mask->control[band].ht_mcs)) 5194 return -EINVAL; 5195 } 5196 5197 if (tb[NL80211_TXRATE_VHT]) { 5198 if (!vht_set_mcs_mask( 5199 sband, 5200 nla_data(tb[NL80211_TXRATE_VHT]), 5201 mask->control[band].vht_mcs)) 5202 return -EINVAL; 5203 } 5204 5205 if (tb[NL80211_TXRATE_GI]) { 5206 mask->control[band].gi = 5207 nla_get_u8(tb[NL80211_TXRATE_GI]); 5208 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) 5209 return -EINVAL; 5210 } 5211 if (tb[NL80211_TXRATE_HE] && 5212 !he_set_mcs_mask(info, wdev, sband, 5213 nla_data(tb[NL80211_TXRATE_HE]), 5214 mask->control[band].he_mcs, 5215 link_id)) 5216 return -EINVAL; 5217 5218 if (tb[NL80211_TXRATE_HE_GI]) 5219 mask->control[band].he_gi = 5220 nla_get_u8(tb[NL80211_TXRATE_HE_GI]); 5221 if (tb[NL80211_TXRATE_HE_LTF]) 5222 mask->control[band].he_ltf = 5223 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); 5224 5225 if (mask->control[band].legacy == 0) { 5226 /* don't allow empty legacy rates if HT, VHT or HE 5227 * are not even supported. 5228 */ 5229 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || 5230 rdev->wiphy.bands[band]->vht_cap.vht_supported || 5231 ieee80211_get_he_iftype_cap(sband, wdev->iftype))) 5232 return -EINVAL; 5233 5234 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) 5235 if (mask->control[band].ht_mcs[i]) 5236 goto out; 5237 5238 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) 5239 if (mask->control[band].vht_mcs[i]) 5240 goto out; 5241 5242 for (i = 0; i < NL80211_HE_NSS_MAX; i++) 5243 if (mask->control[band].he_mcs[i]) 5244 goto out; 5245 5246 /* legacy and mcs rates may not be both empty */ 5247 return -EINVAL; 5248 } 5249 } 5250 5251 out: 5252 return 0; 5253 } 5254 5255 static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, 5256 enum nl80211_band band, 5257 struct cfg80211_bitrate_mask *beacon_rate) 5258 { 5259 u32 count_ht, count_vht, count_he, i; 5260 u32 rate = beacon_rate->control[band].legacy; 5261 5262 /* Allow only one rate */ 5263 if (hweight32(rate) > 1) 5264 return -EINVAL; 5265 5266 count_ht = 0; 5267 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { 5268 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { 5269 return -EINVAL; 5270 } else if (beacon_rate->control[band].ht_mcs[i]) { 5271 count_ht++; 5272 if (count_ht > 1) 5273 return -EINVAL; 5274 } 5275 if (count_ht && rate) 5276 return -EINVAL; 5277 } 5278 5279 count_vht = 0; 5280 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { 5281 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { 5282 return -EINVAL; 5283 } else if (beacon_rate->control[band].vht_mcs[i]) { 5284 count_vht++; 5285 if (count_vht > 1) 5286 return -EINVAL; 5287 } 5288 if (count_vht && rate) 5289 return -EINVAL; 5290 } 5291 5292 count_he = 0; 5293 for (i = 0; i < NL80211_HE_NSS_MAX; i++) { 5294 if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { 5295 return -EINVAL; 5296 } else if (beacon_rate->control[band].he_mcs[i]) { 5297 count_he++; 5298 if (count_he > 1) 5299 return -EINVAL; 5300 } 5301 if (count_he && rate) 5302 return -EINVAL; 5303 } 5304 5305 if ((count_ht && count_vht && count_he) || 5306 (!rate && !count_ht && !count_vht && !count_he)) 5307 return -EINVAL; 5308 5309 if (rate && 5310 !wiphy_ext_feature_isset(&rdev->wiphy, 5311 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) 5312 return -EINVAL; 5313 if (count_ht && 5314 !wiphy_ext_feature_isset(&rdev->wiphy, 5315 NL80211_EXT_FEATURE_BEACON_RATE_HT)) 5316 return -EINVAL; 5317 if (count_vht && 5318 !wiphy_ext_feature_isset(&rdev->wiphy, 5319 NL80211_EXT_FEATURE_BEACON_RATE_VHT)) 5320 return -EINVAL; 5321 if (count_he && 5322 !wiphy_ext_feature_isset(&rdev->wiphy, 5323 NL80211_EXT_FEATURE_BEACON_RATE_HE)) 5324 return -EINVAL; 5325 5326 return 0; 5327 } 5328 5329 static int nl80211_parse_mbssid_config(struct wiphy *wiphy, 5330 struct net_device *dev, 5331 struct nlattr *attrs, 5332 struct cfg80211_mbssid_config *config, 5333 u8 num_elems) 5334 { 5335 struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1]; 5336 5337 if (!wiphy->mbssid_max_interfaces) 5338 return -EOPNOTSUPP; 5339 5340 if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL, 5341 NULL) || 5342 !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]) 5343 return -EINVAL; 5344 5345 config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]); 5346 if (config->ema) { 5347 if (!wiphy->ema_max_profile_periodicity) 5348 return -EOPNOTSUPP; 5349 5350 if (num_elems > wiphy->ema_max_profile_periodicity) 5351 return -EINVAL; 5352 } 5353 5354 config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]); 5355 if (config->index >= wiphy->mbssid_max_interfaces || 5356 (!config->index && !num_elems)) 5357 return -EINVAL; 5358 5359 if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) { 5360 u32 tx_ifindex = 5361 nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]); 5362 5363 if ((!config->index && tx_ifindex != dev->ifindex) || 5364 (config->index && tx_ifindex == dev->ifindex)) 5365 return -EINVAL; 5366 5367 if (tx_ifindex != dev->ifindex) { 5368 struct net_device *tx_netdev = 5369 dev_get_by_index(wiphy_net(wiphy), tx_ifindex); 5370 5371 if (!tx_netdev || !tx_netdev->ieee80211_ptr || 5372 tx_netdev->ieee80211_ptr->wiphy != wiphy || 5373 tx_netdev->ieee80211_ptr->iftype != 5374 NL80211_IFTYPE_AP) { 5375 dev_put(tx_netdev); 5376 return -EINVAL; 5377 } 5378 5379 config->tx_wdev = tx_netdev->ieee80211_ptr; 5380 } else { 5381 config->tx_wdev = dev->ieee80211_ptr; 5382 } 5383 } else if (!config->index) { 5384 config->tx_wdev = dev->ieee80211_ptr; 5385 } else { 5386 return -EINVAL; 5387 } 5388 5389 return 0; 5390 } 5391 5392 static struct cfg80211_mbssid_elems * 5393 nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs) 5394 { 5395 struct nlattr *nl_elems; 5396 struct cfg80211_mbssid_elems *elems; 5397 int rem_elems; 5398 u8 i = 0, num_elems = 0; 5399 5400 if (!wiphy->mbssid_max_interfaces) 5401 return ERR_PTR(-EINVAL); 5402 5403 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5404 if (num_elems >= 255) 5405 return ERR_PTR(-EINVAL); 5406 num_elems++; 5407 } 5408 5409 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); 5410 if (!elems) 5411 return ERR_PTR(-ENOMEM); 5412 elems->cnt = num_elems; 5413 5414 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5415 elems->elem[i].data = nla_data(nl_elems); 5416 elems->elem[i].len = nla_len(nl_elems); 5417 i++; 5418 } 5419 return elems; 5420 } 5421 5422 static struct cfg80211_rnr_elems * 5423 nl80211_parse_rnr_elems(struct wiphy *wiphy, struct nlattr *attrs, 5424 struct netlink_ext_ack *extack) 5425 { 5426 struct nlattr *nl_elems; 5427 struct cfg80211_rnr_elems *elems; 5428 int rem_elems; 5429 u8 i = 0, num_elems = 0; 5430 5431 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5432 int ret; 5433 5434 ret = validate_ie_attr(nl_elems, extack); 5435 if (ret) 5436 return ERR_PTR(ret); 5437 5438 num_elems++; 5439 } 5440 5441 elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); 5442 if (!elems) 5443 return ERR_PTR(-ENOMEM); 5444 elems->cnt = num_elems; 5445 5446 nla_for_each_nested(nl_elems, attrs, rem_elems) { 5447 elems->elem[i].data = nla_data(nl_elems); 5448 elems->elem[i].len = nla_len(nl_elems); 5449 i++; 5450 } 5451 return elems; 5452 } 5453 5454 static int nl80211_parse_he_bss_color(struct nlattr *attrs, 5455 struct cfg80211_he_bss_color *he_bss_color) 5456 { 5457 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; 5458 int err; 5459 5460 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, 5461 he_bss_color_policy, NULL); 5462 if (err) 5463 return err; 5464 5465 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) 5466 return -EINVAL; 5467 5468 he_bss_color->color = 5469 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); 5470 he_bss_color->enabled = 5471 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); 5472 he_bss_color->partial = 5473 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); 5474 5475 return 0; 5476 } 5477 5478 static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, 5479 struct nlattr *attrs[], 5480 struct cfg80211_beacon_data *bcn, 5481 struct netlink_ext_ack *extack) 5482 { 5483 bool haveinfo = false; 5484 int err; 5485 5486 memset(bcn, 0, sizeof(*bcn)); 5487 5488 bcn->link_id = nl80211_link_id(attrs); 5489 5490 if (attrs[NL80211_ATTR_BEACON_HEAD]) { 5491 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); 5492 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); 5493 if (!bcn->head_len) 5494 return -EINVAL; 5495 haveinfo = true; 5496 } 5497 5498 if (attrs[NL80211_ATTR_BEACON_TAIL]) { 5499 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); 5500 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); 5501 haveinfo = true; 5502 } 5503 5504 if (!haveinfo) 5505 return -EINVAL; 5506 5507 if (attrs[NL80211_ATTR_IE]) { 5508 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); 5509 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); 5510 } 5511 5512 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { 5513 bcn->proberesp_ies = 5514 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5515 bcn->proberesp_ies_len = 5516 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); 5517 } 5518 5519 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { 5520 bcn->assocresp_ies = 5521 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5522 bcn->assocresp_ies_len = 5523 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); 5524 } 5525 5526 if (attrs[NL80211_ATTR_PROBE_RESP]) { 5527 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); 5528 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); 5529 } 5530 5531 if (attrs[NL80211_ATTR_FTM_RESPONDER]) { 5532 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; 5533 5534 err = nla_parse_nested_deprecated(tb, 5535 NL80211_FTM_RESP_ATTR_MAX, 5536 attrs[NL80211_ATTR_FTM_RESPONDER], 5537 NULL, NULL); 5538 if (err) 5539 return err; 5540 5541 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && 5542 wiphy_ext_feature_isset(&rdev->wiphy, 5543 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) 5544 bcn->ftm_responder = 1; 5545 else 5546 return -EOPNOTSUPP; 5547 5548 if (tb[NL80211_FTM_RESP_ATTR_LCI]) { 5549 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); 5550 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); 5551 } 5552 5553 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { 5554 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5555 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); 5556 } 5557 } else { 5558 bcn->ftm_responder = -1; 5559 } 5560 5561 if (attrs[NL80211_ATTR_HE_BSS_COLOR]) { 5562 err = nl80211_parse_he_bss_color(attrs[NL80211_ATTR_HE_BSS_COLOR], 5563 &bcn->he_bss_color); 5564 if (err) 5565 return err; 5566 bcn->he_bss_color_valid = true; 5567 } 5568 5569 if (attrs[NL80211_ATTR_MBSSID_ELEMS]) { 5570 struct cfg80211_mbssid_elems *mbssid = 5571 nl80211_parse_mbssid_elems(&rdev->wiphy, 5572 attrs[NL80211_ATTR_MBSSID_ELEMS]); 5573 5574 if (IS_ERR(mbssid)) 5575 return PTR_ERR(mbssid); 5576 5577 bcn->mbssid_ies = mbssid; 5578 5579 if (bcn->mbssid_ies && attrs[NL80211_ATTR_EMA_RNR_ELEMS]) { 5580 struct cfg80211_rnr_elems *rnr = 5581 nl80211_parse_rnr_elems(&rdev->wiphy, 5582 attrs[NL80211_ATTR_EMA_RNR_ELEMS], 5583 extack); 5584 5585 if (IS_ERR(rnr)) 5586 return PTR_ERR(rnr); 5587 5588 if (rnr && rnr->cnt < bcn->mbssid_ies->cnt) 5589 return -EINVAL; 5590 5591 bcn->rnr_ies = rnr; 5592 } 5593 } 5594 5595 return 0; 5596 } 5597 5598 static int nl80211_parse_he_obss_pd(struct nlattr *attrs, 5599 struct ieee80211_he_obss_pd *he_obss_pd) 5600 { 5601 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; 5602 int err; 5603 5604 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, 5605 he_obss_pd_policy, NULL); 5606 if (err) 5607 return err; 5608 5609 if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) 5610 return -EINVAL; 5611 5612 he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); 5613 5614 if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) 5615 he_obss_pd->min_offset = 5616 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); 5617 if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) 5618 he_obss_pd->max_offset = 5619 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); 5620 if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) 5621 he_obss_pd->non_srg_max_offset = 5622 nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); 5623 5624 if (he_obss_pd->min_offset > he_obss_pd->max_offset) 5625 return -EINVAL; 5626 5627 if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) 5628 memcpy(he_obss_pd->bss_color_bitmap, 5629 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), 5630 sizeof(he_obss_pd->bss_color_bitmap)); 5631 5632 if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) 5633 memcpy(he_obss_pd->partial_bssid_bitmap, 5634 nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), 5635 sizeof(he_obss_pd->partial_bssid_bitmap)); 5636 5637 he_obss_pd->enable = true; 5638 5639 return 0; 5640 } 5641 5642 static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, 5643 struct nlattr *attrs, 5644 struct cfg80211_fils_discovery *fd) 5645 { 5646 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; 5647 int ret; 5648 5649 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5650 NL80211_EXT_FEATURE_FILS_DISCOVERY)) 5651 return -EINVAL; 5652 5653 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, 5654 NULL, NULL); 5655 if (ret) 5656 return ret; 5657 5658 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] && 5659 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] && 5660 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) { 5661 fd->update = true; 5662 return 0; 5663 } 5664 5665 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || 5666 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || 5667 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) 5668 return -EINVAL; 5669 5670 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5671 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); 5672 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); 5673 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); 5674 fd->update = true; 5675 return 0; 5676 } 5677 5678 static int 5679 nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, 5680 struct nlattr *attrs, 5681 struct cfg80211_unsol_bcast_probe_resp *presp) 5682 { 5683 struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; 5684 int ret; 5685 5686 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5687 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) 5688 return -EINVAL; 5689 5690 ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, 5691 attrs, NULL, NULL); 5692 if (ret) 5693 return ret; 5694 5695 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] && 5696 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) { 5697 presp->update = true; 5698 return 0; 5699 } 5700 5701 if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || 5702 !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) 5703 return -EINVAL; 5704 5705 presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5706 presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); 5707 presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); 5708 presp->update = true; 5709 return 0; 5710 } 5711 5712 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, 5713 const struct element *rates) 5714 { 5715 int i; 5716 5717 if (!rates) 5718 return; 5719 5720 for (i = 0; i < rates->datalen; i++) { 5721 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 5722 params->ht_required = true; 5723 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) 5724 params->vht_required = true; 5725 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) 5726 params->he_required = true; 5727 if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) 5728 params->sae_h2e_required = true; 5729 } 5730 } 5731 5732 /* 5733 * Since the nl80211 API didn't include, from the beginning, attributes about 5734 * HT/VHT requirements/capabilities, we parse them out of the IEs for the 5735 * benefit of drivers that rebuild IEs in the firmware. 5736 */ 5737 static int nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) 5738 { 5739 const struct cfg80211_beacon_data *bcn = ¶ms->beacon; 5740 size_t ies_len = bcn->tail_len; 5741 const u8 *ies = bcn->tail; 5742 const struct element *rates; 5743 const struct element *cap; 5744 5745 rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len); 5746 nl80211_check_ap_rate_selectors(params, rates); 5747 5748 rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); 5749 nl80211_check_ap_rate_selectors(params, rates); 5750 5751 cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len); 5752 if (cap && cap->datalen >= sizeof(*params->ht_cap)) 5753 params->ht_cap = (void *)cap->data; 5754 cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len); 5755 if (cap && cap->datalen >= sizeof(*params->vht_cap)) 5756 params->vht_cap = (void *)cap->data; 5757 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); 5758 if (cap && cap->datalen >= sizeof(*params->he_cap) + 1) 5759 params->he_cap = (void *)(cap->data + 1); 5760 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); 5761 if (cap && cap->datalen >= sizeof(*params->he_oper) + 1) 5762 params->he_oper = (void *)(cap->data + 1); 5763 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_CAPABILITY, ies, ies_len); 5764 if (cap) { 5765 if (!cap->datalen) 5766 return -EINVAL; 5767 params->eht_cap = (void *)(cap->data + 1); 5768 if (!ieee80211_eht_capa_size_ok((const u8 *)params->he_cap, 5769 (const u8 *)params->eht_cap, 5770 cap->datalen - 1, true)) 5771 return -EINVAL; 5772 } 5773 cap = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION, ies, ies_len); 5774 if (cap) { 5775 if (!cap->datalen) 5776 return -EINVAL; 5777 params->eht_oper = (void *)(cap->data + 1); 5778 if (!ieee80211_eht_oper_size_ok((const u8 *)params->eht_oper, 5779 cap->datalen - 1)) 5780 return -EINVAL; 5781 } 5782 return 0; 5783 } 5784 5785 static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, 5786 struct cfg80211_ap_settings *params) 5787 { 5788 struct wireless_dev *wdev; 5789 5790 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { 5791 if (wdev->iftype != NL80211_IFTYPE_AP && 5792 wdev->iftype != NL80211_IFTYPE_P2P_GO) 5793 continue; 5794 5795 if (!wdev->u.ap.preset_chandef.chan) 5796 continue; 5797 5798 params->chandef = wdev->u.ap.preset_chandef; 5799 return true; 5800 } 5801 5802 return false; 5803 } 5804 5805 static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, 5806 enum nl80211_auth_type auth_type, 5807 enum nl80211_commands cmd) 5808 { 5809 if (auth_type > NL80211_AUTHTYPE_MAX) 5810 return false; 5811 5812 switch (cmd) { 5813 case NL80211_CMD_AUTHENTICATE: 5814 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5815 auth_type == NL80211_AUTHTYPE_SAE) 5816 return false; 5817 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5818 NL80211_EXT_FEATURE_FILS_STA) && 5819 (auth_type == NL80211_AUTHTYPE_FILS_SK || 5820 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5821 auth_type == NL80211_AUTHTYPE_FILS_PK)) 5822 return false; 5823 return true; 5824 case NL80211_CMD_CONNECT: 5825 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && 5826 !wiphy_ext_feature_isset(&rdev->wiphy, 5827 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 5828 auth_type == NL80211_AUTHTYPE_SAE) 5829 return false; 5830 5831 /* FILS with SK PFS or PK not supported yet */ 5832 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5833 auth_type == NL80211_AUTHTYPE_FILS_PK) 5834 return false; 5835 if (!wiphy_ext_feature_isset( 5836 &rdev->wiphy, 5837 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 5838 auth_type == NL80211_AUTHTYPE_FILS_SK) 5839 return false; 5840 return true; 5841 case NL80211_CMD_START_AP: 5842 if (!wiphy_ext_feature_isset(&rdev->wiphy, 5843 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && 5844 auth_type == NL80211_AUTHTYPE_SAE) 5845 return false; 5846 /* FILS not supported yet */ 5847 if (auth_type == NL80211_AUTHTYPE_FILS_SK || 5848 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 5849 auth_type == NL80211_AUTHTYPE_FILS_PK) 5850 return false; 5851 return true; 5852 default: 5853 return false; 5854 } 5855 } 5856 5857 static void nl80211_send_ap_started(struct wireless_dev *wdev, 5858 unsigned int link_id) 5859 { 5860 struct wiphy *wiphy = wdev->wiphy; 5861 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 5862 struct sk_buff *msg; 5863 void *hdr; 5864 5865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 5866 if (!msg) 5867 return; 5868 5869 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_START_AP); 5870 if (!hdr) 5871 goto out; 5872 5873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 5874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 5875 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 5876 NL80211_ATTR_PAD) || 5877 (wdev->u.ap.ssid_len && 5878 nla_put(msg, NL80211_ATTR_SSID, wdev->u.ap.ssid_len, 5879 wdev->u.ap.ssid)) || 5880 (wdev->valid_links && 5881 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) 5882 goto out; 5883 5884 genlmsg_end(msg, hdr); 5885 5886 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 5887 NL80211_MCGRP_MLME, GFP_KERNEL); 5888 return; 5889 out: 5890 nlmsg_free(msg); 5891 } 5892 5893 static int nl80211_validate_ap_phy_operation(struct cfg80211_ap_settings *params) 5894 { 5895 struct ieee80211_channel *channel = params->chandef.chan; 5896 5897 if ((params->he_cap || params->he_oper) && 5898 (channel->flags & IEEE80211_CHAN_NO_HE)) 5899 return -EOPNOTSUPP; 5900 5901 if ((params->eht_cap || params->eht_oper) && 5902 (channel->flags & IEEE80211_CHAN_NO_EHT)) 5903 return -EOPNOTSUPP; 5904 5905 return 0; 5906 } 5907 5908 static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) 5909 { 5910 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 5911 unsigned int link_id = nl80211_link_id(info->attrs); 5912 struct net_device *dev = info->user_ptr[1]; 5913 struct wireless_dev *wdev = dev->ieee80211_ptr; 5914 struct cfg80211_ap_settings *params; 5915 int err; 5916 5917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 5918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 5919 return -EOPNOTSUPP; 5920 5921 if (!rdev->ops->start_ap) 5922 return -EOPNOTSUPP; 5923 5924 if (wdev->links[link_id].ap.beacon_interval) 5925 return -EALREADY; 5926 5927 /* these are required for START_AP */ 5928 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || 5929 !info->attrs[NL80211_ATTR_DTIM_PERIOD] || 5930 !info->attrs[NL80211_ATTR_BEACON_HEAD]) 5931 return -EINVAL; 5932 5933 params = kzalloc(sizeof(*params), GFP_KERNEL); 5934 if (!params) 5935 return -ENOMEM; 5936 5937 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon, 5938 info->extack); 5939 if (err) 5940 goto out; 5941 5942 params->beacon_interval = 5943 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 5944 params->dtim_period = 5945 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 5946 5947 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, 5948 params->beacon_interval); 5949 if (err) 5950 goto out; 5951 5952 /* 5953 * In theory, some of these attributes should be required here 5954 * but since they were not used when the command was originally 5955 * added, keep them optional for old user space programs to let 5956 * them continue to work with drivers that do not need the 5957 * additional information -- drivers must check! 5958 */ 5959 if (info->attrs[NL80211_ATTR_SSID]) { 5960 params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 5961 params->ssid_len = 5962 nla_len(info->attrs[NL80211_ATTR_SSID]); 5963 if (params->ssid_len == 0) { 5964 err = -EINVAL; 5965 goto out; 5966 } 5967 5968 if (wdev->u.ap.ssid_len && 5969 (wdev->u.ap.ssid_len != params->ssid_len || 5970 memcmp(wdev->u.ap.ssid, params->ssid, params->ssid_len))) { 5971 /* require identical SSID for MLO */ 5972 err = -EINVAL; 5973 goto out; 5974 } 5975 } else if (wdev->valid_links) { 5976 /* require SSID for MLO */ 5977 err = -EINVAL; 5978 goto out; 5979 } 5980 5981 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) 5982 params->hidden_ssid = nla_get_u32( 5983 info->attrs[NL80211_ATTR_HIDDEN_SSID]); 5984 5985 params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 5986 5987 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 5988 params->auth_type = nla_get_u32( 5989 info->attrs[NL80211_ATTR_AUTH_TYPE]); 5990 if (!nl80211_valid_auth_type(rdev, params->auth_type, 5991 NL80211_CMD_START_AP)) { 5992 err = -EINVAL; 5993 goto out; 5994 } 5995 } else 5996 params->auth_type = NL80211_AUTHTYPE_AUTOMATIC; 5997 5998 err = nl80211_crypto_settings(rdev, info, ¶ms->crypto, 5999 NL80211_MAX_NR_CIPHER_SUITES); 6000 if (err) 6001 goto out; 6002 6003 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { 6004 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) { 6005 err = -EOPNOTSUPP; 6006 goto out; 6007 } 6008 params->inactivity_timeout = nla_get_u16( 6009 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 6010 } 6011 6012 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 6013 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6014 err = -EINVAL; 6015 goto out; 6016 } 6017 params->p2p_ctwindow = 6018 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 6019 if (params->p2p_ctwindow != 0 && 6020 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) { 6021 err = -EINVAL; 6022 goto out; 6023 } 6024 } 6025 6026 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 6027 u8 tmp; 6028 6029 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 6030 err = -EINVAL; 6031 goto out; 6032 } 6033 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 6034 params->p2p_opp_ps = tmp; 6035 if (params->p2p_opp_ps != 0 && 6036 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) { 6037 err = -EINVAL; 6038 goto out; 6039 } 6040 } 6041 6042 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 6043 err = nl80211_parse_chandef(rdev, info, ¶ms->chandef); 6044 if (err) 6045 goto out; 6046 } else if (wdev->valid_links) { 6047 /* with MLD need to specify the channel configuration */ 6048 err = -EINVAL; 6049 goto out; 6050 } else if (wdev->u.ap.preset_chandef.chan) { 6051 params->chandef = wdev->u.ap.preset_chandef; 6052 } else if (!nl80211_get_ap_channel(rdev, params)) { 6053 err = -EINVAL; 6054 goto out; 6055 } 6056 6057 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) { 6058 err = nl80211_parse_punct_bitmap(rdev, info, 6059 ¶ms->chandef, 6060 ¶ms->punct_bitmap); 6061 if (err) 6062 goto out; 6063 } 6064 6065 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef, 6066 wdev->iftype)) { 6067 err = -EINVAL; 6068 goto out; 6069 } 6070 6071 if (info->attrs[NL80211_ATTR_TX_RATES]) { 6072 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 6073 NL80211_ATTR_TX_RATES, 6074 ¶ms->beacon_rate, 6075 dev, false, link_id); 6076 if (err) 6077 goto out; 6078 6079 err = validate_beacon_tx_rate(rdev, params->chandef.chan->band, 6080 ¶ms->beacon_rate); 6081 if (err) 6082 goto out; 6083 } 6084 6085 if (info->attrs[NL80211_ATTR_SMPS_MODE]) { 6086 params->smps_mode = 6087 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); 6088 switch (params->smps_mode) { 6089 case NL80211_SMPS_OFF: 6090 break; 6091 case NL80211_SMPS_STATIC: 6092 if (!(rdev->wiphy.features & 6093 NL80211_FEATURE_STATIC_SMPS)) { 6094 err = -EINVAL; 6095 goto out; 6096 } 6097 break; 6098 case NL80211_SMPS_DYNAMIC: 6099 if (!(rdev->wiphy.features & 6100 NL80211_FEATURE_DYNAMIC_SMPS)) { 6101 err = -EINVAL; 6102 goto out; 6103 } 6104 break; 6105 default: 6106 err = -EINVAL; 6107 goto out; 6108 } 6109 } else { 6110 params->smps_mode = NL80211_SMPS_OFF; 6111 } 6112 6113 params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 6114 if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 6115 err = -EOPNOTSUPP; 6116 goto out; 6117 } 6118 6119 if (info->attrs[NL80211_ATTR_ACL_POLICY]) { 6120 params->acl = parse_acl_data(&rdev->wiphy, info); 6121 if (IS_ERR(params->acl)) { 6122 err = PTR_ERR(params->acl); 6123 params->acl = NULL; 6124 goto out; 6125 } 6126 } 6127 6128 params->twt_responder = 6129 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); 6130 6131 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { 6132 err = nl80211_parse_he_obss_pd( 6133 info->attrs[NL80211_ATTR_HE_OBSS_PD], 6134 ¶ms->he_obss_pd); 6135 if (err) 6136 goto out; 6137 } 6138 6139 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { 6140 err = nl80211_parse_fils_discovery(rdev, 6141 info->attrs[NL80211_ATTR_FILS_DISCOVERY], 6142 ¶ms->fils_discovery); 6143 if (err) 6144 goto out; 6145 } 6146 6147 if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { 6148 err = nl80211_parse_unsol_bcast_probe_resp( 6149 rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], 6150 ¶ms->unsol_bcast_probe_resp); 6151 if (err) 6152 goto out; 6153 } 6154 6155 if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) { 6156 err = nl80211_parse_mbssid_config(&rdev->wiphy, dev, 6157 info->attrs[NL80211_ATTR_MBSSID_CONFIG], 6158 ¶ms->mbssid_config, 6159 params->beacon.mbssid_ies ? 6160 params->beacon.mbssid_ies->cnt : 6161 0); 6162 if (err) 6163 goto out; 6164 } 6165 6166 if (!params->mbssid_config.ema && params->beacon.rnr_ies) { 6167 err = -EINVAL; 6168 goto out; 6169 } 6170 6171 err = nl80211_calculate_ap_params(params); 6172 if (err) 6173 goto out; 6174 6175 err = nl80211_validate_ap_phy_operation(params); 6176 if (err) 6177 goto out; 6178 6179 if (info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]) 6180 params->flags = nla_get_u32( 6181 info->attrs[NL80211_ATTR_AP_SETTINGS_FLAGS]); 6182 else if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) 6183 params->flags |= NL80211_AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; 6184 6185 if (wdev->conn_owner_nlportid && 6186 info->attrs[NL80211_ATTR_SOCKET_OWNER] && 6187 wdev->conn_owner_nlportid != info->snd_portid) { 6188 err = -EINVAL; 6189 goto out; 6190 } 6191 6192 /* FIXME: validate MLO/link-id against driver capabilities */ 6193 6194 err = rdev_start_ap(rdev, dev, params); 6195 if (!err) { 6196 wdev->links[link_id].ap.beacon_interval = params->beacon_interval; 6197 wdev->links[link_id].ap.chandef = params->chandef; 6198 wdev->u.ap.ssid_len = params->ssid_len; 6199 memcpy(wdev->u.ap.ssid, params->ssid, 6200 params->ssid_len); 6201 6202 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 6203 wdev->conn_owner_nlportid = info->snd_portid; 6204 6205 nl80211_send_ap_started(wdev, link_id); 6206 } 6207 out: 6208 kfree(params->acl); 6209 kfree(params->beacon.mbssid_ies); 6210 if (params->mbssid_config.tx_wdev && 6211 params->mbssid_config.tx_wdev->netdev && 6212 params->mbssid_config.tx_wdev->netdev != dev) 6213 dev_put(params->mbssid_config.tx_wdev->netdev); 6214 kfree(params->beacon.rnr_ies); 6215 kfree(params); 6216 6217 return err; 6218 } 6219 6220 static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) 6221 { 6222 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6223 unsigned int link_id = nl80211_link_id(info->attrs); 6224 struct net_device *dev = info->user_ptr[1]; 6225 struct wireless_dev *wdev = dev->ieee80211_ptr; 6226 struct cfg80211_ap_update *params; 6227 struct nlattr *attr; 6228 int err; 6229 6230 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 6231 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 6232 return -EOPNOTSUPP; 6233 6234 if (!rdev->ops->change_beacon) 6235 return -EOPNOTSUPP; 6236 6237 if (!wdev->links[link_id].ap.beacon_interval) 6238 return -EINVAL; 6239 6240 params = kzalloc(sizeof(*params), GFP_KERNEL); 6241 if (!params) 6242 return -ENOMEM; 6243 6244 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon, 6245 info->extack); 6246 if (err) 6247 goto out; 6248 6249 attr = info->attrs[NL80211_ATTR_FILS_DISCOVERY]; 6250 if (attr) { 6251 err = nl80211_parse_fils_discovery(rdev, attr, 6252 ¶ms->fils_discovery); 6253 if (err) 6254 goto out; 6255 } 6256 6257 attr = info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]; 6258 if (attr) { 6259 err = nl80211_parse_unsol_bcast_probe_resp(rdev, attr, 6260 ¶ms->unsol_bcast_probe_resp); 6261 if (err) 6262 goto out; 6263 } 6264 6265 err = rdev_change_beacon(rdev, dev, params); 6266 6267 out: 6268 kfree(params->beacon.mbssid_ies); 6269 kfree(params->beacon.rnr_ies); 6270 kfree(params); 6271 return err; 6272 } 6273 6274 static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) 6275 { 6276 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6277 unsigned int link_id = nl80211_link_id(info->attrs); 6278 struct net_device *dev = info->user_ptr[1]; 6279 6280 return cfg80211_stop_ap(rdev, dev, link_id, false); 6281 } 6282 6283 static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { 6284 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, 6285 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, 6286 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, 6287 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, 6288 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, 6289 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, 6290 }; 6291 6292 static int parse_station_flags(struct genl_info *info, 6293 enum nl80211_iftype iftype, 6294 struct station_parameters *params) 6295 { 6296 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; 6297 struct nlattr *nla; 6298 int flag; 6299 6300 /* 6301 * Try parsing the new attribute first so userspace 6302 * can specify both for older kernels. 6303 */ 6304 nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; 6305 if (nla) { 6306 struct nl80211_sta_flag_update *sta_flags; 6307 6308 sta_flags = nla_data(nla); 6309 params->sta_flags_mask = sta_flags->mask; 6310 params->sta_flags_set = sta_flags->set; 6311 params->sta_flags_set &= params->sta_flags_mask; 6312 if ((params->sta_flags_mask | 6313 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) 6314 return -EINVAL; 6315 return 0; 6316 } 6317 6318 /* if present, parse the old attribute */ 6319 6320 nla = info->attrs[NL80211_ATTR_STA_FLAGS]; 6321 if (!nla) 6322 return 0; 6323 6324 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) 6325 return -EINVAL; 6326 6327 /* 6328 * Only allow certain flags for interface types so that 6329 * other attributes are silently ignored. Remember that 6330 * this is backward compatibility code with old userspace 6331 * and shouldn't be hit in other cases anyway. 6332 */ 6333 switch (iftype) { 6334 case NL80211_IFTYPE_AP: 6335 case NL80211_IFTYPE_AP_VLAN: 6336 case NL80211_IFTYPE_P2P_GO: 6337 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6338 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6339 BIT(NL80211_STA_FLAG_WME) | 6340 BIT(NL80211_STA_FLAG_MFP); 6341 break; 6342 case NL80211_IFTYPE_P2P_CLIENT: 6343 case NL80211_IFTYPE_STATION: 6344 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | 6345 BIT(NL80211_STA_FLAG_TDLS_PEER); 6346 break; 6347 case NL80211_IFTYPE_MESH_POINT: 6348 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6349 BIT(NL80211_STA_FLAG_MFP) | 6350 BIT(NL80211_STA_FLAG_AUTHORIZED); 6351 break; 6352 default: 6353 return -EINVAL; 6354 } 6355 6356 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { 6357 if (flags[flag]) { 6358 params->sta_flags_set |= (1<<flag); 6359 6360 /* no longer support new API additions in old API */ 6361 if (flag > NL80211_STA_FLAG_MAX_OLD_API) 6362 return -EINVAL; 6363 } 6364 } 6365 6366 return 0; 6367 } 6368 6369 bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) 6370 { 6371 struct nlattr *rate; 6372 u32 bitrate; 6373 u16 bitrate_compat; 6374 enum nl80211_rate_info rate_flg; 6375 6376 rate = nla_nest_start_noflag(msg, attr); 6377 if (!rate) 6378 return false; 6379 6380 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ 6381 bitrate = cfg80211_calculate_bitrate(info); 6382 /* report 16-bit bitrate only if we can */ 6383 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; 6384 if (bitrate > 0 && 6385 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) 6386 return false; 6387 if (bitrate_compat > 0 && 6388 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) 6389 return false; 6390 6391 switch (info->bw) { 6392 case RATE_INFO_BW_1: 6393 rate_flg = NL80211_RATE_INFO_1_MHZ_WIDTH; 6394 break; 6395 case RATE_INFO_BW_2: 6396 rate_flg = NL80211_RATE_INFO_2_MHZ_WIDTH; 6397 break; 6398 case RATE_INFO_BW_4: 6399 rate_flg = NL80211_RATE_INFO_4_MHZ_WIDTH; 6400 break; 6401 case RATE_INFO_BW_5: 6402 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; 6403 break; 6404 case RATE_INFO_BW_8: 6405 rate_flg = NL80211_RATE_INFO_8_MHZ_WIDTH; 6406 break; 6407 case RATE_INFO_BW_10: 6408 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; 6409 break; 6410 case RATE_INFO_BW_16: 6411 rate_flg = NL80211_RATE_INFO_16_MHZ_WIDTH; 6412 break; 6413 default: 6414 WARN_ON(1); 6415 fallthrough; 6416 case RATE_INFO_BW_20: 6417 rate_flg = 0; 6418 break; 6419 case RATE_INFO_BW_40: 6420 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; 6421 break; 6422 case RATE_INFO_BW_80: 6423 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; 6424 break; 6425 case RATE_INFO_BW_160: 6426 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; 6427 break; 6428 case RATE_INFO_BW_HE_RU: 6429 rate_flg = 0; 6430 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); 6431 break; 6432 case RATE_INFO_BW_320: 6433 rate_flg = NL80211_RATE_INFO_320_MHZ_WIDTH; 6434 break; 6435 case RATE_INFO_BW_EHT_RU: 6436 rate_flg = 0; 6437 WARN_ON(!(info->flags & RATE_INFO_FLAGS_EHT_MCS)); 6438 break; 6439 } 6440 6441 if (rate_flg && nla_put_flag(msg, rate_flg)) 6442 return false; 6443 6444 if (info->flags & RATE_INFO_FLAGS_MCS) { 6445 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) 6446 return false; 6447 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6448 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6449 return false; 6450 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { 6451 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) 6452 return false; 6453 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) 6454 return false; 6455 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6456 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6457 return false; 6458 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { 6459 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) 6460 return false; 6461 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) 6462 return false; 6463 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) 6464 return false; 6465 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) 6466 return false; 6467 if (info->bw == RATE_INFO_BW_HE_RU && 6468 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, 6469 info->he_ru_alloc)) 6470 return false; 6471 } else if (info->flags & RATE_INFO_FLAGS_S1G_MCS) { 6472 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_MCS, info->mcs)) 6473 return false; 6474 if (nla_put_u8(msg, NL80211_RATE_INFO_S1G_NSS, info->nss)) 6475 return false; 6476 if (info->flags & RATE_INFO_FLAGS_SHORT_GI && 6477 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) 6478 return false; 6479 } else if (info->flags & RATE_INFO_FLAGS_EHT_MCS) { 6480 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_MCS, info->mcs)) 6481 return false; 6482 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_NSS, info->nss)) 6483 return false; 6484 if (nla_put_u8(msg, NL80211_RATE_INFO_EHT_GI, info->eht_gi)) 6485 return false; 6486 if (info->bw == RATE_INFO_BW_EHT_RU && 6487 nla_put_u8(msg, NL80211_RATE_INFO_EHT_RU_ALLOC, 6488 info->eht_ru_alloc)) 6489 return false; 6490 } 6491 6492 nla_nest_end(msg, rate); 6493 return true; 6494 } 6495 6496 static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, 6497 int id) 6498 { 6499 void *attr; 6500 int i = 0; 6501 6502 if (!mask) 6503 return true; 6504 6505 attr = nla_nest_start_noflag(msg, id); 6506 if (!attr) 6507 return false; 6508 6509 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { 6510 if (!(mask & BIT(i))) 6511 continue; 6512 6513 if (nla_put_u8(msg, i, signal[i])) 6514 return false; 6515 } 6516 6517 nla_nest_end(msg, attr); 6518 6519 return true; 6520 } 6521 6522 static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, 6523 u32 seq, int flags, 6524 struct cfg80211_registered_device *rdev, 6525 struct net_device *dev, 6526 const u8 *mac_addr, struct station_info *sinfo) 6527 { 6528 void *hdr; 6529 struct nlattr *sinfoattr, *bss_param; 6530 6531 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 6532 if (!hdr) { 6533 cfg80211_sinfo_release_content(sinfo); 6534 return -1; 6535 } 6536 6537 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 6538 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 6539 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) 6540 goto nla_put_failure; 6541 6542 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); 6543 if (!sinfoattr) 6544 goto nla_put_failure; 6545 6546 #define PUT_SINFO(attr, memb, type) do { \ 6547 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ 6548 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6549 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ 6550 sinfo->memb)) \ 6551 goto nla_put_failure; \ 6552 } while (0) 6553 #define PUT_SINFO_U64(attr, memb) do { \ 6554 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ 6555 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ 6556 sinfo->memb, NL80211_STA_INFO_PAD)) \ 6557 goto nla_put_failure; \ 6558 } while (0) 6559 6560 PUT_SINFO(CONNECTED_TIME, connected_time, u32); 6561 PUT_SINFO(INACTIVE_TIME, inactive_time, u32); 6562 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); 6563 6564 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | 6565 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && 6566 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, 6567 (u32)sinfo->rx_bytes)) 6568 goto nla_put_failure; 6569 6570 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | 6571 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && 6572 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, 6573 (u32)sinfo->tx_bytes)) 6574 goto nla_put_failure; 6575 6576 PUT_SINFO_U64(RX_BYTES64, rx_bytes); 6577 PUT_SINFO_U64(TX_BYTES64, tx_bytes); 6578 PUT_SINFO(LLID, llid, u16); 6579 PUT_SINFO(PLID, plid, u16); 6580 PUT_SINFO(PLINK_STATE, plink_state, u8); 6581 PUT_SINFO_U64(RX_DURATION, rx_duration); 6582 PUT_SINFO_U64(TX_DURATION, tx_duration); 6583 6584 if (wiphy_ext_feature_isset(&rdev->wiphy, 6585 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 6586 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); 6587 6588 switch (rdev->wiphy.signal_type) { 6589 case CFG80211_SIGNAL_TYPE_MBM: 6590 PUT_SINFO(SIGNAL, signal, u8); 6591 PUT_SINFO(SIGNAL_AVG, signal_avg, u8); 6592 break; 6593 default: 6594 break; 6595 } 6596 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { 6597 if (!nl80211_put_signal(msg, sinfo->chains, 6598 sinfo->chain_signal, 6599 NL80211_STA_INFO_CHAIN_SIGNAL)) 6600 goto nla_put_failure; 6601 } 6602 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { 6603 if (!nl80211_put_signal(msg, sinfo->chains, 6604 sinfo->chain_signal_avg, 6605 NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) 6606 goto nla_put_failure; 6607 } 6608 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { 6609 if (!nl80211_put_sta_rate(msg, &sinfo->txrate, 6610 NL80211_STA_INFO_TX_BITRATE)) 6611 goto nla_put_failure; 6612 } 6613 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { 6614 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, 6615 NL80211_STA_INFO_RX_BITRATE)) 6616 goto nla_put_failure; 6617 } 6618 6619 PUT_SINFO(RX_PACKETS, rx_packets, u32); 6620 PUT_SINFO(TX_PACKETS, tx_packets, u32); 6621 PUT_SINFO(TX_RETRIES, tx_retries, u32); 6622 PUT_SINFO(TX_FAILED, tx_failed, u32); 6623 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); 6624 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); 6625 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); 6626 PUT_SINFO(LOCAL_PM, local_pm, u32); 6627 PUT_SINFO(PEER_PM, peer_pm, u32); 6628 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); 6629 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); 6630 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); 6631 6632 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { 6633 bss_param = nla_nest_start_noflag(msg, 6634 NL80211_STA_INFO_BSS_PARAM); 6635 if (!bss_param) 6636 goto nla_put_failure; 6637 6638 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && 6639 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || 6640 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && 6641 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || 6642 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && 6643 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || 6644 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, 6645 sinfo->bss_param.dtim_period) || 6646 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, 6647 sinfo->bss_param.beacon_interval)) 6648 goto nla_put_failure; 6649 6650 nla_nest_end(msg, bss_param); 6651 } 6652 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && 6653 nla_put(msg, NL80211_STA_INFO_STA_FLAGS, 6654 sizeof(struct nl80211_sta_flag_update), 6655 &sinfo->sta_flags)) 6656 goto nla_put_failure; 6657 6658 PUT_SINFO_U64(T_OFFSET, t_offset); 6659 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); 6660 PUT_SINFO_U64(BEACON_RX, rx_beacon); 6661 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); 6662 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); 6663 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); 6664 if (wiphy_ext_feature_isset(&rdev->wiphy, 6665 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { 6666 PUT_SINFO(ACK_SIGNAL, ack_signal, u8); 6667 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); 6668 } 6669 6670 #undef PUT_SINFO 6671 #undef PUT_SINFO_U64 6672 6673 if (sinfo->pertid) { 6674 struct nlattr *tidsattr; 6675 int tid; 6676 6677 tidsattr = nla_nest_start_noflag(msg, 6678 NL80211_STA_INFO_TID_STATS); 6679 if (!tidsattr) 6680 goto nla_put_failure; 6681 6682 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { 6683 struct cfg80211_tid_stats *tidstats; 6684 struct nlattr *tidattr; 6685 6686 tidstats = &sinfo->pertid[tid]; 6687 6688 if (!tidstats->filled) 6689 continue; 6690 6691 tidattr = nla_nest_start_noflag(msg, tid + 1); 6692 if (!tidattr) 6693 goto nla_put_failure; 6694 6695 #define PUT_TIDVAL_U64(attr, memb) do { \ 6696 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ 6697 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ 6698 tidstats->memb, NL80211_TID_STATS_PAD)) \ 6699 goto nla_put_failure; \ 6700 } while (0) 6701 6702 PUT_TIDVAL_U64(RX_MSDU, rx_msdu); 6703 PUT_TIDVAL_U64(TX_MSDU, tx_msdu); 6704 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); 6705 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); 6706 6707 #undef PUT_TIDVAL_U64 6708 if ((tidstats->filled & 6709 BIT(NL80211_TID_STATS_TXQ_STATS)) && 6710 !nl80211_put_txq_stats(msg, &tidstats->txq_stats, 6711 NL80211_TID_STATS_TXQ_STATS)) 6712 goto nla_put_failure; 6713 6714 nla_nest_end(msg, tidattr); 6715 } 6716 6717 nla_nest_end(msg, tidsattr); 6718 } 6719 6720 nla_nest_end(msg, sinfoattr); 6721 6722 if (sinfo->assoc_req_ies_len && 6723 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, 6724 sinfo->assoc_req_ies)) 6725 goto nla_put_failure; 6726 6727 if (sinfo->assoc_resp_ies_len && 6728 nla_put(msg, NL80211_ATTR_RESP_IE, sinfo->assoc_resp_ies_len, 6729 sinfo->assoc_resp_ies)) 6730 goto nla_put_failure; 6731 6732 if (sinfo->mlo_params_valid) { 6733 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, 6734 sinfo->assoc_link_id)) 6735 goto nla_put_failure; 6736 6737 if (!is_zero_ether_addr(sinfo->mld_addr) && 6738 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, 6739 sinfo->mld_addr)) 6740 goto nla_put_failure; 6741 } 6742 6743 cfg80211_sinfo_release_content(sinfo); 6744 genlmsg_end(msg, hdr); 6745 return 0; 6746 6747 nla_put_failure: 6748 cfg80211_sinfo_release_content(sinfo); 6749 genlmsg_cancel(msg, hdr); 6750 return -EMSGSIZE; 6751 } 6752 6753 static int nl80211_dump_station(struct sk_buff *skb, 6754 struct netlink_callback *cb) 6755 { 6756 struct station_info sinfo; 6757 struct cfg80211_registered_device *rdev; 6758 struct wireless_dev *wdev; 6759 u8 mac_addr[ETH_ALEN]; 6760 int sta_idx = cb->args[2]; 6761 int err; 6762 6763 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 6764 if (err) 6765 return err; 6766 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 6767 __acquire(&rdev->wiphy.mtx); 6768 6769 if (!wdev->netdev) { 6770 err = -EINVAL; 6771 goto out_err; 6772 } 6773 6774 if (!rdev->ops->dump_station) { 6775 err = -EOPNOTSUPP; 6776 goto out_err; 6777 } 6778 6779 while (1) { 6780 memset(&sinfo, 0, sizeof(sinfo)); 6781 err = rdev_dump_station(rdev, wdev->netdev, sta_idx, 6782 mac_addr, &sinfo); 6783 if (err == -ENOENT) 6784 break; 6785 if (err) 6786 goto out_err; 6787 6788 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, 6789 NETLINK_CB(cb->skb).portid, 6790 cb->nlh->nlmsg_seq, NLM_F_MULTI, 6791 rdev, wdev->netdev, mac_addr, 6792 &sinfo) < 0) 6793 goto out; 6794 6795 sta_idx++; 6796 } 6797 6798 out: 6799 cb->args[2] = sta_idx; 6800 err = skb->len; 6801 out_err: 6802 wiphy_unlock(&rdev->wiphy); 6803 6804 return err; 6805 } 6806 6807 static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) 6808 { 6809 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 6810 struct net_device *dev = info->user_ptr[1]; 6811 struct station_info sinfo; 6812 struct sk_buff *msg; 6813 u8 *mac_addr = NULL; 6814 int err; 6815 6816 memset(&sinfo, 0, sizeof(sinfo)); 6817 6818 if (!info->attrs[NL80211_ATTR_MAC]) 6819 return -EINVAL; 6820 6821 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 6822 6823 if (!rdev->ops->get_station) 6824 return -EOPNOTSUPP; 6825 6826 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 6827 if (err) 6828 return err; 6829 6830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 6831 if (!msg) { 6832 cfg80211_sinfo_release_content(&sinfo); 6833 return -ENOMEM; 6834 } 6835 6836 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 6837 info->snd_portid, info->snd_seq, 0, 6838 rdev, dev, mac_addr, &sinfo) < 0) { 6839 nlmsg_free(msg); 6840 return -ENOBUFS; 6841 } 6842 6843 return genlmsg_reply(msg, info); 6844 } 6845 6846 int cfg80211_check_station_change(struct wiphy *wiphy, 6847 struct station_parameters *params, 6848 enum cfg80211_station_type statype) 6849 { 6850 if (params->listen_interval != -1 && 6851 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6852 return -EINVAL; 6853 6854 if (params->support_p2p_ps != -1 && 6855 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6856 return -EINVAL; 6857 6858 if (params->aid && 6859 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && 6860 statype != CFG80211_STA_AP_CLIENT_UNASSOC) 6861 return -EINVAL; 6862 6863 /* When you run into this, adjust the code below for the new flag */ 6864 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 6865 6866 switch (statype) { 6867 case CFG80211_STA_MESH_PEER_KERNEL: 6868 case CFG80211_STA_MESH_PEER_USER: 6869 /* 6870 * No ignoring the TDLS flag here -- the userspace mesh 6871 * code doesn't have the bug of including TDLS in the 6872 * mask everywhere. 6873 */ 6874 if (params->sta_flags_mask & 6875 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6876 BIT(NL80211_STA_FLAG_MFP) | 6877 BIT(NL80211_STA_FLAG_AUTHORIZED))) 6878 return -EINVAL; 6879 break; 6880 case CFG80211_STA_TDLS_PEER_SETUP: 6881 case CFG80211_STA_TDLS_PEER_ACTIVE: 6882 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 6883 return -EINVAL; 6884 /* ignore since it can't change */ 6885 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6886 break; 6887 default: 6888 /* disallow mesh-specific things */ 6889 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) 6890 return -EINVAL; 6891 if (params->local_pm) 6892 return -EINVAL; 6893 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6894 return -EINVAL; 6895 } 6896 6897 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6898 statype != CFG80211_STA_TDLS_PEER_ACTIVE) { 6899 /* TDLS can't be set, ... */ 6900 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 6901 return -EINVAL; 6902 /* 6903 * ... but don't bother the driver with it. This works around 6904 * a hostapd/wpa_supplicant issue -- it always includes the 6905 * TLDS_PEER flag in the mask even for AP mode. 6906 */ 6907 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 6908 } 6909 6910 if (statype != CFG80211_STA_TDLS_PEER_SETUP && 6911 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6912 /* reject other things that can't change */ 6913 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) 6914 return -EINVAL; 6915 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) 6916 return -EINVAL; 6917 if (params->link_sta_params.supported_rates) 6918 return -EINVAL; 6919 if (params->ext_capab || params->link_sta_params.ht_capa || 6920 params->link_sta_params.vht_capa || 6921 params->link_sta_params.he_capa || 6922 params->link_sta_params.eht_capa) 6923 return -EINVAL; 6924 } 6925 6926 if (statype != CFG80211_STA_AP_CLIENT && 6927 statype != CFG80211_STA_AP_CLIENT_UNASSOC) { 6928 if (params->vlan) 6929 return -EINVAL; 6930 } 6931 6932 switch (statype) { 6933 case CFG80211_STA_AP_MLME_CLIENT: 6934 /* Use this only for authorizing/unauthorizing a station */ 6935 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) 6936 return -EOPNOTSUPP; 6937 break; 6938 case CFG80211_STA_AP_CLIENT: 6939 case CFG80211_STA_AP_CLIENT_UNASSOC: 6940 /* accept only the listed bits */ 6941 if (params->sta_flags_mask & 6942 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6943 BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6944 BIT(NL80211_STA_FLAG_ASSOCIATED) | 6945 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | 6946 BIT(NL80211_STA_FLAG_WME) | 6947 BIT(NL80211_STA_FLAG_MFP))) 6948 return -EINVAL; 6949 6950 /* but authenticated/associated only if driver handles it */ 6951 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 6952 params->sta_flags_mask & 6953 (BIT(NL80211_STA_FLAG_AUTHENTICATED) | 6954 BIT(NL80211_STA_FLAG_ASSOCIATED))) 6955 return -EINVAL; 6956 break; 6957 case CFG80211_STA_IBSS: 6958 case CFG80211_STA_AP_STA: 6959 /* reject any changes other than AUTHORIZED */ 6960 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) 6961 return -EINVAL; 6962 break; 6963 case CFG80211_STA_TDLS_PEER_SETUP: 6964 /* reject any changes other than AUTHORIZED or WME */ 6965 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | 6966 BIT(NL80211_STA_FLAG_WME))) 6967 return -EINVAL; 6968 /* force (at least) rates when authorizing */ 6969 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && 6970 !params->link_sta_params.supported_rates) 6971 return -EINVAL; 6972 break; 6973 case CFG80211_STA_TDLS_PEER_ACTIVE: 6974 /* reject any changes */ 6975 return -EINVAL; 6976 case CFG80211_STA_MESH_PEER_KERNEL: 6977 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) 6978 return -EINVAL; 6979 break; 6980 case CFG80211_STA_MESH_PEER_USER: 6981 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && 6982 params->plink_action != NL80211_PLINK_ACTION_BLOCK) 6983 return -EINVAL; 6984 break; 6985 } 6986 6987 /* 6988 * Older kernel versions ignored this attribute entirely, so don't 6989 * reject attempts to update it but mark it as unused instead so the 6990 * driver won't look at the data. 6991 */ 6992 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && 6993 statype != CFG80211_STA_TDLS_PEER_SETUP) 6994 params->link_sta_params.opmode_notif_used = false; 6995 6996 return 0; 6997 } 6998 EXPORT_SYMBOL(cfg80211_check_station_change); 6999 7000 /* 7001 * Get vlan interface making sure it is running and on the right wiphy. 7002 */ 7003 static struct net_device *get_vlan(struct genl_info *info, 7004 struct cfg80211_registered_device *rdev) 7005 { 7006 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; 7007 struct net_device *v; 7008 int ret; 7009 7010 if (!vlanattr) 7011 return NULL; 7012 7013 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); 7014 if (!v) 7015 return ERR_PTR(-ENODEV); 7016 7017 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { 7018 ret = -EINVAL; 7019 goto error; 7020 } 7021 7022 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && 7023 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 7024 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { 7025 ret = -EINVAL; 7026 goto error; 7027 } 7028 7029 if (!netif_running(v)) { 7030 ret = -ENETDOWN; 7031 goto error; 7032 } 7033 7034 return v; 7035 error: 7036 dev_put(v); 7037 return ERR_PTR(ret); 7038 } 7039 7040 static int nl80211_parse_sta_wme(struct genl_info *info, 7041 struct station_parameters *params) 7042 { 7043 struct nlattr *tb[NL80211_STA_WME_MAX + 1]; 7044 struct nlattr *nla; 7045 int err; 7046 7047 /* parse WME attributes if present */ 7048 if (!info->attrs[NL80211_ATTR_STA_WME]) 7049 return 0; 7050 7051 nla = info->attrs[NL80211_ATTR_STA_WME]; 7052 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, 7053 nl80211_sta_wme_policy, 7054 info->extack); 7055 if (err) 7056 return err; 7057 7058 if (tb[NL80211_STA_WME_UAPSD_QUEUES]) 7059 params->uapsd_queues = nla_get_u8( 7060 tb[NL80211_STA_WME_UAPSD_QUEUES]); 7061 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) 7062 return -EINVAL; 7063 7064 if (tb[NL80211_STA_WME_MAX_SP]) 7065 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); 7066 7067 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) 7068 return -EINVAL; 7069 7070 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; 7071 7072 return 0; 7073 } 7074 7075 static int nl80211_parse_sta_channel_info(struct genl_info *info, 7076 struct station_parameters *params) 7077 { 7078 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { 7079 params->supported_channels = 7080 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 7081 params->supported_channels_len = 7082 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); 7083 /* 7084 * Need to include at least one (first channel, number of 7085 * channels) tuple for each subband (checked in policy), 7086 * and must have proper tuples for the rest of the data as well. 7087 */ 7088 if (params->supported_channels_len % 2) 7089 return -EINVAL; 7090 } 7091 7092 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { 7093 params->supported_oper_classes = 7094 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 7095 params->supported_oper_classes_len = 7096 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); 7097 } 7098 return 0; 7099 } 7100 7101 static int nl80211_set_station_tdls(struct genl_info *info, 7102 struct station_parameters *params) 7103 { 7104 int err; 7105 /* Dummy STA entry gets updated once the peer capabilities are known */ 7106 if (info->attrs[NL80211_ATTR_PEER_AID]) 7107 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 7108 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 7109 params->link_sta_params.ht_capa = 7110 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 7111 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 7112 params->link_sta_params.vht_capa = 7113 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 7114 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 7115 params->link_sta_params.he_capa = 7116 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7117 params->link_sta_params.he_capa_len = 7118 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7119 7120 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 7121 params->link_sta_params.eht_capa = 7122 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7123 params->link_sta_params.eht_capa_len = 7124 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7125 7126 if (!ieee80211_eht_capa_size_ok((const u8 *)params->link_sta_params.he_capa, 7127 (const u8 *)params->link_sta_params.eht_capa, 7128 params->link_sta_params.eht_capa_len, 7129 false)) 7130 return -EINVAL; 7131 } 7132 } 7133 7134 err = nl80211_parse_sta_channel_info(info, params); 7135 if (err) 7136 return err; 7137 7138 return nl80211_parse_sta_wme(info, params); 7139 } 7140 7141 static int nl80211_parse_sta_txpower_setting(struct genl_info *info, 7142 struct sta_txpwr *txpwr, 7143 bool *txpwr_set) 7144 { 7145 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7146 int idx; 7147 7148 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { 7149 if (!rdev->ops->set_tx_power || 7150 !wiphy_ext_feature_isset(&rdev->wiphy, 7151 NL80211_EXT_FEATURE_STA_TX_PWR)) 7152 return -EOPNOTSUPP; 7153 7154 idx = NL80211_ATTR_STA_TX_POWER_SETTING; 7155 txpwr->type = nla_get_u8(info->attrs[idx]); 7156 7157 if (txpwr->type == NL80211_TX_POWER_LIMITED) { 7158 idx = NL80211_ATTR_STA_TX_POWER; 7159 7160 if (info->attrs[idx]) 7161 txpwr->power = nla_get_s16(info->attrs[idx]); 7162 else 7163 return -EINVAL; 7164 } 7165 7166 *txpwr_set = true; 7167 } else { 7168 *txpwr_set = false; 7169 } 7170 7171 return 0; 7172 } 7173 7174 static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) 7175 { 7176 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7177 struct net_device *dev = info->user_ptr[1]; 7178 struct station_parameters params; 7179 u8 *mac_addr; 7180 int err; 7181 7182 memset(¶ms, 0, sizeof(params)); 7183 7184 if (!rdev->ops->change_station) 7185 return -EOPNOTSUPP; 7186 7187 /* 7188 * AID and listen_interval properties can be set only for unassociated 7189 * station. Include these parameters here and will check them in 7190 * cfg80211_check_station_change(). 7191 */ 7192 if (info->attrs[NL80211_ATTR_STA_AID]) 7193 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 7194 7195 if (info->attrs[NL80211_ATTR_VLAN_ID]) 7196 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 7197 7198 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 7199 params.listen_interval = 7200 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 7201 else 7202 params.listen_interval = -1; 7203 7204 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) 7205 params.support_p2p_ps = 7206 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 7207 else 7208 params.support_p2p_ps = -1; 7209 7210 if (!info->attrs[NL80211_ATTR_MAC]) 7211 return -EINVAL; 7212 7213 params.link_sta_params.link_id = 7214 nl80211_link_id_or_invalid(info->attrs); 7215 7216 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7217 /* If MLD_ADDR attribute is set then this is an MLD station 7218 * and the MLD_ADDR attribute holds the MLD address and the 7219 * MAC attribute holds for the LINK address. 7220 * In that case, the link_id is also expected to be valid. 7221 */ 7222 if (params.link_sta_params.link_id < 0) 7223 return -EINVAL; 7224 7225 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7226 params.link_sta_params.mld_mac = mac_addr; 7227 params.link_sta_params.link_mac = 7228 nla_data(info->attrs[NL80211_ATTR_MAC]); 7229 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7230 return -EINVAL; 7231 } else { 7232 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7233 } 7234 7235 7236 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 7237 params.link_sta_params.supported_rates = 7238 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7239 params.link_sta_params.supported_rates_len = 7240 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7241 } 7242 7243 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7244 params.capability = 7245 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7246 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7247 } 7248 7249 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7250 params.ext_capab = 7251 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7252 params.ext_capab_len = 7253 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7254 } 7255 7256 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7257 return -EINVAL; 7258 7259 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7260 params.plink_action = 7261 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7262 7263 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { 7264 params.plink_state = 7265 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); 7266 if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) 7267 params.peer_aid = nla_get_u16( 7268 info->attrs[NL80211_ATTR_MESH_PEER_AID]); 7269 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; 7270 } 7271 7272 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) 7273 params.local_pm = nla_get_u32( 7274 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); 7275 7276 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7277 params.link_sta_params.opmode_notif_used = true; 7278 params.link_sta_params.opmode_notif = 7279 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7280 } 7281 7282 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7283 params.link_sta_params.he_6ghz_capa = 7284 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7285 7286 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7287 params.airtime_weight = 7288 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7289 7290 if (params.airtime_weight && 7291 !wiphy_ext_feature_isset(&rdev->wiphy, 7292 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7293 return -EOPNOTSUPP; 7294 7295 err = nl80211_parse_sta_txpower_setting(info, 7296 ¶ms.link_sta_params.txpwr, 7297 ¶ms.link_sta_params.txpwr_set); 7298 if (err) 7299 return err; 7300 7301 /* Include parameters for TDLS peer (will check later) */ 7302 err = nl80211_set_station_tdls(info, ¶ms); 7303 if (err) 7304 return err; 7305 7306 params.vlan = get_vlan(info, rdev); 7307 if (IS_ERR(params.vlan)) 7308 return PTR_ERR(params.vlan); 7309 7310 switch (dev->ieee80211_ptr->iftype) { 7311 case NL80211_IFTYPE_AP: 7312 case NL80211_IFTYPE_AP_VLAN: 7313 case NL80211_IFTYPE_P2P_GO: 7314 case NL80211_IFTYPE_P2P_CLIENT: 7315 case NL80211_IFTYPE_STATION: 7316 case NL80211_IFTYPE_ADHOC: 7317 case NL80211_IFTYPE_MESH_POINT: 7318 break; 7319 default: 7320 err = -EOPNOTSUPP; 7321 goto out_put_vlan; 7322 } 7323 7324 /* driver will call cfg80211_check_station_change() */ 7325 err = rdev_change_station(rdev, dev, mac_addr, ¶ms); 7326 7327 out_put_vlan: 7328 dev_put(params.vlan); 7329 7330 return err; 7331 } 7332 7333 static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) 7334 { 7335 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7336 int err; 7337 struct net_device *dev = info->user_ptr[1]; 7338 struct wireless_dev *wdev = dev->ieee80211_ptr; 7339 struct station_parameters params; 7340 u8 *mac_addr = NULL; 7341 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | 7342 BIT(NL80211_STA_FLAG_ASSOCIATED); 7343 7344 memset(¶ms, 0, sizeof(params)); 7345 7346 if (!rdev->ops->add_station) 7347 return -EOPNOTSUPP; 7348 7349 if (!info->attrs[NL80211_ATTR_MAC]) 7350 return -EINVAL; 7351 7352 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) 7353 return -EINVAL; 7354 7355 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 7356 return -EINVAL; 7357 7358 if (!info->attrs[NL80211_ATTR_STA_AID] && 7359 !info->attrs[NL80211_ATTR_PEER_AID]) 7360 return -EINVAL; 7361 7362 params.link_sta_params.link_id = 7363 nl80211_link_id_or_invalid(info->attrs); 7364 7365 if (info->attrs[NL80211_ATTR_MLD_ADDR]) { 7366 mac_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 7367 params.link_sta_params.mld_mac = mac_addr; 7368 params.link_sta_params.link_mac = 7369 nla_data(info->attrs[NL80211_ATTR_MAC]); 7370 if (!is_valid_ether_addr(params.link_sta_params.link_mac)) 7371 return -EINVAL; 7372 } else { 7373 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 7374 } 7375 7376 params.link_sta_params.supported_rates = 7377 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7378 params.link_sta_params.supported_rates_len = 7379 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 7380 params.listen_interval = 7381 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); 7382 7383 if (info->attrs[NL80211_ATTR_VLAN_ID]) 7384 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); 7385 7386 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { 7387 params.support_p2p_ps = 7388 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); 7389 } else { 7390 /* 7391 * if not specified, assume it's supported for P2P GO interface, 7392 * and is NOT supported for AP interface 7393 */ 7394 params.support_p2p_ps = 7395 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; 7396 } 7397 7398 if (info->attrs[NL80211_ATTR_PEER_AID]) 7399 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); 7400 else 7401 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); 7402 7403 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { 7404 params.capability = 7405 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); 7406 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; 7407 } 7408 7409 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { 7410 params.ext_capab = 7411 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7412 params.ext_capab_len = 7413 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); 7414 } 7415 7416 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 7417 params.link_sta_params.ht_capa = 7418 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 7419 7420 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 7421 params.link_sta_params.vht_capa = 7422 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 7423 7424 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 7425 params.link_sta_params.he_capa = 7426 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7427 params.link_sta_params.he_capa_len = 7428 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 7429 7430 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 7431 params.link_sta_params.eht_capa = 7432 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7433 params.link_sta_params.eht_capa_len = 7434 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 7435 7436 if (!ieee80211_eht_capa_size_ok((const u8 *)params.link_sta_params.he_capa, 7437 (const u8 *)params.link_sta_params.eht_capa, 7438 params.link_sta_params.eht_capa_len, 7439 false)) 7440 return -EINVAL; 7441 } 7442 } 7443 7444 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 7445 params.link_sta_params.he_6ghz_capa = 7446 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 7447 7448 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 7449 params.link_sta_params.opmode_notif_used = true; 7450 params.link_sta_params.opmode_notif = 7451 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 7452 } 7453 7454 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) 7455 params.plink_action = 7456 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); 7457 7458 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) 7459 params.airtime_weight = 7460 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); 7461 7462 if (params.airtime_weight && 7463 !wiphy_ext_feature_isset(&rdev->wiphy, 7464 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) 7465 return -EOPNOTSUPP; 7466 7467 err = nl80211_parse_sta_txpower_setting(info, 7468 ¶ms.link_sta_params.txpwr, 7469 ¶ms.link_sta_params.txpwr_set); 7470 if (err) 7471 return err; 7472 7473 err = nl80211_parse_sta_channel_info(info, ¶ms); 7474 if (err) 7475 return err; 7476 7477 err = nl80211_parse_sta_wme(info, ¶ms); 7478 if (err) 7479 return err; 7480 7481 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) 7482 return -EINVAL; 7483 7484 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT 7485 * as userspace might just pass through the capabilities from the IEs 7486 * directly, rather than enforcing this restriction and returning an 7487 * error in this case. 7488 */ 7489 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { 7490 params.link_sta_params.ht_capa = NULL; 7491 params.link_sta_params.vht_capa = NULL; 7492 7493 /* HE and EHT require WME */ 7494 if (params.link_sta_params.he_capa_len || 7495 params.link_sta_params.he_6ghz_capa || 7496 params.link_sta_params.eht_capa_len) 7497 return -EINVAL; 7498 } 7499 7500 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ 7501 if (params.link_sta_params.he_6ghz_capa && 7502 (params.link_sta_params.ht_capa || params.link_sta_params.vht_capa)) 7503 return -EINVAL; 7504 7505 /* When you run into this, adjust the code below for the new flag */ 7506 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); 7507 7508 switch (dev->ieee80211_ptr->iftype) { 7509 case NL80211_IFTYPE_AP: 7510 case NL80211_IFTYPE_AP_VLAN: 7511 case NL80211_IFTYPE_P2P_GO: 7512 /* ignore WME attributes if iface/sta is not capable */ 7513 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || 7514 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) 7515 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7516 7517 /* TDLS peers cannot be added */ 7518 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7519 info->attrs[NL80211_ATTR_PEER_AID]) 7520 return -EINVAL; 7521 /* but don't bother the driver with it */ 7522 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); 7523 7524 /* allow authenticated/associated only if driver handles it */ 7525 if (!(rdev->wiphy.features & 7526 NL80211_FEATURE_FULL_AP_CLIENT_STATE) && 7527 params.sta_flags_mask & auth_assoc) 7528 return -EINVAL; 7529 7530 /* Older userspace, or userspace wanting to be compatible with 7531 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth 7532 * and assoc flags in the mask, but assumes the station will be 7533 * added as associated anyway since this was the required driver 7534 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was 7535 * introduced. 7536 * In order to not bother drivers with this quirk in the API 7537 * set the flags in both the mask and set for new stations in 7538 * this case. 7539 */ 7540 if (!(params.sta_flags_mask & auth_assoc)) { 7541 params.sta_flags_mask |= auth_assoc; 7542 params.sta_flags_set |= auth_assoc; 7543 } 7544 7545 /* must be last in here for error handling */ 7546 params.vlan = get_vlan(info, rdev); 7547 if (IS_ERR(params.vlan)) 7548 return PTR_ERR(params.vlan); 7549 break; 7550 case NL80211_IFTYPE_MESH_POINT: 7551 /* ignore uAPSD data */ 7552 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7553 7554 /* associated is disallowed */ 7555 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) 7556 return -EINVAL; 7557 /* TDLS peers cannot be added */ 7558 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || 7559 info->attrs[NL80211_ATTR_PEER_AID]) 7560 return -EINVAL; 7561 break; 7562 case NL80211_IFTYPE_STATION: 7563 case NL80211_IFTYPE_P2P_CLIENT: 7564 /* ignore uAPSD data */ 7565 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; 7566 7567 /* these are disallowed */ 7568 if (params.sta_flags_mask & 7569 (BIT(NL80211_STA_FLAG_ASSOCIATED) | 7570 BIT(NL80211_STA_FLAG_AUTHENTICATED))) 7571 return -EINVAL; 7572 /* Only TDLS peers can be added */ 7573 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) 7574 return -EINVAL; 7575 /* Can only add if TDLS ... */ 7576 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) 7577 return -EOPNOTSUPP; 7578 /* ... with external setup is supported */ 7579 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) 7580 return -EOPNOTSUPP; 7581 /* 7582 * Older wpa_supplicant versions always mark the TDLS peer 7583 * as authorized, but it shouldn't yet be. 7584 */ 7585 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); 7586 break; 7587 default: 7588 return -EOPNOTSUPP; 7589 } 7590 7591 /* be aware of params.vlan when changing code here */ 7592 7593 if (wdev->valid_links) { 7594 if (params.link_sta_params.link_id < 0) { 7595 err = -EINVAL; 7596 goto out; 7597 } 7598 if (!(wdev->valid_links & BIT(params.link_sta_params.link_id))) { 7599 err = -ENOLINK; 7600 goto out; 7601 } 7602 } else { 7603 if (params.link_sta_params.link_id >= 0) { 7604 err = -EINVAL; 7605 goto out; 7606 } 7607 } 7608 err = rdev_add_station(rdev, dev, mac_addr, ¶ms); 7609 out: 7610 dev_put(params.vlan); 7611 return err; 7612 } 7613 7614 static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) 7615 { 7616 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7617 struct net_device *dev = info->user_ptr[1]; 7618 struct station_del_parameters params; 7619 7620 memset(¶ms, 0, sizeof(params)); 7621 7622 if (info->attrs[NL80211_ATTR_MAC]) 7623 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 7624 7625 switch (dev->ieee80211_ptr->iftype) { 7626 case NL80211_IFTYPE_AP: 7627 case NL80211_IFTYPE_AP_VLAN: 7628 case NL80211_IFTYPE_MESH_POINT: 7629 case NL80211_IFTYPE_P2P_GO: 7630 /* always accept these */ 7631 break; 7632 case NL80211_IFTYPE_ADHOC: 7633 /* conditionally accept */ 7634 if (wiphy_ext_feature_isset(&rdev->wiphy, 7635 NL80211_EXT_FEATURE_DEL_IBSS_STA)) 7636 break; 7637 return -EINVAL; 7638 default: 7639 return -EINVAL; 7640 } 7641 7642 if (!rdev->ops->del_station) 7643 return -EOPNOTSUPP; 7644 7645 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { 7646 params.subtype = 7647 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); 7648 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && 7649 params.subtype != IEEE80211_STYPE_DEAUTH >> 4) 7650 return -EINVAL; 7651 } else { 7652 /* Default to Deauthentication frame */ 7653 params.subtype = IEEE80211_STYPE_DEAUTH >> 4; 7654 } 7655 7656 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 7657 params.reason_code = 7658 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 7659 if (params.reason_code == 0) 7660 return -EINVAL; /* 0 is reserved */ 7661 } else { 7662 /* Default to reason code 2 */ 7663 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; 7664 } 7665 7666 return rdev_del_station(rdev, dev, ¶ms); 7667 } 7668 7669 static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, 7670 int flags, struct net_device *dev, 7671 u8 *dst, u8 *next_hop, 7672 struct mpath_info *pinfo) 7673 { 7674 void *hdr; 7675 struct nlattr *pinfoattr; 7676 7677 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); 7678 if (!hdr) 7679 return -1; 7680 7681 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 7682 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || 7683 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || 7684 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) 7685 goto nla_put_failure; 7686 7687 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); 7688 if (!pinfoattr) 7689 goto nla_put_failure; 7690 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && 7691 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, 7692 pinfo->frame_qlen)) 7693 goto nla_put_failure; 7694 if (((pinfo->filled & MPATH_INFO_SN) && 7695 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || 7696 ((pinfo->filled & MPATH_INFO_METRIC) && 7697 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, 7698 pinfo->metric)) || 7699 ((pinfo->filled & MPATH_INFO_EXPTIME) && 7700 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, 7701 pinfo->exptime)) || 7702 ((pinfo->filled & MPATH_INFO_FLAGS) && 7703 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, 7704 pinfo->flags)) || 7705 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && 7706 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, 7707 pinfo->discovery_timeout)) || 7708 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && 7709 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, 7710 pinfo->discovery_retries)) || 7711 ((pinfo->filled & MPATH_INFO_HOP_COUNT) && 7712 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, 7713 pinfo->hop_count)) || 7714 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && 7715 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, 7716 pinfo->path_change_count))) 7717 goto nla_put_failure; 7718 7719 nla_nest_end(msg, pinfoattr); 7720 7721 genlmsg_end(msg, hdr); 7722 return 0; 7723 7724 nla_put_failure: 7725 genlmsg_cancel(msg, hdr); 7726 return -EMSGSIZE; 7727 } 7728 7729 static int nl80211_dump_mpath(struct sk_buff *skb, 7730 struct netlink_callback *cb) 7731 { 7732 struct mpath_info pinfo; 7733 struct cfg80211_registered_device *rdev; 7734 struct wireless_dev *wdev; 7735 u8 dst[ETH_ALEN]; 7736 u8 next_hop[ETH_ALEN]; 7737 int path_idx = cb->args[2]; 7738 int err; 7739 7740 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7741 if (err) 7742 return err; 7743 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7744 __acquire(&rdev->wiphy.mtx); 7745 7746 if (!rdev->ops->dump_mpath) { 7747 err = -EOPNOTSUPP; 7748 goto out_err; 7749 } 7750 7751 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7752 err = -EOPNOTSUPP; 7753 goto out_err; 7754 } 7755 7756 while (1) { 7757 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, 7758 next_hop, &pinfo); 7759 if (err == -ENOENT) 7760 break; 7761 if (err) 7762 goto out_err; 7763 7764 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7765 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7766 wdev->netdev, dst, next_hop, 7767 &pinfo) < 0) 7768 goto out; 7769 7770 path_idx++; 7771 } 7772 7773 out: 7774 cb->args[2] = path_idx; 7775 err = skb->len; 7776 out_err: 7777 wiphy_unlock(&rdev->wiphy); 7778 return err; 7779 } 7780 7781 static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) 7782 { 7783 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7784 int err; 7785 struct net_device *dev = info->user_ptr[1]; 7786 struct mpath_info pinfo; 7787 struct sk_buff *msg; 7788 u8 *dst = NULL; 7789 u8 next_hop[ETH_ALEN]; 7790 7791 memset(&pinfo, 0, sizeof(pinfo)); 7792 7793 if (!info->attrs[NL80211_ATTR_MAC]) 7794 return -EINVAL; 7795 7796 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7797 7798 if (!rdev->ops->get_mpath) 7799 return -EOPNOTSUPP; 7800 7801 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7802 return -EOPNOTSUPP; 7803 7804 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); 7805 if (err) 7806 return err; 7807 7808 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7809 if (!msg) 7810 return -ENOMEM; 7811 7812 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7813 dev, dst, next_hop, &pinfo) < 0) { 7814 nlmsg_free(msg); 7815 return -ENOBUFS; 7816 } 7817 7818 return genlmsg_reply(msg, info); 7819 } 7820 7821 static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) 7822 { 7823 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7824 struct net_device *dev = info->user_ptr[1]; 7825 u8 *dst = NULL; 7826 u8 *next_hop = NULL; 7827 7828 if (!info->attrs[NL80211_ATTR_MAC]) 7829 return -EINVAL; 7830 7831 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7832 return -EINVAL; 7833 7834 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7835 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7836 7837 if (!rdev->ops->change_mpath) 7838 return -EOPNOTSUPP; 7839 7840 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7841 return -EOPNOTSUPP; 7842 7843 return rdev_change_mpath(rdev, dev, dst, next_hop); 7844 } 7845 7846 static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) 7847 { 7848 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7849 struct net_device *dev = info->user_ptr[1]; 7850 u8 *dst = NULL; 7851 u8 *next_hop = NULL; 7852 7853 if (!info->attrs[NL80211_ATTR_MAC]) 7854 return -EINVAL; 7855 7856 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) 7857 return -EINVAL; 7858 7859 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7860 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); 7861 7862 if (!rdev->ops->add_mpath) 7863 return -EOPNOTSUPP; 7864 7865 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7866 return -EOPNOTSUPP; 7867 7868 return rdev_add_mpath(rdev, dev, dst, next_hop); 7869 } 7870 7871 static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) 7872 { 7873 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7874 struct net_device *dev = info->user_ptr[1]; 7875 u8 *dst = NULL; 7876 7877 if (info->attrs[NL80211_ATTR_MAC]) 7878 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7879 7880 if (!rdev->ops->del_mpath) 7881 return -EOPNOTSUPP; 7882 7883 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7884 return -EOPNOTSUPP; 7885 7886 return rdev_del_mpath(rdev, dev, dst); 7887 } 7888 7889 static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) 7890 { 7891 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7892 int err; 7893 struct net_device *dev = info->user_ptr[1]; 7894 struct mpath_info pinfo; 7895 struct sk_buff *msg; 7896 u8 *dst = NULL; 7897 u8 mpp[ETH_ALEN]; 7898 7899 memset(&pinfo, 0, sizeof(pinfo)); 7900 7901 if (!info->attrs[NL80211_ATTR_MAC]) 7902 return -EINVAL; 7903 7904 dst = nla_data(info->attrs[NL80211_ATTR_MAC]); 7905 7906 if (!rdev->ops->get_mpp) 7907 return -EOPNOTSUPP; 7908 7909 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) 7910 return -EOPNOTSUPP; 7911 7912 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); 7913 if (err) 7914 return err; 7915 7916 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 7917 if (!msg) 7918 return -ENOMEM; 7919 7920 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, 7921 dev, dst, mpp, &pinfo) < 0) { 7922 nlmsg_free(msg); 7923 return -ENOBUFS; 7924 } 7925 7926 return genlmsg_reply(msg, info); 7927 } 7928 7929 static int nl80211_dump_mpp(struct sk_buff *skb, 7930 struct netlink_callback *cb) 7931 { 7932 struct mpath_info pinfo; 7933 struct cfg80211_registered_device *rdev; 7934 struct wireless_dev *wdev; 7935 u8 dst[ETH_ALEN]; 7936 u8 mpp[ETH_ALEN]; 7937 int path_idx = cb->args[2]; 7938 int err; 7939 7940 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 7941 if (err) 7942 return err; 7943 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 7944 __acquire(&rdev->wiphy.mtx); 7945 7946 if (!rdev->ops->dump_mpp) { 7947 err = -EOPNOTSUPP; 7948 goto out_err; 7949 } 7950 7951 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { 7952 err = -EOPNOTSUPP; 7953 goto out_err; 7954 } 7955 7956 while (1) { 7957 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, 7958 mpp, &pinfo); 7959 if (err == -ENOENT) 7960 break; 7961 if (err) 7962 goto out_err; 7963 7964 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, 7965 cb->nlh->nlmsg_seq, NLM_F_MULTI, 7966 wdev->netdev, dst, mpp, 7967 &pinfo) < 0) 7968 goto out; 7969 7970 path_idx++; 7971 } 7972 7973 out: 7974 cb->args[2] = path_idx; 7975 err = skb->len; 7976 out_err: 7977 wiphy_unlock(&rdev->wiphy); 7978 return err; 7979 } 7980 7981 static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) 7982 { 7983 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 7984 struct net_device *dev = info->user_ptr[1]; 7985 struct bss_parameters params; 7986 7987 memset(¶ms, 0, sizeof(params)); 7988 params.link_id = nl80211_link_id_or_invalid(info->attrs); 7989 /* default to not changing parameters */ 7990 params.use_cts_prot = -1; 7991 params.use_short_preamble = -1; 7992 params.use_short_slot_time = -1; 7993 params.ap_isolate = -1; 7994 params.ht_opmode = -1; 7995 params.p2p_ctwindow = -1; 7996 params.p2p_opp_ps = -1; 7997 7998 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 7999 params.use_cts_prot = 8000 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); 8001 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) 8002 params.use_short_preamble = 8003 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); 8004 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) 8005 params.use_short_slot_time = 8006 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); 8007 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 8008 params.basic_rates = 8009 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 8010 params.basic_rates_len = 8011 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 8012 } 8013 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 8014 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 8015 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) 8016 params.ht_opmode = 8017 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); 8018 8019 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { 8020 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8021 return -EINVAL; 8022 params.p2p_ctwindow = 8023 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); 8024 if (params.p2p_ctwindow != 0 && 8025 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) 8026 return -EINVAL; 8027 } 8028 8029 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { 8030 u8 tmp; 8031 8032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8033 return -EINVAL; 8034 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); 8035 params.p2p_opp_ps = tmp; 8036 if (params.p2p_opp_ps && 8037 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) 8038 return -EINVAL; 8039 } 8040 8041 if (!rdev->ops->change_bss) 8042 return -EOPNOTSUPP; 8043 8044 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 8045 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 8046 return -EOPNOTSUPP; 8047 8048 return rdev_change_bss(rdev, dev, ¶ms); 8049 } 8050 8051 static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) 8052 { 8053 char *data = NULL; 8054 bool is_indoor; 8055 enum nl80211_user_reg_hint_type user_reg_hint_type; 8056 u32 owner_nlportid; 8057 8058 /* 8059 * You should only get this when cfg80211 hasn't yet initialized 8060 * completely when built-in to the kernel right between the time 8061 * window between nl80211_init() and regulatory_init(), if that is 8062 * even possible. 8063 */ 8064 if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) 8065 return -EINPROGRESS; 8066 8067 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) 8068 user_reg_hint_type = 8069 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); 8070 else 8071 user_reg_hint_type = NL80211_USER_REG_HINT_USER; 8072 8073 switch (user_reg_hint_type) { 8074 case NL80211_USER_REG_HINT_USER: 8075 case NL80211_USER_REG_HINT_CELL_BASE: 8076 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 8077 return -EINVAL; 8078 8079 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 8080 return regulatory_hint_user(data, user_reg_hint_type); 8081 case NL80211_USER_REG_HINT_INDOOR: 8082 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 8083 owner_nlportid = info->snd_portid; 8084 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; 8085 } else { 8086 owner_nlportid = 0; 8087 is_indoor = true; 8088 } 8089 8090 return regulatory_hint_indoor(is_indoor, owner_nlportid); 8091 default: 8092 return -EINVAL; 8093 } 8094 } 8095 8096 static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) 8097 { 8098 return reg_reload_regdb(); 8099 } 8100 8101 static int nl80211_get_mesh_config(struct sk_buff *skb, 8102 struct genl_info *info) 8103 { 8104 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8105 struct net_device *dev = info->user_ptr[1]; 8106 struct wireless_dev *wdev = dev->ieee80211_ptr; 8107 struct mesh_config cur_params; 8108 int err = 0; 8109 void *hdr; 8110 struct nlattr *pinfoattr; 8111 struct sk_buff *msg; 8112 8113 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 8114 return -EOPNOTSUPP; 8115 8116 if (!rdev->ops->get_mesh_config) 8117 return -EOPNOTSUPP; 8118 8119 /* If not connected, get default parameters */ 8120 if (!wdev->u.mesh.id_len) 8121 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); 8122 else 8123 err = rdev_get_mesh_config(rdev, dev, &cur_params); 8124 8125 if (err) 8126 return err; 8127 8128 /* Draw up a netlink message to send back */ 8129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 8130 if (!msg) 8131 return -ENOMEM; 8132 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 8133 NL80211_CMD_GET_MESH_CONFIG); 8134 if (!hdr) 8135 goto out; 8136 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); 8137 if (!pinfoattr) 8138 goto nla_put_failure; 8139 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 8140 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, 8141 cur_params.dot11MeshRetryTimeout) || 8142 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, 8143 cur_params.dot11MeshConfirmTimeout) || 8144 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, 8145 cur_params.dot11MeshHoldingTimeout) || 8146 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, 8147 cur_params.dot11MeshMaxPeerLinks) || 8148 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, 8149 cur_params.dot11MeshMaxRetries) || 8150 nla_put_u8(msg, NL80211_MESHCONF_TTL, 8151 cur_params.dot11MeshTTL) || 8152 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, 8153 cur_params.element_ttl) || 8154 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 8155 cur_params.auto_open_plinks) || 8156 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 8157 cur_params.dot11MeshNbrOffsetMaxNeighbor) || 8158 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 8159 cur_params.dot11MeshHWMPmaxPREQretries) || 8160 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, 8161 cur_params.path_refresh_time) || 8162 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 8163 cur_params.min_discovery_timeout) || 8164 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 8165 cur_params.dot11MeshHWMPactivePathTimeout) || 8166 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 8167 cur_params.dot11MeshHWMPpreqMinInterval) || 8168 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 8169 cur_params.dot11MeshHWMPperrMinInterval) || 8170 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 8171 cur_params.dot11MeshHWMPnetDiameterTraversalTime) || 8172 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, 8173 cur_params.dot11MeshHWMPRootMode) || 8174 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, 8175 cur_params.dot11MeshHWMPRannInterval) || 8176 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 8177 cur_params.dot11MeshGateAnnouncementProtocol) || 8178 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, 8179 cur_params.dot11MeshForwarding) || 8180 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, 8181 cur_params.rssi_threshold) || 8182 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, 8183 cur_params.ht_opmode) || 8184 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 8185 cur_params.dot11MeshHWMPactivePathToRootTimeout) || 8186 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 8187 cur_params.dot11MeshHWMProotInterval) || 8188 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 8189 cur_params.dot11MeshHWMPconfirmationInterval) || 8190 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, 8191 cur_params.power_mode) || 8192 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, 8193 cur_params.dot11MeshAwakeWindowDuration) || 8194 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, 8195 cur_params.plink_timeout) || 8196 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, 8197 cur_params.dot11MeshConnectedToMeshGate) || 8198 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, 8199 cur_params.dot11MeshNolearn) || 8200 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, 8201 cur_params.dot11MeshConnectedToAuthServer)) 8202 goto nla_put_failure; 8203 nla_nest_end(msg, pinfoattr); 8204 genlmsg_end(msg, hdr); 8205 return genlmsg_reply(msg, info); 8206 8207 nla_put_failure: 8208 out: 8209 nlmsg_free(msg); 8210 return -ENOBUFS; 8211 } 8212 8213 static const struct nla_policy 8214 nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 8215 [NL80211_MESHCONF_RETRY_TIMEOUT] = 8216 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8217 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = 8218 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8219 [NL80211_MESHCONF_HOLDING_TIMEOUT] = 8220 NLA_POLICY_RANGE(NLA_U16, 1, 255), 8221 [NL80211_MESHCONF_MAX_PEER_LINKS] = 8222 NLA_POLICY_RANGE(NLA_U16, 0, 255), 8223 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), 8224 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8225 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), 8226 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), 8227 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = 8228 NLA_POLICY_RANGE(NLA_U32, 1, 255), 8229 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 8230 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, 8231 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), 8232 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, 8233 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = 8234 NLA_POLICY_MIN(NLA_U16, 1), 8235 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = 8236 NLA_POLICY_MIN(NLA_U16, 1), 8237 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = 8238 NLA_POLICY_MIN(NLA_U16, 1), 8239 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), 8240 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = 8241 NLA_POLICY_MIN(NLA_U16, 1), 8242 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), 8243 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), 8244 [NL80211_MESHCONF_RSSI_THRESHOLD] = 8245 NLA_POLICY_RANGE(NLA_S32, -255, 0), 8246 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, 8247 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, 8248 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = 8249 NLA_POLICY_MIN(NLA_U16, 1), 8250 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = 8251 NLA_POLICY_MIN(NLA_U16, 1), 8252 [NL80211_MESHCONF_POWER_MODE] = 8253 NLA_POLICY_RANGE(NLA_U32, 8254 NL80211_MESH_POWER_ACTIVE, 8255 NL80211_MESH_POWER_MAX), 8256 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, 8257 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, 8258 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8259 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8260 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), 8261 }; 8262 8263 static const struct nla_policy 8264 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { 8265 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, 8266 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, 8267 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, 8268 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, 8269 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, 8270 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, 8271 [NL80211_MESH_SETUP_IE] = 8272 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, 8273 IEEE80211_MAX_DATA_LEN), 8274 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, 8275 }; 8276 8277 static int nl80211_parse_mesh_config(struct genl_info *info, 8278 struct mesh_config *cfg, 8279 u32 *mask_out) 8280 { 8281 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 8282 u32 mask = 0; 8283 u16 ht_opmode; 8284 8285 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ 8286 do { \ 8287 if (tb[attr]) { \ 8288 cfg->param = fn(tb[attr]); \ 8289 mask |= BIT((attr) - 1); \ 8290 } \ 8291 } while (0) 8292 8293 if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) 8294 return -EINVAL; 8295 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) 8296 return -EINVAL; 8297 8298 /* This makes sure that there aren't more than 32 mesh config 8299 * parameters (otherwise our bitfield scheme would not work.) */ 8300 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 8301 8302 /* Fill in the params struct */ 8303 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, 8304 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 8305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, 8306 NL80211_MESHCONF_CONFIRM_TIMEOUT, 8307 nla_get_u16); 8308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, 8309 NL80211_MESHCONF_HOLDING_TIMEOUT, 8310 nla_get_u16); 8311 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, 8312 NL80211_MESHCONF_MAX_PEER_LINKS, 8313 nla_get_u16); 8314 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, 8315 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 8316 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, 8317 NL80211_MESHCONF_TTL, nla_get_u8); 8318 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, 8319 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); 8320 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, 8321 NL80211_MESHCONF_AUTO_OPEN_PLINKS, 8322 nla_get_u8); 8323 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, 8324 mask, 8325 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, 8326 nla_get_u32); 8327 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, 8328 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 8329 nla_get_u8); 8330 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, 8331 NL80211_MESHCONF_PATH_REFRESH_TIME, 8332 nla_get_u32); 8333 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && 8334 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) 8335 return -EINVAL; 8336 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, 8337 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, 8338 nla_get_u16); 8339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, 8340 mask, 8341 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, 8342 nla_get_u32); 8343 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && 8344 (cfg->dot11MeshHWMPactivePathTimeout < 1 || 8345 cfg->dot11MeshHWMPactivePathTimeout > 65535)) 8346 return -EINVAL; 8347 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, 8348 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, 8349 nla_get_u16); 8350 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, 8351 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, 8352 nla_get_u16); 8353 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8354 dot11MeshHWMPnetDiameterTraversalTime, mask, 8355 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 8356 nla_get_u16); 8357 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, 8358 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); 8359 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, 8360 NL80211_MESHCONF_HWMP_RANN_INTERVAL, 8361 nla_get_u16); 8362 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, 8363 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, 8364 nla_get_u8); 8365 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, 8366 NL80211_MESHCONF_FORWARDING, nla_get_u8); 8367 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, 8368 NL80211_MESHCONF_RSSI_THRESHOLD, 8369 nla_get_s32); 8370 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, 8371 NL80211_MESHCONF_CONNECTED_TO_GATE, 8372 nla_get_u8); 8373 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, 8374 NL80211_MESHCONF_CONNECTED_TO_AS, 8375 nla_get_u8); 8376 /* 8377 * Check HT operation mode based on 8378 * IEEE 802.11-2016 9.4.2.57 HT Operation element. 8379 */ 8380 if (tb[NL80211_MESHCONF_HT_OPMODE]) { 8381 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); 8382 8383 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | 8384 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | 8385 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) 8386 return -EINVAL; 8387 8388 /* NON_HT_STA bit is reserved, but some programs set it */ 8389 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; 8390 8391 cfg->ht_opmode = ht_opmode; 8392 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); 8393 } 8394 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, 8395 dot11MeshHWMPactivePathToRootTimeout, mask, 8396 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, 8397 nla_get_u32); 8398 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && 8399 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || 8400 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) 8401 return -EINVAL; 8402 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, 8403 NL80211_MESHCONF_HWMP_ROOT_INTERVAL, 8404 nla_get_u16); 8405 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, 8406 mask, 8407 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, 8408 nla_get_u16); 8409 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, 8410 NL80211_MESHCONF_POWER_MODE, nla_get_u32); 8411 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, 8412 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); 8413 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, 8414 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); 8415 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, 8416 NL80211_MESHCONF_NOLEARN, nla_get_u8); 8417 if (mask_out) 8418 *mask_out = mask; 8419 8420 return 0; 8421 8422 #undef FILL_IN_MESH_PARAM_IF_SET 8423 } 8424 8425 static int nl80211_parse_mesh_setup(struct genl_info *info, 8426 struct mesh_setup *setup) 8427 { 8428 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8429 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; 8430 8431 if (!info->attrs[NL80211_ATTR_MESH_SETUP]) 8432 return -EINVAL; 8433 if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) 8434 return -EINVAL; 8435 8436 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) 8437 setup->sync_method = 8438 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? 8439 IEEE80211_SYNC_METHOD_VENDOR : 8440 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; 8441 8442 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) 8443 setup->path_sel_proto = 8444 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? 8445 IEEE80211_PATH_PROTOCOL_VENDOR : 8446 IEEE80211_PATH_PROTOCOL_HWMP; 8447 8448 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) 8449 setup->path_metric = 8450 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? 8451 IEEE80211_PATH_METRIC_VENDOR : 8452 IEEE80211_PATH_METRIC_AIRTIME; 8453 8454 if (tb[NL80211_MESH_SETUP_IE]) { 8455 struct nlattr *ieattr = 8456 tb[NL80211_MESH_SETUP_IE]; 8457 setup->ie = nla_data(ieattr); 8458 setup->ie_len = nla_len(ieattr); 8459 } 8460 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && 8461 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) 8462 return -EINVAL; 8463 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); 8464 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); 8465 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); 8466 if (setup->is_secure) 8467 setup->user_mpm = true; 8468 8469 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { 8470 if (!setup->user_mpm) 8471 return -EINVAL; 8472 setup->auth_id = 8473 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); 8474 } 8475 8476 return 0; 8477 } 8478 8479 static int nl80211_update_mesh_config(struct sk_buff *skb, 8480 struct genl_info *info) 8481 { 8482 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 8483 struct net_device *dev = info->user_ptr[1]; 8484 struct wireless_dev *wdev = dev->ieee80211_ptr; 8485 struct mesh_config cfg = {}; 8486 u32 mask; 8487 int err; 8488 8489 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 8490 return -EOPNOTSUPP; 8491 8492 if (!rdev->ops->update_mesh_config) 8493 return -EOPNOTSUPP; 8494 8495 err = nl80211_parse_mesh_config(info, &cfg, &mask); 8496 if (err) 8497 return err; 8498 8499 if (!wdev->u.mesh.id_len) 8500 err = -ENOLINK; 8501 8502 if (!err) 8503 err = rdev_update_mesh_config(rdev, dev, mask, &cfg); 8504 8505 return err; 8506 } 8507 8508 static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, 8509 struct sk_buff *msg) 8510 { 8511 struct nlattr *nl_reg_rules; 8512 unsigned int i; 8513 8514 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || 8515 (regdom->dfs_region && 8516 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) 8517 goto nla_put_failure; 8518 8519 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); 8520 if (!nl_reg_rules) 8521 goto nla_put_failure; 8522 8523 for (i = 0; i < regdom->n_reg_rules; i++) { 8524 struct nlattr *nl_reg_rule; 8525 const struct ieee80211_reg_rule *reg_rule; 8526 const struct ieee80211_freq_range *freq_range; 8527 const struct ieee80211_power_rule *power_rule; 8528 unsigned int max_bandwidth_khz; 8529 8530 reg_rule = ®dom->reg_rules[i]; 8531 freq_range = ®_rule->freq_range; 8532 power_rule = ®_rule->power_rule; 8533 8534 nl_reg_rule = nla_nest_start_noflag(msg, i); 8535 if (!nl_reg_rule) 8536 goto nla_put_failure; 8537 8538 max_bandwidth_khz = freq_range->max_bandwidth_khz; 8539 if (!max_bandwidth_khz) 8540 max_bandwidth_khz = reg_get_max_bandwidth(regdom, 8541 reg_rule); 8542 8543 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, 8544 reg_rule->flags) || 8545 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, 8546 freq_range->start_freq_khz) || 8547 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, 8548 freq_range->end_freq_khz) || 8549 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, 8550 max_bandwidth_khz) || 8551 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, 8552 power_rule->max_antenna_gain) || 8553 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, 8554 power_rule->max_eirp) || 8555 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, 8556 reg_rule->dfs_cac_ms)) 8557 goto nla_put_failure; 8558 8559 if ((reg_rule->flags & NL80211_RRF_PSD) && 8560 nla_put_s8(msg, NL80211_ATTR_POWER_RULE_PSD, 8561 reg_rule->psd)) 8562 goto nla_put_failure; 8563 8564 nla_nest_end(msg, nl_reg_rule); 8565 } 8566 8567 nla_nest_end(msg, nl_reg_rules); 8568 return 0; 8569 8570 nla_put_failure: 8571 return -EMSGSIZE; 8572 } 8573 8574 static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) 8575 { 8576 const struct ieee80211_regdomain *regdom = NULL; 8577 struct cfg80211_registered_device *rdev; 8578 struct wiphy *wiphy = NULL; 8579 struct sk_buff *msg; 8580 int err = -EMSGSIZE; 8581 void *hdr; 8582 8583 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 8584 if (!msg) 8585 return -ENOBUFS; 8586 8587 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 8588 NL80211_CMD_GET_REG); 8589 if (!hdr) 8590 goto put_failure; 8591 8592 rtnl_lock(); 8593 8594 if (info->attrs[NL80211_ATTR_WIPHY]) { 8595 bool self_managed; 8596 8597 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 8598 if (IS_ERR(rdev)) { 8599 err = PTR_ERR(rdev); 8600 goto nla_put_failure; 8601 } 8602 8603 wiphy = &rdev->wiphy; 8604 self_managed = wiphy->regulatory_flags & 8605 REGULATORY_WIPHY_SELF_MANAGED; 8606 8607 rcu_read_lock(); 8608 8609 regdom = get_wiphy_regdom(wiphy); 8610 8611 /* a self-managed-reg device must have a private regdom */ 8612 if (WARN_ON(!regdom && self_managed)) { 8613 err = -EINVAL; 8614 goto nla_put_failure_rcu; 8615 } 8616 8617 if (regdom && 8618 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8619 goto nla_put_failure_rcu; 8620 } else { 8621 rcu_read_lock(); 8622 } 8623 8624 if (!wiphy && reg_last_request_cell_base() && 8625 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8626 NL80211_USER_REG_HINT_CELL_BASE)) 8627 goto nla_put_failure_rcu; 8628 8629 if (!regdom) 8630 regdom = rcu_dereference(cfg80211_regdomain); 8631 8632 if (nl80211_put_regdom(regdom, msg)) 8633 goto nla_put_failure_rcu; 8634 8635 rcu_read_unlock(); 8636 8637 genlmsg_end(msg, hdr); 8638 rtnl_unlock(); 8639 return genlmsg_reply(msg, info); 8640 8641 nla_put_failure_rcu: 8642 rcu_read_unlock(); 8643 nla_put_failure: 8644 rtnl_unlock(); 8645 put_failure: 8646 nlmsg_free(msg); 8647 return err; 8648 } 8649 8650 static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, 8651 u32 seq, int flags, struct wiphy *wiphy, 8652 const struct ieee80211_regdomain *regdom) 8653 { 8654 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 8655 NL80211_CMD_GET_REG); 8656 8657 if (!hdr) 8658 return -1; 8659 8660 genl_dump_check_consistent(cb, hdr); 8661 8662 if (nl80211_put_regdom(regdom, msg)) 8663 goto nla_put_failure; 8664 8665 if (!wiphy && reg_last_request_cell_base() && 8666 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, 8667 NL80211_USER_REG_HINT_CELL_BASE)) 8668 goto nla_put_failure; 8669 8670 if (wiphy && 8671 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 8672 goto nla_put_failure; 8673 8674 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 8675 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 8676 goto nla_put_failure; 8677 8678 genlmsg_end(msg, hdr); 8679 return 0; 8680 8681 nla_put_failure: 8682 genlmsg_cancel(msg, hdr); 8683 return -EMSGSIZE; 8684 } 8685 8686 static int nl80211_get_reg_dump(struct sk_buff *skb, 8687 struct netlink_callback *cb) 8688 { 8689 const struct ieee80211_regdomain *regdom = NULL; 8690 struct cfg80211_registered_device *rdev; 8691 int err, reg_idx, start = cb->args[2]; 8692 8693 rcu_read_lock(); 8694 8695 if (cfg80211_regdomain && start == 0) { 8696 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8697 NLM_F_MULTI, NULL, 8698 rcu_dereference(cfg80211_regdomain)); 8699 if (err < 0) 8700 goto out_err; 8701 } 8702 8703 /* the global regdom is idx 0 */ 8704 reg_idx = 1; 8705 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 8706 regdom = get_wiphy_regdom(&rdev->wiphy); 8707 if (!regdom) 8708 continue; 8709 8710 if (++reg_idx <= start) 8711 continue; 8712 8713 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, 8714 NLM_F_MULTI, &rdev->wiphy, regdom); 8715 if (err < 0) { 8716 reg_idx--; 8717 break; 8718 } 8719 } 8720 8721 cb->args[2] = reg_idx; 8722 err = skb->len; 8723 out_err: 8724 rcu_read_unlock(); 8725 return err; 8726 } 8727 8728 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 8729 static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { 8730 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, 8731 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, 8732 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, 8733 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, 8734 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, 8735 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, 8736 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, 8737 }; 8738 8739 static int parse_reg_rule(struct nlattr *tb[], 8740 struct ieee80211_reg_rule *reg_rule) 8741 { 8742 struct ieee80211_freq_range *freq_range = ®_rule->freq_range; 8743 struct ieee80211_power_rule *power_rule = ®_rule->power_rule; 8744 8745 if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) 8746 return -EINVAL; 8747 if (!tb[NL80211_ATTR_FREQ_RANGE_START]) 8748 return -EINVAL; 8749 if (!tb[NL80211_ATTR_FREQ_RANGE_END]) 8750 return -EINVAL; 8751 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) 8752 return -EINVAL; 8753 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) 8754 return -EINVAL; 8755 8756 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); 8757 8758 freq_range->start_freq_khz = 8759 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); 8760 freq_range->end_freq_khz = 8761 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); 8762 freq_range->max_bandwidth_khz = 8763 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); 8764 8765 power_rule->max_eirp = 8766 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); 8767 8768 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) 8769 power_rule->max_antenna_gain = 8770 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); 8771 8772 if (tb[NL80211_ATTR_DFS_CAC_TIME]) 8773 reg_rule->dfs_cac_ms = 8774 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); 8775 8776 return 0; 8777 } 8778 8779 static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) 8780 { 8781 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; 8782 struct nlattr *nl_reg_rule; 8783 char *alpha2; 8784 int rem_reg_rules, r; 8785 u32 num_rules = 0, rule_idx = 0; 8786 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; 8787 struct ieee80211_regdomain *rd; 8788 8789 if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) 8790 return -EINVAL; 8791 8792 if (!info->attrs[NL80211_ATTR_REG_RULES]) 8793 return -EINVAL; 8794 8795 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); 8796 8797 if (info->attrs[NL80211_ATTR_DFS_REGION]) 8798 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); 8799 8800 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8801 rem_reg_rules) { 8802 num_rules++; 8803 if (num_rules > NL80211_MAX_SUPP_REG_RULES) 8804 return -EINVAL; 8805 } 8806 8807 rtnl_lock(); 8808 if (!reg_is_valid_request(alpha2)) { 8809 r = -EINVAL; 8810 goto out; 8811 } 8812 8813 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); 8814 if (!rd) { 8815 r = -ENOMEM; 8816 goto out; 8817 } 8818 8819 rd->n_reg_rules = num_rules; 8820 rd->alpha2[0] = alpha2[0]; 8821 rd->alpha2[1] = alpha2[1]; 8822 8823 /* 8824 * Disable DFS master mode if the DFS region was 8825 * not supported or known on this kernel. 8826 */ 8827 if (reg_supported_dfs_region(dfs_region)) 8828 rd->dfs_region = dfs_region; 8829 8830 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], 8831 rem_reg_rules) { 8832 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, 8833 nl_reg_rule, reg_rule_policy, 8834 info->extack); 8835 if (r) 8836 goto bad_reg; 8837 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); 8838 if (r) 8839 goto bad_reg; 8840 8841 rule_idx++; 8842 8843 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { 8844 r = -EINVAL; 8845 goto bad_reg; 8846 } 8847 } 8848 8849 r = set_regdom(rd, REGD_SOURCE_CRDA); 8850 /* set_regdom takes ownership of rd */ 8851 rd = NULL; 8852 bad_reg: 8853 kfree(rd); 8854 out: 8855 rtnl_unlock(); 8856 return r; 8857 } 8858 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ 8859 8860 static int validate_scan_freqs(struct nlattr *freqs) 8861 { 8862 struct nlattr *attr1, *attr2; 8863 int n_channels = 0, tmp1, tmp2; 8864 8865 nla_for_each_nested(attr1, freqs, tmp1) 8866 if (nla_len(attr1) != sizeof(u32)) 8867 return 0; 8868 8869 nla_for_each_nested(attr1, freqs, tmp1) { 8870 n_channels++; 8871 /* 8872 * Some hardware has a limited channel list for 8873 * scanning, and it is pretty much nonsensical 8874 * to scan for a channel twice, so disallow that 8875 * and don't require drivers to check that the 8876 * channel list they get isn't longer than what 8877 * they can scan, as long as they can scan all 8878 * the channels they registered at once. 8879 */ 8880 nla_for_each_nested(attr2, freqs, tmp2) 8881 if (attr1 != attr2 && 8882 nla_get_u32(attr1) == nla_get_u32(attr2)) 8883 return 0; 8884 } 8885 8886 return n_channels; 8887 } 8888 8889 static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) 8890 { 8891 return b < NUM_NL80211_BANDS && wiphy->bands[b]; 8892 } 8893 8894 static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, 8895 struct cfg80211_bss_selection *bss_select) 8896 { 8897 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; 8898 struct nlattr *nest; 8899 int err; 8900 bool found = false; 8901 int i; 8902 8903 /* only process one nested attribute */ 8904 nest = nla_data(nla); 8905 if (!nla_ok(nest, nla_len(nest))) 8906 return -EINVAL; 8907 8908 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, 8909 nest, nl80211_bss_select_policy, 8910 NULL); 8911 if (err) 8912 return err; 8913 8914 /* only one attribute may be given */ 8915 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { 8916 if (attr[i]) { 8917 if (found) 8918 return -EINVAL; 8919 found = true; 8920 } 8921 } 8922 8923 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; 8924 8925 if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) 8926 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; 8927 8928 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { 8929 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; 8930 bss_select->param.band_pref = 8931 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); 8932 if (!is_band_valid(wiphy, bss_select->param.band_pref)) 8933 return -EINVAL; 8934 } 8935 8936 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { 8937 struct nl80211_bss_select_rssi_adjust *adj_param; 8938 8939 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); 8940 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; 8941 bss_select->param.adjust.band = adj_param->band; 8942 bss_select->param.adjust.delta = adj_param->delta; 8943 if (!is_band_valid(wiphy, bss_select->param.adjust.band)) 8944 return -EINVAL; 8945 } 8946 8947 /* user-space did not provide behaviour attribute */ 8948 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) 8949 return -EINVAL; 8950 8951 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) 8952 return -EINVAL; 8953 8954 return 0; 8955 } 8956 8957 int nl80211_parse_random_mac(struct nlattr **attrs, 8958 u8 *mac_addr, u8 *mac_addr_mask) 8959 { 8960 int i; 8961 8962 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { 8963 eth_zero_addr(mac_addr); 8964 eth_zero_addr(mac_addr_mask); 8965 mac_addr[0] = 0x2; 8966 mac_addr_mask[0] = 0x3; 8967 8968 return 0; 8969 } 8970 8971 /* need both or none */ 8972 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) 8973 return -EINVAL; 8974 8975 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); 8976 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); 8977 8978 /* don't allow or configure an mcast address */ 8979 if (!is_multicast_ether_addr(mac_addr_mask) || 8980 is_multicast_ether_addr(mac_addr)) 8981 return -EINVAL; 8982 8983 /* 8984 * allow users to pass a MAC address that has bits set outside 8985 * of the mask, but don't bother drivers with having to deal 8986 * with such bits 8987 */ 8988 for (i = 0; i < ETH_ALEN; i++) 8989 mac_addr[i] &= mac_addr_mask[i]; 8990 8991 return 0; 8992 } 8993 8994 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev, 8995 struct ieee80211_channel *chan) 8996 { 8997 unsigned int link_id; 8998 bool all_ok = true; 8999 9000 lockdep_assert_wiphy(wdev->wiphy); 9001 9002 if (!cfg80211_beaconing_iface_active(wdev)) 9003 return true; 9004 9005 /* 9006 * FIXME: check if we have a free HW resource/link for chan 9007 * 9008 * This, as well as the FIXME below, requires knowing the link 9009 * capabilities of the hardware. 9010 */ 9011 9012 /* we cannot leave radar channels */ 9013 for_each_valid_link(wdev, link_id) { 9014 struct cfg80211_chan_def *chandef; 9015 9016 chandef = wdev_chandef(wdev, link_id); 9017 if (!chandef || !chandef->chan) 9018 continue; 9019 9020 /* 9021 * FIXME: don't require all_ok, but rather check only the 9022 * correct HW resource/link onto which 'chan' falls, 9023 * as only that link leaves the channel for doing 9024 * the off-channel operation. 9025 */ 9026 9027 if (chandef->chan->flags & IEEE80211_CHAN_RADAR) 9028 all_ok = false; 9029 } 9030 9031 if (all_ok) 9032 return true; 9033 9034 return regulatory_pre_cac_allowed(wdev->wiphy); 9035 } 9036 9037 static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, 9038 enum nl80211_ext_feature_index feat) 9039 { 9040 if (!(flags & flag)) 9041 return true; 9042 if (wiphy_ext_feature_isset(wiphy, feat)) 9043 return true; 9044 return false; 9045 } 9046 9047 static int 9048 nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, 9049 void *request, struct nlattr **attrs, 9050 bool is_sched_scan) 9051 { 9052 u8 *mac_addr, *mac_addr_mask; 9053 u32 *flags; 9054 enum nl80211_feature_flags randomness_flag; 9055 9056 if (!attrs[NL80211_ATTR_SCAN_FLAGS]) 9057 return 0; 9058 9059 if (is_sched_scan) { 9060 struct cfg80211_sched_scan_request *req = request; 9061 9062 randomness_flag = wdev ? 9063 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : 9064 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 9065 flags = &req->flags; 9066 mac_addr = req->mac_addr; 9067 mac_addr_mask = req->mac_addr_mask; 9068 } else { 9069 struct cfg80211_scan_request *req = request; 9070 9071 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; 9072 flags = &req->flags; 9073 mac_addr = req->mac_addr; 9074 mac_addr_mask = req->mac_addr_mask; 9075 } 9076 9077 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); 9078 9079 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && 9080 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || 9081 !nl80211_check_scan_feat(wiphy, *flags, 9082 NL80211_SCAN_FLAG_LOW_SPAN, 9083 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || 9084 !nl80211_check_scan_feat(wiphy, *flags, 9085 NL80211_SCAN_FLAG_LOW_POWER, 9086 NL80211_EXT_FEATURE_LOW_POWER_SCAN) || 9087 !nl80211_check_scan_feat(wiphy, *flags, 9088 NL80211_SCAN_FLAG_HIGH_ACCURACY, 9089 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || 9090 !nl80211_check_scan_feat(wiphy, *flags, 9091 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, 9092 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || 9093 !nl80211_check_scan_feat(wiphy, *flags, 9094 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, 9095 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || 9096 !nl80211_check_scan_feat(wiphy, *flags, 9097 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, 9098 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || 9099 !nl80211_check_scan_feat(wiphy, *flags, 9100 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, 9101 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || 9102 !nl80211_check_scan_feat(wiphy, *flags, 9103 NL80211_SCAN_FLAG_RANDOM_SN, 9104 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || 9105 !nl80211_check_scan_feat(wiphy, *flags, 9106 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, 9107 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) 9108 return -EOPNOTSUPP; 9109 9110 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { 9111 int err; 9112 9113 if (!(wiphy->features & randomness_flag) || 9114 (wdev && wdev->connected)) 9115 return -EOPNOTSUPP; 9116 9117 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); 9118 if (err) 9119 return err; 9120 } 9121 9122 return 0; 9123 } 9124 9125 static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) 9126 { 9127 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9128 struct wireless_dev *wdev = info->user_ptr[1]; 9129 struct cfg80211_scan_request *request; 9130 struct nlattr *scan_freqs = NULL; 9131 bool scan_freqs_khz = false; 9132 struct nlattr *attr; 9133 struct wiphy *wiphy; 9134 int err, tmp, n_ssids = 0, n_channels, i; 9135 size_t ie_len, size; 9136 9137 wiphy = &rdev->wiphy; 9138 9139 if (wdev->iftype == NL80211_IFTYPE_NAN) 9140 return -EOPNOTSUPP; 9141 9142 if (!rdev->ops->scan) 9143 return -EOPNOTSUPP; 9144 9145 if (rdev->scan_req || rdev->scan_msg) 9146 return -EBUSY; 9147 9148 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { 9149 if (!wiphy_ext_feature_isset(wiphy, 9150 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) 9151 return -EOPNOTSUPP; 9152 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; 9153 scan_freqs_khz = true; 9154 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) 9155 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; 9156 9157 if (scan_freqs) { 9158 n_channels = validate_scan_freqs(scan_freqs); 9159 if (!n_channels) 9160 return -EINVAL; 9161 } else { 9162 n_channels = ieee80211_get_num_supported_channels(wiphy); 9163 } 9164 9165 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) 9166 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) 9167 n_ssids++; 9168 9169 if (n_ssids > wiphy->max_scan_ssids) 9170 return -EINVAL; 9171 9172 if (info->attrs[NL80211_ATTR_IE]) 9173 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9174 else 9175 ie_len = 0; 9176 9177 if (ie_len > wiphy->max_scan_ie_len) 9178 return -EINVAL; 9179 9180 size = struct_size(request, channels, n_channels); 9181 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids)); 9182 size = size_add(size, ie_len); 9183 request = kzalloc(size, GFP_KERNEL); 9184 if (!request) 9185 return -ENOMEM; 9186 9187 if (n_ssids) 9188 request->ssids = (void *)&request->channels[n_channels]; 9189 request->n_ssids = n_ssids; 9190 if (ie_len) { 9191 if (n_ssids) 9192 request->ie = (void *)(request->ssids + n_ssids); 9193 else 9194 request->ie = (void *)(request->channels + n_channels); 9195 } 9196 9197 i = 0; 9198 if (scan_freqs) { 9199 /* user specified, bail out if channel not found */ 9200 nla_for_each_nested(attr, scan_freqs, tmp) { 9201 struct ieee80211_channel *chan; 9202 int freq = nla_get_u32(attr); 9203 9204 if (!scan_freqs_khz) 9205 freq = MHZ_TO_KHZ(freq); 9206 9207 chan = ieee80211_get_channel_khz(wiphy, freq); 9208 if (!chan) { 9209 err = -EINVAL; 9210 goto out_free; 9211 } 9212 9213 /* ignore disabled channels */ 9214 if (chan->flags & IEEE80211_CHAN_DISABLED) 9215 continue; 9216 9217 request->channels[i] = chan; 9218 i++; 9219 } 9220 } else { 9221 enum nl80211_band band; 9222 9223 /* all channels */ 9224 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9225 int j; 9226 9227 if (!wiphy->bands[band]) 9228 continue; 9229 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9230 struct ieee80211_channel *chan; 9231 9232 chan = &wiphy->bands[band]->channels[j]; 9233 9234 if (chan->flags & IEEE80211_CHAN_DISABLED) 9235 continue; 9236 9237 request->channels[i] = chan; 9238 i++; 9239 } 9240 } 9241 } 9242 9243 if (!i) { 9244 err = -EINVAL; 9245 goto out_free; 9246 } 9247 9248 request->n_channels = i; 9249 9250 for (i = 0; i < request->n_channels; i++) { 9251 struct ieee80211_channel *chan = request->channels[i]; 9252 9253 /* if we can go off-channel to the target channel we're good */ 9254 if (cfg80211_off_channel_oper_allowed(wdev, chan)) 9255 continue; 9256 9257 if (!cfg80211_wdev_on_sub_chan(wdev, chan, true)) { 9258 err = -EBUSY; 9259 goto out_free; 9260 } 9261 } 9262 9263 i = 0; 9264 if (n_ssids) { 9265 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { 9266 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9267 err = -EINVAL; 9268 goto out_free; 9269 } 9270 request->ssids[i].ssid_len = nla_len(attr); 9271 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); 9272 i++; 9273 } 9274 } 9275 9276 if (info->attrs[NL80211_ATTR_IE]) { 9277 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 9278 memcpy((void *)request->ie, 9279 nla_data(info->attrs[NL80211_ATTR_IE]), 9280 request->ie_len); 9281 } 9282 9283 for (i = 0; i < NUM_NL80211_BANDS; i++) 9284 if (wiphy->bands[i]) 9285 request->rates[i] = 9286 (1 << wiphy->bands[i]->n_bitrates) - 1; 9287 9288 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { 9289 nla_for_each_nested(attr, 9290 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], 9291 tmp) { 9292 enum nl80211_band band = nla_type(attr); 9293 9294 if (band < 0 || band >= NUM_NL80211_BANDS) { 9295 err = -EINVAL; 9296 goto out_free; 9297 } 9298 9299 if (!wiphy->bands[band]) 9300 continue; 9301 9302 err = ieee80211_get_ratemask(wiphy->bands[band], 9303 nla_data(attr), 9304 nla_len(attr), 9305 &request->rates[band]); 9306 if (err) 9307 goto out_free; 9308 } 9309 } 9310 9311 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { 9312 request->duration = 9313 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); 9314 request->duration_mandatory = 9315 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); 9316 } 9317 9318 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, 9319 false); 9320 if (err) 9321 goto out_free; 9322 9323 request->no_cck = 9324 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 9325 9326 /* Initial implementation used NL80211_ATTR_MAC to set the specific 9327 * BSSID to scan for. This was problematic because that same attribute 9328 * was already used for another purpose (local random MAC address). The 9329 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards 9330 * compatibility with older userspace components, also use the 9331 * NL80211_ATTR_MAC value here if it can be determined to be used for 9332 * the specific BSSID use case instead of the random MAC address 9333 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). 9334 */ 9335 if (info->attrs[NL80211_ATTR_BSSID]) 9336 memcpy(request->bssid, 9337 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); 9338 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && 9339 info->attrs[NL80211_ATTR_MAC]) 9340 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), 9341 ETH_ALEN); 9342 else 9343 eth_broadcast_addr(request->bssid); 9344 9345 request->tsf_report_link_id = nl80211_link_id_or_invalid(info->attrs); 9346 request->wdev = wdev; 9347 request->wiphy = &rdev->wiphy; 9348 request->scan_start = jiffies; 9349 9350 rdev->scan_req = request; 9351 err = cfg80211_scan(rdev); 9352 9353 if (err) 9354 goto out_free; 9355 9356 nl80211_send_scan_start(rdev, wdev); 9357 dev_hold(wdev->netdev); 9358 9359 return 0; 9360 9361 out_free: 9362 rdev->scan_req = NULL; 9363 kfree(request); 9364 9365 return err; 9366 } 9367 9368 static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) 9369 { 9370 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9371 struct wireless_dev *wdev = info->user_ptr[1]; 9372 9373 if (!rdev->ops->abort_scan) 9374 return -EOPNOTSUPP; 9375 9376 if (rdev->scan_msg) 9377 return 0; 9378 9379 if (!rdev->scan_req) 9380 return -ENOENT; 9381 9382 rdev_abort_scan(rdev, wdev); 9383 return 0; 9384 } 9385 9386 static int 9387 nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, 9388 struct cfg80211_sched_scan_request *request, 9389 struct nlattr **attrs) 9390 { 9391 int tmp, err, i = 0; 9392 struct nlattr *attr; 9393 9394 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9395 u32 interval; 9396 9397 /* 9398 * If scan plans are not specified, 9399 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this 9400 * case one scan plan will be set with the specified scan 9401 * interval and infinite number of iterations. 9402 */ 9403 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); 9404 if (!interval) 9405 return -EINVAL; 9406 9407 request->scan_plans[0].interval = 9408 DIV_ROUND_UP(interval, MSEC_PER_SEC); 9409 if (!request->scan_plans[0].interval) 9410 return -EINVAL; 9411 9412 if (request->scan_plans[0].interval > 9413 wiphy->max_sched_scan_plan_interval) 9414 request->scan_plans[0].interval = 9415 wiphy->max_sched_scan_plan_interval; 9416 9417 return 0; 9418 } 9419 9420 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { 9421 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; 9422 9423 if (WARN_ON(i >= n_plans)) 9424 return -EINVAL; 9425 9426 err = nla_parse_nested_deprecated(plan, 9427 NL80211_SCHED_SCAN_PLAN_MAX, 9428 attr, nl80211_plan_policy, 9429 NULL); 9430 if (err) 9431 return err; 9432 9433 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) 9434 return -EINVAL; 9435 9436 request->scan_plans[i].interval = 9437 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); 9438 if (!request->scan_plans[i].interval || 9439 request->scan_plans[i].interval > 9440 wiphy->max_sched_scan_plan_interval) 9441 return -EINVAL; 9442 9443 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { 9444 request->scan_plans[i].iterations = 9445 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); 9446 if (!request->scan_plans[i].iterations || 9447 (request->scan_plans[i].iterations > 9448 wiphy->max_sched_scan_plan_iterations)) 9449 return -EINVAL; 9450 } else if (i < n_plans - 1) { 9451 /* 9452 * All scan plans but the last one must specify 9453 * a finite number of iterations 9454 */ 9455 return -EINVAL; 9456 } 9457 9458 i++; 9459 } 9460 9461 /* 9462 * The last scan plan must not specify the number of 9463 * iterations, it is supposed to run infinitely 9464 */ 9465 if (request->scan_plans[n_plans - 1].iterations) 9466 return -EINVAL; 9467 9468 return 0; 9469 } 9470 9471 static int 9472 nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, 9473 struct cfg80211_match_set *match_sets, 9474 struct nlattr *tb_band_rssi, 9475 s32 rssi_thold) 9476 { 9477 struct nlattr *attr; 9478 int i, tmp, ret = 0; 9479 9480 if (!wiphy_ext_feature_isset(wiphy, 9481 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { 9482 if (tb_band_rssi) 9483 ret = -EOPNOTSUPP; 9484 else 9485 for (i = 0; i < NUM_NL80211_BANDS; i++) 9486 match_sets->per_band_rssi_thold[i] = 9487 NL80211_SCAN_RSSI_THOLD_OFF; 9488 return ret; 9489 } 9490 9491 for (i = 0; i < NUM_NL80211_BANDS; i++) 9492 match_sets->per_band_rssi_thold[i] = rssi_thold; 9493 9494 nla_for_each_nested(attr, tb_band_rssi, tmp) { 9495 enum nl80211_band band = nla_type(attr); 9496 9497 if (band < 0 || band >= NUM_NL80211_BANDS) 9498 return -EINVAL; 9499 9500 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); 9501 } 9502 9503 return 0; 9504 } 9505 9506 static struct cfg80211_sched_scan_request * 9507 nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, 9508 struct nlattr **attrs, int max_match_sets) 9509 { 9510 struct cfg80211_sched_scan_request *request; 9511 struct nlattr *attr; 9512 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; 9513 enum nl80211_band band; 9514 size_t ie_len, size; 9515 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; 9516 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; 9517 9518 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9519 n_channels = validate_scan_freqs( 9520 attrs[NL80211_ATTR_SCAN_FREQUENCIES]); 9521 if (!n_channels) 9522 return ERR_PTR(-EINVAL); 9523 } else { 9524 n_channels = ieee80211_get_num_supported_channels(wiphy); 9525 } 9526 9527 if (attrs[NL80211_ATTR_SCAN_SSIDS]) 9528 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9529 tmp) 9530 n_ssids++; 9531 9532 if (n_ssids > wiphy->max_sched_scan_ssids) 9533 return ERR_PTR(-EINVAL); 9534 9535 /* 9536 * First, count the number of 'real' matchsets. Due to an issue with 9537 * the old implementation, matchsets containing only the RSSI attribute 9538 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' 9539 * RSSI for all matchsets, rather than their own matchset for reporting 9540 * all APs with a strong RSSI. This is needed to be compatible with 9541 * older userspace that treated a matchset with only the RSSI as the 9542 * global RSSI for all other matchsets - if there are other matchsets. 9543 */ 9544 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9545 nla_for_each_nested(attr, 9546 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9547 tmp) { 9548 struct nlattr *rssi; 9549 9550 err = nla_parse_nested_deprecated(tb, 9551 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9552 attr, 9553 nl80211_match_policy, 9554 NULL); 9555 if (err) 9556 return ERR_PTR(err); 9557 9558 /* SSID and BSSID are mutually exclusive */ 9559 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && 9560 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) 9561 return ERR_PTR(-EINVAL); 9562 9563 /* add other standalone attributes here */ 9564 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || 9565 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { 9566 n_match_sets++; 9567 continue; 9568 } 9569 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9570 if (rssi) 9571 default_match_rssi = nla_get_s32(rssi); 9572 } 9573 } 9574 9575 /* However, if there's no other matchset, add the RSSI one */ 9576 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) 9577 n_match_sets = 1; 9578 9579 if (n_match_sets > max_match_sets) 9580 return ERR_PTR(-EINVAL); 9581 9582 if (attrs[NL80211_ATTR_IE]) 9583 ie_len = nla_len(attrs[NL80211_ATTR_IE]); 9584 else 9585 ie_len = 0; 9586 9587 if (ie_len > wiphy->max_sched_scan_ie_len) 9588 return ERR_PTR(-EINVAL); 9589 9590 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { 9591 /* 9592 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since 9593 * each scan plan already specifies its own interval 9594 */ 9595 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9596 return ERR_PTR(-EINVAL); 9597 9598 nla_for_each_nested(attr, 9599 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) 9600 n_plans++; 9601 } else { 9602 /* 9603 * The scan interval attribute is kept for backward 9604 * compatibility. If no scan plans are specified and sched scan 9605 * interval is specified, one scan plan will be set with this 9606 * scan interval and infinite number of iterations. 9607 */ 9608 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) 9609 return ERR_PTR(-EINVAL); 9610 9611 n_plans = 1; 9612 } 9613 9614 if (!n_plans || n_plans > wiphy->max_sched_scan_plans) 9615 return ERR_PTR(-EINVAL); 9616 9617 if (!wiphy_ext_feature_isset( 9618 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && 9619 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || 9620 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) 9621 return ERR_PTR(-EINVAL); 9622 9623 size = struct_size(request, channels, n_channels); 9624 size = size_add(size, array_size(sizeof(*request->ssids), n_ssids)); 9625 size = size_add(size, array_size(sizeof(*request->match_sets), 9626 n_match_sets)); 9627 size = size_add(size, array_size(sizeof(*request->scan_plans), 9628 n_plans)); 9629 size = size_add(size, ie_len); 9630 request = kzalloc(size, GFP_KERNEL); 9631 if (!request) 9632 return ERR_PTR(-ENOMEM); 9633 9634 if (n_ssids) 9635 request->ssids = (void *)&request->channels[n_channels]; 9636 request->n_ssids = n_ssids; 9637 if (ie_len) { 9638 if (n_ssids) 9639 request->ie = (void *)(request->ssids + n_ssids); 9640 else 9641 request->ie = (void *)(request->channels + n_channels); 9642 } 9643 9644 if (n_match_sets) { 9645 if (request->ie) 9646 request->match_sets = (void *)(request->ie + ie_len); 9647 else if (n_ssids) 9648 request->match_sets = 9649 (void *)(request->ssids + n_ssids); 9650 else 9651 request->match_sets = 9652 (void *)(request->channels + n_channels); 9653 } 9654 request->n_match_sets = n_match_sets; 9655 9656 if (n_match_sets) 9657 request->scan_plans = (void *)(request->match_sets + 9658 n_match_sets); 9659 else if (request->ie) 9660 request->scan_plans = (void *)(request->ie + ie_len); 9661 else if (n_ssids) 9662 request->scan_plans = (void *)(request->ssids + n_ssids); 9663 else 9664 request->scan_plans = (void *)(request->channels + n_channels); 9665 9666 request->n_scan_plans = n_plans; 9667 9668 i = 0; 9669 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { 9670 /* user specified, bail out if channel not found */ 9671 nla_for_each_nested(attr, 9672 attrs[NL80211_ATTR_SCAN_FREQUENCIES], 9673 tmp) { 9674 struct ieee80211_channel *chan; 9675 9676 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); 9677 9678 if (!chan) { 9679 err = -EINVAL; 9680 goto out_free; 9681 } 9682 9683 /* ignore disabled channels */ 9684 if (chan->flags & IEEE80211_CHAN_DISABLED) 9685 continue; 9686 9687 request->channels[i] = chan; 9688 i++; 9689 } 9690 } else { 9691 /* all channels */ 9692 for (band = 0; band < NUM_NL80211_BANDS; band++) { 9693 int j; 9694 9695 if (!wiphy->bands[band]) 9696 continue; 9697 for (j = 0; j < wiphy->bands[band]->n_channels; j++) { 9698 struct ieee80211_channel *chan; 9699 9700 chan = &wiphy->bands[band]->channels[j]; 9701 9702 if (chan->flags & IEEE80211_CHAN_DISABLED) 9703 continue; 9704 9705 request->channels[i] = chan; 9706 i++; 9707 } 9708 } 9709 } 9710 9711 if (!i) { 9712 err = -EINVAL; 9713 goto out_free; 9714 } 9715 9716 request->n_channels = i; 9717 9718 i = 0; 9719 if (n_ssids) { 9720 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], 9721 tmp) { 9722 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { 9723 err = -EINVAL; 9724 goto out_free; 9725 } 9726 request->ssids[i].ssid_len = nla_len(attr); 9727 memcpy(request->ssids[i].ssid, nla_data(attr), 9728 nla_len(attr)); 9729 i++; 9730 } 9731 } 9732 9733 i = 0; 9734 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { 9735 nla_for_each_nested(attr, 9736 attrs[NL80211_ATTR_SCHED_SCAN_MATCH], 9737 tmp) { 9738 struct nlattr *ssid, *bssid, *rssi; 9739 9740 err = nla_parse_nested_deprecated(tb, 9741 NL80211_SCHED_SCAN_MATCH_ATTR_MAX, 9742 attr, 9743 nl80211_match_policy, 9744 NULL); 9745 if (err) 9746 goto out_free; 9747 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; 9748 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; 9749 9750 if (!ssid && !bssid) { 9751 i++; 9752 continue; 9753 } 9754 9755 if (WARN_ON(i >= n_match_sets)) { 9756 /* this indicates a programming error, 9757 * the loop above should have verified 9758 * things properly 9759 */ 9760 err = -EINVAL; 9761 goto out_free; 9762 } 9763 9764 if (ssid) { 9765 memcpy(request->match_sets[i].ssid.ssid, 9766 nla_data(ssid), nla_len(ssid)); 9767 request->match_sets[i].ssid.ssid_len = 9768 nla_len(ssid); 9769 } 9770 if (bssid) 9771 memcpy(request->match_sets[i].bssid, 9772 nla_data(bssid), ETH_ALEN); 9773 9774 /* special attribute - old implementation w/a */ 9775 request->match_sets[i].rssi_thold = default_match_rssi; 9776 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; 9777 if (rssi) 9778 request->match_sets[i].rssi_thold = 9779 nla_get_s32(rssi); 9780 9781 /* Parse per band RSSI attribute */ 9782 err = nl80211_parse_sched_scan_per_band_rssi(wiphy, 9783 &request->match_sets[i], 9784 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], 9785 request->match_sets[i].rssi_thold); 9786 if (err) 9787 goto out_free; 9788 9789 i++; 9790 } 9791 9792 /* there was no other matchset, so the RSSI one is alone */ 9793 if (i == 0 && n_match_sets) 9794 request->match_sets[0].rssi_thold = default_match_rssi; 9795 9796 request->min_rssi_thold = INT_MAX; 9797 for (i = 0; i < n_match_sets; i++) 9798 request->min_rssi_thold = 9799 min(request->match_sets[i].rssi_thold, 9800 request->min_rssi_thold); 9801 } else { 9802 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; 9803 } 9804 9805 if (ie_len) { 9806 request->ie_len = ie_len; 9807 memcpy((void *)request->ie, 9808 nla_data(attrs[NL80211_ATTR_IE]), 9809 request->ie_len); 9810 } 9811 9812 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); 9813 if (err) 9814 goto out_free; 9815 9816 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) 9817 request->delay = 9818 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); 9819 9820 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { 9821 request->relative_rssi = nla_get_s8( 9822 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); 9823 request->relative_rssi_set = true; 9824 } 9825 9826 if (request->relative_rssi_set && 9827 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { 9828 struct nl80211_bss_select_rssi_adjust *rssi_adjust; 9829 9830 rssi_adjust = nla_data( 9831 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); 9832 request->rssi_adjust.band = rssi_adjust->band; 9833 request->rssi_adjust.delta = rssi_adjust->delta; 9834 if (!is_band_valid(wiphy, request->rssi_adjust.band)) { 9835 err = -EINVAL; 9836 goto out_free; 9837 } 9838 } 9839 9840 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); 9841 if (err) 9842 goto out_free; 9843 9844 request->scan_start = jiffies; 9845 9846 return request; 9847 9848 out_free: 9849 kfree(request); 9850 return ERR_PTR(err); 9851 } 9852 9853 static int nl80211_start_sched_scan(struct sk_buff *skb, 9854 struct genl_info *info) 9855 { 9856 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9857 struct net_device *dev = info->user_ptr[1]; 9858 struct wireless_dev *wdev = dev->ieee80211_ptr; 9859 struct cfg80211_sched_scan_request *sched_scan_req; 9860 bool want_multi; 9861 int err; 9862 9863 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) 9864 return -EOPNOTSUPP; 9865 9866 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; 9867 err = cfg80211_sched_scan_req_possible(rdev, want_multi); 9868 if (err) 9869 return err; 9870 9871 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, 9872 info->attrs, 9873 rdev->wiphy.max_match_sets); 9874 9875 err = PTR_ERR_OR_ZERO(sched_scan_req); 9876 if (err) 9877 goto out_err; 9878 9879 /* leave request id zero for legacy request 9880 * or if driver does not support multi-scheduled scan 9881 */ 9882 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) 9883 sched_scan_req->reqid = cfg80211_assign_cookie(rdev); 9884 9885 err = rdev_sched_scan_start(rdev, dev, sched_scan_req); 9886 if (err) 9887 goto out_free; 9888 9889 sched_scan_req->dev = dev; 9890 sched_scan_req->wiphy = &rdev->wiphy; 9891 9892 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 9893 sched_scan_req->owner_nlportid = info->snd_portid; 9894 9895 cfg80211_add_sched_scan_req(rdev, sched_scan_req); 9896 9897 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); 9898 return 0; 9899 9900 out_free: 9901 kfree(sched_scan_req); 9902 out_err: 9903 return err; 9904 } 9905 9906 static int nl80211_stop_sched_scan(struct sk_buff *skb, 9907 struct genl_info *info) 9908 { 9909 struct cfg80211_sched_scan_request *req; 9910 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9911 u64 cookie; 9912 9913 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) 9914 return -EOPNOTSUPP; 9915 9916 if (info->attrs[NL80211_ATTR_COOKIE]) { 9917 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 9918 return __cfg80211_stop_sched_scan(rdev, cookie, false); 9919 } 9920 9921 req = list_first_or_null_rcu(&rdev->sched_scan_req_list, 9922 struct cfg80211_sched_scan_request, 9923 list); 9924 if (!req || req->reqid || 9925 (req->owner_nlportid && 9926 req->owner_nlportid != info->snd_portid)) 9927 return -ENOENT; 9928 9929 return cfg80211_stop_sched_scan_req(rdev, req, false); 9930 } 9931 9932 static int nl80211_start_radar_detection(struct sk_buff *skb, 9933 struct genl_info *info) 9934 { 9935 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 9936 struct net_device *dev = info->user_ptr[1]; 9937 struct wireless_dev *wdev = dev->ieee80211_ptr; 9938 struct wiphy *wiphy = wdev->wiphy; 9939 struct cfg80211_chan_def chandef; 9940 enum nl80211_dfs_regions dfs_region; 9941 unsigned int cac_time_ms; 9942 int err = -EINVAL; 9943 9944 flush_delayed_work(&rdev->dfs_update_channels_wk); 9945 9946 wiphy_lock(wiphy); 9947 9948 dfs_region = reg_get_dfs_region(wiphy); 9949 if (dfs_region == NL80211_DFS_UNSET) 9950 goto unlock; 9951 9952 err = nl80211_parse_chandef(rdev, info, &chandef); 9953 if (err) 9954 goto unlock; 9955 9956 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 9957 if (err < 0) 9958 goto unlock; 9959 9960 if (err == 0) { 9961 err = -EINVAL; 9962 goto unlock; 9963 } 9964 9965 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) { 9966 err = -EINVAL; 9967 goto unlock; 9968 } 9969 9970 if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_BACKGROUND])) { 9971 err = cfg80211_start_background_radar_detection(rdev, wdev, 9972 &chandef); 9973 goto unlock; 9974 } 9975 9976 if (netif_carrier_ok(dev)) { 9977 err = -EBUSY; 9978 goto unlock; 9979 } 9980 9981 if (wdev->cac_started) { 9982 err = -EBUSY; 9983 goto unlock; 9984 } 9985 9986 /* CAC start is offloaded to HW and can't be started manually */ 9987 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) { 9988 err = -EOPNOTSUPP; 9989 goto unlock; 9990 } 9991 9992 if (!rdev->ops->start_radar_detection) { 9993 err = -EOPNOTSUPP; 9994 goto unlock; 9995 } 9996 9997 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); 9998 if (WARN_ON(!cac_time_ms)) 9999 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; 10000 10001 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); 10002 if (!err) { 10003 wdev->links[0].ap.chandef = chandef; 10004 wdev->cac_started = true; 10005 wdev->cac_start_time = jiffies; 10006 wdev->cac_time_ms = cac_time_ms; 10007 } 10008 unlock: 10009 wiphy_unlock(wiphy); 10010 10011 return err; 10012 } 10013 10014 static int nl80211_notify_radar_detection(struct sk_buff *skb, 10015 struct genl_info *info) 10016 { 10017 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10018 struct net_device *dev = info->user_ptr[1]; 10019 struct wireless_dev *wdev = dev->ieee80211_ptr; 10020 struct wiphy *wiphy = wdev->wiphy; 10021 struct cfg80211_chan_def chandef; 10022 enum nl80211_dfs_regions dfs_region; 10023 int err; 10024 10025 dfs_region = reg_get_dfs_region(wiphy); 10026 if (dfs_region == NL80211_DFS_UNSET) { 10027 GENL_SET_ERR_MSG(info, 10028 "DFS Region is not set. Unexpected Radar indication"); 10029 return -EINVAL; 10030 } 10031 10032 err = nl80211_parse_chandef(rdev, info, &chandef); 10033 if (err) { 10034 GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); 10035 return err; 10036 } 10037 10038 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); 10039 if (err < 0) { 10040 GENL_SET_ERR_MSG(info, "chandef is invalid"); 10041 return err; 10042 } 10043 10044 if (err == 0) { 10045 GENL_SET_ERR_MSG(info, 10046 "Unexpected Radar indication for chandef/iftype"); 10047 return -EINVAL; 10048 } 10049 10050 /* Do not process this notification if radar is already detected 10051 * by kernel on this channel, and return success. 10052 */ 10053 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) 10054 return 0; 10055 10056 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); 10057 10058 cfg80211_sched_dfs_chan_update(rdev); 10059 10060 rdev->radar_chandef = chandef; 10061 10062 /* Propagate this notification to other radios as well */ 10063 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); 10064 10065 return 0; 10066 } 10067 10068 static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) 10069 { 10070 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10071 unsigned int link_id = nl80211_link_id(info->attrs); 10072 struct net_device *dev = info->user_ptr[1]; 10073 struct wireless_dev *wdev = dev->ieee80211_ptr; 10074 struct cfg80211_csa_settings params; 10075 struct nlattr **csa_attrs = NULL; 10076 int err; 10077 bool need_new_beacon = false; 10078 bool need_handle_dfs_flag = true; 10079 int len, i; 10080 u32 cs_count; 10081 10082 if (!rdev->ops->channel_switch || 10083 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) 10084 return -EOPNOTSUPP; 10085 10086 switch (dev->ieee80211_ptr->iftype) { 10087 case NL80211_IFTYPE_AP: 10088 case NL80211_IFTYPE_P2P_GO: 10089 need_new_beacon = true; 10090 /* For all modes except AP the handle_dfs flag needs to be 10091 * supplied to tell the kernel that userspace will handle radar 10092 * events when they happen. Otherwise a switch to a channel 10093 * requiring DFS will be rejected. 10094 */ 10095 need_handle_dfs_flag = false; 10096 10097 /* useless if AP is not running */ 10098 if (!wdev->links[link_id].ap.beacon_interval) 10099 return -ENOTCONN; 10100 break; 10101 case NL80211_IFTYPE_ADHOC: 10102 if (!wdev->u.ibss.ssid_len) 10103 return -ENOTCONN; 10104 break; 10105 case NL80211_IFTYPE_MESH_POINT: 10106 if (!wdev->u.mesh.id_len) 10107 return -ENOTCONN; 10108 break; 10109 default: 10110 return -EOPNOTSUPP; 10111 } 10112 10113 memset(¶ms, 0, sizeof(params)); 10114 params.beacon_csa.ftm_responder = -1; 10115 10116 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 10117 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) 10118 return -EINVAL; 10119 10120 /* only important for AP, IBSS and mesh create IEs internally */ 10121 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) 10122 return -EINVAL; 10123 10124 /* Even though the attribute is u32, the specification says 10125 * u8, so let's make sure we don't overflow. 10126 */ 10127 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); 10128 if (cs_count > 255) 10129 return -EINVAL; 10130 10131 params.count = cs_count; 10132 10133 if (!need_new_beacon) 10134 goto skip_beacons; 10135 10136 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after, 10137 info->extack); 10138 if (err) 10139 goto free; 10140 10141 csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), 10142 GFP_KERNEL); 10143 if (!csa_attrs) { 10144 err = -ENOMEM; 10145 goto free; 10146 } 10147 10148 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, 10149 info->attrs[NL80211_ATTR_CSA_IES], 10150 nl80211_policy, info->extack); 10151 if (err) 10152 goto free; 10153 10154 err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa, 10155 info->extack); 10156 if (err) 10157 goto free; 10158 10159 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 10160 err = -EINVAL; 10161 goto free; 10162 } 10163 10164 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 10165 if (!len || (len % sizeof(u16))) { 10166 err = -EINVAL; 10167 goto free; 10168 } 10169 10170 params.n_counter_offsets_beacon = len / sizeof(u16); 10171 if (rdev->wiphy.max_num_csa_counters && 10172 (params.n_counter_offsets_beacon > 10173 rdev->wiphy.max_num_csa_counters)) { 10174 err = -EINVAL; 10175 goto free; 10176 } 10177 10178 params.counter_offsets_beacon = 10179 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 10180 10181 /* sanity checks - counters should fit and be the same */ 10182 for (i = 0; i < params.n_counter_offsets_beacon; i++) { 10183 u16 offset = params.counter_offsets_beacon[i]; 10184 10185 if (offset >= params.beacon_csa.tail_len) { 10186 err = -EINVAL; 10187 goto free; 10188 } 10189 10190 if (params.beacon_csa.tail[offset] != params.count) { 10191 err = -EINVAL; 10192 goto free; 10193 } 10194 } 10195 10196 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 10197 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 10198 if (!len || (len % sizeof(u16))) { 10199 err = -EINVAL; 10200 goto free; 10201 } 10202 10203 params.n_counter_offsets_presp = len / sizeof(u16); 10204 if (rdev->wiphy.max_num_csa_counters && 10205 (params.n_counter_offsets_presp > 10206 rdev->wiphy.max_num_csa_counters)) { 10207 err = -EINVAL; 10208 goto free; 10209 } 10210 10211 params.counter_offsets_presp = 10212 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 10213 10214 /* sanity checks - counters should fit and be the same */ 10215 for (i = 0; i < params.n_counter_offsets_presp; i++) { 10216 u16 offset = params.counter_offsets_presp[i]; 10217 10218 if (offset >= params.beacon_csa.probe_resp_len) { 10219 err = -EINVAL; 10220 goto free; 10221 } 10222 10223 if (params.beacon_csa.probe_resp[offset] != 10224 params.count) { 10225 err = -EINVAL; 10226 goto free; 10227 } 10228 } 10229 } 10230 10231 skip_beacons: 10232 err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); 10233 if (err) 10234 goto free; 10235 10236 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, 10237 wdev->iftype)) { 10238 err = -EINVAL; 10239 goto free; 10240 } 10241 10242 err = cfg80211_chandef_dfs_required(wdev->wiphy, 10243 ¶ms.chandef, 10244 wdev->iftype); 10245 if (err < 0) 10246 goto free; 10247 10248 if (err > 0) { 10249 params.radar_required = true; 10250 if (need_handle_dfs_flag && 10251 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { 10252 err = -EINVAL; 10253 goto free; 10254 } 10255 } 10256 10257 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) 10258 params.block_tx = true; 10259 10260 if (info->attrs[NL80211_ATTR_PUNCT_BITMAP]) { 10261 err = nl80211_parse_punct_bitmap(rdev, info, 10262 ¶ms.chandef, 10263 ¶ms.punct_bitmap); 10264 if (err) 10265 goto free; 10266 } 10267 10268 err = rdev_channel_switch(rdev, dev, ¶ms); 10269 10270 free: 10271 kfree(params.beacon_after.mbssid_ies); 10272 kfree(params.beacon_csa.mbssid_ies); 10273 kfree(params.beacon_after.rnr_ies); 10274 kfree(params.beacon_csa.rnr_ies); 10275 kfree(csa_attrs); 10276 return err; 10277 } 10278 10279 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, 10280 u32 seq, int flags, 10281 struct cfg80211_registered_device *rdev, 10282 struct wireless_dev *wdev, 10283 struct cfg80211_internal_bss *intbss) 10284 { 10285 struct cfg80211_bss *res = &intbss->pub; 10286 const struct cfg80211_bss_ies *ies; 10287 unsigned int link_id; 10288 void *hdr; 10289 struct nlattr *bss; 10290 10291 lockdep_assert_wiphy(wdev->wiphy); 10292 10293 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, 10294 NL80211_CMD_NEW_SCAN_RESULTS); 10295 if (!hdr) 10296 return -1; 10297 10298 genl_dump_check_consistent(cb, hdr); 10299 10300 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) 10301 goto nla_put_failure; 10302 if (wdev->netdev && 10303 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) 10304 goto nla_put_failure; 10305 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 10306 NL80211_ATTR_PAD)) 10307 goto nla_put_failure; 10308 10309 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); 10310 if (!bss) 10311 goto nla_put_failure; 10312 if ((!is_zero_ether_addr(res->bssid) && 10313 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) 10314 goto nla_put_failure; 10315 10316 rcu_read_lock(); 10317 /* indicate whether we have probe response data or not */ 10318 if (rcu_access_pointer(res->proberesp_ies) && 10319 nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) 10320 goto fail_unlock_rcu; 10321 10322 /* this pointer prefers to be pointed to probe response data 10323 * but is always valid 10324 */ 10325 ies = rcu_dereference(res->ies); 10326 if (ies) { 10327 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, 10328 NL80211_BSS_PAD)) 10329 goto fail_unlock_rcu; 10330 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, 10331 ies->len, ies->data)) 10332 goto fail_unlock_rcu; 10333 } 10334 10335 /* and this pointer is always (unless driver didn't know) beacon data */ 10336 ies = rcu_dereference(res->beacon_ies); 10337 if (ies && ies->from_beacon) { 10338 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, 10339 NL80211_BSS_PAD)) 10340 goto fail_unlock_rcu; 10341 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, 10342 ies->len, ies->data)) 10343 goto fail_unlock_rcu; 10344 } 10345 rcu_read_unlock(); 10346 10347 if (res->beacon_interval && 10348 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) 10349 goto nla_put_failure; 10350 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || 10351 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || 10352 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, 10353 res->channel->freq_offset) || 10354 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, 10355 jiffies_to_msecs(jiffies - intbss->ts))) 10356 goto nla_put_failure; 10357 10358 if (intbss->parent_tsf && 10359 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, 10360 intbss->parent_tsf, NL80211_BSS_PAD) || 10361 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, 10362 intbss->parent_bssid))) 10363 goto nla_put_failure; 10364 10365 if (intbss->ts_boottime && 10366 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, 10367 intbss->ts_boottime, NL80211_BSS_PAD)) 10368 goto nla_put_failure; 10369 10370 if (!nl80211_put_signal(msg, intbss->pub.chains, 10371 intbss->pub.chain_signal, 10372 NL80211_BSS_CHAIN_SIGNAL)) 10373 goto nla_put_failure; 10374 10375 switch (rdev->wiphy.signal_type) { 10376 case CFG80211_SIGNAL_TYPE_MBM: 10377 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) 10378 goto nla_put_failure; 10379 break; 10380 case CFG80211_SIGNAL_TYPE_UNSPEC: 10381 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) 10382 goto nla_put_failure; 10383 break; 10384 default: 10385 break; 10386 } 10387 10388 switch (wdev->iftype) { 10389 case NL80211_IFTYPE_P2P_CLIENT: 10390 case NL80211_IFTYPE_STATION: 10391 for_each_valid_link(wdev, link_id) { 10392 if (intbss == wdev->links[link_id].client.current_bss && 10393 (nla_put_u32(msg, NL80211_BSS_STATUS, 10394 NL80211_BSS_STATUS_ASSOCIATED) || 10395 (wdev->valid_links && 10396 (nla_put_u8(msg, NL80211_BSS_MLO_LINK_ID, 10397 link_id) || 10398 nla_put(msg, NL80211_BSS_MLD_ADDR, ETH_ALEN, 10399 wdev->u.client.connected_addr))))) 10400 goto nla_put_failure; 10401 } 10402 break; 10403 case NL80211_IFTYPE_ADHOC: 10404 if (intbss == wdev->u.ibss.current_bss && 10405 nla_put_u32(msg, NL80211_BSS_STATUS, 10406 NL80211_BSS_STATUS_IBSS_JOINED)) 10407 goto nla_put_failure; 10408 break; 10409 default: 10410 break; 10411 } 10412 10413 nla_nest_end(msg, bss); 10414 10415 genlmsg_end(msg, hdr); 10416 return 0; 10417 10418 fail_unlock_rcu: 10419 rcu_read_unlock(); 10420 nla_put_failure: 10421 genlmsg_cancel(msg, hdr); 10422 return -EMSGSIZE; 10423 } 10424 10425 static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) 10426 { 10427 struct cfg80211_registered_device *rdev; 10428 struct cfg80211_internal_bss *scan; 10429 struct wireless_dev *wdev; 10430 int start = cb->args[2], idx = 0; 10431 int err; 10432 10433 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, NULL); 10434 if (err) 10435 return err; 10436 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10437 __acquire(&rdev->wiphy.mtx); 10438 10439 spin_lock_bh(&rdev->bss_lock); 10440 10441 /* 10442 * dump_scan will be called multiple times to break up the scan results 10443 * into multiple messages. It is unlikely that any more bss-es will be 10444 * expired after the first call, so only call only call this on the 10445 * first dump_scan invocation. 10446 */ 10447 if (start == 0) 10448 cfg80211_bss_expire(rdev); 10449 10450 cb->seq = rdev->bss_generation; 10451 10452 list_for_each_entry(scan, &rdev->bss_list, list) { 10453 if (++idx <= start) 10454 continue; 10455 if (nl80211_send_bss(skb, cb, 10456 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10457 rdev, wdev, scan) < 0) { 10458 idx--; 10459 break; 10460 } 10461 } 10462 10463 spin_unlock_bh(&rdev->bss_lock); 10464 10465 cb->args[2] = idx; 10466 wiphy_unlock(&rdev->wiphy); 10467 10468 return skb->len; 10469 } 10470 10471 static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, 10472 int flags, struct net_device *dev, 10473 bool allow_radio_stats, 10474 struct survey_info *survey) 10475 { 10476 void *hdr; 10477 struct nlattr *infoattr; 10478 10479 /* skip radio stats if userspace didn't request them */ 10480 if (!survey->channel && !allow_radio_stats) 10481 return 0; 10482 10483 hdr = nl80211hdr_put(msg, portid, seq, flags, 10484 NL80211_CMD_NEW_SURVEY_RESULTS); 10485 if (!hdr) 10486 return -ENOMEM; 10487 10488 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 10489 goto nla_put_failure; 10490 10491 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); 10492 if (!infoattr) 10493 goto nla_put_failure; 10494 10495 if (survey->channel && 10496 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, 10497 survey->channel->center_freq)) 10498 goto nla_put_failure; 10499 10500 if (survey->channel && survey->channel->freq_offset && 10501 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, 10502 survey->channel->freq_offset)) 10503 goto nla_put_failure; 10504 10505 if ((survey->filled & SURVEY_INFO_NOISE_DBM) && 10506 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) 10507 goto nla_put_failure; 10508 if ((survey->filled & SURVEY_INFO_IN_USE) && 10509 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) 10510 goto nla_put_failure; 10511 if ((survey->filled & SURVEY_INFO_TIME) && 10512 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, 10513 survey->time, NL80211_SURVEY_INFO_PAD)) 10514 goto nla_put_failure; 10515 if ((survey->filled & SURVEY_INFO_TIME_BUSY) && 10516 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, 10517 survey->time_busy, NL80211_SURVEY_INFO_PAD)) 10518 goto nla_put_failure; 10519 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && 10520 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, 10521 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) 10522 goto nla_put_failure; 10523 if ((survey->filled & SURVEY_INFO_TIME_RX) && 10524 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, 10525 survey->time_rx, NL80211_SURVEY_INFO_PAD)) 10526 goto nla_put_failure; 10527 if ((survey->filled & SURVEY_INFO_TIME_TX) && 10528 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, 10529 survey->time_tx, NL80211_SURVEY_INFO_PAD)) 10530 goto nla_put_failure; 10531 if ((survey->filled & SURVEY_INFO_TIME_SCAN) && 10532 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, 10533 survey->time_scan, NL80211_SURVEY_INFO_PAD)) 10534 goto nla_put_failure; 10535 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && 10536 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, 10537 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) 10538 goto nla_put_failure; 10539 10540 nla_nest_end(msg, infoattr); 10541 10542 genlmsg_end(msg, hdr); 10543 return 0; 10544 10545 nla_put_failure: 10546 genlmsg_cancel(msg, hdr); 10547 return -EMSGSIZE; 10548 } 10549 10550 static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) 10551 { 10552 struct nlattr **attrbuf; 10553 struct survey_info survey; 10554 struct cfg80211_registered_device *rdev; 10555 struct wireless_dev *wdev; 10556 int survey_idx = cb->args[2]; 10557 int res; 10558 bool radio_stats; 10559 10560 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 10561 if (!attrbuf) 10562 return -ENOMEM; 10563 10564 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev, attrbuf); 10565 if (res) { 10566 kfree(attrbuf); 10567 return res; 10568 } 10569 /* nl80211_prepare_wdev_dump acquired it in the successful case */ 10570 __acquire(&rdev->wiphy.mtx); 10571 10572 /* prepare_wdev_dump parsed the attributes */ 10573 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; 10574 10575 if (!wdev->netdev) { 10576 res = -EINVAL; 10577 goto out_err; 10578 } 10579 10580 if (!rdev->ops->dump_survey) { 10581 res = -EOPNOTSUPP; 10582 goto out_err; 10583 } 10584 10585 while (1) { 10586 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); 10587 if (res == -ENOENT) 10588 break; 10589 if (res) 10590 goto out_err; 10591 10592 /* don't send disabled channels, but do send non-channel data */ 10593 if (survey.channel && 10594 survey.channel->flags & IEEE80211_CHAN_DISABLED) { 10595 survey_idx++; 10596 continue; 10597 } 10598 10599 if (nl80211_send_survey(skb, 10600 NETLINK_CB(cb->skb).portid, 10601 cb->nlh->nlmsg_seq, NLM_F_MULTI, 10602 wdev->netdev, radio_stats, &survey) < 0) 10603 goto out; 10604 survey_idx++; 10605 } 10606 10607 out: 10608 cb->args[2] = survey_idx; 10609 res = skb->len; 10610 out_err: 10611 kfree(attrbuf); 10612 wiphy_unlock(&rdev->wiphy); 10613 return res; 10614 } 10615 10616 static bool nl80211_valid_wpa_versions(u32 wpa_versions) 10617 { 10618 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | 10619 NL80211_WPA_VERSION_2 | 10620 NL80211_WPA_VERSION_3)); 10621 } 10622 10623 static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) 10624 { 10625 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10626 struct net_device *dev = info->user_ptr[1]; 10627 struct ieee80211_channel *chan; 10628 const u8 *bssid, *ssid; 10629 int err, ssid_len; 10630 enum nl80211_auth_type auth_type; 10631 struct key_parse key; 10632 bool local_state_change; 10633 struct cfg80211_auth_request req = {}; 10634 u32 freq; 10635 10636 if (!info->attrs[NL80211_ATTR_MAC]) 10637 return -EINVAL; 10638 10639 if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) 10640 return -EINVAL; 10641 10642 if (!info->attrs[NL80211_ATTR_SSID]) 10643 return -EINVAL; 10644 10645 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 10646 return -EINVAL; 10647 10648 err = nl80211_parse_key(info, &key); 10649 if (err) 10650 return err; 10651 10652 if (key.idx >= 0) { 10653 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) 10654 return -EINVAL; 10655 if (!key.p.key || !key.p.key_len) 10656 return -EINVAL; 10657 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || 10658 key.p.key_len != WLAN_KEY_LEN_WEP40) && 10659 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || 10660 key.p.key_len != WLAN_KEY_LEN_WEP104)) 10661 return -EINVAL; 10662 if (key.idx > 3) 10663 return -EINVAL; 10664 } else { 10665 key.p.key_len = 0; 10666 key.p.key = NULL; 10667 } 10668 10669 if (key.idx >= 0) { 10670 int i; 10671 bool ok = false; 10672 10673 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { 10674 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { 10675 ok = true; 10676 break; 10677 } 10678 } 10679 if (!ok) 10680 return -EINVAL; 10681 } 10682 10683 if (!rdev->ops->auth) 10684 return -EOPNOTSUPP; 10685 10686 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10687 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10688 return -EOPNOTSUPP; 10689 10690 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 10691 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 10692 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10693 freq += 10694 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10695 10696 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10697 if (!chan) 10698 return -EINVAL; 10699 10700 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10701 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10702 10703 if (info->attrs[NL80211_ATTR_IE]) { 10704 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10705 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10706 } 10707 10708 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 10709 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) 10710 return -EINVAL; 10711 10712 if ((auth_type == NL80211_AUTHTYPE_SAE || 10713 auth_type == NL80211_AUTHTYPE_FILS_SK || 10714 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || 10715 auth_type == NL80211_AUTHTYPE_FILS_PK) && 10716 !info->attrs[NL80211_ATTR_AUTH_DATA]) 10717 return -EINVAL; 10718 10719 if (info->attrs[NL80211_ATTR_AUTH_DATA]) { 10720 if (auth_type != NL80211_AUTHTYPE_SAE && 10721 auth_type != NL80211_AUTHTYPE_FILS_SK && 10722 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && 10723 auth_type != NL80211_AUTHTYPE_FILS_PK) 10724 return -EINVAL; 10725 req.auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); 10726 req.auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); 10727 } 10728 10729 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 10730 10731 /* 10732 * Since we no longer track auth state, ignore 10733 * requests to only change local state. 10734 */ 10735 if (local_state_change) 10736 return 0; 10737 10738 req.auth_type = auth_type; 10739 req.key = key.p.key; 10740 req.key_len = key.p.key_len; 10741 req.key_idx = key.idx; 10742 req.link_id = nl80211_link_id_or_invalid(info->attrs); 10743 if (req.link_id >= 0) { 10744 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 10745 return -EINVAL; 10746 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 10747 return -EINVAL; 10748 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 10749 if (!is_valid_ether_addr(req.ap_mld_addr)) 10750 return -EINVAL; 10751 } 10752 10753 req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, 10754 IEEE80211_BSS_TYPE_ESS, 10755 IEEE80211_PRIVACY_ANY); 10756 if (!req.bss) 10757 return -ENOENT; 10758 10759 err = cfg80211_mlme_auth(rdev, dev, &req); 10760 10761 cfg80211_put_bss(&rdev->wiphy, req.bss); 10762 10763 return err; 10764 } 10765 10766 static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, 10767 struct genl_info *info) 10768 { 10769 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 10770 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); 10771 return -EINVAL; 10772 } 10773 10774 if (!rdev->ops->tx_control_port || 10775 !wiphy_ext_feature_isset(&rdev->wiphy, 10776 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 10777 return -EOPNOTSUPP; 10778 10779 return 0; 10780 } 10781 10782 static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, 10783 struct genl_info *info, 10784 struct cfg80211_crypto_settings *settings, 10785 int cipher_limit) 10786 { 10787 memset(settings, 0, sizeof(*settings)); 10788 10789 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; 10790 10791 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 10792 u16 proto; 10793 10794 proto = nla_get_u16( 10795 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 10796 settings->control_port_ethertype = cpu_to_be16(proto); 10797 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && 10798 proto != ETH_P_PAE) 10799 return -EINVAL; 10800 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) 10801 settings->control_port_no_encrypt = true; 10802 } else 10803 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); 10804 10805 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 10806 int r = validate_pae_over_nl80211(rdev, info); 10807 10808 if (r < 0) 10809 return r; 10810 10811 settings->control_port_over_nl80211 = true; 10812 10813 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) 10814 settings->control_port_no_preauth = true; 10815 } 10816 10817 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { 10818 void *data; 10819 int len, i; 10820 10821 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10822 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); 10823 settings->n_ciphers_pairwise = len / sizeof(u32); 10824 10825 if (len % sizeof(u32)) 10826 return -EINVAL; 10827 10828 if (settings->n_ciphers_pairwise > cipher_limit) 10829 return -EINVAL; 10830 10831 memcpy(settings->ciphers_pairwise, data, len); 10832 10833 for (i = 0; i < settings->n_ciphers_pairwise; i++) 10834 if (!cfg80211_supported_cipher_suite( 10835 &rdev->wiphy, 10836 settings->ciphers_pairwise[i])) 10837 return -EINVAL; 10838 } 10839 10840 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { 10841 settings->cipher_group = 10842 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); 10843 if (!cfg80211_supported_cipher_suite(&rdev->wiphy, 10844 settings->cipher_group)) 10845 return -EINVAL; 10846 } 10847 10848 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { 10849 settings->wpa_versions = 10850 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); 10851 if (!nl80211_valid_wpa_versions(settings->wpa_versions)) 10852 return -EINVAL; 10853 } 10854 10855 if (info->attrs[NL80211_ATTR_AKM_SUITES]) { 10856 void *data; 10857 int len; 10858 10859 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); 10860 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); 10861 settings->n_akm_suites = len / sizeof(u32); 10862 10863 if (len % sizeof(u32)) 10864 return -EINVAL; 10865 10866 if (settings->n_akm_suites > rdev->wiphy.max_num_akm_suites) 10867 return -EINVAL; 10868 10869 memcpy(settings->akm_suites, data, len); 10870 } 10871 10872 if (info->attrs[NL80211_ATTR_PMK]) { 10873 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) 10874 return -EINVAL; 10875 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10876 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && 10877 !wiphy_ext_feature_isset(&rdev->wiphy, 10878 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) 10879 return -EINVAL; 10880 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); 10881 } 10882 10883 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { 10884 if (!wiphy_ext_feature_isset(&rdev->wiphy, 10885 NL80211_EXT_FEATURE_SAE_OFFLOAD) && 10886 !wiphy_ext_feature_isset(&rdev->wiphy, 10887 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) 10888 return -EINVAL; 10889 settings->sae_pwd = 10890 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10891 settings->sae_pwd_len = 10892 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); 10893 } 10894 10895 if (info->attrs[NL80211_ATTR_SAE_PWE]) 10896 settings->sae_pwe = 10897 nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); 10898 else 10899 settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; 10900 10901 return 0; 10902 } 10903 10904 static struct cfg80211_bss *nl80211_assoc_bss(struct cfg80211_registered_device *rdev, 10905 const u8 *ssid, int ssid_len, 10906 struct nlattr **attrs) 10907 { 10908 struct ieee80211_channel *chan; 10909 struct cfg80211_bss *bss; 10910 const u8 *bssid; 10911 u32 freq; 10912 10913 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_WIPHY_FREQ]) 10914 return ERR_PTR(-EINVAL); 10915 10916 bssid = nla_data(attrs[NL80211_ATTR_MAC]); 10917 10918 freq = MHZ_TO_KHZ(nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ])); 10919 if (attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 10920 freq += nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 10921 10922 chan = nl80211_get_valid_chan(&rdev->wiphy, freq); 10923 if (!chan) 10924 return ERR_PTR(-EINVAL); 10925 10926 bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, 10927 ssid, ssid_len, 10928 IEEE80211_BSS_TYPE_ESS, 10929 IEEE80211_PRIVACY_ANY); 10930 if (!bss) 10931 return ERR_PTR(-ENOENT); 10932 10933 return bss; 10934 } 10935 10936 static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) 10937 { 10938 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 10939 struct net_device *dev = info->user_ptr[1]; 10940 struct cfg80211_assoc_request req = {}; 10941 struct nlattr **attrs = NULL; 10942 const u8 *ap_addr, *ssid; 10943 unsigned int link_id; 10944 int err, ssid_len; 10945 10946 if (dev->ieee80211_ptr->conn_owner_nlportid && 10947 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 10948 return -EPERM; 10949 10950 if (!info->attrs[NL80211_ATTR_SSID]) 10951 return -EINVAL; 10952 10953 if (!rdev->ops->assoc) 10954 return -EOPNOTSUPP; 10955 10956 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 10957 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 10958 return -EOPNOTSUPP; 10959 10960 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 10961 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 10962 10963 if (info->attrs[NL80211_ATTR_IE]) { 10964 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 10965 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 10966 10967 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 10968 req.ie, req.ie_len)) { 10969 NL_SET_ERR_MSG_ATTR(info->extack, 10970 info->attrs[NL80211_ATTR_IE], 10971 "non-inheritance makes no sense"); 10972 return -EINVAL; 10973 } 10974 } 10975 10976 if (info->attrs[NL80211_ATTR_USE_MFP]) { 10977 enum nl80211_mfp mfp = 10978 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 10979 if (mfp == NL80211_MFP_REQUIRED) 10980 req.use_mfp = true; 10981 else if (mfp != NL80211_MFP_NO) 10982 return -EINVAL; 10983 } 10984 10985 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 10986 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 10987 10988 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 10989 req.flags |= ASSOC_REQ_DISABLE_HT; 10990 10991 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10992 memcpy(&req.ht_capa_mask, 10993 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 10994 sizeof(req.ht_capa_mask)); 10995 10996 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 10997 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 10998 return -EINVAL; 10999 memcpy(&req.ht_capa, 11000 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11001 sizeof(req.ht_capa)); 11002 } 11003 11004 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 11005 req.flags |= ASSOC_REQ_DISABLE_VHT; 11006 11007 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 11008 req.flags |= ASSOC_REQ_DISABLE_HE; 11009 11010 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 11011 req.flags |= ASSOC_REQ_DISABLE_EHT; 11012 11013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11014 memcpy(&req.vht_capa_mask, 11015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 11016 sizeof(req.vht_capa_mask)); 11017 11018 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 11019 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11020 return -EINVAL; 11021 memcpy(&req.vht_capa, 11022 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 11023 sizeof(req.vht_capa)); 11024 } 11025 11026 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 11027 if (!((rdev->wiphy.features & 11028 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 11029 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 11030 !wiphy_ext_feature_isset(&rdev->wiphy, 11031 NL80211_EXT_FEATURE_RRM)) 11032 return -EINVAL; 11033 req.flags |= ASSOC_REQ_USE_RRM; 11034 } 11035 11036 if (info->attrs[NL80211_ATTR_FILS_KEK]) { 11037 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 11038 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 11039 if (!info->attrs[NL80211_ATTR_FILS_NONCES]) 11040 return -EINVAL; 11041 req.fils_nonces = 11042 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 11043 } 11044 11045 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { 11046 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) 11047 return -EINVAL; 11048 memcpy(&req.s1g_capa_mask, 11049 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), 11050 sizeof(req.s1g_capa_mask)); 11051 } 11052 11053 if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { 11054 if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) 11055 return -EINVAL; 11056 memcpy(&req.s1g_capa, 11057 nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), 11058 sizeof(req.s1g_capa)); 11059 } 11060 11061 req.link_id = nl80211_link_id_or_invalid(info->attrs); 11062 11063 if (info->attrs[NL80211_ATTR_MLO_LINKS]) { 11064 unsigned int attrsize = NUM_NL80211_ATTR * sizeof(*attrs); 11065 struct nlattr *link; 11066 int rem = 0; 11067 11068 if (req.link_id < 0) 11069 return -EINVAL; 11070 11071 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_MLO)) 11072 return -EINVAL; 11073 11074 if (info->attrs[NL80211_ATTR_MAC] || 11075 info->attrs[NL80211_ATTR_WIPHY_FREQ] || 11076 !info->attrs[NL80211_ATTR_MLD_ADDR]) 11077 return -EINVAL; 11078 11079 req.ap_mld_addr = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 11080 ap_addr = req.ap_mld_addr; 11081 11082 attrs = kzalloc(attrsize, GFP_KERNEL); 11083 if (!attrs) 11084 return -ENOMEM; 11085 11086 nla_for_each_nested(link, 11087 info->attrs[NL80211_ATTR_MLO_LINKS], 11088 rem) { 11089 memset(attrs, 0, attrsize); 11090 11091 nla_parse_nested(attrs, NL80211_ATTR_MAX, 11092 link, NULL, NULL); 11093 11094 if (!attrs[NL80211_ATTR_MLO_LINK_ID]) { 11095 err = -EINVAL; 11096 NL_SET_BAD_ATTR(info->extack, link); 11097 goto free; 11098 } 11099 11100 link_id = nla_get_u8(attrs[NL80211_ATTR_MLO_LINK_ID]); 11101 /* cannot use the same link ID again */ 11102 if (req.links[link_id].bss) { 11103 err = -EINVAL; 11104 NL_SET_BAD_ATTR(info->extack, link); 11105 goto free; 11106 } 11107 req.links[link_id].bss = 11108 nl80211_assoc_bss(rdev, ssid, ssid_len, attrs); 11109 if (IS_ERR(req.links[link_id].bss)) { 11110 err = PTR_ERR(req.links[link_id].bss); 11111 req.links[link_id].bss = NULL; 11112 NL_SET_ERR_MSG_ATTR(info->extack, 11113 link, "Error fetching BSS for link"); 11114 goto free; 11115 } 11116 11117 if (attrs[NL80211_ATTR_IE]) { 11118 req.links[link_id].elems = 11119 nla_data(attrs[NL80211_ATTR_IE]); 11120 req.links[link_id].elems_len = 11121 nla_len(attrs[NL80211_ATTR_IE]); 11122 11123 if (cfg80211_find_elem(WLAN_EID_FRAGMENT, 11124 req.links[link_id].elems, 11125 req.links[link_id].elems_len)) { 11126 NL_SET_ERR_MSG_ATTR(info->extack, 11127 attrs[NL80211_ATTR_IE], 11128 "cannot deal with fragmentation"); 11129 err = -EINVAL; 11130 goto free; 11131 } 11132 11133 if (cfg80211_find_ext_elem(WLAN_EID_EXT_NON_INHERITANCE, 11134 req.links[link_id].elems, 11135 req.links[link_id].elems_len)) { 11136 NL_SET_ERR_MSG_ATTR(info->extack, 11137 attrs[NL80211_ATTR_IE], 11138 "cannot deal with non-inheritance"); 11139 err = -EINVAL; 11140 goto free; 11141 } 11142 } 11143 11144 req.links[link_id].disabled = 11145 nla_get_flag(attrs[NL80211_ATTR_MLO_LINK_DISABLED]); 11146 } 11147 11148 if (!req.links[req.link_id].bss) { 11149 err = -EINVAL; 11150 goto free; 11151 } 11152 11153 if (req.links[req.link_id].elems_len) { 11154 GENL_SET_ERR_MSG(info, 11155 "cannot have per-link elems on assoc link"); 11156 err = -EINVAL; 11157 goto free; 11158 } 11159 11160 if (req.links[req.link_id].disabled) { 11161 GENL_SET_ERR_MSG(info, 11162 "cannot have assoc link disabled"); 11163 err = -EINVAL; 11164 goto free; 11165 } 11166 11167 kfree(attrs); 11168 attrs = NULL; 11169 } else { 11170 if (req.link_id >= 0) 11171 return -EINVAL; 11172 11173 req.bss = nl80211_assoc_bss(rdev, ssid, ssid_len, info->attrs); 11174 if (IS_ERR(req.bss)) 11175 return PTR_ERR(req.bss); 11176 ap_addr = req.bss->bssid; 11177 } 11178 11179 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); 11180 if (!err) { 11181 struct nlattr *link; 11182 int rem = 0; 11183 11184 err = cfg80211_mlme_assoc(rdev, dev, &req); 11185 11186 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 11187 dev->ieee80211_ptr->conn_owner_nlportid = 11188 info->snd_portid; 11189 memcpy(dev->ieee80211_ptr->disconnect_bssid, 11190 ap_addr, ETH_ALEN); 11191 } 11192 11193 /* Report error from first problematic link */ 11194 if (info->attrs[NL80211_ATTR_MLO_LINKS]) { 11195 nla_for_each_nested(link, 11196 info->attrs[NL80211_ATTR_MLO_LINKS], 11197 rem) { 11198 struct nlattr *link_id_attr = 11199 nla_find_nested(link, NL80211_ATTR_MLO_LINK_ID); 11200 11201 if (!link_id_attr) 11202 continue; 11203 11204 link_id = nla_get_u8(link_id_attr); 11205 11206 if (link_id == req.link_id) 11207 continue; 11208 11209 if (!req.links[link_id].error || 11210 WARN_ON(req.links[link_id].error > 0)) 11211 continue; 11212 11213 WARN_ON(err >= 0); 11214 11215 NL_SET_BAD_ATTR(info->extack, link); 11216 err = req.links[link_id].error; 11217 break; 11218 } 11219 } 11220 } 11221 11222 free: 11223 for (link_id = 0; link_id < ARRAY_SIZE(req.links); link_id++) 11224 cfg80211_put_bss(&rdev->wiphy, req.links[link_id].bss); 11225 cfg80211_put_bss(&rdev->wiphy, req.bss); 11226 kfree(attrs); 11227 11228 return err; 11229 } 11230 11231 static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) 11232 { 11233 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11234 struct net_device *dev = info->user_ptr[1]; 11235 const u8 *ie = NULL, *bssid; 11236 int ie_len = 0; 11237 u16 reason_code; 11238 bool local_state_change; 11239 11240 if (dev->ieee80211_ptr->conn_owner_nlportid && 11241 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11242 return -EPERM; 11243 11244 if (!info->attrs[NL80211_ATTR_MAC]) 11245 return -EINVAL; 11246 11247 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11248 return -EINVAL; 11249 11250 if (!rdev->ops->deauth) 11251 return -EOPNOTSUPP; 11252 11253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11254 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11255 return -EOPNOTSUPP; 11256 11257 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11258 11259 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11260 if (reason_code == 0) { 11261 /* Reason Code 0 is reserved */ 11262 return -EINVAL; 11263 } 11264 11265 if (info->attrs[NL80211_ATTR_IE]) { 11266 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11267 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11268 } 11269 11270 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11271 11272 return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, 11273 local_state_change); 11274 } 11275 11276 static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) 11277 { 11278 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11279 struct net_device *dev = info->user_ptr[1]; 11280 const u8 *ie = NULL, *bssid; 11281 int ie_len = 0; 11282 u16 reason_code; 11283 bool local_state_change; 11284 11285 if (dev->ieee80211_ptr->conn_owner_nlportid && 11286 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 11287 return -EPERM; 11288 11289 if (!info->attrs[NL80211_ATTR_MAC]) 11290 return -EINVAL; 11291 11292 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 11293 return -EINVAL; 11294 11295 if (!rdev->ops->disassoc) 11296 return -EOPNOTSUPP; 11297 11298 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11299 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11300 return -EOPNOTSUPP; 11301 11302 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11303 11304 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 11305 if (reason_code == 0) { 11306 /* Reason Code 0 is reserved */ 11307 return -EINVAL; 11308 } 11309 11310 if (info->attrs[NL80211_ATTR_IE]) { 11311 ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11312 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11313 } 11314 11315 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; 11316 11317 return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, 11318 local_state_change); 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 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); 11497 if (err) 11498 kfree_sensitive(connkeys); 11499 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) 11500 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 11501 11502 return err; 11503 } 11504 11505 static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) 11506 { 11507 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11508 struct net_device *dev = info->user_ptr[1]; 11509 11510 if (!rdev->ops->leave_ibss) 11511 return -EOPNOTSUPP; 11512 11513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) 11514 return -EOPNOTSUPP; 11515 11516 return cfg80211_leave_ibss(rdev, dev, false); 11517 } 11518 11519 static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) 11520 { 11521 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11522 struct net_device *dev = info->user_ptr[1]; 11523 int mcast_rate[NUM_NL80211_BANDS]; 11524 u32 nla_rate; 11525 11526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && 11527 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && 11528 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) 11529 return -EOPNOTSUPP; 11530 11531 if (!rdev->ops->set_mcast_rate) 11532 return -EOPNOTSUPP; 11533 11534 memset(mcast_rate, 0, sizeof(mcast_rate)); 11535 11536 if (!info->attrs[NL80211_ATTR_MCAST_RATE]) 11537 return -EINVAL; 11538 11539 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); 11540 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) 11541 return -EINVAL; 11542 11543 return rdev_set_mcast_rate(rdev, dev, mcast_rate); 11544 } 11545 11546 static struct sk_buff * 11547 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, 11548 struct wireless_dev *wdev, int approxlen, 11549 u32 portid, u32 seq, enum nl80211_commands cmd, 11550 enum nl80211_attrs attr, 11551 const struct nl80211_vendor_cmd_info *info, 11552 gfp_t gfp) 11553 { 11554 struct sk_buff *skb; 11555 void *hdr; 11556 struct nlattr *data; 11557 11558 skb = nlmsg_new(approxlen + 100, gfp); 11559 if (!skb) 11560 return NULL; 11561 11562 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); 11563 if (!hdr) { 11564 kfree_skb(skb); 11565 return NULL; 11566 } 11567 11568 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 11569 goto nla_put_failure; 11570 11571 if (info) { 11572 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, 11573 info->vendor_id)) 11574 goto nla_put_failure; 11575 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, 11576 info->subcmd)) 11577 goto nla_put_failure; 11578 } 11579 11580 if (wdev) { 11581 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 11582 wdev_id(wdev), NL80211_ATTR_PAD)) 11583 goto nla_put_failure; 11584 if (wdev->netdev && 11585 nla_put_u32(skb, NL80211_ATTR_IFINDEX, 11586 wdev->netdev->ifindex)) 11587 goto nla_put_failure; 11588 } 11589 11590 data = nla_nest_start_noflag(skb, attr); 11591 if (!data) 11592 goto nla_put_failure; 11593 11594 ((void **)skb->cb)[0] = rdev; 11595 ((void **)skb->cb)[1] = hdr; 11596 ((void **)skb->cb)[2] = data; 11597 11598 return skb; 11599 11600 nla_put_failure: 11601 kfree_skb(skb); 11602 return NULL; 11603 } 11604 11605 struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, 11606 struct wireless_dev *wdev, 11607 enum nl80211_commands cmd, 11608 enum nl80211_attrs attr, 11609 unsigned int portid, 11610 int vendor_event_idx, 11611 int approxlen, gfp_t gfp) 11612 { 11613 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 11614 const struct nl80211_vendor_cmd_info *info; 11615 11616 switch (cmd) { 11617 case NL80211_CMD_TESTMODE: 11618 if (WARN_ON(vendor_event_idx != -1)) 11619 return NULL; 11620 info = NULL; 11621 break; 11622 case NL80211_CMD_VENDOR: 11623 if (WARN_ON(vendor_event_idx < 0 || 11624 vendor_event_idx >= wiphy->n_vendor_events)) 11625 return NULL; 11626 info = &wiphy->vendor_events[vendor_event_idx]; 11627 break; 11628 default: 11629 WARN_ON(1); 11630 return NULL; 11631 } 11632 11633 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, 11634 cmd, attr, info, gfp); 11635 } 11636 EXPORT_SYMBOL(__cfg80211_alloc_event_skb); 11637 11638 void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) 11639 { 11640 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 11641 void *hdr = ((void **)skb->cb)[1]; 11642 struct nlmsghdr *nlhdr = nlmsg_hdr(skb); 11643 struct nlattr *data = ((void **)skb->cb)[2]; 11644 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; 11645 11646 /* clear CB data for netlink core to own from now on */ 11647 memset(skb->cb, 0, sizeof(skb->cb)); 11648 11649 nla_nest_end(skb, data); 11650 genlmsg_end(skb, hdr); 11651 11652 if (nlhdr->nlmsg_pid) { 11653 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, 11654 nlhdr->nlmsg_pid); 11655 } else { 11656 if (data->nla_type == NL80211_ATTR_VENDOR_DATA) 11657 mcgrp = NL80211_MCGRP_VENDOR; 11658 11659 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 11660 skb, 0, mcgrp, gfp); 11661 } 11662 } 11663 EXPORT_SYMBOL(__cfg80211_send_event_skb); 11664 11665 #ifdef CONFIG_NL80211_TESTMODE 11666 static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) 11667 { 11668 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11669 struct wireless_dev *wdev; 11670 int err; 11671 11672 lockdep_assert_held(&rdev->wiphy.mtx); 11673 11674 wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 11675 info->attrs); 11676 11677 if (!rdev->ops->testmode_cmd) 11678 return -EOPNOTSUPP; 11679 11680 if (IS_ERR(wdev)) { 11681 err = PTR_ERR(wdev); 11682 if (err != -EINVAL) 11683 return err; 11684 wdev = NULL; 11685 } else if (wdev->wiphy != &rdev->wiphy) { 11686 return -EINVAL; 11687 } 11688 11689 if (!info->attrs[NL80211_ATTR_TESTDATA]) 11690 return -EINVAL; 11691 11692 rdev->cur_cmd_info = info; 11693 err = rdev_testmode_cmd(rdev, wdev, 11694 nla_data(info->attrs[NL80211_ATTR_TESTDATA]), 11695 nla_len(info->attrs[NL80211_ATTR_TESTDATA])); 11696 rdev->cur_cmd_info = NULL; 11697 11698 return err; 11699 } 11700 11701 static int nl80211_testmode_dump(struct sk_buff *skb, 11702 struct netlink_callback *cb) 11703 { 11704 struct cfg80211_registered_device *rdev; 11705 struct nlattr **attrbuf = NULL; 11706 int err; 11707 long phy_idx; 11708 void *data = NULL; 11709 int data_len = 0; 11710 11711 rtnl_lock(); 11712 11713 if (cb->args[0]) { 11714 /* 11715 * 0 is a valid index, but not valid for args[0], 11716 * so we need to offset by 1. 11717 */ 11718 phy_idx = cb->args[0] - 1; 11719 11720 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); 11721 if (!rdev) { 11722 err = -ENOENT; 11723 goto out_err; 11724 } 11725 } else { 11726 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), 11727 GFP_KERNEL); 11728 if (!attrbuf) { 11729 err = -ENOMEM; 11730 goto out_err; 11731 } 11732 11733 err = nlmsg_parse_deprecated(cb->nlh, 11734 GENL_HDRLEN + nl80211_fam.hdrsize, 11735 attrbuf, nl80211_fam.maxattr, 11736 nl80211_policy, NULL); 11737 if (err) 11738 goto out_err; 11739 11740 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 11741 if (IS_ERR(rdev)) { 11742 err = PTR_ERR(rdev); 11743 goto out_err; 11744 } 11745 phy_idx = rdev->wiphy_idx; 11746 11747 if (attrbuf[NL80211_ATTR_TESTDATA]) 11748 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; 11749 } 11750 11751 if (cb->args[1]) { 11752 data = nla_data((void *)cb->args[1]); 11753 data_len = nla_len((void *)cb->args[1]); 11754 } 11755 11756 if (!rdev->ops->testmode_dump) { 11757 err = -EOPNOTSUPP; 11758 goto out_err; 11759 } 11760 11761 while (1) { 11762 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 11763 cb->nlh->nlmsg_seq, NLM_F_MULTI, 11764 NL80211_CMD_TESTMODE); 11765 struct nlattr *tmdata; 11766 11767 if (!hdr) 11768 break; 11769 11770 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { 11771 genlmsg_cancel(skb, hdr); 11772 break; 11773 } 11774 11775 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); 11776 if (!tmdata) { 11777 genlmsg_cancel(skb, hdr); 11778 break; 11779 } 11780 err = rdev_testmode_dump(rdev, skb, cb, data, data_len); 11781 nla_nest_end(skb, tmdata); 11782 11783 if (err == -ENOBUFS || err == -ENOENT) { 11784 genlmsg_cancel(skb, hdr); 11785 break; 11786 } else if (err) { 11787 genlmsg_cancel(skb, hdr); 11788 goto out_err; 11789 } 11790 11791 genlmsg_end(skb, hdr); 11792 } 11793 11794 err = skb->len; 11795 /* see above */ 11796 cb->args[0] = phy_idx + 1; 11797 out_err: 11798 kfree(attrbuf); 11799 rtnl_unlock(); 11800 return err; 11801 } 11802 #endif 11803 11804 static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) 11805 { 11806 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 11807 struct net_device *dev = info->user_ptr[1]; 11808 struct cfg80211_connect_params connect; 11809 struct wiphy *wiphy; 11810 struct cfg80211_cached_keys *connkeys = NULL; 11811 u32 freq = 0; 11812 int err; 11813 11814 memset(&connect, 0, sizeof(connect)); 11815 11816 if (!info->attrs[NL80211_ATTR_SSID] || 11817 !nla_len(info->attrs[NL80211_ATTR_SSID])) 11818 return -EINVAL; 11819 11820 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 11821 connect.auth_type = 11822 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 11823 if (!nl80211_valid_auth_type(rdev, connect.auth_type, 11824 NL80211_CMD_CONNECT)) 11825 return -EINVAL; 11826 } else 11827 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; 11828 11829 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; 11830 11831 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && 11832 !wiphy_ext_feature_isset(&rdev->wiphy, 11833 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 11834 return -EINVAL; 11835 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; 11836 11837 err = nl80211_crypto_settings(rdev, info, &connect.crypto, 11838 NL80211_MAX_NR_CIPHER_SUITES); 11839 if (err) 11840 return err; 11841 11842 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 11843 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 11844 return -EOPNOTSUPP; 11845 11846 wiphy = &rdev->wiphy; 11847 11848 connect.bg_scan_period = -1; 11849 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && 11850 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { 11851 connect.bg_scan_period = 11852 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); 11853 } 11854 11855 if (info->attrs[NL80211_ATTR_MAC]) 11856 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 11857 else if (info->attrs[NL80211_ATTR_MAC_HINT]) 11858 connect.bssid_hint = 11859 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); 11860 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 11861 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 11862 11863 if (info->attrs[NL80211_ATTR_IE]) { 11864 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 11865 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 11866 } 11867 11868 if (info->attrs[NL80211_ATTR_USE_MFP]) { 11869 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); 11870 if (connect.mfp == NL80211_MFP_OPTIONAL && 11871 !wiphy_ext_feature_isset(&rdev->wiphy, 11872 NL80211_EXT_FEATURE_MFP_OPTIONAL)) 11873 return -EOPNOTSUPP; 11874 } else { 11875 connect.mfp = NL80211_MFP_NO; 11876 } 11877 11878 if (info->attrs[NL80211_ATTR_PREV_BSSID]) 11879 connect.prev_bssid = 11880 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); 11881 11882 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) 11883 freq = MHZ_TO_KHZ(nla_get_u32( 11884 info->attrs[NL80211_ATTR_WIPHY_FREQ])); 11885 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) 11886 freq += 11887 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); 11888 11889 if (freq) { 11890 connect.channel = nl80211_get_valid_chan(wiphy, freq); 11891 if (!connect.channel) 11892 return -EINVAL; 11893 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { 11894 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); 11895 freq = MHZ_TO_KHZ(freq); 11896 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); 11897 if (!connect.channel_hint) 11898 return -EINVAL; 11899 } 11900 11901 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { 11902 connect.edmg.channels = 11903 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); 11904 11905 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) 11906 connect.edmg.bw_config = 11907 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); 11908 } 11909 11910 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { 11911 connkeys = nl80211_parse_connkeys(rdev, info, NULL); 11912 if (IS_ERR(connkeys)) 11913 return PTR_ERR(connkeys); 11914 } 11915 11916 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) 11917 connect.flags |= ASSOC_REQ_DISABLE_HT; 11918 11919 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) 11920 memcpy(&connect.ht_capa_mask, 11921 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), 11922 sizeof(connect.ht_capa_mask)); 11923 11924 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { 11925 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { 11926 kfree_sensitive(connkeys); 11927 return -EINVAL; 11928 } 11929 memcpy(&connect.ht_capa, 11930 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), 11931 sizeof(connect.ht_capa)); 11932 } 11933 11934 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) 11935 connect.flags |= ASSOC_REQ_DISABLE_VHT; 11936 11937 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) 11938 connect.flags |= ASSOC_REQ_DISABLE_HE; 11939 11940 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_EHT])) 11941 connect.flags |= ASSOC_REQ_DISABLE_EHT; 11942 11943 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) 11944 memcpy(&connect.vht_capa_mask, 11945 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), 11946 sizeof(connect.vht_capa_mask)); 11947 11948 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { 11949 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { 11950 kfree_sensitive(connkeys); 11951 return -EINVAL; 11952 } 11953 memcpy(&connect.vht_capa, 11954 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), 11955 sizeof(connect.vht_capa)); 11956 } 11957 11958 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { 11959 if (!((rdev->wiphy.features & 11960 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && 11961 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && 11962 !wiphy_ext_feature_isset(&rdev->wiphy, 11963 NL80211_EXT_FEATURE_RRM)) { 11964 kfree_sensitive(connkeys); 11965 return -EINVAL; 11966 } 11967 connect.flags |= ASSOC_REQ_USE_RRM; 11968 } 11969 11970 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); 11971 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { 11972 kfree_sensitive(connkeys); 11973 return -EOPNOTSUPP; 11974 } 11975 11976 if (info->attrs[NL80211_ATTR_BSS_SELECT]) { 11977 /* bss selection makes no sense if bssid is set */ 11978 if (connect.bssid) { 11979 kfree_sensitive(connkeys); 11980 return -EINVAL; 11981 } 11982 11983 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], 11984 wiphy, &connect.bss_select); 11985 if (err) { 11986 kfree_sensitive(connkeys); 11987 return err; 11988 } 11989 } 11990 11991 if (wiphy_ext_feature_isset(&rdev->wiphy, 11992 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && 11993 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 11994 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 11995 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 11996 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 11997 connect.fils_erp_username = 11998 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 11999 connect.fils_erp_username_len = 12000 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12001 connect.fils_erp_realm = 12002 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12003 connect.fils_erp_realm_len = 12004 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12005 connect.fils_erp_next_seq_num = 12006 nla_get_u16( 12007 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 12008 connect.fils_erp_rrk = 12009 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12010 connect.fils_erp_rrk_len = 12011 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12012 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 12013 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 12014 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 12015 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12016 kfree_sensitive(connkeys); 12017 return -EINVAL; 12018 } 12019 12020 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { 12021 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 12022 kfree_sensitive(connkeys); 12023 GENL_SET_ERR_MSG(info, 12024 "external auth requires connection ownership"); 12025 return -EINVAL; 12026 } 12027 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; 12028 } 12029 12030 if (nla_get_flag(info->attrs[NL80211_ATTR_MLO_SUPPORT])) 12031 connect.flags |= CONNECT_REQ_MLO_SUPPORT; 12032 12033 err = cfg80211_connect(rdev, dev, &connect, connkeys, 12034 connect.prev_bssid); 12035 if (err) 12036 kfree_sensitive(connkeys); 12037 12038 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { 12039 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 12040 if (connect.bssid) 12041 memcpy(dev->ieee80211_ptr->disconnect_bssid, 12042 connect.bssid, ETH_ALEN); 12043 else 12044 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); 12045 } 12046 12047 return err; 12048 } 12049 12050 static int nl80211_update_connect_params(struct sk_buff *skb, 12051 struct genl_info *info) 12052 { 12053 struct cfg80211_connect_params connect = {}; 12054 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12055 struct net_device *dev = info->user_ptr[1]; 12056 struct wireless_dev *wdev = dev->ieee80211_ptr; 12057 bool fils_sk_offload; 12058 u32 auth_type; 12059 u32 changed = 0; 12060 12061 if (!rdev->ops->update_connect_params) 12062 return -EOPNOTSUPP; 12063 12064 if (info->attrs[NL80211_ATTR_IE]) { 12065 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 12066 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 12067 changed |= UPDATE_ASSOC_IES; 12068 } 12069 12070 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, 12071 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); 12072 12073 /* 12074 * when driver supports fils-sk offload all attributes must be 12075 * provided. So the else covers "fils-sk-not-all" and 12076 * "no-fils-sk-any". 12077 */ 12078 if (fils_sk_offload && 12079 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && 12080 info->attrs[NL80211_ATTR_FILS_ERP_REALM] && 12081 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && 12082 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12083 connect.fils_erp_username = 12084 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12085 connect.fils_erp_username_len = 12086 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); 12087 connect.fils_erp_realm = 12088 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12089 connect.fils_erp_realm_len = 12090 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); 12091 connect.fils_erp_next_seq_num = 12092 nla_get_u16( 12093 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); 12094 connect.fils_erp_rrk = 12095 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12096 connect.fils_erp_rrk_len = 12097 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); 12098 changed |= UPDATE_FILS_ERP_INFO; 12099 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || 12100 info->attrs[NL80211_ATTR_FILS_ERP_REALM] || 12101 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || 12102 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { 12103 return -EINVAL; 12104 } 12105 12106 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 12107 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 12108 if (!nl80211_valid_auth_type(rdev, auth_type, 12109 NL80211_CMD_CONNECT)) 12110 return -EINVAL; 12111 12112 if (auth_type == NL80211_AUTHTYPE_FILS_SK && 12113 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) 12114 return -EINVAL; 12115 12116 connect.auth_type = auth_type; 12117 changed |= UPDATE_AUTH_TYPE; 12118 } 12119 12120 if (!wdev->connected) 12121 return -ENOLINK; 12122 12123 return rdev_update_connect_params(rdev, dev, &connect, changed); 12124 } 12125 12126 static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) 12127 { 12128 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12129 struct net_device *dev = info->user_ptr[1]; 12130 u16 reason; 12131 12132 if (dev->ieee80211_ptr->conn_owner_nlportid && 12133 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) 12134 return -EPERM; 12135 12136 if (!info->attrs[NL80211_ATTR_REASON_CODE]) 12137 reason = WLAN_REASON_DEAUTH_LEAVING; 12138 else 12139 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 12140 12141 if (reason == 0) 12142 return -EINVAL; 12143 12144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12145 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 12146 return -EOPNOTSUPP; 12147 12148 return cfg80211_disconnect(rdev, dev, reason, true); 12149 } 12150 12151 static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) 12152 { 12153 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12154 struct net *net; 12155 int err; 12156 12157 if (info->attrs[NL80211_ATTR_PID]) { 12158 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); 12159 12160 net = get_net_ns_by_pid(pid); 12161 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { 12162 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); 12163 12164 net = get_net_ns_by_fd(fd); 12165 } else { 12166 return -EINVAL; 12167 } 12168 12169 if (IS_ERR(net)) 12170 return PTR_ERR(net); 12171 12172 err = 0; 12173 12174 /* check if anything to do */ 12175 if (!net_eq(wiphy_net(&rdev->wiphy), net)) 12176 err = cfg80211_switch_netns(rdev, net); 12177 12178 put_net(net); 12179 return err; 12180 } 12181 12182 static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) 12183 { 12184 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12185 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, 12186 struct cfg80211_pmksa *pmksa) = NULL; 12187 struct net_device *dev = info->user_ptr[1]; 12188 struct cfg80211_pmksa pmksa; 12189 12190 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); 12191 12192 if (!info->attrs[NL80211_ATTR_PMKID]) 12193 return -EINVAL; 12194 12195 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 12196 12197 if (info->attrs[NL80211_ATTR_MAC]) { 12198 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); 12199 } else if (info->attrs[NL80211_ATTR_SSID] && 12200 info->attrs[NL80211_ATTR_FILS_CACHE_ID] && 12201 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || 12202 info->attrs[NL80211_ATTR_PMK])) { 12203 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); 12204 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 12205 pmksa.cache_id = 12206 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); 12207 } else { 12208 return -EINVAL; 12209 } 12210 if (info->attrs[NL80211_ATTR_PMK]) { 12211 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 12212 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 12213 } 12214 12215 if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) 12216 pmksa.pmk_lifetime = 12217 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); 12218 12219 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) 12220 pmksa.pmk_reauth_threshold = 12221 nla_get_u8( 12222 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); 12223 12224 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12225 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && 12226 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && 12227 wiphy_ext_feature_isset(&rdev->wiphy, 12228 NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) 12229 return -EOPNOTSUPP; 12230 12231 switch (info->genlhdr->cmd) { 12232 case NL80211_CMD_SET_PMKSA: 12233 rdev_ops = rdev->ops->set_pmksa; 12234 break; 12235 case NL80211_CMD_DEL_PMKSA: 12236 rdev_ops = rdev->ops->del_pmksa; 12237 break; 12238 default: 12239 WARN_ON(1); 12240 break; 12241 } 12242 12243 if (!rdev_ops) 12244 return -EOPNOTSUPP; 12245 12246 return rdev_ops(&rdev->wiphy, dev, &pmksa); 12247 } 12248 12249 static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) 12250 { 12251 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12252 struct net_device *dev = info->user_ptr[1]; 12253 12254 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && 12255 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) 12256 return -EOPNOTSUPP; 12257 12258 if (!rdev->ops->flush_pmksa) 12259 return -EOPNOTSUPP; 12260 12261 return rdev_flush_pmksa(rdev, dev); 12262 } 12263 12264 static int nl80211_tdls_mgmt(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 u8 action_code, dialog_token; 12269 u32 peer_capability = 0; 12270 u16 status_code; 12271 u8 *peer; 12272 int link_id; 12273 bool initiator; 12274 12275 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12276 !rdev->ops->tdls_mgmt) 12277 return -EOPNOTSUPP; 12278 12279 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || 12280 !info->attrs[NL80211_ATTR_STATUS_CODE] || 12281 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || 12282 !info->attrs[NL80211_ATTR_IE] || 12283 !info->attrs[NL80211_ATTR_MAC]) 12284 return -EINVAL; 12285 12286 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12287 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); 12288 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 12289 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); 12290 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); 12291 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) 12292 peer_capability = 12293 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); 12294 link_id = nl80211_link_id_or_invalid(info->attrs); 12295 12296 return rdev_tdls_mgmt(rdev, dev, peer, link_id, action_code, 12297 dialog_token, status_code, peer_capability, 12298 initiator, 12299 nla_data(info->attrs[NL80211_ATTR_IE]), 12300 nla_len(info->attrs[NL80211_ATTR_IE])); 12301 } 12302 12303 static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) 12304 { 12305 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12306 struct net_device *dev = info->user_ptr[1]; 12307 enum nl80211_tdls_operation operation; 12308 u8 *peer; 12309 12310 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || 12311 !rdev->ops->tdls_oper) 12312 return -EOPNOTSUPP; 12313 12314 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || 12315 !info->attrs[NL80211_ATTR_MAC]) 12316 return -EINVAL; 12317 12318 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); 12319 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 12320 12321 return rdev_tdls_oper(rdev, dev, peer, operation); 12322 } 12323 12324 static int nl80211_remain_on_channel(struct sk_buff *skb, 12325 struct genl_info *info) 12326 { 12327 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12328 unsigned int link_id = nl80211_link_id(info->attrs); 12329 struct wireless_dev *wdev = info->user_ptr[1]; 12330 struct cfg80211_chan_def chandef; 12331 struct sk_buff *msg; 12332 void *hdr; 12333 u64 cookie; 12334 u32 duration; 12335 int err; 12336 12337 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || 12338 !info->attrs[NL80211_ATTR_DURATION]) 12339 return -EINVAL; 12340 12341 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12342 12343 if (!rdev->ops->remain_on_channel || 12344 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) 12345 return -EOPNOTSUPP; 12346 12347 /* 12348 * We should be on that channel for at least a minimum amount of 12349 * time (10ms) but no longer than the driver supports. 12350 */ 12351 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12352 duration > rdev->wiphy.max_remain_on_channel_duration) 12353 return -EINVAL; 12354 12355 err = nl80211_parse_chandef(rdev, info, &chandef); 12356 if (err) 12357 return err; 12358 12359 if (!cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) { 12360 const struct cfg80211_chan_def *oper_chandef, *compat_chandef; 12361 12362 oper_chandef = wdev_chandef(wdev, link_id); 12363 12364 if (WARN_ON(!oper_chandef)) { 12365 /* cannot happen since we must beacon to get here */ 12366 WARN_ON(1); 12367 return -EBUSY; 12368 } 12369 12370 /* note: returns first one if identical chandefs */ 12371 compat_chandef = cfg80211_chandef_compatible(&chandef, 12372 oper_chandef); 12373 12374 if (compat_chandef != &chandef) 12375 return -EBUSY; 12376 } 12377 12378 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12379 if (!msg) 12380 return -ENOMEM; 12381 12382 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12383 NL80211_CMD_REMAIN_ON_CHANNEL); 12384 if (!hdr) { 12385 err = -ENOBUFS; 12386 goto free_msg; 12387 } 12388 12389 err = rdev_remain_on_channel(rdev, wdev, chandef.chan, 12390 duration, &cookie); 12391 12392 if (err) 12393 goto free_msg; 12394 12395 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12396 NL80211_ATTR_PAD)) 12397 goto nla_put_failure; 12398 12399 genlmsg_end(msg, hdr); 12400 12401 return genlmsg_reply(msg, info); 12402 12403 nla_put_failure: 12404 err = -ENOBUFS; 12405 free_msg: 12406 nlmsg_free(msg); 12407 return err; 12408 } 12409 12410 static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, 12411 struct genl_info *info) 12412 { 12413 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12414 struct wireless_dev *wdev = info->user_ptr[1]; 12415 u64 cookie; 12416 12417 if (!info->attrs[NL80211_ATTR_COOKIE]) 12418 return -EINVAL; 12419 12420 if (!rdev->ops->cancel_remain_on_channel) 12421 return -EOPNOTSUPP; 12422 12423 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12424 12425 return rdev_cancel_remain_on_channel(rdev, wdev, cookie); 12426 } 12427 12428 static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, 12429 struct genl_info *info) 12430 { 12431 struct cfg80211_bitrate_mask mask; 12432 unsigned int link_id = nl80211_link_id(info->attrs); 12433 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12434 struct net_device *dev = info->user_ptr[1]; 12435 int err; 12436 12437 if (!rdev->ops->set_bitrate_mask) 12438 return -EOPNOTSUPP; 12439 12440 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 12441 NL80211_ATTR_TX_RATES, &mask, 12442 dev, true, link_id); 12443 if (err) 12444 return err; 12445 12446 return rdev_set_bitrate_mask(rdev, dev, link_id, NULL, &mask); 12447 } 12448 12449 static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) 12450 { 12451 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12452 struct wireless_dev *wdev = info->user_ptr[1]; 12453 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; 12454 12455 if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) 12456 return -EINVAL; 12457 12458 if (info->attrs[NL80211_ATTR_FRAME_TYPE]) 12459 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); 12460 12461 switch (wdev->iftype) { 12462 case NL80211_IFTYPE_STATION: 12463 case NL80211_IFTYPE_ADHOC: 12464 case NL80211_IFTYPE_P2P_CLIENT: 12465 case NL80211_IFTYPE_AP: 12466 case NL80211_IFTYPE_AP_VLAN: 12467 case NL80211_IFTYPE_MESH_POINT: 12468 case NL80211_IFTYPE_P2P_GO: 12469 case NL80211_IFTYPE_P2P_DEVICE: 12470 break; 12471 case NL80211_IFTYPE_NAN: 12472 if (!wiphy_ext_feature_isset(wdev->wiphy, 12473 NL80211_EXT_FEATURE_SECURE_NAN)) 12474 return -EOPNOTSUPP; 12475 break; 12476 default: 12477 return -EOPNOTSUPP; 12478 } 12479 12480 /* not much point in registering if we can't reply */ 12481 if (!rdev->ops->mgmt_tx) 12482 return -EOPNOTSUPP; 12483 12484 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && 12485 !wiphy_ext_feature_isset(&rdev->wiphy, 12486 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { 12487 GENL_SET_ERR_MSG(info, 12488 "multicast RX registrations are not supported"); 12489 return -EOPNOTSUPP; 12490 } 12491 12492 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, 12493 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12494 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), 12495 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], 12496 info->extack); 12497 } 12498 12499 static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) 12500 { 12501 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12502 struct wireless_dev *wdev = info->user_ptr[1]; 12503 struct cfg80211_chan_def chandef; 12504 int err; 12505 void *hdr = NULL; 12506 u64 cookie; 12507 struct sk_buff *msg = NULL; 12508 struct cfg80211_mgmt_tx_params params = { 12509 .dont_wait_for_ack = 12510 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], 12511 }; 12512 12513 if (!info->attrs[NL80211_ATTR_FRAME]) 12514 return -EINVAL; 12515 12516 if (!rdev->ops->mgmt_tx) 12517 return -EOPNOTSUPP; 12518 12519 switch (wdev->iftype) { 12520 case NL80211_IFTYPE_P2P_DEVICE: 12521 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 12522 return -EINVAL; 12523 break; 12524 case NL80211_IFTYPE_STATION: 12525 case NL80211_IFTYPE_ADHOC: 12526 case NL80211_IFTYPE_P2P_CLIENT: 12527 case NL80211_IFTYPE_AP: 12528 case NL80211_IFTYPE_AP_VLAN: 12529 case NL80211_IFTYPE_MESH_POINT: 12530 case NL80211_IFTYPE_P2P_GO: 12531 break; 12532 case NL80211_IFTYPE_NAN: 12533 if (!wiphy_ext_feature_isset(wdev->wiphy, 12534 NL80211_EXT_FEATURE_SECURE_NAN)) 12535 return -EOPNOTSUPP; 12536 break; 12537 default: 12538 return -EOPNOTSUPP; 12539 } 12540 12541 if (info->attrs[NL80211_ATTR_DURATION]) { 12542 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12543 return -EINVAL; 12544 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 12545 12546 /* 12547 * We should wait on the channel for at least a minimum amount 12548 * of time (10ms) but no longer than the driver supports. 12549 */ 12550 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || 12551 params.wait > rdev->wiphy.max_remain_on_channel_duration) 12552 return -EINVAL; 12553 } 12554 12555 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; 12556 12557 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 12558 return -EINVAL; 12559 12560 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); 12561 12562 /* get the channel if any has been specified, otherwise pass NULL to 12563 * the driver. The latter will use the current one 12564 */ 12565 chandef.chan = NULL; 12566 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 12567 err = nl80211_parse_chandef(rdev, info, &chandef); 12568 if (err) 12569 return err; 12570 } 12571 12572 if (!chandef.chan && params.offchan) 12573 return -EINVAL; 12574 12575 if (params.offchan && 12576 !cfg80211_off_channel_oper_allowed(wdev, chandef.chan)) 12577 return -EBUSY; 12578 12579 params.link_id = nl80211_link_id_or_invalid(info->attrs); 12580 /* 12581 * This now races due to the unlock, but we cannot check 12582 * the valid links for the _station_ anyway, so that's up 12583 * to the driver. 12584 */ 12585 if (params.link_id >= 0 && 12586 !(wdev->valid_links & BIT(params.link_id))) 12587 return -EINVAL; 12588 12589 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 12590 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 12591 12592 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { 12593 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12594 int i; 12595 12596 if (len % sizeof(u16)) 12597 return -EINVAL; 12598 12599 params.n_csa_offsets = len / sizeof(u16); 12600 params.csa_offsets = 12601 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); 12602 12603 /* check that all the offsets fit the frame */ 12604 for (i = 0; i < params.n_csa_offsets; i++) { 12605 if (params.csa_offsets[i] >= params.len) 12606 return -EINVAL; 12607 } 12608 } 12609 12610 if (!params.dont_wait_for_ack) { 12611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12612 if (!msg) 12613 return -ENOMEM; 12614 12615 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12616 NL80211_CMD_FRAME); 12617 if (!hdr) { 12618 err = -ENOBUFS; 12619 goto free_msg; 12620 } 12621 } 12622 12623 params.chan = chandef.chan; 12624 err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); 12625 if (err) 12626 goto free_msg; 12627 12628 if (msg) { 12629 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 12630 NL80211_ATTR_PAD)) 12631 goto nla_put_failure; 12632 12633 genlmsg_end(msg, hdr); 12634 return genlmsg_reply(msg, info); 12635 } 12636 12637 return 0; 12638 12639 nla_put_failure: 12640 err = -ENOBUFS; 12641 free_msg: 12642 nlmsg_free(msg); 12643 return err; 12644 } 12645 12646 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) 12647 { 12648 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12649 struct wireless_dev *wdev = info->user_ptr[1]; 12650 u64 cookie; 12651 12652 if (!info->attrs[NL80211_ATTR_COOKIE]) 12653 return -EINVAL; 12654 12655 if (!rdev->ops->mgmt_tx_cancel_wait) 12656 return -EOPNOTSUPP; 12657 12658 switch (wdev->iftype) { 12659 case NL80211_IFTYPE_STATION: 12660 case NL80211_IFTYPE_ADHOC: 12661 case NL80211_IFTYPE_P2P_CLIENT: 12662 case NL80211_IFTYPE_AP: 12663 case NL80211_IFTYPE_AP_VLAN: 12664 case NL80211_IFTYPE_P2P_GO: 12665 case NL80211_IFTYPE_P2P_DEVICE: 12666 break; 12667 case NL80211_IFTYPE_NAN: 12668 if (!wiphy_ext_feature_isset(wdev->wiphy, 12669 NL80211_EXT_FEATURE_SECURE_NAN)) 12670 return -EOPNOTSUPP; 12671 break; 12672 default: 12673 return -EOPNOTSUPP; 12674 } 12675 12676 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 12677 12678 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); 12679 } 12680 12681 static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) 12682 { 12683 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12684 struct wireless_dev *wdev; 12685 struct net_device *dev = info->user_ptr[1]; 12686 u8 ps_state; 12687 bool state; 12688 int err; 12689 12690 if (!info->attrs[NL80211_ATTR_PS_STATE]) 12691 return -EINVAL; 12692 12693 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); 12694 12695 wdev = dev->ieee80211_ptr; 12696 12697 if (!rdev->ops->set_power_mgmt) 12698 return -EOPNOTSUPP; 12699 12700 state = (ps_state == NL80211_PS_ENABLED) ? true : false; 12701 12702 if (state == wdev->ps) 12703 return 0; 12704 12705 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); 12706 if (!err) 12707 wdev->ps = state; 12708 return err; 12709 } 12710 12711 static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) 12712 { 12713 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12714 enum nl80211_ps_state ps_state; 12715 struct wireless_dev *wdev; 12716 struct net_device *dev = info->user_ptr[1]; 12717 struct sk_buff *msg; 12718 void *hdr; 12719 int err; 12720 12721 wdev = dev->ieee80211_ptr; 12722 12723 if (!rdev->ops->set_power_mgmt) 12724 return -EOPNOTSUPP; 12725 12726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 12727 if (!msg) 12728 return -ENOMEM; 12729 12730 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 12731 NL80211_CMD_GET_POWER_SAVE); 12732 if (!hdr) { 12733 err = -ENOBUFS; 12734 goto free_msg; 12735 } 12736 12737 if (wdev->ps) 12738 ps_state = NL80211_PS_ENABLED; 12739 else 12740 ps_state = NL80211_PS_DISABLED; 12741 12742 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) 12743 goto nla_put_failure; 12744 12745 genlmsg_end(msg, hdr); 12746 return genlmsg_reply(msg, info); 12747 12748 nla_put_failure: 12749 err = -ENOBUFS; 12750 free_msg: 12751 nlmsg_free(msg); 12752 return err; 12753 } 12754 12755 static const struct nla_policy 12756 nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { 12757 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, 12758 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, 12759 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, 12760 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, 12761 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, 12762 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, 12763 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, 12764 }; 12765 12766 static int nl80211_set_cqm_txe(struct genl_info *info, 12767 u32 rate, u32 pkts, u32 intvl) 12768 { 12769 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12770 struct net_device *dev = info->user_ptr[1]; 12771 struct wireless_dev *wdev = dev->ieee80211_ptr; 12772 12773 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) 12774 return -EINVAL; 12775 12776 if (!rdev->ops->set_cqm_txe_config) 12777 return -EOPNOTSUPP; 12778 12779 if (wdev->iftype != NL80211_IFTYPE_STATION && 12780 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12781 return -EOPNOTSUPP; 12782 12783 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); 12784 } 12785 12786 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, 12787 struct net_device *dev, 12788 struct cfg80211_cqm_config *cqm_config) 12789 { 12790 struct wireless_dev *wdev = dev->ieee80211_ptr; 12791 s32 last, low, high; 12792 u32 hyst; 12793 int i, n, low_index; 12794 int err; 12795 12796 /* 12797 * Obtain current RSSI value if possible, if not and no RSSI threshold 12798 * event has been received yet, we should receive an event after a 12799 * connection is established and enough beacons received to calculate 12800 * the average. 12801 */ 12802 if (!cqm_config->last_rssi_event_value && 12803 wdev->links[0].client.current_bss && 12804 rdev->ops->get_station) { 12805 struct station_info sinfo = {}; 12806 u8 *mac_addr; 12807 12808 mac_addr = wdev->links[0].client.current_bss->pub.bssid; 12809 12810 err = rdev_get_station(rdev, dev, mac_addr, &sinfo); 12811 if (err) 12812 return err; 12813 12814 cfg80211_sinfo_release_content(&sinfo); 12815 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) 12816 cqm_config->last_rssi_event_value = 12817 (s8) sinfo.rx_beacon_signal_avg; 12818 } 12819 12820 last = cqm_config->last_rssi_event_value; 12821 hyst = cqm_config->rssi_hyst; 12822 n = cqm_config->n_rssi_thresholds; 12823 12824 for (i = 0; i < n; i++) { 12825 i = array_index_nospec(i, n); 12826 if (last < cqm_config->rssi_thresholds[i]) 12827 break; 12828 } 12829 12830 low_index = i - 1; 12831 if (low_index >= 0) { 12832 low_index = array_index_nospec(low_index, n); 12833 low = cqm_config->rssi_thresholds[low_index] - hyst; 12834 } else { 12835 low = S32_MIN; 12836 } 12837 if (i < n) { 12838 i = array_index_nospec(i, n); 12839 high = cqm_config->rssi_thresholds[i] + hyst - 1; 12840 } else { 12841 high = S32_MAX; 12842 } 12843 12844 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); 12845 } 12846 12847 static int nl80211_set_cqm_rssi(struct genl_info *info, 12848 const s32 *thresholds, int n_thresholds, 12849 u32 hysteresis) 12850 { 12851 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12852 struct cfg80211_cqm_config *cqm_config = NULL, *old; 12853 struct net_device *dev = info->user_ptr[1]; 12854 struct wireless_dev *wdev = dev->ieee80211_ptr; 12855 s32 prev = S32_MIN; 12856 int i, err; 12857 12858 /* Check all values negative and sorted */ 12859 for (i = 0; i < n_thresholds; i++) { 12860 if (thresholds[i] > 0 || thresholds[i] <= prev) 12861 return -EINVAL; 12862 12863 prev = thresholds[i]; 12864 } 12865 12866 if (wdev->iftype != NL80211_IFTYPE_STATION && 12867 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 12868 return -EOPNOTSUPP; 12869 12870 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ 12871 n_thresholds = 0; 12872 12873 old = wiphy_dereference(wdev->wiphy, wdev->cqm_config); 12874 12875 /* if already disabled just succeed */ 12876 if (!n_thresholds && !old) 12877 return 0; 12878 12879 if (n_thresholds > 1) { 12880 if (!wiphy_ext_feature_isset(&rdev->wiphy, 12881 NL80211_EXT_FEATURE_CQM_RSSI_LIST) || 12882 !rdev->ops->set_cqm_rssi_range_config) 12883 return -EOPNOTSUPP; 12884 } else { 12885 if (!rdev->ops->set_cqm_rssi_config) 12886 return -EOPNOTSUPP; 12887 } 12888 12889 if (n_thresholds) { 12890 cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, 12891 n_thresholds), 12892 GFP_KERNEL); 12893 if (!cqm_config) 12894 return -ENOMEM; 12895 12896 cqm_config->rssi_hyst = hysteresis; 12897 cqm_config->n_rssi_thresholds = n_thresholds; 12898 memcpy(cqm_config->rssi_thresholds, thresholds, 12899 flex_array_size(cqm_config, rssi_thresholds, 12900 n_thresholds)); 12901 cqm_config->use_range_api = n_thresholds > 1 || 12902 !rdev->ops->set_cqm_rssi_config; 12903 12904 rcu_assign_pointer(wdev->cqm_config, cqm_config); 12905 12906 if (cqm_config->use_range_api) 12907 err = cfg80211_cqm_rssi_update(rdev, dev, cqm_config); 12908 else 12909 err = rdev_set_cqm_rssi_config(rdev, dev, 12910 thresholds[0], 12911 hysteresis); 12912 } else { 12913 RCU_INIT_POINTER(wdev->cqm_config, NULL); 12914 /* if enabled as range also disable via range */ 12915 if (old->use_range_api) 12916 err = rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); 12917 else 12918 err = rdev_set_cqm_rssi_config(rdev, dev, 0, 0); 12919 } 12920 12921 if (err) { 12922 rcu_assign_pointer(wdev->cqm_config, old); 12923 kfree_rcu(cqm_config, rcu_head); 12924 } else { 12925 kfree_rcu(old, rcu_head); 12926 } 12927 12928 return err; 12929 } 12930 12931 static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) 12932 { 12933 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; 12934 struct nlattr *cqm; 12935 int err; 12936 12937 cqm = info->attrs[NL80211_ATTR_CQM]; 12938 if (!cqm) 12939 return -EINVAL; 12940 12941 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, 12942 nl80211_attr_cqm_policy, 12943 info->extack); 12944 if (err) 12945 return err; 12946 12947 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && 12948 attrs[NL80211_ATTR_CQM_RSSI_HYST]) { 12949 const s32 *thresholds = 12950 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12951 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); 12952 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); 12953 12954 if (len % 4) 12955 return -EINVAL; 12956 12957 return nl80211_set_cqm_rssi(info, thresholds, len / 4, 12958 hysteresis); 12959 } 12960 12961 if (attrs[NL80211_ATTR_CQM_TXE_RATE] && 12962 attrs[NL80211_ATTR_CQM_TXE_PKTS] && 12963 attrs[NL80211_ATTR_CQM_TXE_INTVL]) { 12964 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); 12965 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); 12966 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); 12967 12968 return nl80211_set_cqm_txe(info, rate, pkts, intvl); 12969 } 12970 12971 return -EINVAL; 12972 } 12973 12974 static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) 12975 { 12976 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12977 struct net_device *dev = info->user_ptr[1]; 12978 struct ocb_setup setup = {}; 12979 int err; 12980 12981 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 12982 if (err) 12983 return err; 12984 12985 return cfg80211_join_ocb(rdev, dev, &setup); 12986 } 12987 12988 static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) 12989 { 12990 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12991 struct net_device *dev = info->user_ptr[1]; 12992 12993 return cfg80211_leave_ocb(rdev, dev); 12994 } 12995 12996 static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) 12997 { 12998 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 12999 struct net_device *dev = info->user_ptr[1]; 13000 struct mesh_config cfg; 13001 struct mesh_setup setup; 13002 int err; 13003 13004 /* start with default */ 13005 memcpy(&cfg, &default_mesh_config, sizeof(cfg)); 13006 memcpy(&setup, &default_mesh_setup, sizeof(setup)); 13007 13008 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { 13009 /* and parse parameters if given */ 13010 err = nl80211_parse_mesh_config(info, &cfg, NULL); 13011 if (err) 13012 return err; 13013 } 13014 13015 if (!info->attrs[NL80211_ATTR_MESH_ID] || 13016 !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) 13017 return -EINVAL; 13018 13019 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 13020 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 13021 13022 if (info->attrs[NL80211_ATTR_MCAST_RATE] && 13023 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, 13024 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) 13025 return -EINVAL; 13026 13027 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { 13028 setup.beacon_interval = 13029 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); 13030 13031 err = cfg80211_validate_beacon_int(rdev, 13032 NL80211_IFTYPE_MESH_POINT, 13033 setup.beacon_interval); 13034 if (err) 13035 return err; 13036 } 13037 13038 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { 13039 setup.dtim_period = 13040 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); 13041 if (setup.dtim_period < 1 || setup.dtim_period > 100) 13042 return -EINVAL; 13043 } 13044 13045 if (info->attrs[NL80211_ATTR_MESH_SETUP]) { 13046 /* parse additional setup parameters if given */ 13047 err = nl80211_parse_mesh_setup(info, &setup); 13048 if (err) 13049 return err; 13050 } 13051 13052 if (setup.user_mpm) 13053 cfg.auto_open_plinks = false; 13054 13055 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { 13056 err = nl80211_parse_chandef(rdev, info, &setup.chandef); 13057 if (err) 13058 return err; 13059 } else { 13060 /* __cfg80211_join_mesh() will sort it out */ 13061 setup.chandef.chan = NULL; 13062 } 13063 13064 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { 13065 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 13066 int n_rates = 13067 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); 13068 struct ieee80211_supported_band *sband; 13069 13070 if (!setup.chandef.chan) 13071 return -EINVAL; 13072 13073 sband = rdev->wiphy.bands[setup.chandef.chan->band]; 13074 13075 err = ieee80211_get_ratemask(sband, rates, n_rates, 13076 &setup.basic_rates); 13077 if (err) 13078 return err; 13079 } 13080 13081 if (info->attrs[NL80211_ATTR_TX_RATES]) { 13082 err = nl80211_parse_tx_bitrate_mask(info, info->attrs, 13083 NL80211_ATTR_TX_RATES, 13084 &setup.beacon_rate, 13085 dev, false, 0); 13086 if (err) 13087 return err; 13088 13089 if (!setup.chandef.chan) 13090 return -EINVAL; 13091 13092 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, 13093 &setup.beacon_rate); 13094 if (err) 13095 return err; 13096 } 13097 13098 setup.userspace_handles_dfs = 13099 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); 13100 13101 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { 13102 int r = validate_pae_over_nl80211(rdev, info); 13103 13104 if (r < 0) 13105 return r; 13106 13107 setup.control_port_over_nl80211 = true; 13108 } 13109 13110 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); 13111 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) 13112 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; 13113 13114 return err; 13115 } 13116 13117 static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) 13118 { 13119 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13120 struct net_device *dev = info->user_ptr[1]; 13121 13122 return cfg80211_leave_mesh(rdev, dev); 13123 } 13124 13125 #ifdef CONFIG_PM 13126 static int nl80211_send_wowlan_patterns(struct sk_buff *msg, 13127 struct cfg80211_registered_device *rdev) 13128 { 13129 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; 13130 struct nlattr *nl_pats, *nl_pat; 13131 int i, pat_len; 13132 13133 if (!wowlan->n_patterns) 13134 return 0; 13135 13136 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); 13137 if (!nl_pats) 13138 return -ENOBUFS; 13139 13140 for (i = 0; i < wowlan->n_patterns; i++) { 13141 nl_pat = nla_nest_start_noflag(msg, i + 1); 13142 if (!nl_pat) 13143 return -ENOBUFS; 13144 pat_len = wowlan->patterns[i].pattern_len; 13145 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), 13146 wowlan->patterns[i].mask) || 13147 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 13148 wowlan->patterns[i].pattern) || 13149 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 13150 wowlan->patterns[i].pkt_offset)) 13151 return -ENOBUFS; 13152 nla_nest_end(msg, nl_pat); 13153 } 13154 nla_nest_end(msg, nl_pats); 13155 13156 return 0; 13157 } 13158 13159 static int nl80211_send_wowlan_tcp(struct sk_buff *msg, 13160 struct cfg80211_wowlan_tcp *tcp) 13161 { 13162 struct nlattr *nl_tcp; 13163 13164 if (!tcp) 13165 return 0; 13166 13167 nl_tcp = nla_nest_start_noflag(msg, 13168 NL80211_WOWLAN_TRIG_TCP_CONNECTION); 13169 if (!nl_tcp) 13170 return -ENOBUFS; 13171 13172 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || 13173 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || 13174 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || 13175 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || 13176 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || 13177 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, 13178 tcp->payload_len, tcp->payload) || 13179 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, 13180 tcp->data_interval) || 13181 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, 13182 tcp->wake_len, tcp->wake_data) || 13183 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, 13184 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) 13185 return -ENOBUFS; 13186 13187 if (tcp->payload_seq.len && 13188 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, 13189 sizeof(tcp->payload_seq), &tcp->payload_seq)) 13190 return -ENOBUFS; 13191 13192 if (tcp->payload_tok.len && 13193 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, 13194 sizeof(tcp->payload_tok) + tcp->tokens_size, 13195 &tcp->payload_tok)) 13196 return -ENOBUFS; 13197 13198 nla_nest_end(msg, nl_tcp); 13199 13200 return 0; 13201 } 13202 13203 static int nl80211_send_wowlan_nd(struct sk_buff *msg, 13204 struct cfg80211_sched_scan_request *req) 13205 { 13206 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; 13207 int i; 13208 13209 if (!req) 13210 return 0; 13211 13212 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); 13213 if (!nd) 13214 return -ENOBUFS; 13215 13216 if (req->n_scan_plans == 1 && 13217 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, 13218 req->scan_plans[0].interval * 1000)) 13219 return -ENOBUFS; 13220 13221 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) 13222 return -ENOBUFS; 13223 13224 if (req->relative_rssi_set) { 13225 struct nl80211_bss_select_rssi_adjust rssi_adjust; 13226 13227 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, 13228 req->relative_rssi)) 13229 return -ENOBUFS; 13230 13231 rssi_adjust.band = req->rssi_adjust.band; 13232 rssi_adjust.delta = req->rssi_adjust.delta; 13233 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, 13234 sizeof(rssi_adjust), &rssi_adjust)) 13235 return -ENOBUFS; 13236 } 13237 13238 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); 13239 if (!freqs) 13240 return -ENOBUFS; 13241 13242 for (i = 0; i < req->n_channels; i++) { 13243 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 13244 return -ENOBUFS; 13245 } 13246 13247 nla_nest_end(msg, freqs); 13248 13249 if (req->n_match_sets) { 13250 matches = nla_nest_start_noflag(msg, 13251 NL80211_ATTR_SCHED_SCAN_MATCH); 13252 if (!matches) 13253 return -ENOBUFS; 13254 13255 for (i = 0; i < req->n_match_sets; i++) { 13256 match = nla_nest_start_noflag(msg, i); 13257 if (!match) 13258 return -ENOBUFS; 13259 13260 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, 13261 req->match_sets[i].ssid.ssid_len, 13262 req->match_sets[i].ssid.ssid)) 13263 return -ENOBUFS; 13264 nla_nest_end(msg, match); 13265 } 13266 nla_nest_end(msg, matches); 13267 } 13268 13269 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); 13270 if (!scan_plans) 13271 return -ENOBUFS; 13272 13273 for (i = 0; i < req->n_scan_plans; i++) { 13274 scan_plan = nla_nest_start_noflag(msg, i + 1); 13275 if (!scan_plan) 13276 return -ENOBUFS; 13277 13278 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, 13279 req->scan_plans[i].interval) || 13280 (req->scan_plans[i].iterations && 13281 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, 13282 req->scan_plans[i].iterations))) 13283 return -ENOBUFS; 13284 nla_nest_end(msg, scan_plan); 13285 } 13286 nla_nest_end(msg, scan_plans); 13287 13288 nla_nest_end(msg, nd); 13289 13290 return 0; 13291 } 13292 13293 static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) 13294 { 13295 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13296 struct sk_buff *msg; 13297 void *hdr; 13298 u32 size = NLMSG_DEFAULT_SIZE; 13299 13300 if (!rdev->wiphy.wowlan) 13301 return -EOPNOTSUPP; 13302 13303 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { 13304 /* adjust size to have room for all the data */ 13305 size += rdev->wiphy.wowlan_config->tcp->tokens_size + 13306 rdev->wiphy.wowlan_config->tcp->payload_len + 13307 rdev->wiphy.wowlan_config->tcp->wake_len + 13308 rdev->wiphy.wowlan_config->tcp->wake_len / 8; 13309 } 13310 13311 msg = nlmsg_new(size, GFP_KERNEL); 13312 if (!msg) 13313 return -ENOMEM; 13314 13315 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13316 NL80211_CMD_GET_WOWLAN); 13317 if (!hdr) 13318 goto nla_put_failure; 13319 13320 if (rdev->wiphy.wowlan_config) { 13321 struct nlattr *nl_wowlan; 13322 13323 nl_wowlan = nla_nest_start_noflag(msg, 13324 NL80211_ATTR_WOWLAN_TRIGGERS); 13325 if (!nl_wowlan) 13326 goto nla_put_failure; 13327 13328 if ((rdev->wiphy.wowlan_config->any && 13329 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || 13330 (rdev->wiphy.wowlan_config->disconnect && 13331 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || 13332 (rdev->wiphy.wowlan_config->magic_pkt && 13333 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || 13334 (rdev->wiphy.wowlan_config->gtk_rekey_failure && 13335 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || 13336 (rdev->wiphy.wowlan_config->eap_identity_req && 13337 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || 13338 (rdev->wiphy.wowlan_config->four_way_handshake && 13339 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || 13340 (rdev->wiphy.wowlan_config->rfkill_release && 13341 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) 13342 goto nla_put_failure; 13343 13344 if (nl80211_send_wowlan_patterns(msg, rdev)) 13345 goto nla_put_failure; 13346 13347 if (nl80211_send_wowlan_tcp(msg, 13348 rdev->wiphy.wowlan_config->tcp)) 13349 goto nla_put_failure; 13350 13351 if (nl80211_send_wowlan_nd( 13352 msg, 13353 rdev->wiphy.wowlan_config->nd_config)) 13354 goto nla_put_failure; 13355 13356 nla_nest_end(msg, nl_wowlan); 13357 } 13358 13359 genlmsg_end(msg, hdr); 13360 return genlmsg_reply(msg, info); 13361 13362 nla_put_failure: 13363 nlmsg_free(msg); 13364 return -ENOBUFS; 13365 } 13366 13367 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, 13368 struct nlattr *attr, 13369 struct cfg80211_wowlan *trig) 13370 { 13371 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; 13372 struct cfg80211_wowlan_tcp *cfg; 13373 struct nl80211_wowlan_tcp_data_token *tok = NULL; 13374 struct nl80211_wowlan_tcp_data_seq *seq = NULL; 13375 u32 size; 13376 u32 data_size, wake_size, tokens_size = 0, wake_mask_size; 13377 int err, port; 13378 13379 if (!rdev->wiphy.wowlan->tcp) 13380 return -EINVAL; 13381 13382 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, 13383 nl80211_wowlan_tcp_policy, NULL); 13384 if (err) 13385 return err; 13386 13387 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || 13388 !tb[NL80211_WOWLAN_TCP_DST_IPV4] || 13389 !tb[NL80211_WOWLAN_TCP_DST_MAC] || 13390 !tb[NL80211_WOWLAN_TCP_DST_PORT] || 13391 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || 13392 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || 13393 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || 13394 !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) 13395 return -EINVAL; 13396 13397 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); 13398 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) 13399 return -EINVAL; 13400 13401 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > 13402 rdev->wiphy.wowlan->tcp->data_interval_max || 13403 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) 13404 return -EINVAL; 13405 13406 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); 13407 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) 13408 return -EINVAL; 13409 13410 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); 13411 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) 13412 return -EINVAL; 13413 13414 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { 13415 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13416 13417 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); 13418 tokens_size = tokln - sizeof(*tok); 13419 13420 if (!tok->len || tokens_size % tok->len) 13421 return -EINVAL; 13422 if (!rdev->wiphy.wowlan->tcp->tok) 13423 return -EINVAL; 13424 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) 13425 return -EINVAL; 13426 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) 13427 return -EINVAL; 13428 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) 13429 return -EINVAL; 13430 if (tok->offset + tok->len > data_size) 13431 return -EINVAL; 13432 } 13433 13434 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { 13435 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); 13436 if (!rdev->wiphy.wowlan->tcp->seq) 13437 return -EINVAL; 13438 if (seq->len == 0 || seq->len > 4) 13439 return -EINVAL; 13440 if (seq->len + seq->offset > data_size) 13441 return -EINVAL; 13442 } 13443 13444 size = sizeof(*cfg); 13445 size += data_size; 13446 size += wake_size + wake_mask_size; 13447 size += tokens_size; 13448 13449 cfg = kzalloc(size, GFP_KERNEL); 13450 if (!cfg) 13451 return -ENOMEM; 13452 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); 13453 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); 13454 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), 13455 ETH_ALEN); 13456 if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) 13457 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); 13458 else 13459 port = 0; 13460 #ifdef CONFIG_INET 13461 /* allocate a socket and port for it and use it */ 13462 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, 13463 IPPROTO_TCP, &cfg->sock, 1); 13464 if (err) { 13465 kfree(cfg); 13466 return err; 13467 } 13468 if (inet_csk_get_port(cfg->sock->sk, port)) { 13469 sock_release(cfg->sock); 13470 kfree(cfg); 13471 return -EADDRINUSE; 13472 } 13473 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; 13474 #else 13475 if (!port) { 13476 kfree(cfg); 13477 return -EINVAL; 13478 } 13479 cfg->src_port = port; 13480 #endif 13481 13482 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); 13483 cfg->payload_len = data_size; 13484 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; 13485 memcpy((void *)cfg->payload, 13486 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), 13487 data_size); 13488 if (seq) 13489 cfg->payload_seq = *seq; 13490 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); 13491 cfg->wake_len = wake_size; 13492 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; 13493 memcpy((void *)cfg->wake_data, 13494 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), 13495 wake_size); 13496 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + 13497 data_size + wake_size; 13498 memcpy((void *)cfg->wake_mask, 13499 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), 13500 wake_mask_size); 13501 if (tok) { 13502 cfg->tokens_size = tokens_size; 13503 cfg->payload_tok = *tok; 13504 memcpy(cfg->payload_tok.token_stream, tok->token_stream, 13505 tokens_size); 13506 } 13507 13508 trig->tcp = cfg; 13509 13510 return 0; 13511 } 13512 13513 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, 13514 const struct wiphy_wowlan_support *wowlan, 13515 struct nlattr *attr, 13516 struct cfg80211_wowlan *trig) 13517 { 13518 struct nlattr **tb; 13519 int err; 13520 13521 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); 13522 if (!tb) 13523 return -ENOMEM; 13524 13525 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { 13526 err = -EOPNOTSUPP; 13527 goto out; 13528 } 13529 13530 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, 13531 nl80211_policy, NULL); 13532 if (err) 13533 goto out; 13534 13535 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, 13536 wowlan->max_nd_match_sets); 13537 err = PTR_ERR_OR_ZERO(trig->nd_config); 13538 if (err) 13539 trig->nd_config = NULL; 13540 13541 out: 13542 kfree(tb); 13543 return err; 13544 } 13545 13546 static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) 13547 { 13548 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13549 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; 13550 struct cfg80211_wowlan new_triggers = {}; 13551 struct cfg80211_wowlan *ntrig; 13552 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; 13553 int err, i; 13554 bool prev_enabled = rdev->wiphy.wowlan_config; 13555 bool regular = false; 13556 13557 if (!wowlan) 13558 return -EOPNOTSUPP; 13559 13560 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { 13561 cfg80211_rdev_free_wowlan(rdev); 13562 rdev->wiphy.wowlan_config = NULL; 13563 goto set_wakeup; 13564 } 13565 13566 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, 13567 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], 13568 nl80211_wowlan_policy, info->extack); 13569 if (err) 13570 return err; 13571 13572 if (tb[NL80211_WOWLAN_TRIG_ANY]) { 13573 if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) 13574 return -EINVAL; 13575 new_triggers.any = true; 13576 } 13577 13578 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { 13579 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) 13580 return -EINVAL; 13581 new_triggers.disconnect = true; 13582 regular = true; 13583 } 13584 13585 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { 13586 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) 13587 return -EINVAL; 13588 new_triggers.magic_pkt = true; 13589 regular = true; 13590 } 13591 13592 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) 13593 return -EINVAL; 13594 13595 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { 13596 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) 13597 return -EINVAL; 13598 new_triggers.gtk_rekey_failure = true; 13599 regular = true; 13600 } 13601 13602 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { 13603 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) 13604 return -EINVAL; 13605 new_triggers.eap_identity_req = true; 13606 regular = true; 13607 } 13608 13609 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { 13610 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) 13611 return -EINVAL; 13612 new_triggers.four_way_handshake = true; 13613 regular = true; 13614 } 13615 13616 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { 13617 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) 13618 return -EINVAL; 13619 new_triggers.rfkill_release = true; 13620 regular = true; 13621 } 13622 13623 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { 13624 struct nlattr *pat; 13625 int n_patterns = 0; 13626 int rem, pat_len, mask_len, pkt_offset; 13627 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13628 13629 regular = true; 13630 13631 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13632 rem) 13633 n_patterns++; 13634 if (n_patterns > wowlan->n_patterns) 13635 return -EINVAL; 13636 13637 new_triggers.patterns = kcalloc(n_patterns, 13638 sizeof(new_triggers.patterns[0]), 13639 GFP_KERNEL); 13640 if (!new_triggers.patterns) 13641 return -ENOMEM; 13642 13643 new_triggers.n_patterns = n_patterns; 13644 i = 0; 13645 13646 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], 13647 rem) { 13648 u8 *mask_pat; 13649 13650 err = nla_parse_nested_deprecated(pat_tb, 13651 MAX_NL80211_PKTPAT, 13652 pat, 13653 nl80211_packet_pattern_policy, 13654 info->extack); 13655 if (err) 13656 goto error; 13657 13658 err = -EINVAL; 13659 if (!pat_tb[NL80211_PKTPAT_MASK] || 13660 !pat_tb[NL80211_PKTPAT_PATTERN]) 13661 goto error; 13662 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13663 mask_len = DIV_ROUND_UP(pat_len, 8); 13664 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13665 goto error; 13666 if (pat_len > wowlan->pattern_max_len || 13667 pat_len < wowlan->pattern_min_len) 13668 goto error; 13669 13670 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13671 pkt_offset = 0; 13672 else 13673 pkt_offset = nla_get_u32( 13674 pat_tb[NL80211_PKTPAT_OFFSET]); 13675 if (pkt_offset > wowlan->max_pkt_offset) 13676 goto error; 13677 new_triggers.patterns[i].pkt_offset = pkt_offset; 13678 13679 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13680 if (!mask_pat) { 13681 err = -ENOMEM; 13682 goto error; 13683 } 13684 new_triggers.patterns[i].mask = mask_pat; 13685 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13686 mask_len); 13687 mask_pat += mask_len; 13688 new_triggers.patterns[i].pattern = mask_pat; 13689 new_triggers.patterns[i].pattern_len = pat_len; 13690 memcpy(mask_pat, 13691 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13692 pat_len); 13693 i++; 13694 } 13695 } 13696 13697 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { 13698 regular = true; 13699 err = nl80211_parse_wowlan_tcp( 13700 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], 13701 &new_triggers); 13702 if (err) 13703 goto error; 13704 } 13705 13706 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { 13707 regular = true; 13708 err = nl80211_parse_wowlan_nd( 13709 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], 13710 &new_triggers); 13711 if (err) 13712 goto error; 13713 } 13714 13715 /* The 'any' trigger means the device continues operating more or less 13716 * as in its normal operation mode and wakes up the host on most of the 13717 * normal interrupts (like packet RX, ...) 13718 * It therefore makes little sense to combine with the more constrained 13719 * wakeup trigger modes. 13720 */ 13721 if (new_triggers.any && regular) { 13722 err = -EINVAL; 13723 goto error; 13724 } 13725 13726 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); 13727 if (!ntrig) { 13728 err = -ENOMEM; 13729 goto error; 13730 } 13731 cfg80211_rdev_free_wowlan(rdev); 13732 rdev->wiphy.wowlan_config = ntrig; 13733 13734 set_wakeup: 13735 if (rdev->ops->set_wakeup && 13736 prev_enabled != !!rdev->wiphy.wowlan_config) 13737 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); 13738 13739 return 0; 13740 error: 13741 for (i = 0; i < new_triggers.n_patterns; i++) 13742 kfree(new_triggers.patterns[i].mask); 13743 kfree(new_triggers.patterns); 13744 if (new_triggers.tcp && new_triggers.tcp->sock) 13745 sock_release(new_triggers.tcp->sock); 13746 kfree(new_triggers.tcp); 13747 kfree(new_triggers.nd_config); 13748 return err; 13749 } 13750 #endif 13751 13752 static int nl80211_send_coalesce_rules(struct sk_buff *msg, 13753 struct cfg80211_registered_device *rdev) 13754 { 13755 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; 13756 int i, j, pat_len; 13757 struct cfg80211_coalesce_rules *rule; 13758 13759 if (!rdev->coalesce->n_rules) 13760 return 0; 13761 13762 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); 13763 if (!nl_rules) 13764 return -ENOBUFS; 13765 13766 for (i = 0; i < rdev->coalesce->n_rules; i++) { 13767 nl_rule = nla_nest_start_noflag(msg, i + 1); 13768 if (!nl_rule) 13769 return -ENOBUFS; 13770 13771 rule = &rdev->coalesce->rules[i]; 13772 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, 13773 rule->delay)) 13774 return -ENOBUFS; 13775 13776 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, 13777 rule->condition)) 13778 return -ENOBUFS; 13779 13780 nl_pats = nla_nest_start_noflag(msg, 13781 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); 13782 if (!nl_pats) 13783 return -ENOBUFS; 13784 13785 for (j = 0; j < rule->n_patterns; j++) { 13786 nl_pat = nla_nest_start_noflag(msg, j + 1); 13787 if (!nl_pat) 13788 return -ENOBUFS; 13789 pat_len = rule->patterns[j].pattern_len; 13790 if (nla_put(msg, NL80211_PKTPAT_MASK, 13791 DIV_ROUND_UP(pat_len, 8), 13792 rule->patterns[j].mask) || 13793 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, 13794 rule->patterns[j].pattern) || 13795 nla_put_u32(msg, NL80211_PKTPAT_OFFSET, 13796 rule->patterns[j].pkt_offset)) 13797 return -ENOBUFS; 13798 nla_nest_end(msg, nl_pat); 13799 } 13800 nla_nest_end(msg, nl_pats); 13801 nla_nest_end(msg, nl_rule); 13802 } 13803 nla_nest_end(msg, nl_rules); 13804 13805 return 0; 13806 } 13807 13808 static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) 13809 { 13810 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13811 struct sk_buff *msg; 13812 void *hdr; 13813 13814 if (!rdev->wiphy.coalesce) 13815 return -EOPNOTSUPP; 13816 13817 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 13818 if (!msg) 13819 return -ENOMEM; 13820 13821 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 13822 NL80211_CMD_GET_COALESCE); 13823 if (!hdr) 13824 goto nla_put_failure; 13825 13826 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) 13827 goto nla_put_failure; 13828 13829 genlmsg_end(msg, hdr); 13830 return genlmsg_reply(msg, info); 13831 13832 nla_put_failure: 13833 nlmsg_free(msg); 13834 return -ENOBUFS; 13835 } 13836 13837 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) 13838 { 13839 struct cfg80211_coalesce *coalesce = rdev->coalesce; 13840 int i, j; 13841 struct cfg80211_coalesce_rules *rule; 13842 13843 if (!coalesce) 13844 return; 13845 13846 for (i = 0; i < coalesce->n_rules; i++) { 13847 rule = &coalesce->rules[i]; 13848 for (j = 0; j < rule->n_patterns; j++) 13849 kfree(rule->patterns[j].mask); 13850 kfree(rule->patterns); 13851 } 13852 kfree(coalesce->rules); 13853 kfree(coalesce); 13854 rdev->coalesce = NULL; 13855 } 13856 13857 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, 13858 struct nlattr *rule, 13859 struct cfg80211_coalesce_rules *new_rule) 13860 { 13861 int err, i; 13862 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13863 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; 13864 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; 13865 struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; 13866 13867 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, 13868 rule, nl80211_coalesce_policy, NULL); 13869 if (err) 13870 return err; 13871 13872 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) 13873 new_rule->delay = 13874 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); 13875 if (new_rule->delay > coalesce->max_delay) 13876 return -EINVAL; 13877 13878 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) 13879 new_rule->condition = 13880 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); 13881 13882 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) 13883 return -EINVAL; 13884 13885 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13886 rem) 13887 n_patterns++; 13888 if (n_patterns > coalesce->n_patterns) 13889 return -EINVAL; 13890 13891 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), 13892 GFP_KERNEL); 13893 if (!new_rule->patterns) 13894 return -ENOMEM; 13895 13896 new_rule->n_patterns = n_patterns; 13897 i = 0; 13898 13899 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], 13900 rem) { 13901 u8 *mask_pat; 13902 13903 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, 13904 pat, 13905 nl80211_packet_pattern_policy, 13906 NULL); 13907 if (err) 13908 return err; 13909 13910 if (!pat_tb[NL80211_PKTPAT_MASK] || 13911 !pat_tb[NL80211_PKTPAT_PATTERN]) 13912 return -EINVAL; 13913 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); 13914 mask_len = DIV_ROUND_UP(pat_len, 8); 13915 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) 13916 return -EINVAL; 13917 if (pat_len > coalesce->pattern_max_len || 13918 pat_len < coalesce->pattern_min_len) 13919 return -EINVAL; 13920 13921 if (!pat_tb[NL80211_PKTPAT_OFFSET]) 13922 pkt_offset = 0; 13923 else 13924 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); 13925 if (pkt_offset > coalesce->max_pkt_offset) 13926 return -EINVAL; 13927 new_rule->patterns[i].pkt_offset = pkt_offset; 13928 13929 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); 13930 if (!mask_pat) 13931 return -ENOMEM; 13932 13933 new_rule->patterns[i].mask = mask_pat; 13934 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), 13935 mask_len); 13936 13937 mask_pat += mask_len; 13938 new_rule->patterns[i].pattern = mask_pat; 13939 new_rule->patterns[i].pattern_len = pat_len; 13940 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), 13941 pat_len); 13942 i++; 13943 } 13944 13945 return 0; 13946 } 13947 13948 static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) 13949 { 13950 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 13951 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; 13952 struct cfg80211_coalesce new_coalesce = {}; 13953 struct cfg80211_coalesce *n_coalesce; 13954 int err, rem_rule, n_rules = 0, i, j; 13955 struct nlattr *rule; 13956 struct cfg80211_coalesce_rules *tmp_rule; 13957 13958 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) 13959 return -EOPNOTSUPP; 13960 13961 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { 13962 cfg80211_rdev_free_coalesce(rdev); 13963 rdev_set_coalesce(rdev, NULL); 13964 return 0; 13965 } 13966 13967 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 13968 rem_rule) 13969 n_rules++; 13970 if (n_rules > coalesce->n_rules) 13971 return -EINVAL; 13972 13973 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), 13974 GFP_KERNEL); 13975 if (!new_coalesce.rules) 13976 return -ENOMEM; 13977 13978 new_coalesce.n_rules = n_rules; 13979 i = 0; 13980 13981 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], 13982 rem_rule) { 13983 err = nl80211_parse_coalesce_rule(rdev, rule, 13984 &new_coalesce.rules[i]); 13985 if (err) 13986 goto error; 13987 13988 i++; 13989 } 13990 13991 err = rdev_set_coalesce(rdev, &new_coalesce); 13992 if (err) 13993 goto error; 13994 13995 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); 13996 if (!n_coalesce) { 13997 err = -ENOMEM; 13998 goto error; 13999 } 14000 cfg80211_rdev_free_coalesce(rdev); 14001 rdev->coalesce = n_coalesce; 14002 14003 return 0; 14004 error: 14005 for (i = 0; i < new_coalesce.n_rules; i++) { 14006 tmp_rule = &new_coalesce.rules[i]; 14007 for (j = 0; j < tmp_rule->n_patterns; j++) 14008 kfree(tmp_rule->patterns[j].mask); 14009 kfree(tmp_rule->patterns); 14010 } 14011 kfree(new_coalesce.rules); 14012 14013 return err; 14014 } 14015 14016 static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) 14017 { 14018 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14019 struct net_device *dev = info->user_ptr[1]; 14020 struct wireless_dev *wdev = dev->ieee80211_ptr; 14021 struct nlattr *tb[NUM_NL80211_REKEY_DATA]; 14022 struct cfg80211_gtk_rekey_data rekey_data = {}; 14023 int err; 14024 14025 if (!info->attrs[NL80211_ATTR_REKEY_DATA]) 14026 return -EINVAL; 14027 14028 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, 14029 info->attrs[NL80211_ATTR_REKEY_DATA], 14030 nl80211_rekey_policy, info->extack); 14031 if (err) 14032 return err; 14033 14034 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || 14035 !tb[NL80211_REKEY_DATA_KCK]) 14036 return -EINVAL; 14037 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && 14038 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 14039 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) 14040 return -ERANGE; 14041 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && 14042 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && 14043 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN) && 14044 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KCK_32 && 14045 nla_len(tb[NL80211_REKEY_DATA_KCK]) == NL80211_KCK_EXT_LEN_32)) 14046 return -ERANGE; 14047 14048 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); 14049 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); 14050 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); 14051 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); 14052 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); 14053 if (tb[NL80211_REKEY_DATA_AKM]) 14054 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); 14055 14056 if (!wdev->connected) 14057 return -ENOTCONN; 14058 14059 if (!rdev->ops->set_rekey_data) 14060 return -EOPNOTSUPP; 14061 14062 return rdev_set_rekey_data(rdev, dev, &rekey_data); 14063 } 14064 14065 static int nl80211_register_unexpected_frame(struct sk_buff *skb, 14066 struct genl_info *info) 14067 { 14068 struct net_device *dev = info->user_ptr[1]; 14069 struct wireless_dev *wdev = dev->ieee80211_ptr; 14070 14071 if (wdev->iftype != NL80211_IFTYPE_AP && 14072 wdev->iftype != NL80211_IFTYPE_P2P_GO) 14073 return -EINVAL; 14074 14075 if (wdev->ap_unexpected_nlportid) 14076 return -EBUSY; 14077 14078 wdev->ap_unexpected_nlportid = info->snd_portid; 14079 return 0; 14080 } 14081 14082 static int nl80211_probe_client(struct sk_buff *skb, 14083 struct genl_info *info) 14084 { 14085 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14086 struct net_device *dev = info->user_ptr[1]; 14087 struct wireless_dev *wdev = dev->ieee80211_ptr; 14088 struct sk_buff *msg; 14089 void *hdr; 14090 const u8 *addr; 14091 u64 cookie; 14092 int err; 14093 14094 if (wdev->iftype != NL80211_IFTYPE_AP && 14095 wdev->iftype != NL80211_IFTYPE_P2P_GO) 14096 return -EOPNOTSUPP; 14097 14098 if (!info->attrs[NL80211_ATTR_MAC]) 14099 return -EINVAL; 14100 14101 if (!rdev->ops->probe_client) 14102 return -EOPNOTSUPP; 14103 14104 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14105 if (!msg) 14106 return -ENOMEM; 14107 14108 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14109 NL80211_CMD_PROBE_CLIENT); 14110 if (!hdr) { 14111 err = -ENOBUFS; 14112 goto free_msg; 14113 } 14114 14115 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 14116 14117 err = rdev_probe_client(rdev, dev, addr, &cookie); 14118 if (err) 14119 goto free_msg; 14120 14121 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 14122 NL80211_ATTR_PAD)) 14123 goto nla_put_failure; 14124 14125 genlmsg_end(msg, hdr); 14126 14127 return genlmsg_reply(msg, info); 14128 14129 nla_put_failure: 14130 err = -ENOBUFS; 14131 free_msg: 14132 nlmsg_free(msg); 14133 return err; 14134 } 14135 14136 static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) 14137 { 14138 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14139 struct cfg80211_beacon_registration *reg, *nreg; 14140 int rv; 14141 14142 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) 14143 return -EOPNOTSUPP; 14144 14145 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); 14146 if (!nreg) 14147 return -ENOMEM; 14148 14149 /* First, check if already registered. */ 14150 spin_lock_bh(&rdev->beacon_registrations_lock); 14151 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 14152 if (reg->nlportid == info->snd_portid) { 14153 rv = -EALREADY; 14154 goto out_err; 14155 } 14156 } 14157 /* Add it to the list */ 14158 nreg->nlportid = info->snd_portid; 14159 list_add(&nreg->list, &rdev->beacon_registrations); 14160 14161 spin_unlock_bh(&rdev->beacon_registrations_lock); 14162 14163 return 0; 14164 out_err: 14165 spin_unlock_bh(&rdev->beacon_registrations_lock); 14166 kfree(nreg); 14167 return rv; 14168 } 14169 14170 static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) 14171 { 14172 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14173 struct wireless_dev *wdev = info->user_ptr[1]; 14174 int err; 14175 14176 if (!rdev->ops->start_p2p_device) 14177 return -EOPNOTSUPP; 14178 14179 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 14180 return -EOPNOTSUPP; 14181 14182 if (wdev_running(wdev)) 14183 return 0; 14184 14185 if (rfkill_blocked(rdev->wiphy.rfkill)) 14186 return -ERFKILL; 14187 14188 err = rdev_start_p2p_device(rdev, wdev); 14189 if (err) 14190 return err; 14191 14192 wdev->is_running = true; 14193 rdev->opencount++; 14194 14195 return 0; 14196 } 14197 14198 static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) 14199 { 14200 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14201 struct wireless_dev *wdev = info->user_ptr[1]; 14202 14203 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) 14204 return -EOPNOTSUPP; 14205 14206 if (!rdev->ops->stop_p2p_device) 14207 return -EOPNOTSUPP; 14208 14209 cfg80211_stop_p2p_device(rdev, wdev); 14210 14211 return 0; 14212 } 14213 14214 static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) 14215 { 14216 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14217 struct wireless_dev *wdev = info->user_ptr[1]; 14218 struct cfg80211_nan_conf conf = {}; 14219 int err; 14220 14221 if (wdev->iftype != NL80211_IFTYPE_NAN) 14222 return -EOPNOTSUPP; 14223 14224 if (wdev_running(wdev)) 14225 return -EEXIST; 14226 14227 if (rfkill_blocked(rdev->wiphy.rfkill)) 14228 return -ERFKILL; 14229 14230 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) 14231 return -EINVAL; 14232 14233 conf.master_pref = 14234 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14235 14236 if (info->attrs[NL80211_ATTR_BANDS]) { 14237 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14238 14239 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14240 return -EOPNOTSUPP; 14241 14242 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14243 return -EINVAL; 14244 14245 conf.bands = bands; 14246 } 14247 14248 err = rdev_start_nan(rdev, wdev, &conf); 14249 if (err) 14250 return err; 14251 14252 wdev->is_running = true; 14253 rdev->opencount++; 14254 14255 return 0; 14256 } 14257 14258 static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) 14259 { 14260 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14261 struct wireless_dev *wdev = info->user_ptr[1]; 14262 14263 if (wdev->iftype != NL80211_IFTYPE_NAN) 14264 return -EOPNOTSUPP; 14265 14266 cfg80211_stop_nan(rdev, wdev); 14267 14268 return 0; 14269 } 14270 14271 static int validate_nan_filter(struct nlattr *filter_attr) 14272 { 14273 struct nlattr *attr; 14274 int len = 0, n_entries = 0, rem; 14275 14276 nla_for_each_nested(attr, filter_attr, rem) { 14277 len += nla_len(attr); 14278 n_entries++; 14279 } 14280 14281 if (len >= U8_MAX) 14282 return -EINVAL; 14283 14284 return n_entries; 14285 } 14286 14287 static int handle_nan_filter(struct nlattr *attr_filter, 14288 struct cfg80211_nan_func *func, 14289 bool tx) 14290 { 14291 struct nlattr *attr; 14292 int n_entries, rem, i; 14293 struct cfg80211_nan_func_filter *filter; 14294 14295 n_entries = validate_nan_filter(attr_filter); 14296 if (n_entries < 0) 14297 return n_entries; 14298 14299 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); 14300 14301 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); 14302 if (!filter) 14303 return -ENOMEM; 14304 14305 i = 0; 14306 nla_for_each_nested(attr, attr_filter, rem) { 14307 filter[i].filter = nla_memdup(attr, GFP_KERNEL); 14308 if (!filter[i].filter) 14309 goto err; 14310 14311 filter[i].len = nla_len(attr); 14312 i++; 14313 } 14314 if (tx) { 14315 func->num_tx_filters = n_entries; 14316 func->tx_filters = filter; 14317 } else { 14318 func->num_rx_filters = n_entries; 14319 func->rx_filters = filter; 14320 } 14321 14322 return 0; 14323 14324 err: 14325 i = 0; 14326 nla_for_each_nested(attr, attr_filter, rem) { 14327 kfree(filter[i].filter); 14328 i++; 14329 } 14330 kfree(filter); 14331 return -ENOMEM; 14332 } 14333 14334 static int nl80211_nan_add_func(struct sk_buff *skb, 14335 struct genl_info *info) 14336 { 14337 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14338 struct wireless_dev *wdev = info->user_ptr[1]; 14339 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; 14340 struct cfg80211_nan_func *func; 14341 struct sk_buff *msg = NULL; 14342 void *hdr = NULL; 14343 int err = 0; 14344 14345 if (wdev->iftype != NL80211_IFTYPE_NAN) 14346 return -EOPNOTSUPP; 14347 14348 if (!wdev_running(wdev)) 14349 return -ENOTCONN; 14350 14351 if (!info->attrs[NL80211_ATTR_NAN_FUNC]) 14352 return -EINVAL; 14353 14354 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, 14355 info->attrs[NL80211_ATTR_NAN_FUNC], 14356 nl80211_nan_func_policy, 14357 info->extack); 14358 if (err) 14359 return err; 14360 14361 func = kzalloc(sizeof(*func), GFP_KERNEL); 14362 if (!func) 14363 return -ENOMEM; 14364 14365 func->cookie = cfg80211_assign_cookie(rdev); 14366 14367 if (!tb[NL80211_NAN_FUNC_TYPE]) { 14368 err = -EINVAL; 14369 goto out; 14370 } 14371 14372 14373 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); 14374 14375 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { 14376 err = -EINVAL; 14377 goto out; 14378 } 14379 14380 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), 14381 sizeof(func->service_id)); 14382 14383 func->close_range = 14384 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); 14385 14386 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { 14387 func->serv_spec_info_len = 14388 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); 14389 func->serv_spec_info = 14390 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), 14391 func->serv_spec_info_len, 14392 GFP_KERNEL); 14393 if (!func->serv_spec_info) { 14394 err = -ENOMEM; 14395 goto out; 14396 } 14397 } 14398 14399 if (tb[NL80211_NAN_FUNC_TTL]) 14400 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); 14401 14402 switch (func->type) { 14403 case NL80211_NAN_FUNC_PUBLISH: 14404 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { 14405 err = -EINVAL; 14406 goto out; 14407 } 14408 14409 func->publish_type = 14410 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); 14411 func->publish_bcast = 14412 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); 14413 14414 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && 14415 func->publish_bcast) { 14416 err = -EINVAL; 14417 goto out; 14418 } 14419 break; 14420 case NL80211_NAN_FUNC_SUBSCRIBE: 14421 func->subscribe_active = 14422 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); 14423 break; 14424 case NL80211_NAN_FUNC_FOLLOW_UP: 14425 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || 14426 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || 14427 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { 14428 err = -EINVAL; 14429 goto out; 14430 } 14431 14432 func->followup_id = 14433 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); 14434 func->followup_reqid = 14435 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); 14436 memcpy(func->followup_dest.addr, 14437 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), 14438 sizeof(func->followup_dest.addr)); 14439 if (func->ttl) { 14440 err = -EINVAL; 14441 goto out; 14442 } 14443 break; 14444 default: 14445 err = -EINVAL; 14446 goto out; 14447 } 14448 14449 if (tb[NL80211_NAN_FUNC_SRF]) { 14450 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; 14451 14452 err = nla_parse_nested_deprecated(srf_tb, 14453 NL80211_NAN_SRF_ATTR_MAX, 14454 tb[NL80211_NAN_FUNC_SRF], 14455 nl80211_nan_srf_policy, 14456 info->extack); 14457 if (err) 14458 goto out; 14459 14460 func->srf_include = 14461 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); 14462 14463 if (srf_tb[NL80211_NAN_SRF_BF]) { 14464 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || 14465 !srf_tb[NL80211_NAN_SRF_BF_IDX]) { 14466 err = -EINVAL; 14467 goto out; 14468 } 14469 14470 func->srf_bf_len = 14471 nla_len(srf_tb[NL80211_NAN_SRF_BF]); 14472 func->srf_bf = 14473 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), 14474 func->srf_bf_len, GFP_KERNEL); 14475 if (!func->srf_bf) { 14476 err = -ENOMEM; 14477 goto out; 14478 } 14479 14480 func->srf_bf_idx = 14481 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); 14482 } else { 14483 struct nlattr *attr, *mac_attr = 14484 srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; 14485 int n_entries, rem, i = 0; 14486 14487 if (!mac_attr) { 14488 err = -EINVAL; 14489 goto out; 14490 } 14491 14492 n_entries = validate_acl_mac_addrs(mac_attr); 14493 if (n_entries <= 0) { 14494 err = -EINVAL; 14495 goto out; 14496 } 14497 14498 func->srf_num_macs = n_entries; 14499 func->srf_macs = 14500 kcalloc(n_entries, sizeof(*func->srf_macs), 14501 GFP_KERNEL); 14502 if (!func->srf_macs) { 14503 err = -ENOMEM; 14504 goto out; 14505 } 14506 14507 nla_for_each_nested(attr, mac_attr, rem) 14508 memcpy(func->srf_macs[i++].addr, nla_data(attr), 14509 sizeof(*func->srf_macs)); 14510 } 14511 } 14512 14513 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { 14514 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], 14515 func, true); 14516 if (err) 14517 goto out; 14518 } 14519 14520 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { 14521 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], 14522 func, false); 14523 if (err) 14524 goto out; 14525 } 14526 14527 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14528 if (!msg) { 14529 err = -ENOMEM; 14530 goto out; 14531 } 14532 14533 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14534 NL80211_CMD_ADD_NAN_FUNCTION); 14535 /* This can't really happen - we just allocated 4KB */ 14536 if (WARN_ON(!hdr)) { 14537 err = -ENOMEM; 14538 goto out; 14539 } 14540 14541 err = rdev_add_nan_func(rdev, wdev, func); 14542 out: 14543 if (err < 0) { 14544 cfg80211_free_nan_func(func); 14545 nlmsg_free(msg); 14546 return err; 14547 } 14548 14549 /* propagate the instance id and cookie to userspace */ 14550 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, 14551 NL80211_ATTR_PAD)) 14552 goto nla_put_failure; 14553 14554 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14555 if (!func_attr) 14556 goto nla_put_failure; 14557 14558 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, 14559 func->instance_id)) 14560 goto nla_put_failure; 14561 14562 nla_nest_end(msg, func_attr); 14563 14564 genlmsg_end(msg, hdr); 14565 return genlmsg_reply(msg, info); 14566 14567 nla_put_failure: 14568 nlmsg_free(msg); 14569 return -ENOBUFS; 14570 } 14571 14572 static int nl80211_nan_del_func(struct sk_buff *skb, 14573 struct genl_info *info) 14574 { 14575 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14576 struct wireless_dev *wdev = info->user_ptr[1]; 14577 u64 cookie; 14578 14579 if (wdev->iftype != NL80211_IFTYPE_NAN) 14580 return -EOPNOTSUPP; 14581 14582 if (!wdev_running(wdev)) 14583 return -ENOTCONN; 14584 14585 if (!info->attrs[NL80211_ATTR_COOKIE]) 14586 return -EINVAL; 14587 14588 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); 14589 14590 rdev_del_nan_func(rdev, wdev, cookie); 14591 14592 return 0; 14593 } 14594 14595 static int nl80211_nan_change_config(struct sk_buff *skb, 14596 struct genl_info *info) 14597 { 14598 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14599 struct wireless_dev *wdev = info->user_ptr[1]; 14600 struct cfg80211_nan_conf conf = {}; 14601 u32 changed = 0; 14602 14603 if (wdev->iftype != NL80211_IFTYPE_NAN) 14604 return -EOPNOTSUPP; 14605 14606 if (!wdev_running(wdev)) 14607 return -ENOTCONN; 14608 14609 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { 14610 conf.master_pref = 14611 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); 14612 if (conf.master_pref <= 1 || conf.master_pref == 255) 14613 return -EINVAL; 14614 14615 changed |= CFG80211_NAN_CONF_CHANGED_PREF; 14616 } 14617 14618 if (info->attrs[NL80211_ATTR_BANDS]) { 14619 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); 14620 14621 if (bands & ~(u32)wdev->wiphy->nan_supported_bands) 14622 return -EOPNOTSUPP; 14623 14624 if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) 14625 return -EINVAL; 14626 14627 conf.bands = bands; 14628 changed |= CFG80211_NAN_CONF_CHANGED_BANDS; 14629 } 14630 14631 if (!changed) 14632 return -EINVAL; 14633 14634 return rdev_nan_change_conf(rdev, wdev, &conf, changed); 14635 } 14636 14637 void cfg80211_nan_match(struct wireless_dev *wdev, 14638 struct cfg80211_nan_match_params *match, gfp_t gfp) 14639 { 14640 struct wiphy *wiphy = wdev->wiphy; 14641 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14642 struct nlattr *match_attr, *local_func_attr, *peer_func_attr; 14643 struct sk_buff *msg; 14644 void *hdr; 14645 14646 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) 14647 return; 14648 14649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14650 if (!msg) 14651 return; 14652 14653 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); 14654 if (!hdr) { 14655 nlmsg_free(msg); 14656 return; 14657 } 14658 14659 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14660 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14661 wdev->netdev->ifindex)) || 14662 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14663 NL80211_ATTR_PAD)) 14664 goto nla_put_failure; 14665 14666 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, 14667 NL80211_ATTR_PAD) || 14668 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) 14669 goto nla_put_failure; 14670 14671 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); 14672 if (!match_attr) 14673 goto nla_put_failure; 14674 14675 local_func_attr = nla_nest_start_noflag(msg, 14676 NL80211_NAN_MATCH_FUNC_LOCAL); 14677 if (!local_func_attr) 14678 goto nla_put_failure; 14679 14680 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) 14681 goto nla_put_failure; 14682 14683 nla_nest_end(msg, local_func_attr); 14684 14685 peer_func_attr = nla_nest_start_noflag(msg, 14686 NL80211_NAN_MATCH_FUNC_PEER); 14687 if (!peer_func_attr) 14688 goto nla_put_failure; 14689 14690 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || 14691 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) 14692 goto nla_put_failure; 14693 14694 if (match->info && match->info_len && 14695 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, 14696 match->info)) 14697 goto nla_put_failure; 14698 14699 nla_nest_end(msg, peer_func_attr); 14700 nla_nest_end(msg, match_attr); 14701 genlmsg_end(msg, hdr); 14702 14703 if (!wdev->owner_nlportid) 14704 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14705 msg, 0, NL80211_MCGRP_NAN, gfp); 14706 else 14707 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14708 wdev->owner_nlportid); 14709 14710 return; 14711 14712 nla_put_failure: 14713 nlmsg_free(msg); 14714 } 14715 EXPORT_SYMBOL(cfg80211_nan_match); 14716 14717 void cfg80211_nan_func_terminated(struct wireless_dev *wdev, 14718 u8 inst_id, 14719 enum nl80211_nan_func_term_reason reason, 14720 u64 cookie, gfp_t gfp) 14721 { 14722 struct wiphy *wiphy = wdev->wiphy; 14723 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 14724 struct sk_buff *msg; 14725 struct nlattr *func_attr; 14726 void *hdr; 14727 14728 if (WARN_ON(!inst_id)) 14729 return; 14730 14731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 14732 if (!msg) 14733 return; 14734 14735 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); 14736 if (!hdr) { 14737 nlmsg_free(msg); 14738 return; 14739 } 14740 14741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 14742 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 14743 wdev->netdev->ifindex)) || 14744 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 14745 NL80211_ATTR_PAD)) 14746 goto nla_put_failure; 14747 14748 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 14749 NL80211_ATTR_PAD)) 14750 goto nla_put_failure; 14751 14752 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); 14753 if (!func_attr) 14754 goto nla_put_failure; 14755 14756 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || 14757 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) 14758 goto nla_put_failure; 14759 14760 nla_nest_end(msg, func_attr); 14761 genlmsg_end(msg, hdr); 14762 14763 if (!wdev->owner_nlportid) 14764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 14765 msg, 0, NL80211_MCGRP_NAN, gfp); 14766 else 14767 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 14768 wdev->owner_nlportid); 14769 14770 return; 14771 14772 nla_put_failure: 14773 nlmsg_free(msg); 14774 } 14775 EXPORT_SYMBOL(cfg80211_nan_func_terminated); 14776 14777 static int nl80211_get_protocol_features(struct sk_buff *skb, 14778 struct genl_info *info) 14779 { 14780 void *hdr; 14781 struct sk_buff *msg; 14782 14783 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 14784 if (!msg) 14785 return -ENOMEM; 14786 14787 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 14788 NL80211_CMD_GET_PROTOCOL_FEATURES); 14789 if (!hdr) 14790 goto nla_put_failure; 14791 14792 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, 14793 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) 14794 goto nla_put_failure; 14795 14796 genlmsg_end(msg, hdr); 14797 return genlmsg_reply(msg, info); 14798 14799 nla_put_failure: 14800 kfree_skb(msg); 14801 return -ENOBUFS; 14802 } 14803 14804 static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) 14805 { 14806 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14807 struct cfg80211_update_ft_ies_params ft_params; 14808 struct net_device *dev = info->user_ptr[1]; 14809 14810 if (!rdev->ops->update_ft_ies) 14811 return -EOPNOTSUPP; 14812 14813 if (!info->attrs[NL80211_ATTR_MDID] || 14814 !info->attrs[NL80211_ATTR_IE]) 14815 return -EINVAL; 14816 14817 memset(&ft_params, 0, sizeof(ft_params)); 14818 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); 14819 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 14820 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 14821 14822 return rdev_update_ft_ies(rdev, dev, &ft_params); 14823 } 14824 14825 static int nl80211_crit_protocol_start(struct sk_buff *skb, 14826 struct genl_info *info) 14827 { 14828 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14829 struct wireless_dev *wdev = info->user_ptr[1]; 14830 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; 14831 u16 duration; 14832 int ret; 14833 14834 if (!rdev->ops->crit_proto_start) 14835 return -EOPNOTSUPP; 14836 14837 if (WARN_ON(!rdev->ops->crit_proto_stop)) 14838 return -EINVAL; 14839 14840 if (rdev->crit_proto_nlportid) 14841 return -EBUSY; 14842 14843 /* determine protocol if provided */ 14844 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) 14845 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); 14846 14847 if (proto >= NUM_NL80211_CRIT_PROTO) 14848 return -EINVAL; 14849 14850 /* timeout must be provided */ 14851 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) 14852 return -EINVAL; 14853 14854 duration = 14855 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); 14856 14857 ret = rdev_crit_proto_start(rdev, wdev, proto, duration); 14858 if (!ret) 14859 rdev->crit_proto_nlportid = info->snd_portid; 14860 14861 return ret; 14862 } 14863 14864 static int nl80211_crit_protocol_stop(struct sk_buff *skb, 14865 struct genl_info *info) 14866 { 14867 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14868 struct wireless_dev *wdev = info->user_ptr[1]; 14869 14870 if (!rdev->ops->crit_proto_stop) 14871 return -EOPNOTSUPP; 14872 14873 if (rdev->crit_proto_nlportid) { 14874 rdev->crit_proto_nlportid = 0; 14875 rdev_crit_proto_stop(rdev, wdev); 14876 } 14877 return 0; 14878 } 14879 14880 static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, 14881 struct nlattr *attr, 14882 struct netlink_ext_ack *extack) 14883 { 14884 if (vcmd->policy == VENDOR_CMD_RAW_DATA) { 14885 if (attr->nla_type & NLA_F_NESTED) { 14886 NL_SET_ERR_MSG_ATTR(extack, attr, 14887 "unexpected nested data"); 14888 return -EINVAL; 14889 } 14890 14891 return 0; 14892 } 14893 14894 if (!(attr->nla_type & NLA_F_NESTED)) { 14895 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); 14896 return -EINVAL; 14897 } 14898 14899 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); 14900 } 14901 14902 static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) 14903 { 14904 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 14905 struct wireless_dev *wdev = 14906 __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), 14907 info->attrs); 14908 int i, err; 14909 u32 vid, subcmd; 14910 14911 if (!rdev->wiphy.vendor_commands) 14912 return -EOPNOTSUPP; 14913 14914 if (IS_ERR(wdev)) { 14915 err = PTR_ERR(wdev); 14916 if (err != -EINVAL) 14917 return err; 14918 wdev = NULL; 14919 } else if (wdev->wiphy != &rdev->wiphy) { 14920 return -EINVAL; 14921 } 14922 14923 if (!info->attrs[NL80211_ATTR_VENDOR_ID] || 14924 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) 14925 return -EINVAL; 14926 14927 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); 14928 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); 14929 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { 14930 const struct wiphy_vendor_command *vcmd; 14931 void *data = NULL; 14932 int len = 0; 14933 14934 vcmd = &rdev->wiphy.vendor_commands[i]; 14935 14936 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 14937 continue; 14938 14939 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 14940 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 14941 if (!wdev) 14942 return -EINVAL; 14943 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 14944 !wdev->netdev) 14945 return -EINVAL; 14946 14947 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 14948 if (!wdev_running(wdev)) 14949 return -ENETDOWN; 14950 } 14951 } else { 14952 wdev = NULL; 14953 } 14954 14955 if (!vcmd->doit) 14956 return -EOPNOTSUPP; 14957 14958 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { 14959 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14960 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); 14961 14962 err = nl80211_vendor_check_policy(vcmd, 14963 info->attrs[NL80211_ATTR_VENDOR_DATA], 14964 info->extack); 14965 if (err) 14966 return err; 14967 } 14968 14969 rdev->cur_cmd_info = info; 14970 err = vcmd->doit(&rdev->wiphy, wdev, data, len); 14971 rdev->cur_cmd_info = NULL; 14972 return err; 14973 } 14974 14975 return -EOPNOTSUPP; 14976 } 14977 14978 static int nl80211_prepare_vendor_dump(struct sk_buff *skb, 14979 struct netlink_callback *cb, 14980 struct cfg80211_registered_device **rdev, 14981 struct wireless_dev **wdev) 14982 { 14983 struct nlattr **attrbuf; 14984 u32 vid, subcmd; 14985 unsigned int i; 14986 int vcmd_idx = -1; 14987 int err; 14988 void *data = NULL; 14989 unsigned int data_len = 0; 14990 14991 if (cb->args[0]) { 14992 /* subtract the 1 again here */ 14993 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); 14994 struct wireless_dev *tmp; 14995 14996 if (!wiphy) 14997 return -ENODEV; 14998 *rdev = wiphy_to_rdev(wiphy); 14999 *wdev = NULL; 15000 15001 if (cb->args[1]) { 15002 list_for_each_entry(tmp, &wiphy->wdev_list, list) { 15003 if (tmp->identifier == cb->args[1] - 1) { 15004 *wdev = tmp; 15005 break; 15006 } 15007 } 15008 } 15009 15010 /* keep rtnl locked in successful case */ 15011 return 0; 15012 } 15013 15014 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); 15015 if (!attrbuf) 15016 return -ENOMEM; 15017 15018 err = nlmsg_parse_deprecated(cb->nlh, 15019 GENL_HDRLEN + nl80211_fam.hdrsize, 15020 attrbuf, nl80211_fam.maxattr, 15021 nl80211_policy, NULL); 15022 if (err) 15023 goto out; 15024 15025 if (!attrbuf[NL80211_ATTR_VENDOR_ID] || 15026 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { 15027 err = -EINVAL; 15028 goto out; 15029 } 15030 15031 *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); 15032 if (IS_ERR(*wdev)) 15033 *wdev = NULL; 15034 15035 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); 15036 if (IS_ERR(*rdev)) { 15037 err = PTR_ERR(*rdev); 15038 goto out; 15039 } 15040 15041 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); 15042 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); 15043 15044 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { 15045 const struct wiphy_vendor_command *vcmd; 15046 15047 vcmd = &(*rdev)->wiphy.vendor_commands[i]; 15048 15049 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) 15050 continue; 15051 15052 if (!vcmd->dumpit) { 15053 err = -EOPNOTSUPP; 15054 goto out; 15055 } 15056 15057 vcmd_idx = i; 15058 break; 15059 } 15060 15061 if (vcmd_idx < 0) { 15062 err = -EOPNOTSUPP; 15063 goto out; 15064 } 15065 15066 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { 15067 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); 15068 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); 15069 15070 err = nl80211_vendor_check_policy( 15071 &(*rdev)->wiphy.vendor_commands[vcmd_idx], 15072 attrbuf[NL80211_ATTR_VENDOR_DATA], 15073 cb->extack); 15074 if (err) 15075 goto out; 15076 } 15077 15078 /* 0 is the first index - add 1 to parse only once */ 15079 cb->args[0] = (*rdev)->wiphy_idx + 1; 15080 /* add 1 to know if it was NULL */ 15081 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; 15082 cb->args[2] = vcmd_idx; 15083 cb->args[3] = (unsigned long)data; 15084 cb->args[4] = data_len; 15085 15086 /* keep rtnl locked in successful case */ 15087 err = 0; 15088 out: 15089 kfree(attrbuf); 15090 return err; 15091 } 15092 15093 static int nl80211_vendor_cmd_dump(struct sk_buff *skb, 15094 struct netlink_callback *cb) 15095 { 15096 struct cfg80211_registered_device *rdev; 15097 struct wireless_dev *wdev; 15098 unsigned int vcmd_idx; 15099 const struct wiphy_vendor_command *vcmd; 15100 void *data; 15101 int data_len; 15102 int err; 15103 struct nlattr *vendor_data; 15104 15105 rtnl_lock(); 15106 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); 15107 if (err) 15108 goto out; 15109 15110 vcmd_idx = cb->args[2]; 15111 data = (void *)cb->args[3]; 15112 data_len = cb->args[4]; 15113 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; 15114 15115 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | 15116 WIPHY_VENDOR_CMD_NEED_NETDEV)) { 15117 if (!wdev) { 15118 err = -EINVAL; 15119 goto out; 15120 } 15121 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && 15122 !wdev->netdev) { 15123 err = -EINVAL; 15124 goto out; 15125 } 15126 15127 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { 15128 if (!wdev_running(wdev)) { 15129 err = -ENETDOWN; 15130 goto out; 15131 } 15132 } 15133 } 15134 15135 while (1) { 15136 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, 15137 cb->nlh->nlmsg_seq, NLM_F_MULTI, 15138 NL80211_CMD_VENDOR); 15139 if (!hdr) 15140 break; 15141 15142 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 15143 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, 15144 wdev_id(wdev), 15145 NL80211_ATTR_PAD))) { 15146 genlmsg_cancel(skb, hdr); 15147 break; 15148 } 15149 15150 vendor_data = nla_nest_start_noflag(skb, 15151 NL80211_ATTR_VENDOR_DATA); 15152 if (!vendor_data) { 15153 genlmsg_cancel(skb, hdr); 15154 break; 15155 } 15156 15157 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, 15158 (unsigned long *)&cb->args[5]); 15159 nla_nest_end(skb, vendor_data); 15160 15161 if (err == -ENOBUFS || err == -ENOENT) { 15162 genlmsg_cancel(skb, hdr); 15163 break; 15164 } else if (err <= 0) { 15165 genlmsg_cancel(skb, hdr); 15166 goto out; 15167 } 15168 15169 genlmsg_end(skb, hdr); 15170 } 15171 15172 err = skb->len; 15173 out: 15174 rtnl_unlock(); 15175 return err; 15176 } 15177 15178 struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, 15179 enum nl80211_commands cmd, 15180 enum nl80211_attrs attr, 15181 int approxlen) 15182 { 15183 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15184 15185 if (WARN_ON(!rdev->cur_cmd_info)) 15186 return NULL; 15187 15188 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, 15189 rdev->cur_cmd_info->snd_portid, 15190 rdev->cur_cmd_info->snd_seq, 15191 cmd, attr, NULL, GFP_KERNEL); 15192 } 15193 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); 15194 15195 int cfg80211_vendor_cmd_reply(struct sk_buff *skb) 15196 { 15197 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; 15198 void *hdr = ((void **)skb->cb)[1]; 15199 struct nlattr *data = ((void **)skb->cb)[2]; 15200 15201 /* clear CB data for netlink core to own from now on */ 15202 memset(skb->cb, 0, sizeof(skb->cb)); 15203 15204 if (WARN_ON(!rdev->cur_cmd_info)) { 15205 kfree_skb(skb); 15206 return -EINVAL; 15207 } 15208 15209 nla_nest_end(skb, data); 15210 genlmsg_end(skb, hdr); 15211 return genlmsg_reply(skb, rdev->cur_cmd_info); 15212 } 15213 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); 15214 15215 unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) 15216 { 15217 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 15218 15219 if (WARN_ON(!rdev->cur_cmd_info)) 15220 return 0; 15221 15222 return rdev->cur_cmd_info->snd_portid; 15223 } 15224 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); 15225 15226 static int nl80211_set_qos_map(struct sk_buff *skb, 15227 struct genl_info *info) 15228 { 15229 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15230 struct cfg80211_qos_map *qos_map = NULL; 15231 struct net_device *dev = info->user_ptr[1]; 15232 u8 *pos, len, num_des, des_len, des; 15233 int ret; 15234 15235 if (!rdev->ops->set_qos_map) 15236 return -EOPNOTSUPP; 15237 15238 if (info->attrs[NL80211_ATTR_QOS_MAP]) { 15239 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); 15240 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); 15241 15242 if (len % 2) 15243 return -EINVAL; 15244 15245 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); 15246 if (!qos_map) 15247 return -ENOMEM; 15248 15249 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; 15250 if (num_des) { 15251 des_len = num_des * 15252 sizeof(struct cfg80211_dscp_exception); 15253 memcpy(qos_map->dscp_exception, pos, des_len); 15254 qos_map->num_des = num_des; 15255 for (des = 0; des < num_des; des++) { 15256 if (qos_map->dscp_exception[des].up > 7) { 15257 kfree(qos_map); 15258 return -EINVAL; 15259 } 15260 } 15261 pos += des_len; 15262 } 15263 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); 15264 } 15265 15266 ret = nl80211_key_allowed(dev->ieee80211_ptr); 15267 if (!ret) 15268 ret = rdev_set_qos_map(rdev, dev, qos_map); 15269 15270 kfree(qos_map); 15271 return ret; 15272 } 15273 15274 static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) 15275 { 15276 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15277 struct net_device *dev = info->user_ptr[1]; 15278 struct wireless_dev *wdev = dev->ieee80211_ptr; 15279 const u8 *peer; 15280 u8 tsid, up; 15281 u16 admitted_time = 0; 15282 15283 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) 15284 return -EOPNOTSUPP; 15285 15286 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || 15287 !info->attrs[NL80211_ATTR_USER_PRIO]) 15288 return -EINVAL; 15289 15290 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15291 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); 15292 15293 /* WMM uses TIDs 0-7 even for TSPEC */ 15294 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { 15295 /* TODO: handle 802.11 TSPEC/admission control 15296 * need more attributes for that (e.g. BA session requirement); 15297 * change the WMM adminssion test above to allow both then 15298 */ 15299 return -EINVAL; 15300 } 15301 15302 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15303 15304 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { 15305 admitted_time = 15306 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); 15307 if (!admitted_time) 15308 return -EINVAL; 15309 } 15310 15311 switch (wdev->iftype) { 15312 case NL80211_IFTYPE_STATION: 15313 case NL80211_IFTYPE_P2P_CLIENT: 15314 if (wdev->connected) 15315 break; 15316 return -ENOTCONN; 15317 default: 15318 return -EOPNOTSUPP; 15319 } 15320 15321 return rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); 15322 } 15323 15324 static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) 15325 { 15326 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15327 struct net_device *dev = info->user_ptr[1]; 15328 const u8 *peer; 15329 u8 tsid; 15330 15331 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) 15332 return -EINVAL; 15333 15334 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); 15335 peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15336 15337 return rdev_del_tx_ts(rdev, dev, tsid, peer); 15338 } 15339 15340 static int nl80211_tdls_channel_switch(struct sk_buff *skb, 15341 struct genl_info *info) 15342 { 15343 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15344 struct net_device *dev = info->user_ptr[1]; 15345 struct wireless_dev *wdev = dev->ieee80211_ptr; 15346 struct cfg80211_chan_def chandef = {}; 15347 const u8 *addr; 15348 u8 oper_class; 15349 int err; 15350 15351 if (!rdev->ops->tdls_channel_switch || 15352 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15353 return -EOPNOTSUPP; 15354 15355 switch (dev->ieee80211_ptr->iftype) { 15356 case NL80211_IFTYPE_STATION: 15357 case NL80211_IFTYPE_P2P_CLIENT: 15358 break; 15359 default: 15360 return -EOPNOTSUPP; 15361 } 15362 15363 if (!info->attrs[NL80211_ATTR_MAC] || 15364 !info->attrs[NL80211_ATTR_OPER_CLASS]) 15365 return -EINVAL; 15366 15367 err = nl80211_parse_chandef(rdev, info, &chandef); 15368 if (err) 15369 return err; 15370 15371 /* 15372 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 15373 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the 15374 * specification is not defined for them. 15375 */ 15376 if (chandef.chan->band == NL80211_BAND_2GHZ && 15377 chandef.width != NL80211_CHAN_WIDTH_20_NOHT && 15378 chandef.width != NL80211_CHAN_WIDTH_20) 15379 return -EINVAL; 15380 15381 /* we will be active on the TDLS link */ 15382 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, 15383 wdev->iftype)) 15384 return -EINVAL; 15385 15386 /* don't allow switching to DFS channels */ 15387 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) 15388 return -EINVAL; 15389 15390 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15391 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); 15392 15393 return rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); 15394 } 15395 15396 static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, 15397 struct genl_info *info) 15398 { 15399 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15400 struct net_device *dev = info->user_ptr[1]; 15401 const u8 *addr; 15402 15403 if (!rdev->ops->tdls_channel_switch || 15404 !rdev->ops->tdls_cancel_channel_switch || 15405 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) 15406 return -EOPNOTSUPP; 15407 15408 switch (dev->ieee80211_ptr->iftype) { 15409 case NL80211_IFTYPE_STATION: 15410 case NL80211_IFTYPE_P2P_CLIENT: 15411 break; 15412 default: 15413 return -EOPNOTSUPP; 15414 } 15415 15416 if (!info->attrs[NL80211_ATTR_MAC]) 15417 return -EINVAL; 15418 15419 addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 15420 15421 rdev_tdls_cancel_channel_switch(rdev, dev, addr); 15422 15423 return 0; 15424 } 15425 15426 static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, 15427 struct genl_info *info) 15428 { 15429 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15430 struct net_device *dev = info->user_ptr[1]; 15431 struct wireless_dev *wdev = dev->ieee80211_ptr; 15432 const struct nlattr *nla; 15433 bool enabled; 15434 15435 if (!rdev->ops->set_multicast_to_unicast) 15436 return -EOPNOTSUPP; 15437 15438 if (wdev->iftype != NL80211_IFTYPE_AP && 15439 wdev->iftype != NL80211_IFTYPE_P2P_GO) 15440 return -EOPNOTSUPP; 15441 15442 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; 15443 enabled = nla_get_flag(nla); 15444 15445 return rdev_set_multicast_to_unicast(rdev, dev, enabled); 15446 } 15447 15448 static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) 15449 { 15450 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15451 struct net_device *dev = info->user_ptr[1]; 15452 struct wireless_dev *wdev = dev->ieee80211_ptr; 15453 struct cfg80211_pmk_conf pmk_conf = {}; 15454 15455 if (wdev->iftype != NL80211_IFTYPE_STATION && 15456 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15457 return -EOPNOTSUPP; 15458 15459 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15460 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15461 return -EOPNOTSUPP; 15462 15463 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) 15464 return -EINVAL; 15465 15466 if (!wdev->connected) 15467 return -ENOTCONN; 15468 15469 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15470 if (memcmp(pmk_conf.aa, wdev->u.client.connected_addr, ETH_ALEN)) 15471 return -EINVAL; 15472 15473 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); 15474 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); 15475 if (pmk_conf.pmk_len != WLAN_PMK_LEN && 15476 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) 15477 return -EINVAL; 15478 15479 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) 15480 pmk_conf.pmk_r0_name = 15481 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); 15482 15483 return rdev_set_pmk(rdev, dev, &pmk_conf); 15484 } 15485 15486 static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) 15487 { 15488 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15489 struct net_device *dev = info->user_ptr[1]; 15490 struct wireless_dev *wdev = dev->ieee80211_ptr; 15491 const u8 *aa; 15492 15493 if (wdev->iftype != NL80211_IFTYPE_STATION && 15494 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) 15495 return -EOPNOTSUPP; 15496 15497 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15498 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) 15499 return -EOPNOTSUPP; 15500 15501 if (!info->attrs[NL80211_ATTR_MAC]) 15502 return -EINVAL; 15503 15504 aa = nla_data(info->attrs[NL80211_ATTR_MAC]); 15505 return rdev_del_pmk(rdev, dev, aa); 15506 } 15507 15508 static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) 15509 { 15510 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15511 struct net_device *dev = info->user_ptr[1]; 15512 struct cfg80211_external_auth_params params; 15513 15514 if (!rdev->ops->external_auth) 15515 return -EOPNOTSUPP; 15516 15517 if (!info->attrs[NL80211_ATTR_SSID] && 15518 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && 15519 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) 15520 return -EINVAL; 15521 15522 if (!info->attrs[NL80211_ATTR_BSSID]) 15523 return -EINVAL; 15524 15525 if (!info->attrs[NL80211_ATTR_STATUS_CODE]) 15526 return -EINVAL; 15527 15528 memset(¶ms, 0, sizeof(params)); 15529 15530 if (info->attrs[NL80211_ATTR_SSID]) { 15531 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); 15532 if (params.ssid.ssid_len == 0) 15533 return -EINVAL; 15534 memcpy(params.ssid.ssid, 15535 nla_data(info->attrs[NL80211_ATTR_SSID]), 15536 params.ssid.ssid_len); 15537 } 15538 15539 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), 15540 ETH_ALEN); 15541 15542 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15543 15544 if (info->attrs[NL80211_ATTR_PMKID]) 15545 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); 15546 15547 return rdev_external_auth(rdev, dev, ¶ms); 15548 } 15549 15550 static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) 15551 { 15552 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; 15553 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15554 struct net_device *dev = info->user_ptr[1]; 15555 struct wireless_dev *wdev = dev->ieee80211_ptr; 15556 const u8 *buf; 15557 size_t len; 15558 u8 *dest; 15559 u16 proto; 15560 bool noencrypt; 15561 u64 cookie = 0; 15562 int link_id; 15563 int err; 15564 15565 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15566 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) 15567 return -EOPNOTSUPP; 15568 15569 if (!rdev->ops->tx_control_port) 15570 return -EOPNOTSUPP; 15571 15572 if (!info->attrs[NL80211_ATTR_FRAME] || 15573 !info->attrs[NL80211_ATTR_MAC] || 15574 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { 15575 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); 15576 return -EINVAL; 15577 } 15578 15579 switch (wdev->iftype) { 15580 case NL80211_IFTYPE_AP: 15581 case NL80211_IFTYPE_P2P_GO: 15582 case NL80211_IFTYPE_MESH_POINT: 15583 break; 15584 case NL80211_IFTYPE_ADHOC: 15585 if (wdev->u.ibss.current_bss) 15586 break; 15587 return -ENOTCONN; 15588 case NL80211_IFTYPE_STATION: 15589 case NL80211_IFTYPE_P2P_CLIENT: 15590 if (wdev->connected) 15591 break; 15592 return -ENOTCONN; 15593 default: 15594 return -EOPNOTSUPP; 15595 } 15596 15597 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15598 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15599 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15600 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); 15601 noencrypt = 15602 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); 15603 15604 link_id = nl80211_link_id_or_invalid(info->attrs); 15605 15606 err = rdev_tx_control_port(rdev, dev, buf, len, 15607 dest, cpu_to_be16(proto), noencrypt, link_id, 15608 dont_wait_for_ack ? NULL : &cookie); 15609 if (!err && !dont_wait_for_ack) 15610 nl_set_extack_cookie_u64(info->extack, cookie); 15611 return err; 15612 } 15613 15614 static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, 15615 struct genl_info *info) 15616 { 15617 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15618 struct net_device *dev = info->user_ptr[1]; 15619 struct wireless_dev *wdev = dev->ieee80211_ptr; 15620 struct cfg80211_ftm_responder_stats ftm_stats = {}; 15621 unsigned int link_id = nl80211_link_id(info->attrs); 15622 struct sk_buff *msg; 15623 void *hdr; 15624 struct nlattr *ftm_stats_attr; 15625 int err; 15626 15627 if (wdev->iftype != NL80211_IFTYPE_AP || 15628 !wdev->links[link_id].ap.beacon_interval) 15629 return -EOPNOTSUPP; 15630 15631 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); 15632 if (err) 15633 return err; 15634 15635 if (!ftm_stats.filled) 15636 return -ENODATA; 15637 15638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 15639 if (!msg) 15640 return -ENOMEM; 15641 15642 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, 15643 NL80211_CMD_GET_FTM_RESPONDER_STATS); 15644 if (!hdr) 15645 goto nla_put_failure; 15646 15647 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 15648 goto nla_put_failure; 15649 15650 ftm_stats_attr = nla_nest_start_noflag(msg, 15651 NL80211_ATTR_FTM_RESPONDER_STATS); 15652 if (!ftm_stats_attr) 15653 goto nla_put_failure; 15654 15655 #define SET_FTM(field, name, type) \ 15656 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15657 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ 15658 ftm_stats.field)) \ 15659 goto nla_put_failure; } while (0) 15660 #define SET_FTM_U64(field, name) \ 15661 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ 15662 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ 15663 ftm_stats.field, NL80211_FTM_STATS_PAD)) \ 15664 goto nla_put_failure; } while (0) 15665 15666 SET_FTM(success_num, SUCCESS_NUM, u32); 15667 SET_FTM(partial_num, PARTIAL_NUM, u32); 15668 SET_FTM(failed_num, FAILED_NUM, u32); 15669 SET_FTM(asap_num, ASAP_NUM, u32); 15670 SET_FTM(non_asap_num, NON_ASAP_NUM, u32); 15671 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); 15672 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); 15673 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); 15674 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); 15675 #undef SET_FTM 15676 15677 nla_nest_end(msg, ftm_stats_attr); 15678 15679 genlmsg_end(msg, hdr); 15680 return genlmsg_reply(msg, info); 15681 15682 nla_put_failure: 15683 nlmsg_free(msg); 15684 return -ENOBUFS; 15685 } 15686 15687 static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) 15688 { 15689 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15690 struct cfg80211_update_owe_info owe_info; 15691 struct net_device *dev = info->user_ptr[1]; 15692 15693 if (!rdev->ops->update_owe_info) 15694 return -EOPNOTSUPP; 15695 15696 if (!info->attrs[NL80211_ATTR_STATUS_CODE] || 15697 !info->attrs[NL80211_ATTR_MAC]) 15698 return -EINVAL; 15699 15700 memset(&owe_info, 0, sizeof(owe_info)); 15701 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); 15702 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); 15703 15704 if (info->attrs[NL80211_ATTR_IE]) { 15705 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); 15706 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 15707 } 15708 15709 return rdev_update_owe_info(rdev, dev, &owe_info); 15710 } 15711 15712 static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) 15713 { 15714 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15715 struct net_device *dev = info->user_ptr[1]; 15716 struct wireless_dev *wdev = dev->ieee80211_ptr; 15717 struct station_info sinfo = {}; 15718 const u8 *buf; 15719 size_t len; 15720 u8 *dest; 15721 int err; 15722 15723 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) 15724 return -EOPNOTSUPP; 15725 15726 if (!info->attrs[NL80211_ATTR_MAC] || 15727 !info->attrs[NL80211_ATTR_FRAME]) { 15728 GENL_SET_ERR_MSG(info, "Frame or MAC missing"); 15729 return -EINVAL; 15730 } 15731 15732 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) 15733 return -EOPNOTSUPP; 15734 15735 dest = nla_data(info->attrs[NL80211_ATTR_MAC]); 15736 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); 15737 len = nla_len(info->attrs[NL80211_ATTR_FRAME]); 15738 15739 if (len < sizeof(struct ethhdr)) 15740 return -EINVAL; 15741 15742 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || 15743 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) 15744 return -EINVAL; 15745 15746 err = rdev_get_station(rdev, dev, dest, &sinfo); 15747 if (err) 15748 return err; 15749 15750 cfg80211_sinfo_release_content(&sinfo); 15751 15752 return rdev_probe_mesh_link(rdev, dev, dest, buf, len); 15753 } 15754 15755 static int parse_tid_conf(struct cfg80211_registered_device *rdev, 15756 struct nlattr *attrs[], struct net_device *dev, 15757 struct cfg80211_tid_cfg *tid_conf, 15758 struct genl_info *info, const u8 *peer, 15759 unsigned int link_id) 15760 { 15761 struct netlink_ext_ack *extack = info->extack; 15762 u64 mask; 15763 int err; 15764 15765 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) 15766 return -EINVAL; 15767 15768 tid_conf->config_override = 15769 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); 15770 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); 15771 15772 if (tid_conf->config_override) { 15773 if (rdev->ops->reset_tid_config) { 15774 err = rdev_reset_tid_config(rdev, dev, peer, 15775 tid_conf->tids); 15776 if (err) 15777 return err; 15778 } else { 15779 return -EINVAL; 15780 } 15781 } 15782 15783 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { 15784 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); 15785 tid_conf->noack = 15786 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); 15787 } 15788 15789 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { 15790 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); 15791 tid_conf->retry_short = 15792 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); 15793 15794 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) 15795 return -EINVAL; 15796 } 15797 15798 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { 15799 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); 15800 tid_conf->retry_long = 15801 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); 15802 15803 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) 15804 return -EINVAL; 15805 } 15806 15807 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { 15808 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); 15809 tid_conf->ampdu = 15810 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); 15811 } 15812 15813 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { 15814 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); 15815 tid_conf->rtscts = 15816 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); 15817 } 15818 15819 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { 15820 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); 15821 tid_conf->amsdu = 15822 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); 15823 } 15824 15825 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { 15826 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; 15827 15828 tid_conf->txrate_type = nla_get_u8(attrs[idx]); 15829 15830 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { 15831 attr = NL80211_TID_CONFIG_ATTR_TX_RATE; 15832 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, 15833 &tid_conf->txrate_mask, dev, 15834 true, link_id); 15835 if (err) 15836 return err; 15837 15838 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); 15839 } 15840 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); 15841 } 15842 15843 if (peer) 15844 mask = rdev->wiphy.tid_config_support.peer; 15845 else 15846 mask = rdev->wiphy.tid_config_support.vif; 15847 15848 if (tid_conf->mask & ~mask) { 15849 NL_SET_ERR_MSG(extack, "unsupported TID configuration"); 15850 return -ENOTSUPP; 15851 } 15852 15853 return 0; 15854 } 15855 15856 static int nl80211_set_tid_config(struct sk_buff *skb, 15857 struct genl_info *info) 15858 { 15859 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15860 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; 15861 unsigned int link_id = nl80211_link_id(info->attrs); 15862 struct net_device *dev = info->user_ptr[1]; 15863 struct cfg80211_tid_config *tid_config; 15864 struct nlattr *tid; 15865 int conf_idx = 0, rem_conf; 15866 int ret = -EINVAL; 15867 u32 num_conf = 0; 15868 15869 if (!info->attrs[NL80211_ATTR_TID_CONFIG]) 15870 return -EINVAL; 15871 15872 if (!rdev->ops->set_tid_config) 15873 return -EOPNOTSUPP; 15874 15875 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15876 rem_conf) 15877 num_conf++; 15878 15879 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), 15880 GFP_KERNEL); 15881 if (!tid_config) 15882 return -ENOMEM; 15883 15884 tid_config->n_tid_conf = num_conf; 15885 15886 if (info->attrs[NL80211_ATTR_MAC]) 15887 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); 15888 15889 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], 15890 rem_conf) { 15891 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, 15892 tid, NULL, NULL); 15893 15894 if (ret) 15895 goto bad_tid_conf; 15896 15897 ret = parse_tid_conf(rdev, attrs, dev, 15898 &tid_config->tid_conf[conf_idx], 15899 info, tid_config->peer, link_id); 15900 if (ret) 15901 goto bad_tid_conf; 15902 15903 conf_idx++; 15904 } 15905 15906 ret = rdev_set_tid_config(rdev, dev, tid_config); 15907 15908 bad_tid_conf: 15909 kfree(tid_config); 15910 return ret; 15911 } 15912 15913 static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) 15914 { 15915 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 15916 struct cfg80211_color_change_settings params = {}; 15917 struct net_device *dev = info->user_ptr[1]; 15918 struct wireless_dev *wdev = dev->ieee80211_ptr; 15919 struct nlattr **tb; 15920 u16 offset; 15921 int err; 15922 15923 if (!rdev->ops->color_change) 15924 return -EOPNOTSUPP; 15925 15926 if (!wiphy_ext_feature_isset(&rdev->wiphy, 15927 NL80211_EXT_FEATURE_BSS_COLOR)) 15928 return -EOPNOTSUPP; 15929 15930 if (wdev->iftype != NL80211_IFTYPE_AP) 15931 return -EOPNOTSUPP; 15932 15933 if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] || 15934 !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] || 15935 !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS]) 15936 return -EINVAL; 15937 15938 params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]); 15939 params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]); 15940 15941 err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next, 15942 info->extack); 15943 if (err) 15944 return err; 15945 15946 tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL); 15947 if (!tb) 15948 return -ENOMEM; 15949 15950 err = nla_parse_nested(tb, NL80211_ATTR_MAX, 15951 info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS], 15952 nl80211_policy, info->extack); 15953 if (err) 15954 goto out; 15955 15956 err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change, 15957 info->extack); 15958 if (err) 15959 goto out; 15960 15961 if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { 15962 err = -EINVAL; 15963 goto out; 15964 } 15965 15966 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) { 15967 err = -EINVAL; 15968 goto out; 15969 } 15970 15971 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]); 15972 if (offset >= params.beacon_color_change.tail_len) { 15973 err = -EINVAL; 15974 goto out; 15975 } 15976 15977 if (params.beacon_color_change.tail[offset] != params.count) { 15978 err = -EINVAL; 15979 goto out; 15980 } 15981 15982 params.counter_offset_beacon = offset; 15983 15984 if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { 15985 if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) != 15986 sizeof(u16)) { 15987 err = -EINVAL; 15988 goto out; 15989 } 15990 15991 offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]); 15992 if (offset >= params.beacon_color_change.probe_resp_len) { 15993 err = -EINVAL; 15994 goto out; 15995 } 15996 15997 if (params.beacon_color_change.probe_resp[offset] != 15998 params.count) { 15999 err = -EINVAL; 16000 goto out; 16001 } 16002 16003 params.counter_offset_presp = offset; 16004 } 16005 16006 err = rdev_color_change(rdev, dev, ¶ms); 16007 16008 out: 16009 kfree(params.beacon_next.mbssid_ies); 16010 kfree(params.beacon_color_change.mbssid_ies); 16011 kfree(params.beacon_next.rnr_ies); 16012 kfree(params.beacon_color_change.rnr_ies); 16013 kfree(tb); 16014 return err; 16015 } 16016 16017 static int nl80211_set_fils_aad(struct sk_buff *skb, 16018 struct genl_info *info) 16019 { 16020 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16021 struct net_device *dev = info->user_ptr[1]; 16022 struct cfg80211_fils_aad fils_aad = {}; 16023 u8 *nonces; 16024 16025 if (!info->attrs[NL80211_ATTR_MAC] || 16026 !info->attrs[NL80211_ATTR_FILS_KEK] || 16027 !info->attrs[NL80211_ATTR_FILS_NONCES]) 16028 return -EINVAL; 16029 16030 fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); 16031 fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); 16032 fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); 16033 nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); 16034 fils_aad.snonce = nonces; 16035 fils_aad.anonce = nonces + FILS_NONCE_LEN; 16036 16037 return rdev_set_fils_aad(rdev, dev, &fils_aad); 16038 } 16039 16040 static int nl80211_add_link(struct sk_buff *skb, struct genl_info *info) 16041 { 16042 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16043 unsigned int link_id = nl80211_link_id(info->attrs); 16044 struct net_device *dev = info->user_ptr[1]; 16045 struct wireless_dev *wdev = dev->ieee80211_ptr; 16046 int ret; 16047 16048 if (!(wdev->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) 16049 return -EINVAL; 16050 16051 switch (wdev->iftype) { 16052 case NL80211_IFTYPE_AP: 16053 break; 16054 default: 16055 return -EINVAL; 16056 } 16057 16058 if (!info->attrs[NL80211_ATTR_MAC] || 16059 !is_valid_ether_addr(nla_data(info->attrs[NL80211_ATTR_MAC]))) 16060 return -EINVAL; 16061 16062 wdev->valid_links |= BIT(link_id); 16063 ether_addr_copy(wdev->links[link_id].addr, 16064 nla_data(info->attrs[NL80211_ATTR_MAC])); 16065 16066 ret = rdev_add_intf_link(rdev, wdev, link_id); 16067 if (ret) { 16068 wdev->valid_links &= ~BIT(link_id); 16069 eth_zero_addr(wdev->links[link_id].addr); 16070 } 16071 16072 return ret; 16073 } 16074 16075 static int nl80211_remove_link(struct sk_buff *skb, struct genl_info *info) 16076 { 16077 unsigned int link_id = nl80211_link_id(info->attrs); 16078 struct net_device *dev = info->user_ptr[1]; 16079 struct wireless_dev *wdev = dev->ieee80211_ptr; 16080 16081 /* cannot remove if there's no link */ 16082 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16083 return -EINVAL; 16084 16085 switch (wdev->iftype) { 16086 case NL80211_IFTYPE_AP: 16087 break; 16088 default: 16089 return -EINVAL; 16090 } 16091 16092 cfg80211_remove_link(wdev, link_id); 16093 16094 return 0; 16095 } 16096 16097 static int 16098 nl80211_add_mod_link_station(struct sk_buff *skb, struct genl_info *info, 16099 bool add) 16100 { 16101 struct link_station_parameters params = {}; 16102 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16103 struct net_device *dev = info->user_ptr[1]; 16104 int err; 16105 16106 if ((add && !rdev->ops->add_link_station) || 16107 (!add && !rdev->ops->mod_link_station)) 16108 return -EOPNOTSUPP; 16109 16110 if (add && !info->attrs[NL80211_ATTR_MAC]) 16111 return -EINVAL; 16112 16113 if (!info->attrs[NL80211_ATTR_MLD_ADDR]) 16114 return -EINVAL; 16115 16116 if (add && !info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) 16117 return -EINVAL; 16118 16119 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 16120 16121 if (info->attrs[NL80211_ATTR_MAC]) { 16122 params.link_mac = nla_data(info->attrs[NL80211_ATTR_MAC]); 16123 if (!is_valid_ether_addr(params.link_mac)) 16124 return -EINVAL; 16125 } 16126 16127 if (!info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16128 return -EINVAL; 16129 16130 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 16131 16132 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { 16133 params.supported_rates = 16134 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 16135 params.supported_rates_len = 16136 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); 16137 } 16138 16139 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) 16140 params.ht_capa = 16141 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); 16142 16143 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) 16144 params.vht_capa = 16145 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); 16146 16147 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { 16148 params.he_capa = 16149 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 16150 params.he_capa_len = 16151 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); 16152 16153 if (info->attrs[NL80211_ATTR_EHT_CAPABILITY]) { 16154 params.eht_capa = 16155 nla_data(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 16156 params.eht_capa_len = 16157 nla_len(info->attrs[NL80211_ATTR_EHT_CAPABILITY]); 16158 16159 if (!ieee80211_eht_capa_size_ok((const u8 *)params.he_capa, 16160 (const u8 *)params.eht_capa, 16161 params.eht_capa_len, 16162 false)) 16163 return -EINVAL; 16164 } 16165 } 16166 16167 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) 16168 params.he_6ghz_capa = 16169 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); 16170 16171 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { 16172 params.opmode_notif_used = true; 16173 params.opmode_notif = 16174 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); 16175 } 16176 16177 err = nl80211_parse_sta_txpower_setting(info, ¶ms.txpwr, 16178 ¶ms.txpwr_set); 16179 if (err) 16180 return err; 16181 16182 if (add) 16183 return rdev_add_link_station(rdev, dev, ¶ms); 16184 16185 return rdev_mod_link_station(rdev, dev, ¶ms); 16186 } 16187 16188 static int 16189 nl80211_add_link_station(struct sk_buff *skb, struct genl_info *info) 16190 { 16191 return nl80211_add_mod_link_station(skb, info, true); 16192 } 16193 16194 static int 16195 nl80211_modify_link_station(struct sk_buff *skb, struct genl_info *info) 16196 { 16197 return nl80211_add_mod_link_station(skb, info, false); 16198 } 16199 16200 static int 16201 nl80211_remove_link_station(struct sk_buff *skb, struct genl_info *info) 16202 { 16203 struct link_station_del_parameters params = {}; 16204 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16205 struct net_device *dev = info->user_ptr[1]; 16206 16207 if (!rdev->ops->del_link_station) 16208 return -EOPNOTSUPP; 16209 16210 if (!info->attrs[NL80211_ATTR_MLD_ADDR] || 16211 !info->attrs[NL80211_ATTR_MLO_LINK_ID]) 16212 return -EINVAL; 16213 16214 params.mld_mac = nla_data(info->attrs[NL80211_ATTR_MLD_ADDR]); 16215 params.link_id = nla_get_u8(info->attrs[NL80211_ATTR_MLO_LINK_ID]); 16216 16217 return rdev_del_link_station(rdev, dev, ¶ms); 16218 } 16219 16220 static int nl80211_set_hw_timestamp(struct sk_buff *skb, 16221 struct genl_info *info) 16222 { 16223 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16224 struct net_device *dev = info->user_ptr[1]; 16225 struct cfg80211_set_hw_timestamp hwts = {}; 16226 16227 if (!rdev->wiphy.hw_timestamp_max_peers) 16228 return -EOPNOTSUPP; 16229 16230 if (!info->attrs[NL80211_ATTR_MAC] && 16231 rdev->wiphy.hw_timestamp_max_peers != CFG80211_HW_TIMESTAMP_ALL_PEERS) 16232 return -EOPNOTSUPP; 16233 16234 if (info->attrs[NL80211_ATTR_MAC]) 16235 hwts.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); 16236 16237 hwts.enable = 16238 nla_get_flag(info->attrs[NL80211_ATTR_HW_TIMESTAMP_ENABLED]); 16239 16240 return rdev_set_hw_timestamp(rdev, dev, &hwts); 16241 } 16242 16243 #define NL80211_FLAG_NEED_WIPHY 0x01 16244 #define NL80211_FLAG_NEED_NETDEV 0x02 16245 #define NL80211_FLAG_NEED_RTNL 0x04 16246 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 16247 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ 16248 NL80211_FLAG_CHECK_NETDEV_UP) 16249 #define NL80211_FLAG_NEED_WDEV 0x10 16250 /* If a netdev is associated, it must be UP, P2P must be started */ 16251 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ 16252 NL80211_FLAG_CHECK_NETDEV_UP) 16253 #define NL80211_FLAG_CLEAR_SKB 0x20 16254 #define NL80211_FLAG_NO_WIPHY_MTX 0x40 16255 #define NL80211_FLAG_MLO_VALID_LINK_ID 0x80 16256 #define NL80211_FLAG_MLO_UNSUPPORTED 0x100 16257 16258 #define INTERNAL_FLAG_SELECTORS(__sel) \ 16259 SELECTOR(__sel, NONE, 0) /* must be first */ \ 16260 SELECTOR(__sel, WIPHY, \ 16261 NL80211_FLAG_NEED_WIPHY) \ 16262 SELECTOR(__sel, WDEV, \ 16263 NL80211_FLAG_NEED_WDEV) \ 16264 SELECTOR(__sel, NETDEV, \ 16265 NL80211_FLAG_NEED_NETDEV) \ 16266 SELECTOR(__sel, NETDEV_LINK, \ 16267 NL80211_FLAG_NEED_NETDEV | \ 16268 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16269 SELECTOR(__sel, NETDEV_NO_MLO, \ 16270 NL80211_FLAG_NEED_NETDEV | \ 16271 NL80211_FLAG_MLO_UNSUPPORTED) \ 16272 SELECTOR(__sel, WIPHY_RTNL, \ 16273 NL80211_FLAG_NEED_WIPHY | \ 16274 NL80211_FLAG_NEED_RTNL) \ 16275 SELECTOR(__sel, WIPHY_RTNL_NOMTX, \ 16276 NL80211_FLAG_NEED_WIPHY | \ 16277 NL80211_FLAG_NEED_RTNL | \ 16278 NL80211_FLAG_NO_WIPHY_MTX) \ 16279 SELECTOR(__sel, WDEV_RTNL, \ 16280 NL80211_FLAG_NEED_WDEV | \ 16281 NL80211_FLAG_NEED_RTNL) \ 16282 SELECTOR(__sel, NETDEV_RTNL, \ 16283 NL80211_FLAG_NEED_NETDEV | \ 16284 NL80211_FLAG_NEED_RTNL) \ 16285 SELECTOR(__sel, NETDEV_UP, \ 16286 NL80211_FLAG_NEED_NETDEV_UP) \ 16287 SELECTOR(__sel, NETDEV_UP_LINK, \ 16288 NL80211_FLAG_NEED_NETDEV_UP | \ 16289 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16290 SELECTOR(__sel, NETDEV_UP_NO_MLO, \ 16291 NL80211_FLAG_NEED_NETDEV_UP | \ 16292 NL80211_FLAG_MLO_UNSUPPORTED) \ 16293 SELECTOR(__sel, NETDEV_UP_NO_MLO_CLEAR, \ 16294 NL80211_FLAG_NEED_NETDEV_UP | \ 16295 NL80211_FLAG_CLEAR_SKB | \ 16296 NL80211_FLAG_MLO_UNSUPPORTED) \ 16297 SELECTOR(__sel, NETDEV_UP_NOTMX, \ 16298 NL80211_FLAG_NEED_NETDEV_UP | \ 16299 NL80211_FLAG_NO_WIPHY_MTX) \ 16300 SELECTOR(__sel, NETDEV_UP_NOTMX_NOMLO, \ 16301 NL80211_FLAG_NEED_NETDEV_UP | \ 16302 NL80211_FLAG_NO_WIPHY_MTX | \ 16303 NL80211_FLAG_MLO_UNSUPPORTED) \ 16304 SELECTOR(__sel, NETDEV_UP_CLEAR, \ 16305 NL80211_FLAG_NEED_NETDEV_UP | \ 16306 NL80211_FLAG_CLEAR_SKB) \ 16307 SELECTOR(__sel, WDEV_UP, \ 16308 NL80211_FLAG_NEED_WDEV_UP) \ 16309 SELECTOR(__sel, WDEV_UP_LINK, \ 16310 NL80211_FLAG_NEED_WDEV_UP | \ 16311 NL80211_FLAG_MLO_VALID_LINK_ID) \ 16312 SELECTOR(__sel, WDEV_UP_RTNL, \ 16313 NL80211_FLAG_NEED_WDEV_UP | \ 16314 NL80211_FLAG_NEED_RTNL) \ 16315 SELECTOR(__sel, WIPHY_CLEAR, \ 16316 NL80211_FLAG_NEED_WIPHY | \ 16317 NL80211_FLAG_CLEAR_SKB) 16318 16319 enum nl80211_internal_flags_selector { 16320 #define SELECTOR(_, name, value) NL80211_IFL_SEL_##name, 16321 INTERNAL_FLAG_SELECTORS(_) 16322 #undef SELECTOR 16323 }; 16324 16325 static u32 nl80211_internal_flags[] = { 16326 #define SELECTOR(_, name, value) [NL80211_IFL_SEL_##name] = value, 16327 INTERNAL_FLAG_SELECTORS(_) 16328 #undef SELECTOR 16329 }; 16330 16331 static int nl80211_pre_doit(const struct genl_split_ops *ops, 16332 struct sk_buff *skb, 16333 struct genl_info *info) 16334 { 16335 struct cfg80211_registered_device *rdev = NULL; 16336 struct wireless_dev *wdev = NULL; 16337 struct net_device *dev = NULL; 16338 u32 internal_flags; 16339 int err; 16340 16341 if (WARN_ON(ops->internal_flags >= ARRAY_SIZE(nl80211_internal_flags))) 16342 return -EINVAL; 16343 16344 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16345 16346 rtnl_lock(); 16347 if (internal_flags & NL80211_FLAG_NEED_WIPHY) { 16348 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); 16349 if (IS_ERR(rdev)) { 16350 err = PTR_ERR(rdev); 16351 goto out_unlock; 16352 } 16353 info->user_ptr[0] = rdev; 16354 } else if (internal_flags & NL80211_FLAG_NEED_NETDEV || 16355 internal_flags & NL80211_FLAG_NEED_WDEV) { 16356 wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), 16357 info->attrs); 16358 if (IS_ERR(wdev)) { 16359 err = PTR_ERR(wdev); 16360 goto out_unlock; 16361 } 16362 16363 dev = wdev->netdev; 16364 dev_hold(dev); 16365 rdev = wiphy_to_rdev(wdev->wiphy); 16366 16367 if (internal_flags & NL80211_FLAG_NEED_NETDEV) { 16368 if (!dev) { 16369 err = -EINVAL; 16370 goto out_unlock; 16371 } 16372 16373 info->user_ptr[1] = dev; 16374 } else { 16375 info->user_ptr[1] = wdev; 16376 } 16377 16378 if (internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && 16379 !wdev_running(wdev)) { 16380 err = -ENETDOWN; 16381 goto out_unlock; 16382 } 16383 16384 info->user_ptr[0] = rdev; 16385 } 16386 16387 if (internal_flags & NL80211_FLAG_MLO_VALID_LINK_ID) { 16388 struct nlattr *link_id = info->attrs[NL80211_ATTR_MLO_LINK_ID]; 16389 16390 if (!wdev) { 16391 err = -EINVAL; 16392 goto out_unlock; 16393 } 16394 16395 /* MLO -> require valid link ID */ 16396 if (wdev->valid_links && 16397 (!link_id || 16398 !(wdev->valid_links & BIT(nla_get_u8(link_id))))) { 16399 err = -EINVAL; 16400 goto out_unlock; 16401 } 16402 16403 /* non-MLO -> no link ID attribute accepted */ 16404 if (!wdev->valid_links && link_id) { 16405 err = -EINVAL; 16406 goto out_unlock; 16407 } 16408 } 16409 16410 if (internal_flags & NL80211_FLAG_MLO_UNSUPPORTED) { 16411 if (info->attrs[NL80211_ATTR_MLO_LINK_ID] || 16412 (wdev && wdev->valid_links)) { 16413 err = -EINVAL; 16414 goto out_unlock; 16415 } 16416 } 16417 16418 if (rdev && !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16419 wiphy_lock(&rdev->wiphy); 16420 /* we keep the mutex locked until post_doit */ 16421 __release(&rdev->wiphy.mtx); 16422 } 16423 if (!(internal_flags & NL80211_FLAG_NEED_RTNL)) 16424 rtnl_unlock(); 16425 16426 return 0; 16427 out_unlock: 16428 rtnl_unlock(); 16429 dev_put(dev); 16430 return err; 16431 } 16432 16433 static void nl80211_post_doit(const struct genl_split_ops *ops, 16434 struct sk_buff *skb, 16435 struct genl_info *info) 16436 { 16437 u32 internal_flags = nl80211_internal_flags[ops->internal_flags]; 16438 16439 if (info->user_ptr[1]) { 16440 if (internal_flags & NL80211_FLAG_NEED_WDEV) { 16441 struct wireless_dev *wdev = info->user_ptr[1]; 16442 16443 dev_put(wdev->netdev); 16444 } else { 16445 dev_put(info->user_ptr[1]); 16446 } 16447 } 16448 16449 if (info->user_ptr[0] && 16450 !(internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { 16451 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16452 16453 /* we kept the mutex locked since pre_doit */ 16454 __acquire(&rdev->wiphy.mtx); 16455 wiphy_unlock(&rdev->wiphy); 16456 } 16457 16458 if (internal_flags & NL80211_FLAG_NEED_RTNL) 16459 rtnl_unlock(); 16460 16461 /* If needed, clear the netlink message payload from the SKB 16462 * as it might contain key data that shouldn't stick around on 16463 * the heap after the SKB is freed. The netlink message header 16464 * is still needed for further processing, so leave it intact. 16465 */ 16466 if (internal_flags & NL80211_FLAG_CLEAR_SKB) { 16467 struct nlmsghdr *nlh = nlmsg_hdr(skb); 16468 16469 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); 16470 } 16471 } 16472 16473 static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, 16474 struct cfg80211_sar_specs *sar_specs, 16475 struct nlattr *spec[], int index) 16476 { 16477 u32 range_index, i; 16478 16479 if (!sar_specs || !spec) 16480 return -EINVAL; 16481 16482 if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || 16483 !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) 16484 return -EINVAL; 16485 16486 range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); 16487 16488 /* check if range_index exceeds num_freq_ranges */ 16489 if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) 16490 return -EINVAL; 16491 16492 /* check if range_index duplicates */ 16493 for (i = 0; i < index; i++) { 16494 if (sar_specs->sub_specs[i].freq_range_index == range_index) 16495 return -EINVAL; 16496 } 16497 16498 sar_specs->sub_specs[index].power = 16499 nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); 16500 16501 sar_specs->sub_specs[index].freq_range_index = range_index; 16502 16503 return 0; 16504 } 16505 16506 static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) 16507 { 16508 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 16509 struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; 16510 struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; 16511 struct cfg80211_sar_specs *sar_spec; 16512 enum nl80211_sar_type type; 16513 struct nlattr *spec_list; 16514 u32 specs; 16515 int rem, err; 16516 16517 if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) 16518 return -EOPNOTSUPP; 16519 16520 if (!info->attrs[NL80211_ATTR_SAR_SPEC]) 16521 return -EINVAL; 16522 16523 nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, 16524 info->attrs[NL80211_ATTR_SAR_SPEC], 16525 NULL, NULL); 16526 16527 if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) 16528 return -EINVAL; 16529 16530 type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); 16531 if (type != rdev->wiphy.sar_capa->type) 16532 return -EINVAL; 16533 16534 specs = 0; 16535 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) 16536 specs++; 16537 16538 if (specs > rdev->wiphy.sar_capa->num_freq_ranges) 16539 return -EINVAL; 16540 16541 sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL); 16542 if (!sar_spec) 16543 return -ENOMEM; 16544 16545 sar_spec->type = type; 16546 specs = 0; 16547 nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { 16548 nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, 16549 spec_list, NULL, NULL); 16550 16551 switch (type) { 16552 case NL80211_SAR_TYPE_POWER: 16553 if (nl80211_set_sar_sub_specs(rdev, sar_spec, 16554 spec, specs)) { 16555 err = -EINVAL; 16556 goto error; 16557 } 16558 break; 16559 default: 16560 err = -EINVAL; 16561 goto error; 16562 } 16563 specs++; 16564 } 16565 16566 sar_spec->num_sub_specs = specs; 16567 16568 rdev->cur_cmd_info = info; 16569 err = rdev_set_sar_specs(rdev, sar_spec); 16570 rdev->cur_cmd_info = NULL; 16571 error: 16572 kfree(sar_spec); 16573 return err; 16574 } 16575 16576 #define SELECTOR(__sel, name, value) \ 16577 ((__sel) == (value)) ? NL80211_IFL_SEL_##name : 16578 int __missing_selector(void); 16579 #define IFLAGS(__val) INTERNAL_FLAG_SELECTORS(__val) __missing_selector() 16580 16581 static const struct genl_ops nl80211_ops[] = { 16582 { 16583 .cmd = NL80211_CMD_GET_WIPHY, 16584 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16585 .doit = nl80211_get_wiphy, 16586 .dumpit = nl80211_dump_wiphy, 16587 .done = nl80211_dump_wiphy_done, 16588 /* can be retrieved by unprivileged users */ 16589 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16590 }, 16591 }; 16592 16593 static const struct genl_small_ops nl80211_small_ops[] = { 16594 { 16595 .cmd = NL80211_CMD_SET_WIPHY, 16596 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16597 .doit = nl80211_set_wiphy, 16598 .flags = GENL_UNS_ADMIN_PERM, 16599 }, 16600 { 16601 .cmd = NL80211_CMD_GET_INTERFACE, 16602 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16603 .doit = nl80211_get_interface, 16604 .dumpit = nl80211_dump_interface, 16605 /* can be retrieved by unprivileged users */ 16606 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 16607 }, 16608 { 16609 .cmd = NL80211_CMD_SET_INTERFACE, 16610 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16611 .doit = nl80211_set_interface, 16612 .flags = GENL_UNS_ADMIN_PERM, 16613 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16614 NL80211_FLAG_NEED_RTNL), 16615 }, 16616 { 16617 .cmd = NL80211_CMD_NEW_INTERFACE, 16618 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16619 .doit = nl80211_new_interface, 16620 .flags = GENL_UNS_ADMIN_PERM, 16621 .internal_flags = 16622 IFLAGS(NL80211_FLAG_NEED_WIPHY | 16623 NL80211_FLAG_NEED_RTNL | 16624 /* we take the wiphy mutex later ourselves */ 16625 NL80211_FLAG_NO_WIPHY_MTX), 16626 }, 16627 { 16628 .cmd = NL80211_CMD_DEL_INTERFACE, 16629 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16630 .doit = nl80211_del_interface, 16631 .flags = GENL_UNS_ADMIN_PERM, 16632 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 16633 NL80211_FLAG_NEED_RTNL), 16634 }, 16635 { 16636 .cmd = NL80211_CMD_GET_KEY, 16637 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16638 .doit = nl80211_get_key, 16639 .flags = GENL_UNS_ADMIN_PERM, 16640 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16641 }, 16642 { 16643 .cmd = NL80211_CMD_SET_KEY, 16644 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16645 .doit = nl80211_set_key, 16646 .flags = GENL_UNS_ADMIN_PERM, 16647 /* cannot use NL80211_FLAG_MLO_VALID_LINK_ID, depends on key */ 16648 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16649 NL80211_FLAG_CLEAR_SKB), 16650 }, 16651 { 16652 .cmd = NL80211_CMD_NEW_KEY, 16653 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16654 .doit = nl80211_new_key, 16655 .flags = GENL_UNS_ADMIN_PERM, 16656 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16657 NL80211_FLAG_CLEAR_SKB), 16658 }, 16659 { 16660 .cmd = NL80211_CMD_DEL_KEY, 16661 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16662 .doit = nl80211_del_key, 16663 .flags = GENL_UNS_ADMIN_PERM, 16664 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16665 }, 16666 { 16667 .cmd = NL80211_CMD_SET_BEACON, 16668 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16669 .flags = GENL_UNS_ADMIN_PERM, 16670 .doit = nl80211_set_beacon, 16671 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16672 NL80211_FLAG_MLO_VALID_LINK_ID), 16673 }, 16674 { 16675 .cmd = NL80211_CMD_START_AP, 16676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16677 .flags = GENL_UNS_ADMIN_PERM, 16678 .doit = nl80211_start_ap, 16679 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16680 NL80211_FLAG_MLO_VALID_LINK_ID), 16681 }, 16682 { 16683 .cmd = NL80211_CMD_STOP_AP, 16684 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16685 .flags = GENL_UNS_ADMIN_PERM, 16686 .doit = nl80211_stop_ap, 16687 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16688 NL80211_FLAG_MLO_VALID_LINK_ID), 16689 }, 16690 { 16691 .cmd = NL80211_CMD_GET_STATION, 16692 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16693 .doit = nl80211_get_station, 16694 .dumpit = nl80211_dump_station, 16695 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 16696 }, 16697 { 16698 .cmd = NL80211_CMD_SET_STATION, 16699 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16700 .doit = nl80211_set_station, 16701 .flags = GENL_UNS_ADMIN_PERM, 16702 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16703 }, 16704 { 16705 .cmd = NL80211_CMD_NEW_STATION, 16706 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16707 .doit = nl80211_new_station, 16708 .flags = GENL_UNS_ADMIN_PERM, 16709 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16710 }, 16711 { 16712 .cmd = NL80211_CMD_DEL_STATION, 16713 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16714 .doit = nl80211_del_station, 16715 .flags = GENL_UNS_ADMIN_PERM, 16716 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16717 }, 16718 { 16719 .cmd = NL80211_CMD_GET_MPATH, 16720 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16721 .doit = nl80211_get_mpath, 16722 .dumpit = nl80211_dump_mpath, 16723 .flags = GENL_UNS_ADMIN_PERM, 16724 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16725 }, 16726 { 16727 .cmd = NL80211_CMD_GET_MPP, 16728 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16729 .doit = nl80211_get_mpp, 16730 .dumpit = nl80211_dump_mpp, 16731 .flags = GENL_UNS_ADMIN_PERM, 16732 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16733 }, 16734 { 16735 .cmd = NL80211_CMD_SET_MPATH, 16736 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16737 .doit = nl80211_set_mpath, 16738 .flags = GENL_UNS_ADMIN_PERM, 16739 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16740 }, 16741 { 16742 .cmd = NL80211_CMD_NEW_MPATH, 16743 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16744 .doit = nl80211_new_mpath, 16745 .flags = GENL_UNS_ADMIN_PERM, 16746 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16747 }, 16748 { 16749 .cmd = NL80211_CMD_DEL_MPATH, 16750 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16751 .doit = nl80211_del_mpath, 16752 .flags = GENL_UNS_ADMIN_PERM, 16753 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16754 }, 16755 { 16756 .cmd = NL80211_CMD_SET_BSS, 16757 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16758 .doit = nl80211_set_bss, 16759 .flags = GENL_UNS_ADMIN_PERM, 16760 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16761 NL80211_FLAG_MLO_VALID_LINK_ID), 16762 }, 16763 { 16764 .cmd = NL80211_CMD_GET_REG, 16765 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16766 .doit = nl80211_get_reg_do, 16767 .dumpit = nl80211_get_reg_dump, 16768 /* can be retrieved by unprivileged users */ 16769 }, 16770 #ifdef CONFIG_CFG80211_CRDA_SUPPORT 16771 { 16772 .cmd = NL80211_CMD_SET_REG, 16773 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16774 .doit = nl80211_set_reg, 16775 .flags = GENL_ADMIN_PERM, 16776 }, 16777 #endif 16778 { 16779 .cmd = NL80211_CMD_REQ_SET_REG, 16780 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16781 .doit = nl80211_req_set_reg, 16782 .flags = GENL_ADMIN_PERM, 16783 }, 16784 { 16785 .cmd = NL80211_CMD_RELOAD_REGDB, 16786 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16787 .doit = nl80211_reload_regdb, 16788 .flags = GENL_ADMIN_PERM, 16789 }, 16790 { 16791 .cmd = NL80211_CMD_GET_MESH_CONFIG, 16792 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16793 .doit = nl80211_get_mesh_config, 16794 /* can be retrieved by unprivileged users */ 16795 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16796 }, 16797 { 16798 .cmd = NL80211_CMD_SET_MESH_CONFIG, 16799 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16800 .doit = nl80211_update_mesh_config, 16801 .flags = GENL_UNS_ADMIN_PERM, 16802 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16803 }, 16804 { 16805 .cmd = NL80211_CMD_TRIGGER_SCAN, 16806 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16807 .doit = nl80211_trigger_scan, 16808 .flags = GENL_UNS_ADMIN_PERM, 16809 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16810 }, 16811 { 16812 .cmd = NL80211_CMD_ABORT_SCAN, 16813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16814 .doit = nl80211_abort_scan, 16815 .flags = GENL_UNS_ADMIN_PERM, 16816 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16817 }, 16818 { 16819 .cmd = NL80211_CMD_GET_SCAN, 16820 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16821 .dumpit = nl80211_dump_scan, 16822 }, 16823 { 16824 .cmd = NL80211_CMD_START_SCHED_SCAN, 16825 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16826 .doit = nl80211_start_sched_scan, 16827 .flags = GENL_UNS_ADMIN_PERM, 16828 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16829 }, 16830 { 16831 .cmd = NL80211_CMD_STOP_SCHED_SCAN, 16832 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16833 .doit = nl80211_stop_sched_scan, 16834 .flags = GENL_UNS_ADMIN_PERM, 16835 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16836 }, 16837 { 16838 .cmd = NL80211_CMD_AUTHENTICATE, 16839 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16840 .doit = nl80211_authenticate, 16841 .flags = GENL_UNS_ADMIN_PERM, 16842 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16843 NL80211_FLAG_CLEAR_SKB), 16844 }, 16845 { 16846 .cmd = NL80211_CMD_ASSOCIATE, 16847 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16848 .doit = nl80211_associate, 16849 .flags = GENL_UNS_ADMIN_PERM, 16850 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16851 NL80211_FLAG_CLEAR_SKB), 16852 }, 16853 { 16854 .cmd = NL80211_CMD_DEAUTHENTICATE, 16855 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16856 .doit = nl80211_deauthenticate, 16857 .flags = GENL_UNS_ADMIN_PERM, 16858 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16859 }, 16860 { 16861 .cmd = NL80211_CMD_DISASSOCIATE, 16862 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16863 .doit = nl80211_disassociate, 16864 .flags = GENL_UNS_ADMIN_PERM, 16865 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16866 }, 16867 { 16868 .cmd = NL80211_CMD_JOIN_IBSS, 16869 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16870 .doit = nl80211_join_ibss, 16871 .flags = GENL_UNS_ADMIN_PERM, 16872 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16873 }, 16874 { 16875 .cmd = NL80211_CMD_LEAVE_IBSS, 16876 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16877 .doit = nl80211_leave_ibss, 16878 .flags = GENL_UNS_ADMIN_PERM, 16879 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16880 }, 16881 #ifdef CONFIG_NL80211_TESTMODE 16882 { 16883 .cmd = NL80211_CMD_TESTMODE, 16884 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16885 .doit = nl80211_testmode_do, 16886 .dumpit = nl80211_testmode_dump, 16887 .flags = GENL_UNS_ADMIN_PERM, 16888 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 16889 }, 16890 #endif 16891 { 16892 .cmd = NL80211_CMD_CONNECT, 16893 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16894 .doit = nl80211_connect, 16895 .flags = GENL_UNS_ADMIN_PERM, 16896 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16897 NL80211_FLAG_CLEAR_SKB), 16898 }, 16899 { 16900 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, 16901 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16902 .doit = nl80211_update_connect_params, 16903 .flags = GENL_ADMIN_PERM, 16904 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16905 NL80211_FLAG_CLEAR_SKB), 16906 }, 16907 { 16908 .cmd = NL80211_CMD_DISCONNECT, 16909 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16910 .doit = nl80211_disconnect, 16911 .flags = GENL_UNS_ADMIN_PERM, 16912 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16913 }, 16914 { 16915 .cmd = NL80211_CMD_SET_WIPHY_NETNS, 16916 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16917 .doit = nl80211_wiphy_netns, 16918 .flags = GENL_UNS_ADMIN_PERM, 16919 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 16920 NL80211_FLAG_NEED_RTNL | 16921 NL80211_FLAG_NO_WIPHY_MTX), 16922 }, 16923 { 16924 .cmd = NL80211_CMD_GET_SURVEY, 16925 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16926 .dumpit = nl80211_dump_survey, 16927 }, 16928 { 16929 .cmd = NL80211_CMD_SET_PMKSA, 16930 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16931 .doit = nl80211_setdel_pmksa, 16932 .flags = GENL_UNS_ADMIN_PERM, 16933 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 16934 NL80211_FLAG_CLEAR_SKB), 16935 }, 16936 { 16937 .cmd = NL80211_CMD_DEL_PMKSA, 16938 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16939 .doit = nl80211_setdel_pmksa, 16940 .flags = GENL_UNS_ADMIN_PERM, 16941 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16942 }, 16943 { 16944 .cmd = NL80211_CMD_FLUSH_PMKSA, 16945 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16946 .doit = nl80211_flush_pmksa, 16947 .flags = GENL_UNS_ADMIN_PERM, 16948 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 16949 }, 16950 { 16951 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, 16952 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16953 .doit = nl80211_remain_on_channel, 16954 .flags = GENL_UNS_ADMIN_PERM, 16955 /* FIXME: requiring a link ID here is probably not good */ 16956 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 16957 NL80211_FLAG_MLO_VALID_LINK_ID), 16958 }, 16959 { 16960 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 16961 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16962 .doit = nl80211_cancel_remain_on_channel, 16963 .flags = GENL_UNS_ADMIN_PERM, 16964 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16965 }, 16966 { 16967 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, 16968 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16969 .doit = nl80211_set_tx_bitrate_mask, 16970 .flags = GENL_UNS_ADMIN_PERM, 16971 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 16972 NL80211_FLAG_MLO_VALID_LINK_ID), 16973 }, 16974 { 16975 .cmd = NL80211_CMD_REGISTER_FRAME, 16976 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16977 .doit = nl80211_register_mgmt, 16978 .flags = GENL_UNS_ADMIN_PERM, 16979 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV), 16980 }, 16981 { 16982 .cmd = NL80211_CMD_FRAME, 16983 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16984 .doit = nl80211_tx_mgmt, 16985 .flags = GENL_UNS_ADMIN_PERM, 16986 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16987 }, 16988 { 16989 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, 16990 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16991 .doit = nl80211_tx_mgmt_cancel_wait, 16992 .flags = GENL_UNS_ADMIN_PERM, 16993 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 16994 }, 16995 { 16996 .cmd = NL80211_CMD_SET_POWER_SAVE, 16997 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 16998 .doit = nl80211_set_power_save, 16999 .flags = GENL_UNS_ADMIN_PERM, 17000 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17001 }, 17002 { 17003 .cmd = NL80211_CMD_GET_POWER_SAVE, 17004 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17005 .doit = nl80211_get_power_save, 17006 /* can be retrieved by unprivileged users */ 17007 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17008 }, 17009 { 17010 .cmd = NL80211_CMD_SET_CQM, 17011 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17012 .doit = nl80211_set_cqm, 17013 .flags = GENL_UNS_ADMIN_PERM, 17014 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17015 }, 17016 { 17017 .cmd = NL80211_CMD_SET_CHANNEL, 17018 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17019 .doit = nl80211_set_channel, 17020 .flags = GENL_UNS_ADMIN_PERM, 17021 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17022 NL80211_FLAG_MLO_VALID_LINK_ID), 17023 }, 17024 { 17025 .cmd = NL80211_CMD_JOIN_MESH, 17026 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17027 .doit = nl80211_join_mesh, 17028 .flags = GENL_UNS_ADMIN_PERM, 17029 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17030 }, 17031 { 17032 .cmd = NL80211_CMD_LEAVE_MESH, 17033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17034 .doit = nl80211_leave_mesh, 17035 .flags = GENL_UNS_ADMIN_PERM, 17036 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17037 }, 17038 { 17039 .cmd = NL80211_CMD_JOIN_OCB, 17040 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17041 .doit = nl80211_join_ocb, 17042 .flags = GENL_UNS_ADMIN_PERM, 17043 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17044 }, 17045 { 17046 .cmd = NL80211_CMD_LEAVE_OCB, 17047 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17048 .doit = nl80211_leave_ocb, 17049 .flags = GENL_UNS_ADMIN_PERM, 17050 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17051 }, 17052 #ifdef CONFIG_PM 17053 { 17054 .cmd = NL80211_CMD_GET_WOWLAN, 17055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17056 .doit = nl80211_get_wowlan, 17057 /* can be retrieved by unprivileged users */ 17058 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17059 }, 17060 { 17061 .cmd = NL80211_CMD_SET_WOWLAN, 17062 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17063 .doit = nl80211_set_wowlan, 17064 .flags = GENL_UNS_ADMIN_PERM, 17065 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17066 }, 17067 #endif 17068 { 17069 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, 17070 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17071 .doit = nl80211_set_rekey_data, 17072 .flags = GENL_UNS_ADMIN_PERM, 17073 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17074 NL80211_FLAG_CLEAR_SKB), 17075 }, 17076 { 17077 .cmd = NL80211_CMD_TDLS_MGMT, 17078 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17079 .doit = nl80211_tdls_mgmt, 17080 .flags = GENL_UNS_ADMIN_PERM, 17081 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17082 NL80211_FLAG_MLO_VALID_LINK_ID), 17083 }, 17084 { 17085 .cmd = NL80211_CMD_TDLS_OPER, 17086 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17087 .doit = nl80211_tdls_oper, 17088 .flags = GENL_UNS_ADMIN_PERM, 17089 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17090 }, 17091 { 17092 .cmd = NL80211_CMD_UNEXPECTED_FRAME, 17093 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17094 .doit = nl80211_register_unexpected_frame, 17095 .flags = GENL_UNS_ADMIN_PERM, 17096 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17097 }, 17098 { 17099 .cmd = NL80211_CMD_PROBE_CLIENT, 17100 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17101 .doit = nl80211_probe_client, 17102 .flags = GENL_UNS_ADMIN_PERM, 17103 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17104 }, 17105 { 17106 .cmd = NL80211_CMD_REGISTER_BEACONS, 17107 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17108 .doit = nl80211_register_beacons, 17109 .flags = GENL_UNS_ADMIN_PERM, 17110 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17111 }, 17112 { 17113 .cmd = NL80211_CMD_SET_NOACK_MAP, 17114 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17115 .doit = nl80211_set_noack_map, 17116 .flags = GENL_UNS_ADMIN_PERM, 17117 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17118 }, 17119 { 17120 .cmd = NL80211_CMD_START_P2P_DEVICE, 17121 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17122 .doit = nl80211_start_p2p_device, 17123 .flags = GENL_UNS_ADMIN_PERM, 17124 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 17125 NL80211_FLAG_NEED_RTNL), 17126 }, 17127 { 17128 .cmd = NL80211_CMD_STOP_P2P_DEVICE, 17129 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17130 .doit = nl80211_stop_p2p_device, 17131 .flags = GENL_UNS_ADMIN_PERM, 17132 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 17133 NL80211_FLAG_NEED_RTNL), 17134 }, 17135 { 17136 .cmd = NL80211_CMD_START_NAN, 17137 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17138 .doit = nl80211_start_nan, 17139 .flags = GENL_ADMIN_PERM, 17140 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV | 17141 NL80211_FLAG_NEED_RTNL), 17142 }, 17143 { 17144 .cmd = NL80211_CMD_STOP_NAN, 17145 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17146 .doit = nl80211_stop_nan, 17147 .flags = GENL_ADMIN_PERM, 17148 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP | 17149 NL80211_FLAG_NEED_RTNL), 17150 }, 17151 { 17152 .cmd = NL80211_CMD_ADD_NAN_FUNCTION, 17153 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17154 .doit = nl80211_nan_add_func, 17155 .flags = GENL_ADMIN_PERM, 17156 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17157 }, 17158 { 17159 .cmd = NL80211_CMD_DEL_NAN_FUNCTION, 17160 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17161 .doit = nl80211_nan_del_func, 17162 .flags = GENL_ADMIN_PERM, 17163 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17164 }, 17165 { 17166 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, 17167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17168 .doit = nl80211_nan_change_config, 17169 .flags = GENL_ADMIN_PERM, 17170 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17171 }, 17172 { 17173 .cmd = NL80211_CMD_SET_MCAST_RATE, 17174 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17175 .doit = nl80211_set_mcast_rate, 17176 .flags = GENL_UNS_ADMIN_PERM, 17177 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17178 }, 17179 { 17180 .cmd = NL80211_CMD_SET_MAC_ACL, 17181 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17182 .doit = nl80211_set_mac_acl, 17183 .flags = GENL_UNS_ADMIN_PERM, 17184 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17185 NL80211_FLAG_MLO_UNSUPPORTED), 17186 }, 17187 { 17188 .cmd = NL80211_CMD_RADAR_DETECT, 17189 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17190 .doit = nl80211_start_radar_detection, 17191 .flags = GENL_UNS_ADMIN_PERM, 17192 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17193 NL80211_FLAG_NO_WIPHY_MTX | 17194 NL80211_FLAG_MLO_UNSUPPORTED), 17195 }, 17196 { 17197 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, 17198 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17199 .doit = nl80211_get_protocol_features, 17200 }, 17201 { 17202 .cmd = NL80211_CMD_UPDATE_FT_IES, 17203 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17204 .doit = nl80211_update_ft_ies, 17205 .flags = GENL_UNS_ADMIN_PERM, 17206 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17207 }, 17208 { 17209 .cmd = NL80211_CMD_CRIT_PROTOCOL_START, 17210 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17211 .doit = nl80211_crit_protocol_start, 17212 .flags = GENL_UNS_ADMIN_PERM, 17213 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17214 }, 17215 { 17216 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, 17217 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17218 .doit = nl80211_crit_protocol_stop, 17219 .flags = GENL_UNS_ADMIN_PERM, 17220 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17221 }, 17222 { 17223 .cmd = NL80211_CMD_GET_COALESCE, 17224 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17225 .doit = nl80211_get_coalesce, 17226 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17227 }, 17228 { 17229 .cmd = NL80211_CMD_SET_COALESCE, 17230 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17231 .doit = nl80211_set_coalesce, 17232 .flags = GENL_UNS_ADMIN_PERM, 17233 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY), 17234 }, 17235 { 17236 .cmd = NL80211_CMD_CHANNEL_SWITCH, 17237 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17238 .doit = nl80211_channel_switch, 17239 .flags = GENL_UNS_ADMIN_PERM, 17240 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17241 NL80211_FLAG_MLO_VALID_LINK_ID), 17242 }, 17243 { 17244 .cmd = NL80211_CMD_VENDOR, 17245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17246 .doit = nl80211_vendor_cmd, 17247 .dumpit = nl80211_vendor_cmd_dump, 17248 .flags = GENL_UNS_ADMIN_PERM, 17249 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17250 NL80211_FLAG_CLEAR_SKB), 17251 }, 17252 { 17253 .cmd = NL80211_CMD_SET_QOS_MAP, 17254 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17255 .doit = nl80211_set_qos_map, 17256 .flags = GENL_UNS_ADMIN_PERM, 17257 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17258 }, 17259 { 17260 .cmd = NL80211_CMD_ADD_TX_TS, 17261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17262 .doit = nl80211_add_tx_ts, 17263 .flags = GENL_UNS_ADMIN_PERM, 17264 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17265 NL80211_FLAG_MLO_UNSUPPORTED), 17266 }, 17267 { 17268 .cmd = NL80211_CMD_DEL_TX_TS, 17269 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17270 .doit = nl80211_del_tx_ts, 17271 .flags = GENL_UNS_ADMIN_PERM, 17272 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17273 }, 17274 { 17275 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, 17276 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17277 .doit = nl80211_tdls_channel_switch, 17278 .flags = GENL_UNS_ADMIN_PERM, 17279 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17280 }, 17281 { 17282 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, 17283 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17284 .doit = nl80211_tdls_cancel_channel_switch, 17285 .flags = GENL_UNS_ADMIN_PERM, 17286 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17287 }, 17288 { 17289 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, 17290 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17291 .doit = nl80211_set_multicast_to_unicast, 17292 .flags = GENL_UNS_ADMIN_PERM, 17293 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV), 17294 }, 17295 { 17296 .cmd = NL80211_CMD_SET_PMK, 17297 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17298 .doit = nl80211_set_pmk, 17299 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17300 NL80211_FLAG_CLEAR_SKB), 17301 }, 17302 { 17303 .cmd = NL80211_CMD_DEL_PMK, 17304 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17305 .doit = nl80211_del_pmk, 17306 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17307 }, 17308 { 17309 .cmd = NL80211_CMD_EXTERNAL_AUTH, 17310 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17311 .doit = nl80211_external_auth, 17312 .flags = GENL_ADMIN_PERM, 17313 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17314 }, 17315 { 17316 .cmd = NL80211_CMD_CONTROL_PORT_FRAME, 17317 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17318 .doit = nl80211_tx_control_port, 17319 .flags = GENL_UNS_ADMIN_PERM, 17320 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17321 }, 17322 { 17323 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, 17324 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17325 .doit = nl80211_get_ftm_responder_stats, 17326 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17327 NL80211_FLAG_MLO_VALID_LINK_ID), 17328 }, 17329 { 17330 .cmd = NL80211_CMD_PEER_MEASUREMENT_START, 17331 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17332 .doit = nl80211_pmsr_start, 17333 .flags = GENL_UNS_ADMIN_PERM, 17334 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WDEV_UP), 17335 }, 17336 { 17337 .cmd = NL80211_CMD_NOTIFY_RADAR, 17338 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17339 .doit = nl80211_notify_radar_detection, 17340 .flags = GENL_UNS_ADMIN_PERM, 17341 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17342 }, 17343 { 17344 .cmd = NL80211_CMD_UPDATE_OWE_INFO, 17345 .doit = nl80211_update_owe_info, 17346 .flags = GENL_ADMIN_PERM, 17347 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17348 }, 17349 { 17350 .cmd = NL80211_CMD_PROBE_MESH_LINK, 17351 .doit = nl80211_probe_mesh_link, 17352 .flags = GENL_UNS_ADMIN_PERM, 17353 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17354 }, 17355 { 17356 .cmd = NL80211_CMD_SET_TID_CONFIG, 17357 .doit = nl80211_set_tid_config, 17358 .flags = GENL_UNS_ADMIN_PERM, 17359 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV | 17360 NL80211_FLAG_MLO_VALID_LINK_ID), 17361 }, 17362 { 17363 .cmd = NL80211_CMD_SET_SAR_SPECS, 17364 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17365 .doit = nl80211_set_sar_specs, 17366 .flags = GENL_UNS_ADMIN_PERM, 17367 .internal_flags = IFLAGS(NL80211_FLAG_NEED_WIPHY | 17368 NL80211_FLAG_NEED_RTNL), 17369 }, 17370 { 17371 .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, 17372 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17373 .doit = nl80211_color_change, 17374 .flags = GENL_UNS_ADMIN_PERM, 17375 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17376 }, 17377 { 17378 .cmd = NL80211_CMD_SET_FILS_AAD, 17379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, 17380 .doit = nl80211_set_fils_aad, 17381 .flags = GENL_UNS_ADMIN_PERM, 17382 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17383 }, 17384 { 17385 .cmd = NL80211_CMD_ADD_LINK, 17386 .doit = nl80211_add_link, 17387 .flags = GENL_UNS_ADMIN_PERM, 17388 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17389 }, 17390 { 17391 .cmd = NL80211_CMD_REMOVE_LINK, 17392 .doit = nl80211_remove_link, 17393 .flags = GENL_UNS_ADMIN_PERM, 17394 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17395 NL80211_FLAG_MLO_VALID_LINK_ID), 17396 }, 17397 { 17398 .cmd = NL80211_CMD_ADD_LINK_STA, 17399 .doit = nl80211_add_link_station, 17400 .flags = GENL_UNS_ADMIN_PERM, 17401 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17402 NL80211_FLAG_MLO_VALID_LINK_ID), 17403 }, 17404 { 17405 .cmd = NL80211_CMD_MODIFY_LINK_STA, 17406 .doit = nl80211_modify_link_station, 17407 .flags = GENL_UNS_ADMIN_PERM, 17408 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17409 NL80211_FLAG_MLO_VALID_LINK_ID), 17410 }, 17411 { 17412 .cmd = NL80211_CMD_REMOVE_LINK_STA, 17413 .doit = nl80211_remove_link_station, 17414 .flags = GENL_UNS_ADMIN_PERM, 17415 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP | 17416 NL80211_FLAG_MLO_VALID_LINK_ID), 17417 }, 17418 { 17419 .cmd = NL80211_CMD_SET_HW_TIMESTAMP, 17420 .doit = nl80211_set_hw_timestamp, 17421 .flags = GENL_UNS_ADMIN_PERM, 17422 .internal_flags = IFLAGS(NL80211_FLAG_NEED_NETDEV_UP), 17423 }, 17424 }; 17425 17426 static struct genl_family nl80211_fam __ro_after_init = { 17427 .name = NL80211_GENL_NAME, /* have users key off the name instead */ 17428 .hdrsize = 0, /* no private header */ 17429 .version = 1, /* no particular meaning now */ 17430 .maxattr = NL80211_ATTR_MAX, 17431 .policy = nl80211_policy, 17432 .netnsok = true, 17433 .pre_doit = nl80211_pre_doit, 17434 .post_doit = nl80211_post_doit, 17435 .module = THIS_MODULE, 17436 .ops = nl80211_ops, 17437 .n_ops = ARRAY_SIZE(nl80211_ops), 17438 .small_ops = nl80211_small_ops, 17439 .n_small_ops = ARRAY_SIZE(nl80211_small_ops), 17440 .resv_start_op = NL80211_CMD_REMOVE_LINK_STA + 1, 17441 .mcgrps = nl80211_mcgrps, 17442 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), 17443 .parallel_ops = true, 17444 }; 17445 17446 /* notification functions */ 17447 17448 void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, 17449 enum nl80211_commands cmd) 17450 { 17451 struct sk_buff *msg; 17452 struct nl80211_dump_wiphy_state state = {}; 17453 17454 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && 17455 cmd != NL80211_CMD_DEL_WIPHY); 17456 17457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17458 if (!msg) 17459 return; 17460 17461 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { 17462 nlmsg_free(msg); 17463 return; 17464 } 17465 17466 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17467 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17468 } 17469 17470 void nl80211_notify_iface(struct cfg80211_registered_device *rdev, 17471 struct wireless_dev *wdev, 17472 enum nl80211_commands cmd) 17473 { 17474 struct sk_buff *msg; 17475 17476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17477 if (!msg) 17478 return; 17479 17480 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { 17481 nlmsg_free(msg); 17482 return; 17483 } 17484 17485 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17486 NL80211_MCGRP_CONFIG, GFP_KERNEL); 17487 } 17488 17489 static int nl80211_add_scan_req(struct sk_buff *msg, 17490 struct cfg80211_registered_device *rdev) 17491 { 17492 struct cfg80211_scan_request *req = rdev->scan_req; 17493 struct nlattr *nest; 17494 int i; 17495 struct cfg80211_scan_info *info; 17496 17497 if (WARN_ON(!req)) 17498 return 0; 17499 17500 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); 17501 if (!nest) 17502 goto nla_put_failure; 17503 for (i = 0; i < req->n_ssids; i++) { 17504 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) 17505 goto nla_put_failure; 17506 } 17507 nla_nest_end(msg, nest); 17508 17509 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { 17510 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); 17511 if (!nest) 17512 goto nla_put_failure; 17513 for (i = 0; i < req->n_channels; i++) { 17514 if (nla_put_u32(msg, i, 17515 ieee80211_channel_to_khz(req->channels[i]))) 17516 goto nla_put_failure; 17517 } 17518 nla_nest_end(msg, nest); 17519 } else { 17520 nest = nla_nest_start_noflag(msg, 17521 NL80211_ATTR_SCAN_FREQUENCIES); 17522 if (!nest) 17523 goto nla_put_failure; 17524 for (i = 0; i < req->n_channels; i++) { 17525 if (nla_put_u32(msg, i, req->channels[i]->center_freq)) 17526 goto nla_put_failure; 17527 } 17528 nla_nest_end(msg, nest); 17529 } 17530 17531 if (req->ie && 17532 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) 17533 goto nla_put_failure; 17534 17535 if (req->flags && 17536 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) 17537 goto nla_put_failure; 17538 17539 info = rdev->int_scan_req ? &rdev->int_scan_req->info : 17540 &rdev->scan_req->info; 17541 if (info->scan_start_tsf && 17542 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, 17543 info->scan_start_tsf, NL80211_BSS_PAD) || 17544 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, 17545 info->tsf_bssid))) 17546 goto nla_put_failure; 17547 17548 return 0; 17549 nla_put_failure: 17550 return -ENOBUFS; 17551 } 17552 17553 static int nl80211_prep_scan_msg(struct sk_buff *msg, 17554 struct cfg80211_registered_device *rdev, 17555 struct wireless_dev *wdev, 17556 u32 portid, u32 seq, int flags, 17557 u32 cmd) 17558 { 17559 void *hdr; 17560 17561 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); 17562 if (!hdr) 17563 return -1; 17564 17565 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17566 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 17567 wdev->netdev->ifindex)) || 17568 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 17569 NL80211_ATTR_PAD)) 17570 goto nla_put_failure; 17571 17572 /* ignore errors and send incomplete event anyway */ 17573 nl80211_add_scan_req(msg, rdev); 17574 17575 genlmsg_end(msg, hdr); 17576 return 0; 17577 17578 nla_put_failure: 17579 genlmsg_cancel(msg, hdr); 17580 return -EMSGSIZE; 17581 } 17582 17583 static int 17584 nl80211_prep_sched_scan_msg(struct sk_buff *msg, 17585 struct cfg80211_sched_scan_request *req, u32 cmd) 17586 { 17587 void *hdr; 17588 17589 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17590 if (!hdr) 17591 return -1; 17592 17593 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, 17594 wiphy_to_rdev(req->wiphy)->wiphy_idx) || 17595 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || 17596 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, 17597 NL80211_ATTR_PAD)) 17598 goto nla_put_failure; 17599 17600 genlmsg_end(msg, hdr); 17601 return 0; 17602 17603 nla_put_failure: 17604 genlmsg_cancel(msg, hdr); 17605 return -EMSGSIZE; 17606 } 17607 17608 void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 17609 struct wireless_dev *wdev) 17610 { 17611 struct sk_buff *msg; 17612 17613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17614 if (!msg) 17615 return; 17616 17617 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17618 NL80211_CMD_TRIGGER_SCAN) < 0) { 17619 nlmsg_free(msg); 17620 return; 17621 } 17622 17623 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17624 NL80211_MCGRP_SCAN, GFP_KERNEL); 17625 } 17626 17627 struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 17628 struct wireless_dev *wdev, bool aborted) 17629 { 17630 struct sk_buff *msg; 17631 17632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17633 if (!msg) 17634 return NULL; 17635 17636 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, 17637 aborted ? NL80211_CMD_SCAN_ABORTED : 17638 NL80211_CMD_NEW_SCAN_RESULTS) < 0) { 17639 nlmsg_free(msg); 17640 return NULL; 17641 } 17642 17643 return msg; 17644 } 17645 17646 /* send message created by nl80211_build_scan_msg() */ 17647 void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, 17648 struct sk_buff *msg) 17649 { 17650 if (!msg) 17651 return; 17652 17653 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17654 NL80211_MCGRP_SCAN, GFP_KERNEL); 17655 } 17656 17657 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) 17658 { 17659 struct sk_buff *msg; 17660 17661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17662 if (!msg) 17663 return; 17664 17665 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { 17666 nlmsg_free(msg); 17667 return; 17668 } 17669 17670 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, 17671 NL80211_MCGRP_SCAN, GFP_KERNEL); 17672 } 17673 17674 static bool nl80211_reg_change_event_fill(struct sk_buff *msg, 17675 struct regulatory_request *request) 17676 { 17677 /* Userspace can always count this one always being set */ 17678 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) 17679 goto nla_put_failure; 17680 17681 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { 17682 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17683 NL80211_REGDOM_TYPE_WORLD)) 17684 goto nla_put_failure; 17685 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { 17686 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17687 NL80211_REGDOM_TYPE_CUSTOM_WORLD)) 17688 goto nla_put_failure; 17689 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || 17690 request->intersect) { 17691 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17692 NL80211_REGDOM_TYPE_INTERSECTION)) 17693 goto nla_put_failure; 17694 } else { 17695 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, 17696 NL80211_REGDOM_TYPE_COUNTRY) || 17697 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, 17698 request->alpha2)) 17699 goto nla_put_failure; 17700 } 17701 17702 if (request->wiphy_idx != WIPHY_IDX_INVALID) { 17703 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); 17704 17705 if (wiphy && 17706 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) 17707 goto nla_put_failure; 17708 17709 if (wiphy && 17710 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && 17711 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) 17712 goto nla_put_failure; 17713 } 17714 17715 return true; 17716 17717 nla_put_failure: 17718 return false; 17719 } 17720 17721 /* 17722 * This can happen on global regulatory changes or device specific settings 17723 * based on custom regulatory domains. 17724 */ 17725 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, 17726 struct regulatory_request *request) 17727 { 17728 struct sk_buff *msg; 17729 void *hdr; 17730 17731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 17732 if (!msg) 17733 return; 17734 17735 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); 17736 if (!hdr) 17737 goto nla_put_failure; 17738 17739 if (!nl80211_reg_change_event_fill(msg, request)) 17740 goto nla_put_failure; 17741 17742 genlmsg_end(msg, hdr); 17743 17744 rcu_read_lock(); 17745 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 17746 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 17747 rcu_read_unlock(); 17748 17749 return; 17750 17751 nla_put_failure: 17752 nlmsg_free(msg); 17753 } 17754 17755 static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, 17756 struct net_device *netdev, 17757 const u8 *buf, size_t len, 17758 enum nl80211_commands cmd, gfp_t gfp, 17759 int uapsd_queues, const u8 *req_ies, 17760 size_t req_ies_len, bool reconnect) 17761 { 17762 struct sk_buff *msg; 17763 void *hdr; 17764 17765 msg = nlmsg_new(100 + len + req_ies_len, gfp); 17766 if (!msg) 17767 return; 17768 17769 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17770 if (!hdr) { 17771 nlmsg_free(msg); 17772 return; 17773 } 17774 17775 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17776 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17777 nla_put(msg, NL80211_ATTR_FRAME, len, buf) || 17778 (req_ies && 17779 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) 17780 goto nla_put_failure; 17781 17782 if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) 17783 goto nla_put_failure; 17784 17785 if (uapsd_queues >= 0) { 17786 struct nlattr *nla_wmm = 17787 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); 17788 if (!nla_wmm) 17789 goto nla_put_failure; 17790 17791 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, 17792 uapsd_queues)) 17793 goto nla_put_failure; 17794 17795 nla_nest_end(msg, nla_wmm); 17796 } 17797 17798 genlmsg_end(msg, hdr); 17799 17800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17801 NL80211_MCGRP_MLME, gfp); 17802 return; 17803 17804 nla_put_failure: 17805 nlmsg_free(msg); 17806 } 17807 17808 void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, 17809 struct net_device *netdev, const u8 *buf, 17810 size_t len, gfp_t gfp) 17811 { 17812 nl80211_send_mlme_event(rdev, netdev, buf, len, 17813 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, 17814 false); 17815 } 17816 17817 void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 17818 struct net_device *netdev, 17819 struct cfg80211_rx_assoc_resp_data *data) 17820 { 17821 nl80211_send_mlme_event(rdev, netdev, data->buf, data->len, 17822 NL80211_CMD_ASSOCIATE, GFP_KERNEL, 17823 data->uapsd_queues, 17824 data->req_ies, data->req_ies_len, false); 17825 } 17826 17827 void nl80211_send_deauth(struct cfg80211_registered_device *rdev, 17828 struct net_device *netdev, const u8 *buf, 17829 size_t len, bool reconnect, gfp_t gfp) 17830 { 17831 nl80211_send_mlme_event(rdev, netdev, buf, len, 17832 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, 17833 reconnect); 17834 } 17835 17836 void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, 17837 struct net_device *netdev, const u8 *buf, 17838 size_t len, bool reconnect, gfp_t gfp) 17839 { 17840 nl80211_send_mlme_event(rdev, netdev, buf, len, 17841 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, 17842 reconnect); 17843 } 17844 17845 void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, 17846 size_t len) 17847 { 17848 struct wireless_dev *wdev = dev->ieee80211_ptr; 17849 struct wiphy *wiphy = wdev->wiphy; 17850 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 17851 const struct ieee80211_mgmt *mgmt = (void *)buf; 17852 u32 cmd; 17853 17854 if (WARN_ON(len < 2)) 17855 return; 17856 17857 if (ieee80211_is_deauth(mgmt->frame_control)) { 17858 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; 17859 } else if (ieee80211_is_disassoc(mgmt->frame_control)) { 17860 cmd = NL80211_CMD_UNPROT_DISASSOCIATE; 17861 } else if (ieee80211_is_beacon(mgmt->frame_control)) { 17862 if (wdev->unprot_beacon_reported && 17863 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) 17864 return; 17865 cmd = NL80211_CMD_UNPROT_BEACON; 17866 wdev->unprot_beacon_reported = jiffies; 17867 } else { 17868 return; 17869 } 17870 17871 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); 17872 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, 17873 NULL, 0, false); 17874 } 17875 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); 17876 17877 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, 17878 struct net_device *netdev, int cmd, 17879 const u8 *addr, gfp_t gfp) 17880 { 17881 struct sk_buff *msg; 17882 void *hdr; 17883 17884 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 17885 if (!msg) 17886 return; 17887 17888 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 17889 if (!hdr) { 17890 nlmsg_free(msg); 17891 return; 17892 } 17893 17894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17895 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17896 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 17897 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 17898 goto nla_put_failure; 17899 17900 genlmsg_end(msg, hdr); 17901 17902 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 17903 NL80211_MCGRP_MLME, gfp); 17904 return; 17905 17906 nla_put_failure: 17907 nlmsg_free(msg); 17908 } 17909 17910 void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, 17911 struct net_device *netdev, const u8 *addr, 17912 gfp_t gfp) 17913 { 17914 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, 17915 addr, gfp); 17916 } 17917 17918 void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, 17919 struct net_device *netdev, const u8 *addr, 17920 gfp_t gfp) 17921 { 17922 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, 17923 addr, gfp); 17924 } 17925 17926 void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, 17927 struct net_device *netdev, 17928 struct cfg80211_connect_resp_params *cr, 17929 gfp_t gfp) 17930 { 17931 struct sk_buff *msg; 17932 void *hdr; 17933 unsigned int link; 17934 size_t link_info_size = 0; 17935 const u8 *connected_addr = cr->valid_links ? 17936 cr->ap_mld_addr : cr->links[0].bssid; 17937 17938 if (cr->valid_links) { 17939 for_each_valid_link(cr, link) { 17940 /* Nested attribute header */ 17941 link_info_size += NLA_HDRLEN; 17942 /* Link ID */ 17943 link_info_size += nla_total_size(sizeof(u8)); 17944 link_info_size += cr->links[link].addr ? 17945 nla_total_size(ETH_ALEN) : 0; 17946 link_info_size += (cr->links[link].bssid || 17947 cr->links[link].bss) ? 17948 nla_total_size(ETH_ALEN) : 0; 17949 link_info_size += nla_total_size(sizeof(u16)); 17950 } 17951 } 17952 17953 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + 17954 cr->fils.kek_len + cr->fils.pmk_len + 17955 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0) + link_info_size, 17956 gfp); 17957 if (!msg) 17958 return; 17959 17960 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); 17961 if (!hdr) { 17962 nlmsg_free(msg); 17963 return; 17964 } 17965 17966 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 17967 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 17968 (connected_addr && 17969 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr)) || 17970 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 17971 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : 17972 cr->status) || 17973 (cr->status < 0 && 17974 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || 17975 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, 17976 cr->timeout_reason))) || 17977 (cr->req_ie && 17978 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || 17979 (cr->resp_ie && 17980 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, 17981 cr->resp_ie)) || 17982 (cr->fils.update_erp_next_seq_num && 17983 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 17984 cr->fils.erp_next_seq_num)) || 17985 (cr->status == WLAN_STATUS_SUCCESS && 17986 ((cr->fils.kek && 17987 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, 17988 cr->fils.kek)) || 17989 (cr->fils.pmk && 17990 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || 17991 (cr->fils.pmkid && 17992 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) 17993 goto nla_put_failure; 17994 17995 if (cr->valid_links) { 17996 int i = 1; 17997 struct nlattr *nested; 17998 17999 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18000 if (!nested) 18001 goto nla_put_failure; 18002 18003 for_each_valid_link(cr, link) { 18004 struct nlattr *nested_mlo_links; 18005 const u8 *bssid = cr->links[link].bss ? 18006 cr->links[link].bss->bssid : 18007 cr->links[link].bssid; 18008 18009 nested_mlo_links = nla_nest_start(msg, i); 18010 if (!nested_mlo_links) 18011 goto nla_put_failure; 18012 18013 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 18014 (bssid && 18015 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 18016 (cr->links[link].addr && 18017 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 18018 cr->links[link].addr)) || 18019 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, 18020 cr->links[link].status)) 18021 goto nla_put_failure; 18022 18023 nla_nest_end(msg, nested_mlo_links); 18024 i++; 18025 } 18026 nla_nest_end(msg, nested); 18027 } 18028 18029 genlmsg_end(msg, hdr); 18030 18031 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18032 NL80211_MCGRP_MLME, gfp); 18033 return; 18034 18035 nla_put_failure: 18036 nlmsg_free(msg); 18037 } 18038 18039 void nl80211_send_roamed(struct cfg80211_registered_device *rdev, 18040 struct net_device *netdev, 18041 struct cfg80211_roam_info *info, gfp_t gfp) 18042 { 18043 struct sk_buff *msg; 18044 void *hdr; 18045 size_t link_info_size = 0; 18046 unsigned int link; 18047 const u8 *connected_addr = info->ap_mld_addr ? 18048 info->ap_mld_addr : 18049 (info->links[0].bss ? 18050 info->links[0].bss->bssid : 18051 info->links[0].bssid); 18052 18053 if (info->valid_links) { 18054 for_each_valid_link(info, link) { 18055 /* Nested attribute header */ 18056 link_info_size += NLA_HDRLEN; 18057 /* Link ID */ 18058 link_info_size += nla_total_size(sizeof(u8)); 18059 link_info_size += info->links[link].addr ? 18060 nla_total_size(ETH_ALEN) : 0; 18061 link_info_size += (info->links[link].bssid || 18062 info->links[link].bss) ? 18063 nla_total_size(ETH_ALEN) : 0; 18064 } 18065 } 18066 18067 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + 18068 info->fils.kek_len + info->fils.pmk_len + 18069 (info->fils.pmkid ? WLAN_PMKID_LEN : 0) + 18070 link_info_size, gfp); 18071 if (!msg) 18072 return; 18073 18074 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); 18075 if (!hdr) { 18076 nlmsg_free(msg); 18077 return; 18078 } 18079 18080 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18081 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18082 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, connected_addr) || 18083 (info->req_ie && 18084 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, 18085 info->req_ie)) || 18086 (info->resp_ie && 18087 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, 18088 info->resp_ie)) || 18089 (info->fils.update_erp_next_seq_num && 18090 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, 18091 info->fils.erp_next_seq_num)) || 18092 (info->fils.kek && 18093 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, 18094 info->fils.kek)) || 18095 (info->fils.pmk && 18096 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || 18097 (info->fils.pmkid && 18098 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) 18099 goto nla_put_failure; 18100 18101 if (info->valid_links) { 18102 int i = 1; 18103 struct nlattr *nested; 18104 18105 nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18106 if (!nested) 18107 goto nla_put_failure; 18108 18109 for_each_valid_link(info, link) { 18110 struct nlattr *nested_mlo_links; 18111 const u8 *bssid = info->links[link].bss ? 18112 info->links[link].bss->bssid : 18113 info->links[link].bssid; 18114 18115 nested_mlo_links = nla_nest_start(msg, i); 18116 if (!nested_mlo_links) 18117 goto nla_put_failure; 18118 18119 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link) || 18120 (bssid && 18121 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, bssid)) || 18122 (info->links[link].addr && 18123 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, 18124 info->links[link].addr))) 18125 goto nla_put_failure; 18126 18127 nla_nest_end(msg, nested_mlo_links); 18128 i++; 18129 } 18130 nla_nest_end(msg, nested); 18131 } 18132 18133 genlmsg_end(msg, hdr); 18134 18135 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18136 NL80211_MCGRP_MLME, gfp); 18137 return; 18138 18139 nla_put_failure: 18140 nlmsg_free(msg); 18141 } 18142 18143 void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, 18144 struct net_device *netdev, const u8 *peer_addr, 18145 const u8 *td_bitmap, u8 td_bitmap_len) 18146 { 18147 struct sk_buff *msg; 18148 void *hdr; 18149 18150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18151 if (!msg) 18152 return; 18153 18154 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); 18155 if (!hdr) { 18156 nlmsg_free(msg); 18157 return; 18158 } 18159 18160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18162 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_addr)) 18163 goto nla_put_failure; 18164 18165 if ((td_bitmap_len > 0) && td_bitmap) 18166 if (nla_put(msg, NL80211_ATTR_TD_BITMAP, 18167 td_bitmap_len, td_bitmap)) 18168 goto nla_put_failure; 18169 18170 genlmsg_end(msg, hdr); 18171 18172 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18173 NL80211_MCGRP_MLME, GFP_KERNEL); 18174 return; 18175 18176 nla_put_failure: 18177 nlmsg_free(msg); 18178 } 18179 18180 void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, 18181 struct net_device *netdev, u16 reason, 18182 const u8 *ie, size_t ie_len, bool from_ap) 18183 { 18184 struct sk_buff *msg; 18185 void *hdr; 18186 18187 msg = nlmsg_new(100 + ie_len, GFP_KERNEL); 18188 if (!msg) 18189 return; 18190 18191 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); 18192 if (!hdr) { 18193 nlmsg_free(msg); 18194 return; 18195 } 18196 18197 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18198 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18199 (reason && 18200 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || 18201 (from_ap && 18202 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || 18203 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) 18204 goto nla_put_failure; 18205 18206 genlmsg_end(msg, hdr); 18207 18208 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18209 NL80211_MCGRP_MLME, GFP_KERNEL); 18210 return; 18211 18212 nla_put_failure: 18213 nlmsg_free(msg); 18214 } 18215 18216 void cfg80211_links_removed(struct net_device *dev, u16 link_mask) 18217 { 18218 struct wireless_dev *wdev = dev->ieee80211_ptr; 18219 struct wiphy *wiphy = wdev->wiphy; 18220 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18221 struct sk_buff *msg; 18222 struct nlattr *links; 18223 void *hdr; 18224 18225 lockdep_assert_wiphy(wdev->wiphy); 18226 trace_cfg80211_links_removed(dev, link_mask); 18227 18228 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_STATION && 18229 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)) 18230 return; 18231 18232 if (WARN_ON(!wdev->valid_links || !link_mask || 18233 (wdev->valid_links & link_mask) != link_mask || 18234 wdev->valid_links == link_mask)) 18235 return; 18236 18237 cfg80211_wdev_release_link_bsses(wdev, link_mask); 18238 wdev->valid_links &= ~link_mask; 18239 18240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18241 if (!msg) 18242 return; 18243 18244 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_LINKS_REMOVED); 18245 if (!hdr) { 18246 nlmsg_free(msg); 18247 return; 18248 } 18249 18250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 18252 goto nla_put_failure; 18253 18254 links = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS); 18255 if (!links) 18256 goto nla_put_failure; 18257 18258 while (link_mask) { 18259 struct nlattr *link; 18260 int link_id = __ffs(link_mask); 18261 18262 link = nla_nest_start(msg, link_id + 1); 18263 if (!link) 18264 goto nla_put_failure; 18265 18266 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 18267 goto nla_put_failure; 18268 18269 nla_nest_end(msg, link); 18270 link_mask &= ~(1 << link_id); 18271 } 18272 18273 nla_nest_end(msg, links); 18274 18275 genlmsg_end(msg, hdr); 18276 18277 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18278 NL80211_MCGRP_MLME, GFP_KERNEL); 18279 return; 18280 18281 nla_put_failure: 18282 nlmsg_free(msg); 18283 } 18284 EXPORT_SYMBOL(cfg80211_links_removed); 18285 18286 void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, 18287 struct net_device *netdev, const u8 *bssid, 18288 gfp_t gfp) 18289 { 18290 struct sk_buff *msg; 18291 void *hdr; 18292 18293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18294 if (!msg) 18295 return; 18296 18297 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); 18298 if (!hdr) { 18299 nlmsg_free(msg); 18300 return; 18301 } 18302 18303 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18304 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18305 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 18306 goto nla_put_failure; 18307 18308 genlmsg_end(msg, hdr); 18309 18310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18311 NL80211_MCGRP_MLME, gfp); 18312 return; 18313 18314 nla_put_failure: 18315 nlmsg_free(msg); 18316 } 18317 18318 void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, 18319 const u8 *ie, u8 ie_len, 18320 int sig_dbm, gfp_t gfp) 18321 { 18322 struct wireless_dev *wdev = dev->ieee80211_ptr; 18323 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18324 struct sk_buff *msg; 18325 void *hdr; 18326 18327 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) 18328 return; 18329 18330 trace_cfg80211_notify_new_peer_candidate(dev, addr); 18331 18332 msg = nlmsg_new(100 + ie_len, gfp); 18333 if (!msg) 18334 return; 18335 18336 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); 18337 if (!hdr) { 18338 nlmsg_free(msg); 18339 return; 18340 } 18341 18342 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18343 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18344 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 18345 (ie_len && ie && 18346 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || 18347 (sig_dbm && 18348 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) 18349 goto nla_put_failure; 18350 18351 genlmsg_end(msg, hdr); 18352 18353 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18354 NL80211_MCGRP_MLME, gfp); 18355 return; 18356 18357 nla_put_failure: 18358 nlmsg_free(msg); 18359 } 18360 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); 18361 18362 void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, 18363 struct net_device *netdev, const u8 *addr, 18364 enum nl80211_key_type key_type, int key_id, 18365 const u8 *tsc, gfp_t gfp) 18366 { 18367 struct sk_buff *msg; 18368 void *hdr; 18369 18370 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18371 if (!msg) 18372 return; 18373 18374 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); 18375 if (!hdr) { 18376 nlmsg_free(msg); 18377 return; 18378 } 18379 18380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18381 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18382 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || 18383 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || 18384 (key_id != -1 && 18385 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || 18386 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) 18387 goto nla_put_failure; 18388 18389 genlmsg_end(msg, hdr); 18390 18391 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18392 NL80211_MCGRP_MLME, gfp); 18393 return; 18394 18395 nla_put_failure: 18396 nlmsg_free(msg); 18397 } 18398 18399 void nl80211_send_beacon_hint_event(struct wiphy *wiphy, 18400 struct ieee80211_channel *channel_before, 18401 struct ieee80211_channel *channel_after) 18402 { 18403 struct sk_buff *msg; 18404 void *hdr; 18405 struct nlattr *nl_freq; 18406 18407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); 18408 if (!msg) 18409 return; 18410 18411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); 18412 if (!hdr) { 18413 nlmsg_free(msg); 18414 return; 18415 } 18416 18417 /* 18418 * Since we are applying the beacon hint to a wiphy we know its 18419 * wiphy_idx is valid 18420 */ 18421 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) 18422 goto nla_put_failure; 18423 18424 /* Before */ 18425 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); 18426 if (!nl_freq) 18427 goto nla_put_failure; 18428 18429 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) 18430 goto nla_put_failure; 18431 nla_nest_end(msg, nl_freq); 18432 18433 /* After */ 18434 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); 18435 if (!nl_freq) 18436 goto nla_put_failure; 18437 18438 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) 18439 goto nla_put_failure; 18440 nla_nest_end(msg, nl_freq); 18441 18442 genlmsg_end(msg, hdr); 18443 18444 rcu_read_lock(); 18445 genlmsg_multicast_allns(&nl80211_fam, msg, 0, 18446 NL80211_MCGRP_REGULATORY, GFP_ATOMIC); 18447 rcu_read_unlock(); 18448 18449 return; 18450 18451 nla_put_failure: 18452 nlmsg_free(msg); 18453 } 18454 18455 static void nl80211_send_remain_on_chan_event( 18456 int cmd, struct cfg80211_registered_device *rdev, 18457 struct wireless_dev *wdev, u64 cookie, 18458 struct ieee80211_channel *chan, 18459 unsigned int duration, gfp_t gfp) 18460 { 18461 struct sk_buff *msg; 18462 void *hdr; 18463 18464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18465 if (!msg) 18466 return; 18467 18468 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18469 if (!hdr) { 18470 nlmsg_free(msg); 18471 return; 18472 } 18473 18474 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18475 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18476 wdev->netdev->ifindex)) || 18477 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18478 NL80211_ATTR_PAD) || 18479 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || 18480 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, 18481 NL80211_CHAN_NO_HT) || 18482 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 18483 NL80211_ATTR_PAD)) 18484 goto nla_put_failure; 18485 18486 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && 18487 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) 18488 goto nla_put_failure; 18489 18490 genlmsg_end(msg, hdr); 18491 18492 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18493 NL80211_MCGRP_MLME, gfp); 18494 return; 18495 18496 nla_put_failure: 18497 nlmsg_free(msg); 18498 } 18499 18500 void cfg80211_assoc_comeback(struct net_device *netdev, 18501 const u8 *ap_addr, u32 timeout) 18502 { 18503 struct wireless_dev *wdev = netdev->ieee80211_ptr; 18504 struct wiphy *wiphy = wdev->wiphy; 18505 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18506 struct sk_buff *msg; 18507 void *hdr; 18508 18509 trace_cfg80211_assoc_comeback(wdev, ap_addr, timeout); 18510 18511 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 18512 if (!msg) 18513 return; 18514 18515 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ASSOC_COMEBACK); 18516 if (!hdr) { 18517 nlmsg_free(msg); 18518 return; 18519 } 18520 18521 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18522 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 18523 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ap_addr) || 18524 nla_put_u32(msg, NL80211_ATTR_TIMEOUT, timeout)) 18525 goto nla_put_failure; 18526 18527 genlmsg_end(msg, hdr); 18528 18529 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18530 NL80211_MCGRP_MLME, GFP_KERNEL); 18531 return; 18532 18533 nla_put_failure: 18534 nlmsg_free(msg); 18535 } 18536 EXPORT_SYMBOL(cfg80211_assoc_comeback); 18537 18538 void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, 18539 struct ieee80211_channel *chan, 18540 unsigned int duration, gfp_t gfp) 18541 { 18542 struct wiphy *wiphy = wdev->wiphy; 18543 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18544 18545 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); 18546 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, 18547 rdev, wdev, cookie, chan, 18548 duration, gfp); 18549 } 18550 EXPORT_SYMBOL(cfg80211_ready_on_channel); 18551 18552 void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, 18553 struct ieee80211_channel *chan, 18554 gfp_t gfp) 18555 { 18556 struct wiphy *wiphy = wdev->wiphy; 18557 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18558 18559 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); 18560 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, 18561 rdev, wdev, cookie, chan, 0, gfp); 18562 } 18563 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); 18564 18565 void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, 18566 struct ieee80211_channel *chan, 18567 gfp_t gfp) 18568 { 18569 struct wiphy *wiphy = wdev->wiphy; 18570 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18571 18572 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); 18573 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, 18574 rdev, wdev, cookie, chan, 0, gfp); 18575 } 18576 EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); 18577 18578 void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, 18579 struct station_info *sinfo, gfp_t gfp) 18580 { 18581 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18582 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18583 struct sk_buff *msg; 18584 18585 trace_cfg80211_new_sta(dev, mac_addr, sinfo); 18586 18587 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18588 if (!msg) 18589 return; 18590 18591 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, 18592 rdev, dev, mac_addr, sinfo) < 0) { 18593 nlmsg_free(msg); 18594 return; 18595 } 18596 18597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18598 NL80211_MCGRP_MLME, gfp); 18599 } 18600 EXPORT_SYMBOL(cfg80211_new_sta); 18601 18602 void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, 18603 struct station_info *sinfo, gfp_t gfp) 18604 { 18605 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18606 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18607 struct sk_buff *msg; 18608 struct station_info empty_sinfo = {}; 18609 18610 if (!sinfo) 18611 sinfo = &empty_sinfo; 18612 18613 trace_cfg80211_del_sta(dev, mac_addr); 18614 18615 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18616 if (!msg) { 18617 cfg80211_sinfo_release_content(sinfo); 18618 return; 18619 } 18620 18621 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, 18622 rdev, dev, mac_addr, sinfo) < 0) { 18623 nlmsg_free(msg); 18624 return; 18625 } 18626 18627 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18628 NL80211_MCGRP_MLME, gfp); 18629 } 18630 EXPORT_SYMBOL(cfg80211_del_sta_sinfo); 18631 18632 void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, 18633 enum nl80211_connect_failed_reason reason, 18634 gfp_t gfp) 18635 { 18636 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 18637 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18638 struct sk_buff *msg; 18639 void *hdr; 18640 18641 msg = nlmsg_new(NLMSG_GOODSIZE, gfp); 18642 if (!msg) 18643 return; 18644 18645 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); 18646 if (!hdr) { 18647 nlmsg_free(msg); 18648 return; 18649 } 18650 18651 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18652 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || 18653 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) 18654 goto nla_put_failure; 18655 18656 genlmsg_end(msg, hdr); 18657 18658 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18659 NL80211_MCGRP_MLME, gfp); 18660 return; 18661 18662 nla_put_failure: 18663 nlmsg_free(msg); 18664 } 18665 EXPORT_SYMBOL(cfg80211_conn_failed); 18666 18667 static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, 18668 const u8 *addr, gfp_t gfp) 18669 { 18670 struct wireless_dev *wdev = dev->ieee80211_ptr; 18671 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18672 struct sk_buff *msg; 18673 void *hdr; 18674 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); 18675 18676 if (!nlportid) 18677 return false; 18678 18679 msg = nlmsg_new(100, gfp); 18680 if (!msg) 18681 return true; 18682 18683 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 18684 if (!hdr) { 18685 nlmsg_free(msg); 18686 return true; 18687 } 18688 18689 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18690 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18691 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) 18692 goto nla_put_failure; 18693 18694 genlmsg_end(msg, hdr); 18695 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18696 return true; 18697 18698 nla_put_failure: 18699 nlmsg_free(msg); 18700 return true; 18701 } 18702 18703 bool cfg80211_rx_spurious_frame(struct net_device *dev, 18704 const u8 *addr, gfp_t gfp) 18705 { 18706 struct wireless_dev *wdev = dev->ieee80211_ptr; 18707 bool ret; 18708 18709 trace_cfg80211_rx_spurious_frame(dev, addr); 18710 18711 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18712 wdev->iftype != NL80211_IFTYPE_P2P_GO)) { 18713 trace_cfg80211_return_bool(false); 18714 return false; 18715 } 18716 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, 18717 addr, gfp); 18718 trace_cfg80211_return_bool(ret); 18719 return ret; 18720 } 18721 EXPORT_SYMBOL(cfg80211_rx_spurious_frame); 18722 18723 bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, 18724 const u8 *addr, gfp_t gfp) 18725 { 18726 struct wireless_dev *wdev = dev->ieee80211_ptr; 18727 bool ret; 18728 18729 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); 18730 18731 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && 18732 wdev->iftype != NL80211_IFTYPE_P2P_GO && 18733 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { 18734 trace_cfg80211_return_bool(false); 18735 return false; 18736 } 18737 ret = __nl80211_unexpected_frame(dev, 18738 NL80211_CMD_UNEXPECTED_4ADDR_FRAME, 18739 addr, gfp); 18740 trace_cfg80211_return_bool(ret); 18741 return ret; 18742 } 18743 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); 18744 18745 int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, 18746 struct wireless_dev *wdev, u32 nlportid, 18747 struct cfg80211_rx_info *info, gfp_t gfp) 18748 { 18749 struct net_device *netdev = wdev->netdev; 18750 struct sk_buff *msg; 18751 void *hdr; 18752 18753 msg = nlmsg_new(100 + info->len, gfp); 18754 if (!msg) 18755 return -ENOMEM; 18756 18757 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 18758 if (!hdr) { 18759 nlmsg_free(msg); 18760 return -ENOMEM; 18761 } 18762 18763 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18764 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18765 netdev->ifindex)) || 18766 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18767 NL80211_ATTR_PAD) || 18768 (info->have_link_id && 18769 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, info->link_id)) || 18770 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(info->freq)) || 18771 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, info->freq % 1000) || 18772 (info->sig_dbm && 18773 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, info->sig_dbm)) || 18774 nla_put(msg, NL80211_ATTR_FRAME, info->len, info->buf) || 18775 (info->flags && 18776 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, info->flags)) || 18777 (info->rx_tstamp && nla_put_u64_64bit(msg, 18778 NL80211_ATTR_RX_HW_TIMESTAMP, 18779 info->rx_tstamp, 18780 NL80211_ATTR_PAD)) || 18781 (info->ack_tstamp && nla_put_u64_64bit(msg, 18782 NL80211_ATTR_TX_HW_TIMESTAMP, 18783 info->ack_tstamp, 18784 NL80211_ATTR_PAD))) 18785 goto nla_put_failure; 18786 18787 genlmsg_end(msg, hdr); 18788 18789 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18790 18791 nla_put_failure: 18792 nlmsg_free(msg); 18793 return -ENOBUFS; 18794 } 18795 18796 static void nl80211_frame_tx_status(struct wireless_dev *wdev, 18797 struct cfg80211_tx_status *status, 18798 gfp_t gfp, enum nl80211_commands command) 18799 { 18800 struct wiphy *wiphy = wdev->wiphy; 18801 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 18802 struct net_device *netdev = wdev->netdev; 18803 struct sk_buff *msg; 18804 void *hdr; 18805 18806 if (command == NL80211_CMD_FRAME_TX_STATUS) 18807 trace_cfg80211_mgmt_tx_status(wdev, status->cookie, 18808 status->ack); 18809 else 18810 trace_cfg80211_control_port_tx_status(wdev, status->cookie, 18811 status->ack); 18812 18813 msg = nlmsg_new(100 + status->len, gfp); 18814 if (!msg) 18815 return; 18816 18817 hdr = nl80211hdr_put(msg, 0, 0, 0, command); 18818 if (!hdr) { 18819 nlmsg_free(msg); 18820 return; 18821 } 18822 18823 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18824 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 18825 netdev->ifindex)) || 18826 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18827 NL80211_ATTR_PAD) || 18828 nla_put(msg, NL80211_ATTR_FRAME, status->len, status->buf) || 18829 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, status->cookie, 18830 NL80211_ATTR_PAD) || 18831 (status->ack && nla_put_flag(msg, NL80211_ATTR_ACK)) || 18832 (status->tx_tstamp && 18833 nla_put_u64_64bit(msg, NL80211_ATTR_TX_HW_TIMESTAMP, 18834 status->tx_tstamp, NL80211_ATTR_PAD)) || 18835 (status->ack_tstamp && 18836 nla_put_u64_64bit(msg, NL80211_ATTR_RX_HW_TIMESTAMP, 18837 status->ack_tstamp, NL80211_ATTR_PAD))) 18838 goto nla_put_failure; 18839 18840 genlmsg_end(msg, hdr); 18841 18842 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18843 NL80211_MCGRP_MLME, gfp); 18844 return; 18845 18846 nla_put_failure: 18847 nlmsg_free(msg); 18848 } 18849 18850 void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, 18851 const u8 *buf, size_t len, bool ack, 18852 gfp_t gfp) 18853 { 18854 struct cfg80211_tx_status status = { 18855 .cookie = cookie, 18856 .buf = buf, 18857 .len = len, 18858 .ack = ack 18859 }; 18860 18861 nl80211_frame_tx_status(wdev, &status, gfp, 18862 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); 18863 } 18864 EXPORT_SYMBOL(cfg80211_control_port_tx_status); 18865 18866 void cfg80211_mgmt_tx_status_ext(struct wireless_dev *wdev, 18867 struct cfg80211_tx_status *status, gfp_t gfp) 18868 { 18869 nl80211_frame_tx_status(wdev, status, gfp, NL80211_CMD_FRAME_TX_STATUS); 18870 } 18871 EXPORT_SYMBOL(cfg80211_mgmt_tx_status_ext); 18872 18873 static int __nl80211_rx_control_port(struct net_device *dev, 18874 struct sk_buff *skb, 18875 bool unencrypted, 18876 int link_id, 18877 gfp_t gfp) 18878 { 18879 struct wireless_dev *wdev = dev->ieee80211_ptr; 18880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18881 struct ethhdr *ehdr = eth_hdr(skb); 18882 const u8 *addr = ehdr->h_source; 18883 u16 proto = be16_to_cpu(skb->protocol); 18884 struct sk_buff *msg; 18885 void *hdr; 18886 struct nlattr *frame; 18887 18888 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); 18889 18890 if (!nlportid) 18891 return -ENOENT; 18892 18893 msg = nlmsg_new(100 + skb->len, gfp); 18894 if (!msg) 18895 return -ENOMEM; 18896 18897 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); 18898 if (!hdr) { 18899 nlmsg_free(msg); 18900 return -ENOBUFS; 18901 } 18902 18903 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18904 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 18905 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 18906 NL80211_ATTR_PAD) || 18907 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 18908 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || 18909 (link_id >= 0 && 18910 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) || 18911 (unencrypted && nla_put_flag(msg, 18912 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) 18913 goto nla_put_failure; 18914 18915 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); 18916 if (!frame) 18917 goto nla_put_failure; 18918 18919 skb_copy_bits(skb, 0, nla_data(frame), skb->len); 18920 genlmsg_end(msg, hdr); 18921 18922 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 18923 18924 nla_put_failure: 18925 nlmsg_free(msg); 18926 return -ENOBUFS; 18927 } 18928 18929 bool cfg80211_rx_control_port(struct net_device *dev, struct sk_buff *skb, 18930 bool unencrypted, int link_id) 18931 { 18932 int ret; 18933 18934 trace_cfg80211_rx_control_port(dev, skb, unencrypted, link_id); 18935 ret = __nl80211_rx_control_port(dev, skb, unencrypted, link_id, 18936 GFP_ATOMIC); 18937 trace_cfg80211_return_bool(ret == 0); 18938 return ret == 0; 18939 } 18940 EXPORT_SYMBOL(cfg80211_rx_control_port); 18941 18942 static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, 18943 const char *mac, gfp_t gfp) 18944 { 18945 struct wireless_dev *wdev = dev->ieee80211_ptr; 18946 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 18947 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 18948 void **cb; 18949 18950 if (!msg) 18951 return NULL; 18952 18953 cb = (void **)msg->cb; 18954 18955 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); 18956 if (!cb[0]) { 18957 nlmsg_free(msg); 18958 return NULL; 18959 } 18960 18961 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 18962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 18963 goto nla_put_failure; 18964 18965 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 18966 goto nla_put_failure; 18967 18968 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); 18969 if (!cb[1]) 18970 goto nla_put_failure; 18971 18972 cb[2] = rdev; 18973 18974 return msg; 18975 nla_put_failure: 18976 nlmsg_free(msg); 18977 return NULL; 18978 } 18979 18980 static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) 18981 { 18982 void **cb = (void **)msg->cb; 18983 struct cfg80211_registered_device *rdev = cb[2]; 18984 18985 nla_nest_end(msg, cb[1]); 18986 genlmsg_end(msg, cb[0]); 18987 18988 memset(msg->cb, 0, sizeof(msg->cb)); 18989 18990 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 18991 NL80211_MCGRP_MLME, gfp); 18992 } 18993 18994 void cfg80211_cqm_rssi_notify(struct net_device *dev, 18995 enum nl80211_cqm_rssi_threshold_event rssi_event, 18996 s32 rssi_level, gfp_t gfp) 18997 { 18998 struct wireless_dev *wdev = dev->ieee80211_ptr; 18999 struct cfg80211_cqm_config *cqm_config; 19000 19001 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); 19002 19003 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && 19004 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) 19005 return; 19006 19007 rcu_read_lock(); 19008 cqm_config = rcu_dereference(wdev->cqm_config); 19009 if (cqm_config) { 19010 cqm_config->last_rssi_event_value = rssi_level; 19011 cqm_config->last_rssi_event_type = rssi_event; 19012 wiphy_work_queue(wdev->wiphy, &wdev->cqm_rssi_work); 19013 } 19014 rcu_read_unlock(); 19015 } 19016 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); 19017 19018 void cfg80211_cqm_rssi_notify_work(struct wiphy *wiphy, struct wiphy_work *work) 19019 { 19020 struct wireless_dev *wdev = container_of(work, struct wireless_dev, 19021 cqm_rssi_work); 19022 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19023 enum nl80211_cqm_rssi_threshold_event rssi_event; 19024 struct cfg80211_cqm_config *cqm_config; 19025 struct sk_buff *msg; 19026 s32 rssi_level; 19027 19028 cqm_config = wiphy_dereference(wdev->wiphy, wdev->cqm_config); 19029 if (!cqm_config) 19030 return; 19031 19032 if (cqm_config->use_range_api) 19033 cfg80211_cqm_rssi_update(rdev, wdev->netdev, cqm_config); 19034 19035 rssi_level = cqm_config->last_rssi_event_value; 19036 rssi_event = cqm_config->last_rssi_event_type; 19037 19038 msg = cfg80211_prepare_cqm(wdev->netdev, NULL, GFP_KERNEL); 19039 if (!msg) 19040 return; 19041 19042 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, 19043 rssi_event)) 19044 goto nla_put_failure; 19045 19046 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, 19047 rssi_level)) 19048 goto nla_put_failure; 19049 19050 cfg80211_send_cqm(msg, GFP_KERNEL); 19051 19052 return; 19053 19054 nla_put_failure: 19055 nlmsg_free(msg); 19056 } 19057 19058 void cfg80211_cqm_txe_notify(struct net_device *dev, 19059 const u8 *peer, u32 num_packets, 19060 u32 rate, u32 intvl, gfp_t gfp) 19061 { 19062 struct sk_buff *msg; 19063 19064 msg = cfg80211_prepare_cqm(dev, peer, gfp); 19065 if (!msg) 19066 return; 19067 19068 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) 19069 goto nla_put_failure; 19070 19071 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) 19072 goto nla_put_failure; 19073 19074 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) 19075 goto nla_put_failure; 19076 19077 cfg80211_send_cqm(msg, gfp); 19078 return; 19079 19080 nla_put_failure: 19081 nlmsg_free(msg); 19082 } 19083 EXPORT_SYMBOL(cfg80211_cqm_txe_notify); 19084 19085 void cfg80211_cqm_pktloss_notify(struct net_device *dev, 19086 const u8 *peer, u32 num_packets, gfp_t gfp) 19087 { 19088 struct sk_buff *msg; 19089 19090 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); 19091 19092 msg = cfg80211_prepare_cqm(dev, peer, gfp); 19093 if (!msg) 19094 return; 19095 19096 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) 19097 goto nla_put_failure; 19098 19099 cfg80211_send_cqm(msg, gfp); 19100 return; 19101 19102 nla_put_failure: 19103 nlmsg_free(msg); 19104 } 19105 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); 19106 19107 void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) 19108 { 19109 struct sk_buff *msg; 19110 19111 msg = cfg80211_prepare_cqm(dev, NULL, gfp); 19112 if (!msg) 19113 return; 19114 19115 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) 19116 goto nla_put_failure; 19117 19118 cfg80211_send_cqm(msg, gfp); 19119 return; 19120 19121 nla_put_failure: 19122 nlmsg_free(msg); 19123 } 19124 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); 19125 19126 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, 19127 struct net_device *netdev, const u8 *bssid, 19128 const u8 *replay_ctr, gfp_t gfp) 19129 { 19130 struct sk_buff *msg; 19131 struct nlattr *rekey_attr; 19132 void *hdr; 19133 19134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19135 if (!msg) 19136 return; 19137 19138 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); 19139 if (!hdr) { 19140 nlmsg_free(msg); 19141 return; 19142 } 19143 19144 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19145 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19146 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) 19147 goto nla_put_failure; 19148 19149 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); 19150 if (!rekey_attr) 19151 goto nla_put_failure; 19152 19153 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, 19154 NL80211_REPLAY_CTR_LEN, replay_ctr)) 19155 goto nla_put_failure; 19156 19157 nla_nest_end(msg, rekey_attr); 19158 19159 genlmsg_end(msg, hdr); 19160 19161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19162 NL80211_MCGRP_MLME, gfp); 19163 return; 19164 19165 nla_put_failure: 19166 nlmsg_free(msg); 19167 } 19168 19169 void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, 19170 const u8 *replay_ctr, gfp_t gfp) 19171 { 19172 struct wireless_dev *wdev = dev->ieee80211_ptr; 19173 struct wiphy *wiphy = wdev->wiphy; 19174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19175 19176 trace_cfg80211_gtk_rekey_notify(dev, bssid); 19177 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); 19178 } 19179 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); 19180 19181 static void 19182 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, 19183 struct net_device *netdev, int index, 19184 const u8 *bssid, bool preauth, gfp_t gfp) 19185 { 19186 struct sk_buff *msg; 19187 struct nlattr *attr; 19188 void *hdr; 19189 19190 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19191 if (!msg) 19192 return; 19193 19194 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); 19195 if (!hdr) { 19196 nlmsg_free(msg); 19197 return; 19198 } 19199 19200 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19201 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 19202 goto nla_put_failure; 19203 19204 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); 19205 if (!attr) 19206 goto nla_put_failure; 19207 19208 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || 19209 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || 19210 (preauth && 19211 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) 19212 goto nla_put_failure; 19213 19214 nla_nest_end(msg, attr); 19215 19216 genlmsg_end(msg, hdr); 19217 19218 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19219 NL80211_MCGRP_MLME, gfp); 19220 return; 19221 19222 nla_put_failure: 19223 nlmsg_free(msg); 19224 } 19225 19226 void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, 19227 const u8 *bssid, bool preauth, gfp_t gfp) 19228 { 19229 struct wireless_dev *wdev = dev->ieee80211_ptr; 19230 struct wiphy *wiphy = wdev->wiphy; 19231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19232 19233 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); 19234 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); 19235 } 19236 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); 19237 19238 static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, 19239 struct net_device *netdev, 19240 unsigned int link_id, 19241 struct cfg80211_chan_def *chandef, 19242 gfp_t gfp, 19243 enum nl80211_commands notif, 19244 u8 count, bool quiet, u16 punct_bitmap) 19245 { 19246 struct wireless_dev *wdev = netdev->ieee80211_ptr; 19247 struct sk_buff *msg; 19248 void *hdr; 19249 19250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19251 if (!msg) 19252 return; 19253 19254 hdr = nl80211hdr_put(msg, 0, 0, 0, notif); 19255 if (!hdr) { 19256 nlmsg_free(msg); 19257 return; 19258 } 19259 19260 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) 19261 goto nla_put_failure; 19262 19263 if (wdev->valid_links && 19264 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id)) 19265 goto nla_put_failure; 19266 19267 if (nl80211_send_chandef(msg, chandef)) 19268 goto nla_put_failure; 19269 19270 if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { 19271 if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) 19272 goto nla_put_failure; 19273 if (quiet && 19274 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) 19275 goto nla_put_failure; 19276 } 19277 19278 if (nla_put_u32(msg, NL80211_ATTR_PUNCT_BITMAP, punct_bitmap)) 19279 goto nla_put_failure; 19280 19281 genlmsg_end(msg, hdr); 19282 19283 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19284 NL80211_MCGRP_MLME, gfp); 19285 return; 19286 19287 nla_put_failure: 19288 nlmsg_free(msg); 19289 } 19290 19291 void cfg80211_ch_switch_notify(struct net_device *dev, 19292 struct cfg80211_chan_def *chandef, 19293 unsigned int link_id, u16 punct_bitmap) 19294 { 19295 struct wireless_dev *wdev = dev->ieee80211_ptr; 19296 struct wiphy *wiphy = wdev->wiphy; 19297 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19298 19299 lockdep_assert_wiphy(wdev->wiphy); 19300 WARN_INVALID_LINK_ID(wdev, link_id); 19301 19302 trace_cfg80211_ch_switch_notify(dev, chandef, link_id, punct_bitmap); 19303 19304 switch (wdev->iftype) { 19305 case NL80211_IFTYPE_STATION: 19306 case NL80211_IFTYPE_P2P_CLIENT: 19307 if (!WARN_ON(!wdev->links[link_id].client.current_bss)) 19308 cfg80211_update_assoc_bss_entry(wdev, link_id, 19309 chandef->chan); 19310 break; 19311 case NL80211_IFTYPE_MESH_POINT: 19312 wdev->u.mesh.chandef = *chandef; 19313 wdev->u.mesh.preset_chandef = *chandef; 19314 break; 19315 case NL80211_IFTYPE_AP: 19316 case NL80211_IFTYPE_P2P_GO: 19317 wdev->links[link_id].ap.chandef = *chandef; 19318 break; 19319 case NL80211_IFTYPE_ADHOC: 19320 wdev->u.ibss.chandef = *chandef; 19321 break; 19322 default: 19323 WARN_ON(1); 19324 break; 19325 } 19326 19327 cfg80211_sched_dfs_chan_update(rdev); 19328 19329 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19330 NL80211_CMD_CH_SWITCH_NOTIFY, 0, false, 19331 punct_bitmap); 19332 } 19333 EXPORT_SYMBOL(cfg80211_ch_switch_notify); 19334 19335 void cfg80211_ch_switch_started_notify(struct net_device *dev, 19336 struct cfg80211_chan_def *chandef, 19337 unsigned int link_id, u8 count, 19338 bool quiet, u16 punct_bitmap) 19339 { 19340 struct wireless_dev *wdev = dev->ieee80211_ptr; 19341 struct wiphy *wiphy = wdev->wiphy; 19342 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19343 19344 lockdep_assert_wiphy(wdev->wiphy); 19345 WARN_INVALID_LINK_ID(wdev, link_id); 19346 19347 trace_cfg80211_ch_switch_started_notify(dev, chandef, link_id, 19348 punct_bitmap); 19349 19350 19351 nl80211_ch_switch_notify(rdev, dev, link_id, chandef, GFP_KERNEL, 19352 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, 19353 count, quiet, punct_bitmap); 19354 } 19355 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); 19356 19357 int cfg80211_bss_color_notify(struct net_device *dev, 19358 enum nl80211_commands cmd, u8 count, 19359 u64 color_bitmap) 19360 { 19361 struct wireless_dev *wdev = dev->ieee80211_ptr; 19362 struct wiphy *wiphy = wdev->wiphy; 19363 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19364 struct sk_buff *msg; 19365 void *hdr; 19366 19367 lockdep_assert_wiphy(wdev->wiphy); 19368 19369 trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap); 19370 19371 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 19372 if (!msg) 19373 return -ENOMEM; 19374 19375 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); 19376 if (!hdr) 19377 goto nla_put_failure; 19378 19379 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19380 goto nla_put_failure; 19381 19382 if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED && 19383 nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count)) 19384 goto nla_put_failure; 19385 19386 if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION && 19387 nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP, 19388 color_bitmap, NL80211_ATTR_PAD)) 19389 goto nla_put_failure; 19390 19391 genlmsg_end(msg, hdr); 19392 19393 return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), 19394 msg, 0, NL80211_MCGRP_MLME, GFP_KERNEL); 19395 19396 nla_put_failure: 19397 nlmsg_free(msg); 19398 return -EINVAL; 19399 } 19400 EXPORT_SYMBOL(cfg80211_bss_color_notify); 19401 19402 void 19403 nl80211_radar_notify(struct cfg80211_registered_device *rdev, 19404 const struct cfg80211_chan_def *chandef, 19405 enum nl80211_radar_event event, 19406 struct net_device *netdev, gfp_t gfp) 19407 { 19408 struct sk_buff *msg; 19409 void *hdr; 19410 19411 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19412 if (!msg) 19413 return; 19414 19415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); 19416 if (!hdr) { 19417 nlmsg_free(msg); 19418 return; 19419 } 19420 19421 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19422 goto nla_put_failure; 19423 19424 /* NOP and radar events don't need a netdev parameter */ 19425 if (netdev) { 19426 struct wireless_dev *wdev = netdev->ieee80211_ptr; 19427 19428 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19429 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19430 NL80211_ATTR_PAD)) 19431 goto nla_put_failure; 19432 } 19433 19434 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) 19435 goto nla_put_failure; 19436 19437 if (nl80211_send_chandef(msg, chandef)) 19438 goto nla_put_failure; 19439 19440 genlmsg_end(msg, hdr); 19441 19442 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19443 NL80211_MCGRP_MLME, gfp); 19444 return; 19445 19446 nla_put_failure: 19447 nlmsg_free(msg); 19448 } 19449 19450 void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, 19451 struct sta_opmode_info *sta_opmode, 19452 gfp_t gfp) 19453 { 19454 struct sk_buff *msg; 19455 struct wireless_dev *wdev = dev->ieee80211_ptr; 19456 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19457 void *hdr; 19458 19459 if (WARN_ON(!mac)) 19460 return; 19461 19462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19463 if (!msg) 19464 return; 19465 19466 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); 19467 if (!hdr) { 19468 nlmsg_free(msg); 19469 return; 19470 } 19471 19472 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) 19473 goto nla_put_failure; 19474 19475 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) 19476 goto nla_put_failure; 19477 19478 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) 19479 goto nla_put_failure; 19480 19481 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && 19482 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) 19483 goto nla_put_failure; 19484 19485 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && 19486 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) 19487 goto nla_put_failure; 19488 19489 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && 19490 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) 19491 goto nla_put_failure; 19492 19493 genlmsg_end(msg, hdr); 19494 19495 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19496 NL80211_MCGRP_MLME, gfp); 19497 19498 return; 19499 19500 nla_put_failure: 19501 nlmsg_free(msg); 19502 } 19503 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); 19504 19505 void cfg80211_probe_status(struct net_device *dev, const u8 *addr, 19506 u64 cookie, bool acked, s32 ack_signal, 19507 bool is_valid_ack_signal, gfp_t gfp) 19508 { 19509 struct wireless_dev *wdev = dev->ieee80211_ptr; 19510 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19511 struct sk_buff *msg; 19512 void *hdr; 19513 19514 trace_cfg80211_probe_status(dev, addr, cookie, acked); 19515 19516 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19517 19518 if (!msg) 19519 return; 19520 19521 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); 19522 if (!hdr) { 19523 nlmsg_free(msg); 19524 return; 19525 } 19526 19527 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19528 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19529 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || 19530 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, 19531 NL80211_ATTR_PAD) || 19532 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || 19533 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, 19534 ack_signal))) 19535 goto nla_put_failure; 19536 19537 genlmsg_end(msg, hdr); 19538 19539 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19540 NL80211_MCGRP_MLME, gfp); 19541 return; 19542 19543 nla_put_failure: 19544 nlmsg_free(msg); 19545 } 19546 EXPORT_SYMBOL(cfg80211_probe_status); 19547 19548 void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, 19549 size_t len, int freq, int sig_dbm) 19550 { 19551 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19552 struct sk_buff *msg; 19553 void *hdr; 19554 struct cfg80211_beacon_registration *reg; 19555 19556 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); 19557 19558 spin_lock_bh(&rdev->beacon_registrations_lock); 19559 list_for_each_entry(reg, &rdev->beacon_registrations, list) { 19560 msg = nlmsg_new(len + 100, GFP_ATOMIC); 19561 if (!msg) { 19562 spin_unlock_bh(&rdev->beacon_registrations_lock); 19563 return; 19564 } 19565 19566 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); 19567 if (!hdr) 19568 goto nla_put_failure; 19569 19570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19571 (freq && 19572 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, 19573 KHZ_TO_MHZ(freq)) || 19574 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, 19575 freq % 1000))) || 19576 (sig_dbm && 19577 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || 19578 nla_put(msg, NL80211_ATTR_FRAME, len, frame)) 19579 goto nla_put_failure; 19580 19581 genlmsg_end(msg, hdr); 19582 19583 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); 19584 } 19585 spin_unlock_bh(&rdev->beacon_registrations_lock); 19586 return; 19587 19588 nla_put_failure: 19589 spin_unlock_bh(&rdev->beacon_registrations_lock); 19590 nlmsg_free(msg); 19591 } 19592 EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); 19593 19594 #ifdef CONFIG_PM 19595 static int cfg80211_net_detect_results(struct sk_buff *msg, 19596 struct cfg80211_wowlan_wakeup *wakeup) 19597 { 19598 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; 19599 struct nlattr *nl_results, *nl_match, *nl_freqs; 19600 int i, j; 19601 19602 nl_results = nla_nest_start_noflag(msg, 19603 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); 19604 if (!nl_results) 19605 return -EMSGSIZE; 19606 19607 for (i = 0; i < nd->n_matches; i++) { 19608 struct cfg80211_wowlan_nd_match *match = nd->matches[i]; 19609 19610 nl_match = nla_nest_start_noflag(msg, i); 19611 if (!nl_match) 19612 break; 19613 19614 /* The SSID attribute is optional in nl80211, but for 19615 * simplicity reasons it's always present in the 19616 * cfg80211 structure. If a driver can't pass the 19617 * SSID, that needs to be changed. A zero length SSID 19618 * is still a valid SSID (wildcard), so it cannot be 19619 * used for this purpose. 19620 */ 19621 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, 19622 match->ssid.ssid)) { 19623 nla_nest_cancel(msg, nl_match); 19624 goto out; 19625 } 19626 19627 if (match->n_channels) { 19628 nl_freqs = nla_nest_start_noflag(msg, 19629 NL80211_ATTR_SCAN_FREQUENCIES); 19630 if (!nl_freqs) { 19631 nla_nest_cancel(msg, nl_match); 19632 goto out; 19633 } 19634 19635 for (j = 0; j < match->n_channels; j++) { 19636 if (nla_put_u32(msg, j, match->channels[j])) { 19637 nla_nest_cancel(msg, nl_freqs); 19638 nla_nest_cancel(msg, nl_match); 19639 goto out; 19640 } 19641 } 19642 19643 nla_nest_end(msg, nl_freqs); 19644 } 19645 19646 nla_nest_end(msg, nl_match); 19647 } 19648 19649 out: 19650 nla_nest_end(msg, nl_results); 19651 return 0; 19652 } 19653 19654 void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, 19655 struct cfg80211_wowlan_wakeup *wakeup, 19656 gfp_t gfp) 19657 { 19658 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19659 struct sk_buff *msg; 19660 void *hdr; 19661 int size = 200; 19662 19663 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); 19664 19665 if (wakeup) 19666 size += wakeup->packet_present_len; 19667 19668 msg = nlmsg_new(size, gfp); 19669 if (!msg) 19670 return; 19671 19672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); 19673 if (!hdr) 19674 goto free_msg; 19675 19676 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19677 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19678 NL80211_ATTR_PAD)) 19679 goto free_msg; 19680 19681 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, 19682 wdev->netdev->ifindex)) 19683 goto free_msg; 19684 19685 if (wakeup) { 19686 struct nlattr *reasons; 19687 19688 reasons = nla_nest_start_noflag(msg, 19689 NL80211_ATTR_WOWLAN_TRIGGERS); 19690 if (!reasons) 19691 goto free_msg; 19692 19693 if (wakeup->disconnect && 19694 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) 19695 goto free_msg; 19696 if (wakeup->magic_pkt && 19697 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) 19698 goto free_msg; 19699 if (wakeup->gtk_rekey_failure && 19700 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) 19701 goto free_msg; 19702 if (wakeup->eap_identity_req && 19703 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) 19704 goto free_msg; 19705 if (wakeup->four_way_handshake && 19706 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) 19707 goto free_msg; 19708 if (wakeup->rfkill_release && 19709 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) 19710 goto free_msg; 19711 19712 if (wakeup->pattern_idx >= 0 && 19713 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, 19714 wakeup->pattern_idx)) 19715 goto free_msg; 19716 19717 if (wakeup->tcp_match && 19718 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) 19719 goto free_msg; 19720 19721 if (wakeup->tcp_connlost && 19722 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) 19723 goto free_msg; 19724 19725 if (wakeup->tcp_nomoretokens && 19726 nla_put_flag(msg, 19727 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) 19728 goto free_msg; 19729 19730 if (wakeup->packet) { 19731 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; 19732 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; 19733 19734 if (!wakeup->packet_80211) { 19735 pkt_attr = 19736 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; 19737 len_attr = 19738 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; 19739 } 19740 19741 if (wakeup->packet_len && 19742 nla_put_u32(msg, len_attr, wakeup->packet_len)) 19743 goto free_msg; 19744 19745 if (nla_put(msg, pkt_attr, wakeup->packet_present_len, 19746 wakeup->packet)) 19747 goto free_msg; 19748 } 19749 19750 if (wakeup->net_detect && 19751 cfg80211_net_detect_results(msg, wakeup)) 19752 goto free_msg; 19753 19754 nla_nest_end(msg, reasons); 19755 } 19756 19757 genlmsg_end(msg, hdr); 19758 19759 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19760 NL80211_MCGRP_MLME, gfp); 19761 return; 19762 19763 free_msg: 19764 nlmsg_free(msg); 19765 } 19766 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); 19767 #endif 19768 19769 void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, 19770 enum nl80211_tdls_operation oper, 19771 u16 reason_code, gfp_t gfp) 19772 { 19773 struct wireless_dev *wdev = dev->ieee80211_ptr; 19774 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19775 struct sk_buff *msg; 19776 void *hdr; 19777 19778 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, 19779 reason_code); 19780 19781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19782 if (!msg) 19783 return; 19784 19785 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); 19786 if (!hdr) { 19787 nlmsg_free(msg); 19788 return; 19789 } 19790 19791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19792 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 19793 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || 19794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || 19795 (reason_code > 0 && 19796 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) 19797 goto nla_put_failure; 19798 19799 genlmsg_end(msg, hdr); 19800 19801 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19802 NL80211_MCGRP_MLME, gfp); 19803 return; 19804 19805 nla_put_failure: 19806 nlmsg_free(msg); 19807 } 19808 EXPORT_SYMBOL(cfg80211_tdls_oper_request); 19809 19810 static int nl80211_netlink_notify(struct notifier_block * nb, 19811 unsigned long state, 19812 void *_notify) 19813 { 19814 struct netlink_notify *notify = _notify; 19815 struct cfg80211_registered_device *rdev; 19816 struct wireless_dev *wdev; 19817 struct cfg80211_beacon_registration *reg, *tmp; 19818 19819 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) 19820 return NOTIFY_DONE; 19821 19822 rcu_read_lock(); 19823 19824 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { 19825 struct cfg80211_sched_scan_request *sched_scan_req; 19826 19827 list_for_each_entry_rcu(sched_scan_req, 19828 &rdev->sched_scan_req_list, 19829 list) { 19830 if (sched_scan_req->owner_nlportid == notify->portid) { 19831 sched_scan_req->nl_owner_dead = true; 19832 wiphy_work_queue(&rdev->wiphy, 19833 &rdev->sched_scan_stop_wk); 19834 } 19835 } 19836 19837 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { 19838 cfg80211_mlme_unregister_socket(wdev, notify->portid); 19839 19840 if (wdev->owner_nlportid == notify->portid) { 19841 wdev->nl_owner_dead = true; 19842 schedule_work(&rdev->destroy_work); 19843 } else if (wdev->conn_owner_nlportid == notify->portid) { 19844 schedule_work(&wdev->disconnect_wk); 19845 } 19846 19847 cfg80211_release_pmsr(wdev, notify->portid); 19848 } 19849 19850 spin_lock_bh(&rdev->beacon_registrations_lock); 19851 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, 19852 list) { 19853 if (reg->nlportid == notify->portid) { 19854 list_del(®->list); 19855 kfree(reg); 19856 break; 19857 } 19858 } 19859 spin_unlock_bh(&rdev->beacon_registrations_lock); 19860 } 19861 19862 rcu_read_unlock(); 19863 19864 /* 19865 * It is possible that the user space process that is controlling the 19866 * indoor setting disappeared, so notify the regulatory core. 19867 */ 19868 regulatory_netlink_notify(notify->portid); 19869 return NOTIFY_OK; 19870 } 19871 19872 static struct notifier_block nl80211_netlink_notifier = { 19873 .notifier_call = nl80211_netlink_notify, 19874 }; 19875 19876 void cfg80211_ft_event(struct net_device *netdev, 19877 struct cfg80211_ft_event_params *ft_event) 19878 { 19879 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 19880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19881 struct sk_buff *msg; 19882 void *hdr; 19883 19884 trace_cfg80211_ft_event(wiphy, netdev, ft_event); 19885 19886 if (!ft_event->target_ap) 19887 return; 19888 19889 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, 19890 GFP_KERNEL); 19891 if (!msg) 19892 return; 19893 19894 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); 19895 if (!hdr) 19896 goto out; 19897 19898 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19899 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 19900 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) 19901 goto out; 19902 19903 if (ft_event->ies && 19904 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) 19905 goto out; 19906 if (ft_event->ric_ies && 19907 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, 19908 ft_event->ric_ies)) 19909 goto out; 19910 19911 genlmsg_end(msg, hdr); 19912 19913 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 19914 NL80211_MCGRP_MLME, GFP_KERNEL); 19915 return; 19916 out: 19917 nlmsg_free(msg); 19918 } 19919 EXPORT_SYMBOL(cfg80211_ft_event); 19920 19921 void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) 19922 { 19923 struct cfg80211_registered_device *rdev; 19924 struct sk_buff *msg; 19925 void *hdr; 19926 u32 nlportid; 19927 19928 rdev = wiphy_to_rdev(wdev->wiphy); 19929 if (!rdev->crit_proto_nlportid) 19930 return; 19931 19932 nlportid = rdev->crit_proto_nlportid; 19933 rdev->crit_proto_nlportid = 0; 19934 19935 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 19936 if (!msg) 19937 return; 19938 19939 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); 19940 if (!hdr) 19941 goto nla_put_failure; 19942 19943 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19944 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19945 NL80211_ATTR_PAD)) 19946 goto nla_put_failure; 19947 19948 genlmsg_end(msg, hdr); 19949 19950 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); 19951 return; 19952 19953 nla_put_failure: 19954 nlmsg_free(msg); 19955 } 19956 EXPORT_SYMBOL(cfg80211_crit_proto_stopped); 19957 19958 void nl80211_send_ap_stopped(struct wireless_dev *wdev, unsigned int link_id) 19959 { 19960 struct wiphy *wiphy = wdev->wiphy; 19961 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 19962 struct sk_buff *msg; 19963 void *hdr; 19964 19965 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 19966 if (!msg) 19967 return; 19968 19969 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); 19970 if (!hdr) 19971 goto out; 19972 19973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 19974 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || 19975 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), 19976 NL80211_ATTR_PAD) || 19977 (wdev->valid_links && 19978 nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))) 19979 goto out; 19980 19981 genlmsg_end(msg, hdr); 19982 19983 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, 19984 NL80211_MCGRP_MLME, GFP_KERNEL); 19985 return; 19986 out: 19987 nlmsg_free(msg); 19988 } 19989 19990 int cfg80211_external_auth_request(struct net_device *dev, 19991 struct cfg80211_external_auth_params *params, 19992 gfp_t gfp) 19993 { 19994 struct wireless_dev *wdev = dev->ieee80211_ptr; 19995 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); 19996 struct sk_buff *msg; 19997 void *hdr; 19998 19999 if (!wdev->conn_owner_nlportid) 20000 return -EINVAL; 20001 20002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 20003 if (!msg) 20004 return -ENOMEM; 20005 20006 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); 20007 if (!hdr) 20008 goto nla_put_failure; 20009 20010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20011 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || 20012 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || 20013 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, 20014 params->action) || 20015 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || 20016 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, 20017 params->ssid.ssid) || 20018 (!is_zero_ether_addr(params->mld_addr) && 20019 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, params->mld_addr))) 20020 goto nla_put_failure; 20021 20022 genlmsg_end(msg, hdr); 20023 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, 20024 wdev->conn_owner_nlportid); 20025 return 0; 20026 20027 nla_put_failure: 20028 nlmsg_free(msg); 20029 return -ENOBUFS; 20030 } 20031 EXPORT_SYMBOL(cfg80211_external_auth_request); 20032 20033 void cfg80211_update_owe_info_event(struct net_device *netdev, 20034 struct cfg80211_update_owe_info *owe_info, 20035 gfp_t gfp) 20036 { 20037 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; 20038 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); 20039 struct sk_buff *msg; 20040 void *hdr; 20041 20042 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); 20043 20044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); 20045 if (!msg) 20046 return; 20047 20048 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); 20049 if (!hdr) 20050 goto nla_put_failure; 20051 20052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || 20053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || 20054 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) 20055 goto nla_put_failure; 20056 20057 if (!owe_info->ie_len || 20058 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) 20059 goto nla_put_failure; 20060 20061 if (owe_info->assoc_link_id != -1) { 20062 if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, 20063 owe_info->assoc_link_id)) 20064 goto nla_put_failure; 20065 20066 if (!is_zero_ether_addr(owe_info->peer_mld_addr) && 20067 nla_put(msg, NL80211_ATTR_MLD_ADDR, ETH_ALEN, 20068 owe_info->peer_mld_addr)) 20069 goto nla_put_failure; 20070 } 20071 20072 genlmsg_end(msg, hdr); 20073 20074 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, 20075 NL80211_MCGRP_MLME, gfp); 20076 return; 20077 20078 nla_put_failure: 20079 genlmsg_cancel(msg, hdr); 20080 nlmsg_free(msg); 20081 } 20082 EXPORT_SYMBOL(cfg80211_update_owe_info_event); 20083 20084 /* initialisation/exit functions */ 20085 20086 int __init nl80211_init(void) 20087 { 20088 int err; 20089 20090 err = genl_register_family(&nl80211_fam); 20091 if (err) 20092 return err; 20093 20094 err = netlink_register_notifier(&nl80211_netlink_notifier); 20095 if (err) 20096 goto err_out; 20097 20098 return 0; 20099 err_out: 20100 genl_unregister_family(&nl80211_fam); 20101 return err; 20102 } 20103 20104 void nl80211_exit(void) 20105 { 20106 netlink_unregister_notifier(&nl80211_netlink_notifier); 20107 genl_unregister_family(&nl80211_fam); 20108 } 20109