1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * mac80211 configuration hooks for cfg80211 4 * 5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> 6 * Copyright 2013-2015 Intel Mobile Communications GmbH 7 * Copyright (C) 2015-2017 Intel Deutschland GmbH 8 * Copyright (C) 2018-2022 Intel Corporation 9 */ 10 11 #include <linux/ieee80211.h> 12 #include <linux/nl80211.h> 13 #include <linux/rtnetlink.h> 14 #include <linux/slab.h> 15 #include <net/net_namespace.h> 16 #include <linux/rcupdate.h> 17 #include <linux/fips.h> 18 #include <linux/if_ether.h> 19 #include <net/cfg80211.h> 20 #include "ieee80211_i.h" 21 #include "driver-ops.h" 22 #include "rate.h" 23 #include "mesh.h" 24 #include "wme.h" 25 26 static struct ieee80211_link_data * 27 ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id, 28 bool require_valid) 29 { 30 struct ieee80211_link_data *link; 31 32 if (link_id < 0) { 33 /* 34 * For keys, if sdata is not an MLD, we might not use 35 * the return value at all (if it's not a pairwise key), 36 * so in that case (require_valid==false) don't error. 37 */ 38 if (require_valid && sdata->vif.valid_links) 39 return ERR_PTR(-EINVAL); 40 41 return &sdata->deflink; 42 } 43 44 link = sdata_dereference(sdata->link[link_id], sdata); 45 if (!link) 46 return ERR_PTR(-ENOLINK); 47 return link; 48 } 49 50 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata, 51 struct vif_params *params) 52 { 53 bool mu_mimo_groups = false; 54 bool mu_mimo_follow = false; 55 56 if (params->vht_mumimo_groups) { 57 u64 membership; 58 59 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN); 60 61 memcpy(sdata->vif.bss_conf.mu_group.membership, 62 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN); 63 memcpy(sdata->vif.bss_conf.mu_group.position, 64 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN, 65 WLAN_USER_POSITION_LEN); 66 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 67 BSS_CHANGED_MU_GROUPS); 68 /* don't care about endianness - just check for 0 */ 69 memcpy(&membership, params->vht_mumimo_groups, 70 WLAN_MEMBERSHIP_LEN); 71 mu_mimo_groups = membership != 0; 72 } 73 74 if (params->vht_mumimo_follow_addr) { 75 mu_mimo_follow = 76 is_valid_ether_addr(params->vht_mumimo_follow_addr); 77 ether_addr_copy(sdata->u.mntr.mu_follow_addr, 78 params->vht_mumimo_follow_addr); 79 } 80 81 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; 82 } 83 84 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata, 85 struct vif_params *params) 86 { 87 struct ieee80211_local *local = sdata->local; 88 struct ieee80211_sub_if_data *monitor_sdata; 89 90 /* check flags first */ 91 if (params->flags && ieee80211_sdata_running(sdata)) { 92 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE; 93 94 /* 95 * Prohibit MONITOR_FLAG_COOK_FRAMES and 96 * MONITOR_FLAG_ACTIVE to be changed while the 97 * interface is up. 98 * Else we would need to add a lot of cruft 99 * to update everything: 100 * cooked_mntrs, monitor and all fif_* counters 101 * reconfigure hardware 102 */ 103 if ((params->flags & mask) != (sdata->u.mntr.flags & mask)) 104 return -EBUSY; 105 } 106 107 /* also validate MU-MIMO change */ 108 monitor_sdata = wiphy_dereference(local->hw.wiphy, 109 local->monitor_sdata); 110 111 if (!monitor_sdata && 112 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr)) 113 return -EOPNOTSUPP; 114 115 /* apply all changes now - no failures allowed */ 116 117 if (monitor_sdata) 118 ieee80211_set_mu_mimo_follow(monitor_sdata, params); 119 120 if (params->flags) { 121 if (ieee80211_sdata_running(sdata)) { 122 ieee80211_adjust_monitor_flags(sdata, -1); 123 sdata->u.mntr.flags = params->flags; 124 ieee80211_adjust_monitor_flags(sdata, 1); 125 126 ieee80211_configure_filter(local); 127 } else { 128 /* 129 * Because the interface is down, ieee80211_do_stop 130 * and ieee80211_do_open take care of "everything" 131 * mentioned in the comment above. 132 */ 133 sdata->u.mntr.flags = params->flags; 134 } 135 } 136 137 return 0; 138 } 139 140 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata, 141 struct cfg80211_mbssid_config params, 142 struct ieee80211_bss_conf *link_conf) 143 { 144 struct ieee80211_sub_if_data *tx_sdata; 145 146 sdata->vif.mbssid_tx_vif = NULL; 147 link_conf->bssid_index = 0; 148 link_conf->nontransmitted = false; 149 link_conf->ema_ap = false; 150 link_conf->bssid_indicator = 0; 151 152 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev) 153 return -EINVAL; 154 155 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev); 156 if (!tx_sdata) 157 return -EINVAL; 158 159 if (tx_sdata == sdata) { 160 sdata->vif.mbssid_tx_vif = &sdata->vif; 161 } else { 162 sdata->vif.mbssid_tx_vif = &tx_sdata->vif; 163 link_conf->nontransmitted = true; 164 link_conf->bssid_index = params.index; 165 } 166 if (params.ema) 167 link_conf->ema_ap = true; 168 169 return 0; 170 } 171 172 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, 173 const char *name, 174 unsigned char name_assign_type, 175 enum nl80211_iftype type, 176 struct vif_params *params) 177 { 178 struct ieee80211_local *local = wiphy_priv(wiphy); 179 struct wireless_dev *wdev; 180 struct ieee80211_sub_if_data *sdata; 181 int err; 182 183 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params); 184 if (err) 185 return ERR_PTR(err); 186 187 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 188 189 if (type == NL80211_IFTYPE_MONITOR) { 190 err = ieee80211_set_mon_options(sdata, params); 191 if (err) { 192 ieee80211_if_remove(sdata); 193 return NULL; 194 } 195 } 196 197 return wdev; 198 } 199 200 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) 201 { 202 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev)); 203 204 return 0; 205 } 206 207 static int ieee80211_change_iface(struct wiphy *wiphy, 208 struct net_device *dev, 209 enum nl80211_iftype type, 210 struct vif_params *params) 211 { 212 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 213 struct ieee80211_local *local = sdata->local; 214 struct sta_info *sta; 215 int ret; 216 217 ret = ieee80211_if_change_type(sdata, type); 218 if (ret) 219 return ret; 220 221 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) { 222 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); 223 ieee80211_check_fast_rx_iface(sdata); 224 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) { 225 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 226 227 if (params->use_4addr == ifmgd->use_4addr) 228 return 0; 229 230 /* FIXME: no support for 4-addr MLO yet */ 231 if (sdata->vif.valid_links) 232 return -EOPNOTSUPP; 233 234 sdata->u.mgd.use_4addr = params->use_4addr; 235 if (!ifmgd->associated) 236 return 0; 237 238 mutex_lock(&local->sta_mtx); 239 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid); 240 if (sta) 241 drv_sta_set_4addr(local, sdata, &sta->sta, 242 params->use_4addr); 243 mutex_unlock(&local->sta_mtx); 244 245 if (params->use_4addr) 246 ieee80211_send_4addr_nullfunc(local, sdata); 247 } 248 249 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { 250 ret = ieee80211_set_mon_options(sdata, params); 251 if (ret) 252 return ret; 253 } 254 255 return 0; 256 } 257 258 static int ieee80211_start_p2p_device(struct wiphy *wiphy, 259 struct wireless_dev *wdev) 260 { 261 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 262 int ret; 263 264 mutex_lock(&sdata->local->chanctx_mtx); 265 ret = ieee80211_check_combinations(sdata, NULL, 0, 0); 266 mutex_unlock(&sdata->local->chanctx_mtx); 267 if (ret < 0) 268 return ret; 269 270 return ieee80211_do_open(wdev, true); 271 } 272 273 static void ieee80211_stop_p2p_device(struct wiphy *wiphy, 274 struct wireless_dev *wdev) 275 { 276 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev)); 277 } 278 279 static int ieee80211_start_nan(struct wiphy *wiphy, 280 struct wireless_dev *wdev, 281 struct cfg80211_nan_conf *conf) 282 { 283 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 284 int ret; 285 286 mutex_lock(&sdata->local->chanctx_mtx); 287 ret = ieee80211_check_combinations(sdata, NULL, 0, 0); 288 mutex_unlock(&sdata->local->chanctx_mtx); 289 if (ret < 0) 290 return ret; 291 292 ret = ieee80211_do_open(wdev, true); 293 if (ret) 294 return ret; 295 296 ret = drv_start_nan(sdata->local, sdata, conf); 297 if (ret) 298 ieee80211_sdata_stop(sdata); 299 300 sdata->u.nan.conf = *conf; 301 302 return ret; 303 } 304 305 static void ieee80211_stop_nan(struct wiphy *wiphy, 306 struct wireless_dev *wdev) 307 { 308 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 309 310 drv_stop_nan(sdata->local, sdata); 311 ieee80211_sdata_stop(sdata); 312 } 313 314 static int ieee80211_nan_change_conf(struct wiphy *wiphy, 315 struct wireless_dev *wdev, 316 struct cfg80211_nan_conf *conf, 317 u32 changes) 318 { 319 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 320 struct cfg80211_nan_conf new_conf; 321 int ret = 0; 322 323 if (sdata->vif.type != NL80211_IFTYPE_NAN) 324 return -EOPNOTSUPP; 325 326 if (!ieee80211_sdata_running(sdata)) 327 return -ENETDOWN; 328 329 new_conf = sdata->u.nan.conf; 330 331 if (changes & CFG80211_NAN_CONF_CHANGED_PREF) 332 new_conf.master_pref = conf->master_pref; 333 334 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) 335 new_conf.bands = conf->bands; 336 337 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes); 338 if (!ret) 339 sdata->u.nan.conf = new_conf; 340 341 return ret; 342 } 343 344 static int ieee80211_add_nan_func(struct wiphy *wiphy, 345 struct wireless_dev *wdev, 346 struct cfg80211_nan_func *nan_func) 347 { 348 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 349 int ret; 350 351 if (sdata->vif.type != NL80211_IFTYPE_NAN) 352 return -EOPNOTSUPP; 353 354 if (!ieee80211_sdata_running(sdata)) 355 return -ENETDOWN; 356 357 spin_lock_bh(&sdata->u.nan.func_lock); 358 359 ret = idr_alloc(&sdata->u.nan.function_inst_ids, 360 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1, 361 GFP_ATOMIC); 362 spin_unlock_bh(&sdata->u.nan.func_lock); 363 364 if (ret < 0) 365 return ret; 366 367 nan_func->instance_id = ret; 368 369 WARN_ON(nan_func->instance_id == 0); 370 371 ret = drv_add_nan_func(sdata->local, sdata, nan_func); 372 if (ret) { 373 spin_lock_bh(&sdata->u.nan.func_lock); 374 idr_remove(&sdata->u.nan.function_inst_ids, 375 nan_func->instance_id); 376 spin_unlock_bh(&sdata->u.nan.func_lock); 377 } 378 379 return ret; 380 } 381 382 static struct cfg80211_nan_func * 383 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata, 384 u64 cookie) 385 { 386 struct cfg80211_nan_func *func; 387 int id; 388 389 lockdep_assert_held(&sdata->u.nan.func_lock); 390 391 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) { 392 if (func->cookie == cookie) 393 return func; 394 } 395 396 return NULL; 397 } 398 399 static void ieee80211_del_nan_func(struct wiphy *wiphy, 400 struct wireless_dev *wdev, u64 cookie) 401 { 402 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 403 struct cfg80211_nan_func *func; 404 u8 instance_id = 0; 405 406 if (sdata->vif.type != NL80211_IFTYPE_NAN || 407 !ieee80211_sdata_running(sdata)) 408 return; 409 410 spin_lock_bh(&sdata->u.nan.func_lock); 411 412 func = ieee80211_find_nan_func_by_cookie(sdata, cookie); 413 if (func) 414 instance_id = func->instance_id; 415 416 spin_unlock_bh(&sdata->u.nan.func_lock); 417 418 if (instance_id) 419 drv_del_nan_func(sdata->local, sdata, instance_id); 420 } 421 422 static int ieee80211_set_noack_map(struct wiphy *wiphy, 423 struct net_device *dev, 424 u16 noack_map) 425 { 426 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 427 428 sdata->noack_map = noack_map; 429 430 ieee80211_check_fast_xmit_iface(sdata); 431 432 return 0; 433 } 434 435 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata, 436 const u8 *mac_addr, u8 key_idx) 437 { 438 struct ieee80211_local *local = sdata->local; 439 struct ieee80211_key *key; 440 struct sta_info *sta; 441 int ret = -EINVAL; 442 443 if (!wiphy_ext_feature_isset(local->hw.wiphy, 444 NL80211_EXT_FEATURE_EXT_KEY_ID)) 445 return -EINVAL; 446 447 sta = sta_info_get_bss(sdata, mac_addr); 448 449 if (!sta) 450 return -EINVAL; 451 452 if (sta->ptk_idx == key_idx) 453 return 0; 454 455 mutex_lock(&local->key_mtx); 456 key = key_mtx_dereference(local, sta->ptk[key_idx]); 457 458 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX) 459 ret = ieee80211_set_tx_key(key); 460 461 mutex_unlock(&local->key_mtx); 462 return ret; 463 } 464 465 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, 466 int link_id, u8 key_idx, bool pairwise, 467 const u8 *mac_addr, struct key_params *params) 468 { 469 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 470 struct ieee80211_link_data *link = 471 ieee80211_link_or_deflink(sdata, link_id, false); 472 struct ieee80211_local *local = sdata->local; 473 struct sta_info *sta = NULL; 474 struct ieee80211_key *key; 475 int err; 476 477 if (!ieee80211_sdata_running(sdata)) 478 return -ENETDOWN; 479 480 if (IS_ERR(link)) 481 return PTR_ERR(link); 482 483 if (pairwise && params->mode == NL80211_KEY_SET_TX) 484 return ieee80211_set_tx(sdata, mac_addr, key_idx); 485 486 /* reject WEP and TKIP keys if WEP failed to initialize */ 487 switch (params->cipher) { 488 case WLAN_CIPHER_SUITE_WEP40: 489 case WLAN_CIPHER_SUITE_TKIP: 490 case WLAN_CIPHER_SUITE_WEP104: 491 if (link_id >= 0) 492 return -EINVAL; 493 if (WARN_ON_ONCE(fips_enabled)) 494 return -EINVAL; 495 break; 496 default: 497 break; 498 } 499 500 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, 501 params->key, params->seq_len, params->seq); 502 if (IS_ERR(key)) 503 return PTR_ERR(key); 504 505 key->conf.link_id = link_id; 506 507 if (pairwise) 508 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; 509 510 if (params->mode == NL80211_KEY_NO_TX) 511 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX; 512 513 mutex_lock(&local->sta_mtx); 514 515 if (mac_addr) { 516 sta = sta_info_get_bss(sdata, mac_addr); 517 /* 518 * The ASSOC test makes sure the driver is ready to 519 * receive the key. When wpa_supplicant has roamed 520 * using FT, it attempts to set the key before 521 * association has completed, this rejects that attempt 522 * so it will set the key again after association. 523 * 524 * TODO: accept the key if we have a station entry and 525 * add it to the device after the station. 526 */ 527 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) { 528 ieee80211_key_free_unused(key); 529 err = -ENOENT; 530 goto out_unlock; 531 } 532 } 533 534 switch (sdata->vif.type) { 535 case NL80211_IFTYPE_STATION: 536 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) 537 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; 538 break; 539 case NL80211_IFTYPE_AP: 540 case NL80211_IFTYPE_AP_VLAN: 541 /* Keys without a station are used for TX only */ 542 if (sta && test_sta_flag(sta, WLAN_STA_MFP)) 543 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; 544 break; 545 case NL80211_IFTYPE_ADHOC: 546 /* no MFP (yet) */ 547 break; 548 case NL80211_IFTYPE_MESH_POINT: 549 #ifdef CONFIG_MAC80211_MESH 550 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) 551 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; 552 break; 553 #endif 554 case NL80211_IFTYPE_WDS: 555 case NL80211_IFTYPE_MONITOR: 556 case NL80211_IFTYPE_P2P_DEVICE: 557 case NL80211_IFTYPE_NAN: 558 case NL80211_IFTYPE_UNSPECIFIED: 559 case NUM_NL80211_IFTYPES: 560 case NL80211_IFTYPE_P2P_CLIENT: 561 case NL80211_IFTYPE_P2P_GO: 562 case NL80211_IFTYPE_OCB: 563 /* shouldn't happen */ 564 WARN_ON_ONCE(1); 565 break; 566 } 567 568 err = ieee80211_key_link(key, link, sta); 569 570 out_unlock: 571 mutex_unlock(&local->sta_mtx); 572 573 return err; 574 } 575 576 static struct ieee80211_key * 577 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, 578 u8 key_idx, bool pairwise, const u8 *mac_addr) 579 { 580 struct ieee80211_local *local __maybe_unused = sdata->local; 581 struct ieee80211_link_data *link = &sdata->deflink; 582 struct ieee80211_key *key; 583 584 if (link_id >= 0) { 585 link = rcu_dereference_check(sdata->link[link_id], 586 lockdep_is_held(&sdata->wdev.mtx)); 587 if (!link) 588 return NULL; 589 } 590 591 if (mac_addr) { 592 struct sta_info *sta; 593 struct link_sta_info *link_sta; 594 595 sta = sta_info_get_bss(sdata, mac_addr); 596 if (!sta) 597 return NULL; 598 599 if (link_id >= 0) { 600 link_sta = rcu_dereference_check(sta->link[link_id], 601 lockdep_is_held(&local->sta_mtx)); 602 if (!link_sta) 603 return NULL; 604 } else { 605 link_sta = &sta->deflink; 606 } 607 608 if (pairwise && key_idx < NUM_DEFAULT_KEYS) 609 return rcu_dereference_check_key_mtx(local, 610 sta->ptk[key_idx]); 611 612 if (!pairwise && 613 key_idx < NUM_DEFAULT_KEYS + 614 NUM_DEFAULT_MGMT_KEYS + 615 NUM_DEFAULT_BEACON_KEYS) 616 return rcu_dereference_check_key_mtx(local, 617 link_sta->gtk[key_idx]); 618 619 return NULL; 620 } 621 622 if (pairwise && key_idx < NUM_DEFAULT_KEYS) 623 return rcu_dereference_check_key_mtx(local, 624 sdata->keys[key_idx]); 625 626 key = rcu_dereference_check_key_mtx(local, link->gtk[key_idx]); 627 if (key) 628 return key; 629 630 /* or maybe it was a WEP key */ 631 if (key_idx < NUM_DEFAULT_KEYS) 632 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]); 633 634 return NULL; 635 } 636 637 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, 638 int link_id, u8 key_idx, bool pairwise, 639 const u8 *mac_addr) 640 { 641 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 642 struct ieee80211_local *local = sdata->local; 643 struct ieee80211_key *key; 644 int ret; 645 646 mutex_lock(&local->sta_mtx); 647 mutex_lock(&local->key_mtx); 648 649 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); 650 if (!key) { 651 ret = -ENOENT; 652 goto out_unlock; 653 } 654 655 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION); 656 657 ret = 0; 658 out_unlock: 659 mutex_unlock(&local->key_mtx); 660 mutex_unlock(&local->sta_mtx); 661 662 return ret; 663 } 664 665 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, 666 int link_id, u8 key_idx, bool pairwise, 667 const u8 *mac_addr, void *cookie, 668 void (*callback)(void *cookie, 669 struct key_params *params)) 670 { 671 struct ieee80211_sub_if_data *sdata; 672 u8 seq[6] = {0}; 673 struct key_params params; 674 struct ieee80211_key *key; 675 u64 pn64; 676 u32 iv32; 677 u16 iv16; 678 int err = -ENOENT; 679 struct ieee80211_key_seq kseq = {}; 680 681 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 682 683 rcu_read_lock(); 684 685 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); 686 if (!key) 687 goto out; 688 689 memset(¶ms, 0, sizeof(params)); 690 691 params.cipher = key->conf.cipher; 692 693 switch (key->conf.cipher) { 694 case WLAN_CIPHER_SUITE_TKIP: 695 pn64 = atomic64_read(&key->conf.tx_pn); 696 iv32 = TKIP_PN_TO_IV32(pn64); 697 iv16 = TKIP_PN_TO_IV16(pn64); 698 699 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && 700 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { 701 drv_get_key_seq(sdata->local, key, &kseq); 702 iv32 = kseq.tkip.iv32; 703 iv16 = kseq.tkip.iv16; 704 } 705 706 seq[0] = iv16 & 0xff; 707 seq[1] = (iv16 >> 8) & 0xff; 708 seq[2] = iv32 & 0xff; 709 seq[3] = (iv32 >> 8) & 0xff; 710 seq[4] = (iv32 >> 16) & 0xff; 711 seq[5] = (iv32 >> 24) & 0xff; 712 params.seq = seq; 713 params.seq_len = 6; 714 break; 715 case WLAN_CIPHER_SUITE_CCMP: 716 case WLAN_CIPHER_SUITE_CCMP_256: 717 case WLAN_CIPHER_SUITE_AES_CMAC: 718 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 719 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != 720 offsetof(typeof(kseq), aes_cmac)); 721 fallthrough; 722 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 723 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 724 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != 725 offsetof(typeof(kseq), aes_gmac)); 726 fallthrough; 727 case WLAN_CIPHER_SUITE_GCMP: 728 case WLAN_CIPHER_SUITE_GCMP_256: 729 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != 730 offsetof(typeof(kseq), gcmp)); 731 732 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && 733 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { 734 drv_get_key_seq(sdata->local, key, &kseq); 735 memcpy(seq, kseq.ccmp.pn, 6); 736 } else { 737 pn64 = atomic64_read(&key->conf.tx_pn); 738 seq[0] = pn64; 739 seq[1] = pn64 >> 8; 740 seq[2] = pn64 >> 16; 741 seq[3] = pn64 >> 24; 742 seq[4] = pn64 >> 32; 743 seq[5] = pn64 >> 40; 744 } 745 params.seq = seq; 746 params.seq_len = 6; 747 break; 748 default: 749 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 750 break; 751 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) 752 break; 753 drv_get_key_seq(sdata->local, key, &kseq); 754 params.seq = kseq.hw.seq; 755 params.seq_len = kseq.hw.seq_len; 756 break; 757 } 758 759 params.key = key->conf.key; 760 params.key_len = key->conf.keylen; 761 762 callback(cookie, ¶ms); 763 err = 0; 764 765 out: 766 rcu_read_unlock(); 767 return err; 768 } 769 770 static int ieee80211_config_default_key(struct wiphy *wiphy, 771 struct net_device *dev, 772 int link_id, u8 key_idx, bool uni, 773 bool multi) 774 { 775 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 776 struct ieee80211_link_data *link = 777 ieee80211_link_or_deflink(sdata, link_id, false); 778 779 if (IS_ERR(link)) 780 return PTR_ERR(link); 781 782 ieee80211_set_default_key(link, key_idx, uni, multi); 783 784 return 0; 785 } 786 787 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, 788 struct net_device *dev, 789 int link_id, u8 key_idx) 790 { 791 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 792 struct ieee80211_link_data *link = 793 ieee80211_link_or_deflink(sdata, link_id, true); 794 795 if (IS_ERR(link)) 796 return PTR_ERR(link); 797 798 ieee80211_set_default_mgmt_key(link, key_idx); 799 800 return 0; 801 } 802 803 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy, 804 struct net_device *dev, 805 int link_id, u8 key_idx) 806 { 807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 808 struct ieee80211_link_data *link = 809 ieee80211_link_or_deflink(sdata, link_id, true); 810 811 if (IS_ERR(link)) 812 return PTR_ERR(link); 813 814 ieee80211_set_default_beacon_key(link, key_idx); 815 816 return 0; 817 } 818 819 void sta_set_rate_info_tx(struct sta_info *sta, 820 const struct ieee80211_tx_rate *rate, 821 struct rate_info *rinfo) 822 { 823 rinfo->flags = 0; 824 if (rate->flags & IEEE80211_TX_RC_MCS) { 825 rinfo->flags |= RATE_INFO_FLAGS_MCS; 826 rinfo->mcs = rate->idx; 827 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) { 828 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 829 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate); 830 rinfo->nss = ieee80211_rate_get_vht_nss(rate); 831 } else { 832 struct ieee80211_supported_band *sband; 833 int shift = ieee80211_vif_get_shift(&sta->sdata->vif); 834 u16 brate; 835 836 sband = ieee80211_get_sband(sta->sdata); 837 WARN_ON_ONCE(sband && !sband->bitrates); 838 if (sband && sband->bitrates) { 839 brate = sband->bitrates[rate->idx].bitrate; 840 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift); 841 } 842 } 843 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) 844 rinfo->bw = RATE_INFO_BW_40; 845 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) 846 rinfo->bw = RATE_INFO_BW_80; 847 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) 848 rinfo->bw = RATE_INFO_BW_160; 849 else 850 rinfo->bw = RATE_INFO_BW_20; 851 if (rate->flags & IEEE80211_TX_RC_SHORT_GI) 852 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 853 } 854 855 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, 856 int idx, u8 *mac, struct station_info *sinfo) 857 { 858 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 859 struct ieee80211_local *local = sdata->local; 860 struct sta_info *sta; 861 int ret = -ENOENT; 862 863 mutex_lock(&local->sta_mtx); 864 865 sta = sta_info_get_by_idx(sdata, idx); 866 if (sta) { 867 ret = 0; 868 memcpy(mac, sta->sta.addr, ETH_ALEN); 869 sta_set_sinfo(sta, sinfo, true); 870 } 871 872 mutex_unlock(&local->sta_mtx); 873 874 return ret; 875 } 876 877 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, 878 int idx, struct survey_info *survey) 879 { 880 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 881 882 return drv_get_survey(local, idx, survey); 883 } 884 885 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, 886 const u8 *mac, struct station_info *sinfo) 887 { 888 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 889 struct ieee80211_local *local = sdata->local; 890 struct sta_info *sta; 891 int ret = -ENOENT; 892 893 mutex_lock(&local->sta_mtx); 894 895 sta = sta_info_get_bss(sdata, mac); 896 if (sta) { 897 ret = 0; 898 sta_set_sinfo(sta, sinfo, true); 899 } 900 901 mutex_unlock(&local->sta_mtx); 902 903 return ret; 904 } 905 906 static int ieee80211_set_monitor_channel(struct wiphy *wiphy, 907 struct cfg80211_chan_def *chandef) 908 { 909 struct ieee80211_local *local = wiphy_priv(wiphy); 910 struct ieee80211_sub_if_data *sdata; 911 int ret = 0; 912 913 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef)) 914 return 0; 915 916 mutex_lock(&local->mtx); 917 if (local->use_chanctx) { 918 sdata = wiphy_dereference(local->hw.wiphy, 919 local->monitor_sdata); 920 if (sdata) { 921 ieee80211_link_release_channel(&sdata->deflink); 922 ret = ieee80211_link_use_channel(&sdata->deflink, 923 chandef, 924 IEEE80211_CHANCTX_EXCLUSIVE); 925 } 926 } else if (local->open_count == local->monitors) { 927 local->_oper_chandef = *chandef; 928 ieee80211_hw_config(local, 0); 929 } 930 931 if (ret == 0) 932 local->monitor_chandef = *chandef; 933 mutex_unlock(&local->mtx); 934 935 return ret; 936 } 937 938 static int 939 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, 940 const u8 *resp, size_t resp_len, 941 const struct ieee80211_csa_settings *csa, 942 const struct ieee80211_color_change_settings *cca, 943 struct ieee80211_link_data *link) 944 { 945 struct probe_resp *new, *old; 946 947 if (!resp || !resp_len) 948 return 1; 949 950 old = sdata_dereference(link->u.ap.probe_resp, sdata); 951 952 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL); 953 if (!new) 954 return -ENOMEM; 955 956 new->len = resp_len; 957 memcpy(new->data, resp, resp_len); 958 959 if (csa) 960 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp, 961 csa->n_counter_offsets_presp * 962 sizeof(new->cntdwn_counter_offsets[0])); 963 else if (cca) 964 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp; 965 966 rcu_assign_pointer(link->u.ap.probe_resp, new); 967 if (old) 968 kfree_rcu(old, rcu_head); 969 970 return 0; 971 } 972 973 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, 974 struct cfg80211_fils_discovery *params, 975 struct ieee80211_link_data *link, 976 struct ieee80211_bss_conf *link_conf) 977 { 978 struct fils_discovery_data *new, *old = NULL; 979 struct ieee80211_fils_discovery *fd; 980 981 if (!params->tmpl || !params->tmpl_len) 982 return -EINVAL; 983 984 fd = &link_conf->fils_discovery; 985 fd->min_interval = params->min_interval; 986 fd->max_interval = params->max_interval; 987 988 old = sdata_dereference(link->u.ap.fils_discovery, sdata); 989 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); 990 if (!new) 991 return -ENOMEM; 992 new->len = params->tmpl_len; 993 memcpy(new->data, params->tmpl, params->tmpl_len); 994 rcu_assign_pointer(link->u.ap.fils_discovery, new); 995 996 if (old) 997 kfree_rcu(old, rcu_head); 998 999 return 0; 1000 } 1001 1002 static int 1003 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, 1004 struct cfg80211_unsol_bcast_probe_resp *params, 1005 struct ieee80211_link_data *link, 1006 struct ieee80211_bss_conf *link_conf) 1007 { 1008 struct unsol_bcast_probe_resp_data *new, *old = NULL; 1009 1010 if (!params->tmpl || !params->tmpl_len) 1011 return -EINVAL; 1012 1013 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata); 1014 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); 1015 if (!new) 1016 return -ENOMEM; 1017 new->len = params->tmpl_len; 1018 memcpy(new->data, params->tmpl, params->tmpl_len); 1019 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new); 1020 1021 if (old) 1022 kfree_rcu(old, rcu_head); 1023 1024 link_conf->unsol_bcast_probe_resp_interval = params->interval; 1025 1026 return 0; 1027 } 1028 1029 static int ieee80211_set_ftm_responder_params( 1030 struct ieee80211_sub_if_data *sdata, 1031 const u8 *lci, size_t lci_len, 1032 const u8 *civicloc, size_t civicloc_len, 1033 struct ieee80211_bss_conf *link_conf) 1034 { 1035 struct ieee80211_ftm_responder_params *new, *old; 1036 u8 *pos; 1037 int len; 1038 1039 if (!lci_len && !civicloc_len) 1040 return 0; 1041 1042 old = link_conf->ftmr_params; 1043 len = lci_len + civicloc_len; 1044 1045 new = kzalloc(sizeof(*new) + len, GFP_KERNEL); 1046 if (!new) 1047 return -ENOMEM; 1048 1049 pos = (u8 *)(new + 1); 1050 if (lci_len) { 1051 new->lci_len = lci_len; 1052 new->lci = pos; 1053 memcpy(pos, lci, lci_len); 1054 pos += lci_len; 1055 } 1056 1057 if (civicloc_len) { 1058 new->civicloc_len = civicloc_len; 1059 new->civicloc = pos; 1060 memcpy(pos, civicloc, civicloc_len); 1061 pos += civicloc_len; 1062 } 1063 1064 link_conf->ftmr_params = new; 1065 kfree(old); 1066 1067 return 0; 1068 } 1069 1070 static int 1071 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst, 1072 struct cfg80211_mbssid_elems *src) 1073 { 1074 int i, offset = 0; 1075 1076 for (i = 0; i < src->cnt; i++) { 1077 memcpy(pos + offset, src->elem[i].data, src->elem[i].len); 1078 dst->elem[i].len = src->elem[i].len; 1079 dst->elem[i].data = pos + offset; 1080 offset += dst->elem[i].len; 1081 } 1082 dst->cnt = src->cnt; 1083 1084 return offset; 1085 } 1086 1087 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, 1088 struct ieee80211_link_data *link, 1089 struct cfg80211_beacon_data *params, 1090 const struct ieee80211_csa_settings *csa, 1091 const struct ieee80211_color_change_settings *cca) 1092 { 1093 struct cfg80211_mbssid_elems *mbssid = NULL; 1094 struct beacon_data *new, *old; 1095 int new_head_len, new_tail_len; 1096 int size, err; 1097 u32 changed = BSS_CHANGED_BEACON; 1098 struct ieee80211_bss_conf *link_conf = link->conf; 1099 1100 old = sdata_dereference(link->u.ap.beacon, sdata); 1101 1102 /* Need to have a beacon head if we don't have one yet */ 1103 if (!params->head && !old) 1104 return -EINVAL; 1105 1106 /* new or old head? */ 1107 if (params->head) 1108 new_head_len = params->head_len; 1109 else 1110 new_head_len = old->head_len; 1111 1112 /* new or old tail? */ 1113 if (params->tail || !old) 1114 /* params->tail_len will be zero for !params->tail */ 1115 new_tail_len = params->tail_len; 1116 else 1117 new_tail_len = old->tail_len; 1118 1119 size = sizeof(*new) + new_head_len + new_tail_len; 1120 1121 /* new or old multiple BSSID elements? */ 1122 if (params->mbssid_ies) { 1123 mbssid = params->mbssid_ies; 1124 size += struct_size(new->mbssid_ies, elem, mbssid->cnt); 1125 size += ieee80211_get_mbssid_beacon_len(mbssid); 1126 } else if (old && old->mbssid_ies) { 1127 mbssid = old->mbssid_ies; 1128 size += struct_size(new->mbssid_ies, elem, mbssid->cnt); 1129 size += ieee80211_get_mbssid_beacon_len(mbssid); 1130 } 1131 1132 new = kzalloc(size, GFP_KERNEL); 1133 if (!new) 1134 return -ENOMEM; 1135 1136 /* start filling the new info now */ 1137 1138 /* 1139 * pointers go into the block we allocated, 1140 * memory is | beacon_data | head | tail | mbssid_ies 1141 */ 1142 new->head = ((u8 *) new) + sizeof(*new); 1143 new->tail = new->head + new_head_len; 1144 new->head_len = new_head_len; 1145 new->tail_len = new_tail_len; 1146 /* copy in optional mbssid_ies */ 1147 if (mbssid) { 1148 u8 *pos = new->tail + new->tail_len; 1149 1150 new->mbssid_ies = (void *)pos; 1151 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt); 1152 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid); 1153 /* update bssid_indicator */ 1154 link_conf->bssid_indicator = 1155 ilog2(__roundup_pow_of_two(mbssid->cnt + 1)); 1156 } 1157 1158 if (csa) { 1159 new->cntdwn_current_counter = csa->count; 1160 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon, 1161 csa->n_counter_offsets_beacon * 1162 sizeof(new->cntdwn_counter_offsets[0])); 1163 } else if (cca) { 1164 new->cntdwn_current_counter = cca->count; 1165 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon; 1166 } 1167 1168 /* copy in head */ 1169 if (params->head) 1170 memcpy(new->head, params->head, new_head_len); 1171 else 1172 memcpy(new->head, old->head, new_head_len); 1173 1174 /* copy in optional tail */ 1175 if (params->tail) 1176 memcpy(new->tail, params->tail, new_tail_len); 1177 else 1178 if (old) 1179 memcpy(new->tail, old->tail, new_tail_len); 1180 1181 err = ieee80211_set_probe_resp(sdata, params->probe_resp, 1182 params->probe_resp_len, csa, cca, link); 1183 if (err < 0) { 1184 kfree(new); 1185 return err; 1186 } 1187 if (err == 0) 1188 changed |= BSS_CHANGED_AP_PROBE_RESP; 1189 1190 if (params->ftm_responder != -1) { 1191 link_conf->ftm_responder = params->ftm_responder; 1192 err = ieee80211_set_ftm_responder_params(sdata, 1193 params->lci, 1194 params->lci_len, 1195 params->civicloc, 1196 params->civicloc_len, 1197 link_conf); 1198 1199 if (err < 0) { 1200 kfree(new); 1201 return err; 1202 } 1203 1204 changed |= BSS_CHANGED_FTM_RESPONDER; 1205 } 1206 1207 rcu_assign_pointer(link->u.ap.beacon, new); 1208 sdata->u.ap.active = true; 1209 1210 if (old) 1211 kfree_rcu(old, rcu_head); 1212 1213 return changed; 1214 } 1215 1216 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, 1217 struct cfg80211_ap_settings *params) 1218 { 1219 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1220 struct ieee80211_local *local = sdata->local; 1221 struct beacon_data *old; 1222 struct ieee80211_sub_if_data *vlan; 1223 u32 changed = BSS_CHANGED_BEACON_INT | 1224 BSS_CHANGED_BEACON_ENABLED | 1225 BSS_CHANGED_BEACON | 1226 BSS_CHANGED_P2P_PS | 1227 BSS_CHANGED_TXPOWER | 1228 BSS_CHANGED_TWT; 1229 int i, err; 1230 int prev_beacon_int; 1231 unsigned int link_id = params->beacon.link_id; 1232 struct ieee80211_link_data *link; 1233 struct ieee80211_bss_conf *link_conf; 1234 1235 link = sdata_dereference(sdata->link[link_id], sdata); 1236 if (!link) 1237 return -ENOLINK; 1238 1239 link_conf = link->conf; 1240 1241 old = sdata_dereference(link->u.ap.beacon, sdata); 1242 if (old) 1243 return -EALREADY; 1244 1245 if (params->smps_mode != NL80211_SMPS_OFF) 1246 return -ENOTSUPP; 1247 1248 link->smps_mode = IEEE80211_SMPS_OFF; 1249 1250 link->needed_rx_chains = sdata->local->rx_chains; 1251 1252 prev_beacon_int = link_conf->beacon_int; 1253 link_conf->beacon_int = params->beacon_interval; 1254 1255 if (params->vht_cap) { 1256 link_conf->vht_su_beamformer = 1257 params->vht_cap->vht_cap_info & 1258 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); 1259 link_conf->vht_su_beamformee = 1260 params->vht_cap->vht_cap_info & 1261 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); 1262 link_conf->vht_mu_beamformer = 1263 params->vht_cap->vht_cap_info & 1264 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); 1265 link_conf->vht_mu_beamformee = 1266 params->vht_cap->vht_cap_info & 1267 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); 1268 } 1269 1270 if (params->he_cap && params->he_oper) { 1271 link_conf->he_support = true; 1272 link_conf->htc_trig_based_pkt_ext = 1273 le32_get_bits(params->he_oper->he_oper_params, 1274 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); 1275 link_conf->frame_time_rts_th = 1276 le32_get_bits(params->he_oper->he_oper_params, 1277 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); 1278 changed |= BSS_CHANGED_HE_OBSS_PD; 1279 1280 if (params->beacon.he_bss_color.enabled) 1281 changed |= BSS_CHANGED_HE_BSS_COLOR; 1282 } 1283 1284 if (params->he_cap) { 1285 link_conf->he_su_beamformer = 1286 params->he_cap->phy_cap_info[3] & 1287 IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER; 1288 link_conf->he_su_beamformee = 1289 params->he_cap->phy_cap_info[4] & 1290 IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE; 1291 link_conf->he_mu_beamformer = 1292 params->he_cap->phy_cap_info[4] & 1293 IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; 1294 link_conf->he_full_ul_mumimo = 1295 params->he_cap->phy_cap_info[2] & 1296 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO; 1297 } 1298 1299 if (sdata->vif.type == NL80211_IFTYPE_AP && 1300 params->mbssid_config.tx_wdev) { 1301 err = ieee80211_set_ap_mbssid_options(sdata, 1302 params->mbssid_config, 1303 link_conf); 1304 if (err) 1305 return err; 1306 } 1307 1308 mutex_lock(&local->mtx); 1309 err = ieee80211_link_use_channel(link, ¶ms->chandef, 1310 IEEE80211_CHANCTX_SHARED); 1311 if (!err) 1312 ieee80211_link_copy_chanctx_to_vlans(link, false); 1313 mutex_unlock(&local->mtx); 1314 if (err) { 1315 link_conf->beacon_int = prev_beacon_int; 1316 return err; 1317 } 1318 1319 /* 1320 * Apply control port protocol, this allows us to 1321 * not encrypt dynamic WEP control frames. 1322 */ 1323 sdata->control_port_protocol = params->crypto.control_port_ethertype; 1324 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; 1325 sdata->control_port_over_nl80211 = 1326 params->crypto.control_port_over_nl80211; 1327 sdata->control_port_no_preauth = 1328 params->crypto.control_port_no_preauth; 1329 1330 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { 1331 vlan->control_port_protocol = 1332 params->crypto.control_port_ethertype; 1333 vlan->control_port_no_encrypt = 1334 params->crypto.control_port_no_encrypt; 1335 vlan->control_port_over_nl80211 = 1336 params->crypto.control_port_over_nl80211; 1337 vlan->control_port_no_preauth = 1338 params->crypto.control_port_no_preauth; 1339 } 1340 1341 link_conf->dtim_period = params->dtim_period; 1342 link_conf->enable_beacon = true; 1343 link_conf->allow_p2p_go_ps = sdata->vif.p2p; 1344 link_conf->twt_responder = params->twt_responder; 1345 link_conf->he_obss_pd = params->he_obss_pd; 1346 link_conf->he_bss_color = params->beacon.he_bss_color; 1347 sdata->vif.cfg.s1g = params->chandef.chan->band == 1348 NL80211_BAND_S1GHZ; 1349 1350 sdata->vif.cfg.ssid_len = params->ssid_len; 1351 if (params->ssid_len) 1352 memcpy(sdata->vif.cfg.ssid, params->ssid, 1353 params->ssid_len); 1354 link_conf->hidden_ssid = 1355 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); 1356 1357 memset(&link_conf->p2p_noa_attr, 0, 1358 sizeof(link_conf->p2p_noa_attr)); 1359 link_conf->p2p_noa_attr.oppps_ctwindow = 1360 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; 1361 if (params->p2p_opp_ps) 1362 link_conf->p2p_noa_attr.oppps_ctwindow |= 1363 IEEE80211_P2P_OPPPS_ENABLE_BIT; 1364 1365 sdata->beacon_rate_set = false; 1366 if (wiphy_ext_feature_isset(local->hw.wiphy, 1367 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { 1368 for (i = 0; i < NUM_NL80211_BANDS; i++) { 1369 sdata->beacon_rateidx_mask[i] = 1370 params->beacon_rate.control[i].legacy; 1371 if (sdata->beacon_rateidx_mask[i]) 1372 sdata->beacon_rate_set = true; 1373 } 1374 } 1375 1376 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) 1377 link_conf->beacon_tx_rate = params->beacon_rate; 1378 1379 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL); 1380 if (err < 0) 1381 goto error; 1382 changed |= err; 1383 1384 if (params->fils_discovery.max_interval) { 1385 err = ieee80211_set_fils_discovery(sdata, 1386 ¶ms->fils_discovery, 1387 link, link_conf); 1388 if (err < 0) 1389 goto error; 1390 changed |= BSS_CHANGED_FILS_DISCOVERY; 1391 } 1392 1393 if (params->unsol_bcast_probe_resp.interval) { 1394 err = ieee80211_set_unsol_bcast_probe_resp(sdata, 1395 ¶ms->unsol_bcast_probe_resp, 1396 link, link_conf); 1397 if (err < 0) 1398 goto error; 1399 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP; 1400 } 1401 1402 err = drv_start_ap(sdata->local, sdata, link_conf); 1403 if (err) { 1404 old = sdata_dereference(link->u.ap.beacon, sdata); 1405 1406 if (old) 1407 kfree_rcu(old, rcu_head); 1408 RCU_INIT_POINTER(link->u.ap.beacon, NULL); 1409 sdata->u.ap.active = false; 1410 goto error; 1411 } 1412 1413 ieee80211_recalc_dtim(local, sdata); 1414 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID); 1415 ieee80211_link_info_change_notify(sdata, link, changed); 1416 1417 netif_carrier_on(dev); 1418 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1419 netif_carrier_on(vlan->dev); 1420 1421 return 0; 1422 1423 error: 1424 mutex_lock(&local->mtx); 1425 ieee80211_link_release_channel(link); 1426 mutex_unlock(&local->mtx); 1427 1428 return err; 1429 } 1430 1431 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, 1432 struct cfg80211_beacon_data *params) 1433 { 1434 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1435 struct ieee80211_link_data *link; 1436 struct beacon_data *old; 1437 int err; 1438 struct ieee80211_bss_conf *link_conf; 1439 1440 sdata_assert_lock(sdata); 1441 1442 link = sdata_dereference(sdata->link[params->link_id], sdata); 1443 if (!link) 1444 return -ENOLINK; 1445 1446 link_conf = link->conf; 1447 1448 /* don't allow changing the beacon while a countdown is in place - offset 1449 * of channel switch counter may change 1450 */ 1451 if (link_conf->csa_active || link_conf->color_change_active) 1452 return -EBUSY; 1453 1454 old = sdata_dereference(link->u.ap.beacon, sdata); 1455 if (!old) 1456 return -ENOENT; 1457 1458 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL); 1459 if (err < 0) 1460 return err; 1461 1462 if (params->he_bss_color_valid && 1463 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) { 1464 link_conf->he_bss_color.enabled = params->he_bss_color.enabled; 1465 err |= BSS_CHANGED_HE_BSS_COLOR; 1466 } 1467 1468 ieee80211_link_info_change_notify(sdata, link, err); 1469 return 0; 1470 } 1471 1472 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link) 1473 { 1474 if (!link->u.ap.next_beacon) 1475 return; 1476 1477 kfree(link->u.ap.next_beacon->mbssid_ies); 1478 kfree(link->u.ap.next_beacon); 1479 link->u.ap.next_beacon = NULL; 1480 } 1481 1482 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, 1483 unsigned int link_id) 1484 { 1485 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1486 struct ieee80211_sub_if_data *vlan; 1487 struct ieee80211_local *local = sdata->local; 1488 struct beacon_data *old_beacon; 1489 struct probe_resp *old_probe_resp; 1490 struct fils_discovery_data *old_fils_discovery; 1491 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp; 1492 struct cfg80211_chan_def chandef; 1493 struct ieee80211_link_data *link = 1494 sdata_dereference(sdata->link[link_id], sdata); 1495 struct ieee80211_bss_conf *link_conf = link->conf; 1496 1497 sdata_assert_lock(sdata); 1498 1499 old_beacon = sdata_dereference(link->u.ap.beacon, sdata); 1500 if (!old_beacon) 1501 return -ENOENT; 1502 old_probe_resp = sdata_dereference(link->u.ap.probe_resp, 1503 sdata); 1504 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery, 1505 sdata); 1506 old_unsol_bcast_probe_resp = 1507 sdata_dereference(link->u.ap.unsol_bcast_probe_resp, 1508 sdata); 1509 1510 /* abort any running channel switch */ 1511 mutex_lock(&local->mtx); 1512 link_conf->csa_active = false; 1513 if (link->csa_block_tx) { 1514 ieee80211_wake_vif_queues(local, sdata, 1515 IEEE80211_QUEUE_STOP_REASON_CSA); 1516 link->csa_block_tx = false; 1517 } 1518 1519 mutex_unlock(&local->mtx); 1520 1521 ieee80211_free_next_beacon(link); 1522 1523 /* turn off carrier for this interface and dependent VLANs */ 1524 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) 1525 netif_carrier_off(vlan->dev); 1526 netif_carrier_off(dev); 1527 1528 /* remove beacon and probe response */ 1529 sdata->u.ap.active = false; 1530 RCU_INIT_POINTER(link->u.ap.beacon, NULL); 1531 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL); 1532 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); 1533 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); 1534 kfree_rcu(old_beacon, rcu_head); 1535 if (old_probe_resp) 1536 kfree_rcu(old_probe_resp, rcu_head); 1537 if (old_fils_discovery) 1538 kfree_rcu(old_fils_discovery, rcu_head); 1539 if (old_unsol_bcast_probe_resp) 1540 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head); 1541 1542 kfree(link_conf->ftmr_params); 1543 link_conf->ftmr_params = NULL; 1544 1545 sdata->vif.mbssid_tx_vif = NULL; 1546 link_conf->bssid_index = 0; 1547 link_conf->nontransmitted = false; 1548 link_conf->ema_ap = false; 1549 link_conf->bssid_indicator = 0; 1550 1551 __sta_info_flush(sdata, true); 1552 ieee80211_free_keys(sdata, true); 1553 1554 link_conf->enable_beacon = false; 1555 sdata->beacon_rate_set = false; 1556 sdata->vif.cfg.ssid_len = 0; 1557 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); 1558 ieee80211_link_info_change_notify(sdata, link, 1559 BSS_CHANGED_BEACON_ENABLED); 1560 1561 if (sdata->wdev.cac_started) { 1562 chandef = link_conf->chandef; 1563 cancel_delayed_work_sync(&link->dfs_cac_timer_work); 1564 cfg80211_cac_event(sdata->dev, &chandef, 1565 NL80211_RADAR_CAC_ABORTED, 1566 GFP_KERNEL); 1567 } 1568 1569 drv_stop_ap(sdata->local, sdata, link_conf); 1570 1571 /* free all potentially still buffered bcast frames */ 1572 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); 1573 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf); 1574 1575 mutex_lock(&local->mtx); 1576 ieee80211_link_copy_chanctx_to_vlans(link, true); 1577 ieee80211_link_release_channel(link); 1578 mutex_unlock(&local->mtx); 1579 1580 return 0; 1581 } 1582 1583 static int sta_apply_auth_flags(struct ieee80211_local *local, 1584 struct sta_info *sta, 1585 u32 mask, u32 set) 1586 { 1587 int ret; 1588 1589 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && 1590 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && 1591 !test_sta_flag(sta, WLAN_STA_AUTH)) { 1592 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); 1593 if (ret) 1594 return ret; 1595 } 1596 1597 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && 1598 set & BIT(NL80211_STA_FLAG_ASSOCIATED) && 1599 !test_sta_flag(sta, WLAN_STA_ASSOC)) { 1600 /* 1601 * When peer becomes associated, init rate control as 1602 * well. Some drivers require rate control initialized 1603 * before drv_sta_state() is called. 1604 */ 1605 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) 1606 rate_control_rate_init(sta); 1607 1608 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); 1609 if (ret) 1610 return ret; 1611 } 1612 1613 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { 1614 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) 1615 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); 1616 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 1617 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); 1618 else 1619 ret = 0; 1620 if (ret) 1621 return ret; 1622 } 1623 1624 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && 1625 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) && 1626 test_sta_flag(sta, WLAN_STA_ASSOC)) { 1627 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); 1628 if (ret) 1629 return ret; 1630 } 1631 1632 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && 1633 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) && 1634 test_sta_flag(sta, WLAN_STA_AUTH)) { 1635 ret = sta_info_move_state(sta, IEEE80211_STA_NONE); 1636 if (ret) 1637 return ret; 1638 } 1639 1640 return 0; 1641 } 1642 1643 static void sta_apply_mesh_params(struct ieee80211_local *local, 1644 struct sta_info *sta, 1645 struct station_parameters *params) 1646 { 1647 #ifdef CONFIG_MAC80211_MESH 1648 struct ieee80211_sub_if_data *sdata = sta->sdata; 1649 u32 changed = 0; 1650 1651 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) { 1652 switch (params->plink_state) { 1653 case NL80211_PLINK_ESTAB: 1654 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) 1655 changed = mesh_plink_inc_estab_count(sdata); 1656 sta->mesh->plink_state = params->plink_state; 1657 sta->mesh->aid = params->peer_aid; 1658 1659 ieee80211_mps_sta_status_update(sta); 1660 changed |= ieee80211_mps_set_sta_local_pm(sta, 1661 sdata->u.mesh.mshcfg.power_mode); 1662 1663 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg); 1664 /* init at low value */ 1665 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10); 1666 1667 break; 1668 case NL80211_PLINK_LISTEN: 1669 case NL80211_PLINK_BLOCKED: 1670 case NL80211_PLINK_OPN_SNT: 1671 case NL80211_PLINK_OPN_RCVD: 1672 case NL80211_PLINK_CNF_RCVD: 1673 case NL80211_PLINK_HOLDING: 1674 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB) 1675 changed = mesh_plink_dec_estab_count(sdata); 1676 sta->mesh->plink_state = params->plink_state; 1677 1678 ieee80211_mps_sta_status_update(sta); 1679 changed |= ieee80211_mps_set_sta_local_pm(sta, 1680 NL80211_MESH_POWER_UNKNOWN); 1681 break; 1682 default: 1683 /* nothing */ 1684 break; 1685 } 1686 } 1687 1688 switch (params->plink_action) { 1689 case NL80211_PLINK_ACTION_NO_ACTION: 1690 /* nothing */ 1691 break; 1692 case NL80211_PLINK_ACTION_OPEN: 1693 changed |= mesh_plink_open(sta); 1694 break; 1695 case NL80211_PLINK_ACTION_BLOCK: 1696 changed |= mesh_plink_block(sta); 1697 break; 1698 } 1699 1700 if (params->local_pm) 1701 changed |= ieee80211_mps_set_sta_local_pm(sta, 1702 params->local_pm); 1703 1704 ieee80211_mbss_info_change_notify(sdata, changed); 1705 #endif 1706 } 1707 1708 static int sta_link_apply_parameters(struct ieee80211_local *local, 1709 struct sta_info *sta, bool new_link, 1710 struct link_station_parameters *params) 1711 { 1712 int ret = 0; 1713 struct ieee80211_supported_band *sband; 1714 struct ieee80211_sub_if_data *sdata = sta->sdata; 1715 u32 link_id = params->link_id < 0 ? 0 : params->link_id; 1716 struct ieee80211_link_data *link = 1717 sdata_dereference(sdata->link[link_id], sdata); 1718 struct link_sta_info *link_sta = 1719 rcu_dereference_protected(sta->link[link_id], 1720 lockdep_is_held(&local->sta_mtx)); 1721 1722 /* 1723 * If there are no changes, then accept a link that doesn't exist, 1724 * unless it's a new link. 1725 */ 1726 if (params->link_id < 0 && !new_link && 1727 !params->link_mac && !params->txpwr_set && 1728 !params->supported_rates_len && 1729 !params->ht_capa && !params->vht_capa && 1730 !params->he_capa && !params->eht_capa && 1731 !params->opmode_notif_used) 1732 return 0; 1733 1734 if (!link || !link_sta) 1735 return -EINVAL; 1736 1737 sband = ieee80211_get_link_sband(link); 1738 if (!sband) 1739 return -EINVAL; 1740 1741 if (params->link_mac) { 1742 if (new_link) { 1743 memcpy(link_sta->addr, params->link_mac, ETH_ALEN); 1744 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN); 1745 } else if (!ether_addr_equal(link_sta->addr, 1746 params->link_mac)) { 1747 return -EINVAL; 1748 } 1749 } else if (new_link) { 1750 return -EINVAL; 1751 } 1752 1753 if (params->txpwr_set) { 1754 link_sta->pub->txpwr.type = params->txpwr.type; 1755 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) 1756 link_sta->pub->txpwr.power = params->txpwr.power; 1757 ret = drv_sta_set_txpwr(local, sdata, sta); 1758 if (ret) 1759 return ret; 1760 } 1761 1762 if (params->supported_rates && 1763 params->supported_rates_len) { 1764 ieee80211_parse_bitrates(link->conf->chandef.width, 1765 sband, params->supported_rates, 1766 params->supported_rates_len, 1767 &link_sta->pub->supp_rates[sband->band]); 1768 } 1769 1770 if (params->ht_capa) 1771 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, 1772 params->ht_capa, link_sta); 1773 1774 /* VHT can override some HT caps such as the A-MSDU max length */ 1775 if (params->vht_capa) 1776 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, 1777 params->vht_capa, link_sta); 1778 1779 if (params->he_capa) 1780 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, 1781 (void *)params->he_capa, 1782 params->he_capa_len, 1783 (void *)params->he_6ghz_capa, 1784 link_sta); 1785 1786 if (params->eht_capa) 1787 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband, 1788 (u8 *)params->he_capa, 1789 params->he_capa_len, 1790 params->eht_capa, 1791 params->eht_capa_len, 1792 link_sta); 1793 1794 if (params->opmode_notif_used) { 1795 /* returned value is only needed for rc update, but the 1796 * rc isn't initialized here yet, so ignore it 1797 */ 1798 __ieee80211_vht_handle_opmode(sdata, link_sta, 1799 params->opmode_notif, 1800 sband->band); 1801 } 1802 1803 return ret; 1804 } 1805 1806 static int sta_apply_parameters(struct ieee80211_local *local, 1807 struct sta_info *sta, 1808 struct station_parameters *params) 1809 { 1810 struct ieee80211_sub_if_data *sdata = sta->sdata; 1811 u32 mask, set; 1812 int ret = 0; 1813 1814 mask = params->sta_flags_mask; 1815 set = params->sta_flags_set; 1816 1817 if (ieee80211_vif_is_mesh(&sdata->vif)) { 1818 /* 1819 * In mesh mode, ASSOCIATED isn't part of the nl80211 1820 * API but must follow AUTHENTICATED for driver state. 1821 */ 1822 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) 1823 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); 1824 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) 1825 set |= BIT(NL80211_STA_FLAG_ASSOCIATED); 1826 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 1827 /* 1828 * TDLS -- everything follows authorized, but 1829 * only becoming authorized is possible, not 1830 * going back 1831 */ 1832 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) { 1833 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | 1834 BIT(NL80211_STA_FLAG_ASSOCIATED); 1835 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | 1836 BIT(NL80211_STA_FLAG_ASSOCIATED); 1837 } 1838 } 1839 1840 if (mask & BIT(NL80211_STA_FLAG_WME) && 1841 local->hw.queues >= IEEE80211_NUM_ACS) 1842 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME); 1843 1844 /* auth flags will be set later for TDLS, 1845 * and for unassociated stations that move to associated */ 1846 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && 1847 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) && 1848 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) { 1849 ret = sta_apply_auth_flags(local, sta, mask, set); 1850 if (ret) 1851 return ret; 1852 } 1853 1854 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { 1855 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) 1856 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); 1857 else 1858 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); 1859 } 1860 1861 if (mask & BIT(NL80211_STA_FLAG_MFP)) { 1862 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP)); 1863 if (set & BIT(NL80211_STA_FLAG_MFP)) 1864 set_sta_flag(sta, WLAN_STA_MFP); 1865 else 1866 clear_sta_flag(sta, WLAN_STA_MFP); 1867 } 1868 1869 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { 1870 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 1871 set_sta_flag(sta, WLAN_STA_TDLS_PEER); 1872 else 1873 clear_sta_flag(sta, WLAN_STA_TDLS_PEER); 1874 } 1875 1876 /* mark TDLS channel switch support, if the AP allows it */ 1877 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && 1878 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited && 1879 params->ext_capab_len >= 4 && 1880 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) 1881 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH); 1882 1883 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && 1884 !sdata->u.mgd.tdls_wider_bw_prohibited && 1885 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && 1886 params->ext_capab_len >= 8 && 1887 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) 1888 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW); 1889 1890 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { 1891 sta->sta.uapsd_queues = params->uapsd_queues; 1892 sta->sta.max_sp = params->max_sp; 1893 } 1894 1895 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab, 1896 params->ext_capab_len); 1897 1898 /* 1899 * cfg80211 validates this (1-2007) and allows setting the AID 1900 * only when creating a new station entry 1901 */ 1902 if (params->aid) 1903 sta->sta.aid = params->aid; 1904 1905 /* 1906 * Some of the following updates would be racy if called on an 1907 * existing station, via ieee80211_change_station(). However, 1908 * all such changes are rejected by cfg80211 except for updates 1909 * changing the supported rates on an existing but not yet used 1910 * TDLS peer. 1911 */ 1912 1913 if (params->listen_interval >= 0) 1914 sta->listen_interval = params->listen_interval; 1915 1916 ret = sta_link_apply_parameters(local, sta, false, 1917 ¶ms->link_sta_params); 1918 if (ret) 1919 return ret; 1920 1921 if (params->support_p2p_ps >= 0) 1922 sta->sta.support_p2p_ps = params->support_p2p_ps; 1923 1924 if (ieee80211_vif_is_mesh(&sdata->vif)) 1925 sta_apply_mesh_params(local, sta, params); 1926 1927 if (params->airtime_weight) 1928 sta->airtime_weight = params->airtime_weight; 1929 1930 /* set the STA state after all sta info from usermode has been set */ 1931 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || 1932 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { 1933 ret = sta_apply_auth_flags(local, sta, mask, set); 1934 if (ret) 1935 return ret; 1936 } 1937 1938 /* Mark the STA as MLO if MLD MAC address is available */ 1939 if (params->link_sta_params.mld_mac) 1940 sta->sta.mlo = true; 1941 1942 return 0; 1943 } 1944 1945 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, 1946 const u8 *mac, 1947 struct station_parameters *params) 1948 { 1949 struct ieee80211_local *local = wiphy_priv(wiphy); 1950 struct sta_info *sta; 1951 struct ieee80211_sub_if_data *sdata; 1952 int err; 1953 1954 if (params->vlan) { 1955 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 1956 1957 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 1958 sdata->vif.type != NL80211_IFTYPE_AP) 1959 return -EINVAL; 1960 } else 1961 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1962 1963 if (ether_addr_equal(mac, sdata->vif.addr)) 1964 return -EINVAL; 1965 1966 if (!is_valid_ether_addr(mac)) 1967 return -EINVAL; 1968 1969 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) && 1970 sdata->vif.type == NL80211_IFTYPE_STATION && 1971 !sdata->u.mgd.associated) 1972 return -EINVAL; 1973 1974 /* 1975 * If we have a link ID, it can be a non-MLO station on an AP MLD, 1976 * but we need to have a link_mac in that case as well, so use the 1977 * STA's MAC address in that case. 1978 */ 1979 if (params->link_sta_params.link_id >= 0) 1980 sta = sta_info_alloc_with_link(sdata, mac, 1981 params->link_sta_params.link_id, 1982 params->link_sta_params.link_mac ?: mac, 1983 GFP_KERNEL); 1984 else 1985 sta = sta_info_alloc(sdata, mac, GFP_KERNEL); 1986 1987 if (!sta) 1988 return -ENOMEM; 1989 1990 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 1991 sta->sta.tdls = true; 1992 1993 /* Though the mutex is not needed here (since the station is not 1994 * visible yet), sta_apply_parameters (and inner functions) require 1995 * the mutex due to other paths. 1996 */ 1997 mutex_lock(&local->sta_mtx); 1998 err = sta_apply_parameters(local, sta, params); 1999 mutex_unlock(&local->sta_mtx); 2000 if (err) { 2001 sta_info_free(local, sta); 2002 return err; 2003 } 2004 2005 /* 2006 * for TDLS and for unassociated station, rate control should be 2007 * initialized only when rates are known and station is marked 2008 * authorized/associated 2009 */ 2010 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && 2011 test_sta_flag(sta, WLAN_STA_ASSOC)) 2012 rate_control_rate_init(sta); 2013 2014 return sta_info_insert(sta); 2015 } 2016 2017 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, 2018 struct station_del_parameters *params) 2019 { 2020 struct ieee80211_sub_if_data *sdata; 2021 2022 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2023 2024 if (params->mac) 2025 return sta_info_destroy_addr_bss(sdata, params->mac); 2026 2027 sta_info_flush(sdata); 2028 return 0; 2029 } 2030 2031 static int ieee80211_change_station(struct wiphy *wiphy, 2032 struct net_device *dev, const u8 *mac, 2033 struct station_parameters *params) 2034 { 2035 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2036 struct ieee80211_local *local = wiphy_priv(wiphy); 2037 struct sta_info *sta; 2038 struct ieee80211_sub_if_data *vlansdata; 2039 enum cfg80211_station_type statype; 2040 int err; 2041 2042 mutex_lock(&local->sta_mtx); 2043 2044 sta = sta_info_get_bss(sdata, mac); 2045 if (!sta) { 2046 err = -ENOENT; 2047 goto out_err; 2048 } 2049 2050 switch (sdata->vif.type) { 2051 case NL80211_IFTYPE_MESH_POINT: 2052 if (sdata->u.mesh.user_mpm) 2053 statype = CFG80211_STA_MESH_PEER_USER; 2054 else 2055 statype = CFG80211_STA_MESH_PEER_KERNEL; 2056 break; 2057 case NL80211_IFTYPE_ADHOC: 2058 statype = CFG80211_STA_IBSS; 2059 break; 2060 case NL80211_IFTYPE_STATION: 2061 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 2062 statype = CFG80211_STA_AP_STA; 2063 break; 2064 } 2065 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 2066 statype = CFG80211_STA_TDLS_PEER_ACTIVE; 2067 else 2068 statype = CFG80211_STA_TDLS_PEER_SETUP; 2069 break; 2070 case NL80211_IFTYPE_AP: 2071 case NL80211_IFTYPE_AP_VLAN: 2072 if (test_sta_flag(sta, WLAN_STA_ASSOC)) 2073 statype = CFG80211_STA_AP_CLIENT; 2074 else 2075 statype = CFG80211_STA_AP_CLIENT_UNASSOC; 2076 break; 2077 default: 2078 err = -EOPNOTSUPP; 2079 goto out_err; 2080 } 2081 2082 err = cfg80211_check_station_change(wiphy, params, statype); 2083 if (err) 2084 goto out_err; 2085 2086 if (params->vlan && params->vlan != sta->sdata->dev) { 2087 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 2088 2089 if (params->vlan->ieee80211_ptr->use_4addr) { 2090 if (vlansdata->u.vlan.sta) { 2091 err = -EBUSY; 2092 goto out_err; 2093 } 2094 2095 rcu_assign_pointer(vlansdata->u.vlan.sta, sta); 2096 __ieee80211_check_fast_rx_iface(vlansdata); 2097 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true); 2098 } 2099 2100 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 2101 sta->sdata->u.vlan.sta) { 2102 ieee80211_clear_fast_rx(sta); 2103 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); 2104 } 2105 2106 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 2107 ieee80211_vif_dec_num_mcast(sta->sdata); 2108 2109 sta->sdata = vlansdata; 2110 ieee80211_check_fast_xmit(sta); 2111 2112 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { 2113 ieee80211_vif_inc_num_mcast(sta->sdata); 2114 cfg80211_send_layer2_update(sta->sdata->dev, 2115 sta->sta.addr); 2116 } 2117 } 2118 2119 /* we use sta_info_get_bss() so this might be different */ 2120 if (sdata != sta->sdata) { 2121 mutex_lock_nested(&sta->sdata->wdev.mtx, 1); 2122 err = sta_apply_parameters(local, sta, params); 2123 mutex_unlock(&sta->sdata->wdev.mtx); 2124 } else { 2125 err = sta_apply_parameters(local, sta, params); 2126 } 2127 if (err) 2128 goto out_err; 2129 2130 mutex_unlock(&local->sta_mtx); 2131 2132 if (sdata->vif.type == NL80211_IFTYPE_STATION && 2133 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { 2134 ieee80211_recalc_ps(local); 2135 ieee80211_recalc_ps_vif(sdata); 2136 } 2137 2138 return 0; 2139 out_err: 2140 mutex_unlock(&local->sta_mtx); 2141 return err; 2142 } 2143 2144 #ifdef CONFIG_MAC80211_MESH 2145 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, 2146 const u8 *dst, const u8 *next_hop) 2147 { 2148 struct ieee80211_sub_if_data *sdata; 2149 struct mesh_path *mpath; 2150 struct sta_info *sta; 2151 2152 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2153 2154 rcu_read_lock(); 2155 sta = sta_info_get(sdata, next_hop); 2156 if (!sta) { 2157 rcu_read_unlock(); 2158 return -ENOENT; 2159 } 2160 2161 mpath = mesh_path_add(sdata, dst); 2162 if (IS_ERR(mpath)) { 2163 rcu_read_unlock(); 2164 return PTR_ERR(mpath); 2165 } 2166 2167 mesh_path_fix_nexthop(mpath, sta); 2168 2169 rcu_read_unlock(); 2170 return 0; 2171 } 2172 2173 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, 2174 const u8 *dst) 2175 { 2176 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2177 2178 if (dst) 2179 return mesh_path_del(sdata, dst); 2180 2181 mesh_path_flush_by_iface(sdata); 2182 return 0; 2183 } 2184 2185 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, 2186 const u8 *dst, const u8 *next_hop) 2187 { 2188 struct ieee80211_sub_if_data *sdata; 2189 struct mesh_path *mpath; 2190 struct sta_info *sta; 2191 2192 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2193 2194 rcu_read_lock(); 2195 2196 sta = sta_info_get(sdata, next_hop); 2197 if (!sta) { 2198 rcu_read_unlock(); 2199 return -ENOENT; 2200 } 2201 2202 mpath = mesh_path_lookup(sdata, dst); 2203 if (!mpath) { 2204 rcu_read_unlock(); 2205 return -ENOENT; 2206 } 2207 2208 mesh_path_fix_nexthop(mpath, sta); 2209 2210 rcu_read_unlock(); 2211 return 0; 2212 } 2213 2214 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, 2215 struct mpath_info *pinfo) 2216 { 2217 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); 2218 2219 if (next_hop_sta) 2220 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); 2221 else 2222 eth_zero_addr(next_hop); 2223 2224 memset(pinfo, 0, sizeof(*pinfo)); 2225 2226 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; 2227 2228 pinfo->filled = MPATH_INFO_FRAME_QLEN | 2229 MPATH_INFO_SN | 2230 MPATH_INFO_METRIC | 2231 MPATH_INFO_EXPTIME | 2232 MPATH_INFO_DISCOVERY_TIMEOUT | 2233 MPATH_INFO_DISCOVERY_RETRIES | 2234 MPATH_INFO_FLAGS | 2235 MPATH_INFO_HOP_COUNT | 2236 MPATH_INFO_PATH_CHANGE; 2237 2238 pinfo->frame_qlen = mpath->frame_queue.qlen; 2239 pinfo->sn = mpath->sn; 2240 pinfo->metric = mpath->metric; 2241 if (time_before(jiffies, mpath->exp_time)) 2242 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); 2243 pinfo->discovery_timeout = 2244 jiffies_to_msecs(mpath->discovery_timeout); 2245 pinfo->discovery_retries = mpath->discovery_retries; 2246 if (mpath->flags & MESH_PATH_ACTIVE) 2247 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; 2248 if (mpath->flags & MESH_PATH_RESOLVING) 2249 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; 2250 if (mpath->flags & MESH_PATH_SN_VALID) 2251 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; 2252 if (mpath->flags & MESH_PATH_FIXED) 2253 pinfo->flags |= NL80211_MPATH_FLAG_FIXED; 2254 if (mpath->flags & MESH_PATH_RESOLVED) 2255 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; 2256 pinfo->hop_count = mpath->hop_count; 2257 pinfo->path_change_count = mpath->path_change_count; 2258 } 2259 2260 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, 2261 u8 *dst, u8 *next_hop, struct mpath_info *pinfo) 2262 2263 { 2264 struct ieee80211_sub_if_data *sdata; 2265 struct mesh_path *mpath; 2266 2267 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2268 2269 rcu_read_lock(); 2270 mpath = mesh_path_lookup(sdata, dst); 2271 if (!mpath) { 2272 rcu_read_unlock(); 2273 return -ENOENT; 2274 } 2275 memcpy(dst, mpath->dst, ETH_ALEN); 2276 mpath_set_pinfo(mpath, next_hop, pinfo); 2277 rcu_read_unlock(); 2278 return 0; 2279 } 2280 2281 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, 2282 int idx, u8 *dst, u8 *next_hop, 2283 struct mpath_info *pinfo) 2284 { 2285 struct ieee80211_sub_if_data *sdata; 2286 struct mesh_path *mpath; 2287 2288 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2289 2290 rcu_read_lock(); 2291 mpath = mesh_path_lookup_by_idx(sdata, idx); 2292 if (!mpath) { 2293 rcu_read_unlock(); 2294 return -ENOENT; 2295 } 2296 memcpy(dst, mpath->dst, ETH_ALEN); 2297 mpath_set_pinfo(mpath, next_hop, pinfo); 2298 rcu_read_unlock(); 2299 return 0; 2300 } 2301 2302 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, 2303 struct mpath_info *pinfo) 2304 { 2305 memset(pinfo, 0, sizeof(*pinfo)); 2306 memcpy(mpp, mpath->mpp, ETH_ALEN); 2307 2308 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; 2309 } 2310 2311 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, 2312 u8 *dst, u8 *mpp, struct mpath_info *pinfo) 2313 2314 { 2315 struct ieee80211_sub_if_data *sdata; 2316 struct mesh_path *mpath; 2317 2318 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2319 2320 rcu_read_lock(); 2321 mpath = mpp_path_lookup(sdata, dst); 2322 if (!mpath) { 2323 rcu_read_unlock(); 2324 return -ENOENT; 2325 } 2326 memcpy(dst, mpath->dst, ETH_ALEN); 2327 mpp_set_pinfo(mpath, mpp, pinfo); 2328 rcu_read_unlock(); 2329 return 0; 2330 } 2331 2332 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, 2333 int idx, u8 *dst, u8 *mpp, 2334 struct mpath_info *pinfo) 2335 { 2336 struct ieee80211_sub_if_data *sdata; 2337 struct mesh_path *mpath; 2338 2339 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2340 2341 rcu_read_lock(); 2342 mpath = mpp_path_lookup_by_idx(sdata, idx); 2343 if (!mpath) { 2344 rcu_read_unlock(); 2345 return -ENOENT; 2346 } 2347 memcpy(dst, mpath->dst, ETH_ALEN); 2348 mpp_set_pinfo(mpath, mpp, pinfo); 2349 rcu_read_unlock(); 2350 return 0; 2351 } 2352 2353 static int ieee80211_get_mesh_config(struct wiphy *wiphy, 2354 struct net_device *dev, 2355 struct mesh_config *conf) 2356 { 2357 struct ieee80211_sub_if_data *sdata; 2358 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2359 2360 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); 2361 return 0; 2362 } 2363 2364 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) 2365 { 2366 return (mask >> (parm-1)) & 0x1; 2367 } 2368 2369 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, 2370 const struct mesh_setup *setup) 2371 { 2372 u8 *new_ie; 2373 struct ieee80211_sub_if_data *sdata = container_of(ifmsh, 2374 struct ieee80211_sub_if_data, u.mesh); 2375 int i; 2376 2377 /* allocate information elements */ 2378 new_ie = NULL; 2379 2380 if (setup->ie_len) { 2381 new_ie = kmemdup(setup->ie, setup->ie_len, 2382 GFP_KERNEL); 2383 if (!new_ie) 2384 return -ENOMEM; 2385 } 2386 ifmsh->ie_len = setup->ie_len; 2387 ifmsh->ie = new_ie; 2388 2389 /* now copy the rest of the setup parameters */ 2390 ifmsh->mesh_id_len = setup->mesh_id_len; 2391 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); 2392 ifmsh->mesh_sp_id = setup->sync_method; 2393 ifmsh->mesh_pp_id = setup->path_sel_proto; 2394 ifmsh->mesh_pm_id = setup->path_metric; 2395 ifmsh->user_mpm = setup->user_mpm; 2396 ifmsh->mesh_auth_id = setup->auth_id; 2397 ifmsh->security = IEEE80211_MESH_SEC_NONE; 2398 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; 2399 if (setup->is_authenticated) 2400 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; 2401 if (setup->is_secure) 2402 ifmsh->security |= IEEE80211_MESH_SEC_SECURED; 2403 2404 /* mcast rate setting in Mesh Node */ 2405 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, 2406 sizeof(setup->mcast_rate)); 2407 sdata->vif.bss_conf.basic_rates = setup->basic_rates; 2408 2409 sdata->vif.bss_conf.beacon_int = setup->beacon_interval; 2410 sdata->vif.bss_conf.dtim_period = setup->dtim_period; 2411 2412 sdata->beacon_rate_set = false; 2413 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy, 2414 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { 2415 for (i = 0; i < NUM_NL80211_BANDS; i++) { 2416 sdata->beacon_rateidx_mask[i] = 2417 setup->beacon_rate.control[i].legacy; 2418 if (sdata->beacon_rateidx_mask[i]) 2419 sdata->beacon_rate_set = true; 2420 } 2421 } 2422 2423 return 0; 2424 } 2425 2426 static int ieee80211_update_mesh_config(struct wiphy *wiphy, 2427 struct net_device *dev, u32 mask, 2428 const struct mesh_config *nconf) 2429 { 2430 struct mesh_config *conf; 2431 struct ieee80211_sub_if_data *sdata; 2432 struct ieee80211_if_mesh *ifmsh; 2433 2434 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2435 ifmsh = &sdata->u.mesh; 2436 2437 /* Set the config options which we are interested in setting */ 2438 conf = &(sdata->u.mesh.mshcfg); 2439 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) 2440 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; 2441 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) 2442 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; 2443 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) 2444 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; 2445 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) 2446 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; 2447 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) 2448 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; 2449 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) 2450 conf->dot11MeshTTL = nconf->dot11MeshTTL; 2451 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) 2452 conf->element_ttl = nconf->element_ttl; 2453 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { 2454 if (ifmsh->user_mpm) 2455 return -EBUSY; 2456 conf->auto_open_plinks = nconf->auto_open_plinks; 2457 } 2458 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) 2459 conf->dot11MeshNbrOffsetMaxNeighbor = 2460 nconf->dot11MeshNbrOffsetMaxNeighbor; 2461 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) 2462 conf->dot11MeshHWMPmaxPREQretries = 2463 nconf->dot11MeshHWMPmaxPREQretries; 2464 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) 2465 conf->path_refresh_time = nconf->path_refresh_time; 2466 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) 2467 conf->min_discovery_timeout = nconf->min_discovery_timeout; 2468 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) 2469 conf->dot11MeshHWMPactivePathTimeout = 2470 nconf->dot11MeshHWMPactivePathTimeout; 2471 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) 2472 conf->dot11MeshHWMPpreqMinInterval = 2473 nconf->dot11MeshHWMPpreqMinInterval; 2474 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) 2475 conf->dot11MeshHWMPperrMinInterval = 2476 nconf->dot11MeshHWMPperrMinInterval; 2477 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 2478 mask)) 2479 conf->dot11MeshHWMPnetDiameterTraversalTime = 2480 nconf->dot11MeshHWMPnetDiameterTraversalTime; 2481 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { 2482 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; 2483 ieee80211_mesh_root_setup(ifmsh); 2484 } 2485 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { 2486 /* our current gate announcement implementation rides on root 2487 * announcements, so require this ifmsh to also be a root node 2488 * */ 2489 if (nconf->dot11MeshGateAnnouncementProtocol && 2490 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { 2491 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; 2492 ieee80211_mesh_root_setup(ifmsh); 2493 } 2494 conf->dot11MeshGateAnnouncementProtocol = 2495 nconf->dot11MeshGateAnnouncementProtocol; 2496 } 2497 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) 2498 conf->dot11MeshHWMPRannInterval = 2499 nconf->dot11MeshHWMPRannInterval; 2500 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) 2501 conf->dot11MeshForwarding = nconf->dot11MeshForwarding; 2502 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { 2503 /* our RSSI threshold implementation is supported only for 2504 * devices that report signal in dBm. 2505 */ 2506 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) 2507 return -ENOTSUPP; 2508 conf->rssi_threshold = nconf->rssi_threshold; 2509 } 2510 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { 2511 conf->ht_opmode = nconf->ht_opmode; 2512 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; 2513 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 2514 BSS_CHANGED_HT); 2515 } 2516 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) 2517 conf->dot11MeshHWMPactivePathToRootTimeout = 2518 nconf->dot11MeshHWMPactivePathToRootTimeout; 2519 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) 2520 conf->dot11MeshHWMProotInterval = 2521 nconf->dot11MeshHWMProotInterval; 2522 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) 2523 conf->dot11MeshHWMPconfirmationInterval = 2524 nconf->dot11MeshHWMPconfirmationInterval; 2525 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { 2526 conf->power_mode = nconf->power_mode; 2527 ieee80211_mps_local_status_update(sdata); 2528 } 2529 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) 2530 conf->dot11MeshAwakeWindowDuration = 2531 nconf->dot11MeshAwakeWindowDuration; 2532 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) 2533 conf->plink_timeout = nconf->plink_timeout; 2534 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask)) 2535 conf->dot11MeshConnectedToMeshGate = 2536 nconf->dot11MeshConnectedToMeshGate; 2537 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask)) 2538 conf->dot11MeshNolearn = nconf->dot11MeshNolearn; 2539 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask)) 2540 conf->dot11MeshConnectedToAuthServer = 2541 nconf->dot11MeshConnectedToAuthServer; 2542 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); 2543 return 0; 2544 } 2545 2546 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, 2547 const struct mesh_config *conf, 2548 const struct mesh_setup *setup) 2549 { 2550 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2551 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 2552 int err; 2553 2554 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); 2555 err = copy_mesh_setup(ifmsh, setup); 2556 if (err) 2557 return err; 2558 2559 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; 2560 2561 /* can mesh use other SMPS modes? */ 2562 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 2563 sdata->deflink.needed_rx_chains = sdata->local->rx_chains; 2564 2565 mutex_lock(&sdata->local->mtx); 2566 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef, 2567 IEEE80211_CHANCTX_SHARED); 2568 mutex_unlock(&sdata->local->mtx); 2569 if (err) 2570 return err; 2571 2572 return ieee80211_start_mesh(sdata); 2573 } 2574 2575 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) 2576 { 2577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2578 2579 ieee80211_stop_mesh(sdata); 2580 mutex_lock(&sdata->local->mtx); 2581 ieee80211_link_release_channel(&sdata->deflink); 2582 kfree(sdata->u.mesh.ie); 2583 mutex_unlock(&sdata->local->mtx); 2584 2585 return 0; 2586 } 2587 #endif 2588 2589 static int ieee80211_change_bss(struct wiphy *wiphy, 2590 struct net_device *dev, 2591 struct bss_parameters *params) 2592 { 2593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2594 struct ieee80211_link_data *link; 2595 struct ieee80211_supported_band *sband; 2596 u32 changed = 0; 2597 2598 link = ieee80211_link_or_deflink(sdata, params->link_id, true); 2599 if (IS_ERR(link)) 2600 return PTR_ERR(link); 2601 2602 if (!sdata_dereference(link->u.ap.beacon, sdata)) 2603 return -ENOENT; 2604 2605 sband = ieee80211_get_link_sband(link); 2606 if (!sband) 2607 return -EINVAL; 2608 2609 if (params->use_cts_prot >= 0) { 2610 link->conf->use_cts_prot = params->use_cts_prot; 2611 changed |= BSS_CHANGED_ERP_CTS_PROT; 2612 } 2613 if (params->use_short_preamble >= 0) { 2614 link->conf->use_short_preamble = params->use_short_preamble; 2615 changed |= BSS_CHANGED_ERP_PREAMBLE; 2616 } 2617 2618 if (!link->conf->use_short_slot && 2619 (sband->band == NL80211_BAND_5GHZ || 2620 sband->band == NL80211_BAND_6GHZ)) { 2621 link->conf->use_short_slot = true; 2622 changed |= BSS_CHANGED_ERP_SLOT; 2623 } 2624 2625 if (params->use_short_slot_time >= 0) { 2626 link->conf->use_short_slot = params->use_short_slot_time; 2627 changed |= BSS_CHANGED_ERP_SLOT; 2628 } 2629 2630 if (params->basic_rates) { 2631 ieee80211_parse_bitrates(link->conf->chandef.width, 2632 wiphy->bands[sband->band], 2633 params->basic_rates, 2634 params->basic_rates_len, 2635 &link->conf->basic_rates); 2636 changed |= BSS_CHANGED_BASIC_RATES; 2637 ieee80211_check_rate_mask(link); 2638 } 2639 2640 if (params->ap_isolate >= 0) { 2641 if (params->ap_isolate) 2642 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; 2643 else 2644 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; 2645 ieee80211_check_fast_rx_iface(sdata); 2646 } 2647 2648 if (params->ht_opmode >= 0) { 2649 link->conf->ht_operation_mode = (u16)params->ht_opmode; 2650 changed |= BSS_CHANGED_HT; 2651 } 2652 2653 if (params->p2p_ctwindow >= 0) { 2654 link->conf->p2p_noa_attr.oppps_ctwindow &= 2655 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; 2656 link->conf->p2p_noa_attr.oppps_ctwindow |= 2657 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; 2658 changed |= BSS_CHANGED_P2P_PS; 2659 } 2660 2661 if (params->p2p_opp_ps > 0) { 2662 link->conf->p2p_noa_attr.oppps_ctwindow |= 2663 IEEE80211_P2P_OPPPS_ENABLE_BIT; 2664 changed |= BSS_CHANGED_P2P_PS; 2665 } else if (params->p2p_opp_ps == 0) { 2666 link->conf->p2p_noa_attr.oppps_ctwindow &= 2667 ~IEEE80211_P2P_OPPPS_ENABLE_BIT; 2668 changed |= BSS_CHANGED_P2P_PS; 2669 } 2670 2671 ieee80211_link_info_change_notify(sdata, link, changed); 2672 2673 return 0; 2674 } 2675 2676 static int ieee80211_set_txq_params(struct wiphy *wiphy, 2677 struct net_device *dev, 2678 struct ieee80211_txq_params *params) 2679 { 2680 struct ieee80211_local *local = wiphy_priv(wiphy); 2681 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2682 struct ieee80211_link_data *link = 2683 ieee80211_link_or_deflink(sdata, params->link_id, true); 2684 struct ieee80211_tx_queue_params p; 2685 2686 if (!local->ops->conf_tx) 2687 return -EOPNOTSUPP; 2688 2689 if (local->hw.queues < IEEE80211_NUM_ACS) 2690 return -EOPNOTSUPP; 2691 2692 if (IS_ERR(link)) 2693 return PTR_ERR(link); 2694 2695 memset(&p, 0, sizeof(p)); 2696 p.aifs = params->aifs; 2697 p.cw_max = params->cwmax; 2698 p.cw_min = params->cwmin; 2699 p.txop = params->txop; 2700 2701 /* 2702 * Setting tx queue params disables u-apsd because it's only 2703 * called in master mode. 2704 */ 2705 p.uapsd = false; 2706 2707 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); 2708 2709 link->tx_conf[params->ac] = p; 2710 if (drv_conf_tx(local, link, params->ac, &p)) { 2711 wiphy_debug(local->hw.wiphy, 2712 "failed to set TX queue parameters for AC %d\n", 2713 params->ac); 2714 return -EINVAL; 2715 } 2716 2717 ieee80211_link_info_change_notify(sdata, link, 2718 BSS_CHANGED_QOS); 2719 2720 return 0; 2721 } 2722 2723 #ifdef CONFIG_PM 2724 static int ieee80211_suspend(struct wiphy *wiphy, 2725 struct cfg80211_wowlan *wowlan) 2726 { 2727 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); 2728 } 2729 2730 static int ieee80211_resume(struct wiphy *wiphy) 2731 { 2732 return __ieee80211_resume(wiphy_priv(wiphy)); 2733 } 2734 #else 2735 #define ieee80211_suspend NULL 2736 #define ieee80211_resume NULL 2737 #endif 2738 2739 static int ieee80211_scan(struct wiphy *wiphy, 2740 struct cfg80211_scan_request *req) 2741 { 2742 struct ieee80211_sub_if_data *sdata; 2743 2744 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); 2745 2746 switch (ieee80211_vif_type_p2p(&sdata->vif)) { 2747 case NL80211_IFTYPE_STATION: 2748 case NL80211_IFTYPE_ADHOC: 2749 case NL80211_IFTYPE_MESH_POINT: 2750 case NL80211_IFTYPE_P2P_CLIENT: 2751 case NL80211_IFTYPE_P2P_DEVICE: 2752 break; 2753 case NL80211_IFTYPE_P2P_GO: 2754 if (sdata->local->ops->hw_scan) 2755 break; 2756 /* 2757 * FIXME: implement NoA while scanning in software, 2758 * for now fall through to allow scanning only when 2759 * beaconing hasn't been configured yet 2760 */ 2761 fallthrough; 2762 case NL80211_IFTYPE_AP: 2763 /* 2764 * If the scan has been forced (and the driver supports 2765 * forcing), don't care about being beaconing already. 2766 * This will create problems to the attached stations (e.g. all 2767 * the frames sent while scanning on other channel will be 2768 * lost) 2769 */ 2770 if (sdata->deflink.u.ap.beacon && 2771 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || 2772 !(req->flags & NL80211_SCAN_FLAG_AP))) 2773 return -EOPNOTSUPP; 2774 break; 2775 case NL80211_IFTYPE_NAN: 2776 default: 2777 return -EOPNOTSUPP; 2778 } 2779 2780 return ieee80211_request_scan(sdata, req); 2781 } 2782 2783 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) 2784 { 2785 ieee80211_scan_cancel(wiphy_priv(wiphy)); 2786 } 2787 2788 static int 2789 ieee80211_sched_scan_start(struct wiphy *wiphy, 2790 struct net_device *dev, 2791 struct cfg80211_sched_scan_request *req) 2792 { 2793 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2794 2795 if (!sdata->local->ops->sched_scan_start) 2796 return -EOPNOTSUPP; 2797 2798 return ieee80211_request_sched_scan_start(sdata, req); 2799 } 2800 2801 static int 2802 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, 2803 u64 reqid) 2804 { 2805 struct ieee80211_local *local = wiphy_priv(wiphy); 2806 2807 if (!local->ops->sched_scan_stop) 2808 return -EOPNOTSUPP; 2809 2810 return ieee80211_request_sched_scan_stop(local); 2811 } 2812 2813 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, 2814 struct cfg80211_auth_request *req) 2815 { 2816 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); 2817 } 2818 2819 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, 2820 struct cfg80211_assoc_request *req) 2821 { 2822 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); 2823 } 2824 2825 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 2826 struct cfg80211_deauth_request *req) 2827 { 2828 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); 2829 } 2830 2831 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 2832 struct cfg80211_disassoc_request *req) 2833 { 2834 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); 2835 } 2836 2837 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 2838 struct cfg80211_ibss_params *params) 2839 { 2840 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); 2841 } 2842 2843 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 2844 { 2845 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); 2846 } 2847 2848 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, 2849 struct ocb_setup *setup) 2850 { 2851 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); 2852 } 2853 2854 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) 2855 { 2856 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); 2857 } 2858 2859 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, 2860 int rate[NUM_NL80211_BANDS]) 2861 { 2862 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2863 2864 memcpy(sdata->vif.bss_conf.mcast_rate, rate, 2865 sizeof(int) * NUM_NL80211_BANDS); 2866 2867 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 2868 BSS_CHANGED_MCAST_RATE); 2869 2870 return 0; 2871 } 2872 2873 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) 2874 { 2875 struct ieee80211_local *local = wiphy_priv(wiphy); 2876 int err; 2877 2878 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { 2879 ieee80211_check_fast_xmit_all(local); 2880 2881 err = drv_set_frag_threshold(local, wiphy->frag_threshold); 2882 2883 if (err) { 2884 ieee80211_check_fast_xmit_all(local); 2885 return err; 2886 } 2887 } 2888 2889 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || 2890 (changed & WIPHY_PARAM_DYN_ACK)) { 2891 s16 coverage_class; 2892 2893 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? 2894 wiphy->coverage_class : -1; 2895 err = drv_set_coverage_class(local, coverage_class); 2896 2897 if (err) 2898 return err; 2899 } 2900 2901 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 2902 err = drv_set_rts_threshold(local, wiphy->rts_threshold); 2903 2904 if (err) 2905 return err; 2906 } 2907 2908 if (changed & WIPHY_PARAM_RETRY_SHORT) { 2909 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) 2910 return -EINVAL; 2911 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; 2912 } 2913 if (changed & WIPHY_PARAM_RETRY_LONG) { 2914 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) 2915 return -EINVAL; 2916 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; 2917 } 2918 if (changed & 2919 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) 2920 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); 2921 2922 if (changed & (WIPHY_PARAM_TXQ_LIMIT | 2923 WIPHY_PARAM_TXQ_MEMORY_LIMIT | 2924 WIPHY_PARAM_TXQ_QUANTUM)) 2925 ieee80211_txq_set_params(local); 2926 2927 return 0; 2928 } 2929 2930 static int ieee80211_set_tx_power(struct wiphy *wiphy, 2931 struct wireless_dev *wdev, 2932 enum nl80211_tx_power_setting type, int mbm) 2933 { 2934 struct ieee80211_local *local = wiphy_priv(wiphy); 2935 struct ieee80211_sub_if_data *sdata; 2936 enum nl80211_tx_power_setting txp_type = type; 2937 bool update_txp_type = false; 2938 bool has_monitor = false; 2939 2940 if (wdev) { 2941 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 2942 2943 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { 2944 sdata = wiphy_dereference(local->hw.wiphy, 2945 local->monitor_sdata); 2946 if (!sdata) 2947 return -EOPNOTSUPP; 2948 } 2949 2950 switch (type) { 2951 case NL80211_TX_POWER_AUTOMATIC: 2952 sdata->deflink.user_power_level = 2953 IEEE80211_UNSET_POWER_LEVEL; 2954 txp_type = NL80211_TX_POWER_LIMITED; 2955 break; 2956 case NL80211_TX_POWER_LIMITED: 2957 case NL80211_TX_POWER_FIXED: 2958 if (mbm < 0 || (mbm % 100)) 2959 return -EOPNOTSUPP; 2960 sdata->deflink.user_power_level = MBM_TO_DBM(mbm); 2961 break; 2962 } 2963 2964 if (txp_type != sdata->vif.bss_conf.txpower_type) { 2965 update_txp_type = true; 2966 sdata->vif.bss_conf.txpower_type = txp_type; 2967 } 2968 2969 ieee80211_recalc_txpower(sdata, update_txp_type); 2970 2971 return 0; 2972 } 2973 2974 switch (type) { 2975 case NL80211_TX_POWER_AUTOMATIC: 2976 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; 2977 txp_type = NL80211_TX_POWER_LIMITED; 2978 break; 2979 case NL80211_TX_POWER_LIMITED: 2980 case NL80211_TX_POWER_FIXED: 2981 if (mbm < 0 || (mbm % 100)) 2982 return -EOPNOTSUPP; 2983 local->user_power_level = MBM_TO_DBM(mbm); 2984 break; 2985 } 2986 2987 mutex_lock(&local->iflist_mtx); 2988 list_for_each_entry(sdata, &local->interfaces, list) { 2989 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { 2990 has_monitor = true; 2991 continue; 2992 } 2993 sdata->deflink.user_power_level = local->user_power_level; 2994 if (txp_type != sdata->vif.bss_conf.txpower_type) 2995 update_txp_type = true; 2996 sdata->vif.bss_conf.txpower_type = txp_type; 2997 } 2998 list_for_each_entry(sdata, &local->interfaces, list) { 2999 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) 3000 continue; 3001 ieee80211_recalc_txpower(sdata, update_txp_type); 3002 } 3003 mutex_unlock(&local->iflist_mtx); 3004 3005 if (has_monitor) { 3006 sdata = wiphy_dereference(local->hw.wiphy, 3007 local->monitor_sdata); 3008 if (sdata) { 3009 sdata->deflink.user_power_level = local->user_power_level; 3010 if (txp_type != sdata->vif.bss_conf.txpower_type) 3011 update_txp_type = true; 3012 sdata->vif.bss_conf.txpower_type = txp_type; 3013 3014 ieee80211_recalc_txpower(sdata, update_txp_type); 3015 } 3016 } 3017 3018 return 0; 3019 } 3020 3021 static int ieee80211_get_tx_power(struct wiphy *wiphy, 3022 struct wireless_dev *wdev, 3023 int *dbm) 3024 { 3025 struct ieee80211_local *local = wiphy_priv(wiphy); 3026 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3027 3028 if (local->ops->get_txpower) 3029 return drv_get_txpower(local, sdata, dbm); 3030 3031 if (!local->use_chanctx) 3032 *dbm = local->hw.conf.power_level; 3033 else 3034 *dbm = sdata->vif.bss_conf.txpower; 3035 3036 return 0; 3037 } 3038 3039 static void ieee80211_rfkill_poll(struct wiphy *wiphy) 3040 { 3041 struct ieee80211_local *local = wiphy_priv(wiphy); 3042 3043 drv_rfkill_poll(local); 3044 } 3045 3046 #ifdef CONFIG_NL80211_TESTMODE 3047 static int ieee80211_testmode_cmd(struct wiphy *wiphy, 3048 struct wireless_dev *wdev, 3049 void *data, int len) 3050 { 3051 struct ieee80211_local *local = wiphy_priv(wiphy); 3052 struct ieee80211_vif *vif = NULL; 3053 3054 if (!local->ops->testmode_cmd) 3055 return -EOPNOTSUPP; 3056 3057 if (wdev) { 3058 struct ieee80211_sub_if_data *sdata; 3059 3060 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3061 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) 3062 vif = &sdata->vif; 3063 } 3064 3065 return local->ops->testmode_cmd(&local->hw, vif, data, len); 3066 } 3067 3068 static int ieee80211_testmode_dump(struct wiphy *wiphy, 3069 struct sk_buff *skb, 3070 struct netlink_callback *cb, 3071 void *data, int len) 3072 { 3073 struct ieee80211_local *local = wiphy_priv(wiphy); 3074 3075 if (!local->ops->testmode_dump) 3076 return -EOPNOTSUPP; 3077 3078 return local->ops->testmode_dump(&local->hw, skb, cb, data, len); 3079 } 3080 #endif 3081 3082 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, 3083 struct ieee80211_link_data *link, 3084 enum ieee80211_smps_mode smps_mode) 3085 { 3086 const u8 *ap; 3087 enum ieee80211_smps_mode old_req; 3088 int err; 3089 struct sta_info *sta; 3090 bool tdls_peer_found = false; 3091 3092 lockdep_assert_held(&sdata->wdev.mtx); 3093 3094 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) 3095 return -EINVAL; 3096 3097 old_req = link->u.mgd.req_smps; 3098 link->u.mgd.req_smps = smps_mode; 3099 3100 if (old_req == smps_mode && 3101 smps_mode != IEEE80211_SMPS_AUTOMATIC) 3102 return 0; 3103 3104 /* 3105 * If not associated, or current association is not an HT 3106 * association, there's no need to do anything, just store 3107 * the new value until we associate. 3108 */ 3109 if (!sdata->u.mgd.associated || 3110 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT) 3111 return 0; 3112 3113 ap = link->u.mgd.bssid; 3114 3115 rcu_read_lock(); 3116 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { 3117 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || 3118 !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 3119 continue; 3120 3121 tdls_peer_found = true; 3122 break; 3123 } 3124 rcu_read_unlock(); 3125 3126 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { 3127 if (tdls_peer_found || !sdata->u.mgd.powersave) 3128 smps_mode = IEEE80211_SMPS_OFF; 3129 else 3130 smps_mode = IEEE80211_SMPS_DYNAMIC; 3131 } 3132 3133 /* send SM PS frame to AP */ 3134 err = ieee80211_send_smps_action(sdata, smps_mode, 3135 ap, ap); 3136 if (err) 3137 link->u.mgd.req_smps = old_req; 3138 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) 3139 ieee80211_teardown_tdls_peers(sdata); 3140 3141 return err; 3142 } 3143 3144 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, 3145 bool enabled, int timeout) 3146 { 3147 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3148 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3149 unsigned int link_id; 3150 3151 if (sdata->vif.type != NL80211_IFTYPE_STATION) 3152 return -EOPNOTSUPP; 3153 3154 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) 3155 return -EOPNOTSUPP; 3156 3157 if (enabled == sdata->u.mgd.powersave && 3158 timeout == local->dynamic_ps_forced_timeout) 3159 return 0; 3160 3161 sdata->u.mgd.powersave = enabled; 3162 local->dynamic_ps_forced_timeout = timeout; 3163 3164 /* no change, but if automatic follow powersave */ 3165 sdata_lock(sdata); 3166 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { 3167 struct ieee80211_link_data *link; 3168 3169 link = sdata_dereference(sdata->link[link_id], sdata); 3170 3171 if (!link) 3172 continue; 3173 __ieee80211_request_smps_mgd(sdata, link, 3174 link->u.mgd.req_smps); 3175 } 3176 sdata_unlock(sdata); 3177 3178 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) 3179 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 3180 3181 ieee80211_recalc_ps(local); 3182 ieee80211_recalc_ps_vif(sdata); 3183 ieee80211_check_fast_rx_iface(sdata); 3184 3185 return 0; 3186 } 3187 3188 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, 3189 struct net_device *dev, 3190 s32 rssi_thold, u32 rssi_hyst) 3191 { 3192 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3193 struct ieee80211_vif *vif = &sdata->vif; 3194 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 3195 3196 if (rssi_thold == bss_conf->cqm_rssi_thold && 3197 rssi_hyst == bss_conf->cqm_rssi_hyst) 3198 return 0; 3199 3200 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER && 3201 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) 3202 return -EOPNOTSUPP; 3203 3204 bss_conf->cqm_rssi_thold = rssi_thold; 3205 bss_conf->cqm_rssi_hyst = rssi_hyst; 3206 bss_conf->cqm_rssi_low = 0; 3207 bss_conf->cqm_rssi_high = 0; 3208 sdata->deflink.u.mgd.last_cqm_event_signal = 0; 3209 3210 /* tell the driver upon association, unless already associated */ 3211 if (sdata->u.mgd.associated && 3212 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) 3213 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3214 BSS_CHANGED_CQM); 3215 3216 return 0; 3217 } 3218 3219 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, 3220 struct net_device *dev, 3221 s32 rssi_low, s32 rssi_high) 3222 { 3223 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3224 struct ieee80211_vif *vif = &sdata->vif; 3225 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 3226 3227 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) 3228 return -EOPNOTSUPP; 3229 3230 bss_conf->cqm_rssi_low = rssi_low; 3231 bss_conf->cqm_rssi_high = rssi_high; 3232 bss_conf->cqm_rssi_thold = 0; 3233 bss_conf->cqm_rssi_hyst = 0; 3234 sdata->deflink.u.mgd.last_cqm_event_signal = 0; 3235 3236 /* tell the driver upon association, unless already associated */ 3237 if (sdata->u.mgd.associated && 3238 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) 3239 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3240 BSS_CHANGED_CQM); 3241 3242 return 0; 3243 } 3244 3245 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, 3246 struct net_device *dev, 3247 unsigned int link_id, 3248 const u8 *addr, 3249 const struct cfg80211_bitrate_mask *mask) 3250 { 3251 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3252 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3253 int i, ret; 3254 3255 if (!ieee80211_sdata_running(sdata)) 3256 return -ENETDOWN; 3257 3258 /* 3259 * If active validate the setting and reject it if it doesn't leave 3260 * at least one basic rate usable, since we really have to be able 3261 * to send something, and if we're an AP we have to be able to do 3262 * so at a basic rate so that all clients can receive it. 3263 */ 3264 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) && 3265 sdata->vif.bss_conf.chandef.chan) { 3266 u32 basic_rates = sdata->vif.bss_conf.basic_rates; 3267 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band; 3268 3269 if (!(mask->control[band].legacy & basic_rates)) 3270 return -EINVAL; 3271 } 3272 3273 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { 3274 ret = drv_set_bitrate_mask(local, sdata, mask); 3275 if (ret) 3276 return ret; 3277 } 3278 3279 for (i = 0; i < NUM_NL80211_BANDS; i++) { 3280 struct ieee80211_supported_band *sband = wiphy->bands[i]; 3281 int j; 3282 3283 sdata->rc_rateidx_mask[i] = mask->control[i].legacy; 3284 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, 3285 sizeof(mask->control[i].ht_mcs)); 3286 memcpy(sdata->rc_rateidx_vht_mcs_mask[i], 3287 mask->control[i].vht_mcs, 3288 sizeof(mask->control[i].vht_mcs)); 3289 3290 sdata->rc_has_mcs_mask[i] = false; 3291 sdata->rc_has_vht_mcs_mask[i] = false; 3292 if (!sband) 3293 continue; 3294 3295 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { 3296 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) { 3297 sdata->rc_has_mcs_mask[i] = true; 3298 break; 3299 } 3300 } 3301 3302 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { 3303 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) { 3304 sdata->rc_has_vht_mcs_mask[i] = true; 3305 break; 3306 } 3307 } 3308 } 3309 3310 return 0; 3311 } 3312 3313 static int ieee80211_start_radar_detection(struct wiphy *wiphy, 3314 struct net_device *dev, 3315 struct cfg80211_chan_def *chandef, 3316 u32 cac_time_ms) 3317 { 3318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3319 struct ieee80211_local *local = sdata->local; 3320 int err; 3321 3322 mutex_lock(&local->mtx); 3323 if (!list_empty(&local->roc_list) || local->scanning) { 3324 err = -EBUSY; 3325 goto out_unlock; 3326 } 3327 3328 /* whatever, but channel contexts should not complain about that one */ 3329 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 3330 sdata->deflink.needed_rx_chains = local->rx_chains; 3331 3332 err = ieee80211_link_use_channel(&sdata->deflink, chandef, 3333 IEEE80211_CHANCTX_SHARED); 3334 if (err) 3335 goto out_unlock; 3336 3337 ieee80211_queue_delayed_work(&sdata->local->hw, 3338 &sdata->deflink.dfs_cac_timer_work, 3339 msecs_to_jiffies(cac_time_ms)); 3340 3341 out_unlock: 3342 mutex_unlock(&local->mtx); 3343 return err; 3344 } 3345 3346 static void ieee80211_end_cac(struct wiphy *wiphy, 3347 struct net_device *dev) 3348 { 3349 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3350 struct ieee80211_local *local = sdata->local; 3351 3352 mutex_lock(&local->mtx); 3353 list_for_each_entry(sdata, &local->interfaces, list) { 3354 /* it might be waiting for the local->mtx, but then 3355 * by the time it gets it, sdata->wdev.cac_started 3356 * will no longer be true 3357 */ 3358 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work); 3359 3360 if (sdata->wdev.cac_started) { 3361 ieee80211_link_release_channel(&sdata->deflink); 3362 sdata->wdev.cac_started = false; 3363 } 3364 } 3365 mutex_unlock(&local->mtx); 3366 } 3367 3368 static struct cfg80211_beacon_data * 3369 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) 3370 { 3371 struct cfg80211_beacon_data *new_beacon; 3372 u8 *pos; 3373 int len; 3374 3375 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + 3376 beacon->proberesp_ies_len + beacon->assocresp_ies_len + 3377 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len + 3378 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies); 3379 3380 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); 3381 if (!new_beacon) 3382 return NULL; 3383 3384 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { 3385 new_beacon->mbssid_ies = 3386 kzalloc(struct_size(new_beacon->mbssid_ies, 3387 elem, beacon->mbssid_ies->cnt), 3388 GFP_KERNEL); 3389 if (!new_beacon->mbssid_ies) { 3390 kfree(new_beacon); 3391 return NULL; 3392 } 3393 } 3394 3395 pos = (u8 *)(new_beacon + 1); 3396 if (beacon->head_len) { 3397 new_beacon->head_len = beacon->head_len; 3398 new_beacon->head = pos; 3399 memcpy(pos, beacon->head, beacon->head_len); 3400 pos += beacon->head_len; 3401 } 3402 if (beacon->tail_len) { 3403 new_beacon->tail_len = beacon->tail_len; 3404 new_beacon->tail = pos; 3405 memcpy(pos, beacon->tail, beacon->tail_len); 3406 pos += beacon->tail_len; 3407 } 3408 if (beacon->beacon_ies_len) { 3409 new_beacon->beacon_ies_len = beacon->beacon_ies_len; 3410 new_beacon->beacon_ies = pos; 3411 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); 3412 pos += beacon->beacon_ies_len; 3413 } 3414 if (beacon->proberesp_ies_len) { 3415 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; 3416 new_beacon->proberesp_ies = pos; 3417 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); 3418 pos += beacon->proberesp_ies_len; 3419 } 3420 if (beacon->assocresp_ies_len) { 3421 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; 3422 new_beacon->assocresp_ies = pos; 3423 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); 3424 pos += beacon->assocresp_ies_len; 3425 } 3426 if (beacon->probe_resp_len) { 3427 new_beacon->probe_resp_len = beacon->probe_resp_len; 3428 new_beacon->probe_resp = pos; 3429 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); 3430 pos += beacon->probe_resp_len; 3431 } 3432 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) 3433 pos += ieee80211_copy_mbssid_beacon(pos, 3434 new_beacon->mbssid_ies, 3435 beacon->mbssid_ies); 3436 3437 /* might copy -1, meaning no changes requested */ 3438 new_beacon->ftm_responder = beacon->ftm_responder; 3439 if (beacon->lci) { 3440 new_beacon->lci_len = beacon->lci_len; 3441 new_beacon->lci = pos; 3442 memcpy(pos, beacon->lci, beacon->lci_len); 3443 pos += beacon->lci_len; 3444 } 3445 if (beacon->civicloc) { 3446 new_beacon->civicloc_len = beacon->civicloc_len; 3447 new_beacon->civicloc = pos; 3448 memcpy(pos, beacon->civicloc, beacon->civicloc_len); 3449 pos += beacon->civicloc_len; 3450 } 3451 3452 return new_beacon; 3453 } 3454 3455 void ieee80211_csa_finish(struct ieee80211_vif *vif) 3456 { 3457 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3458 struct ieee80211_local *local = sdata->local; 3459 3460 rcu_read_lock(); 3461 3462 if (vif->mbssid_tx_vif == vif) { 3463 /* Trigger ieee80211_csa_finish() on the non-transmitting 3464 * interfaces when channel switch is received on 3465 * transmitting interface 3466 */ 3467 struct ieee80211_sub_if_data *iter; 3468 3469 list_for_each_entry_rcu(iter, &local->interfaces, list) { 3470 if (!ieee80211_sdata_running(iter)) 3471 continue; 3472 3473 if (iter == sdata || iter->vif.mbssid_tx_vif != vif) 3474 continue; 3475 3476 ieee80211_queue_work(&iter->local->hw, 3477 &iter->deflink.csa_finalize_work); 3478 } 3479 } 3480 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work); 3481 3482 rcu_read_unlock(); 3483 } 3484 EXPORT_SYMBOL(ieee80211_csa_finish); 3485 3486 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx) 3487 { 3488 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 3489 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 3490 struct ieee80211_local *local = sdata->local; 3491 3492 sdata->deflink.csa_block_tx = block_tx; 3493 sdata_info(sdata, "channel switch failed, disconnecting\n"); 3494 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work); 3495 } 3496 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect); 3497 3498 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata, 3499 u32 *changed) 3500 { 3501 int err; 3502 3503 switch (sdata->vif.type) { 3504 case NL80211_IFTYPE_AP: 3505 if (!sdata->deflink.u.ap.next_beacon) 3506 return -EINVAL; 3507 3508 err = ieee80211_assign_beacon(sdata, &sdata->deflink, 3509 sdata->deflink.u.ap.next_beacon, 3510 NULL, NULL); 3511 ieee80211_free_next_beacon(&sdata->deflink); 3512 3513 if (err < 0) 3514 return err; 3515 *changed |= err; 3516 break; 3517 case NL80211_IFTYPE_ADHOC: 3518 err = ieee80211_ibss_finish_csa(sdata); 3519 if (err < 0) 3520 return err; 3521 *changed |= err; 3522 break; 3523 #ifdef CONFIG_MAC80211_MESH 3524 case NL80211_IFTYPE_MESH_POINT: 3525 err = ieee80211_mesh_finish_csa(sdata); 3526 if (err < 0) 3527 return err; 3528 *changed |= err; 3529 break; 3530 #endif 3531 default: 3532 WARN_ON(1); 3533 return -EINVAL; 3534 } 3535 3536 return 0; 3537 } 3538 3539 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) 3540 { 3541 struct ieee80211_local *local = sdata->local; 3542 u32 changed = 0; 3543 int err; 3544 3545 sdata_assert_lock(sdata); 3546 lockdep_assert_held(&local->mtx); 3547 lockdep_assert_held(&local->chanctx_mtx); 3548 3549 /* 3550 * using reservation isn't immediate as it may be deferred until later 3551 * with multi-vif. once reservation is complete it will re-schedule the 3552 * work with no reserved_chanctx so verify chandef to check if it 3553 * completed successfully 3554 */ 3555 3556 if (sdata->deflink.reserved_chanctx) { 3557 /* 3558 * with multi-vif csa driver may call ieee80211_csa_finish() 3559 * many times while waiting for other interfaces to use their 3560 * reservations 3561 */ 3562 if (sdata->deflink.reserved_ready) 3563 return 0; 3564 3565 return ieee80211_link_use_reserved_context(&sdata->deflink); 3566 } 3567 3568 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, 3569 &sdata->deflink.csa_chandef)) 3570 return -EINVAL; 3571 3572 sdata->vif.bss_conf.csa_active = false; 3573 3574 err = ieee80211_set_after_csa_beacon(sdata, &changed); 3575 if (err) 3576 return err; 3577 3578 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); 3579 3580 if (sdata->deflink.csa_block_tx) { 3581 ieee80211_wake_vif_queues(local, sdata, 3582 IEEE80211_QUEUE_STOP_REASON_CSA); 3583 sdata->deflink.csa_block_tx = false; 3584 } 3585 3586 err = drv_post_channel_switch(sdata); 3587 if (err) 3588 return err; 3589 3590 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0); 3591 3592 return 0; 3593 } 3594 3595 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) 3596 { 3597 if (__ieee80211_csa_finalize(sdata)) { 3598 sdata_info(sdata, "failed to finalize CSA, disconnecting\n"); 3599 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev, 3600 GFP_KERNEL); 3601 } 3602 } 3603 3604 void ieee80211_csa_finalize_work(struct work_struct *work) 3605 { 3606 struct ieee80211_sub_if_data *sdata = 3607 container_of(work, struct ieee80211_sub_if_data, 3608 deflink.csa_finalize_work); 3609 struct ieee80211_local *local = sdata->local; 3610 3611 sdata_lock(sdata); 3612 mutex_lock(&local->mtx); 3613 mutex_lock(&local->chanctx_mtx); 3614 3615 /* AP might have been stopped while waiting for the lock. */ 3616 if (!sdata->vif.bss_conf.csa_active) 3617 goto unlock; 3618 3619 if (!ieee80211_sdata_running(sdata)) 3620 goto unlock; 3621 3622 ieee80211_csa_finalize(sdata); 3623 3624 unlock: 3625 mutex_unlock(&local->chanctx_mtx); 3626 mutex_unlock(&local->mtx); 3627 sdata_unlock(sdata); 3628 } 3629 3630 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata, 3631 struct cfg80211_csa_settings *params, 3632 u32 *changed) 3633 { 3634 struct ieee80211_csa_settings csa = {}; 3635 int err; 3636 3637 switch (sdata->vif.type) { 3638 case NL80211_IFTYPE_AP: 3639 sdata->deflink.u.ap.next_beacon = 3640 cfg80211_beacon_dup(¶ms->beacon_after); 3641 if (!sdata->deflink.u.ap.next_beacon) 3642 return -ENOMEM; 3643 3644 /* 3645 * With a count of 0, we don't have to wait for any 3646 * TBTT before switching, so complete the CSA 3647 * immediately. In theory, with a count == 1 we 3648 * should delay the switch until just before the next 3649 * TBTT, but that would complicate things so we switch 3650 * immediately too. If we would delay the switch 3651 * until the next TBTT, we would have to set the probe 3652 * response here. 3653 * 3654 * TODO: A channel switch with count <= 1 without 3655 * sending a CSA action frame is kind of useless, 3656 * because the clients won't know we're changing 3657 * channels. The action frame must be implemented 3658 * either here or in the userspace. 3659 */ 3660 if (params->count <= 1) 3661 break; 3662 3663 if ((params->n_counter_offsets_beacon > 3664 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) || 3665 (params->n_counter_offsets_presp > 3666 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) { 3667 ieee80211_free_next_beacon(&sdata->deflink); 3668 return -EINVAL; 3669 } 3670 3671 csa.counter_offsets_beacon = params->counter_offsets_beacon; 3672 csa.counter_offsets_presp = params->counter_offsets_presp; 3673 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; 3674 csa.n_counter_offsets_presp = params->n_counter_offsets_presp; 3675 csa.count = params->count; 3676 3677 err = ieee80211_assign_beacon(sdata, &sdata->deflink, 3678 ¶ms->beacon_csa, &csa, 3679 NULL); 3680 if (err < 0) { 3681 ieee80211_free_next_beacon(&sdata->deflink); 3682 return err; 3683 } 3684 *changed |= err; 3685 3686 break; 3687 case NL80211_IFTYPE_ADHOC: 3688 if (!sdata->vif.cfg.ibss_joined) 3689 return -EINVAL; 3690 3691 if (params->chandef.width != sdata->u.ibss.chandef.width) 3692 return -EINVAL; 3693 3694 switch (params->chandef.width) { 3695 case NL80211_CHAN_WIDTH_40: 3696 if (cfg80211_get_chandef_type(¶ms->chandef) != 3697 cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) 3698 return -EINVAL; 3699 break; 3700 case NL80211_CHAN_WIDTH_5: 3701 case NL80211_CHAN_WIDTH_10: 3702 case NL80211_CHAN_WIDTH_20_NOHT: 3703 case NL80211_CHAN_WIDTH_20: 3704 break; 3705 default: 3706 return -EINVAL; 3707 } 3708 3709 /* changes into another band are not supported */ 3710 if (sdata->u.ibss.chandef.chan->band != 3711 params->chandef.chan->band) 3712 return -EINVAL; 3713 3714 /* see comments in the NL80211_IFTYPE_AP block */ 3715 if (params->count > 1) { 3716 err = ieee80211_ibss_csa_beacon(sdata, params); 3717 if (err < 0) 3718 return err; 3719 *changed |= err; 3720 } 3721 3722 ieee80211_send_action_csa(sdata, params); 3723 3724 break; 3725 #ifdef CONFIG_MAC80211_MESH 3726 case NL80211_IFTYPE_MESH_POINT: { 3727 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 3728 3729 /* changes into another band are not supported */ 3730 if (sdata->vif.bss_conf.chandef.chan->band != 3731 params->chandef.chan->band) 3732 return -EINVAL; 3733 3734 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { 3735 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; 3736 if (!ifmsh->pre_value) 3737 ifmsh->pre_value = 1; 3738 else 3739 ifmsh->pre_value++; 3740 } 3741 3742 /* see comments in the NL80211_IFTYPE_AP block */ 3743 if (params->count > 1) { 3744 err = ieee80211_mesh_csa_beacon(sdata, params); 3745 if (err < 0) { 3746 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; 3747 return err; 3748 } 3749 *changed |= err; 3750 } 3751 3752 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) 3753 ieee80211_send_action_csa(sdata, params); 3754 3755 break; 3756 } 3757 #endif 3758 default: 3759 return -EOPNOTSUPP; 3760 } 3761 3762 return 0; 3763 } 3764 3765 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata) 3766 { 3767 sdata->vif.bss_conf.color_change_active = false; 3768 3769 ieee80211_free_next_beacon(&sdata->deflink); 3770 3771 cfg80211_color_change_aborted_notify(sdata->dev); 3772 } 3773 3774 static int 3775 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 3776 struct cfg80211_csa_settings *params) 3777 { 3778 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3779 struct ieee80211_local *local = sdata->local; 3780 struct ieee80211_channel_switch ch_switch; 3781 struct ieee80211_chanctx_conf *conf; 3782 struct ieee80211_chanctx *chanctx; 3783 u32 changed = 0; 3784 int err; 3785 3786 sdata_assert_lock(sdata); 3787 lockdep_assert_held(&local->mtx); 3788 3789 if (!list_empty(&local->roc_list) || local->scanning) 3790 return -EBUSY; 3791 3792 if (sdata->wdev.cac_started) 3793 return -EBUSY; 3794 3795 if (cfg80211_chandef_identical(¶ms->chandef, 3796 &sdata->vif.bss_conf.chandef)) 3797 return -EINVAL; 3798 3799 /* don't allow another channel switch if one is already active. */ 3800 if (sdata->vif.bss_conf.csa_active) 3801 return -EBUSY; 3802 3803 mutex_lock(&local->chanctx_mtx); 3804 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf, 3805 lockdep_is_held(&local->chanctx_mtx)); 3806 if (!conf) { 3807 err = -EBUSY; 3808 goto out; 3809 } 3810 3811 if (params->chandef.chan->freq_offset) { 3812 /* this may work, but is untested */ 3813 err = -EOPNOTSUPP; 3814 goto out; 3815 } 3816 3817 chanctx = container_of(conf, struct ieee80211_chanctx, conf); 3818 3819 ch_switch.timestamp = 0; 3820 ch_switch.device_timestamp = 0; 3821 ch_switch.block_tx = params->block_tx; 3822 ch_switch.chandef = params->chandef; 3823 ch_switch.count = params->count; 3824 3825 err = drv_pre_channel_switch(sdata, &ch_switch); 3826 if (err) 3827 goto out; 3828 3829 err = ieee80211_link_reserve_chanctx(&sdata->deflink, ¶ms->chandef, 3830 chanctx->mode, 3831 params->radar_required); 3832 if (err) 3833 goto out; 3834 3835 /* if reservation is invalid then this will fail */ 3836 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0); 3837 if (err) { 3838 ieee80211_link_unreserve_chanctx(&sdata->deflink); 3839 goto out; 3840 } 3841 3842 /* if there is a color change in progress, abort it */ 3843 if (sdata->vif.bss_conf.color_change_active) 3844 ieee80211_color_change_abort(sdata); 3845 3846 err = ieee80211_set_csa_beacon(sdata, params, &changed); 3847 if (err) { 3848 ieee80211_link_unreserve_chanctx(&sdata->deflink); 3849 goto out; 3850 } 3851 3852 sdata->deflink.csa_chandef = params->chandef; 3853 sdata->deflink.csa_block_tx = params->block_tx; 3854 sdata->vif.bss_conf.csa_active = true; 3855 3856 if (sdata->deflink.csa_block_tx) 3857 ieee80211_stop_vif_queues(local, sdata, 3858 IEEE80211_QUEUE_STOP_REASON_CSA); 3859 3860 cfg80211_ch_switch_started_notify(sdata->dev, 3861 &sdata->deflink.csa_chandef, 0, 3862 params->count, params->block_tx); 3863 3864 if (changed) { 3865 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3866 changed); 3867 drv_channel_switch_beacon(sdata, ¶ms->chandef); 3868 } else { 3869 /* if the beacon didn't change, we can finalize immediately */ 3870 ieee80211_csa_finalize(sdata); 3871 } 3872 3873 out: 3874 mutex_unlock(&local->chanctx_mtx); 3875 return err; 3876 } 3877 3878 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 3879 struct cfg80211_csa_settings *params) 3880 { 3881 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3882 struct ieee80211_local *local = sdata->local; 3883 int err; 3884 3885 mutex_lock(&local->mtx); 3886 err = __ieee80211_channel_switch(wiphy, dev, params); 3887 mutex_unlock(&local->mtx); 3888 3889 return err; 3890 } 3891 3892 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) 3893 { 3894 lockdep_assert_held(&local->mtx); 3895 3896 local->roc_cookie_counter++; 3897 3898 /* wow, you wrapped 64 bits ... more likely a bug */ 3899 if (WARN_ON(local->roc_cookie_counter == 0)) 3900 local->roc_cookie_counter++; 3901 3902 return local->roc_cookie_counter; 3903 } 3904 3905 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, 3906 u64 *cookie, gfp_t gfp) 3907 { 3908 unsigned long spin_flags; 3909 struct sk_buff *ack_skb; 3910 int id; 3911 3912 ack_skb = skb_copy(skb, gfp); 3913 if (!ack_skb) 3914 return -ENOMEM; 3915 3916 spin_lock_irqsave(&local->ack_status_lock, spin_flags); 3917 id = idr_alloc(&local->ack_status_frames, ack_skb, 3918 1, 0x2000, GFP_ATOMIC); 3919 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); 3920 3921 if (id < 0) { 3922 kfree_skb(ack_skb); 3923 return -ENOMEM; 3924 } 3925 3926 IEEE80211_SKB_CB(skb)->ack_frame_id = id; 3927 3928 *cookie = ieee80211_mgmt_tx_cookie(local); 3929 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; 3930 3931 return 0; 3932 } 3933 3934 static void 3935 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy, 3936 struct wireless_dev *wdev, 3937 struct mgmt_frame_regs *upd) 3938 { 3939 struct ieee80211_local *local = wiphy_priv(wiphy); 3940 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3941 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4); 3942 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4); 3943 bool global_change, intf_change; 3944 3945 global_change = 3946 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) || 3947 (local->rx_mcast_action_reg != 3948 !!(upd->global_mcast_stypes & action_mask)); 3949 local->probe_req_reg = upd->global_stypes & preq_mask; 3950 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask; 3951 3952 intf_change = (sdata->vif.probe_req_reg != 3953 !!(upd->interface_stypes & preq_mask)) || 3954 (sdata->vif.rx_mcast_action_reg != 3955 !!(upd->interface_mcast_stypes & action_mask)); 3956 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask; 3957 sdata->vif.rx_mcast_action_reg = 3958 upd->interface_mcast_stypes & action_mask; 3959 3960 if (!local->open_count) 3961 return; 3962 3963 if (intf_change && ieee80211_sdata_running(sdata)) 3964 drv_config_iface_filter(local, sdata, 3965 sdata->vif.probe_req_reg ? 3966 FIF_PROBE_REQ : 0, 3967 FIF_PROBE_REQ); 3968 3969 if (global_change) 3970 ieee80211_configure_filter(local); 3971 } 3972 3973 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) 3974 { 3975 struct ieee80211_local *local = wiphy_priv(wiphy); 3976 3977 if (local->started) 3978 return -EOPNOTSUPP; 3979 3980 return drv_set_antenna(local, tx_ant, rx_ant); 3981 } 3982 3983 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) 3984 { 3985 struct ieee80211_local *local = wiphy_priv(wiphy); 3986 3987 return drv_get_antenna(local, tx_ant, rx_ant); 3988 } 3989 3990 static int ieee80211_set_rekey_data(struct wiphy *wiphy, 3991 struct net_device *dev, 3992 struct cfg80211_gtk_rekey_data *data) 3993 { 3994 struct ieee80211_local *local = wiphy_priv(wiphy); 3995 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3996 3997 if (!local->ops->set_rekey_data) 3998 return -EOPNOTSUPP; 3999 4000 drv_set_rekey_data(local, sdata, data); 4001 4002 return 0; 4003 } 4004 4005 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, 4006 const u8 *peer, u64 *cookie) 4007 { 4008 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4009 struct ieee80211_local *local = sdata->local; 4010 struct ieee80211_qos_hdr *nullfunc; 4011 struct sk_buff *skb; 4012 int size = sizeof(*nullfunc); 4013 __le16 fc; 4014 bool qos; 4015 struct ieee80211_tx_info *info; 4016 struct sta_info *sta; 4017 struct ieee80211_chanctx_conf *chanctx_conf; 4018 enum nl80211_band band; 4019 int ret; 4020 4021 /* the lock is needed to assign the cookie later */ 4022 mutex_lock(&local->mtx); 4023 4024 rcu_read_lock(); 4025 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 4026 if (WARN_ON(!chanctx_conf)) { 4027 ret = -EINVAL; 4028 goto unlock; 4029 } 4030 band = chanctx_conf->def.chan->band; 4031 sta = sta_info_get_bss(sdata, peer); 4032 if (sta) { 4033 qos = sta->sta.wme; 4034 } else { 4035 ret = -ENOLINK; 4036 goto unlock; 4037 } 4038 4039 if (qos) { 4040 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 4041 IEEE80211_STYPE_QOS_NULLFUNC | 4042 IEEE80211_FCTL_FROMDS); 4043 } else { 4044 size -= 2; 4045 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 4046 IEEE80211_STYPE_NULLFUNC | 4047 IEEE80211_FCTL_FROMDS); 4048 } 4049 4050 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); 4051 if (!skb) { 4052 ret = -ENOMEM; 4053 goto unlock; 4054 } 4055 4056 skb->dev = dev; 4057 4058 skb_reserve(skb, local->hw.extra_tx_headroom); 4059 4060 nullfunc = skb_put(skb, size); 4061 nullfunc->frame_control = fc; 4062 nullfunc->duration_id = 0; 4063 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 4064 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 4065 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); 4066 nullfunc->seq_ctrl = 0; 4067 4068 info = IEEE80211_SKB_CB(skb); 4069 4070 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | 4071 IEEE80211_TX_INTFL_NL80211_FRAME_TX; 4072 info->band = band; 4073 4074 skb_set_queue_mapping(skb, IEEE80211_AC_VO); 4075 skb->priority = 7; 4076 if (qos) 4077 nullfunc->qos_ctrl = cpu_to_le16(7); 4078 4079 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); 4080 if (ret) { 4081 kfree_skb(skb); 4082 goto unlock; 4083 } 4084 4085 local_bh_disable(); 4086 ieee80211_xmit(sdata, sta, skb); 4087 local_bh_enable(); 4088 4089 ret = 0; 4090 unlock: 4091 rcu_read_unlock(); 4092 mutex_unlock(&local->mtx); 4093 4094 return ret; 4095 } 4096 4097 static int ieee80211_cfg_get_channel(struct wiphy *wiphy, 4098 struct wireless_dev *wdev, 4099 unsigned int link_id, 4100 struct cfg80211_chan_def *chandef) 4101 { 4102 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 4103 struct ieee80211_local *local = wiphy_priv(wiphy); 4104 struct ieee80211_chanctx_conf *chanctx_conf; 4105 struct ieee80211_link_data *link; 4106 int ret = -ENODATA; 4107 4108 rcu_read_lock(); 4109 link = rcu_dereference(sdata->link[link_id]); 4110 if (!link) { 4111 ret = -ENOLINK; 4112 goto out; 4113 } 4114 4115 chanctx_conf = rcu_dereference(link->conf->chanctx_conf); 4116 if (chanctx_conf) { 4117 *chandef = link->conf->chandef; 4118 ret = 0; 4119 } else if (local->open_count > 0 && 4120 local->open_count == local->monitors && 4121 sdata->vif.type == NL80211_IFTYPE_MONITOR) { 4122 if (local->use_chanctx) 4123 *chandef = local->monitor_chandef; 4124 else 4125 *chandef = local->_oper_chandef; 4126 ret = 0; 4127 } 4128 out: 4129 rcu_read_unlock(); 4130 4131 return ret; 4132 } 4133 4134 #ifdef CONFIG_PM 4135 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) 4136 { 4137 drv_set_wakeup(wiphy_priv(wiphy), enabled); 4138 } 4139 #endif 4140 4141 static int ieee80211_set_qos_map(struct wiphy *wiphy, 4142 struct net_device *dev, 4143 struct cfg80211_qos_map *qos_map) 4144 { 4145 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4146 struct mac80211_qos_map *new_qos_map, *old_qos_map; 4147 4148 if (qos_map) { 4149 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL); 4150 if (!new_qos_map) 4151 return -ENOMEM; 4152 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); 4153 } else { 4154 /* A NULL qos_map was passed to disable QoS mapping */ 4155 new_qos_map = NULL; 4156 } 4157 4158 old_qos_map = sdata_dereference(sdata->qos_map, sdata); 4159 rcu_assign_pointer(sdata->qos_map, new_qos_map); 4160 if (old_qos_map) 4161 kfree_rcu(old_qos_map, rcu_head); 4162 4163 return 0; 4164 } 4165 4166 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, 4167 struct net_device *dev, 4168 unsigned int link_id, 4169 struct cfg80211_chan_def *chandef) 4170 { 4171 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4172 struct ieee80211_link_data *link; 4173 int ret; 4174 u32 changed = 0; 4175 4176 link = sdata_dereference(sdata->link[link_id], sdata); 4177 4178 ret = ieee80211_link_change_bandwidth(link, chandef, &changed); 4179 if (ret == 0) 4180 ieee80211_link_info_change_notify(sdata, link, changed); 4181 4182 return ret; 4183 } 4184 4185 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, 4186 u8 tsid, const u8 *peer, u8 up, 4187 u16 admitted_time) 4188 { 4189 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4190 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4191 int ac = ieee802_1d_to_ac[up]; 4192 4193 if (sdata->vif.type != NL80211_IFTYPE_STATION) 4194 return -EOPNOTSUPP; 4195 4196 if (!(sdata->wmm_acm & BIT(up))) 4197 return -EINVAL; 4198 4199 if (ifmgd->tx_tspec[ac].admitted_time) 4200 return -EBUSY; 4201 4202 if (admitted_time) { 4203 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; 4204 ifmgd->tx_tspec[ac].tsid = tsid; 4205 ifmgd->tx_tspec[ac].up = up; 4206 } 4207 4208 return 0; 4209 } 4210 4211 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, 4212 u8 tsid, const u8 *peer) 4213 { 4214 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4215 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4216 struct ieee80211_local *local = wiphy_priv(wiphy); 4217 int ac; 4218 4219 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 4220 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; 4221 4222 /* skip unused entries */ 4223 if (!tx_tspec->admitted_time) 4224 continue; 4225 4226 if (tx_tspec->tsid != tsid) 4227 continue; 4228 4229 /* due to this new packets will be reassigned to non-ACM ACs */ 4230 tx_tspec->up = -1; 4231 4232 /* Make sure that all packets have been sent to avoid to 4233 * restore the QoS params on packets that are still on the 4234 * queues. 4235 */ 4236 synchronize_net(); 4237 ieee80211_flush_queues(local, sdata, false); 4238 4239 /* restore the normal QoS parameters 4240 * (unconditionally to avoid races) 4241 */ 4242 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; 4243 tx_tspec->downgraded = false; 4244 ieee80211_sta_handle_tspec_ac_params(sdata); 4245 4246 /* finally clear all the data */ 4247 memset(tx_tspec, 0, sizeof(*tx_tspec)); 4248 4249 return 0; 4250 } 4251 4252 return -ENOENT; 4253 } 4254 4255 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, 4256 u8 inst_id, 4257 enum nl80211_nan_func_term_reason reason, 4258 gfp_t gfp) 4259 { 4260 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4261 struct cfg80211_nan_func *func; 4262 u64 cookie; 4263 4264 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) 4265 return; 4266 4267 spin_lock_bh(&sdata->u.nan.func_lock); 4268 4269 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id); 4270 if (WARN_ON(!func)) { 4271 spin_unlock_bh(&sdata->u.nan.func_lock); 4272 return; 4273 } 4274 4275 cookie = func->cookie; 4276 idr_remove(&sdata->u.nan.function_inst_ids, inst_id); 4277 4278 spin_unlock_bh(&sdata->u.nan.func_lock); 4279 4280 cfg80211_free_nan_func(func); 4281 4282 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, 4283 reason, cookie, gfp); 4284 } 4285 EXPORT_SYMBOL(ieee80211_nan_func_terminated); 4286 4287 void ieee80211_nan_func_match(struct ieee80211_vif *vif, 4288 struct cfg80211_nan_match_params *match, 4289 gfp_t gfp) 4290 { 4291 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4292 struct cfg80211_nan_func *func; 4293 4294 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) 4295 return; 4296 4297 spin_lock_bh(&sdata->u.nan.func_lock); 4298 4299 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id); 4300 if (WARN_ON(!func)) { 4301 spin_unlock_bh(&sdata->u.nan.func_lock); 4302 return; 4303 } 4304 match->cookie = func->cookie; 4305 4306 spin_unlock_bh(&sdata->u.nan.func_lock); 4307 4308 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); 4309 } 4310 EXPORT_SYMBOL(ieee80211_nan_func_match); 4311 4312 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, 4313 struct net_device *dev, 4314 const bool enabled) 4315 { 4316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4317 4318 sdata->u.ap.multicast_to_unicast = enabled; 4319 4320 return 0; 4321 } 4322 4323 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, 4324 struct txq_info *txqi) 4325 { 4326 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { 4327 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); 4328 txqstats->backlog_bytes = txqi->tin.backlog_bytes; 4329 } 4330 4331 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { 4332 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); 4333 txqstats->backlog_packets = txqi->tin.backlog_packets; 4334 } 4335 4336 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { 4337 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); 4338 txqstats->flows = txqi->tin.flows; 4339 } 4340 4341 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { 4342 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); 4343 txqstats->drops = txqi->cstats.drop_count; 4344 } 4345 4346 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { 4347 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); 4348 txqstats->ecn_marks = txqi->cstats.ecn_mark; 4349 } 4350 4351 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { 4352 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); 4353 txqstats->overlimit = txqi->tin.overlimit; 4354 } 4355 4356 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { 4357 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); 4358 txqstats->collisions = txqi->tin.collisions; 4359 } 4360 4361 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { 4362 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); 4363 txqstats->tx_bytes = txqi->tin.tx_bytes; 4364 } 4365 4366 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { 4367 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); 4368 txqstats->tx_packets = txqi->tin.tx_packets; 4369 } 4370 } 4371 4372 static int ieee80211_get_txq_stats(struct wiphy *wiphy, 4373 struct wireless_dev *wdev, 4374 struct cfg80211_txq_stats *txqstats) 4375 { 4376 struct ieee80211_local *local = wiphy_priv(wiphy); 4377 struct ieee80211_sub_if_data *sdata; 4378 int ret = 0; 4379 4380 spin_lock_bh(&local->fq.lock); 4381 rcu_read_lock(); 4382 4383 if (wdev) { 4384 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 4385 if (!sdata->vif.txq) { 4386 ret = 1; 4387 goto out; 4388 } 4389 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); 4390 } else { 4391 /* phy stats */ 4392 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | 4393 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | 4394 BIT(NL80211_TXQ_STATS_OVERLIMIT) | 4395 BIT(NL80211_TXQ_STATS_OVERMEMORY) | 4396 BIT(NL80211_TXQ_STATS_COLLISIONS) | 4397 BIT(NL80211_TXQ_STATS_MAX_FLOWS); 4398 txqstats->backlog_packets = local->fq.backlog; 4399 txqstats->backlog_bytes = local->fq.memory_usage; 4400 txqstats->overlimit = local->fq.overlimit; 4401 txqstats->overmemory = local->fq.overmemory; 4402 txqstats->collisions = local->fq.collisions; 4403 txqstats->max_flows = local->fq.flows_cnt; 4404 } 4405 4406 out: 4407 rcu_read_unlock(); 4408 spin_unlock_bh(&local->fq.lock); 4409 4410 return ret; 4411 } 4412 4413 static int 4414 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy, 4415 struct net_device *dev, 4416 struct cfg80211_ftm_responder_stats *ftm_stats) 4417 { 4418 struct ieee80211_local *local = wiphy_priv(wiphy); 4419 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4420 4421 return drv_get_ftm_responder_stats(local, sdata, ftm_stats); 4422 } 4423 4424 static int 4425 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, 4426 struct cfg80211_pmsr_request *request) 4427 { 4428 struct ieee80211_local *local = wiphy_priv(wiphy); 4429 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); 4430 4431 return drv_start_pmsr(local, sdata, request); 4432 } 4433 4434 static void 4435 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, 4436 struct cfg80211_pmsr_request *request) 4437 { 4438 struct ieee80211_local *local = wiphy_priv(wiphy); 4439 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); 4440 4441 return drv_abort_pmsr(local, sdata, request); 4442 } 4443 4444 static int ieee80211_set_tid_config(struct wiphy *wiphy, 4445 struct net_device *dev, 4446 struct cfg80211_tid_config *tid_conf) 4447 { 4448 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4449 struct sta_info *sta; 4450 int ret; 4451 4452 if (!sdata->local->ops->set_tid_config) 4453 return -EOPNOTSUPP; 4454 4455 if (!tid_conf->peer) 4456 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf); 4457 4458 mutex_lock(&sdata->local->sta_mtx); 4459 sta = sta_info_get_bss(sdata, tid_conf->peer); 4460 if (!sta) { 4461 mutex_unlock(&sdata->local->sta_mtx); 4462 return -ENOENT; 4463 } 4464 4465 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf); 4466 mutex_unlock(&sdata->local->sta_mtx); 4467 4468 return ret; 4469 } 4470 4471 static int ieee80211_reset_tid_config(struct wiphy *wiphy, 4472 struct net_device *dev, 4473 const u8 *peer, u8 tids) 4474 { 4475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4476 struct sta_info *sta; 4477 int ret; 4478 4479 if (!sdata->local->ops->reset_tid_config) 4480 return -EOPNOTSUPP; 4481 4482 if (!peer) 4483 return drv_reset_tid_config(sdata->local, sdata, NULL, tids); 4484 4485 mutex_lock(&sdata->local->sta_mtx); 4486 sta = sta_info_get_bss(sdata, peer); 4487 if (!sta) { 4488 mutex_unlock(&sdata->local->sta_mtx); 4489 return -ENOENT; 4490 } 4491 4492 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids); 4493 mutex_unlock(&sdata->local->sta_mtx); 4494 4495 return ret; 4496 } 4497 4498 static int ieee80211_set_sar_specs(struct wiphy *wiphy, 4499 struct cfg80211_sar_specs *sar) 4500 { 4501 struct ieee80211_local *local = wiphy_priv(wiphy); 4502 4503 if (!local->ops->set_sar_specs) 4504 return -EOPNOTSUPP; 4505 4506 return local->ops->set_sar_specs(&local->hw, sar); 4507 } 4508 4509 static int 4510 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata, 4511 u32 *changed) 4512 { 4513 switch (sdata->vif.type) { 4514 case NL80211_IFTYPE_AP: { 4515 int ret; 4516 4517 if (!sdata->deflink.u.ap.next_beacon) 4518 return -EINVAL; 4519 4520 ret = ieee80211_assign_beacon(sdata, &sdata->deflink, 4521 sdata->deflink.u.ap.next_beacon, 4522 NULL, NULL); 4523 ieee80211_free_next_beacon(&sdata->deflink); 4524 4525 if (ret < 0) 4526 return ret; 4527 4528 *changed |= ret; 4529 break; 4530 } 4531 default: 4532 WARN_ON_ONCE(1); 4533 return -EINVAL; 4534 } 4535 4536 return 0; 4537 } 4538 4539 static int 4540 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata, 4541 struct cfg80211_color_change_settings *params, 4542 u32 *changed) 4543 { 4544 struct ieee80211_color_change_settings color_change = {}; 4545 int err; 4546 4547 switch (sdata->vif.type) { 4548 case NL80211_IFTYPE_AP: 4549 sdata->deflink.u.ap.next_beacon = 4550 cfg80211_beacon_dup(¶ms->beacon_next); 4551 if (!sdata->deflink.u.ap.next_beacon) 4552 return -ENOMEM; 4553 4554 if (params->count <= 1) 4555 break; 4556 4557 color_change.counter_offset_beacon = 4558 params->counter_offset_beacon; 4559 color_change.counter_offset_presp = 4560 params->counter_offset_presp; 4561 color_change.count = params->count; 4562 4563 err = ieee80211_assign_beacon(sdata, &sdata->deflink, 4564 ¶ms->beacon_color_change, 4565 NULL, &color_change); 4566 if (err < 0) { 4567 ieee80211_free_next_beacon(&sdata->deflink); 4568 return err; 4569 } 4570 *changed |= err; 4571 break; 4572 default: 4573 return -EOPNOTSUPP; 4574 } 4575 4576 return 0; 4577 } 4578 4579 static void 4580 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata, 4581 u8 color, int enable, u32 changed) 4582 { 4583 sdata->vif.bss_conf.he_bss_color.color = color; 4584 sdata->vif.bss_conf.he_bss_color.enabled = enable; 4585 changed |= BSS_CHANGED_HE_BSS_COLOR; 4586 4587 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); 4588 4589 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) { 4590 struct ieee80211_sub_if_data *child; 4591 4592 mutex_lock(&sdata->local->iflist_mtx); 4593 list_for_each_entry(child, &sdata->local->interfaces, list) { 4594 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) { 4595 child->vif.bss_conf.he_bss_color.color = color; 4596 child->vif.bss_conf.he_bss_color.enabled = enable; 4597 ieee80211_link_info_change_notify(child, 4598 &child->deflink, 4599 BSS_CHANGED_HE_BSS_COLOR); 4600 } 4601 } 4602 mutex_unlock(&sdata->local->iflist_mtx); 4603 } 4604 } 4605 4606 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata) 4607 { 4608 struct ieee80211_local *local = sdata->local; 4609 u32 changed = 0; 4610 int err; 4611 4612 sdata_assert_lock(sdata); 4613 lockdep_assert_held(&local->mtx); 4614 4615 sdata->vif.bss_conf.color_change_active = false; 4616 4617 err = ieee80211_set_after_color_change_beacon(sdata, &changed); 4618 if (err) { 4619 cfg80211_color_change_aborted_notify(sdata->dev); 4620 return err; 4621 } 4622 4623 ieee80211_color_change_bss_config_notify(sdata, 4624 sdata->vif.bss_conf.color_change_color, 4625 1, changed); 4626 cfg80211_color_change_notify(sdata->dev); 4627 4628 return 0; 4629 } 4630 4631 void ieee80211_color_change_finalize_work(struct work_struct *work) 4632 { 4633 struct ieee80211_sub_if_data *sdata = 4634 container_of(work, struct ieee80211_sub_if_data, 4635 deflink.color_change_finalize_work); 4636 struct ieee80211_local *local = sdata->local; 4637 4638 sdata_lock(sdata); 4639 mutex_lock(&local->mtx); 4640 4641 /* AP might have been stopped while waiting for the lock. */ 4642 if (!sdata->vif.bss_conf.color_change_active) 4643 goto unlock; 4644 4645 if (!ieee80211_sdata_running(sdata)) 4646 goto unlock; 4647 4648 ieee80211_color_change_finalize(sdata); 4649 4650 unlock: 4651 mutex_unlock(&local->mtx); 4652 sdata_unlock(sdata); 4653 } 4654 4655 void ieee80211_color_change_finish(struct ieee80211_vif *vif) 4656 { 4657 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4658 4659 ieee80211_queue_work(&sdata->local->hw, 4660 &sdata->deflink.color_change_finalize_work); 4661 } 4662 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish); 4663 4664 void 4665 ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif, 4666 u64 color_bitmap, gfp_t gfp) 4667 { 4668 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4669 4670 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) 4671 return; 4672 4673 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp); 4674 } 4675 EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify); 4676 4677 static int 4678 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, 4679 struct cfg80211_color_change_settings *params) 4680 { 4681 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4682 struct ieee80211_local *local = sdata->local; 4683 u32 changed = 0; 4684 int err; 4685 4686 sdata_assert_lock(sdata); 4687 4688 if (sdata->vif.bss_conf.nontransmitted) 4689 return -EINVAL; 4690 4691 mutex_lock(&local->mtx); 4692 4693 /* don't allow another color change if one is already active or if csa 4694 * is active 4695 */ 4696 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) { 4697 err = -EBUSY; 4698 goto out; 4699 } 4700 4701 err = ieee80211_set_color_change_beacon(sdata, params, &changed); 4702 if (err) 4703 goto out; 4704 4705 sdata->vif.bss_conf.color_change_active = true; 4706 sdata->vif.bss_conf.color_change_color = params->color; 4707 4708 cfg80211_color_change_started_notify(sdata->dev, params->count); 4709 4710 if (changed) 4711 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed); 4712 else 4713 /* if the beacon didn't change, we can finalize immediately */ 4714 ieee80211_color_change_finalize(sdata); 4715 4716 out: 4717 mutex_unlock(&local->mtx); 4718 4719 return err; 4720 } 4721 4722 static int 4723 ieee80211_set_radar_background(struct wiphy *wiphy, 4724 struct cfg80211_chan_def *chandef) 4725 { 4726 struct ieee80211_local *local = wiphy_priv(wiphy); 4727 4728 if (!local->ops->set_radar_background) 4729 return -EOPNOTSUPP; 4730 4731 return local->ops->set_radar_background(&local->hw, chandef); 4732 } 4733 4734 static int ieee80211_add_intf_link(struct wiphy *wiphy, 4735 struct wireless_dev *wdev, 4736 unsigned int link_id) 4737 { 4738 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 4739 4740 if (wdev->use_4addr) 4741 return -EOPNOTSUPP; 4742 4743 return ieee80211_vif_set_links(sdata, wdev->valid_links); 4744 } 4745 4746 static void ieee80211_del_intf_link(struct wiphy *wiphy, 4747 struct wireless_dev *wdev, 4748 unsigned int link_id) 4749 { 4750 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 4751 4752 ieee80211_vif_set_links(sdata, wdev->valid_links); 4753 } 4754 4755 static int sta_add_link_station(struct ieee80211_local *local, 4756 struct ieee80211_sub_if_data *sdata, 4757 struct link_station_parameters *params) 4758 { 4759 struct sta_info *sta; 4760 int ret; 4761 4762 sta = sta_info_get_bss(sdata, params->mld_mac); 4763 if (!sta) 4764 return -ENOENT; 4765 4766 if (!sta->sta.valid_links) 4767 return -EINVAL; 4768 4769 if (sta->sta.valid_links & BIT(params->link_id)) 4770 return -EALREADY; 4771 4772 ret = ieee80211_sta_allocate_link(sta, params->link_id); 4773 if (ret) 4774 return ret; 4775 4776 ret = sta_link_apply_parameters(local, sta, true, params); 4777 if (ret) { 4778 ieee80211_sta_free_link(sta, params->link_id); 4779 return ret; 4780 } 4781 4782 /* ieee80211_sta_activate_link frees the link upon failure */ 4783 return ieee80211_sta_activate_link(sta, params->link_id); 4784 } 4785 4786 static int 4787 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev, 4788 struct link_station_parameters *params) 4789 { 4790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4791 struct ieee80211_local *local = wiphy_priv(wiphy); 4792 int ret; 4793 4794 mutex_lock(&sdata->local->sta_mtx); 4795 ret = sta_add_link_station(local, sdata, params); 4796 mutex_unlock(&sdata->local->sta_mtx); 4797 4798 return ret; 4799 } 4800 4801 static int sta_mod_link_station(struct ieee80211_local *local, 4802 struct ieee80211_sub_if_data *sdata, 4803 struct link_station_parameters *params) 4804 { 4805 struct sta_info *sta; 4806 4807 sta = sta_info_get_bss(sdata, params->mld_mac); 4808 if (!sta) 4809 return -ENOENT; 4810 4811 if (!(sta->sta.valid_links & BIT(params->link_id))) 4812 return -EINVAL; 4813 4814 return sta_link_apply_parameters(local, sta, false, params); 4815 } 4816 4817 static int 4818 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev, 4819 struct link_station_parameters *params) 4820 { 4821 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4822 struct ieee80211_local *local = wiphy_priv(wiphy); 4823 int ret; 4824 4825 mutex_lock(&sdata->local->sta_mtx); 4826 ret = sta_mod_link_station(local, sdata, params); 4827 mutex_unlock(&sdata->local->sta_mtx); 4828 4829 return ret; 4830 } 4831 4832 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata, 4833 struct link_station_del_parameters *params) 4834 { 4835 struct sta_info *sta; 4836 4837 sta = sta_info_get_bss(sdata, params->mld_mac); 4838 if (!sta) 4839 return -ENOENT; 4840 4841 if (!(sta->sta.valid_links & BIT(params->link_id))) 4842 return -EINVAL; 4843 4844 /* must not create a STA without links */ 4845 if (sta->sta.valid_links == BIT(params->link_id)) 4846 return -EINVAL; 4847 4848 ieee80211_sta_remove_link(sta, params->link_id); 4849 4850 return 0; 4851 } 4852 4853 static int 4854 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev, 4855 struct link_station_del_parameters *params) 4856 { 4857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4858 int ret; 4859 4860 mutex_lock(&sdata->local->sta_mtx); 4861 ret = sta_del_link_station(sdata, params); 4862 mutex_unlock(&sdata->local->sta_mtx); 4863 4864 return ret; 4865 } 4866 4867 const struct cfg80211_ops mac80211_config_ops = { 4868 .add_virtual_intf = ieee80211_add_iface, 4869 .del_virtual_intf = ieee80211_del_iface, 4870 .change_virtual_intf = ieee80211_change_iface, 4871 .start_p2p_device = ieee80211_start_p2p_device, 4872 .stop_p2p_device = ieee80211_stop_p2p_device, 4873 .add_key = ieee80211_add_key, 4874 .del_key = ieee80211_del_key, 4875 .get_key = ieee80211_get_key, 4876 .set_default_key = ieee80211_config_default_key, 4877 .set_default_mgmt_key = ieee80211_config_default_mgmt_key, 4878 .set_default_beacon_key = ieee80211_config_default_beacon_key, 4879 .start_ap = ieee80211_start_ap, 4880 .change_beacon = ieee80211_change_beacon, 4881 .stop_ap = ieee80211_stop_ap, 4882 .add_station = ieee80211_add_station, 4883 .del_station = ieee80211_del_station, 4884 .change_station = ieee80211_change_station, 4885 .get_station = ieee80211_get_station, 4886 .dump_station = ieee80211_dump_station, 4887 .dump_survey = ieee80211_dump_survey, 4888 #ifdef CONFIG_MAC80211_MESH 4889 .add_mpath = ieee80211_add_mpath, 4890 .del_mpath = ieee80211_del_mpath, 4891 .change_mpath = ieee80211_change_mpath, 4892 .get_mpath = ieee80211_get_mpath, 4893 .dump_mpath = ieee80211_dump_mpath, 4894 .get_mpp = ieee80211_get_mpp, 4895 .dump_mpp = ieee80211_dump_mpp, 4896 .update_mesh_config = ieee80211_update_mesh_config, 4897 .get_mesh_config = ieee80211_get_mesh_config, 4898 .join_mesh = ieee80211_join_mesh, 4899 .leave_mesh = ieee80211_leave_mesh, 4900 #endif 4901 .join_ocb = ieee80211_join_ocb, 4902 .leave_ocb = ieee80211_leave_ocb, 4903 .change_bss = ieee80211_change_bss, 4904 .set_txq_params = ieee80211_set_txq_params, 4905 .set_monitor_channel = ieee80211_set_monitor_channel, 4906 .suspend = ieee80211_suspend, 4907 .resume = ieee80211_resume, 4908 .scan = ieee80211_scan, 4909 .abort_scan = ieee80211_abort_scan, 4910 .sched_scan_start = ieee80211_sched_scan_start, 4911 .sched_scan_stop = ieee80211_sched_scan_stop, 4912 .auth = ieee80211_auth, 4913 .assoc = ieee80211_assoc, 4914 .deauth = ieee80211_deauth, 4915 .disassoc = ieee80211_disassoc, 4916 .join_ibss = ieee80211_join_ibss, 4917 .leave_ibss = ieee80211_leave_ibss, 4918 .set_mcast_rate = ieee80211_set_mcast_rate, 4919 .set_wiphy_params = ieee80211_set_wiphy_params, 4920 .set_tx_power = ieee80211_set_tx_power, 4921 .get_tx_power = ieee80211_get_tx_power, 4922 .rfkill_poll = ieee80211_rfkill_poll, 4923 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) 4924 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) 4925 .set_power_mgmt = ieee80211_set_power_mgmt, 4926 .set_bitrate_mask = ieee80211_set_bitrate_mask, 4927 .remain_on_channel = ieee80211_remain_on_channel, 4928 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, 4929 .mgmt_tx = ieee80211_mgmt_tx, 4930 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, 4931 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, 4932 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, 4933 .update_mgmt_frame_registrations = 4934 ieee80211_update_mgmt_frame_registrations, 4935 .set_antenna = ieee80211_set_antenna, 4936 .get_antenna = ieee80211_get_antenna, 4937 .set_rekey_data = ieee80211_set_rekey_data, 4938 .tdls_oper = ieee80211_tdls_oper, 4939 .tdls_mgmt = ieee80211_tdls_mgmt, 4940 .tdls_channel_switch = ieee80211_tdls_channel_switch, 4941 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, 4942 .probe_client = ieee80211_probe_client, 4943 .set_noack_map = ieee80211_set_noack_map, 4944 #ifdef CONFIG_PM 4945 .set_wakeup = ieee80211_set_wakeup, 4946 #endif 4947 .get_channel = ieee80211_cfg_get_channel, 4948 .start_radar_detection = ieee80211_start_radar_detection, 4949 .end_cac = ieee80211_end_cac, 4950 .channel_switch = ieee80211_channel_switch, 4951 .set_qos_map = ieee80211_set_qos_map, 4952 .set_ap_chanwidth = ieee80211_set_ap_chanwidth, 4953 .add_tx_ts = ieee80211_add_tx_ts, 4954 .del_tx_ts = ieee80211_del_tx_ts, 4955 .start_nan = ieee80211_start_nan, 4956 .stop_nan = ieee80211_stop_nan, 4957 .nan_change_conf = ieee80211_nan_change_conf, 4958 .add_nan_func = ieee80211_add_nan_func, 4959 .del_nan_func = ieee80211_del_nan_func, 4960 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, 4961 .tx_control_port = ieee80211_tx_control_port, 4962 .get_txq_stats = ieee80211_get_txq_stats, 4963 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, 4964 .start_pmsr = ieee80211_start_pmsr, 4965 .abort_pmsr = ieee80211_abort_pmsr, 4966 .probe_mesh_link = ieee80211_probe_mesh_link, 4967 .set_tid_config = ieee80211_set_tid_config, 4968 .reset_tid_config = ieee80211_reset_tid_config, 4969 .set_sar_specs = ieee80211_set_sar_specs, 4970 .color_change = ieee80211_color_change, 4971 .set_radar_background = ieee80211_set_radar_background, 4972 .add_intf_link = ieee80211_add_intf_link, 4973 .del_intf_link = ieee80211_del_intf_link, 4974 .add_link_station = ieee80211_add_link_station, 4975 .mod_link_station = ieee80211_mod_link_station, 4976 .del_link_station = ieee80211_del_link_station, 4977 }; 4978