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