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