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 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab, 2513 params->ext_capab_len); 2514 2515 /* 2516 * cfg80211 validates this (1-2007) and allows setting the AID 2517 * only when creating a new station entry. For S1G APs, the current 2518 * implementation supports a maximum of 1600 AIDs. 2519 */ 2520 if (params->aid) { 2521 if (sdata->vif.cfg.s1g && 2522 params->aid > IEEE80211_MAX_SUPPORTED_S1G_AID) 2523 return -EINVAL; 2524 2525 sta->sta.aid = params->aid; 2526 } 2527 2528 /* 2529 * Some of the following updates would be racy if called on an 2530 * existing station, via ieee80211_change_station(). However, 2531 * all such changes are rejected by cfg80211 except for updates 2532 * changing the supported rates on an existing but not yet used 2533 * TDLS peer. 2534 */ 2535 2536 if (params->listen_interval >= 0) 2537 sta->listen_interval = params->listen_interval; 2538 2539 if (params->eml_cap_present) 2540 sta->sta.eml_cap = params->eml_cap; 2541 2542 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_STA_MODIFY, 2543 ¶ms->link_sta_params); 2544 if (ret) 2545 return ret; 2546 2547 if (params->support_p2p_ps >= 0) 2548 sta->sta.support_p2p_ps = params->support_p2p_ps; 2549 2550 if (ieee80211_vif_is_mesh(&sdata->vif)) 2551 sta_apply_mesh_params(local, sta, params); 2552 2553 if (params->airtime_weight) 2554 sta->airtime_weight = params->airtime_weight; 2555 2556 if (params->nmi_mac) { 2557 struct ieee80211_sub_if_data *nmi = 2558 rcu_dereference_wiphy(local->hw.wiphy, 2559 sdata->u.nan_data.nmi); 2560 struct sta_info *nmi_sta; 2561 2562 if (WARN_ON(!nmi)) 2563 return -EINVAL; 2564 2565 nmi_sta = sta_info_get(nmi, params->nmi_mac); 2566 if (!nmi_sta) 2567 return -ENOENT; 2568 rcu_assign_pointer(sta->sta.nmi, &nmi_sta->sta); 2569 2570 /* For NAN_DATA stations, copy capabilities from the NMI station */ 2571 if (!nmi_sta->deflink.pub->ht_cap.ht_supported) 2572 return -EINVAL; 2573 2574 sta->deflink.pub->ht_cap = nmi_sta->deflink.pub->ht_cap; 2575 sta->deflink.pub->vht_cap = nmi_sta->deflink.pub->vht_cap; 2576 sta->deflink.pub->he_cap = nmi_sta->deflink.pub->he_cap; 2577 memcpy(&sta->deflink.pub->supp_rates, 2578 &nmi_sta->deflink.pub->supp_rates, 2579 sizeof(sta->deflink.pub->supp_rates)); 2580 } 2581 2582 /* set the STA state after all sta info from usermode has been set */ 2583 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || 2584 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { 2585 ret = sta_apply_auth_flags(local, sta, mask, set); 2586 if (ret) 2587 return ret; 2588 } 2589 2590 /* Mark the STA as MLO if MLD MAC address is available */ 2591 if (params->link_sta_params.mld_mac) 2592 sta->sta.mlo = true; 2593 2594 return 0; 2595 } 2596 2597 static int ieee80211_add_station(struct wiphy *wiphy, struct wireless_dev *wdev, 2598 const u8 *mac, 2599 struct station_parameters *params) 2600 { 2601 struct ieee80211_local *local = wiphy_priv(wiphy); 2602 struct sta_info *sta; 2603 struct ieee80211_sub_if_data *sdata; 2604 int err; 2605 2606 lockdep_assert_wiphy(local->hw.wiphy); 2607 2608 if (params->vlan) { 2609 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 2610 2611 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 2612 sdata->vif.type != NL80211_IFTYPE_AP) 2613 return -EINVAL; 2614 } else 2615 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 2616 2617 if (ether_addr_equal(mac, sdata->vif.addr)) 2618 return -EINVAL; 2619 2620 if (!is_valid_ether_addr(mac)) 2621 return -EINVAL; 2622 2623 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) && 2624 sdata->vif.type == NL80211_IFTYPE_STATION && 2625 !sdata->u.mgd.associated) 2626 return -EINVAL; 2627 2628 /* 2629 * If we have a link ID, it can be a non-MLO station on an AP MLD, 2630 * but we need to have a link_mac in that case as well, so use the 2631 * STA's MAC address in that case. 2632 */ 2633 if (params->link_sta_params.link_id >= 0) 2634 sta = sta_info_alloc_with_link(sdata, mac, 2635 params->link_sta_params.link_id, 2636 params->link_sta_params.link_mac ?: mac, 2637 GFP_KERNEL); 2638 else 2639 sta = sta_info_alloc(sdata, mac, GFP_KERNEL); 2640 2641 if (!sta) 2642 return -ENOMEM; 2643 2644 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) 2645 sta->sta.tdls = true; 2646 2647 /* Though the mutex is not needed here (since the station is not 2648 * visible yet), sta_apply_parameters (and inner functions) require 2649 * the mutex due to other paths. 2650 */ 2651 err = sta_apply_parameters(local, sta, params); 2652 if (err) { 2653 sta_info_free(local, sta); 2654 return err; 2655 } 2656 2657 /* 2658 * for TDLS and for unassociated station, rate control should be 2659 * initialized only when rates are known and station is marked 2660 * authorized/associated 2661 */ 2662 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && 2663 test_sta_flag(sta, WLAN_STA_ASSOC)) 2664 rate_control_rate_init_all_links(sta); 2665 2666 err = sta_info_insert(sta); 2667 2668 /* 2669 * ieee80211_nan_update_ndi_carrier was called from sta_apply_parameters, 2670 * but then we did not have the STA in the list. 2671 */ 2672 if (!err && sdata->vif.type == NL80211_IFTYPE_NAN_DATA) 2673 ieee80211_nan_update_ndi_carrier(sta->sdata); 2674 return err; 2675 } 2676 2677 static int ieee80211_del_station(struct wiphy *wiphy, struct wireless_dev *wdev, 2678 struct station_del_parameters *params) 2679 { 2680 struct ieee80211_sub_if_data *sdata; 2681 2682 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 2683 2684 if (params->mac) 2685 return sta_info_destroy_addr_bss(sdata, params->mac); 2686 2687 sta_info_flush(sdata, params->link_id); 2688 return 0; 2689 } 2690 2691 static int ieee80211_set_sta_4addr(struct ieee80211_local *local, 2692 struct ieee80211_sub_if_data *sdata, 2693 struct sta_info *sta) 2694 { 2695 struct ieee80211_vif *vif = &sdata->vif; 2696 struct wiphy *wiphy = local->hw.wiphy; 2697 struct ieee80211_sub_if_data *master; 2698 struct ieee80211_bss_conf *link_conf; 2699 struct wireless_dev *wdev; 2700 unsigned long master_iter; 2701 int link_id; 2702 int err; 2703 2704 lockdep_assert_wiphy(local->hw.wiphy); 2705 2706 if (sdata->u.vlan.sta) 2707 return -EBUSY; 2708 2709 wdev = &sdata->wdev; 2710 master = container_of(sdata->bss, 2711 struct ieee80211_sub_if_data, 2712 u.ap); 2713 2714 if (sta->sta.valid_links) { 2715 u16 sta_links = sta->sta.valid_links; 2716 u16 new_links = master->vif.valid_links & sta_links; 2717 u16 orig_links = wdev->valid_links; 2718 2719 wdev->valid_links = new_links; 2720 2721 err = ieee80211_vif_set_links(sdata, new_links, 0); 2722 if (err) { 2723 wdev->valid_links = orig_links; 2724 return err; 2725 } 2726 2727 master_iter = master->vif.valid_links; 2728 2729 for_each_set_bit(link_id, &master_iter, 2730 IEEE80211_MLD_MAX_NUM_LINKS) { 2731 if (!(sta_links & BIT(link_id))) { 2732 eth_zero_addr(wdev->links[link_id].addr); 2733 } else { 2734 link_conf = wiphy_dereference(wiphy, 2735 vif->link_conf[link_id]); 2736 2737 ether_addr_copy(wdev->links[link_id].addr, 2738 link_conf->bssid); 2739 } 2740 } 2741 } 2742 2743 rcu_assign_pointer(sdata->u.vlan.sta, sta); 2744 __ieee80211_check_fast_rx_iface(sdata); 2745 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true); 2746 2747 return 0; 2748 } 2749 2750 static int ieee80211_change_station(struct wiphy *wiphy, 2751 struct wireless_dev *wdev, const u8 *mac, 2752 struct station_parameters *params) 2753 { 2754 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 2755 struct ieee80211_local *local = wiphy_priv(wiphy); 2756 struct sta_info *sta; 2757 struct ieee80211_sub_if_data *vlansdata; 2758 enum cfg80211_station_type statype; 2759 int err; 2760 2761 lockdep_assert_wiphy(local->hw.wiphy); 2762 2763 sta = sta_info_get_bss(sdata, mac); 2764 if (!sta) 2765 return -ENOENT; 2766 2767 switch (sdata->vif.type) { 2768 case NL80211_IFTYPE_MESH_POINT: 2769 if (sdata->u.mesh.user_mpm) 2770 statype = CFG80211_STA_MESH_PEER_USER; 2771 else 2772 statype = CFG80211_STA_MESH_PEER_KERNEL; 2773 break; 2774 case NL80211_IFTYPE_ADHOC: 2775 statype = CFG80211_STA_IBSS; 2776 break; 2777 case NL80211_IFTYPE_STATION: 2778 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { 2779 statype = CFG80211_STA_AP_STA; 2780 break; 2781 } 2782 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 2783 statype = CFG80211_STA_TDLS_PEER_ACTIVE; 2784 else 2785 statype = CFG80211_STA_TDLS_PEER_SETUP; 2786 break; 2787 case NL80211_IFTYPE_AP: 2788 case NL80211_IFTYPE_AP_VLAN: 2789 if (test_sta_flag(sta, WLAN_STA_ASSOC)) 2790 statype = CFG80211_STA_AP_CLIENT; 2791 else 2792 statype = CFG80211_STA_AP_CLIENT_UNASSOC; 2793 break; 2794 case NL80211_IFTYPE_NAN: 2795 statype = CFG80211_STA_NAN_MGMT; 2796 break; 2797 case NL80211_IFTYPE_NAN_DATA: 2798 statype = CFG80211_STA_NAN_DATA; 2799 break; 2800 default: 2801 return -EOPNOTSUPP; 2802 } 2803 2804 err = cfg80211_check_station_change(wiphy, params, statype); 2805 if (err) 2806 return err; 2807 2808 if (params->vlan && params->vlan != sta->sdata->dev) { 2809 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 2810 2811 if (params->vlan->ieee80211_ptr->use_4addr) { 2812 err = ieee80211_set_sta_4addr(local, vlansdata, sta); 2813 if (err) 2814 return err; 2815 2816 } 2817 2818 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && 2819 sta->sdata->u.vlan.sta) 2820 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); 2821 2822 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 2823 ieee80211_vif_dec_num_mcast(sta->sdata); 2824 2825 sta->sdata = vlansdata; 2826 ieee80211_check_fast_rx(sta); 2827 ieee80211_check_fast_xmit(sta); 2828 2829 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { 2830 ieee80211_vif_inc_num_mcast(sta->sdata); 2831 cfg80211_send_layer2_update(sta->sdata->dev, 2832 sta->sta.addr); 2833 } 2834 } 2835 2836 /* NAN capabilties should not change */ 2837 if (statype == CFG80211_STA_NAN_DATA && 2838 sta->deflink.pub->ht_cap.ht_supported && 2839 (params->link_sta_params.ht_capa || 2840 params->link_sta_params.vht_capa || 2841 params->link_sta_params.he_capa)) 2842 return -EINVAL; 2843 2844 err = sta_apply_parameters(local, sta, params); 2845 if (err) 2846 return err; 2847 2848 if (sdata->vif.type == NL80211_IFTYPE_STATION && 2849 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { 2850 ieee80211_recalc_ps(local); 2851 ieee80211_recalc_ps_vif(sdata); 2852 } 2853 2854 return 0; 2855 } 2856 2857 #ifdef CONFIG_MAC80211_MESH 2858 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, 2859 const u8 *dst, const u8 *next_hop) 2860 { 2861 struct ieee80211_sub_if_data *sdata; 2862 struct mesh_path *mpath; 2863 struct sta_info *sta; 2864 2865 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2866 2867 rcu_read_lock(); 2868 sta = sta_info_get(sdata, next_hop); 2869 if (!sta) { 2870 rcu_read_unlock(); 2871 return -ENOENT; 2872 } 2873 2874 mpath = mesh_path_add(sdata, dst); 2875 if (IS_ERR(mpath)) { 2876 rcu_read_unlock(); 2877 return PTR_ERR(mpath); 2878 } 2879 2880 mesh_path_fix_nexthop(mpath, sta); 2881 2882 rcu_read_unlock(); 2883 return 0; 2884 } 2885 2886 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, 2887 const u8 *dst) 2888 { 2889 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2890 2891 if (dst) 2892 return mesh_path_del(sdata, dst); 2893 2894 mesh_path_flush_by_iface(sdata); 2895 return 0; 2896 } 2897 2898 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, 2899 const u8 *dst, const u8 *next_hop) 2900 { 2901 struct ieee80211_sub_if_data *sdata; 2902 struct mesh_path *mpath; 2903 struct sta_info *sta; 2904 2905 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2906 2907 rcu_read_lock(); 2908 2909 sta = sta_info_get(sdata, next_hop); 2910 if (!sta) { 2911 rcu_read_unlock(); 2912 return -ENOENT; 2913 } 2914 2915 mpath = mesh_path_lookup(sdata, dst); 2916 if (!mpath) { 2917 rcu_read_unlock(); 2918 return -ENOENT; 2919 } 2920 2921 mesh_path_fix_nexthop(mpath, sta); 2922 2923 rcu_read_unlock(); 2924 return 0; 2925 } 2926 2927 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, 2928 struct mpath_info *pinfo) 2929 { 2930 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); 2931 2932 if (next_hop_sta) 2933 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); 2934 else 2935 eth_zero_addr(next_hop); 2936 2937 memset(pinfo, 0, sizeof(*pinfo)); 2938 2939 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; 2940 2941 pinfo->filled = MPATH_INFO_FRAME_QLEN | 2942 MPATH_INFO_SN | 2943 MPATH_INFO_METRIC | 2944 MPATH_INFO_EXPTIME | 2945 MPATH_INFO_DISCOVERY_TIMEOUT | 2946 MPATH_INFO_DISCOVERY_RETRIES | 2947 MPATH_INFO_FLAGS | 2948 MPATH_INFO_HOP_COUNT | 2949 MPATH_INFO_PATH_CHANGE; 2950 2951 pinfo->frame_qlen = mpath->frame_queue.qlen; 2952 pinfo->sn = mpath->sn; 2953 pinfo->metric = mpath->metric; 2954 if (time_before(jiffies, mpath->exp_time)) 2955 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); 2956 pinfo->discovery_timeout = 2957 jiffies_to_msecs(mpath->discovery_timeout); 2958 pinfo->discovery_retries = mpath->discovery_retries; 2959 if (mpath->flags & MESH_PATH_ACTIVE) 2960 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; 2961 if (mpath->flags & MESH_PATH_RESOLVING) 2962 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; 2963 if (mpath->flags & MESH_PATH_SN_VALID) 2964 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; 2965 if (mpath->flags & MESH_PATH_FIXED) 2966 pinfo->flags |= NL80211_MPATH_FLAG_FIXED; 2967 if (mpath->flags & MESH_PATH_RESOLVED) 2968 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; 2969 pinfo->hop_count = mpath->hop_count; 2970 pinfo->path_change_count = mpath->path_change_count; 2971 } 2972 2973 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, 2974 u8 *dst, u8 *next_hop, struct mpath_info *pinfo) 2975 2976 { 2977 struct ieee80211_sub_if_data *sdata; 2978 struct mesh_path *mpath; 2979 2980 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2981 2982 rcu_read_lock(); 2983 mpath = mesh_path_lookup(sdata, dst); 2984 if (!mpath) { 2985 rcu_read_unlock(); 2986 return -ENOENT; 2987 } 2988 memcpy(dst, mpath->dst, ETH_ALEN); 2989 mpath_set_pinfo(mpath, next_hop, pinfo); 2990 rcu_read_unlock(); 2991 return 0; 2992 } 2993 2994 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, 2995 int idx, u8 *dst, u8 *next_hop, 2996 struct mpath_info *pinfo) 2997 { 2998 struct ieee80211_sub_if_data *sdata; 2999 struct mesh_path *mpath; 3000 3001 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3002 3003 rcu_read_lock(); 3004 mpath = mesh_path_lookup_by_idx(sdata, idx); 3005 if (!mpath) { 3006 rcu_read_unlock(); 3007 return -ENOENT; 3008 } 3009 memcpy(dst, mpath->dst, ETH_ALEN); 3010 mpath_set_pinfo(mpath, next_hop, pinfo); 3011 rcu_read_unlock(); 3012 return 0; 3013 } 3014 3015 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, 3016 struct mpath_info *pinfo) 3017 { 3018 memset(pinfo, 0, sizeof(*pinfo)); 3019 memcpy(mpp, mpath->mpp, ETH_ALEN); 3020 3021 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; 3022 } 3023 3024 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, 3025 u8 *dst, u8 *mpp, struct mpath_info *pinfo) 3026 3027 { 3028 struct ieee80211_sub_if_data *sdata; 3029 struct mesh_path *mpath; 3030 3031 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3032 3033 rcu_read_lock(); 3034 mpath = mpp_path_lookup(sdata, dst); 3035 if (!mpath) { 3036 rcu_read_unlock(); 3037 return -ENOENT; 3038 } 3039 memcpy(dst, mpath->dst, ETH_ALEN); 3040 mpp_set_pinfo(mpath, mpp, pinfo); 3041 rcu_read_unlock(); 3042 return 0; 3043 } 3044 3045 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, 3046 int idx, u8 *dst, u8 *mpp, 3047 struct mpath_info *pinfo) 3048 { 3049 struct ieee80211_sub_if_data *sdata; 3050 struct mesh_path *mpath; 3051 3052 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3053 3054 rcu_read_lock(); 3055 mpath = mpp_path_lookup_by_idx(sdata, idx); 3056 if (!mpath) { 3057 rcu_read_unlock(); 3058 return -ENOENT; 3059 } 3060 memcpy(dst, mpath->dst, ETH_ALEN); 3061 mpp_set_pinfo(mpath, mpp, pinfo); 3062 rcu_read_unlock(); 3063 return 0; 3064 } 3065 3066 static int ieee80211_get_mesh_config(struct wiphy *wiphy, 3067 struct net_device *dev, 3068 struct mesh_config *conf) 3069 { 3070 struct ieee80211_sub_if_data *sdata; 3071 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3072 3073 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); 3074 return 0; 3075 } 3076 3077 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) 3078 { 3079 return (mask >> (parm-1)) & 0x1; 3080 } 3081 3082 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, 3083 const struct mesh_setup *setup) 3084 { 3085 u8 *new_ie; 3086 struct ieee80211_sub_if_data *sdata = container_of(ifmsh, 3087 struct ieee80211_sub_if_data, u.mesh); 3088 int i; 3089 3090 /* allocate information elements */ 3091 new_ie = NULL; 3092 3093 if (setup->ie_len) { 3094 new_ie = kmemdup(setup->ie, setup->ie_len, 3095 GFP_KERNEL); 3096 if (!new_ie) 3097 return -ENOMEM; 3098 } 3099 ifmsh->ie_len = setup->ie_len; 3100 ifmsh->ie = new_ie; 3101 3102 /* now copy the rest of the setup parameters */ 3103 ifmsh->mesh_id_len = setup->mesh_id_len; 3104 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); 3105 ifmsh->mesh_sp_id = setup->sync_method; 3106 ifmsh->mesh_pp_id = setup->path_sel_proto; 3107 ifmsh->mesh_pm_id = setup->path_metric; 3108 ifmsh->user_mpm = setup->user_mpm; 3109 ifmsh->mesh_auth_id = setup->auth_id; 3110 ifmsh->security = IEEE80211_MESH_SEC_NONE; 3111 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; 3112 if (setup->is_authenticated) 3113 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; 3114 if (setup->is_secure) 3115 ifmsh->security |= IEEE80211_MESH_SEC_SECURED; 3116 3117 /* mcast rate setting in Mesh Node */ 3118 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, 3119 sizeof(setup->mcast_rate)); 3120 sdata->vif.bss_conf.basic_rates = setup->basic_rates; 3121 3122 sdata->vif.bss_conf.beacon_int = setup->beacon_interval; 3123 sdata->vif.bss_conf.dtim_period = setup->dtim_period; 3124 3125 sdata->beacon_rate_set = false; 3126 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy, 3127 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { 3128 for (i = 0; i < NUM_NL80211_BANDS; i++) { 3129 sdata->beacon_rateidx_mask[i] = 3130 setup->beacon_rate.control[i].legacy; 3131 if (sdata->beacon_rateidx_mask[i]) 3132 sdata->beacon_rate_set = true; 3133 } 3134 } 3135 3136 return 0; 3137 } 3138 3139 static int ieee80211_update_mesh_config(struct wiphy *wiphy, 3140 struct net_device *dev, u32 mask, 3141 const struct mesh_config *nconf) 3142 { 3143 struct mesh_config *conf; 3144 struct ieee80211_sub_if_data *sdata; 3145 struct ieee80211_if_mesh *ifmsh; 3146 3147 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3148 ifmsh = &sdata->u.mesh; 3149 3150 /* Set the config options which we are interested in setting */ 3151 conf = &(sdata->u.mesh.mshcfg); 3152 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) 3153 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; 3154 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) 3155 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; 3156 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) 3157 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; 3158 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) 3159 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; 3160 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) 3161 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; 3162 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) 3163 conf->dot11MeshTTL = nconf->dot11MeshTTL; 3164 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) 3165 conf->element_ttl = nconf->element_ttl; 3166 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { 3167 if (ifmsh->user_mpm) 3168 return -EBUSY; 3169 conf->auto_open_plinks = nconf->auto_open_plinks; 3170 } 3171 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) 3172 conf->dot11MeshNbrOffsetMaxNeighbor = 3173 nconf->dot11MeshNbrOffsetMaxNeighbor; 3174 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) 3175 conf->dot11MeshHWMPmaxPREQretries = 3176 nconf->dot11MeshHWMPmaxPREQretries; 3177 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) 3178 conf->path_refresh_time = nconf->path_refresh_time; 3179 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) 3180 conf->min_discovery_timeout = nconf->min_discovery_timeout; 3181 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) 3182 conf->dot11MeshHWMPactivePathTimeout = 3183 nconf->dot11MeshHWMPactivePathTimeout; 3184 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) 3185 conf->dot11MeshHWMPpreqMinInterval = 3186 nconf->dot11MeshHWMPpreqMinInterval; 3187 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) 3188 conf->dot11MeshHWMPperrMinInterval = 3189 nconf->dot11MeshHWMPperrMinInterval; 3190 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, 3191 mask)) 3192 conf->dot11MeshHWMPnetDiameterTraversalTime = 3193 nconf->dot11MeshHWMPnetDiameterTraversalTime; 3194 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { 3195 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; 3196 ieee80211_mesh_root_setup(ifmsh); 3197 } 3198 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { 3199 /* our current gate announcement implementation rides on root 3200 * announcements, so require this ifmsh to also be a root node 3201 * */ 3202 if (nconf->dot11MeshGateAnnouncementProtocol && 3203 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { 3204 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; 3205 ieee80211_mesh_root_setup(ifmsh); 3206 } 3207 conf->dot11MeshGateAnnouncementProtocol = 3208 nconf->dot11MeshGateAnnouncementProtocol; 3209 } 3210 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) 3211 conf->dot11MeshHWMPRannInterval = 3212 nconf->dot11MeshHWMPRannInterval; 3213 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) 3214 conf->dot11MeshForwarding = nconf->dot11MeshForwarding; 3215 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { 3216 /* our RSSI threshold implementation is supported only for 3217 * devices that report signal in dBm. 3218 */ 3219 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) 3220 return -EOPNOTSUPP; 3221 conf->rssi_threshold = nconf->rssi_threshold; 3222 } 3223 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { 3224 conf->ht_opmode = nconf->ht_opmode; 3225 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; 3226 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3227 BSS_CHANGED_HT); 3228 } 3229 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) 3230 conf->dot11MeshHWMPactivePathToRootTimeout = 3231 nconf->dot11MeshHWMPactivePathToRootTimeout; 3232 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) 3233 conf->dot11MeshHWMProotInterval = 3234 nconf->dot11MeshHWMProotInterval; 3235 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) 3236 conf->dot11MeshHWMPconfirmationInterval = 3237 nconf->dot11MeshHWMPconfirmationInterval; 3238 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { 3239 conf->power_mode = nconf->power_mode; 3240 ieee80211_mps_local_status_update(sdata); 3241 } 3242 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) 3243 conf->dot11MeshAwakeWindowDuration = 3244 nconf->dot11MeshAwakeWindowDuration; 3245 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) 3246 conf->plink_timeout = nconf->plink_timeout; 3247 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask)) 3248 conf->dot11MeshConnectedToMeshGate = 3249 nconf->dot11MeshConnectedToMeshGate; 3250 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask)) 3251 conf->dot11MeshNolearn = nconf->dot11MeshNolearn; 3252 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask)) 3253 conf->dot11MeshConnectedToAuthServer = 3254 nconf->dot11MeshConnectedToAuthServer; 3255 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); 3256 return 0; 3257 } 3258 3259 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, 3260 const struct mesh_config *conf, 3261 const struct mesh_setup *setup) 3262 { 3263 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3264 struct ieee80211_chan_req chanreq = { .oper = setup->chandef }; 3265 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 3266 int err; 3267 3268 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3269 3270 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); 3271 err = copy_mesh_setup(ifmsh, setup); 3272 if (err) 3273 return err; 3274 3275 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; 3276 3277 /* can mesh use other SMPS modes? */ 3278 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; 3279 sdata->deflink.needed_rx_chains = sdata->local->rx_chains; 3280 3281 err = ieee80211_link_use_channel(&sdata->deflink, &chanreq, 3282 IEEE80211_CHANCTX_SHARED); 3283 if (err) 3284 return err; 3285 3286 return ieee80211_start_mesh(sdata); 3287 } 3288 3289 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) 3290 { 3291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3292 3293 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3294 3295 ieee80211_stop_mesh(sdata); 3296 ieee80211_link_release_channel(&sdata->deflink); 3297 kfree(sdata->u.mesh.ie); 3298 3299 return 0; 3300 } 3301 #endif 3302 3303 static int ieee80211_change_bss(struct wiphy *wiphy, 3304 struct net_device *dev, 3305 struct bss_parameters *params) 3306 { 3307 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3308 struct ieee80211_link_data *link; 3309 struct ieee80211_supported_band *sband; 3310 u64 changed = 0; 3311 3312 link = ieee80211_link_or_deflink(sdata, params->link_id, true); 3313 if (IS_ERR(link)) 3314 return PTR_ERR(link); 3315 3316 if (!sdata_dereference(link->u.ap.beacon, sdata)) 3317 return -ENOENT; 3318 3319 sband = ieee80211_get_link_sband(link); 3320 if (!sband) 3321 return -EINVAL; 3322 3323 if (params->basic_rates) { 3324 if (!ieee80211_parse_bitrates(sband, 3325 params->basic_rates, 3326 params->basic_rates_len, 3327 &link->conf->basic_rates)) 3328 return -EINVAL; 3329 changed |= BSS_CHANGED_BASIC_RATES; 3330 ieee80211_check_rate_mask(link); 3331 } 3332 3333 if (params->use_cts_prot >= 0) { 3334 link->conf->use_cts_prot = params->use_cts_prot; 3335 changed |= BSS_CHANGED_ERP_CTS_PROT; 3336 } 3337 if (params->use_short_preamble >= 0) { 3338 link->conf->use_short_preamble = params->use_short_preamble; 3339 changed |= BSS_CHANGED_ERP_PREAMBLE; 3340 } 3341 3342 if (!link->conf->use_short_slot && 3343 (sband->band == NL80211_BAND_5GHZ || 3344 sband->band == NL80211_BAND_6GHZ)) { 3345 link->conf->use_short_slot = true; 3346 changed |= BSS_CHANGED_ERP_SLOT; 3347 } 3348 3349 if (params->use_short_slot_time >= 0) { 3350 link->conf->use_short_slot = params->use_short_slot_time; 3351 changed |= BSS_CHANGED_ERP_SLOT; 3352 } 3353 3354 if (params->ap_isolate >= 0) { 3355 if (params->ap_isolate) 3356 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; 3357 else 3358 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; 3359 ieee80211_check_fast_rx_iface(sdata); 3360 } 3361 3362 if (params->ht_opmode >= 0) { 3363 link->conf->ht_operation_mode = (u16)params->ht_opmode; 3364 changed |= BSS_CHANGED_HT; 3365 } 3366 3367 if (params->p2p_ctwindow >= 0) { 3368 link->conf->p2p_noa_attr.oppps_ctwindow &= 3369 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; 3370 link->conf->p2p_noa_attr.oppps_ctwindow |= 3371 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; 3372 changed |= BSS_CHANGED_P2P_PS; 3373 } 3374 3375 if (params->p2p_opp_ps > 0) { 3376 link->conf->p2p_noa_attr.oppps_ctwindow |= 3377 IEEE80211_P2P_OPPPS_ENABLE_BIT; 3378 changed |= BSS_CHANGED_P2P_PS; 3379 } else if (params->p2p_opp_ps == 0) { 3380 link->conf->p2p_noa_attr.oppps_ctwindow &= 3381 ~IEEE80211_P2P_OPPPS_ENABLE_BIT; 3382 changed |= BSS_CHANGED_P2P_PS; 3383 } 3384 3385 ieee80211_link_info_change_notify(sdata, link, changed); 3386 3387 return 0; 3388 } 3389 3390 static int ieee80211_set_txq_params(struct wiphy *wiphy, 3391 struct net_device *dev, 3392 struct ieee80211_txq_params *params) 3393 { 3394 struct ieee80211_local *local = wiphy_priv(wiphy); 3395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3396 struct ieee80211_link_data *link = 3397 ieee80211_link_or_deflink(sdata, params->link_id, true); 3398 struct ieee80211_tx_queue_params p; 3399 3400 if (!local->ops->conf_tx) 3401 return -EOPNOTSUPP; 3402 3403 if (local->hw.queues < IEEE80211_NUM_ACS) 3404 return -EOPNOTSUPP; 3405 3406 if (IS_ERR(link)) 3407 return PTR_ERR(link); 3408 3409 memset(&p, 0, sizeof(p)); 3410 p.aifs = params->aifs; 3411 p.cw_max = params->cwmax; 3412 p.cw_min = params->cwmin; 3413 p.txop = params->txop; 3414 3415 /* 3416 * Setting tx queue params disables u-apsd because it's only 3417 * called in master mode. 3418 */ 3419 p.uapsd = false; 3420 3421 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); 3422 3423 link->tx_conf[params->ac] = p; 3424 if (drv_conf_tx(local, link, params->ac, &p)) { 3425 wiphy_debug(local->hw.wiphy, 3426 "failed to set TX queue parameters for AC %d\n", 3427 params->ac); 3428 return -EINVAL; 3429 } 3430 3431 ieee80211_link_info_change_notify(sdata, link, 3432 BSS_CHANGED_QOS); 3433 3434 return 0; 3435 } 3436 3437 #ifdef CONFIG_PM 3438 static int ieee80211_suspend(struct wiphy *wiphy, 3439 struct cfg80211_wowlan *wowlan) 3440 { 3441 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); 3442 } 3443 3444 static int ieee80211_resume(struct wiphy *wiphy) 3445 { 3446 return __ieee80211_resume(wiphy_priv(wiphy)); 3447 } 3448 #else 3449 #define ieee80211_suspend NULL 3450 #define ieee80211_resume NULL 3451 #endif 3452 3453 static int ieee80211_scan(struct wiphy *wiphy, 3454 struct cfg80211_scan_request *req) 3455 { 3456 struct ieee80211_sub_if_data *sdata; 3457 struct ieee80211_link_data *link; 3458 struct ieee80211_channel *chan; 3459 int radio_idx; 3460 3461 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); 3462 3463 switch (ieee80211_vif_type_p2p(&sdata->vif)) { 3464 case NL80211_IFTYPE_STATION: 3465 case NL80211_IFTYPE_ADHOC: 3466 case NL80211_IFTYPE_MESH_POINT: 3467 case NL80211_IFTYPE_P2P_CLIENT: 3468 case NL80211_IFTYPE_P2P_DEVICE: 3469 break; 3470 case NL80211_IFTYPE_P2P_GO: 3471 if (sdata->local->ops->hw_scan) 3472 break; 3473 /* 3474 * FIXME: implement NoA while scanning in software, 3475 * for now fall through to allow scanning only when 3476 * beaconing hasn't been configured yet 3477 */ 3478 fallthrough; 3479 case NL80211_IFTYPE_AP: 3480 /* 3481 * If the scan has been forced (and the driver supports 3482 * forcing), don't care about being beaconing already. 3483 * This will create problems to the attached stations (e.g. all 3484 * the frames sent while scanning on other channel will be 3485 * lost) 3486 */ 3487 for_each_link_data(sdata, link) { 3488 /* if the link is not beaconing, ignore it */ 3489 if (!sdata_dereference(link->u.ap.beacon, sdata)) 3490 continue; 3491 3492 chan = link->conf->chanreq.oper.chan; 3493 radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan); 3494 3495 if (ieee80211_is_radio_idx_in_scan_req(wiphy, req, 3496 radio_idx) && 3497 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || 3498 !(req->flags & NL80211_SCAN_FLAG_AP))) 3499 return -EOPNOTSUPP; 3500 } 3501 break; 3502 case NL80211_IFTYPE_NAN: 3503 case NL80211_IFTYPE_PD: 3504 default: 3505 return -EOPNOTSUPP; 3506 } 3507 3508 return ieee80211_request_scan(sdata, req); 3509 } 3510 3511 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) 3512 { 3513 ieee80211_scan_cancel(wiphy_priv(wiphy)); 3514 } 3515 3516 static int 3517 ieee80211_sched_scan_start(struct wiphy *wiphy, 3518 struct net_device *dev, 3519 struct cfg80211_sched_scan_request *req) 3520 { 3521 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3522 3523 if (!sdata->local->ops->sched_scan_start) 3524 return -EOPNOTSUPP; 3525 3526 return ieee80211_request_sched_scan_start(sdata, req); 3527 } 3528 3529 static int 3530 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, 3531 u64 reqid) 3532 { 3533 struct ieee80211_local *local = wiphy_priv(wiphy); 3534 3535 if (!local->ops->sched_scan_stop) 3536 return -EOPNOTSUPP; 3537 3538 return ieee80211_request_sched_scan_stop(local); 3539 } 3540 3541 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, 3542 struct cfg80211_auth_request *req) 3543 { 3544 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); 3545 } 3546 3547 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, 3548 struct cfg80211_assoc_request *req) 3549 { 3550 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); 3551 } 3552 3553 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 3554 struct cfg80211_deauth_request *req) 3555 { 3556 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); 3557 } 3558 3559 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 3560 struct cfg80211_disassoc_request *req) 3561 { 3562 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); 3563 } 3564 3565 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 3566 struct cfg80211_ibss_params *params) 3567 { 3568 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); 3569 } 3570 3571 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 3572 { 3573 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); 3574 } 3575 3576 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, 3577 struct ocb_setup *setup) 3578 { 3579 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); 3580 } 3581 3582 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) 3583 { 3584 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); 3585 } 3586 3587 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, 3588 int rate[NUM_NL80211_BANDS]) 3589 { 3590 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3591 3592 memcpy(sdata->vif.bss_conf.mcast_rate, rate, 3593 sizeof(int) * NUM_NL80211_BANDS); 3594 3595 if (ieee80211_sdata_running(sdata)) 3596 ieee80211_link_info_change_notify(sdata, &sdata->deflink, 3597 BSS_CHANGED_MCAST_RATE); 3598 3599 return 0; 3600 } 3601 3602 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, int radio_idx, 3603 u32 changed) 3604 { 3605 struct ieee80211_local *local = wiphy_priv(wiphy); 3606 int err; 3607 3608 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { 3609 ieee80211_check_fast_xmit_all(local); 3610 3611 err = drv_set_frag_threshold(local, radio_idx, 3612 wiphy->frag_threshold); 3613 3614 if (err) { 3615 ieee80211_check_fast_xmit_all(local); 3616 return err; 3617 } 3618 } 3619 3620 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || 3621 (changed & WIPHY_PARAM_DYN_ACK)) { 3622 s16 coverage_class; 3623 3624 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? 3625 wiphy->coverage_class : -1; 3626 err = drv_set_coverage_class(local, radio_idx, 3627 coverage_class); 3628 3629 if (err) 3630 return err; 3631 } 3632 3633 if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 3634 u32 rts_threshold; 3635 3636 if ((radio_idx == -1) || (radio_idx >= wiphy->n_radio)) 3637 rts_threshold = wiphy->rts_threshold; 3638 else 3639 rts_threshold = 3640 wiphy->radio_cfg[radio_idx].rts_threshold; 3641 3642 err = drv_set_rts_threshold(local, radio_idx, rts_threshold); 3643 3644 if (err) 3645 return err; 3646 } 3647 3648 if (changed & WIPHY_PARAM_RETRY_SHORT) { 3649 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) 3650 return -EINVAL; 3651 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; 3652 } 3653 if (changed & WIPHY_PARAM_RETRY_LONG) { 3654 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) 3655 return -EINVAL; 3656 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; 3657 } 3658 if (changed & 3659 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) 3660 ieee80211_hw_config(local, radio_idx, 3661 IEEE80211_CONF_CHANGE_RETRY_LIMITS); 3662 3663 if (changed & (WIPHY_PARAM_TXQ_LIMIT | 3664 WIPHY_PARAM_TXQ_MEMORY_LIMIT | 3665 WIPHY_PARAM_TXQ_QUANTUM)) 3666 ieee80211_txq_set_params(local, radio_idx); 3667 3668 return 0; 3669 } 3670 3671 static int ieee80211_set_tx_power(struct wiphy *wiphy, 3672 struct wireless_dev *wdev, int radio_idx, 3673 enum nl80211_tx_power_setting type, int mbm) 3674 { 3675 struct ieee80211_local *local = wiphy_priv(wiphy); 3676 struct ieee80211_sub_if_data *sdata; 3677 enum nl80211_tx_power_setting txp_type = type; 3678 bool update_txp_type = false; 3679 bool has_monitor = false; 3680 int user_power_level; 3681 int old_power = local->user_power_level; 3682 3683 lockdep_assert_wiphy(local->hw.wiphy); 3684 3685 switch (type) { 3686 case NL80211_TX_POWER_AUTOMATIC: 3687 user_power_level = IEEE80211_UNSET_POWER_LEVEL; 3688 txp_type = NL80211_TX_POWER_LIMITED; 3689 break; 3690 case NL80211_TX_POWER_LIMITED: 3691 case NL80211_TX_POWER_FIXED: 3692 if (mbm < 0 || (mbm % 100)) 3693 return -EOPNOTSUPP; 3694 user_power_level = MBM_TO_DBM(mbm); 3695 break; 3696 default: 3697 return -EINVAL; 3698 } 3699 3700 if (wdev) { 3701 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3702 3703 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && 3704 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { 3705 if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) 3706 return -EOPNOTSUPP; 3707 3708 sdata = wiphy_dereference(local->hw.wiphy, 3709 local->monitor_sdata); 3710 if (!sdata) 3711 return -EOPNOTSUPP; 3712 } 3713 3714 for (int link_id = 0; 3715 link_id < ARRAY_SIZE(sdata->link); 3716 link_id++) { 3717 struct ieee80211_link_data *link = 3718 wiphy_dereference(wiphy, sdata->link[link_id]); 3719 3720 if (!link) 3721 continue; 3722 3723 link->user_power_level = user_power_level; 3724 3725 if (txp_type != link->conf->txpower_type) { 3726 update_txp_type = true; 3727 link->conf->txpower_type = txp_type; 3728 } 3729 3730 ieee80211_recalc_txpower(link, update_txp_type); 3731 } 3732 return 0; 3733 } 3734 3735 local->user_power_level = user_power_level; 3736 3737 list_for_each_entry(sdata, &local->interfaces, list) { 3738 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && 3739 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) { 3740 has_monitor = true; 3741 continue; 3742 } 3743 3744 for (int link_id = 0; 3745 link_id < ARRAY_SIZE(sdata->link); 3746 link_id++) { 3747 struct ieee80211_link_data *link = 3748 wiphy_dereference(wiphy, sdata->link[link_id]); 3749 3750 if (!link) 3751 continue; 3752 3753 link->user_power_level = local->user_power_level; 3754 if (txp_type != link->conf->txpower_type) 3755 update_txp_type = true; 3756 link->conf->txpower_type = txp_type; 3757 } 3758 } 3759 list_for_each_entry(sdata, &local->interfaces, list) { 3760 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && 3761 !ieee80211_hw_check(&local->hw, NO_VIRTUAL_MONITOR)) 3762 continue; 3763 3764 for (int link_id = 0; 3765 link_id < ARRAY_SIZE(sdata->link); 3766 link_id++) { 3767 struct ieee80211_link_data *link = 3768 wiphy_dereference(wiphy, sdata->link[link_id]); 3769 3770 if (!link) 3771 continue; 3772 3773 ieee80211_recalc_txpower(link, update_txp_type); 3774 } 3775 } 3776 3777 if (has_monitor) { 3778 sdata = wiphy_dereference(local->hw.wiphy, 3779 local->monitor_sdata); 3780 if (sdata && ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) { 3781 sdata->deflink.user_power_level = local->user_power_level; 3782 if (txp_type != sdata->vif.bss_conf.txpower_type) 3783 update_txp_type = true; 3784 sdata->vif.bss_conf.txpower_type = txp_type; 3785 3786 ieee80211_recalc_txpower(&sdata->deflink, 3787 update_txp_type); 3788 } 3789 } 3790 3791 if (local->emulate_chanctx && 3792 (old_power != local->user_power_level)) 3793 ieee80211_hw_conf_chan(local); 3794 3795 return 0; 3796 } 3797 3798 static int ieee80211_get_tx_power(struct wiphy *wiphy, 3799 struct wireless_dev *wdev, 3800 int radio_idx, 3801 unsigned int link_id, 3802 int *dbm) 3803 { 3804 struct ieee80211_local *local = wiphy_priv(wiphy); 3805 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3806 struct ieee80211_link_data *link_data; 3807 3808 if (local->ops->get_txpower && 3809 (sdata->flags & IEEE80211_SDATA_IN_DRIVER)) 3810 return drv_get_txpower(local, sdata, link_id, dbm); 3811 3812 if (local->emulate_chanctx) { 3813 *dbm = local->hw.conf.power_level; 3814 } else { 3815 link_data = wiphy_dereference(wiphy, sdata->link[link_id]); 3816 3817 if (link_data) 3818 *dbm = link_data->conf->txpower; 3819 else 3820 return -ENOLINK; 3821 } 3822 3823 /* INT_MIN indicates no power level was set yet */ 3824 if (*dbm == INT_MIN) 3825 return -EINVAL; 3826 3827 return 0; 3828 } 3829 3830 static void ieee80211_rfkill_poll(struct wiphy *wiphy) 3831 { 3832 struct ieee80211_local *local = wiphy_priv(wiphy); 3833 3834 drv_rfkill_poll(local); 3835 } 3836 3837 #ifdef CONFIG_NL80211_TESTMODE 3838 static int ieee80211_testmode_cmd(struct wiphy *wiphy, 3839 struct wireless_dev *wdev, 3840 void *data, int len) 3841 { 3842 struct ieee80211_local *local = wiphy_priv(wiphy); 3843 struct ieee80211_vif *vif = NULL; 3844 3845 if (!local->ops->testmode_cmd) 3846 return -EOPNOTSUPP; 3847 3848 if (wdev) { 3849 struct ieee80211_sub_if_data *sdata; 3850 3851 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 3852 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) 3853 vif = &sdata->vif; 3854 } 3855 3856 return local->ops->testmode_cmd(&local->hw, vif, data, len); 3857 } 3858 3859 static int ieee80211_testmode_dump(struct wiphy *wiphy, 3860 struct sk_buff *skb, 3861 struct netlink_callback *cb, 3862 void *data, int len) 3863 { 3864 struct ieee80211_local *local = wiphy_priv(wiphy); 3865 3866 if (!local->ops->testmode_dump) 3867 return -EOPNOTSUPP; 3868 3869 return local->ops->testmode_dump(&local->hw, skb, cb, data, len); 3870 } 3871 #endif 3872 3873 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, 3874 struct ieee80211_link_data *link, 3875 enum ieee80211_smps_mode smps_mode) 3876 { 3877 const u8 *ap; 3878 enum ieee80211_smps_mode old_req; 3879 int err; 3880 struct sta_info *sta; 3881 bool tdls_peer_found = false; 3882 3883 lockdep_assert_wiphy(sdata->local->hw.wiphy); 3884 3885 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) 3886 return -EINVAL; 3887 3888 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) 3889 return 0; 3890 3891 old_req = link->u.mgd.req_smps; 3892 link->u.mgd.req_smps = smps_mode; 3893 3894 /* The driver indicated that EML is enabled for the interface, which 3895 * implies that SMPS flows towards the AP should be stopped. 3896 */ 3897 if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE) 3898 return 0; 3899 3900 if (old_req == smps_mode && 3901 smps_mode != IEEE80211_SMPS_AUTOMATIC) 3902 return 0; 3903 3904 /* 3905 * If not associated, or current association is not an HT 3906 * association, there's no need to do anything, just store 3907 * the new value until we associate. 3908 */ 3909 if (!sdata->u.mgd.associated || 3910 link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT) 3911 return 0; 3912 3913 ap = sdata->vif.cfg.ap_addr; 3914 3915 rcu_read_lock(); 3916 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { 3917 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || 3918 !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) 3919 continue; 3920 3921 tdls_peer_found = true; 3922 break; 3923 } 3924 rcu_read_unlock(); 3925 3926 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { 3927 if (tdls_peer_found || !sdata->u.mgd.powersave) 3928 smps_mode = IEEE80211_SMPS_OFF; 3929 else 3930 smps_mode = IEEE80211_SMPS_DYNAMIC; 3931 } 3932 3933 /* send SM PS frame to AP */ 3934 err = ieee80211_send_smps_action(sdata, smps_mode, 3935 ap, ap, 3936 ieee80211_vif_is_mld(&sdata->vif) ? 3937 link->link_id : -1); 3938 if (err) 3939 link->u.mgd.req_smps = old_req; 3940 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) 3941 ieee80211_teardown_tdls_peers(link); 3942 3943 return err; 3944 } 3945 3946 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, 3947 bool enabled, int timeout) 3948 { 3949 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3950 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3951 unsigned int link_id; 3952 3953 if (sdata->vif.type != NL80211_IFTYPE_STATION) 3954 return -EOPNOTSUPP; 3955 3956 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) 3957 return -EOPNOTSUPP; 3958 3959 if (enabled == sdata->u.mgd.powersave && 3960 timeout == local->dynamic_ps_forced_timeout) 3961 return 0; 3962 3963 sdata->u.mgd.powersave = enabled; 3964 local->dynamic_ps_forced_timeout = timeout; 3965 3966 /* no change, but if automatic follow powersave */ 3967 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { 3968 struct ieee80211_link_data *link; 3969 3970 link = sdata_dereference(sdata->link[link_id], sdata); 3971 3972 if (!link) 3973 continue; 3974 __ieee80211_request_smps_mgd(sdata, link, 3975 link->u.mgd.req_smps); 3976 } 3977 3978 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) 3979 ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS); 3980 3981 ieee80211_recalc_ps(local); 3982 ieee80211_recalc_ps_vif(sdata); 3983 ieee80211_check_fast_rx_iface(sdata); 3984 3985 return 0; 3986 } 3987 3988 static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata, 3989 struct ieee80211_link_data *link, 3990 s32 rssi_thold, u32 rssi_hyst, 3991 s32 rssi_low, s32 rssi_high) 3992 { 3993 struct ieee80211_bss_conf *conf; 3994 3995 if (!link || !link->conf) 3996 return; 3997 3998 conf = link->conf; 3999 4000 if (rssi_thold && rssi_hyst && 4001 rssi_thold == conf->cqm_rssi_thold && 4002 rssi_hyst == conf->cqm_rssi_hyst) 4003 return; 4004 4005 conf->cqm_rssi_thold = rssi_thold; 4006 conf->cqm_rssi_hyst = rssi_hyst; 4007 conf->cqm_rssi_low = rssi_low; 4008 conf->cqm_rssi_high = rssi_high; 4009 link->u.mgd.last_cqm_event_signal = 0; 4010 4011 if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) 4012 return; 4013 4014 if (sdata->u.mgd.associated && 4015 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) 4016 ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM); 4017 } 4018 4019 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, 4020 struct net_device *dev, 4021 s32 rssi_thold, u32 rssi_hyst) 4022 { 4023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4024 struct ieee80211_vif *vif = &sdata->vif; 4025 int link_id; 4026 4027 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER && 4028 !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) 4029 return -EOPNOTSUPP; 4030 4031 /* For MLD, handle CQM change on all the active links */ 4032 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 4033 struct ieee80211_link_data *link = 4034 sdata_dereference(sdata->link[link_id], sdata); 4035 4036 ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst, 4037 0, 0); 4038 } 4039 4040 return 0; 4041 } 4042 4043 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, 4044 struct net_device *dev, 4045 s32 rssi_low, s32 rssi_high) 4046 { 4047 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4048 struct ieee80211_vif *vif = &sdata->vif; 4049 int link_id; 4050 4051 if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER) 4052 return -EOPNOTSUPP; 4053 4054 /* For MLD, handle CQM change on all the active links */ 4055 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { 4056 struct ieee80211_link_data *link = 4057 sdata_dereference(sdata->link[link_id], sdata); 4058 4059 ieee80211_set_cqm_rssi_link(sdata, link, 0, 0, 4060 rssi_low, rssi_high); 4061 } 4062 4063 return 0; 4064 } 4065 4066 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, 4067 struct net_device *dev, 4068 unsigned int link_id, 4069 const u8 *addr, 4070 const struct cfg80211_bitrate_mask *mask) 4071 { 4072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4073 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 4074 int i, ret; 4075 4076 if (!ieee80211_sdata_running(sdata)) 4077 return -ENETDOWN; 4078 4079 /* 4080 * If active validate the setting and reject it if it doesn't leave 4081 * at least one basic rate usable, since we really have to be able 4082 * to send something, and if we're an AP we have to be able to do 4083 * so at a basic rate so that all clients can receive it. 4084 */ 4085 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) && 4086 sdata->vif.bss_conf.chanreq.oper.chan) { 4087 u32 basic_rates = sdata->vif.bss_conf.basic_rates; 4088 enum nl80211_band band; 4089 4090 band = sdata->vif.bss_conf.chanreq.oper.chan->band; 4091 4092 if (!(mask->control[band].legacy & basic_rates)) 4093 return -EINVAL; 4094 } 4095 4096 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { 4097 ret = drv_set_bitrate_mask(local, sdata, mask); 4098 if (ret) 4099 return ret; 4100 } 4101 4102 for (i = 0; i < NUM_NL80211_BANDS; i++) { 4103 struct ieee80211_supported_band *sband = wiphy->bands[i]; 4104 int j; 4105 4106 sdata->rc_rateidx_mask[i] = mask->control[i].legacy; 4107 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, 4108 sizeof(mask->control[i].ht_mcs)); 4109 memcpy(sdata->rc_rateidx_vht_mcs_mask[i], 4110 mask->control[i].vht_mcs, 4111 sizeof(mask->control[i].vht_mcs)); 4112 4113 sdata->rc_has_mcs_mask[i] = false; 4114 sdata->rc_has_vht_mcs_mask[i] = false; 4115 if (!sband) 4116 continue; 4117 4118 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { 4119 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) { 4120 sdata->rc_has_mcs_mask[i] = true; 4121 break; 4122 } 4123 } 4124 4125 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { 4126 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) { 4127 sdata->rc_has_vht_mcs_mask[i] = true; 4128 break; 4129 } 4130 } 4131 } 4132 4133 return 0; 4134 } 4135 4136 static bool ieee80211_is_scan_ongoing(struct wiphy *wiphy, 4137 struct ieee80211_local *local, 4138 struct cfg80211_chan_def *chandef) 4139 { 4140 struct cfg80211_scan_request *scan_req; 4141 int chan_radio_idx, req_radio_idx; 4142 struct ieee80211_roc_work *roc; 4143 4144 if (list_empty(&local->roc_list) && !local->scanning) 4145 return false; 4146 4147 req_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chandef->chan); 4148 4149 if (local->scanning) { 4150 scan_req = wiphy_dereference(wiphy, local->scan_req); 4151 /* 4152 * Scan is going on but info is not there. Should not happen 4153 * but if it does, let's not take risk and assume we can't use 4154 * the hw hence return true 4155 */ 4156 if (WARN_ON_ONCE(!scan_req)) 4157 return true; 4158 4159 return ieee80211_is_radio_idx_in_scan_req(wiphy, scan_req, 4160 req_radio_idx); 4161 } 4162 4163 list_for_each_entry(roc, &local->roc_list, list) { 4164 chan_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, 4165 roc->chan); 4166 if (chan_radio_idx == req_radio_idx) 4167 return true; 4168 } 4169 4170 return false; 4171 } 4172 4173 static int ieee80211_start_radar_detection(struct wiphy *wiphy, 4174 struct net_device *dev, 4175 struct cfg80211_chan_def *chandef, 4176 u32 cac_time_ms, int link_id) 4177 { 4178 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4179 struct ieee80211_chan_req chanreq = { .oper = *chandef }; 4180 struct ieee80211_local *local = sdata->local; 4181 struct ieee80211_link_data *link_data; 4182 int err; 4183 4184 lockdep_assert_wiphy(local->hw.wiphy); 4185 4186 if (ieee80211_is_scan_ongoing(wiphy, local, chandef)) 4187 return -EBUSY; 4188 4189 link_data = sdata_dereference(sdata->link[link_id], sdata); 4190 if (!link_data) 4191 return -ENOLINK; 4192 4193 /* whatever, but channel contexts should not complain about that one */ 4194 link_data->smps_mode = IEEE80211_SMPS_OFF; 4195 link_data->needed_rx_chains = local->rx_chains; 4196 4197 err = ieee80211_link_use_channel(link_data, &chanreq, 4198 IEEE80211_CHANCTX_SHARED); 4199 if (err) 4200 return err; 4201 4202 wiphy_hrtimer_work_queue(wiphy, &link_data->dfs_cac_timer_work, 4203 ms_to_ktime(cac_time_ms)); 4204 4205 return 0; 4206 } 4207 4208 static void ieee80211_end_cac(struct wiphy *wiphy, 4209 struct net_device *dev, unsigned int link_id) 4210 { 4211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4212 struct ieee80211_local *local = sdata->local; 4213 struct ieee80211_link_data *link_data; 4214 4215 lockdep_assert_wiphy(local->hw.wiphy); 4216 4217 list_for_each_entry(sdata, &local->interfaces, list) { 4218 link_data = sdata_dereference(sdata->link[link_id], sdata); 4219 if (!link_data) 4220 continue; 4221 4222 wiphy_hrtimer_work_cancel(wiphy, 4223 &link_data->dfs_cac_timer_work); 4224 4225 if (sdata->wdev.links[link_id].cac_started) { 4226 ieee80211_link_release_channel(link_data); 4227 sdata->wdev.links[link_id].cac_started = false; 4228 } 4229 } 4230 } 4231 4232 static struct cfg80211_beacon_data * 4233 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) 4234 { 4235 struct cfg80211_beacon_data *new_beacon; 4236 u8 *pos; 4237 int len; 4238 4239 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + 4240 beacon->proberesp_ies_len + beacon->assocresp_ies_len + 4241 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len; 4242 4243 if (beacon->mbssid_ies) 4244 len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies, 4245 beacon->rnr_ies, 4246 beacon->mbssid_ies->cnt); 4247 4248 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); 4249 if (!new_beacon) 4250 return NULL; 4251 4252 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { 4253 new_beacon->mbssid_ies = 4254 kzalloc_flex(*new_beacon->mbssid_ies, elem, 4255 beacon->mbssid_ies->cnt); 4256 if (!new_beacon->mbssid_ies) { 4257 kfree(new_beacon); 4258 return NULL; 4259 } 4260 4261 if (beacon->rnr_ies && beacon->rnr_ies->cnt) { 4262 new_beacon->rnr_ies = 4263 kzalloc_flex(*new_beacon->rnr_ies, elem, 4264 beacon->rnr_ies->cnt); 4265 if (!new_beacon->rnr_ies) { 4266 kfree(new_beacon->mbssid_ies); 4267 kfree(new_beacon); 4268 return NULL; 4269 } 4270 } 4271 } 4272 4273 pos = (u8 *)(new_beacon + 1); 4274 if (beacon->head_len) { 4275 new_beacon->head_len = beacon->head_len; 4276 new_beacon->head = pos; 4277 memcpy(pos, beacon->head, beacon->head_len); 4278 pos += beacon->head_len; 4279 } 4280 if (beacon->tail_len) { 4281 new_beacon->tail_len = beacon->tail_len; 4282 new_beacon->tail = pos; 4283 memcpy(pos, beacon->tail, beacon->tail_len); 4284 pos += beacon->tail_len; 4285 } 4286 if (beacon->beacon_ies_len) { 4287 new_beacon->beacon_ies_len = beacon->beacon_ies_len; 4288 new_beacon->beacon_ies = pos; 4289 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); 4290 pos += beacon->beacon_ies_len; 4291 } 4292 if (beacon->proberesp_ies_len) { 4293 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; 4294 new_beacon->proberesp_ies = pos; 4295 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); 4296 pos += beacon->proberesp_ies_len; 4297 } 4298 if (beacon->assocresp_ies_len) { 4299 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; 4300 new_beacon->assocresp_ies = pos; 4301 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); 4302 pos += beacon->assocresp_ies_len; 4303 } 4304 if (beacon->probe_resp_len) { 4305 new_beacon->probe_resp_len = beacon->probe_resp_len; 4306 new_beacon->probe_resp = pos; 4307 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); 4308 pos += beacon->probe_resp_len; 4309 } 4310 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { 4311 pos += ieee80211_copy_mbssid_beacon(pos, 4312 new_beacon->mbssid_ies, 4313 beacon->mbssid_ies); 4314 if (beacon->rnr_ies && beacon->rnr_ies->cnt) 4315 pos += ieee80211_copy_rnr_beacon(pos, 4316 new_beacon->rnr_ies, 4317 beacon->rnr_ies); 4318 } 4319 4320 /* might copy -1, meaning no changes requested */ 4321 new_beacon->ftm_responder = beacon->ftm_responder; 4322 if (beacon->lci) { 4323 new_beacon->lci_len = beacon->lci_len; 4324 new_beacon->lci = pos; 4325 memcpy(pos, beacon->lci, beacon->lci_len); 4326 pos += beacon->lci_len; 4327 } 4328 if (beacon->civicloc) { 4329 new_beacon->civicloc_len = beacon->civicloc_len; 4330 new_beacon->civicloc = pos; 4331 memcpy(pos, beacon->civicloc, beacon->civicloc_len); 4332 pos += beacon->civicloc_len; 4333 } 4334 4335 return new_beacon; 4336 } 4337 4338 void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id) 4339 { 4340 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4341 struct ieee80211_local *local = sdata->local; 4342 struct ieee80211_bss_conf *tx_bss_conf; 4343 struct ieee80211_link_data *link_data; 4344 4345 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 4346 return; 4347 4348 rcu_read_lock(); 4349 4350 link_data = rcu_dereference(sdata->link[link_id]); 4351 if (WARN_ON(!link_data)) { 4352 rcu_read_unlock(); 4353 return; 4354 } 4355 4356 tx_bss_conf = rcu_dereference(link_data->conf->tx_bss_conf); 4357 if (tx_bss_conf == link_data->conf) { 4358 /* Trigger ieee80211_csa_finish() on the non-transmitting 4359 * interfaces when channel switch is received on 4360 * transmitting interface 4361 */ 4362 struct ieee80211_link_data *iter; 4363 4364 for_each_sdata_link_rcu(local, iter) { 4365 if (iter->sdata == sdata || 4366 rcu_access_pointer(iter->conf->tx_bss_conf) != tx_bss_conf) 4367 continue; 4368 4369 wiphy_work_queue(iter->sdata->local->hw.wiphy, 4370 &iter->csa.finalize_work); 4371 } 4372 } 4373 4374 wiphy_work_queue(local->hw.wiphy, &link_data->csa.finalize_work); 4375 4376 rcu_read_unlock(); 4377 } 4378 EXPORT_SYMBOL(ieee80211_csa_finish); 4379 4380 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif) 4381 { 4382 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 4383 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 4384 struct ieee80211_local *local = sdata->local; 4385 4386 sdata_info(sdata, "channel switch failed, disconnecting\n"); 4387 wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work); 4388 } 4389 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect); 4390 4391 static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data, 4392 u64 *changed) 4393 { 4394 struct ieee80211_sub_if_data *sdata = link_data->sdata; 4395 int err; 4396 4397 switch (sdata->vif.type) { 4398 case NL80211_IFTYPE_AP: 4399 if (!link_data->u.ap.next_beacon) 4400 return -EINVAL; 4401 4402 err = ieee80211_assign_beacon(sdata, link_data, 4403 link_data->u.ap.next_beacon, 4404 NULL, NULL, changed); 4405 ieee80211_free_next_beacon(link_data); 4406 4407 if (err < 0) 4408 return err; 4409 break; 4410 case NL80211_IFTYPE_ADHOC: 4411 err = ieee80211_ibss_finish_csa(sdata, changed); 4412 if (err < 0) 4413 return err; 4414 break; 4415 #ifdef CONFIG_MAC80211_MESH 4416 case NL80211_IFTYPE_MESH_POINT: 4417 err = ieee80211_mesh_finish_csa(sdata, changed); 4418 if (err < 0) 4419 return err; 4420 break; 4421 #endif 4422 default: 4423 WARN_ON(1); 4424 return -EINVAL; 4425 } 4426 4427 return 0; 4428 } 4429 4430 static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data) 4431 { 4432 struct ieee80211_sub_if_data *sdata = link_data->sdata; 4433 struct ieee80211_local *local = sdata->local; 4434 struct ieee80211_bss_conf *link_conf = link_data->conf; 4435 u64 changed = 0; 4436 int err; 4437 4438 lockdep_assert_wiphy(local->hw.wiphy); 4439 4440 /* 4441 * using reservation isn't immediate as it may be deferred until later 4442 * with multi-vif. once reservation is complete it will re-schedule the 4443 * work with no reserved_chanctx so verify chandef to check if it 4444 * completed successfully 4445 */ 4446 4447 if (link_data->reserved_chanctx) { 4448 /* 4449 * with multi-vif csa driver may call ieee80211_csa_finish() 4450 * many times while waiting for other interfaces to use their 4451 * reservations 4452 */ 4453 if (link_data->reserved_ready) 4454 return 0; 4455 4456 return ieee80211_link_use_reserved_context(link_data); 4457 } 4458 4459 if (!cfg80211_chandef_identical(&link_conf->chanreq.oper, 4460 &link_data->csa.chanreq.oper)) 4461 return -EINVAL; 4462 4463 link_conf->csa_active = false; 4464 4465 err = ieee80211_set_after_csa_beacon(link_data, &changed); 4466 if (err) 4467 return err; 4468 4469 ieee80211_link_info_change_notify(sdata, link_data, changed); 4470 4471 ieee80211_vif_unblock_queues_csa(sdata); 4472 4473 err = drv_post_channel_switch(link_data); 4474 if (err) 4475 return err; 4476 4477 cfg80211_ch_switch_notify(sdata->dev, &link_data->csa.chanreq.oper, 4478 link_data->link_id); 4479 4480 return 0; 4481 } 4482 4483 static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data) 4484 { 4485 struct ieee80211_sub_if_data *sdata = link_data->sdata; 4486 int link_id = -1; 4487 4488 if (__ieee80211_csa_finalize(link_data)) { 4489 sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n", 4490 link_data->link_id); 4491 if (sdata->vif.type == NL80211_IFTYPE_AP || 4492 sdata->vif.type == NL80211_IFTYPE_P2P_GO) 4493 /* 4494 * link_id is expected only for AP/P2P_GO type 4495 * currently 4496 */ 4497 link_id = link_data->link_id; 4498 4499 cfg80211_stop_link(sdata->local->hw.wiphy, &sdata->wdev, 4500 link_id, GFP_KERNEL); 4501 } 4502 } 4503 4504 void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work) 4505 { 4506 struct ieee80211_link_data *link = 4507 container_of(work, struct ieee80211_link_data, csa.finalize_work); 4508 struct ieee80211_sub_if_data *sdata = link->sdata; 4509 struct ieee80211_local *local = sdata->local; 4510 4511 lockdep_assert_wiphy(local->hw.wiphy); 4512 4513 /* AP might have been stopped while waiting for the lock. */ 4514 if (!link->conf->csa_active) 4515 return; 4516 4517 if (!ieee80211_sdata_running(sdata)) 4518 return; 4519 4520 ieee80211_csa_finalize(link); 4521 } 4522 4523 static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data, 4524 struct cfg80211_csa_settings *params, 4525 u64 *changed) 4526 { 4527 struct ieee80211_sub_if_data *sdata = link_data->sdata; 4528 struct ieee80211_csa_settings csa = {}; 4529 int err; 4530 4531 switch (sdata->vif.type) { 4532 case NL80211_IFTYPE_AP: 4533 link_data->u.ap.next_beacon = 4534 cfg80211_beacon_dup(¶ms->beacon_after); 4535 if (!link_data->u.ap.next_beacon) 4536 return -ENOMEM; 4537 4538 /* 4539 * With a count of 0, we don't have to wait for any 4540 * TBTT before switching, so complete the CSA 4541 * immediately. In theory, with a count == 1 we 4542 * should delay the switch until just before the next 4543 * TBTT, but that would complicate things so we switch 4544 * immediately too. If we would delay the switch 4545 * until the next TBTT, we would have to set the probe 4546 * response here. 4547 * 4548 * TODO: A channel switch with count <= 1 without 4549 * sending a CSA action frame is kind of useless, 4550 * because the clients won't know we're changing 4551 * channels. The action frame must be implemented 4552 * either here or in the userspace. 4553 */ 4554 if (params->count <= 1) 4555 break; 4556 4557 if ((params->n_counter_offsets_beacon > 4558 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) || 4559 (params->n_counter_offsets_presp > 4560 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) { 4561 ieee80211_free_next_beacon(link_data); 4562 return -EINVAL; 4563 } 4564 4565 csa.counter_offsets_beacon = params->counter_offsets_beacon; 4566 csa.counter_offsets_presp = params->counter_offsets_presp; 4567 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; 4568 csa.n_counter_offsets_presp = params->n_counter_offsets_presp; 4569 csa.count = params->count; 4570 4571 err = ieee80211_assign_beacon(sdata, link_data, 4572 ¶ms->beacon_csa, &csa, 4573 NULL, changed); 4574 if (err < 0) { 4575 ieee80211_free_next_beacon(link_data); 4576 return err; 4577 } 4578 4579 break; 4580 case NL80211_IFTYPE_ADHOC: 4581 if (!sdata->vif.cfg.ibss_joined) 4582 return -EINVAL; 4583 4584 if (params->chandef.width != sdata->u.ibss.chandef.width) 4585 return -EINVAL; 4586 4587 switch (params->chandef.width) { 4588 case NL80211_CHAN_WIDTH_40: 4589 if (cfg80211_get_chandef_type(¶ms->chandef) != 4590 cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) 4591 return -EINVAL; 4592 break; 4593 case NL80211_CHAN_WIDTH_5: 4594 case NL80211_CHAN_WIDTH_10: 4595 case NL80211_CHAN_WIDTH_20_NOHT: 4596 case NL80211_CHAN_WIDTH_20: 4597 break; 4598 default: 4599 return -EINVAL; 4600 } 4601 4602 /* changes into another band are not supported */ 4603 if (sdata->u.ibss.chandef.chan->band != 4604 params->chandef.chan->band) 4605 return -EINVAL; 4606 4607 /* see comments in the NL80211_IFTYPE_AP block */ 4608 if (params->count > 1) { 4609 err = ieee80211_ibss_csa_beacon(sdata, params, changed); 4610 if (err < 0) 4611 return err; 4612 } 4613 4614 ieee80211_send_action_csa(sdata, params); 4615 4616 break; 4617 #ifdef CONFIG_MAC80211_MESH 4618 case NL80211_IFTYPE_MESH_POINT: { 4619 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 4620 4621 /* changes into another band are not supported */ 4622 if (sdata->vif.bss_conf.chanreq.oper.chan->band != 4623 params->chandef.chan->band) 4624 return -EINVAL; 4625 4626 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { 4627 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; 4628 if (!ifmsh->pre_value) 4629 ifmsh->pre_value = 1; 4630 else 4631 ifmsh->pre_value++; 4632 } 4633 4634 /* see comments in the NL80211_IFTYPE_AP block */ 4635 if (params->count > 1) { 4636 err = ieee80211_mesh_csa_beacon(sdata, params, changed); 4637 if (err < 0) { 4638 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; 4639 return err; 4640 } 4641 } 4642 4643 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) 4644 ieee80211_send_action_csa(sdata, params); 4645 4646 break; 4647 } 4648 #endif 4649 default: 4650 return -EOPNOTSUPP; 4651 } 4652 4653 return 0; 4654 } 4655 4656 static void ieee80211_color_change_abort(struct ieee80211_link_data *link) 4657 { 4658 link->conf->color_change_active = false; 4659 4660 ieee80211_free_next_beacon(link); 4661 4662 cfg80211_color_change_aborted_notify(link->sdata->dev, link->link_id); 4663 } 4664 4665 static int 4666 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 4667 struct cfg80211_csa_settings *params) 4668 { 4669 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4670 struct ieee80211_chan_req chanreq = { 4671 .oper = params->chandef, 4672 .require_npca = true, 4673 }; 4674 struct ieee80211_local *local = sdata->local; 4675 struct ieee80211_channel_switch ch_switch = { 4676 .link_id = params->link_id, 4677 }; 4678 struct ieee80211_chanctx_conf *conf; 4679 struct ieee80211_chanctx *chanctx; 4680 struct ieee80211_bss_conf *link_conf; 4681 struct ieee80211_link_data *link_data; 4682 u64 changed = 0; 4683 u8 link_id = params->link_id; 4684 int err; 4685 4686 lockdep_assert_wiphy(local->hw.wiphy); 4687 4688 if (ieee80211_is_scan_ongoing(wiphy, local, ¶ms->chandef)) 4689 return -EBUSY; 4690 4691 if (sdata->wdev.links[link_id].cac_started) 4692 return -EBUSY; 4693 4694 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 4695 return -EINVAL; 4696 4697 link_data = wiphy_dereference(wiphy, sdata->link[link_id]); 4698 if (!link_data) 4699 return -ENOLINK; 4700 4701 link_conf = link_data->conf; 4702 4703 if (chanreq.oper.punctured && !link_conf->eht_support) 4704 return -EINVAL; 4705 4706 /* don't allow another channel switch if one is already active. */ 4707 if (link_conf->csa_active) 4708 return -EBUSY; 4709 4710 conf = wiphy_dereference(wiphy, link_conf->chanctx_conf); 4711 if (!conf) { 4712 err = -EBUSY; 4713 goto out; 4714 } 4715 4716 if (params->chandef.chan->freq_offset) { 4717 /* this may work, but is untested */ 4718 err = -EOPNOTSUPP; 4719 goto out; 4720 } 4721 4722 err = ieee80211_set_unsol_bcast_probe_resp(sdata, 4723 ¶ms->unsol_bcast_probe_resp, 4724 link_data, link_conf, &changed); 4725 if (err) 4726 goto out; 4727 4728 chanctx = container_of(conf, struct ieee80211_chanctx, conf); 4729 4730 ch_switch.timestamp = 0; 4731 ch_switch.device_timestamp = 0; 4732 ch_switch.block_tx = params->block_tx; 4733 ch_switch.chandef = chanreq.oper; 4734 ch_switch.count = params->count; 4735 4736 err = drv_pre_channel_switch(sdata, &ch_switch); 4737 if (err) 4738 goto out; 4739 4740 err = ieee80211_link_reserve_chanctx(link_data, &chanreq, 4741 chanctx->mode, 4742 params->radar_required); 4743 if (err) 4744 goto out; 4745 4746 /* if reservation is invalid then this will fail */ 4747 err = ieee80211_check_combinations(sdata, NULL, 0, 0, -1); 4748 if (err) { 4749 ieee80211_link_unreserve_chanctx(link_data); 4750 goto out; 4751 } 4752 4753 /* if there is a color change in progress, abort it */ 4754 if (link_conf->color_change_active) 4755 ieee80211_color_change_abort(link_data); 4756 4757 err = ieee80211_set_csa_beacon(link_data, params, &changed); 4758 if (err) { 4759 ieee80211_link_unreserve_chanctx(link_data); 4760 goto out; 4761 } 4762 4763 link_data->csa.chanreq = chanreq; 4764 link_conf->csa_active = true; 4765 4766 if (params->block_tx) 4767 ieee80211_vif_block_queues_csa(sdata); 4768 4769 cfg80211_ch_switch_started_notify(sdata->dev, 4770 &link_data->csa.chanreq.oper, link_id, 4771 params->count, params->block_tx); 4772 4773 if (changed) { 4774 ieee80211_link_info_change_notify(sdata, link_data, changed); 4775 drv_channel_switch_beacon(sdata, &link_data->csa.chanreq.oper); 4776 } else { 4777 /* if the beacon didn't change, we can finalize immediately */ 4778 ieee80211_csa_finalize(link_data); 4779 } 4780 4781 out: 4782 return err; 4783 } 4784 4785 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, 4786 struct cfg80211_csa_settings *params) 4787 { 4788 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4789 struct ieee80211_local *local = sdata->local; 4790 4791 lockdep_assert_wiphy(local->hw.wiphy); 4792 4793 return __ieee80211_channel_switch(wiphy, dev, params); 4794 } 4795 4796 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) 4797 { 4798 lockdep_assert_wiphy(local->hw.wiphy); 4799 4800 local->roc_cookie_counter++; 4801 4802 /* wow, you wrapped 64 bits ... more likely a bug */ 4803 if (WARN_ON(local->roc_cookie_counter == 0)) 4804 local->roc_cookie_counter++; 4805 4806 return local->roc_cookie_counter; 4807 } 4808 4809 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, 4810 u64 *cookie, gfp_t gfp) 4811 { 4812 unsigned long spin_flags; 4813 struct sk_buff *ack_skb; 4814 int id; 4815 4816 ack_skb = skb_copy(skb, gfp); 4817 if (!ack_skb) 4818 return -ENOMEM; 4819 4820 spin_lock_irqsave(&local->ack_status_lock, spin_flags); 4821 id = idr_alloc(&local->ack_status_frames, ack_skb, 4822 1, 0x2000, GFP_ATOMIC); 4823 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); 4824 4825 if (id < 0) { 4826 kfree_skb(ack_skb); 4827 return -ENOMEM; 4828 } 4829 4830 IEEE80211_SKB_CB(skb)->status_data_idr = 1; 4831 IEEE80211_SKB_CB(skb)->status_data = id; 4832 4833 *cookie = ieee80211_mgmt_tx_cookie(local); 4834 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; 4835 4836 return 0; 4837 } 4838 4839 static void 4840 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy, 4841 struct wireless_dev *wdev, 4842 struct mgmt_frame_regs *upd) 4843 { 4844 struct ieee80211_local *local = wiphy_priv(wiphy); 4845 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 4846 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4); 4847 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4); 4848 bool global_change, intf_change; 4849 4850 global_change = 4851 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) || 4852 (local->rx_mcast_action_reg != 4853 !!(upd->global_mcast_stypes & action_mask)); 4854 local->probe_req_reg = upd->global_stypes & preq_mask; 4855 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask; 4856 4857 intf_change = (sdata->vif.probe_req_reg != 4858 !!(upd->interface_stypes & preq_mask)) || 4859 (sdata->vif.rx_mcast_action_reg != 4860 !!(upd->interface_mcast_stypes & action_mask)); 4861 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask; 4862 sdata->vif.rx_mcast_action_reg = 4863 upd->interface_mcast_stypes & action_mask; 4864 4865 if (!local->open_count) 4866 return; 4867 4868 if (intf_change && ieee80211_sdata_running(sdata)) 4869 drv_config_iface_filter(local, sdata, 4870 sdata->vif.probe_req_reg ? 4871 FIF_PROBE_REQ : 0, 4872 FIF_PROBE_REQ); 4873 4874 if (global_change) 4875 ieee80211_configure_filter(local); 4876 } 4877 4878 static int ieee80211_set_antenna(struct wiphy *wiphy, int radio_idx, 4879 u32 tx_ant, u32 rx_ant) 4880 { 4881 struct ieee80211_local *local = wiphy_priv(wiphy); 4882 int ret; 4883 4884 if (local->started) 4885 return -EOPNOTSUPP; 4886 4887 ret = drv_set_antenna(local, tx_ant, rx_ant); 4888 if (ret) 4889 return ret; 4890 4891 local->rx_chains = hweight8(rx_ant); 4892 return 0; 4893 } 4894 4895 static int ieee80211_get_antenna(struct wiphy *wiphy, int radio_idx, 4896 u32 *tx_ant, u32 *rx_ant) 4897 { 4898 struct ieee80211_local *local = wiphy_priv(wiphy); 4899 4900 return drv_get_antenna(local, radio_idx, tx_ant, rx_ant); 4901 } 4902 4903 static int ieee80211_set_rekey_data(struct wiphy *wiphy, 4904 struct net_device *dev, 4905 struct cfg80211_gtk_rekey_data *data) 4906 { 4907 struct ieee80211_local *local = wiphy_priv(wiphy); 4908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4909 4910 if (!local->ops->set_rekey_data) 4911 return -EOPNOTSUPP; 4912 4913 drv_set_rekey_data(local, sdata, data); 4914 4915 return 0; 4916 } 4917 4918 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, 4919 const u8 *peer, u64 *cookie) 4920 { 4921 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 4922 struct ieee80211_local *local = sdata->local; 4923 struct ieee80211_qos_hdr *nullfunc; 4924 struct sk_buff *skb; 4925 int size = sizeof(*nullfunc); 4926 __le16 fc; 4927 bool qos; 4928 struct ieee80211_tx_info *info; 4929 struct sta_info *sta; 4930 struct ieee80211_chanctx_conf *chanctx_conf; 4931 struct ieee80211_bss_conf *conf; 4932 enum nl80211_band band; 4933 u8 link_id; 4934 int ret; 4935 4936 /* the lock is needed to assign the cookie later */ 4937 lockdep_assert_wiphy(local->hw.wiphy); 4938 4939 rcu_read_lock(); 4940 sta = sta_info_get_bss(sdata, peer); 4941 if (!sta) { 4942 ret = -ENOLINK; 4943 goto unlock; 4944 } 4945 4946 qos = sta->sta.wme; 4947 4948 if (ieee80211_vif_is_mld(&sdata->vif)) { 4949 if (sta->sta.mlo) { 4950 link_id = IEEE80211_LINK_UNSPECIFIED; 4951 } else { 4952 /* 4953 * For non-MLO clients connected to an AP MLD, band 4954 * information is not used; instead, sta->deflink is 4955 * used to send packets. 4956 */ 4957 link_id = sta->deflink.link_id; 4958 4959 conf = rcu_dereference(sdata->vif.link_conf[link_id]); 4960 4961 if (unlikely(!conf)) { 4962 ret = -ENOLINK; 4963 goto unlock; 4964 } 4965 } 4966 /* MLD transmissions must not rely on the band */ 4967 band = 0; 4968 } else { 4969 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); 4970 if (WARN_ON(!chanctx_conf)) { 4971 ret = -EINVAL; 4972 goto unlock; 4973 } 4974 band = chanctx_conf->def.chan->band; 4975 link_id = 0; 4976 } 4977 4978 if (qos) { 4979 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 4980 IEEE80211_STYPE_QOS_NULLFUNC | 4981 IEEE80211_FCTL_FROMDS); 4982 } else { 4983 size -= 2; 4984 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | 4985 IEEE80211_STYPE_NULLFUNC | 4986 IEEE80211_FCTL_FROMDS); 4987 } 4988 4989 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); 4990 if (!skb) { 4991 ret = -ENOMEM; 4992 goto unlock; 4993 } 4994 4995 skb->dev = dev; 4996 4997 skb_reserve(skb, local->hw.extra_tx_headroom); 4998 4999 nullfunc = skb_put(skb, size); 5000 nullfunc->frame_control = fc; 5001 nullfunc->duration_id = 0; 5002 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); 5003 if (ieee80211_vif_is_mld(&sdata->vif) && !sta->sta.mlo) { 5004 memcpy(nullfunc->addr2, conf->addr, ETH_ALEN); 5005 memcpy(nullfunc->addr3, conf->addr, ETH_ALEN); 5006 } else { 5007 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); 5008 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); 5009 } 5010 nullfunc->seq_ctrl = 0; 5011 5012 info = IEEE80211_SKB_CB(skb); 5013 5014 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | 5015 IEEE80211_TX_INTFL_NL80211_FRAME_TX; 5016 info->band = band; 5017 5018 info->control.flags |= u32_encode_bits(link_id, 5019 IEEE80211_TX_CTRL_MLO_LINK); 5020 skb_set_queue_mapping(skb, IEEE80211_AC_VO); 5021 skb->priority = 7; 5022 if (qos) 5023 nullfunc->qos_ctrl = cpu_to_le16(7); 5024 5025 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); 5026 if (ret) { 5027 kfree_skb(skb); 5028 goto unlock; 5029 } 5030 5031 local_bh_disable(); 5032 ieee80211_xmit(sdata, sta, skb); 5033 local_bh_enable(); 5034 5035 ret = 0; 5036 unlock: 5037 rcu_read_unlock(); 5038 5039 return ret; 5040 } 5041 5042 static int ieee80211_cfg_get_channel(struct wiphy *wiphy, 5043 struct wireless_dev *wdev, 5044 unsigned int link_id, 5045 struct cfg80211_chan_def *chandef) 5046 { 5047 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5048 struct ieee80211_local *local = wiphy_priv(wiphy); 5049 struct ieee80211_chanctx_conf *chanctx_conf; 5050 struct ieee80211_link_data *link; 5051 int ret = -ENODATA; 5052 5053 rcu_read_lock(); 5054 link = rcu_dereference(sdata->link[link_id]); 5055 if (!link) { 5056 ret = -ENOLINK; 5057 goto out; 5058 } 5059 5060 chanctx_conf = rcu_dereference(link->conf->chanctx_conf); 5061 if (chanctx_conf) { 5062 *chandef = link->conf->chanreq.oper; 5063 ret = 0; 5064 } else if (local->open_count > 0 && 5065 local->open_count == local->virt_monitors && 5066 sdata->vif.type == NL80211_IFTYPE_MONITOR) { 5067 *chandef = local->monitor_chanreq.oper; 5068 ret = 0; 5069 } 5070 out: 5071 rcu_read_unlock(); 5072 5073 return ret; 5074 } 5075 5076 #ifdef CONFIG_PM 5077 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) 5078 { 5079 drv_set_wakeup(wiphy_priv(wiphy), enabled); 5080 } 5081 #endif 5082 5083 static int ieee80211_set_qos_map(struct wiphy *wiphy, 5084 struct net_device *dev, 5085 struct cfg80211_qos_map *qos_map) 5086 { 5087 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5088 struct mac80211_qos_map *new_qos_map, *old_qos_map; 5089 5090 if (qos_map) { 5091 new_qos_map = kzalloc_obj(*new_qos_map); 5092 if (!new_qos_map) 5093 return -ENOMEM; 5094 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); 5095 } else { 5096 /* A NULL qos_map was passed to disable QoS mapping */ 5097 new_qos_map = NULL; 5098 } 5099 5100 old_qos_map = sdata_dereference(sdata->qos_map, sdata); 5101 rcu_assign_pointer(sdata->qos_map, new_qos_map); 5102 if (old_qos_map) 5103 kfree_rcu(old_qos_map, rcu_head); 5104 5105 return 0; 5106 } 5107 5108 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, 5109 struct net_device *dev, 5110 unsigned int link_id, 5111 struct cfg80211_chan_def *chandef) 5112 { 5113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5114 struct ieee80211_link_data *link; 5115 struct ieee80211_chan_req chanreq = { 5116 .oper = *chandef, 5117 .require_npca = true, 5118 }; 5119 int ret; 5120 u64 changed = 0; 5121 5122 link = sdata_dereference(sdata->link[link_id], sdata); 5123 5124 ret = ieee80211_link_change_chanreq(link, &chanreq, &changed); 5125 if (ret == 0) 5126 ieee80211_link_info_change_notify(sdata, link, changed); 5127 5128 return ret; 5129 } 5130 5131 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, 5132 u8 tsid, const u8 *peer, u8 up, 5133 u16 admitted_time) 5134 { 5135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5136 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5137 int ac = ieee802_1d_to_ac[up]; 5138 5139 if (sdata->vif.type != NL80211_IFTYPE_STATION) 5140 return -EOPNOTSUPP; 5141 5142 if (!(sdata->wmm_acm & BIT(up))) 5143 return -EINVAL; 5144 5145 if (ifmgd->tx_tspec[ac].admitted_time) 5146 return -EBUSY; 5147 5148 if (admitted_time) { 5149 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; 5150 ifmgd->tx_tspec[ac].tsid = tsid; 5151 ifmgd->tx_tspec[ac].up = up; 5152 } 5153 5154 return 0; 5155 } 5156 5157 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, 5158 u8 tsid, const u8 *peer) 5159 { 5160 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5161 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 5162 struct ieee80211_local *local = wiphy_priv(wiphy); 5163 int ac; 5164 5165 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 5166 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; 5167 5168 /* skip unused entries */ 5169 if (!tx_tspec->admitted_time) 5170 continue; 5171 5172 if (tx_tspec->tsid != tsid) 5173 continue; 5174 5175 /* due to this new packets will be reassigned to non-ACM ACs */ 5176 tx_tspec->up = -1; 5177 5178 /* Make sure that all packets have been sent to avoid to 5179 * restore the QoS params on packets that are still on the 5180 * queues. 5181 */ 5182 synchronize_net(); 5183 ieee80211_flush_queues(local, sdata, false); 5184 5185 /* restore the normal QoS parameters 5186 * (unconditionally to avoid races) 5187 */ 5188 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; 5189 tx_tspec->downgraded = false; 5190 ieee80211_sta_handle_tspec_ac_params(sdata); 5191 5192 /* finally clear all the data */ 5193 memset(tx_tspec, 0, sizeof(*tx_tspec)); 5194 5195 return 0; 5196 } 5197 5198 return -ENOENT; 5199 } 5200 5201 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, 5202 u8 inst_id, 5203 enum nl80211_nan_func_term_reason reason, 5204 gfp_t gfp) 5205 { 5206 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5207 struct cfg80211_nan_func *func; 5208 u64 cookie; 5209 5210 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) 5211 return; 5212 5213 if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags & 5214 WIPHY_NAN_FLAGS_USERSPACE_DE)) 5215 return; 5216 5217 spin_lock_bh(&sdata->u.nan.de.func_lock); 5218 5219 func = idr_find(&sdata->u.nan.de.function_inst_ids, inst_id); 5220 if (WARN_ON(!func)) { 5221 spin_unlock_bh(&sdata->u.nan.de.func_lock); 5222 return; 5223 } 5224 5225 cookie = func->cookie; 5226 idr_remove(&sdata->u.nan.de.function_inst_ids, inst_id); 5227 5228 spin_unlock_bh(&sdata->u.nan.de.func_lock); 5229 5230 cfg80211_free_nan_func(func); 5231 5232 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, 5233 reason, cookie, gfp); 5234 } 5235 EXPORT_SYMBOL(ieee80211_nan_func_terminated); 5236 5237 void ieee80211_nan_func_match(struct ieee80211_vif *vif, 5238 struct cfg80211_nan_match_params *match, 5239 gfp_t gfp) 5240 { 5241 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5242 struct cfg80211_nan_func *func; 5243 5244 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) 5245 return; 5246 5247 if (WARN_ON(sdata->local->hw.wiphy->nan_capa.flags & 5248 WIPHY_NAN_FLAGS_USERSPACE_DE)) 5249 return; 5250 5251 spin_lock_bh(&sdata->u.nan.de.func_lock); 5252 5253 func = idr_find(&sdata->u.nan.de.function_inst_ids, match->inst_id); 5254 if (WARN_ON(!func)) { 5255 spin_unlock_bh(&sdata->u.nan.de.func_lock); 5256 return; 5257 } 5258 match->cookie = func->cookie; 5259 5260 spin_unlock_bh(&sdata->u.nan.de.func_lock); 5261 5262 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); 5263 } 5264 EXPORT_SYMBOL(ieee80211_nan_func_match); 5265 5266 void ieee80211_nan_cluster_joined(struct ieee80211_vif *vif, 5267 const u8 *cluster_id, bool new_cluster, 5268 gfp_t gfp) 5269 { 5270 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5271 5272 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) 5273 return; 5274 5275 if (WARN_ON(!sdata->u.nan.started)) 5276 return; 5277 5278 ether_addr_copy(sdata->u.nan.conf.cluster_id, cluster_id); 5279 5280 cfg80211_nan_cluster_joined(ieee80211_vif_to_wdev(vif), cluster_id, 5281 new_cluster, gfp); 5282 } 5283 EXPORT_SYMBOL(ieee80211_nan_cluster_joined); 5284 5285 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, 5286 struct net_device *dev, 5287 const bool enabled) 5288 { 5289 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5290 5291 sdata->u.ap.multicast_to_unicast = enabled; 5292 5293 return 0; 5294 } 5295 5296 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, 5297 struct txq_info *txqi) 5298 { 5299 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { 5300 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); 5301 txqstats->backlog_bytes = txqi->tin.backlog_bytes; 5302 } 5303 5304 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { 5305 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); 5306 txqstats->backlog_packets = txqi->tin.backlog_packets; 5307 } 5308 5309 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { 5310 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); 5311 txqstats->flows = txqi->tin.flows; 5312 } 5313 5314 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { 5315 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); 5316 txqstats->drops = txqi->cstats.drop_count; 5317 } 5318 5319 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { 5320 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); 5321 txqstats->ecn_marks = txqi->cstats.ecn_mark; 5322 } 5323 5324 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { 5325 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); 5326 txqstats->overlimit = txqi->tin.overlimit; 5327 } 5328 5329 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { 5330 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); 5331 txqstats->collisions = txqi->tin.collisions; 5332 } 5333 5334 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { 5335 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); 5336 txqstats->tx_bytes = txqi->tin.tx_bytes; 5337 } 5338 5339 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { 5340 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); 5341 txqstats->tx_packets = txqi->tin.tx_packets; 5342 } 5343 } 5344 5345 static int ieee80211_get_txq_stats(struct wiphy *wiphy, 5346 struct wireless_dev *wdev, 5347 struct cfg80211_txq_stats *txqstats) 5348 { 5349 struct ieee80211_local *local = wiphy_priv(wiphy); 5350 struct ieee80211_sub_if_data *sdata; 5351 int ret = 0; 5352 5353 spin_lock_bh(&local->fq.lock); 5354 5355 if (wdev) { 5356 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5357 if (!sdata->vif.txq) { 5358 ret = 1; 5359 goto out; 5360 } 5361 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); 5362 } else { 5363 /* phy stats */ 5364 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | 5365 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | 5366 BIT(NL80211_TXQ_STATS_OVERLIMIT) | 5367 BIT(NL80211_TXQ_STATS_OVERMEMORY) | 5368 BIT(NL80211_TXQ_STATS_COLLISIONS) | 5369 BIT(NL80211_TXQ_STATS_MAX_FLOWS); 5370 txqstats->backlog_packets = local->fq.backlog; 5371 txqstats->backlog_bytes = local->fq.memory_usage; 5372 txqstats->overlimit = local->fq.overlimit; 5373 txqstats->overmemory = local->fq.overmemory; 5374 txqstats->collisions = local->fq.collisions; 5375 txqstats->max_flows = local->fq.flows_cnt; 5376 } 5377 5378 out: 5379 spin_unlock_bh(&local->fq.lock); 5380 5381 return ret; 5382 } 5383 5384 static int 5385 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy, 5386 struct net_device *dev, 5387 struct cfg80211_ftm_responder_stats *ftm_stats) 5388 { 5389 struct ieee80211_local *local = wiphy_priv(wiphy); 5390 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5391 5392 return drv_get_ftm_responder_stats(local, sdata, ftm_stats); 5393 } 5394 5395 static int 5396 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, 5397 struct cfg80211_pmsr_request *request) 5398 { 5399 struct ieee80211_local *local = wiphy_priv(wiphy); 5400 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); 5401 5402 return drv_start_pmsr(local, sdata, request); 5403 } 5404 5405 static void 5406 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, 5407 struct cfg80211_pmsr_request *request) 5408 { 5409 struct ieee80211_local *local = wiphy_priv(wiphy); 5410 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); 5411 5412 return drv_abort_pmsr(local, sdata, request); 5413 } 5414 5415 static int ieee80211_set_tid_config(struct wiphy *wiphy, 5416 struct net_device *dev, 5417 struct cfg80211_tid_config *tid_conf) 5418 { 5419 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5420 struct sta_info *sta; 5421 5422 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5423 5424 if (!sdata->local->ops->set_tid_config) 5425 return -EOPNOTSUPP; 5426 5427 if (!tid_conf->peer) 5428 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf); 5429 5430 sta = sta_info_get_bss(sdata, tid_conf->peer); 5431 if (!sta) 5432 return -ENOENT; 5433 5434 return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf); 5435 } 5436 5437 static int ieee80211_reset_tid_config(struct wiphy *wiphy, 5438 struct net_device *dev, 5439 const u8 *peer, u8 tids) 5440 { 5441 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5442 struct sta_info *sta; 5443 5444 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5445 5446 if (!sdata->local->ops->reset_tid_config) 5447 return -EOPNOTSUPP; 5448 5449 if (!peer) 5450 return drv_reset_tid_config(sdata->local, sdata, NULL, tids); 5451 5452 sta = sta_info_get_bss(sdata, peer); 5453 if (!sta) 5454 return -ENOENT; 5455 5456 return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids); 5457 } 5458 5459 static int ieee80211_set_sar_specs(struct wiphy *wiphy, 5460 struct cfg80211_sar_specs *sar) 5461 { 5462 struct ieee80211_local *local = wiphy_priv(wiphy); 5463 5464 if (!local->ops->set_sar_specs) 5465 return -EOPNOTSUPP; 5466 5467 return local->ops->set_sar_specs(&local->hw, sar); 5468 } 5469 5470 static int 5471 ieee80211_set_after_color_change_beacon(struct ieee80211_link_data *link, 5472 u64 *changed) 5473 { 5474 struct ieee80211_sub_if_data *sdata = link->sdata; 5475 5476 switch (sdata->vif.type) { 5477 case NL80211_IFTYPE_AP: { 5478 int ret; 5479 5480 if (!link->u.ap.next_beacon) 5481 return -EINVAL; 5482 5483 ret = ieee80211_assign_beacon(sdata, link, 5484 link->u.ap.next_beacon, 5485 NULL, NULL, changed); 5486 ieee80211_free_next_beacon(link); 5487 5488 if (ret < 0) 5489 return ret; 5490 5491 break; 5492 } 5493 default: 5494 WARN_ON_ONCE(1); 5495 return -EINVAL; 5496 } 5497 5498 return 0; 5499 } 5500 5501 static int 5502 ieee80211_set_color_change_beacon(struct ieee80211_link_data *link, 5503 struct cfg80211_color_change_settings *params, 5504 u64 *changed) 5505 { 5506 struct ieee80211_sub_if_data *sdata = link->sdata; 5507 struct ieee80211_color_change_settings color_change = {}; 5508 int err; 5509 5510 switch (sdata->vif.type) { 5511 case NL80211_IFTYPE_AP: 5512 link->u.ap.next_beacon = 5513 cfg80211_beacon_dup(¶ms->beacon_next); 5514 if (!link->u.ap.next_beacon) 5515 return -ENOMEM; 5516 5517 if (params->count <= 1) 5518 break; 5519 5520 color_change.counter_offset_beacon = 5521 params->counter_offset_beacon; 5522 color_change.counter_offset_presp = 5523 params->counter_offset_presp; 5524 color_change.count = params->count; 5525 5526 err = ieee80211_assign_beacon(sdata, link, 5527 ¶ms->beacon_color_change, 5528 NULL, &color_change, changed); 5529 if (err < 0) { 5530 ieee80211_free_next_beacon(link); 5531 return err; 5532 } 5533 break; 5534 default: 5535 return -EOPNOTSUPP; 5536 } 5537 5538 return 0; 5539 } 5540 5541 static void 5542 ieee80211_color_change_bss_config_notify(struct ieee80211_link_data *link, 5543 u8 color, int enable, u64 changed) 5544 { 5545 struct ieee80211_sub_if_data *sdata = link->sdata; 5546 5547 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5548 5549 link->conf->he_bss_color.color = color; 5550 link->conf->he_bss_color.enabled = enable; 5551 changed |= BSS_CHANGED_HE_BSS_COLOR; 5552 5553 ieee80211_link_info_change_notify(sdata, link, changed); 5554 5555 if (!link->conf->nontransmitted && 5556 rcu_access_pointer(link->conf->tx_bss_conf)) { 5557 struct ieee80211_link_data *tmp; 5558 5559 for_each_sdata_link(sdata->local, tmp) { 5560 if (tmp->sdata == sdata || 5561 rcu_access_pointer(tmp->conf->tx_bss_conf) != link->conf) 5562 continue; 5563 5564 tmp->conf->he_bss_color.color = color; 5565 tmp->conf->he_bss_color.enabled = enable; 5566 ieee80211_link_info_change_notify(tmp->sdata, tmp, 5567 BSS_CHANGED_HE_BSS_COLOR); 5568 } 5569 } 5570 } 5571 5572 static int ieee80211_color_change_finalize(struct ieee80211_link_data *link) 5573 { 5574 struct ieee80211_sub_if_data *sdata = link->sdata; 5575 struct ieee80211_local *local = sdata->local; 5576 u64 changed = 0; 5577 int err; 5578 5579 lockdep_assert_wiphy(local->hw.wiphy); 5580 5581 link->conf->color_change_active = false; 5582 5583 err = ieee80211_set_after_color_change_beacon(link, &changed); 5584 if (err) { 5585 cfg80211_color_change_aborted_notify(sdata->dev, link->link_id); 5586 return err; 5587 } 5588 5589 ieee80211_color_change_bss_config_notify(link, 5590 link->conf->color_change_color, 5591 1, changed); 5592 cfg80211_color_change_notify(sdata->dev, link->link_id); 5593 5594 return 0; 5595 } 5596 5597 void ieee80211_color_change_finalize_work(struct wiphy *wiphy, 5598 struct wiphy_work *work) 5599 { 5600 struct ieee80211_link_data *link = 5601 container_of(work, struct ieee80211_link_data, 5602 color_change_finalize_work); 5603 struct ieee80211_sub_if_data *sdata = link->sdata; 5604 struct ieee80211_bss_conf *link_conf = link->conf; 5605 struct ieee80211_local *local = sdata->local; 5606 5607 lockdep_assert_wiphy(local->hw.wiphy); 5608 5609 /* AP might have been stopped while waiting for the lock. */ 5610 if (!link_conf->color_change_active) 5611 return; 5612 5613 if (!ieee80211_sdata_running(sdata)) 5614 return; 5615 5616 ieee80211_color_change_finalize(link); 5617 } 5618 5619 void ieee80211_color_collision_detection_work(struct wiphy *wiphy, 5620 struct wiphy_work *work) 5621 { 5622 struct ieee80211_link_data *link = 5623 container_of(work, struct ieee80211_link_data, 5624 color_collision_detect_work.work); 5625 struct ieee80211_sub_if_data *sdata = link->sdata; 5626 5627 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap, 5628 link->link_id); 5629 } 5630 5631 void ieee80211_color_change_finish(struct ieee80211_vif *vif, u8 link_id) 5632 { 5633 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5634 struct ieee80211_link_data *link; 5635 5636 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5637 return; 5638 5639 rcu_read_lock(); 5640 5641 link = rcu_dereference(sdata->link[link_id]); 5642 if (WARN_ON(!link)) { 5643 rcu_read_unlock(); 5644 return; 5645 } 5646 5647 wiphy_work_queue(sdata->local->hw.wiphy, 5648 &link->color_change_finalize_work); 5649 5650 rcu_read_unlock(); 5651 } 5652 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish); 5653 5654 void 5655 ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif, 5656 u64 color_bitmap, u8 link_id) 5657 { 5658 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 5659 struct ieee80211_link_data *link; 5660 5661 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5662 return; 5663 5664 rcu_read_lock(); 5665 5666 link = rcu_dereference(sdata->link[link_id]); 5667 if (WARN_ON(!link)) { 5668 rcu_read_unlock(); 5669 return; 5670 } 5671 5672 if (link->conf->color_change_active || link->conf->csa_active) { 5673 rcu_read_unlock(); 5674 return; 5675 } 5676 5677 if (wiphy_delayed_work_pending(sdata->local->hw.wiphy, 5678 &link->color_collision_detect_work)) { 5679 rcu_read_unlock(); 5680 return; 5681 } 5682 5683 link->color_bitmap = color_bitmap; 5684 /* queue the color collision detection event every 500 ms in order to 5685 * avoid sending too much netlink messages to userspace. 5686 */ 5687 wiphy_delayed_work_queue(sdata->local->hw.wiphy, 5688 &link->color_collision_detect_work, 5689 msecs_to_jiffies(500)); 5690 5691 rcu_read_unlock(); 5692 } 5693 EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify); 5694 5695 static int 5696 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, 5697 struct cfg80211_color_change_settings *params) 5698 { 5699 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5700 struct ieee80211_local *local = sdata->local; 5701 struct ieee80211_bss_conf *link_conf; 5702 struct ieee80211_link_data *link; 5703 u8 link_id = params->link_id; 5704 u64 changed = 0; 5705 int err; 5706 5707 lockdep_assert_wiphy(local->hw.wiphy); 5708 5709 if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) 5710 return -EINVAL; 5711 5712 link = wiphy_dereference(wiphy, sdata->link[link_id]); 5713 if (!link) 5714 return -ENOLINK; 5715 5716 link_conf = link->conf; 5717 5718 if (link_conf->nontransmitted) 5719 return -EINVAL; 5720 5721 /* don't allow another color change if one is already active or if csa 5722 * is active 5723 */ 5724 if (link_conf->color_change_active || link_conf->csa_active) { 5725 err = -EBUSY; 5726 goto out; 5727 } 5728 5729 err = ieee80211_set_unsol_bcast_probe_resp(sdata, 5730 ¶ms->unsol_bcast_probe_resp, 5731 link, link_conf, &changed); 5732 if (err) 5733 goto out; 5734 5735 err = ieee80211_set_color_change_beacon(link, params, &changed); 5736 if (err) 5737 goto out; 5738 5739 link_conf->color_change_active = true; 5740 link_conf->color_change_color = params->color; 5741 5742 cfg80211_color_change_started_notify(sdata->dev, params->count, link_id); 5743 5744 if (changed) 5745 ieee80211_color_change_bss_config_notify(link, 0, 0, changed); 5746 else 5747 /* if the beacon didn't change, we can finalize immediately */ 5748 ieee80211_color_change_finalize(link); 5749 5750 out: 5751 5752 return err; 5753 } 5754 5755 static int 5756 ieee80211_set_radar_background(struct wiphy *wiphy, 5757 struct cfg80211_chan_def *chandef) 5758 { 5759 struct ieee80211_local *local = wiphy_priv(wiphy); 5760 5761 if (!local->ops->set_radar_background) 5762 return -EOPNOTSUPP; 5763 5764 return local->ops->set_radar_background(&local->hw, chandef); 5765 } 5766 5767 static int ieee80211_add_intf_link(struct wiphy *wiphy, 5768 struct wireless_dev *wdev, 5769 unsigned int link_id) 5770 { 5771 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5772 5773 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5774 5775 return ieee80211_vif_set_links(sdata, wdev->valid_links, 0); 5776 } 5777 5778 static void ieee80211_del_intf_link(struct wiphy *wiphy, 5779 struct wireless_dev *wdev, 5780 unsigned int link_id) 5781 { 5782 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5783 u16 new_links = wdev->valid_links & ~BIT(link_id); 5784 5785 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5786 5787 /* During the link teardown process, certain functions require the 5788 * link_id to remain in the valid_links bitmap. Therefore, instead 5789 * of removing the link_id from the bitmap, pass a masked value to 5790 * simulate as if link_id does not exist anymore. 5791 */ 5792 ieee80211_vif_set_links(sdata, new_links, 0); 5793 } 5794 5795 static int 5796 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev, 5797 struct link_station_parameters *params) 5798 { 5799 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5800 struct ieee80211_local *local = wiphy_priv(wiphy); 5801 struct sta_info *sta; 5802 int ret; 5803 5804 lockdep_assert_wiphy(local->hw.wiphy); 5805 5806 sta = sta_info_get_bss(sdata, params->mld_mac); 5807 if (!sta) 5808 return -ENOENT; 5809 5810 if (!sta->sta.valid_links) 5811 return -EINVAL; 5812 5813 if (sta->sta.valid_links & BIT(params->link_id)) 5814 return -EALREADY; 5815 5816 ret = ieee80211_sta_allocate_link(sta, params->link_id); 5817 if (ret) 5818 return ret; 5819 5820 ret = sta_link_apply_parameters(local, sta, STA_LINK_MODE_NEW, params); 5821 if (ret) { 5822 ieee80211_sta_free_link(sta, params->link_id); 5823 return ret; 5824 } 5825 5826 if (test_sta_flag(sta, WLAN_STA_ASSOC)) { 5827 struct link_sta_info *link_sta; 5828 5829 link_sta = sdata_dereference(sta->link[params->link_id], sdata); 5830 rate_control_rate_init(link_sta); 5831 } 5832 5833 /* ieee80211_sta_activate_link frees the link upon failure */ 5834 return ieee80211_sta_activate_link(sta, params->link_id); 5835 } 5836 5837 static int 5838 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev, 5839 struct link_station_parameters *params) 5840 { 5841 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5842 struct ieee80211_local *local = wiphy_priv(wiphy); 5843 struct sta_info *sta; 5844 5845 lockdep_assert_wiphy(local->hw.wiphy); 5846 5847 sta = sta_info_get_bss(sdata, params->mld_mac); 5848 if (!sta) 5849 return -ENOENT; 5850 5851 if (!(sta->sta.valid_links & BIT(params->link_id))) 5852 return -EINVAL; 5853 5854 return sta_link_apply_parameters(local, sta, STA_LINK_MODE_LINK_MODIFY, 5855 params); 5856 } 5857 5858 static int 5859 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev, 5860 struct link_station_del_parameters *params) 5861 { 5862 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5863 struct sta_info *sta; 5864 5865 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5866 5867 sta = sta_info_get_bss(sdata, params->mld_mac); 5868 if (!sta) 5869 return -ENOENT; 5870 5871 if (!(sta->sta.valid_links & BIT(params->link_id))) 5872 return -EINVAL; 5873 5874 /* must not create a STA without links */ 5875 if (sta->sta.valid_links == BIT(params->link_id)) 5876 return -EINVAL; 5877 5878 ieee80211_sta_remove_link(sta, params->link_id); 5879 5880 return 0; 5881 } 5882 5883 static int ieee80211_set_hw_timestamp(struct wiphy *wiphy, 5884 struct net_device *dev, 5885 struct cfg80211_set_hw_timestamp *hwts) 5886 { 5887 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5888 struct ieee80211_local *local = sdata->local; 5889 5890 if (!local->ops->set_hw_timestamp) 5891 return -EOPNOTSUPP; 5892 5893 if (!check_sdata_in_driver(sdata)) 5894 return -EIO; 5895 5896 return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts); 5897 } 5898 5899 static int 5900 ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev, 5901 struct cfg80211_ttlm_params *params) 5902 { 5903 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5904 5905 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5906 5907 return ieee80211_req_neg_ttlm(sdata, params); 5908 } 5909 5910 static int 5911 ieee80211_assoc_ml_reconf(struct wiphy *wiphy, struct net_device *dev, 5912 struct cfg80211_ml_reconf_req *req) 5913 { 5914 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5915 5916 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5917 5918 return ieee80211_mgd_assoc_ml_reconf(sdata, req); 5919 } 5920 5921 static int 5922 ieee80211_set_epcs(struct wiphy *wiphy, struct net_device *dev, bool enable) 5923 { 5924 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 5925 5926 return ieee80211_mgd_set_epcs(sdata, enable); 5927 } 5928 5929 static int 5930 ieee80211_set_local_nan_sched(struct wiphy *wiphy, 5931 struct wireless_dev *wdev, 5932 struct cfg80211_nan_local_sched *sched) 5933 { 5934 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5935 5936 lockdep_assert_wiphy(wiphy); 5937 5938 return ieee80211_nan_set_local_sched(sdata, sched); 5939 } 5940 5941 static int 5942 ieee80211_set_peer_nan_sched(struct wiphy *wiphy, 5943 struct wireless_dev *wdev, 5944 struct cfg80211_nan_peer_sched *sched) 5945 { 5946 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 5947 5948 lockdep_assert_wiphy(sdata->local->hw.wiphy); 5949 5950 return ieee80211_nan_set_peer_sched(sdata, sched); 5951 } 5952 5953 const struct cfg80211_ops mac80211_config_ops = { 5954 .add_virtual_intf = ieee80211_add_iface, 5955 .del_virtual_intf = ieee80211_del_iface, 5956 .change_virtual_intf = ieee80211_change_iface, 5957 .start_p2p_device = ieee80211_start_p2p_device, 5958 .stop_p2p_device = ieee80211_stop_p2p_device, 5959 .add_key = ieee80211_add_key, 5960 .del_key = ieee80211_del_key, 5961 .get_key = ieee80211_get_key, 5962 .set_default_key = ieee80211_config_default_key, 5963 .set_default_mgmt_key = ieee80211_config_default_mgmt_key, 5964 .set_default_beacon_key = ieee80211_config_default_beacon_key, 5965 .start_ap = ieee80211_start_ap, 5966 .change_beacon = ieee80211_change_beacon, 5967 .stop_ap = ieee80211_stop_ap, 5968 .add_station = ieee80211_add_station, 5969 .del_station = ieee80211_del_station, 5970 .change_station = ieee80211_change_station, 5971 .get_station = ieee80211_get_station, 5972 .dump_station = ieee80211_dump_station, 5973 .dump_survey = ieee80211_dump_survey, 5974 #ifdef CONFIG_MAC80211_MESH 5975 .add_mpath = ieee80211_add_mpath, 5976 .del_mpath = ieee80211_del_mpath, 5977 .change_mpath = ieee80211_change_mpath, 5978 .get_mpath = ieee80211_get_mpath, 5979 .dump_mpath = ieee80211_dump_mpath, 5980 .get_mpp = ieee80211_get_mpp, 5981 .dump_mpp = ieee80211_dump_mpp, 5982 .update_mesh_config = ieee80211_update_mesh_config, 5983 .get_mesh_config = ieee80211_get_mesh_config, 5984 .join_mesh = ieee80211_join_mesh, 5985 .leave_mesh = ieee80211_leave_mesh, 5986 #endif 5987 .join_ocb = ieee80211_join_ocb, 5988 .leave_ocb = ieee80211_leave_ocb, 5989 .change_bss = ieee80211_change_bss, 5990 .inform_bss = ieee80211_inform_bss, 5991 .set_txq_params = ieee80211_set_txq_params, 5992 .set_monitor_channel = ieee80211_set_monitor_channel, 5993 .suspend = ieee80211_suspend, 5994 .resume = ieee80211_resume, 5995 .scan = ieee80211_scan, 5996 .abort_scan = ieee80211_abort_scan, 5997 .sched_scan_start = ieee80211_sched_scan_start, 5998 .sched_scan_stop = ieee80211_sched_scan_stop, 5999 .auth = ieee80211_auth, 6000 .assoc = ieee80211_assoc, 6001 .deauth = ieee80211_deauth, 6002 .disassoc = ieee80211_disassoc, 6003 .join_ibss = ieee80211_join_ibss, 6004 .leave_ibss = ieee80211_leave_ibss, 6005 .set_mcast_rate = ieee80211_set_mcast_rate, 6006 .set_wiphy_params = ieee80211_set_wiphy_params, 6007 .set_tx_power = ieee80211_set_tx_power, 6008 .get_tx_power = ieee80211_get_tx_power, 6009 .rfkill_poll = ieee80211_rfkill_poll, 6010 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) 6011 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) 6012 .set_power_mgmt = ieee80211_set_power_mgmt, 6013 .set_bitrate_mask = ieee80211_set_bitrate_mask, 6014 .remain_on_channel = ieee80211_remain_on_channel, 6015 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, 6016 .mgmt_tx = ieee80211_mgmt_tx, 6017 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, 6018 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, 6019 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, 6020 .update_mgmt_frame_registrations = 6021 ieee80211_update_mgmt_frame_registrations, 6022 .set_antenna = ieee80211_set_antenna, 6023 .get_antenna = ieee80211_get_antenna, 6024 .set_rekey_data = ieee80211_set_rekey_data, 6025 .tdls_oper = ieee80211_tdls_oper, 6026 .tdls_mgmt = ieee80211_tdls_mgmt, 6027 .tdls_channel_switch = ieee80211_tdls_channel_switch, 6028 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, 6029 .probe_client = ieee80211_probe_client, 6030 .set_noack_map = ieee80211_set_noack_map, 6031 #ifdef CONFIG_PM 6032 .set_wakeup = ieee80211_set_wakeup, 6033 #endif 6034 .get_channel = ieee80211_cfg_get_channel, 6035 .start_radar_detection = ieee80211_start_radar_detection, 6036 .end_cac = ieee80211_end_cac, 6037 .channel_switch = ieee80211_channel_switch, 6038 .set_qos_map = ieee80211_set_qos_map, 6039 .set_ap_chanwidth = ieee80211_set_ap_chanwidth, 6040 .add_tx_ts = ieee80211_add_tx_ts, 6041 .del_tx_ts = ieee80211_del_tx_ts, 6042 .start_nan = ieee80211_start_nan, 6043 .stop_nan = ieee80211_stop_nan, 6044 .nan_change_conf = ieee80211_nan_change_conf, 6045 .add_nan_func = ieee80211_add_nan_func, 6046 .del_nan_func = ieee80211_del_nan_func, 6047 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, 6048 .tx_control_port = ieee80211_tx_control_port, 6049 .get_txq_stats = ieee80211_get_txq_stats, 6050 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, 6051 .start_pmsr = ieee80211_start_pmsr, 6052 .abort_pmsr = ieee80211_abort_pmsr, 6053 .probe_mesh_link = ieee80211_probe_mesh_link, 6054 .set_tid_config = ieee80211_set_tid_config, 6055 .reset_tid_config = ieee80211_reset_tid_config, 6056 .set_sar_specs = ieee80211_set_sar_specs, 6057 .color_change = ieee80211_color_change, 6058 .set_radar_background = ieee80211_set_radar_background, 6059 .add_intf_link = ieee80211_add_intf_link, 6060 .del_intf_link = ieee80211_del_intf_link, 6061 .add_link_station = ieee80211_add_link_station, 6062 .mod_link_station = ieee80211_mod_link_station, 6063 .del_link_station = ieee80211_del_link_station, 6064 .set_hw_timestamp = ieee80211_set_hw_timestamp, 6065 .set_ttlm = ieee80211_set_ttlm, 6066 .get_radio_mask = ieee80211_get_radio_mask, 6067 .assoc_ml_reconf = ieee80211_assoc_ml_reconf, 6068 .set_epcs = ieee80211_set_epcs, 6069 .nan_set_local_sched = ieee80211_set_local_nan_sched, 6070 .nan_set_peer_sched = ieee80211_set_peer_nan_sched, 6071 }; 6072