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