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