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