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