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