1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211 configuration hooks for cfg80211
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2022 Intel Corporation
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"
26 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
27 struct vif_params *params)
29 bool mu_mimo_groups = false;
30 bool mu_mimo_follow = false;
32 if (params->vht_mumimo_groups) {
35 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
37 memcpy(sdata->vif.bss_conf.mu_group.membership,
38 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
39 memcpy(sdata->vif.bss_conf.mu_group.position,
40 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
41 WLAN_USER_POSITION_LEN);
42 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
43 BSS_CHANGED_MU_GROUPS);
44 /* don't care about endianness - just check for 0 */
45 memcpy(&membership, params->vht_mumimo_groups,
47 mu_mimo_groups = membership != 0;
50 if (params->vht_mumimo_follow_addr) {
52 is_valid_ether_addr(params->vht_mumimo_follow_addr);
53 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
54 params->vht_mumimo_follow_addr);
57 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
60 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
61 struct vif_params *params)
63 struct ieee80211_local *local = sdata->local;
64 struct ieee80211_sub_if_data *monitor_sdata;
66 /* check flags first */
67 if (params->flags && ieee80211_sdata_running(sdata)) {
68 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
71 * Prohibit MONITOR_FLAG_COOK_FRAMES and
72 * MONITOR_FLAG_ACTIVE to be changed while the
74 * Else we would need to add a lot of cruft
75 * to update everything:
76 * cooked_mntrs, monitor and all fif_* counters
77 * reconfigure hardware
79 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
83 /* also validate MU-MIMO change */
84 monitor_sdata = wiphy_dereference(local->hw.wiphy,
85 local->monitor_sdata);
88 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
91 /* apply all changes now - no failures allowed */
94 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
97 if (ieee80211_sdata_running(sdata)) {
98 ieee80211_adjust_monitor_flags(sdata, -1);
99 sdata->u.mntr.flags = params->flags;
100 ieee80211_adjust_monitor_flags(sdata, 1);
102 ieee80211_configure_filter(local);
105 * Because the interface is down, ieee80211_do_stop
106 * and ieee80211_do_open take care of "everything"
107 * mentioned in the comment above.
109 sdata->u.mntr.flags = params->flags;
116 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
117 struct cfg80211_mbssid_config params,
118 struct ieee80211_bss_conf *link_conf)
120 struct ieee80211_sub_if_data *tx_sdata;
122 sdata->vif.mbssid_tx_vif = NULL;
123 link_conf->bssid_index = 0;
124 link_conf->nontransmitted = false;
125 link_conf->ema_ap = false;
127 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
130 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
134 if (tx_sdata == sdata) {
135 sdata->vif.mbssid_tx_vif = &sdata->vif;
137 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
138 link_conf->nontransmitted = true;
139 link_conf->bssid_index = params.index;
142 link_conf->ema_ap = true;
147 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
149 unsigned char name_assign_type,
150 enum nl80211_iftype type,
151 struct vif_params *params)
153 struct ieee80211_local *local = wiphy_priv(wiphy);
154 struct wireless_dev *wdev;
155 struct ieee80211_sub_if_data *sdata;
158 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
162 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
164 if (type == NL80211_IFTYPE_MONITOR) {
165 err = ieee80211_set_mon_options(sdata, params);
167 ieee80211_if_remove(sdata);
175 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
177 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
182 static int ieee80211_change_iface(struct wiphy *wiphy,
183 struct net_device *dev,
184 enum nl80211_iftype type,
185 struct vif_params *params)
187 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
188 struct ieee80211_local *local = sdata->local;
189 struct sta_info *sta;
192 ret = ieee80211_if_change_type(sdata, type);
196 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
197 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
198 ieee80211_check_fast_rx_iface(sdata);
199 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
200 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
202 if (params->use_4addr == ifmgd->use_4addr)
205 sdata->u.mgd.use_4addr = params->use_4addr;
206 if (!ifmgd->associated)
209 mutex_lock(&local->sta_mtx);
210 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
212 drv_sta_set_4addr(local, sdata, &sta->sta,
214 mutex_unlock(&local->sta_mtx);
216 if (params->use_4addr)
217 ieee80211_send_4addr_nullfunc(local, sdata);
220 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
221 ret = ieee80211_set_mon_options(sdata, params);
229 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
230 struct wireless_dev *wdev)
232 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
235 mutex_lock(&sdata->local->chanctx_mtx);
236 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
237 mutex_unlock(&sdata->local->chanctx_mtx);
241 return ieee80211_do_open(wdev, true);
244 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
245 struct wireless_dev *wdev)
247 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
250 static int ieee80211_start_nan(struct wiphy *wiphy,
251 struct wireless_dev *wdev,
252 struct cfg80211_nan_conf *conf)
254 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
257 mutex_lock(&sdata->local->chanctx_mtx);
258 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
259 mutex_unlock(&sdata->local->chanctx_mtx);
263 ret = ieee80211_do_open(wdev, true);
267 ret = drv_start_nan(sdata->local, sdata, conf);
269 ieee80211_sdata_stop(sdata);
271 sdata->u.nan.conf = *conf;
276 static void ieee80211_stop_nan(struct wiphy *wiphy,
277 struct wireless_dev *wdev)
279 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
281 drv_stop_nan(sdata->local, sdata);
282 ieee80211_sdata_stop(sdata);
285 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
286 struct wireless_dev *wdev,
287 struct cfg80211_nan_conf *conf,
290 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
291 struct cfg80211_nan_conf new_conf;
294 if (sdata->vif.type != NL80211_IFTYPE_NAN)
297 if (!ieee80211_sdata_running(sdata))
300 new_conf = sdata->u.nan.conf;
302 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
303 new_conf.master_pref = conf->master_pref;
305 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
306 new_conf.bands = conf->bands;
308 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
310 sdata->u.nan.conf = new_conf;
315 static int ieee80211_add_nan_func(struct wiphy *wiphy,
316 struct wireless_dev *wdev,
317 struct cfg80211_nan_func *nan_func)
319 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
322 if (sdata->vif.type != NL80211_IFTYPE_NAN)
325 if (!ieee80211_sdata_running(sdata))
328 spin_lock_bh(&sdata->u.nan.func_lock);
330 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
331 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
333 spin_unlock_bh(&sdata->u.nan.func_lock);
338 nan_func->instance_id = ret;
340 WARN_ON(nan_func->instance_id == 0);
342 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
344 spin_lock_bh(&sdata->u.nan.func_lock);
345 idr_remove(&sdata->u.nan.function_inst_ids,
346 nan_func->instance_id);
347 spin_unlock_bh(&sdata->u.nan.func_lock);
353 static struct cfg80211_nan_func *
354 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
357 struct cfg80211_nan_func *func;
360 lockdep_assert_held(&sdata->u.nan.func_lock);
362 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
363 if (func->cookie == cookie)
370 static void ieee80211_del_nan_func(struct wiphy *wiphy,
371 struct wireless_dev *wdev, u64 cookie)
373 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
374 struct cfg80211_nan_func *func;
377 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
378 !ieee80211_sdata_running(sdata))
381 spin_lock_bh(&sdata->u.nan.func_lock);
383 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
385 instance_id = func->instance_id;
387 spin_unlock_bh(&sdata->u.nan.func_lock);
390 drv_del_nan_func(sdata->local, sdata, instance_id);
393 static int ieee80211_set_noack_map(struct wiphy *wiphy,
394 struct net_device *dev,
397 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
399 sdata->noack_map = noack_map;
401 ieee80211_check_fast_xmit_iface(sdata);
406 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
407 const u8 *mac_addr, u8 key_idx)
409 struct ieee80211_local *local = sdata->local;
410 struct ieee80211_key *key;
411 struct sta_info *sta;
414 if (!wiphy_ext_feature_isset(local->hw.wiphy,
415 NL80211_EXT_FEATURE_EXT_KEY_ID))
418 sta = sta_info_get_bss(sdata, mac_addr);
423 if (sta->ptk_idx == key_idx)
426 mutex_lock(&local->key_mtx);
427 key = key_mtx_dereference(local, sta->ptk[key_idx]);
429 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
430 ret = ieee80211_set_tx_key(key);
432 mutex_unlock(&local->key_mtx);
436 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
437 u8 key_idx, bool pairwise, const u8 *mac_addr,
438 struct key_params *params)
440 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
441 struct ieee80211_local *local = sdata->local;
442 struct sta_info *sta = NULL;
443 struct ieee80211_key *key;
446 if (!ieee80211_sdata_running(sdata))
449 if (pairwise && params->mode == NL80211_KEY_SET_TX)
450 return ieee80211_set_tx(sdata, mac_addr, key_idx);
452 /* reject WEP and TKIP keys if WEP failed to initialize */
453 switch (params->cipher) {
454 case WLAN_CIPHER_SUITE_WEP40:
455 case WLAN_CIPHER_SUITE_TKIP:
456 case WLAN_CIPHER_SUITE_WEP104:
457 if (WARN_ON_ONCE(fips_enabled))
464 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
465 params->key, params->seq_len, params->seq);
470 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
472 if (params->mode == NL80211_KEY_NO_TX)
473 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
475 mutex_lock(&local->sta_mtx);
478 sta = sta_info_get_bss(sdata, mac_addr);
480 * The ASSOC test makes sure the driver is ready to
481 * receive the key. When wpa_supplicant has roamed
482 * using FT, it attempts to set the key before
483 * association has completed, this rejects that attempt
484 * so it will set the key again after association.
486 * TODO: accept the key if we have a station entry and
487 * add it to the device after the station.
489 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
490 ieee80211_key_free_unused(key);
496 switch (sdata->vif.type) {
497 case NL80211_IFTYPE_STATION:
498 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
499 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
501 case NL80211_IFTYPE_AP:
502 case NL80211_IFTYPE_AP_VLAN:
503 /* Keys without a station are used for TX only */
504 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
505 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
507 case NL80211_IFTYPE_ADHOC:
510 case NL80211_IFTYPE_MESH_POINT:
511 #ifdef CONFIG_MAC80211_MESH
512 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
513 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
516 case NL80211_IFTYPE_WDS:
517 case NL80211_IFTYPE_MONITOR:
518 case NL80211_IFTYPE_P2P_DEVICE:
519 case NL80211_IFTYPE_NAN:
520 case NL80211_IFTYPE_UNSPECIFIED:
521 case NUM_NL80211_IFTYPES:
522 case NL80211_IFTYPE_P2P_CLIENT:
523 case NL80211_IFTYPE_P2P_GO:
524 case NL80211_IFTYPE_OCB:
525 /* shouldn't happen */
530 err = ieee80211_key_link(key, sdata, sta);
533 mutex_unlock(&local->sta_mtx);
538 static struct ieee80211_key *
539 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata,
540 u8 key_idx, bool pairwise, const u8 *mac_addr)
542 struct ieee80211_local *local = sdata->local;
543 struct ieee80211_key *key;
544 struct sta_info *sta;
547 sta = sta_info_get_bss(sdata, mac_addr);
551 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
552 return rcu_dereference_check_key_mtx(local,
556 key_idx < NUM_DEFAULT_KEYS +
557 NUM_DEFAULT_MGMT_KEYS +
558 NUM_DEFAULT_BEACON_KEYS)
559 return rcu_dereference_check_key_mtx(local,
560 sta->deflink.gtk[key_idx]);
565 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
566 return rcu_dereference_check_key_mtx(local,
567 sdata->keys[key_idx]);
569 key = rcu_dereference_check_key_mtx(local, sdata->deflink.gtk[key_idx]);
573 /* or maybe it was a WEP key */
574 if (key_idx < NUM_DEFAULT_KEYS)
575 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]);
580 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
581 u8 key_idx, bool pairwise, const u8 *mac_addr)
583 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
584 struct ieee80211_local *local = sdata->local;
585 struct ieee80211_key *key;
588 mutex_lock(&local->sta_mtx);
589 mutex_lock(&local->key_mtx);
591 key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
597 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
601 mutex_unlock(&local->key_mtx);
602 mutex_unlock(&local->sta_mtx);
607 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
608 u8 key_idx, bool pairwise, const u8 *mac_addr,
610 void (*callback)(void *cookie,
611 struct key_params *params))
613 struct ieee80211_sub_if_data *sdata;
615 struct key_params params;
616 struct ieee80211_key *key;
621 struct ieee80211_key_seq kseq = {};
623 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
627 key = ieee80211_lookup_key(sdata, key_idx, pairwise, mac_addr);
631 memset(¶ms, 0, sizeof(params));
633 params.cipher = key->conf.cipher;
635 switch (key->conf.cipher) {
636 case WLAN_CIPHER_SUITE_TKIP:
637 pn64 = atomic64_read(&key->conf.tx_pn);
638 iv32 = TKIP_PN_TO_IV32(pn64);
639 iv16 = TKIP_PN_TO_IV16(pn64);
641 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
642 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
643 drv_get_key_seq(sdata->local, key, &kseq);
644 iv32 = kseq.tkip.iv32;
645 iv16 = kseq.tkip.iv16;
648 seq[0] = iv16 & 0xff;
649 seq[1] = (iv16 >> 8) & 0xff;
650 seq[2] = iv32 & 0xff;
651 seq[3] = (iv32 >> 8) & 0xff;
652 seq[4] = (iv32 >> 16) & 0xff;
653 seq[5] = (iv32 >> 24) & 0xff;
657 case WLAN_CIPHER_SUITE_CCMP:
658 case WLAN_CIPHER_SUITE_CCMP_256:
659 case WLAN_CIPHER_SUITE_AES_CMAC:
660 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
661 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
662 offsetof(typeof(kseq), aes_cmac));
664 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
665 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
666 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
667 offsetof(typeof(kseq), aes_gmac));
669 case WLAN_CIPHER_SUITE_GCMP:
670 case WLAN_CIPHER_SUITE_GCMP_256:
671 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
672 offsetof(typeof(kseq), gcmp));
674 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
675 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
676 drv_get_key_seq(sdata->local, key, &kseq);
677 memcpy(seq, kseq.ccmp.pn, 6);
679 pn64 = atomic64_read(&key->conf.tx_pn);
691 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
693 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
695 drv_get_key_seq(sdata->local, key, &kseq);
696 params.seq = kseq.hw.seq;
697 params.seq_len = kseq.hw.seq_len;
701 params.key = key->conf.key;
702 params.key_len = key->conf.keylen;
704 callback(cookie, ¶ms);
712 static int ieee80211_config_default_key(struct wiphy *wiphy,
713 struct net_device *dev,
714 u8 key_idx, bool uni,
717 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
719 ieee80211_set_default_key(sdata, key_idx, uni, multi);
724 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
725 struct net_device *dev,
728 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
730 ieee80211_set_default_mgmt_key(sdata, key_idx);
735 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
736 struct net_device *dev,
739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 ieee80211_set_default_beacon_key(sdata, key_idx);
746 void sta_set_rate_info_tx(struct sta_info *sta,
747 const struct ieee80211_tx_rate *rate,
748 struct rate_info *rinfo)
751 if (rate->flags & IEEE80211_TX_RC_MCS) {
752 rinfo->flags |= RATE_INFO_FLAGS_MCS;
753 rinfo->mcs = rate->idx;
754 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
755 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
756 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
757 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
759 struct ieee80211_supported_band *sband;
760 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
763 sband = ieee80211_get_sband(sta->sdata);
764 WARN_ON_ONCE(sband && !sband->bitrates);
765 if (sband && sband->bitrates) {
766 brate = sband->bitrates[rate->idx].bitrate;
767 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
770 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
771 rinfo->bw = RATE_INFO_BW_40;
772 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
773 rinfo->bw = RATE_INFO_BW_80;
774 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
775 rinfo->bw = RATE_INFO_BW_160;
777 rinfo->bw = RATE_INFO_BW_20;
778 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
779 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
782 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
783 int idx, u8 *mac, struct station_info *sinfo)
785 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
786 struct ieee80211_local *local = sdata->local;
787 struct sta_info *sta;
790 mutex_lock(&local->sta_mtx);
792 sta = sta_info_get_by_idx(sdata, idx);
795 memcpy(mac, sta->sta.addr, ETH_ALEN);
796 sta_set_sinfo(sta, sinfo, true);
799 mutex_unlock(&local->sta_mtx);
804 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
805 int idx, struct survey_info *survey)
807 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
809 return drv_get_survey(local, idx, survey);
812 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
813 const u8 *mac, struct station_info *sinfo)
815 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
816 struct ieee80211_local *local = sdata->local;
817 struct sta_info *sta;
820 mutex_lock(&local->sta_mtx);
822 sta = sta_info_get_bss(sdata, mac);
825 sta_set_sinfo(sta, sinfo, true);
828 mutex_unlock(&local->sta_mtx);
833 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
834 struct cfg80211_chan_def *chandef)
836 struct ieee80211_local *local = wiphy_priv(wiphy);
837 struct ieee80211_sub_if_data *sdata;
840 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
843 mutex_lock(&local->mtx);
844 if (local->use_chanctx) {
845 sdata = wiphy_dereference(local->hw.wiphy,
846 local->monitor_sdata);
848 ieee80211_link_release_channel(&sdata->deflink);
849 ret = ieee80211_link_use_channel(&sdata->deflink,
851 IEEE80211_CHANCTX_EXCLUSIVE);
853 } else if (local->open_count == local->monitors) {
854 local->_oper_chandef = *chandef;
855 ieee80211_hw_config(local, 0);
859 local->monitor_chandef = *chandef;
860 mutex_unlock(&local->mtx);
866 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
867 const u8 *resp, size_t resp_len,
868 const struct ieee80211_csa_settings *csa,
869 const struct ieee80211_color_change_settings *cca,
870 struct ieee80211_link_data *link)
872 struct probe_resp *new, *old;
874 if (!resp || !resp_len)
877 old = sdata_dereference(link->u.ap.probe_resp, sdata);
879 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
884 memcpy(new->data, resp, resp_len);
887 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
888 csa->n_counter_offsets_presp *
889 sizeof(new->cntdwn_counter_offsets[0]));
891 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
893 rcu_assign_pointer(link->u.ap.probe_resp, new);
895 kfree_rcu(old, rcu_head);
900 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
901 struct cfg80211_fils_discovery *params,
902 struct ieee80211_link_data *link,
903 struct ieee80211_bss_conf *link_conf)
905 struct fils_discovery_data *new, *old = NULL;
906 struct ieee80211_fils_discovery *fd;
908 if (!params->tmpl || !params->tmpl_len)
911 fd = &link_conf->fils_discovery;
912 fd->min_interval = params->min_interval;
913 fd->max_interval = params->max_interval;
915 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
916 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
919 new->len = params->tmpl_len;
920 memcpy(new->data, params->tmpl, params->tmpl_len);
921 rcu_assign_pointer(link->u.ap.fils_discovery, new);
924 kfree_rcu(old, rcu_head);
930 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
931 struct cfg80211_unsol_bcast_probe_resp *params,
932 struct ieee80211_link_data *link,
933 struct ieee80211_bss_conf *link_conf)
935 struct unsol_bcast_probe_resp_data *new, *old = NULL;
937 if (!params->tmpl || !params->tmpl_len)
940 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
941 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
944 new->len = params->tmpl_len;
945 memcpy(new->data, params->tmpl, params->tmpl_len);
946 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
949 kfree_rcu(old, rcu_head);
951 link_conf->unsol_bcast_probe_resp_interval = params->interval;
956 static int ieee80211_set_ftm_responder_params(
957 struct ieee80211_sub_if_data *sdata,
958 const u8 *lci, size_t lci_len,
959 const u8 *civicloc, size_t civicloc_len,
960 struct ieee80211_bss_conf *link_conf)
962 struct ieee80211_ftm_responder_params *new, *old;
966 if (!lci_len && !civicloc_len)
969 old = link_conf->ftmr_params;
970 len = lci_len + civicloc_len;
972 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
976 pos = (u8 *)(new + 1);
978 new->lci_len = lci_len;
980 memcpy(pos, lci, lci_len);
985 new->civicloc_len = civicloc_len;
987 memcpy(pos, civicloc, civicloc_len);
991 link_conf->ftmr_params = new;
998 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
999 struct cfg80211_mbssid_elems *src)
1003 for (i = 0; i < src->cnt; i++) {
1004 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1005 dst->elem[i].len = src->elem[i].len;
1006 dst->elem[i].data = pos + offset;
1007 offset += dst->elem[i].len;
1009 dst->cnt = src->cnt;
1014 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1015 struct ieee80211_link_data *link,
1016 struct cfg80211_beacon_data *params,
1017 const struct ieee80211_csa_settings *csa,
1018 const struct ieee80211_color_change_settings *cca)
1020 struct cfg80211_mbssid_elems *mbssid = NULL;
1021 struct beacon_data *new, *old;
1022 int new_head_len, new_tail_len;
1024 u32 changed = BSS_CHANGED_BEACON;
1025 struct ieee80211_bss_conf *link_conf = link->conf;
1027 old = sdata_dereference(link->u.ap.beacon, sdata);
1029 /* Need to have a beacon head if we don't have one yet */
1030 if (!params->head && !old)
1033 /* new or old head? */
1035 new_head_len = params->head_len;
1037 new_head_len = old->head_len;
1039 /* new or old tail? */
1040 if (params->tail || !old)
1041 /* params->tail_len will be zero for !params->tail */
1042 new_tail_len = params->tail_len;
1044 new_tail_len = old->tail_len;
1046 size = sizeof(*new) + new_head_len + new_tail_len;
1048 /* new or old multiple BSSID elements? */
1049 if (params->mbssid_ies) {
1050 mbssid = params->mbssid_ies;
1051 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1052 size += ieee80211_get_mbssid_beacon_len(mbssid);
1053 } else if (old && old->mbssid_ies) {
1054 mbssid = old->mbssid_ies;
1055 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1056 size += ieee80211_get_mbssid_beacon_len(mbssid);
1059 new = kzalloc(size, GFP_KERNEL);
1063 /* start filling the new info now */
1066 * pointers go into the block we allocated,
1067 * memory is | beacon_data | head | tail | mbssid_ies
1069 new->head = ((u8 *) new) + sizeof(*new);
1070 new->tail = new->head + new_head_len;
1071 new->head_len = new_head_len;
1072 new->tail_len = new_tail_len;
1073 /* copy in optional mbssid_ies */
1075 u8 *pos = new->tail + new->tail_len;
1077 new->mbssid_ies = (void *)pos;
1078 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1079 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1080 /* update bssid_indicator */
1081 link_conf->bssid_indicator =
1082 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1086 new->cntdwn_current_counter = csa->count;
1087 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1088 csa->n_counter_offsets_beacon *
1089 sizeof(new->cntdwn_counter_offsets[0]));
1091 new->cntdwn_current_counter = cca->count;
1092 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1097 memcpy(new->head, params->head, new_head_len);
1099 memcpy(new->head, old->head, new_head_len);
1101 /* copy in optional tail */
1103 memcpy(new->tail, params->tail, new_tail_len);
1106 memcpy(new->tail, old->tail, new_tail_len);
1108 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1109 params->probe_resp_len, csa, cca, link);
1115 changed |= BSS_CHANGED_AP_PROBE_RESP;
1117 if (params->ftm_responder != -1) {
1118 link_conf->ftm_responder = params->ftm_responder;
1119 err = ieee80211_set_ftm_responder_params(sdata,
1123 params->civicloc_len,
1131 changed |= BSS_CHANGED_FTM_RESPONDER;
1134 rcu_assign_pointer(link->u.ap.beacon, new);
1135 sdata->u.ap.active = true;
1138 kfree_rcu(old, rcu_head);
1143 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1144 struct cfg80211_ap_settings *params)
1146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1147 struct ieee80211_local *local = sdata->local;
1148 struct beacon_data *old;
1149 struct ieee80211_sub_if_data *vlan;
1150 u32 changed = BSS_CHANGED_BEACON_INT |
1151 BSS_CHANGED_BEACON_ENABLED |
1152 BSS_CHANGED_BEACON |
1153 BSS_CHANGED_P2P_PS |
1154 BSS_CHANGED_TXPOWER |
1157 int prev_beacon_int;
1158 unsigned int link_id = params->beacon.link_id;
1159 struct ieee80211_link_data *link;
1160 struct ieee80211_bss_conf *link_conf;
1162 link = sdata_dereference(sdata->link[link_id], sdata);
1166 link_conf = link->conf;
1168 old = sdata_dereference(link->u.ap.beacon, sdata);
1172 if (params->smps_mode != NL80211_SMPS_OFF)
1175 link->smps_mode = IEEE80211_SMPS_OFF;
1177 link->needed_rx_chains = sdata->local->rx_chains;
1179 prev_beacon_int = link_conf->beacon_int;
1180 link_conf->beacon_int = params->beacon_interval;
1182 if (params->he_cap && params->he_oper) {
1183 link_conf->he_support = true;
1184 link_conf->htc_trig_based_pkt_ext =
1185 le32_get_bits(params->he_oper->he_oper_params,
1186 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1187 link_conf->frame_time_rts_th =
1188 le32_get_bits(params->he_oper->he_oper_params,
1189 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1190 changed |= BSS_CHANGED_HE_OBSS_PD;
1192 if (params->beacon.he_bss_color.enabled)
1193 changed |= BSS_CHANGED_HE_BSS_COLOR;
1196 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1197 params->mbssid_config.tx_wdev) {
1198 err = ieee80211_set_ap_mbssid_options(sdata,
1199 params->mbssid_config,
1205 mutex_lock(&local->mtx);
1206 err = ieee80211_link_use_channel(link, ¶ms->chandef,
1207 IEEE80211_CHANCTX_SHARED);
1209 ieee80211_link_copy_chanctx_to_vlans(link, false);
1210 mutex_unlock(&local->mtx);
1212 link_conf->beacon_int = prev_beacon_int;
1217 * Apply control port protocol, this allows us to
1218 * not encrypt dynamic WEP control frames.
1220 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1221 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1222 sdata->control_port_over_nl80211 =
1223 params->crypto.control_port_over_nl80211;
1224 sdata->control_port_no_preauth =
1225 params->crypto.control_port_no_preauth;
1227 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1228 vlan->control_port_protocol =
1229 params->crypto.control_port_ethertype;
1230 vlan->control_port_no_encrypt =
1231 params->crypto.control_port_no_encrypt;
1232 vlan->control_port_over_nl80211 =
1233 params->crypto.control_port_over_nl80211;
1234 vlan->control_port_no_preauth =
1235 params->crypto.control_port_no_preauth;
1238 link_conf->dtim_period = params->dtim_period;
1239 link_conf->enable_beacon = true;
1240 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1241 link_conf->twt_responder = params->twt_responder;
1242 link_conf->he_obss_pd = params->he_obss_pd;
1243 link_conf->he_bss_color = params->beacon.he_bss_color;
1244 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1247 sdata->vif.cfg.ssid_len = params->ssid_len;
1248 if (params->ssid_len)
1249 memcpy(sdata->vif.cfg.ssid, params->ssid,
1251 link_conf->hidden_ssid =
1252 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1254 memset(&link_conf->p2p_noa_attr, 0,
1255 sizeof(link_conf->p2p_noa_attr));
1256 link_conf->p2p_noa_attr.oppps_ctwindow =
1257 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1258 if (params->p2p_opp_ps)
1259 link_conf->p2p_noa_attr.oppps_ctwindow |=
1260 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1262 sdata->beacon_rate_set = false;
1263 if (wiphy_ext_feature_isset(local->hw.wiphy,
1264 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1265 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1266 sdata->beacon_rateidx_mask[i] =
1267 params->beacon_rate.control[i].legacy;
1268 if (sdata->beacon_rateidx_mask[i])
1269 sdata->beacon_rate_set = true;
1273 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1274 link_conf->beacon_tx_rate = params->beacon_rate;
1276 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL);
1281 if (params->fils_discovery.max_interval) {
1282 err = ieee80211_set_fils_discovery(sdata,
1283 ¶ms->fils_discovery,
1287 changed |= BSS_CHANGED_FILS_DISCOVERY;
1290 if (params->unsol_bcast_probe_resp.interval) {
1291 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1292 ¶ms->unsol_bcast_probe_resp,
1296 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1299 err = drv_start_ap(sdata->local, sdata, link_conf);
1301 old = sdata_dereference(link->u.ap.beacon, sdata);
1304 kfree_rcu(old, rcu_head);
1305 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1306 sdata->u.ap.active = false;
1310 ieee80211_recalc_dtim(local, sdata);
1311 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1312 ieee80211_link_info_change_notify(sdata, link, changed);
1314 netif_carrier_on(dev);
1315 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1316 netif_carrier_on(vlan->dev);
1321 mutex_lock(&local->mtx);
1322 ieee80211_link_release_channel(link);
1323 mutex_unlock(&local->mtx);
1328 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1329 struct cfg80211_beacon_data *params)
1331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1332 struct ieee80211_link_data *link;
1333 struct beacon_data *old;
1335 struct ieee80211_bss_conf *link_conf;
1337 sdata_assert_lock(sdata);
1339 link = sdata_dereference(sdata->link[params->link_id], sdata);
1343 link_conf = link->conf;
1345 /* don't allow changing the beacon while a countdown is in place - offset
1346 * of channel switch counter may change
1348 if (link_conf->csa_active || link_conf->color_change_active)
1351 old = sdata_dereference(link->u.ap.beacon, sdata);
1355 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL);
1359 if (params->he_bss_color_valid &&
1360 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1361 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1362 err |= BSS_CHANGED_HE_BSS_COLOR;
1365 ieee80211_link_info_change_notify(sdata, link, err);
1369 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1371 if (!link->u.ap.next_beacon)
1374 kfree(link->u.ap.next_beacon->mbssid_ies);
1375 kfree(link->u.ap.next_beacon);
1376 link->u.ap.next_beacon = NULL;
1379 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1380 unsigned int link_id)
1382 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1383 struct ieee80211_sub_if_data *vlan;
1384 struct ieee80211_local *local = sdata->local;
1385 struct beacon_data *old_beacon;
1386 struct probe_resp *old_probe_resp;
1387 struct fils_discovery_data *old_fils_discovery;
1388 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1389 struct cfg80211_chan_def chandef;
1390 struct ieee80211_link_data *link =
1391 sdata_dereference(sdata->link[link_id], sdata);
1392 struct ieee80211_bss_conf *link_conf = link->conf;
1394 sdata_assert_lock(sdata);
1396 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1399 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1401 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1403 old_unsol_bcast_probe_resp =
1404 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1407 /* abort any running channel switch */
1408 mutex_lock(&local->mtx);
1409 link_conf->csa_active = false;
1410 if (link->csa_block_tx) {
1411 ieee80211_wake_vif_queues(local, sdata,
1412 IEEE80211_QUEUE_STOP_REASON_CSA);
1413 link->csa_block_tx = false;
1416 mutex_unlock(&local->mtx);
1418 ieee80211_free_next_beacon(link);
1420 /* turn off carrier for this interface and dependent VLANs */
1421 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1422 netif_carrier_off(vlan->dev);
1423 netif_carrier_off(dev);
1425 /* remove beacon and probe response */
1426 sdata->u.ap.active = false;
1427 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1428 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1429 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1430 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1431 kfree_rcu(old_beacon, rcu_head);
1433 kfree_rcu(old_probe_resp, rcu_head);
1434 if (old_fils_discovery)
1435 kfree_rcu(old_fils_discovery, rcu_head);
1436 if (old_unsol_bcast_probe_resp)
1437 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1439 kfree(link_conf->ftmr_params);
1440 link_conf->ftmr_params = NULL;
1442 __sta_info_flush(sdata, true);
1443 ieee80211_free_keys(sdata, true);
1445 link_conf->enable_beacon = false;
1446 sdata->beacon_rate_set = false;
1447 sdata->vif.cfg.ssid_len = 0;
1448 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1449 ieee80211_link_info_change_notify(sdata, link,
1450 BSS_CHANGED_BEACON_ENABLED);
1452 if (sdata->wdev.cac_started) {
1453 chandef = link_conf->chandef;
1454 cancel_delayed_work_sync(&link->dfs_cac_timer_work);
1455 cfg80211_cac_event(sdata->dev, &chandef,
1456 NL80211_RADAR_CAC_ABORTED,
1460 drv_stop_ap(sdata->local, sdata, link_conf);
1462 /* free all potentially still buffered bcast frames */
1463 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1464 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1466 mutex_lock(&local->mtx);
1467 ieee80211_link_copy_chanctx_to_vlans(link, true);
1468 ieee80211_link_release_channel(link);
1469 mutex_unlock(&local->mtx);
1474 static int sta_apply_auth_flags(struct ieee80211_local *local,
1475 struct sta_info *sta,
1480 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1481 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1482 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1483 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1488 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1489 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1490 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1492 * When peer becomes associated, init rate control as
1493 * well. Some drivers require rate control initialized
1494 * before drv_sta_state() is called.
1496 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1497 rate_control_rate_init(sta);
1499 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1504 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1505 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1506 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1507 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1508 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1515 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1516 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1517 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1518 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1523 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1524 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1525 test_sta_flag(sta, WLAN_STA_AUTH)) {
1526 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1534 static void sta_apply_mesh_params(struct ieee80211_local *local,
1535 struct sta_info *sta,
1536 struct station_parameters *params)
1538 #ifdef CONFIG_MAC80211_MESH
1539 struct ieee80211_sub_if_data *sdata = sta->sdata;
1542 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1543 switch (params->plink_state) {
1544 case NL80211_PLINK_ESTAB:
1545 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1546 changed = mesh_plink_inc_estab_count(sdata);
1547 sta->mesh->plink_state = params->plink_state;
1548 sta->mesh->aid = params->peer_aid;
1550 ieee80211_mps_sta_status_update(sta);
1551 changed |= ieee80211_mps_set_sta_local_pm(sta,
1552 sdata->u.mesh.mshcfg.power_mode);
1554 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1555 /* init at low value */
1556 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1559 case NL80211_PLINK_LISTEN:
1560 case NL80211_PLINK_BLOCKED:
1561 case NL80211_PLINK_OPN_SNT:
1562 case NL80211_PLINK_OPN_RCVD:
1563 case NL80211_PLINK_CNF_RCVD:
1564 case NL80211_PLINK_HOLDING:
1565 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1566 changed = mesh_plink_dec_estab_count(sdata);
1567 sta->mesh->plink_state = params->plink_state;
1569 ieee80211_mps_sta_status_update(sta);
1570 changed |= ieee80211_mps_set_sta_local_pm(sta,
1571 NL80211_MESH_POWER_UNKNOWN);
1579 switch (params->plink_action) {
1580 case NL80211_PLINK_ACTION_NO_ACTION:
1583 case NL80211_PLINK_ACTION_OPEN:
1584 changed |= mesh_plink_open(sta);
1586 case NL80211_PLINK_ACTION_BLOCK:
1587 changed |= mesh_plink_block(sta);
1591 if (params->local_pm)
1592 changed |= ieee80211_mps_set_sta_local_pm(sta,
1595 ieee80211_mbss_info_change_notify(sdata, changed);
1599 static int sta_link_apply_parameters(struct ieee80211_local *local,
1600 struct sta_info *sta, bool new_link,
1601 struct link_station_parameters *params)
1604 struct ieee80211_supported_band *sband;
1605 struct ieee80211_sub_if_data *sdata = sta->sdata;
1606 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1607 struct ieee80211_link_data *link =
1608 sdata_dereference(sdata->link[link_id], sdata);
1609 struct link_sta_info *link_sta =
1610 rcu_dereference_protected(sta->link[link_id],
1611 lockdep_is_held(&local->sta_mtx));
1613 if (!link || !link_sta)
1616 sband = ieee80211_get_link_sband(link);
1620 if (params->link_mac) {
1622 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1623 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1624 } else if (!ether_addr_equal(link_sta->addr,
1625 params->link_mac)) {
1630 if (params->txpwr_set) {
1631 link_sta->pub->txpwr.type = params->txpwr.type;
1632 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1633 link_sta->pub->txpwr.power = params->txpwr.power;
1634 ret = drv_sta_set_txpwr(local, sdata, sta);
1639 if (params->supported_rates &&
1640 params->supported_rates_len) {
1641 ieee80211_parse_bitrates(link->conf->chandef.width,
1642 sband, params->supported_rates,
1643 params->supported_rates_len,
1644 &link_sta->pub->supp_rates[sband->band]);
1647 if (params->ht_capa)
1648 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1649 params->ht_capa, link_sta);
1651 /* VHT can override some HT caps such as the A-MSDU max length */
1652 if (params->vht_capa)
1653 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1654 params->vht_capa, link_sta);
1656 if (params->he_capa)
1657 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1658 (void *)params->he_capa,
1659 params->he_capa_len,
1660 (void *)params->he_6ghz_capa,
1663 if (params->eht_capa)
1664 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1665 (u8 *)params->he_capa,
1666 params->he_capa_len,
1668 params->eht_capa_len,
1671 if (params->opmode_notif_used) {
1672 /* returned value is only needed for rc update, but the
1673 * rc isn't initialized here yet, so ignore it
1675 __ieee80211_vht_handle_opmode(sdata, link_sta,
1676 params->opmode_notif,
1683 static int sta_apply_parameters(struct ieee80211_local *local,
1684 struct sta_info *sta,
1685 struct station_parameters *params)
1687 struct ieee80211_sub_if_data *sdata = sta->sdata;
1691 mask = params->sta_flags_mask;
1692 set = params->sta_flags_set;
1694 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1696 * In mesh mode, ASSOCIATED isn't part of the nl80211
1697 * API but must follow AUTHENTICATED for driver state.
1699 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1700 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1701 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1702 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1703 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1705 * TDLS -- everything follows authorized, but
1706 * only becoming authorized is possible, not
1709 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1710 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1711 BIT(NL80211_STA_FLAG_ASSOCIATED);
1712 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1713 BIT(NL80211_STA_FLAG_ASSOCIATED);
1717 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1718 local->hw.queues >= IEEE80211_NUM_ACS)
1719 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1721 /* auth flags will be set later for TDLS,
1722 * and for unassociated stations that move to associated */
1723 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1724 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1725 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1726 ret = sta_apply_auth_flags(local, sta, mask, set);
1731 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1732 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1733 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1735 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1738 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1739 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1740 if (set & BIT(NL80211_STA_FLAG_MFP))
1741 set_sta_flag(sta, WLAN_STA_MFP);
1743 clear_sta_flag(sta, WLAN_STA_MFP);
1746 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1747 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1748 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1750 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1753 /* mark TDLS channel switch support, if the AP allows it */
1754 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1755 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
1756 params->ext_capab_len >= 4 &&
1757 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1758 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1760 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1761 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1762 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1763 params->ext_capab_len >= 8 &&
1764 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1765 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1767 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1768 sta->sta.uapsd_queues = params->uapsd_queues;
1769 sta->sta.max_sp = params->max_sp;
1772 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
1773 params->ext_capab_len);
1776 * cfg80211 validates this (1-2007) and allows setting the AID
1777 * only when creating a new station entry
1780 sta->sta.aid = params->aid;
1783 * Some of the following updates would be racy if called on an
1784 * existing station, via ieee80211_change_station(). However,
1785 * all such changes are rejected by cfg80211 except for updates
1786 * changing the supported rates on an existing but not yet used
1790 if (params->listen_interval >= 0)
1791 sta->listen_interval = params->listen_interval;
1793 ret = sta_link_apply_parameters(local, sta, false,
1794 ¶ms->link_sta_params);
1798 if (params->support_p2p_ps >= 0)
1799 sta->sta.support_p2p_ps = params->support_p2p_ps;
1801 if (ieee80211_vif_is_mesh(&sdata->vif))
1802 sta_apply_mesh_params(local, sta, params);
1804 if (params->airtime_weight)
1805 sta->airtime_weight = params->airtime_weight;
1807 /* set the STA state after all sta info from usermode has been set */
1808 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1809 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1810 ret = sta_apply_auth_flags(local, sta, mask, set);
1815 /* Mark the STA as MLO if MLD MAC address is available */
1816 if (params->link_sta_params.mld_mac)
1817 sta->sta.mlo = true;
1822 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1824 struct station_parameters *params)
1826 struct ieee80211_local *local = wiphy_priv(wiphy);
1827 struct sta_info *sta;
1828 struct ieee80211_sub_if_data *sdata;
1832 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1834 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1835 sdata->vif.type != NL80211_IFTYPE_AP)
1838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1840 if (ether_addr_equal(mac, sdata->vif.addr))
1843 if (!is_valid_ether_addr(mac))
1846 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1847 sdata->vif.type == NL80211_IFTYPE_STATION &&
1848 !sdata->u.mgd.associated)
1852 * If we have a link ID, it can be a non-MLO station on an AP MLD,
1853 * but we need to have a link_mac in that case as well, so use the
1854 * STA's MAC address in that case.
1856 if (params->link_sta_params.link_id >= 0)
1857 sta = sta_info_alloc_with_link(sdata, mac,
1858 params->link_sta_params.link_id,
1859 params->link_sta_params.link_mac ?: mac,
1862 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1867 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1868 sta->sta.tdls = true;
1870 /* Though the mutex is not needed here (since the station is not
1871 * visible yet), sta_apply_parameters (and inner functions) require
1872 * the mutex due to other paths.
1874 mutex_lock(&local->sta_mtx);
1875 err = sta_apply_parameters(local, sta, params);
1876 mutex_unlock(&local->sta_mtx);
1878 sta_info_free(local, sta);
1883 * for TDLS and for unassociated station, rate control should be
1884 * initialized only when rates are known and station is marked
1885 * authorized/associated
1887 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1888 test_sta_flag(sta, WLAN_STA_ASSOC))
1889 rate_control_rate_init(sta);
1891 return sta_info_insert(sta);
1894 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1895 struct station_del_parameters *params)
1897 struct ieee80211_sub_if_data *sdata;
1899 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1902 return sta_info_destroy_addr_bss(sdata, params->mac);
1904 sta_info_flush(sdata);
1908 static int ieee80211_change_station(struct wiphy *wiphy,
1909 struct net_device *dev, const u8 *mac,
1910 struct station_parameters *params)
1912 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1913 struct ieee80211_local *local = wiphy_priv(wiphy);
1914 struct sta_info *sta;
1915 struct ieee80211_sub_if_data *vlansdata;
1916 enum cfg80211_station_type statype;
1919 mutex_lock(&local->sta_mtx);
1921 sta = sta_info_get_bss(sdata, mac);
1927 switch (sdata->vif.type) {
1928 case NL80211_IFTYPE_MESH_POINT:
1929 if (sdata->u.mesh.user_mpm)
1930 statype = CFG80211_STA_MESH_PEER_USER;
1932 statype = CFG80211_STA_MESH_PEER_KERNEL;
1934 case NL80211_IFTYPE_ADHOC:
1935 statype = CFG80211_STA_IBSS;
1937 case NL80211_IFTYPE_STATION:
1938 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1939 statype = CFG80211_STA_AP_STA;
1942 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1943 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1945 statype = CFG80211_STA_TDLS_PEER_SETUP;
1947 case NL80211_IFTYPE_AP:
1948 case NL80211_IFTYPE_AP_VLAN:
1949 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1950 statype = CFG80211_STA_AP_CLIENT;
1952 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1959 err = cfg80211_check_station_change(wiphy, params, statype);
1963 if (params->vlan && params->vlan != sta->sdata->dev) {
1964 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1966 if (params->vlan->ieee80211_ptr->use_4addr) {
1967 if (vlansdata->u.vlan.sta) {
1972 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1973 __ieee80211_check_fast_rx_iface(vlansdata);
1974 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
1977 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1978 sta->sdata->u.vlan.sta) {
1979 ieee80211_clear_fast_rx(sta);
1980 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1983 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1984 ieee80211_vif_dec_num_mcast(sta->sdata);
1986 sta->sdata = vlansdata;
1987 ieee80211_check_fast_xmit(sta);
1989 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
1990 ieee80211_vif_inc_num_mcast(sta->sdata);
1991 cfg80211_send_layer2_update(sta->sdata->dev,
1996 /* we use sta_info_get_bss() so this might be different */
1997 if (sdata != sta->sdata) {
1998 mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
1999 err = sta_apply_parameters(local, sta, params);
2000 mutex_unlock(&sta->sdata->wdev.mtx);
2002 err = sta_apply_parameters(local, sta, params);
2007 mutex_unlock(&local->sta_mtx);
2009 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2010 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2011 ieee80211_recalc_ps(local);
2012 ieee80211_recalc_ps_vif(sdata);
2017 mutex_unlock(&local->sta_mtx);
2021 #ifdef CONFIG_MAC80211_MESH
2022 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2023 const u8 *dst, const u8 *next_hop)
2025 struct ieee80211_sub_if_data *sdata;
2026 struct mesh_path *mpath;
2027 struct sta_info *sta;
2029 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2032 sta = sta_info_get(sdata, next_hop);
2038 mpath = mesh_path_add(sdata, dst);
2039 if (IS_ERR(mpath)) {
2041 return PTR_ERR(mpath);
2044 mesh_path_fix_nexthop(mpath, sta);
2050 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2053 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2056 return mesh_path_del(sdata, dst);
2058 mesh_path_flush_by_iface(sdata);
2062 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2063 const u8 *dst, const u8 *next_hop)
2065 struct ieee80211_sub_if_data *sdata;
2066 struct mesh_path *mpath;
2067 struct sta_info *sta;
2069 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2073 sta = sta_info_get(sdata, next_hop);
2079 mpath = mesh_path_lookup(sdata, dst);
2085 mesh_path_fix_nexthop(mpath, sta);
2091 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2092 struct mpath_info *pinfo)
2094 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2097 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2099 eth_zero_addr(next_hop);
2101 memset(pinfo, 0, sizeof(*pinfo));
2103 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2105 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2108 MPATH_INFO_EXPTIME |
2109 MPATH_INFO_DISCOVERY_TIMEOUT |
2110 MPATH_INFO_DISCOVERY_RETRIES |
2112 MPATH_INFO_HOP_COUNT |
2113 MPATH_INFO_PATH_CHANGE;
2115 pinfo->frame_qlen = mpath->frame_queue.qlen;
2116 pinfo->sn = mpath->sn;
2117 pinfo->metric = mpath->metric;
2118 if (time_before(jiffies, mpath->exp_time))
2119 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2120 pinfo->discovery_timeout =
2121 jiffies_to_msecs(mpath->discovery_timeout);
2122 pinfo->discovery_retries = mpath->discovery_retries;
2123 if (mpath->flags & MESH_PATH_ACTIVE)
2124 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2125 if (mpath->flags & MESH_PATH_RESOLVING)
2126 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2127 if (mpath->flags & MESH_PATH_SN_VALID)
2128 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2129 if (mpath->flags & MESH_PATH_FIXED)
2130 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2131 if (mpath->flags & MESH_PATH_RESOLVED)
2132 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2133 pinfo->hop_count = mpath->hop_count;
2134 pinfo->path_change_count = mpath->path_change_count;
2137 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2138 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2141 struct ieee80211_sub_if_data *sdata;
2142 struct mesh_path *mpath;
2144 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2147 mpath = mesh_path_lookup(sdata, dst);
2152 memcpy(dst, mpath->dst, ETH_ALEN);
2153 mpath_set_pinfo(mpath, next_hop, pinfo);
2158 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2159 int idx, u8 *dst, u8 *next_hop,
2160 struct mpath_info *pinfo)
2162 struct ieee80211_sub_if_data *sdata;
2163 struct mesh_path *mpath;
2165 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2168 mpath = mesh_path_lookup_by_idx(sdata, idx);
2173 memcpy(dst, mpath->dst, ETH_ALEN);
2174 mpath_set_pinfo(mpath, next_hop, pinfo);
2179 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2180 struct mpath_info *pinfo)
2182 memset(pinfo, 0, sizeof(*pinfo));
2183 memcpy(mpp, mpath->mpp, ETH_ALEN);
2185 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2188 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2189 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2192 struct ieee80211_sub_if_data *sdata;
2193 struct mesh_path *mpath;
2195 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2198 mpath = mpp_path_lookup(sdata, dst);
2203 memcpy(dst, mpath->dst, ETH_ALEN);
2204 mpp_set_pinfo(mpath, mpp, pinfo);
2209 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2210 int idx, u8 *dst, u8 *mpp,
2211 struct mpath_info *pinfo)
2213 struct ieee80211_sub_if_data *sdata;
2214 struct mesh_path *mpath;
2216 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2219 mpath = mpp_path_lookup_by_idx(sdata, idx);
2224 memcpy(dst, mpath->dst, ETH_ALEN);
2225 mpp_set_pinfo(mpath, mpp, pinfo);
2230 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2231 struct net_device *dev,
2232 struct mesh_config *conf)
2234 struct ieee80211_sub_if_data *sdata;
2235 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2237 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2241 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2243 return (mask >> (parm-1)) & 0x1;
2246 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2247 const struct mesh_setup *setup)
2250 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2251 struct ieee80211_sub_if_data, u.mesh);
2254 /* allocate information elements */
2257 if (setup->ie_len) {
2258 new_ie = kmemdup(setup->ie, setup->ie_len,
2263 ifmsh->ie_len = setup->ie_len;
2266 /* now copy the rest of the setup parameters */
2267 ifmsh->mesh_id_len = setup->mesh_id_len;
2268 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2269 ifmsh->mesh_sp_id = setup->sync_method;
2270 ifmsh->mesh_pp_id = setup->path_sel_proto;
2271 ifmsh->mesh_pm_id = setup->path_metric;
2272 ifmsh->user_mpm = setup->user_mpm;
2273 ifmsh->mesh_auth_id = setup->auth_id;
2274 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2275 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2276 if (setup->is_authenticated)
2277 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2278 if (setup->is_secure)
2279 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2281 /* mcast rate setting in Mesh Node */
2282 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2283 sizeof(setup->mcast_rate));
2284 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2286 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2287 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2289 sdata->beacon_rate_set = false;
2290 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2291 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2292 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2293 sdata->beacon_rateidx_mask[i] =
2294 setup->beacon_rate.control[i].legacy;
2295 if (sdata->beacon_rateidx_mask[i])
2296 sdata->beacon_rate_set = true;
2303 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2304 struct net_device *dev, u32 mask,
2305 const struct mesh_config *nconf)
2307 struct mesh_config *conf;
2308 struct ieee80211_sub_if_data *sdata;
2309 struct ieee80211_if_mesh *ifmsh;
2311 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2312 ifmsh = &sdata->u.mesh;
2314 /* Set the config options which we are interested in setting */
2315 conf = &(sdata->u.mesh.mshcfg);
2316 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2317 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2318 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2319 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2320 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2321 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2322 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2323 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2324 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2325 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2326 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2327 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2328 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2329 conf->element_ttl = nconf->element_ttl;
2330 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2331 if (ifmsh->user_mpm)
2333 conf->auto_open_plinks = nconf->auto_open_plinks;
2335 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2336 conf->dot11MeshNbrOffsetMaxNeighbor =
2337 nconf->dot11MeshNbrOffsetMaxNeighbor;
2338 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2339 conf->dot11MeshHWMPmaxPREQretries =
2340 nconf->dot11MeshHWMPmaxPREQretries;
2341 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2342 conf->path_refresh_time = nconf->path_refresh_time;
2343 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2344 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2345 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2346 conf->dot11MeshHWMPactivePathTimeout =
2347 nconf->dot11MeshHWMPactivePathTimeout;
2348 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2349 conf->dot11MeshHWMPpreqMinInterval =
2350 nconf->dot11MeshHWMPpreqMinInterval;
2351 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2352 conf->dot11MeshHWMPperrMinInterval =
2353 nconf->dot11MeshHWMPperrMinInterval;
2354 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2356 conf->dot11MeshHWMPnetDiameterTraversalTime =
2357 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2358 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2359 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2360 ieee80211_mesh_root_setup(ifmsh);
2362 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2363 /* our current gate announcement implementation rides on root
2364 * announcements, so require this ifmsh to also be a root node
2366 if (nconf->dot11MeshGateAnnouncementProtocol &&
2367 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2368 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2369 ieee80211_mesh_root_setup(ifmsh);
2371 conf->dot11MeshGateAnnouncementProtocol =
2372 nconf->dot11MeshGateAnnouncementProtocol;
2374 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2375 conf->dot11MeshHWMPRannInterval =
2376 nconf->dot11MeshHWMPRannInterval;
2377 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2378 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2379 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2380 /* our RSSI threshold implementation is supported only for
2381 * devices that report signal in dBm.
2383 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2385 conf->rssi_threshold = nconf->rssi_threshold;
2387 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2388 conf->ht_opmode = nconf->ht_opmode;
2389 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2390 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2393 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2394 conf->dot11MeshHWMPactivePathToRootTimeout =
2395 nconf->dot11MeshHWMPactivePathToRootTimeout;
2396 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2397 conf->dot11MeshHWMProotInterval =
2398 nconf->dot11MeshHWMProotInterval;
2399 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2400 conf->dot11MeshHWMPconfirmationInterval =
2401 nconf->dot11MeshHWMPconfirmationInterval;
2402 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2403 conf->power_mode = nconf->power_mode;
2404 ieee80211_mps_local_status_update(sdata);
2406 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2407 conf->dot11MeshAwakeWindowDuration =
2408 nconf->dot11MeshAwakeWindowDuration;
2409 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2410 conf->plink_timeout = nconf->plink_timeout;
2411 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2412 conf->dot11MeshConnectedToMeshGate =
2413 nconf->dot11MeshConnectedToMeshGate;
2414 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2415 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2416 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2417 conf->dot11MeshConnectedToAuthServer =
2418 nconf->dot11MeshConnectedToAuthServer;
2419 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2423 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2424 const struct mesh_config *conf,
2425 const struct mesh_setup *setup)
2427 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2428 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2431 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2432 err = copy_mesh_setup(ifmsh, setup);
2436 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2438 /* can mesh use other SMPS modes? */
2439 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2440 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2442 mutex_lock(&sdata->local->mtx);
2443 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
2444 IEEE80211_CHANCTX_SHARED);
2445 mutex_unlock(&sdata->local->mtx);
2449 return ieee80211_start_mesh(sdata);
2452 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2456 ieee80211_stop_mesh(sdata);
2457 mutex_lock(&sdata->local->mtx);
2458 ieee80211_link_release_channel(&sdata->deflink);
2459 kfree(sdata->u.mesh.ie);
2460 mutex_unlock(&sdata->local->mtx);
2466 static int ieee80211_change_bss(struct wiphy *wiphy,
2467 struct net_device *dev,
2468 struct bss_parameters *params)
2470 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2471 struct ieee80211_supported_band *sband;
2474 if (!sdata_dereference(sdata->deflink.u.ap.beacon, sdata))
2477 sband = ieee80211_get_sband(sdata);
2481 if (params->use_cts_prot >= 0) {
2482 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2483 changed |= BSS_CHANGED_ERP_CTS_PROT;
2485 if (params->use_short_preamble >= 0) {
2486 sdata->vif.bss_conf.use_short_preamble =
2487 params->use_short_preamble;
2488 changed |= BSS_CHANGED_ERP_PREAMBLE;
2491 if (!sdata->vif.bss_conf.use_short_slot &&
2492 (sband->band == NL80211_BAND_5GHZ ||
2493 sband->band == NL80211_BAND_6GHZ)) {
2494 sdata->vif.bss_conf.use_short_slot = true;
2495 changed |= BSS_CHANGED_ERP_SLOT;
2498 if (params->use_short_slot_time >= 0) {
2499 sdata->vif.bss_conf.use_short_slot =
2500 params->use_short_slot_time;
2501 changed |= BSS_CHANGED_ERP_SLOT;
2504 if (params->basic_rates) {
2505 ieee80211_parse_bitrates(sdata->vif.bss_conf.chandef.width,
2506 wiphy->bands[sband->band],
2507 params->basic_rates,
2508 params->basic_rates_len,
2509 &sdata->vif.bss_conf.basic_rates);
2510 changed |= BSS_CHANGED_BASIC_RATES;
2511 ieee80211_check_rate_mask(&sdata->deflink);
2514 if (params->ap_isolate >= 0) {
2515 if (params->ap_isolate)
2516 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2518 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2519 ieee80211_check_fast_rx_iface(sdata);
2522 if (params->ht_opmode >= 0) {
2523 sdata->vif.bss_conf.ht_operation_mode =
2524 (u16) params->ht_opmode;
2525 changed |= BSS_CHANGED_HT;
2528 if (params->p2p_ctwindow >= 0) {
2529 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2530 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2531 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2532 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2533 changed |= BSS_CHANGED_P2P_PS;
2536 if (params->p2p_opp_ps > 0) {
2537 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2538 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2539 changed |= BSS_CHANGED_P2P_PS;
2540 } else if (params->p2p_opp_ps == 0) {
2541 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2542 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2543 changed |= BSS_CHANGED_P2P_PS;
2546 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
2551 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2552 struct net_device *dev,
2553 struct ieee80211_txq_params *params)
2555 struct ieee80211_local *local = wiphy_priv(wiphy);
2556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2557 struct ieee80211_link_data *link = &sdata->deflink;
2558 struct ieee80211_tx_queue_params p;
2560 if (!local->ops->conf_tx)
2563 if (local->hw.queues < IEEE80211_NUM_ACS)
2566 memset(&p, 0, sizeof(p));
2567 p.aifs = params->aifs;
2568 p.cw_max = params->cwmax;
2569 p.cw_min = params->cwmin;
2570 p.txop = params->txop;
2573 * Setting tx queue params disables u-apsd because it's only
2574 * called in master mode.
2578 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2580 link->tx_conf[params->ac] = p;
2581 if (drv_conf_tx(local, link, params->ac, &p)) {
2582 wiphy_debug(local->hw.wiphy,
2583 "failed to set TX queue parameters for AC %d\n",
2588 ieee80211_link_info_change_notify(sdata, link,
2595 static int ieee80211_suspend(struct wiphy *wiphy,
2596 struct cfg80211_wowlan *wowlan)
2598 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2601 static int ieee80211_resume(struct wiphy *wiphy)
2603 return __ieee80211_resume(wiphy_priv(wiphy));
2606 #define ieee80211_suspend NULL
2607 #define ieee80211_resume NULL
2610 static int ieee80211_scan(struct wiphy *wiphy,
2611 struct cfg80211_scan_request *req)
2613 struct ieee80211_sub_if_data *sdata;
2615 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2617 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2618 case NL80211_IFTYPE_STATION:
2619 case NL80211_IFTYPE_ADHOC:
2620 case NL80211_IFTYPE_MESH_POINT:
2621 case NL80211_IFTYPE_P2P_CLIENT:
2622 case NL80211_IFTYPE_P2P_DEVICE:
2624 case NL80211_IFTYPE_P2P_GO:
2625 if (sdata->local->ops->hw_scan)
2628 * FIXME: implement NoA while scanning in software,
2629 * for now fall through to allow scanning only when
2630 * beaconing hasn't been configured yet
2633 case NL80211_IFTYPE_AP:
2635 * If the scan has been forced (and the driver supports
2636 * forcing), don't care about being beaconing already.
2637 * This will create problems to the attached stations (e.g. all
2638 * the frames sent while scanning on other channel will be
2641 if (sdata->deflink.u.ap.beacon &&
2642 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2643 !(req->flags & NL80211_SCAN_FLAG_AP)))
2646 case NL80211_IFTYPE_NAN:
2651 return ieee80211_request_scan(sdata, req);
2654 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2656 ieee80211_scan_cancel(wiphy_priv(wiphy));
2660 ieee80211_sched_scan_start(struct wiphy *wiphy,
2661 struct net_device *dev,
2662 struct cfg80211_sched_scan_request *req)
2664 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2666 if (!sdata->local->ops->sched_scan_start)
2669 return ieee80211_request_sched_scan_start(sdata, req);
2673 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2676 struct ieee80211_local *local = wiphy_priv(wiphy);
2678 if (!local->ops->sched_scan_stop)
2681 return ieee80211_request_sched_scan_stop(local);
2684 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2685 struct cfg80211_auth_request *req)
2687 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2690 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2691 struct cfg80211_assoc_request *req)
2693 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2696 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2697 struct cfg80211_deauth_request *req)
2699 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2702 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2703 struct cfg80211_disassoc_request *req)
2705 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2708 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2709 struct cfg80211_ibss_params *params)
2711 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2714 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2716 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2719 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2720 struct ocb_setup *setup)
2722 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2725 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2727 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2730 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2731 int rate[NUM_NL80211_BANDS])
2733 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2735 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2736 sizeof(int) * NUM_NL80211_BANDS);
2738 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2739 BSS_CHANGED_MCAST_RATE);
2744 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2746 struct ieee80211_local *local = wiphy_priv(wiphy);
2749 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2750 ieee80211_check_fast_xmit_all(local);
2752 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2755 ieee80211_check_fast_xmit_all(local);
2760 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2761 (changed & WIPHY_PARAM_DYN_ACK)) {
2764 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2765 wiphy->coverage_class : -1;
2766 err = drv_set_coverage_class(local, coverage_class);
2772 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2773 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2779 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2780 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2782 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2784 if (changed & WIPHY_PARAM_RETRY_LONG) {
2785 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2787 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2790 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2791 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2793 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2794 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2795 WIPHY_PARAM_TXQ_QUANTUM))
2796 ieee80211_txq_set_params(local);
2801 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2802 struct wireless_dev *wdev,
2803 enum nl80211_tx_power_setting type, int mbm)
2805 struct ieee80211_local *local = wiphy_priv(wiphy);
2806 struct ieee80211_sub_if_data *sdata;
2807 enum nl80211_tx_power_setting txp_type = type;
2808 bool update_txp_type = false;
2809 bool has_monitor = false;
2812 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2814 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2815 sdata = wiphy_dereference(local->hw.wiphy,
2816 local->monitor_sdata);
2822 case NL80211_TX_POWER_AUTOMATIC:
2823 sdata->deflink.user_power_level =
2824 IEEE80211_UNSET_POWER_LEVEL;
2825 txp_type = NL80211_TX_POWER_LIMITED;
2827 case NL80211_TX_POWER_LIMITED:
2828 case NL80211_TX_POWER_FIXED:
2829 if (mbm < 0 || (mbm % 100))
2831 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
2835 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2836 update_txp_type = true;
2837 sdata->vif.bss_conf.txpower_type = txp_type;
2840 ieee80211_recalc_txpower(sdata, update_txp_type);
2846 case NL80211_TX_POWER_AUTOMATIC:
2847 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2848 txp_type = NL80211_TX_POWER_LIMITED;
2850 case NL80211_TX_POWER_LIMITED:
2851 case NL80211_TX_POWER_FIXED:
2852 if (mbm < 0 || (mbm % 100))
2854 local->user_power_level = MBM_TO_DBM(mbm);
2858 mutex_lock(&local->iflist_mtx);
2859 list_for_each_entry(sdata, &local->interfaces, list) {
2860 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2864 sdata->deflink.user_power_level = local->user_power_level;
2865 if (txp_type != sdata->vif.bss_conf.txpower_type)
2866 update_txp_type = true;
2867 sdata->vif.bss_conf.txpower_type = txp_type;
2869 list_for_each_entry(sdata, &local->interfaces, list) {
2870 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2872 ieee80211_recalc_txpower(sdata, update_txp_type);
2874 mutex_unlock(&local->iflist_mtx);
2877 sdata = wiphy_dereference(local->hw.wiphy,
2878 local->monitor_sdata);
2880 sdata->deflink.user_power_level = local->user_power_level;
2881 if (txp_type != sdata->vif.bss_conf.txpower_type)
2882 update_txp_type = true;
2883 sdata->vif.bss_conf.txpower_type = txp_type;
2885 ieee80211_recalc_txpower(sdata, update_txp_type);
2892 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2893 struct wireless_dev *wdev,
2896 struct ieee80211_local *local = wiphy_priv(wiphy);
2897 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2899 if (local->ops->get_txpower)
2900 return drv_get_txpower(local, sdata, dbm);
2902 if (!local->use_chanctx)
2903 *dbm = local->hw.conf.power_level;
2905 *dbm = sdata->vif.bss_conf.txpower;
2910 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2912 struct ieee80211_local *local = wiphy_priv(wiphy);
2914 drv_rfkill_poll(local);
2917 #ifdef CONFIG_NL80211_TESTMODE
2918 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2919 struct wireless_dev *wdev,
2920 void *data, int len)
2922 struct ieee80211_local *local = wiphy_priv(wiphy);
2923 struct ieee80211_vif *vif = NULL;
2925 if (!local->ops->testmode_cmd)
2929 struct ieee80211_sub_if_data *sdata;
2931 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2932 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2936 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2939 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2940 struct sk_buff *skb,
2941 struct netlink_callback *cb,
2942 void *data, int len)
2944 struct ieee80211_local *local = wiphy_priv(wiphy);
2946 if (!local->ops->testmode_dump)
2949 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2953 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2954 struct ieee80211_link_data *link,
2955 enum ieee80211_smps_mode smps_mode)
2958 enum ieee80211_smps_mode old_req;
2960 struct sta_info *sta;
2961 bool tdls_peer_found = false;
2963 lockdep_assert_held(&sdata->wdev.mtx);
2965 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2968 old_req = link->u.mgd.req_smps;
2969 link->u.mgd.req_smps = smps_mode;
2971 if (old_req == smps_mode &&
2972 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2976 * If not associated, or current association is not an HT
2977 * association, there's no need to do anything, just store
2978 * the new value until we associate.
2980 if (!sdata->u.mgd.associated ||
2981 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2984 ap = link->u.mgd.bssid;
2987 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2988 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2989 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2992 tdls_peer_found = true;
2997 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2998 if (tdls_peer_found || !sdata->u.mgd.powersave)
2999 smps_mode = IEEE80211_SMPS_OFF;
3001 smps_mode = IEEE80211_SMPS_DYNAMIC;
3004 /* send SM PS frame to AP */
3005 err = ieee80211_send_smps_action(sdata, smps_mode,
3008 link->u.mgd.req_smps = old_req;
3009 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3010 ieee80211_teardown_tdls_peers(sdata);
3015 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3016 bool enabled, int timeout)
3018 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3019 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3020 unsigned int link_id;
3022 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3025 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3028 if (enabled == sdata->u.mgd.powersave &&
3029 timeout == local->dynamic_ps_forced_timeout)
3032 sdata->u.mgd.powersave = enabled;
3033 local->dynamic_ps_forced_timeout = timeout;
3035 /* no change, but if automatic follow powersave */
3037 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3038 struct ieee80211_link_data *link;
3040 link = sdata_dereference(sdata->link[link_id], sdata);
3044 __ieee80211_request_smps_mgd(sdata, link,
3045 link->u.mgd.req_smps);
3047 sdata_unlock(sdata);
3049 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3050 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3052 ieee80211_recalc_ps(local);
3053 ieee80211_recalc_ps_vif(sdata);
3054 ieee80211_check_fast_rx_iface(sdata);
3059 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3060 struct net_device *dev,
3061 s32 rssi_thold, u32 rssi_hyst)
3063 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3064 struct ieee80211_vif *vif = &sdata->vif;
3065 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3067 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3068 rssi_hyst == bss_conf->cqm_rssi_hyst)
3071 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3072 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3075 bss_conf->cqm_rssi_thold = rssi_thold;
3076 bss_conf->cqm_rssi_hyst = rssi_hyst;
3077 bss_conf->cqm_rssi_low = 0;
3078 bss_conf->cqm_rssi_high = 0;
3079 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3081 /* tell the driver upon association, unless already associated */
3082 if (sdata->u.mgd.associated &&
3083 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3084 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3090 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3091 struct net_device *dev,
3092 s32 rssi_low, s32 rssi_high)
3094 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3095 struct ieee80211_vif *vif = &sdata->vif;
3096 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3098 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3101 bss_conf->cqm_rssi_low = rssi_low;
3102 bss_conf->cqm_rssi_high = rssi_high;
3103 bss_conf->cqm_rssi_thold = 0;
3104 bss_conf->cqm_rssi_hyst = 0;
3105 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3107 /* tell the driver upon association, unless already associated */
3108 if (sdata->u.mgd.associated &&
3109 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3110 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3116 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3117 struct net_device *dev,
3118 unsigned int link_id,
3120 const struct cfg80211_bitrate_mask *mask)
3122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3123 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3126 if (!ieee80211_sdata_running(sdata))
3130 * If active validate the setting and reject it if it doesn't leave
3131 * at least one basic rate usable, since we really have to be able
3132 * to send something, and if we're an AP we have to be able to do
3133 * so at a basic rate so that all clients can receive it.
3135 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3136 sdata->vif.bss_conf.chandef.chan) {
3137 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3138 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3140 if (!(mask->control[band].legacy & basic_rates))
3144 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3145 ret = drv_set_bitrate_mask(local, sdata, mask);
3150 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3151 struct ieee80211_supported_band *sband = wiphy->bands[i];
3154 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3155 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3156 sizeof(mask->control[i].ht_mcs));
3157 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3158 mask->control[i].vht_mcs,
3159 sizeof(mask->control[i].vht_mcs));
3161 sdata->rc_has_mcs_mask[i] = false;
3162 sdata->rc_has_vht_mcs_mask[i] = false;
3166 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3167 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3168 sdata->rc_has_mcs_mask[i] = true;
3173 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3174 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3175 sdata->rc_has_vht_mcs_mask[i] = true;
3184 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3185 struct net_device *dev,
3186 struct cfg80211_chan_def *chandef,
3189 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3190 struct ieee80211_local *local = sdata->local;
3193 mutex_lock(&local->mtx);
3194 if (!list_empty(&local->roc_list) || local->scanning) {
3199 /* whatever, but channel contexts should not complain about that one */
3200 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3201 sdata->deflink.needed_rx_chains = local->rx_chains;
3203 err = ieee80211_link_use_channel(&sdata->deflink, chandef,
3204 IEEE80211_CHANCTX_SHARED);
3208 ieee80211_queue_delayed_work(&sdata->local->hw,
3209 &sdata->deflink.dfs_cac_timer_work,
3210 msecs_to_jiffies(cac_time_ms));
3213 mutex_unlock(&local->mtx);
3217 static void ieee80211_end_cac(struct wiphy *wiphy,
3218 struct net_device *dev)
3220 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3221 struct ieee80211_local *local = sdata->local;
3223 mutex_lock(&local->mtx);
3224 list_for_each_entry(sdata, &local->interfaces, list) {
3225 /* it might be waiting for the local->mtx, but then
3226 * by the time it gets it, sdata->wdev.cac_started
3227 * will no longer be true
3229 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work);
3231 if (sdata->wdev.cac_started) {
3232 ieee80211_link_release_channel(&sdata->deflink);
3233 sdata->wdev.cac_started = false;
3236 mutex_unlock(&local->mtx);
3239 static struct cfg80211_beacon_data *
3240 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3242 struct cfg80211_beacon_data *new_beacon;
3246 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3247 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3248 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3249 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3251 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3255 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3256 new_beacon->mbssid_ies =
3257 kzalloc(struct_size(new_beacon->mbssid_ies,
3258 elem, beacon->mbssid_ies->cnt),
3260 if (!new_beacon->mbssid_ies) {
3266 pos = (u8 *)(new_beacon + 1);
3267 if (beacon->head_len) {
3268 new_beacon->head_len = beacon->head_len;
3269 new_beacon->head = pos;
3270 memcpy(pos, beacon->head, beacon->head_len);
3271 pos += beacon->head_len;
3273 if (beacon->tail_len) {
3274 new_beacon->tail_len = beacon->tail_len;
3275 new_beacon->tail = pos;
3276 memcpy(pos, beacon->tail, beacon->tail_len);
3277 pos += beacon->tail_len;
3279 if (beacon->beacon_ies_len) {
3280 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3281 new_beacon->beacon_ies = pos;
3282 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3283 pos += beacon->beacon_ies_len;
3285 if (beacon->proberesp_ies_len) {
3286 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3287 new_beacon->proberesp_ies = pos;
3288 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3289 pos += beacon->proberesp_ies_len;
3291 if (beacon->assocresp_ies_len) {
3292 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3293 new_beacon->assocresp_ies = pos;
3294 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3295 pos += beacon->assocresp_ies_len;
3297 if (beacon->probe_resp_len) {
3298 new_beacon->probe_resp_len = beacon->probe_resp_len;
3299 new_beacon->probe_resp = pos;
3300 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3301 pos += beacon->probe_resp_len;
3303 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3304 pos += ieee80211_copy_mbssid_beacon(pos,
3305 new_beacon->mbssid_ies,
3306 beacon->mbssid_ies);
3308 /* might copy -1, meaning no changes requested */
3309 new_beacon->ftm_responder = beacon->ftm_responder;
3311 new_beacon->lci_len = beacon->lci_len;
3312 new_beacon->lci = pos;
3313 memcpy(pos, beacon->lci, beacon->lci_len);
3314 pos += beacon->lci_len;
3316 if (beacon->civicloc) {
3317 new_beacon->civicloc_len = beacon->civicloc_len;
3318 new_beacon->civicloc = pos;
3319 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3320 pos += beacon->civicloc_len;
3326 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3328 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3329 struct ieee80211_local *local = sdata->local;
3333 if (vif->mbssid_tx_vif == vif) {
3334 /* Trigger ieee80211_csa_finish() on the non-transmitting
3335 * interfaces when channel switch is received on
3336 * transmitting interface
3338 struct ieee80211_sub_if_data *iter;
3340 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3341 if (!ieee80211_sdata_running(iter))
3344 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3347 ieee80211_queue_work(&iter->local->hw,
3348 &iter->deflink.csa_finalize_work);
3351 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
3355 EXPORT_SYMBOL(ieee80211_csa_finish);
3357 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3359 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3360 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3361 struct ieee80211_local *local = sdata->local;
3363 sdata->deflink.csa_block_tx = block_tx;
3364 sdata_info(sdata, "channel switch failed, disconnecting\n");
3365 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3367 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3369 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3374 switch (sdata->vif.type) {
3375 case NL80211_IFTYPE_AP:
3376 if (!sdata->deflink.u.ap.next_beacon)
3379 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3380 sdata->deflink.u.ap.next_beacon,
3382 ieee80211_free_next_beacon(&sdata->deflink);
3388 case NL80211_IFTYPE_ADHOC:
3389 err = ieee80211_ibss_finish_csa(sdata);
3394 #ifdef CONFIG_MAC80211_MESH
3395 case NL80211_IFTYPE_MESH_POINT:
3396 err = ieee80211_mesh_finish_csa(sdata);
3410 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3412 struct ieee80211_local *local = sdata->local;
3416 sdata_assert_lock(sdata);
3417 lockdep_assert_held(&local->mtx);
3418 lockdep_assert_held(&local->chanctx_mtx);
3421 * using reservation isn't immediate as it may be deferred until later
3422 * with multi-vif. once reservation is complete it will re-schedule the
3423 * work with no reserved_chanctx so verify chandef to check if it
3424 * completed successfully
3427 if (sdata->deflink.reserved_chanctx) {
3429 * with multi-vif csa driver may call ieee80211_csa_finish()
3430 * many times while waiting for other interfaces to use their
3433 if (sdata->deflink.reserved_ready)
3436 return ieee80211_link_use_reserved_context(&sdata->deflink);
3439 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3440 &sdata->deflink.csa_chandef))
3443 sdata->vif.bss_conf.csa_active = false;
3445 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3449 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
3451 if (sdata->deflink.csa_block_tx) {
3452 ieee80211_wake_vif_queues(local, sdata,
3453 IEEE80211_QUEUE_STOP_REASON_CSA);
3454 sdata->deflink.csa_block_tx = false;
3457 err = drv_post_channel_switch(sdata);
3461 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0);
3466 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3468 if (__ieee80211_csa_finalize(sdata)) {
3469 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3470 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3475 void ieee80211_csa_finalize_work(struct work_struct *work)
3477 struct ieee80211_sub_if_data *sdata =
3478 container_of(work, struct ieee80211_sub_if_data,
3479 deflink.csa_finalize_work);
3480 struct ieee80211_local *local = sdata->local;
3483 mutex_lock(&local->mtx);
3484 mutex_lock(&local->chanctx_mtx);
3486 /* AP might have been stopped while waiting for the lock. */
3487 if (!sdata->vif.bss_conf.csa_active)
3490 if (!ieee80211_sdata_running(sdata))
3493 ieee80211_csa_finalize(sdata);
3496 mutex_unlock(&local->chanctx_mtx);
3497 mutex_unlock(&local->mtx);
3498 sdata_unlock(sdata);
3501 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3502 struct cfg80211_csa_settings *params,
3505 struct ieee80211_csa_settings csa = {};
3508 switch (sdata->vif.type) {
3509 case NL80211_IFTYPE_AP:
3510 sdata->deflink.u.ap.next_beacon =
3511 cfg80211_beacon_dup(¶ms->beacon_after);
3512 if (!sdata->deflink.u.ap.next_beacon)
3516 * With a count of 0, we don't have to wait for any
3517 * TBTT before switching, so complete the CSA
3518 * immediately. In theory, with a count == 1 we
3519 * should delay the switch until just before the next
3520 * TBTT, but that would complicate things so we switch
3521 * immediately too. If we would delay the switch
3522 * until the next TBTT, we would have to set the probe
3525 * TODO: A channel switch with count <= 1 without
3526 * sending a CSA action frame is kind of useless,
3527 * because the clients won't know we're changing
3528 * channels. The action frame must be implemented
3529 * either here or in the userspace.
3531 if (params->count <= 1)
3534 if ((params->n_counter_offsets_beacon >
3535 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3536 (params->n_counter_offsets_presp >
3537 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3538 ieee80211_free_next_beacon(&sdata->deflink);
3542 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3543 csa.counter_offsets_presp = params->counter_offsets_presp;
3544 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3545 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3546 csa.count = params->count;
3548 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3549 ¶ms->beacon_csa, &csa,
3552 ieee80211_free_next_beacon(&sdata->deflink);
3558 case NL80211_IFTYPE_ADHOC:
3559 if (!sdata->vif.cfg.ibss_joined)
3562 if (params->chandef.width != sdata->u.ibss.chandef.width)
3565 switch (params->chandef.width) {
3566 case NL80211_CHAN_WIDTH_40:
3567 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3568 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3571 case NL80211_CHAN_WIDTH_5:
3572 case NL80211_CHAN_WIDTH_10:
3573 case NL80211_CHAN_WIDTH_20_NOHT:
3574 case NL80211_CHAN_WIDTH_20:
3580 /* changes into another band are not supported */
3581 if (sdata->u.ibss.chandef.chan->band !=
3582 params->chandef.chan->band)
3585 /* see comments in the NL80211_IFTYPE_AP block */
3586 if (params->count > 1) {
3587 err = ieee80211_ibss_csa_beacon(sdata, params);
3593 ieee80211_send_action_csa(sdata, params);
3596 #ifdef CONFIG_MAC80211_MESH
3597 case NL80211_IFTYPE_MESH_POINT: {
3598 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3600 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3603 /* changes into another band are not supported */
3604 if (sdata->vif.bss_conf.chandef.chan->band !=
3605 params->chandef.chan->band)
3608 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3609 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3610 if (!ifmsh->pre_value)
3611 ifmsh->pre_value = 1;
3616 /* see comments in the NL80211_IFTYPE_AP block */
3617 if (params->count > 1) {
3618 err = ieee80211_mesh_csa_beacon(sdata, params);
3620 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3626 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3627 ieee80211_send_action_csa(sdata, params);
3639 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3641 sdata->vif.bss_conf.color_change_active = false;
3643 ieee80211_free_next_beacon(&sdata->deflink);
3645 cfg80211_color_change_aborted_notify(sdata->dev);
3649 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3650 struct cfg80211_csa_settings *params)
3652 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3653 struct ieee80211_local *local = sdata->local;
3654 struct ieee80211_channel_switch ch_switch;
3655 struct ieee80211_chanctx_conf *conf;
3656 struct ieee80211_chanctx *chanctx;
3660 sdata_assert_lock(sdata);
3661 lockdep_assert_held(&local->mtx);
3663 if (!list_empty(&local->roc_list) || local->scanning)
3666 if (sdata->wdev.cac_started)
3669 if (cfg80211_chandef_identical(¶ms->chandef,
3670 &sdata->vif.bss_conf.chandef))
3673 /* don't allow another channel switch if one is already active. */
3674 if (sdata->vif.bss_conf.csa_active)
3677 mutex_lock(&local->chanctx_mtx);
3678 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
3679 lockdep_is_held(&local->chanctx_mtx));
3685 if (params->chandef.chan->freq_offset) {
3686 /* this may work, but is untested */
3691 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3693 ch_switch.timestamp = 0;
3694 ch_switch.device_timestamp = 0;
3695 ch_switch.block_tx = params->block_tx;
3696 ch_switch.chandef = params->chandef;
3697 ch_switch.count = params->count;
3699 err = drv_pre_channel_switch(sdata, &ch_switch);
3703 err = ieee80211_link_reserve_chanctx(&sdata->deflink, ¶ms->chandef,
3705 params->radar_required);
3709 /* if reservation is invalid then this will fail */
3710 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3712 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3716 /* if there is a color change in progress, abort it */
3717 if (sdata->vif.bss_conf.color_change_active)
3718 ieee80211_color_change_abort(sdata);
3720 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3722 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3726 sdata->deflink.csa_chandef = params->chandef;
3727 sdata->deflink.csa_block_tx = params->block_tx;
3728 sdata->vif.bss_conf.csa_active = true;
3730 if (sdata->deflink.csa_block_tx)
3731 ieee80211_stop_vif_queues(local, sdata,
3732 IEEE80211_QUEUE_STOP_REASON_CSA);
3734 cfg80211_ch_switch_started_notify(sdata->dev,
3735 &sdata->deflink.csa_chandef,
3736 params->count, params->block_tx);
3739 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3741 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3743 /* if the beacon didn't change, we can finalize immediately */
3744 ieee80211_csa_finalize(sdata);
3748 mutex_unlock(&local->chanctx_mtx);
3752 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3753 struct cfg80211_csa_settings *params)
3755 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3756 struct ieee80211_local *local = sdata->local;
3759 mutex_lock(&local->mtx);
3760 err = __ieee80211_channel_switch(wiphy, dev, params);
3761 mutex_unlock(&local->mtx);
3766 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3768 lockdep_assert_held(&local->mtx);
3770 local->roc_cookie_counter++;
3772 /* wow, you wrapped 64 bits ... more likely a bug */
3773 if (WARN_ON(local->roc_cookie_counter == 0))
3774 local->roc_cookie_counter++;
3776 return local->roc_cookie_counter;
3779 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3780 u64 *cookie, gfp_t gfp)
3782 unsigned long spin_flags;
3783 struct sk_buff *ack_skb;
3786 ack_skb = skb_copy(skb, gfp);
3790 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3791 id = idr_alloc(&local->ack_status_frames, ack_skb,
3792 1, 0x2000, GFP_ATOMIC);
3793 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3800 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3802 *cookie = ieee80211_mgmt_tx_cookie(local);
3803 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3809 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3810 struct wireless_dev *wdev,
3811 struct mgmt_frame_regs *upd)
3813 struct ieee80211_local *local = wiphy_priv(wiphy);
3814 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3815 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3816 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3817 bool global_change, intf_change;
3820 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3821 (local->rx_mcast_action_reg !=
3822 !!(upd->global_mcast_stypes & action_mask));
3823 local->probe_req_reg = upd->global_stypes & preq_mask;
3824 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3826 intf_change = (sdata->vif.probe_req_reg !=
3827 !!(upd->interface_stypes & preq_mask)) ||
3828 (sdata->vif.rx_mcast_action_reg !=
3829 !!(upd->interface_mcast_stypes & action_mask));
3830 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3831 sdata->vif.rx_mcast_action_reg =
3832 upd->interface_mcast_stypes & action_mask;
3834 if (!local->open_count)
3837 if (intf_change && ieee80211_sdata_running(sdata))
3838 drv_config_iface_filter(local, sdata,
3839 sdata->vif.probe_req_reg ?
3844 ieee80211_configure_filter(local);
3847 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3849 struct ieee80211_local *local = wiphy_priv(wiphy);
3854 return drv_set_antenna(local, tx_ant, rx_ant);
3857 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3859 struct ieee80211_local *local = wiphy_priv(wiphy);
3861 return drv_get_antenna(local, tx_ant, rx_ant);
3864 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3865 struct net_device *dev,
3866 struct cfg80211_gtk_rekey_data *data)
3868 struct ieee80211_local *local = wiphy_priv(wiphy);
3869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3871 if (!local->ops->set_rekey_data)
3874 drv_set_rekey_data(local, sdata, data);
3879 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3880 const u8 *peer, u64 *cookie)
3882 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3883 struct ieee80211_local *local = sdata->local;
3884 struct ieee80211_qos_hdr *nullfunc;
3885 struct sk_buff *skb;
3886 int size = sizeof(*nullfunc);
3889 struct ieee80211_tx_info *info;
3890 struct sta_info *sta;
3891 struct ieee80211_chanctx_conf *chanctx_conf;
3892 enum nl80211_band band;
3895 /* the lock is needed to assign the cookie later */
3896 mutex_lock(&local->mtx);
3899 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3900 if (WARN_ON(!chanctx_conf)) {
3904 band = chanctx_conf->def.chan->band;
3905 sta = sta_info_get_bss(sdata, peer);
3914 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3915 IEEE80211_STYPE_QOS_NULLFUNC |
3916 IEEE80211_FCTL_FROMDS);
3919 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3920 IEEE80211_STYPE_NULLFUNC |
3921 IEEE80211_FCTL_FROMDS);
3924 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3932 skb_reserve(skb, local->hw.extra_tx_headroom);
3934 nullfunc = skb_put(skb, size);
3935 nullfunc->frame_control = fc;
3936 nullfunc->duration_id = 0;
3937 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3938 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3939 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3940 nullfunc->seq_ctrl = 0;
3942 info = IEEE80211_SKB_CB(skb);
3944 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3945 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3948 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3951 nullfunc->qos_ctrl = cpu_to_le16(7);
3953 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3960 ieee80211_xmit(sdata, sta, skb);
3966 mutex_unlock(&local->mtx);
3971 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3972 struct wireless_dev *wdev,
3973 unsigned int link_id,
3974 struct cfg80211_chan_def *chandef)
3976 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3977 struct ieee80211_local *local = wiphy_priv(wiphy);
3978 struct ieee80211_chanctx_conf *chanctx_conf;
3979 struct ieee80211_link_data *link;
3983 link = rcu_dereference(sdata->link[link_id]);
3989 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
3991 *chandef = link->conf->chandef;
3993 } else if (local->open_count > 0 &&
3994 local->open_count == local->monitors &&
3995 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3996 if (local->use_chanctx)
3997 *chandef = local->monitor_chandef;
3999 *chandef = local->_oper_chandef;
4009 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4011 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4015 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4016 struct net_device *dev,
4017 struct cfg80211_qos_map *qos_map)
4019 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4020 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4023 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4026 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4028 /* A NULL qos_map was passed to disable QoS mapping */
4032 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4033 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4035 kfree_rcu(old_qos_map, rcu_head);
4040 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4041 struct net_device *dev,
4042 unsigned int link_id,
4043 struct cfg80211_chan_def *chandef)
4045 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4046 struct ieee80211_link_data *link;
4050 link = sdata_dereference(sdata->link[link_id], sdata);
4052 ret = ieee80211_link_change_bandwidth(link, chandef, &changed);
4054 ieee80211_link_info_change_notify(sdata, link, changed);
4059 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4060 u8 tsid, const u8 *peer, u8 up,
4063 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4064 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4065 int ac = ieee802_1d_to_ac[up];
4067 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4070 if (!(sdata->wmm_acm & BIT(up)))
4073 if (ifmgd->tx_tspec[ac].admitted_time)
4076 if (admitted_time) {
4077 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4078 ifmgd->tx_tspec[ac].tsid = tsid;
4079 ifmgd->tx_tspec[ac].up = up;
4085 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4086 u8 tsid, const u8 *peer)
4088 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4089 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4090 struct ieee80211_local *local = wiphy_priv(wiphy);
4093 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4094 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4096 /* skip unused entries */
4097 if (!tx_tspec->admitted_time)
4100 if (tx_tspec->tsid != tsid)
4103 /* due to this new packets will be reassigned to non-ACM ACs */
4106 /* Make sure that all packets have been sent to avoid to
4107 * restore the QoS params on packets that are still on the
4111 ieee80211_flush_queues(local, sdata, false);
4113 /* restore the normal QoS parameters
4114 * (unconditionally to avoid races)
4116 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4117 tx_tspec->downgraded = false;
4118 ieee80211_sta_handle_tspec_ac_params(sdata);
4120 /* finally clear all the data */
4121 memset(tx_tspec, 0, sizeof(*tx_tspec));
4129 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4131 enum nl80211_nan_func_term_reason reason,
4134 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4135 struct cfg80211_nan_func *func;
4138 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4141 spin_lock_bh(&sdata->u.nan.func_lock);
4143 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4144 if (WARN_ON(!func)) {
4145 spin_unlock_bh(&sdata->u.nan.func_lock);
4149 cookie = func->cookie;
4150 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4152 spin_unlock_bh(&sdata->u.nan.func_lock);
4154 cfg80211_free_nan_func(func);
4156 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4157 reason, cookie, gfp);
4159 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4161 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4162 struct cfg80211_nan_match_params *match,
4165 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4166 struct cfg80211_nan_func *func;
4168 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4171 spin_lock_bh(&sdata->u.nan.func_lock);
4173 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4174 if (WARN_ON(!func)) {
4175 spin_unlock_bh(&sdata->u.nan.func_lock);
4178 match->cookie = func->cookie;
4180 spin_unlock_bh(&sdata->u.nan.func_lock);
4182 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4184 EXPORT_SYMBOL(ieee80211_nan_func_match);
4186 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4187 struct net_device *dev,
4190 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4192 sdata->u.ap.multicast_to_unicast = enabled;
4197 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4198 struct txq_info *txqi)
4200 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4201 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4202 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4205 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4206 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4207 txqstats->backlog_packets = txqi->tin.backlog_packets;
4210 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4211 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4212 txqstats->flows = txqi->tin.flows;
4215 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4216 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4217 txqstats->drops = txqi->cstats.drop_count;
4220 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4221 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4222 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4225 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4226 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4227 txqstats->overlimit = txqi->tin.overlimit;
4230 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4231 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4232 txqstats->collisions = txqi->tin.collisions;
4235 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4236 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4237 txqstats->tx_bytes = txqi->tin.tx_bytes;
4240 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4241 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4242 txqstats->tx_packets = txqi->tin.tx_packets;
4246 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4247 struct wireless_dev *wdev,
4248 struct cfg80211_txq_stats *txqstats)
4250 struct ieee80211_local *local = wiphy_priv(wiphy);
4251 struct ieee80211_sub_if_data *sdata;
4254 if (!local->ops->wake_tx_queue)
4257 spin_lock_bh(&local->fq.lock);
4261 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4262 if (!sdata->vif.txq) {
4266 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4269 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4270 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4271 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4272 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4273 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4274 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4275 txqstats->backlog_packets = local->fq.backlog;
4276 txqstats->backlog_bytes = local->fq.memory_usage;
4277 txqstats->overlimit = local->fq.overlimit;
4278 txqstats->overmemory = local->fq.overmemory;
4279 txqstats->collisions = local->fq.collisions;
4280 txqstats->max_flows = local->fq.flows_cnt;
4285 spin_unlock_bh(&local->fq.lock);
4291 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4292 struct net_device *dev,
4293 struct cfg80211_ftm_responder_stats *ftm_stats)
4295 struct ieee80211_local *local = wiphy_priv(wiphy);
4296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4298 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4302 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4303 struct cfg80211_pmsr_request *request)
4305 struct ieee80211_local *local = wiphy_priv(wiphy);
4306 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4308 return drv_start_pmsr(local, sdata, request);
4312 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4313 struct cfg80211_pmsr_request *request)
4315 struct ieee80211_local *local = wiphy_priv(wiphy);
4316 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4318 return drv_abort_pmsr(local, sdata, request);
4321 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4322 struct net_device *dev,
4323 struct cfg80211_tid_config *tid_conf)
4325 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4326 struct sta_info *sta;
4329 if (!sdata->local->ops->set_tid_config)
4332 if (!tid_conf->peer)
4333 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4335 mutex_lock(&sdata->local->sta_mtx);
4336 sta = sta_info_get_bss(sdata, tid_conf->peer);
4338 mutex_unlock(&sdata->local->sta_mtx);
4342 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4343 mutex_unlock(&sdata->local->sta_mtx);
4348 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4349 struct net_device *dev,
4350 const u8 *peer, u8 tids)
4352 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4353 struct sta_info *sta;
4356 if (!sdata->local->ops->reset_tid_config)
4360 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4362 mutex_lock(&sdata->local->sta_mtx);
4363 sta = sta_info_get_bss(sdata, peer);
4365 mutex_unlock(&sdata->local->sta_mtx);
4369 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4370 mutex_unlock(&sdata->local->sta_mtx);
4375 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4376 struct cfg80211_sar_specs *sar)
4378 struct ieee80211_local *local = wiphy_priv(wiphy);
4380 if (!local->ops->set_sar_specs)
4383 return local->ops->set_sar_specs(&local->hw, sar);
4387 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4390 switch (sdata->vif.type) {
4391 case NL80211_IFTYPE_AP: {
4394 if (!sdata->deflink.u.ap.next_beacon)
4397 ret = ieee80211_assign_beacon(sdata, &sdata->deflink,
4398 sdata->deflink.u.ap.next_beacon,
4400 ieee80211_free_next_beacon(&sdata->deflink);
4417 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4418 struct cfg80211_color_change_settings *params,
4421 struct ieee80211_color_change_settings color_change = {};
4424 switch (sdata->vif.type) {
4425 case NL80211_IFTYPE_AP:
4426 sdata->deflink.u.ap.next_beacon =
4427 cfg80211_beacon_dup(¶ms->beacon_next);
4428 if (!sdata->deflink.u.ap.next_beacon)
4431 if (params->count <= 1)
4434 color_change.counter_offset_beacon =
4435 params->counter_offset_beacon;
4436 color_change.counter_offset_presp =
4437 params->counter_offset_presp;
4438 color_change.count = params->count;
4440 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
4441 ¶ms->beacon_color_change,
4442 NULL, &color_change);
4444 ieee80211_free_next_beacon(&sdata->deflink);
4457 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4458 u8 color, int enable, u32 changed)
4460 sdata->vif.bss_conf.he_bss_color.color = color;
4461 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4462 changed |= BSS_CHANGED_HE_BSS_COLOR;
4464 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
4466 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4467 struct ieee80211_sub_if_data *child;
4469 mutex_lock(&sdata->local->iflist_mtx);
4470 list_for_each_entry(child, &sdata->local->interfaces, list) {
4471 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4472 child->vif.bss_conf.he_bss_color.color = color;
4473 child->vif.bss_conf.he_bss_color.enabled = enable;
4474 ieee80211_link_info_change_notify(child,
4476 BSS_CHANGED_HE_BSS_COLOR);
4479 mutex_unlock(&sdata->local->iflist_mtx);
4483 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4485 struct ieee80211_local *local = sdata->local;
4489 sdata_assert_lock(sdata);
4490 lockdep_assert_held(&local->mtx);
4492 sdata->vif.bss_conf.color_change_active = false;
4494 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4496 cfg80211_color_change_aborted_notify(sdata->dev);
4500 ieee80211_color_change_bss_config_notify(sdata,
4501 sdata->vif.bss_conf.color_change_color,
4503 cfg80211_color_change_notify(sdata->dev);
4508 void ieee80211_color_change_finalize_work(struct work_struct *work)
4510 struct ieee80211_sub_if_data *sdata =
4511 container_of(work, struct ieee80211_sub_if_data,
4512 deflink.color_change_finalize_work);
4513 struct ieee80211_local *local = sdata->local;
4516 mutex_lock(&local->mtx);
4518 /* AP might have been stopped while waiting for the lock. */
4519 if (!sdata->vif.bss_conf.color_change_active)
4522 if (!ieee80211_sdata_running(sdata))
4525 ieee80211_color_change_finalize(sdata);
4528 mutex_unlock(&local->mtx);
4529 sdata_unlock(sdata);
4532 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4534 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4536 ieee80211_queue_work(&sdata->local->hw,
4537 &sdata->deflink.color_change_finalize_work);
4539 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4542 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4543 u64 color_bitmap, gfp_t gfp)
4545 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4547 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
4550 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
4552 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4555 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4556 struct cfg80211_color_change_settings *params)
4558 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4559 struct ieee80211_local *local = sdata->local;
4563 sdata_assert_lock(sdata);
4565 if (sdata->vif.bss_conf.nontransmitted)
4568 mutex_lock(&local->mtx);
4570 /* don't allow another color change if one is already active or if csa
4573 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
4578 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4582 sdata->vif.bss_conf.color_change_active = true;
4583 sdata->vif.bss_conf.color_change_color = params->color;
4585 cfg80211_color_change_started_notify(sdata->dev, params->count);
4588 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4590 /* if the beacon didn't change, we can finalize immediately */
4591 ieee80211_color_change_finalize(sdata);
4594 mutex_unlock(&local->mtx);
4600 ieee80211_set_radar_background(struct wiphy *wiphy,
4601 struct cfg80211_chan_def *chandef)
4603 struct ieee80211_local *local = wiphy_priv(wiphy);
4605 if (!local->ops->set_radar_background)
4608 return local->ops->set_radar_background(&local->hw, chandef);
4611 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4612 struct wireless_dev *wdev,
4613 unsigned int link_id)
4615 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4617 return ieee80211_vif_set_links(sdata, wdev->valid_links);
4620 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4621 struct wireless_dev *wdev,
4622 unsigned int link_id)
4624 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4626 ieee80211_vif_set_links(sdata, wdev->valid_links);
4629 static int sta_add_link_station(struct ieee80211_local *local,
4630 struct ieee80211_sub_if_data *sdata,
4631 struct link_station_parameters *params)
4633 struct sta_info *sta;
4636 sta = sta_info_get_bss(sdata, params->mld_mac);
4640 if (!sta->sta.valid_links)
4643 if (sta->sta.valid_links & BIT(params->link_id))
4646 ret = ieee80211_sta_allocate_link(sta, params->link_id);
4650 ret = sta_link_apply_parameters(local, sta, true, params);
4652 ieee80211_sta_free_link(sta, params->link_id);
4656 /* ieee80211_sta_activate_link frees the link upon failure */
4657 return ieee80211_sta_activate_link(sta, params->link_id);
4661 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
4662 struct link_station_parameters *params)
4664 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4665 struct ieee80211_local *local = wiphy_priv(wiphy);
4668 mutex_lock(&sdata->local->sta_mtx);
4669 ret = sta_add_link_station(local, sdata, params);
4670 mutex_unlock(&sdata->local->sta_mtx);
4675 static int sta_mod_link_station(struct ieee80211_local *local,
4676 struct ieee80211_sub_if_data *sdata,
4677 struct link_station_parameters *params)
4679 struct sta_info *sta;
4681 sta = sta_info_get_bss(sdata, params->mld_mac);
4685 if (!(sta->sta.valid_links & BIT(params->link_id)))
4688 return sta_link_apply_parameters(local, sta, false, params);
4692 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
4693 struct link_station_parameters *params)
4695 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4696 struct ieee80211_local *local = wiphy_priv(wiphy);
4699 mutex_lock(&sdata->local->sta_mtx);
4700 ret = sta_mod_link_station(local, sdata, params);
4701 mutex_unlock(&sdata->local->sta_mtx);
4706 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
4707 struct link_station_del_parameters *params)
4709 struct sta_info *sta;
4711 sta = sta_info_get_bss(sdata, params->mld_mac);
4715 if (!(sta->sta.valid_links & BIT(params->link_id)))
4718 /* must not create a STA without links */
4719 if (sta->sta.valid_links == BIT(params->link_id))
4722 ieee80211_sta_remove_link(sta, params->link_id);
4728 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
4729 struct link_station_del_parameters *params)
4731 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4734 mutex_lock(&sdata->local->sta_mtx);
4735 ret = sta_del_link_station(sdata, params);
4736 mutex_unlock(&sdata->local->sta_mtx);
4741 const struct cfg80211_ops mac80211_config_ops = {
4742 .add_virtual_intf = ieee80211_add_iface,
4743 .del_virtual_intf = ieee80211_del_iface,
4744 .change_virtual_intf = ieee80211_change_iface,
4745 .start_p2p_device = ieee80211_start_p2p_device,
4746 .stop_p2p_device = ieee80211_stop_p2p_device,
4747 .add_key = ieee80211_add_key,
4748 .del_key = ieee80211_del_key,
4749 .get_key = ieee80211_get_key,
4750 .set_default_key = ieee80211_config_default_key,
4751 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4752 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4753 .start_ap = ieee80211_start_ap,
4754 .change_beacon = ieee80211_change_beacon,
4755 .stop_ap = ieee80211_stop_ap,
4756 .add_station = ieee80211_add_station,
4757 .del_station = ieee80211_del_station,
4758 .change_station = ieee80211_change_station,
4759 .get_station = ieee80211_get_station,
4760 .dump_station = ieee80211_dump_station,
4761 .dump_survey = ieee80211_dump_survey,
4762 #ifdef CONFIG_MAC80211_MESH
4763 .add_mpath = ieee80211_add_mpath,
4764 .del_mpath = ieee80211_del_mpath,
4765 .change_mpath = ieee80211_change_mpath,
4766 .get_mpath = ieee80211_get_mpath,
4767 .dump_mpath = ieee80211_dump_mpath,
4768 .get_mpp = ieee80211_get_mpp,
4769 .dump_mpp = ieee80211_dump_mpp,
4770 .update_mesh_config = ieee80211_update_mesh_config,
4771 .get_mesh_config = ieee80211_get_mesh_config,
4772 .join_mesh = ieee80211_join_mesh,
4773 .leave_mesh = ieee80211_leave_mesh,
4775 .join_ocb = ieee80211_join_ocb,
4776 .leave_ocb = ieee80211_leave_ocb,
4777 .change_bss = ieee80211_change_bss,
4778 .set_txq_params = ieee80211_set_txq_params,
4779 .set_monitor_channel = ieee80211_set_monitor_channel,
4780 .suspend = ieee80211_suspend,
4781 .resume = ieee80211_resume,
4782 .scan = ieee80211_scan,
4783 .abort_scan = ieee80211_abort_scan,
4784 .sched_scan_start = ieee80211_sched_scan_start,
4785 .sched_scan_stop = ieee80211_sched_scan_stop,
4786 .auth = ieee80211_auth,
4787 .assoc = ieee80211_assoc,
4788 .deauth = ieee80211_deauth,
4789 .disassoc = ieee80211_disassoc,
4790 .join_ibss = ieee80211_join_ibss,
4791 .leave_ibss = ieee80211_leave_ibss,
4792 .set_mcast_rate = ieee80211_set_mcast_rate,
4793 .set_wiphy_params = ieee80211_set_wiphy_params,
4794 .set_tx_power = ieee80211_set_tx_power,
4795 .get_tx_power = ieee80211_get_tx_power,
4796 .rfkill_poll = ieee80211_rfkill_poll,
4797 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4798 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4799 .set_power_mgmt = ieee80211_set_power_mgmt,
4800 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4801 .remain_on_channel = ieee80211_remain_on_channel,
4802 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4803 .mgmt_tx = ieee80211_mgmt_tx,
4804 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4805 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4806 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4807 .update_mgmt_frame_registrations =
4808 ieee80211_update_mgmt_frame_registrations,
4809 .set_antenna = ieee80211_set_antenna,
4810 .get_antenna = ieee80211_get_antenna,
4811 .set_rekey_data = ieee80211_set_rekey_data,
4812 .tdls_oper = ieee80211_tdls_oper,
4813 .tdls_mgmt = ieee80211_tdls_mgmt,
4814 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4815 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4816 .probe_client = ieee80211_probe_client,
4817 .set_noack_map = ieee80211_set_noack_map,
4819 .set_wakeup = ieee80211_set_wakeup,
4821 .get_channel = ieee80211_cfg_get_channel,
4822 .start_radar_detection = ieee80211_start_radar_detection,
4823 .end_cac = ieee80211_end_cac,
4824 .channel_switch = ieee80211_channel_switch,
4825 .set_qos_map = ieee80211_set_qos_map,
4826 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4827 .add_tx_ts = ieee80211_add_tx_ts,
4828 .del_tx_ts = ieee80211_del_tx_ts,
4829 .start_nan = ieee80211_start_nan,
4830 .stop_nan = ieee80211_stop_nan,
4831 .nan_change_conf = ieee80211_nan_change_conf,
4832 .add_nan_func = ieee80211_add_nan_func,
4833 .del_nan_func = ieee80211_del_nan_func,
4834 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4835 .tx_control_port = ieee80211_tx_control_port,
4836 .get_txq_stats = ieee80211_get_txq_stats,
4837 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4838 .start_pmsr = ieee80211_start_pmsr,
4839 .abort_pmsr = ieee80211_abort_pmsr,
4840 .probe_mesh_link = ieee80211_probe_mesh_link,
4841 .set_tid_config = ieee80211_set_tid_config,
4842 .reset_tid_config = ieee80211_reset_tid_config,
4843 .set_sar_specs = ieee80211_set_sar_specs,
4844 .color_change = ieee80211_color_change,
4845 .set_radar_background = ieee80211_set_radar_background,
4846 .add_intf_link = ieee80211_add_intf_link,
4847 .del_intf_link = ieee80211_del_intf_link,
4848 .add_link_station = ieee80211_add_link_station,
4849 .mod_link_station = ieee80211_mod_link_station,
4850 .del_link_station = ieee80211_del_link_station,