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