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