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