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 struct ieee80211_link_data *
27 ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id,
30 struct ieee80211_link_data *link;
34 * For keys, if sdata is not an MLD, we might not use
35 * the return value at all (if it's not a pairwise key),
36 * so in that case (require_valid==false) don't error.
38 if (require_valid && sdata->vif.valid_links)
39 return ERR_PTR(-EINVAL);
41 return &sdata->deflink;
44 link = sdata_dereference(sdata->link[link_id], sdata);
46 return ERR_PTR(-ENOLINK);
50 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
51 struct vif_params *params)
53 bool mu_mimo_groups = false;
54 bool mu_mimo_follow = false;
56 if (params->vht_mumimo_groups) {
59 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
61 memcpy(sdata->vif.bss_conf.mu_group.membership,
62 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
63 memcpy(sdata->vif.bss_conf.mu_group.position,
64 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
65 WLAN_USER_POSITION_LEN);
66 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
67 BSS_CHANGED_MU_GROUPS);
68 /* don't care about endianness - just check for 0 */
69 memcpy(&membership, params->vht_mumimo_groups,
71 mu_mimo_groups = membership != 0;
74 if (params->vht_mumimo_follow_addr) {
76 is_valid_ether_addr(params->vht_mumimo_follow_addr);
77 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
78 params->vht_mumimo_follow_addr);
81 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
84 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
85 struct vif_params *params)
87 struct ieee80211_local *local = sdata->local;
88 struct ieee80211_sub_if_data *monitor_sdata;
90 /* check flags first */
91 if (params->flags && ieee80211_sdata_running(sdata)) {
92 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
95 * Prohibit MONITOR_FLAG_COOK_FRAMES and
96 * MONITOR_FLAG_ACTIVE to be changed while the
98 * Else we would need to add a lot of cruft
99 * to update everything:
100 * cooked_mntrs, monitor and all fif_* counters
101 * reconfigure hardware
103 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
107 /* also validate MU-MIMO change */
108 monitor_sdata = wiphy_dereference(local->hw.wiphy,
109 local->monitor_sdata);
111 if (!monitor_sdata &&
112 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
115 /* apply all changes now - no failures allowed */
118 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
121 if (ieee80211_sdata_running(sdata)) {
122 ieee80211_adjust_monitor_flags(sdata, -1);
123 sdata->u.mntr.flags = params->flags;
124 ieee80211_adjust_monitor_flags(sdata, 1);
126 ieee80211_configure_filter(local);
129 * Because the interface is down, ieee80211_do_stop
130 * and ieee80211_do_open take care of "everything"
131 * mentioned in the comment above.
133 sdata->u.mntr.flags = params->flags;
140 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
141 struct cfg80211_mbssid_config params,
142 struct ieee80211_bss_conf *link_conf)
144 struct ieee80211_sub_if_data *tx_sdata;
146 sdata->vif.mbssid_tx_vif = NULL;
147 link_conf->bssid_index = 0;
148 link_conf->nontransmitted = false;
149 link_conf->ema_ap = false;
151 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
154 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
158 if (tx_sdata == sdata) {
159 sdata->vif.mbssid_tx_vif = &sdata->vif;
161 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
162 link_conf->nontransmitted = true;
163 link_conf->bssid_index = params.index;
166 link_conf->ema_ap = true;
171 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
173 unsigned char name_assign_type,
174 enum nl80211_iftype type,
175 struct vif_params *params)
177 struct ieee80211_local *local = wiphy_priv(wiphy);
178 struct wireless_dev *wdev;
179 struct ieee80211_sub_if_data *sdata;
182 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
186 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
188 if (type == NL80211_IFTYPE_MONITOR) {
189 err = ieee80211_set_mon_options(sdata, params);
191 ieee80211_if_remove(sdata);
199 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
201 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
206 static int ieee80211_change_iface(struct wiphy *wiphy,
207 struct net_device *dev,
208 enum nl80211_iftype type,
209 struct vif_params *params)
211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
212 struct ieee80211_local *local = sdata->local;
213 struct sta_info *sta;
216 ret = ieee80211_if_change_type(sdata, type);
220 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
221 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
222 ieee80211_check_fast_rx_iface(sdata);
223 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
224 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
226 if (params->use_4addr == ifmgd->use_4addr)
229 /* FIXME: no support for 4-addr MLO yet */
230 if (sdata->vif.valid_links)
233 sdata->u.mgd.use_4addr = params->use_4addr;
234 if (!ifmgd->associated)
237 mutex_lock(&local->sta_mtx);
238 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
240 drv_sta_set_4addr(local, sdata, &sta->sta,
242 mutex_unlock(&local->sta_mtx);
244 if (params->use_4addr)
245 ieee80211_send_4addr_nullfunc(local, sdata);
248 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
249 ret = ieee80211_set_mon_options(sdata, params);
257 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
258 struct wireless_dev *wdev)
260 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
263 mutex_lock(&sdata->local->chanctx_mtx);
264 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
265 mutex_unlock(&sdata->local->chanctx_mtx);
269 return ieee80211_do_open(wdev, true);
272 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
273 struct wireless_dev *wdev)
275 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
278 static int ieee80211_start_nan(struct wiphy *wiphy,
279 struct wireless_dev *wdev,
280 struct cfg80211_nan_conf *conf)
282 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
285 mutex_lock(&sdata->local->chanctx_mtx);
286 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
287 mutex_unlock(&sdata->local->chanctx_mtx);
291 ret = ieee80211_do_open(wdev, true);
295 ret = drv_start_nan(sdata->local, sdata, conf);
297 ieee80211_sdata_stop(sdata);
299 sdata->u.nan.conf = *conf;
304 static void ieee80211_stop_nan(struct wiphy *wiphy,
305 struct wireless_dev *wdev)
307 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
309 drv_stop_nan(sdata->local, sdata);
310 ieee80211_sdata_stop(sdata);
313 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
314 struct wireless_dev *wdev,
315 struct cfg80211_nan_conf *conf,
318 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
319 struct cfg80211_nan_conf new_conf;
322 if (sdata->vif.type != NL80211_IFTYPE_NAN)
325 if (!ieee80211_sdata_running(sdata))
328 new_conf = sdata->u.nan.conf;
330 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
331 new_conf.master_pref = conf->master_pref;
333 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
334 new_conf.bands = conf->bands;
336 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
338 sdata->u.nan.conf = new_conf;
343 static int ieee80211_add_nan_func(struct wiphy *wiphy,
344 struct wireless_dev *wdev,
345 struct cfg80211_nan_func *nan_func)
347 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
350 if (sdata->vif.type != NL80211_IFTYPE_NAN)
353 if (!ieee80211_sdata_running(sdata))
356 spin_lock_bh(&sdata->u.nan.func_lock);
358 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
359 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
361 spin_unlock_bh(&sdata->u.nan.func_lock);
366 nan_func->instance_id = ret;
368 WARN_ON(nan_func->instance_id == 0);
370 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
372 spin_lock_bh(&sdata->u.nan.func_lock);
373 idr_remove(&sdata->u.nan.function_inst_ids,
374 nan_func->instance_id);
375 spin_unlock_bh(&sdata->u.nan.func_lock);
381 static struct cfg80211_nan_func *
382 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
385 struct cfg80211_nan_func *func;
388 lockdep_assert_held(&sdata->u.nan.func_lock);
390 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
391 if (func->cookie == cookie)
398 static void ieee80211_del_nan_func(struct wiphy *wiphy,
399 struct wireless_dev *wdev, u64 cookie)
401 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
402 struct cfg80211_nan_func *func;
405 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
406 !ieee80211_sdata_running(sdata))
409 spin_lock_bh(&sdata->u.nan.func_lock);
411 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
413 instance_id = func->instance_id;
415 spin_unlock_bh(&sdata->u.nan.func_lock);
418 drv_del_nan_func(sdata->local, sdata, instance_id);
421 static int ieee80211_set_noack_map(struct wiphy *wiphy,
422 struct net_device *dev,
425 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
427 sdata->noack_map = noack_map;
429 ieee80211_check_fast_xmit_iface(sdata);
434 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
435 const u8 *mac_addr, u8 key_idx)
437 struct ieee80211_local *local = sdata->local;
438 struct ieee80211_key *key;
439 struct sta_info *sta;
442 if (!wiphy_ext_feature_isset(local->hw.wiphy,
443 NL80211_EXT_FEATURE_EXT_KEY_ID))
446 sta = sta_info_get_bss(sdata, mac_addr);
451 if (sta->ptk_idx == key_idx)
454 mutex_lock(&local->key_mtx);
455 key = key_mtx_dereference(local, sta->ptk[key_idx]);
457 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
458 ret = ieee80211_set_tx_key(key);
460 mutex_unlock(&local->key_mtx);
464 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
465 int link_id, u8 key_idx, bool pairwise,
466 const u8 *mac_addr, struct key_params *params)
468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
469 struct ieee80211_link_data *link =
470 ieee80211_link_or_deflink(sdata, link_id, false);
471 struct ieee80211_local *local = sdata->local;
472 struct sta_info *sta = NULL;
473 struct ieee80211_key *key;
476 if (!ieee80211_sdata_running(sdata))
480 return PTR_ERR(link);
482 if (pairwise && params->mode == NL80211_KEY_SET_TX)
483 return ieee80211_set_tx(sdata, mac_addr, key_idx);
485 /* reject WEP and TKIP keys if WEP failed to initialize */
486 switch (params->cipher) {
487 case WLAN_CIPHER_SUITE_WEP40:
488 case WLAN_CIPHER_SUITE_TKIP:
489 case WLAN_CIPHER_SUITE_WEP104:
492 if (WARN_ON_ONCE(fips_enabled))
499 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
500 params->key, params->seq_len, params->seq);
504 key->conf.link_id = link_id;
507 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
509 if (params->mode == NL80211_KEY_NO_TX)
510 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
512 mutex_lock(&local->sta_mtx);
515 sta = sta_info_get_bss(sdata, mac_addr);
517 * The ASSOC test makes sure the driver is ready to
518 * receive the key. When wpa_supplicant has roamed
519 * using FT, it attempts to set the key before
520 * association has completed, this rejects that attempt
521 * so it will set the key again after association.
523 * TODO: accept the key if we have a station entry and
524 * add it to the device after the station.
526 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
527 ieee80211_key_free_unused(key);
533 switch (sdata->vif.type) {
534 case NL80211_IFTYPE_STATION:
535 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
536 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
538 case NL80211_IFTYPE_AP:
539 case NL80211_IFTYPE_AP_VLAN:
540 /* Keys without a station are used for TX only */
541 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
542 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
544 case NL80211_IFTYPE_ADHOC:
547 case NL80211_IFTYPE_MESH_POINT:
548 #ifdef CONFIG_MAC80211_MESH
549 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
550 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
553 case NL80211_IFTYPE_WDS:
554 case NL80211_IFTYPE_MONITOR:
555 case NL80211_IFTYPE_P2P_DEVICE:
556 case NL80211_IFTYPE_NAN:
557 case NL80211_IFTYPE_UNSPECIFIED:
558 case NUM_NL80211_IFTYPES:
559 case NL80211_IFTYPE_P2P_CLIENT:
560 case NL80211_IFTYPE_P2P_GO:
561 case NL80211_IFTYPE_OCB:
562 /* shouldn't happen */
567 err = ieee80211_key_link(key, link, sta);
570 mutex_unlock(&local->sta_mtx);
575 static struct ieee80211_key *
576 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
577 u8 key_idx, bool pairwise, const u8 *mac_addr)
579 struct ieee80211_local *local = sdata->local;
580 struct ieee80211_link_data *link = &sdata->deflink;
581 struct ieee80211_key *key;
584 link = rcu_dereference_check(sdata->link[link_id],
585 lockdep_is_held(&sdata->wdev.mtx));
591 struct sta_info *sta;
592 struct link_sta_info *link_sta;
594 sta = sta_info_get_bss(sdata, mac_addr);
599 link_sta = rcu_dereference_check(sta->link[link_id],
600 lockdep_is_held(&local->sta_mtx));
604 link_sta = &sta->deflink;
607 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
608 return rcu_dereference_check_key_mtx(local,
612 key_idx < NUM_DEFAULT_KEYS +
613 NUM_DEFAULT_MGMT_KEYS +
614 NUM_DEFAULT_BEACON_KEYS)
615 return rcu_dereference_check_key_mtx(local,
616 link_sta->gtk[key_idx]);
621 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
622 return rcu_dereference_check_key_mtx(local,
623 sdata->keys[key_idx]);
625 key = rcu_dereference_check_key_mtx(local, link->gtk[key_idx]);
629 /* or maybe it was a WEP key */
630 if (key_idx < NUM_DEFAULT_KEYS)
631 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]);
636 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
637 int link_id, u8 key_idx, bool pairwise,
640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
641 struct ieee80211_local *local = sdata->local;
642 struct ieee80211_key *key;
645 mutex_lock(&local->sta_mtx);
646 mutex_lock(&local->key_mtx);
648 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
654 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
658 mutex_unlock(&local->key_mtx);
659 mutex_unlock(&local->sta_mtx);
664 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
665 int link_id, u8 key_idx, bool pairwise,
666 const u8 *mac_addr, void *cookie,
667 void (*callback)(void *cookie,
668 struct key_params *params))
670 struct ieee80211_sub_if_data *sdata;
672 struct key_params params;
673 struct ieee80211_key *key;
678 struct ieee80211_key_seq kseq = {};
680 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
684 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
688 memset(¶ms, 0, sizeof(params));
690 params.cipher = key->conf.cipher;
692 switch (key->conf.cipher) {
693 case WLAN_CIPHER_SUITE_TKIP:
694 pn64 = atomic64_read(&key->conf.tx_pn);
695 iv32 = TKIP_PN_TO_IV32(pn64);
696 iv16 = TKIP_PN_TO_IV16(pn64);
698 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
699 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
700 drv_get_key_seq(sdata->local, key, &kseq);
701 iv32 = kseq.tkip.iv32;
702 iv16 = kseq.tkip.iv16;
705 seq[0] = iv16 & 0xff;
706 seq[1] = (iv16 >> 8) & 0xff;
707 seq[2] = iv32 & 0xff;
708 seq[3] = (iv32 >> 8) & 0xff;
709 seq[4] = (iv32 >> 16) & 0xff;
710 seq[5] = (iv32 >> 24) & 0xff;
714 case WLAN_CIPHER_SUITE_CCMP:
715 case WLAN_CIPHER_SUITE_CCMP_256:
716 case WLAN_CIPHER_SUITE_AES_CMAC:
717 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
718 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
719 offsetof(typeof(kseq), aes_cmac));
721 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
722 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
723 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
724 offsetof(typeof(kseq), aes_gmac));
726 case WLAN_CIPHER_SUITE_GCMP:
727 case WLAN_CIPHER_SUITE_GCMP_256:
728 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
729 offsetof(typeof(kseq), gcmp));
731 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
732 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
733 drv_get_key_seq(sdata->local, key, &kseq);
734 memcpy(seq, kseq.ccmp.pn, 6);
736 pn64 = atomic64_read(&key->conf.tx_pn);
748 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
750 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
752 drv_get_key_seq(sdata->local, key, &kseq);
753 params.seq = kseq.hw.seq;
754 params.seq_len = kseq.hw.seq_len;
758 params.key = key->conf.key;
759 params.key_len = key->conf.keylen;
761 callback(cookie, ¶ms);
769 static int ieee80211_config_default_key(struct wiphy *wiphy,
770 struct net_device *dev,
771 int link_id, u8 key_idx, bool uni,
774 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
775 struct ieee80211_link_data *link =
776 ieee80211_link_or_deflink(sdata, link_id, false);
779 return PTR_ERR(link);
781 ieee80211_set_default_key(link, key_idx, uni, multi);
786 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
787 struct net_device *dev,
788 int link_id, u8 key_idx)
790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
791 struct ieee80211_link_data *link =
792 ieee80211_link_or_deflink(sdata, link_id, true);
795 return PTR_ERR(link);
797 ieee80211_set_default_mgmt_key(link, key_idx);
802 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
803 struct net_device *dev,
804 int link_id, u8 key_idx)
806 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
807 struct ieee80211_link_data *link =
808 ieee80211_link_or_deflink(sdata, link_id, true);
811 return PTR_ERR(link);
813 ieee80211_set_default_beacon_key(link, key_idx);
818 void sta_set_rate_info_tx(struct sta_info *sta,
819 const struct ieee80211_tx_rate *rate,
820 struct rate_info *rinfo)
823 if (rate->flags & IEEE80211_TX_RC_MCS) {
824 rinfo->flags |= RATE_INFO_FLAGS_MCS;
825 rinfo->mcs = rate->idx;
826 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
827 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
828 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
829 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
831 struct ieee80211_supported_band *sband;
832 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
835 sband = ieee80211_get_sband(sta->sdata);
836 WARN_ON_ONCE(sband && !sband->bitrates);
837 if (sband && sband->bitrates) {
838 brate = sband->bitrates[rate->idx].bitrate;
839 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
842 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
843 rinfo->bw = RATE_INFO_BW_40;
844 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
845 rinfo->bw = RATE_INFO_BW_80;
846 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
847 rinfo->bw = RATE_INFO_BW_160;
849 rinfo->bw = RATE_INFO_BW_20;
850 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
851 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
854 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
855 int idx, u8 *mac, struct station_info *sinfo)
857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
858 struct ieee80211_local *local = sdata->local;
859 struct sta_info *sta;
862 mutex_lock(&local->sta_mtx);
864 sta = sta_info_get_by_idx(sdata, idx);
867 memcpy(mac, sta->sta.addr, ETH_ALEN);
868 sta_set_sinfo(sta, sinfo, true);
871 mutex_unlock(&local->sta_mtx);
876 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
877 int idx, struct survey_info *survey)
879 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
881 return drv_get_survey(local, idx, survey);
884 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
885 const u8 *mac, struct station_info *sinfo)
887 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
888 struct ieee80211_local *local = sdata->local;
889 struct sta_info *sta;
892 mutex_lock(&local->sta_mtx);
894 sta = sta_info_get_bss(sdata, mac);
897 sta_set_sinfo(sta, sinfo, true);
900 mutex_unlock(&local->sta_mtx);
905 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
906 struct cfg80211_chan_def *chandef)
908 struct ieee80211_local *local = wiphy_priv(wiphy);
909 struct ieee80211_sub_if_data *sdata;
912 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
915 mutex_lock(&local->mtx);
916 if (local->use_chanctx) {
917 sdata = wiphy_dereference(local->hw.wiphy,
918 local->monitor_sdata);
920 ieee80211_link_release_channel(&sdata->deflink);
921 ret = ieee80211_link_use_channel(&sdata->deflink,
923 IEEE80211_CHANCTX_EXCLUSIVE);
925 } else if (local->open_count == local->monitors) {
926 local->_oper_chandef = *chandef;
927 ieee80211_hw_config(local, 0);
931 local->monitor_chandef = *chandef;
932 mutex_unlock(&local->mtx);
938 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
939 const u8 *resp, size_t resp_len,
940 const struct ieee80211_csa_settings *csa,
941 const struct ieee80211_color_change_settings *cca,
942 struct ieee80211_link_data *link)
944 struct probe_resp *new, *old;
946 if (!resp || !resp_len)
949 old = sdata_dereference(link->u.ap.probe_resp, sdata);
951 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
956 memcpy(new->data, resp, resp_len);
959 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
960 csa->n_counter_offsets_presp *
961 sizeof(new->cntdwn_counter_offsets[0]));
963 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
965 rcu_assign_pointer(link->u.ap.probe_resp, new);
967 kfree_rcu(old, rcu_head);
972 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
973 struct cfg80211_fils_discovery *params,
974 struct ieee80211_link_data *link,
975 struct ieee80211_bss_conf *link_conf)
977 struct fils_discovery_data *new, *old = NULL;
978 struct ieee80211_fils_discovery *fd;
980 if (!params->tmpl || !params->tmpl_len)
983 fd = &link_conf->fils_discovery;
984 fd->min_interval = params->min_interval;
985 fd->max_interval = params->max_interval;
987 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
988 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
991 new->len = params->tmpl_len;
992 memcpy(new->data, params->tmpl, params->tmpl_len);
993 rcu_assign_pointer(link->u.ap.fils_discovery, new);
996 kfree_rcu(old, rcu_head);
1002 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
1003 struct cfg80211_unsol_bcast_probe_resp *params,
1004 struct ieee80211_link_data *link,
1005 struct ieee80211_bss_conf *link_conf)
1007 struct unsol_bcast_probe_resp_data *new, *old = NULL;
1009 if (!params->tmpl || !params->tmpl_len)
1012 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
1013 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1016 new->len = params->tmpl_len;
1017 memcpy(new->data, params->tmpl, params->tmpl_len);
1018 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
1021 kfree_rcu(old, rcu_head);
1023 link_conf->unsol_bcast_probe_resp_interval = params->interval;
1028 static int ieee80211_set_ftm_responder_params(
1029 struct ieee80211_sub_if_data *sdata,
1030 const u8 *lci, size_t lci_len,
1031 const u8 *civicloc, size_t civicloc_len,
1032 struct ieee80211_bss_conf *link_conf)
1034 struct ieee80211_ftm_responder_params *new, *old;
1038 if (!lci_len && !civicloc_len)
1041 old = link_conf->ftmr_params;
1042 len = lci_len + civicloc_len;
1044 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
1048 pos = (u8 *)(new + 1);
1050 new->lci_len = lci_len;
1052 memcpy(pos, lci, lci_len);
1057 new->civicloc_len = civicloc_len;
1058 new->civicloc = pos;
1059 memcpy(pos, civicloc, civicloc_len);
1060 pos += civicloc_len;
1063 link_conf->ftmr_params = new;
1070 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
1071 struct cfg80211_mbssid_elems *src)
1075 for (i = 0; i < src->cnt; i++) {
1076 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1077 dst->elem[i].len = src->elem[i].len;
1078 dst->elem[i].data = pos + offset;
1079 offset += dst->elem[i].len;
1081 dst->cnt = src->cnt;
1086 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1087 struct ieee80211_link_data *link,
1088 struct cfg80211_beacon_data *params,
1089 const struct ieee80211_csa_settings *csa,
1090 const struct ieee80211_color_change_settings *cca)
1092 struct cfg80211_mbssid_elems *mbssid = NULL;
1093 struct beacon_data *new, *old;
1094 int new_head_len, new_tail_len;
1096 u32 changed = BSS_CHANGED_BEACON;
1097 struct ieee80211_bss_conf *link_conf = link->conf;
1099 old = sdata_dereference(link->u.ap.beacon, sdata);
1101 /* Need to have a beacon head if we don't have one yet */
1102 if (!params->head && !old)
1105 /* new or old head? */
1107 new_head_len = params->head_len;
1109 new_head_len = old->head_len;
1111 /* new or old tail? */
1112 if (params->tail || !old)
1113 /* params->tail_len will be zero for !params->tail */
1114 new_tail_len = params->tail_len;
1116 new_tail_len = old->tail_len;
1118 size = sizeof(*new) + new_head_len + new_tail_len;
1120 /* new or old multiple BSSID elements? */
1121 if (params->mbssid_ies) {
1122 mbssid = params->mbssid_ies;
1123 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1124 size += ieee80211_get_mbssid_beacon_len(mbssid);
1125 } else if (old && old->mbssid_ies) {
1126 mbssid = old->mbssid_ies;
1127 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1128 size += ieee80211_get_mbssid_beacon_len(mbssid);
1131 new = kzalloc(size, GFP_KERNEL);
1135 /* start filling the new info now */
1138 * pointers go into the block we allocated,
1139 * memory is | beacon_data | head | tail | mbssid_ies
1141 new->head = ((u8 *) new) + sizeof(*new);
1142 new->tail = new->head + new_head_len;
1143 new->head_len = new_head_len;
1144 new->tail_len = new_tail_len;
1145 /* copy in optional mbssid_ies */
1147 u8 *pos = new->tail + new->tail_len;
1149 new->mbssid_ies = (void *)pos;
1150 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1151 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1152 /* update bssid_indicator */
1153 link_conf->bssid_indicator =
1154 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1158 new->cntdwn_current_counter = csa->count;
1159 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1160 csa->n_counter_offsets_beacon *
1161 sizeof(new->cntdwn_counter_offsets[0]));
1163 new->cntdwn_current_counter = cca->count;
1164 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1169 memcpy(new->head, params->head, new_head_len);
1171 memcpy(new->head, old->head, new_head_len);
1173 /* copy in optional tail */
1175 memcpy(new->tail, params->tail, new_tail_len);
1178 memcpy(new->tail, old->tail, new_tail_len);
1180 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1181 params->probe_resp_len, csa, cca, link);
1187 changed |= BSS_CHANGED_AP_PROBE_RESP;
1189 if (params->ftm_responder != -1) {
1190 link_conf->ftm_responder = params->ftm_responder;
1191 err = ieee80211_set_ftm_responder_params(sdata,
1195 params->civicloc_len,
1203 changed |= BSS_CHANGED_FTM_RESPONDER;
1206 rcu_assign_pointer(link->u.ap.beacon, new);
1207 sdata->u.ap.active = true;
1210 kfree_rcu(old, rcu_head);
1215 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1216 struct cfg80211_ap_settings *params)
1218 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1219 struct ieee80211_local *local = sdata->local;
1220 struct beacon_data *old;
1221 struct ieee80211_sub_if_data *vlan;
1222 u32 changed = BSS_CHANGED_BEACON_INT |
1223 BSS_CHANGED_BEACON_ENABLED |
1224 BSS_CHANGED_BEACON |
1225 BSS_CHANGED_P2P_PS |
1226 BSS_CHANGED_TXPOWER |
1229 int prev_beacon_int;
1230 unsigned int link_id = params->beacon.link_id;
1231 struct ieee80211_link_data *link;
1232 struct ieee80211_bss_conf *link_conf;
1234 link = sdata_dereference(sdata->link[link_id], sdata);
1238 link_conf = link->conf;
1240 old = sdata_dereference(link->u.ap.beacon, sdata);
1244 if (params->smps_mode != NL80211_SMPS_OFF)
1247 link->smps_mode = IEEE80211_SMPS_OFF;
1249 link->needed_rx_chains = sdata->local->rx_chains;
1251 prev_beacon_int = link_conf->beacon_int;
1252 link_conf->beacon_int = params->beacon_interval;
1254 if (params->he_cap && params->he_oper) {
1255 link_conf->he_support = true;
1256 link_conf->htc_trig_based_pkt_ext =
1257 le32_get_bits(params->he_oper->he_oper_params,
1258 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1259 link_conf->frame_time_rts_th =
1260 le32_get_bits(params->he_oper->he_oper_params,
1261 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1262 changed |= BSS_CHANGED_HE_OBSS_PD;
1264 if (params->beacon.he_bss_color.enabled)
1265 changed |= BSS_CHANGED_HE_BSS_COLOR;
1268 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1269 params->mbssid_config.tx_wdev) {
1270 err = ieee80211_set_ap_mbssid_options(sdata,
1271 params->mbssid_config,
1277 mutex_lock(&local->mtx);
1278 err = ieee80211_link_use_channel(link, ¶ms->chandef,
1279 IEEE80211_CHANCTX_SHARED);
1281 ieee80211_link_copy_chanctx_to_vlans(link, false);
1282 mutex_unlock(&local->mtx);
1284 link_conf->beacon_int = prev_beacon_int;
1289 * Apply control port protocol, this allows us to
1290 * not encrypt dynamic WEP control frames.
1292 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1293 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1294 sdata->control_port_over_nl80211 =
1295 params->crypto.control_port_over_nl80211;
1296 sdata->control_port_no_preauth =
1297 params->crypto.control_port_no_preauth;
1299 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1300 vlan->control_port_protocol =
1301 params->crypto.control_port_ethertype;
1302 vlan->control_port_no_encrypt =
1303 params->crypto.control_port_no_encrypt;
1304 vlan->control_port_over_nl80211 =
1305 params->crypto.control_port_over_nl80211;
1306 vlan->control_port_no_preauth =
1307 params->crypto.control_port_no_preauth;
1310 link_conf->dtim_period = params->dtim_period;
1311 link_conf->enable_beacon = true;
1312 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1313 link_conf->twt_responder = params->twt_responder;
1314 link_conf->he_obss_pd = params->he_obss_pd;
1315 link_conf->he_bss_color = params->beacon.he_bss_color;
1316 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1319 sdata->vif.cfg.ssid_len = params->ssid_len;
1320 if (params->ssid_len)
1321 memcpy(sdata->vif.cfg.ssid, params->ssid,
1323 link_conf->hidden_ssid =
1324 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1326 memset(&link_conf->p2p_noa_attr, 0,
1327 sizeof(link_conf->p2p_noa_attr));
1328 link_conf->p2p_noa_attr.oppps_ctwindow =
1329 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1330 if (params->p2p_opp_ps)
1331 link_conf->p2p_noa_attr.oppps_ctwindow |=
1332 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1334 sdata->beacon_rate_set = false;
1335 if (wiphy_ext_feature_isset(local->hw.wiphy,
1336 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1337 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1338 sdata->beacon_rateidx_mask[i] =
1339 params->beacon_rate.control[i].legacy;
1340 if (sdata->beacon_rateidx_mask[i])
1341 sdata->beacon_rate_set = true;
1345 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1346 link_conf->beacon_tx_rate = params->beacon_rate;
1348 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL);
1353 if (params->fils_discovery.max_interval) {
1354 err = ieee80211_set_fils_discovery(sdata,
1355 ¶ms->fils_discovery,
1359 changed |= BSS_CHANGED_FILS_DISCOVERY;
1362 if (params->unsol_bcast_probe_resp.interval) {
1363 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1364 ¶ms->unsol_bcast_probe_resp,
1368 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1371 err = drv_start_ap(sdata->local, sdata, link_conf);
1373 old = sdata_dereference(link->u.ap.beacon, sdata);
1376 kfree_rcu(old, rcu_head);
1377 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1378 sdata->u.ap.active = false;
1382 ieee80211_recalc_dtim(local, sdata);
1383 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1384 ieee80211_link_info_change_notify(sdata, link, changed);
1386 netif_carrier_on(dev);
1387 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1388 netif_carrier_on(vlan->dev);
1393 mutex_lock(&local->mtx);
1394 ieee80211_link_release_channel(link);
1395 mutex_unlock(&local->mtx);
1400 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1401 struct cfg80211_beacon_data *params)
1403 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1404 struct ieee80211_link_data *link;
1405 struct beacon_data *old;
1407 struct ieee80211_bss_conf *link_conf;
1409 sdata_assert_lock(sdata);
1411 link = sdata_dereference(sdata->link[params->link_id], sdata);
1415 link_conf = link->conf;
1417 /* don't allow changing the beacon while a countdown is in place - offset
1418 * of channel switch counter may change
1420 if (link_conf->csa_active || link_conf->color_change_active)
1423 old = sdata_dereference(link->u.ap.beacon, sdata);
1427 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL);
1431 if (params->he_bss_color_valid &&
1432 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1433 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1434 err |= BSS_CHANGED_HE_BSS_COLOR;
1437 ieee80211_link_info_change_notify(sdata, link, err);
1441 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1443 if (!link->u.ap.next_beacon)
1446 kfree(link->u.ap.next_beacon->mbssid_ies);
1447 kfree(link->u.ap.next_beacon);
1448 link->u.ap.next_beacon = NULL;
1451 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1452 unsigned int link_id)
1454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1455 struct ieee80211_sub_if_data *vlan;
1456 struct ieee80211_local *local = sdata->local;
1457 struct beacon_data *old_beacon;
1458 struct probe_resp *old_probe_resp;
1459 struct fils_discovery_data *old_fils_discovery;
1460 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1461 struct cfg80211_chan_def chandef;
1462 struct ieee80211_link_data *link =
1463 sdata_dereference(sdata->link[link_id], sdata);
1464 struct ieee80211_bss_conf *link_conf = link->conf;
1466 sdata_assert_lock(sdata);
1468 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1471 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1473 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1475 old_unsol_bcast_probe_resp =
1476 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1479 /* abort any running channel switch */
1480 mutex_lock(&local->mtx);
1481 link_conf->csa_active = false;
1482 if (link->csa_block_tx) {
1483 ieee80211_wake_vif_queues(local, sdata,
1484 IEEE80211_QUEUE_STOP_REASON_CSA);
1485 link->csa_block_tx = false;
1488 mutex_unlock(&local->mtx);
1490 ieee80211_free_next_beacon(link);
1492 /* turn off carrier for this interface and dependent VLANs */
1493 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1494 netif_carrier_off(vlan->dev);
1495 netif_carrier_off(dev);
1497 /* remove beacon and probe response */
1498 sdata->u.ap.active = false;
1499 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1500 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1501 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1502 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1503 kfree_rcu(old_beacon, rcu_head);
1505 kfree_rcu(old_probe_resp, rcu_head);
1506 if (old_fils_discovery)
1507 kfree_rcu(old_fils_discovery, rcu_head);
1508 if (old_unsol_bcast_probe_resp)
1509 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1511 kfree(link_conf->ftmr_params);
1512 link_conf->ftmr_params = NULL;
1514 __sta_info_flush(sdata, true);
1515 ieee80211_free_keys(sdata, true);
1517 link_conf->enable_beacon = false;
1518 sdata->beacon_rate_set = false;
1519 sdata->vif.cfg.ssid_len = 0;
1520 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1521 ieee80211_link_info_change_notify(sdata, link,
1522 BSS_CHANGED_BEACON_ENABLED);
1524 if (sdata->wdev.cac_started) {
1525 chandef = link_conf->chandef;
1526 cancel_delayed_work_sync(&link->dfs_cac_timer_work);
1527 cfg80211_cac_event(sdata->dev, &chandef,
1528 NL80211_RADAR_CAC_ABORTED,
1532 drv_stop_ap(sdata->local, sdata, link_conf);
1534 /* free all potentially still buffered bcast frames */
1535 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1536 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1538 mutex_lock(&local->mtx);
1539 ieee80211_link_copy_chanctx_to_vlans(link, true);
1540 ieee80211_link_release_channel(link);
1541 mutex_unlock(&local->mtx);
1546 static int sta_apply_auth_flags(struct ieee80211_local *local,
1547 struct sta_info *sta,
1552 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1553 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1554 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1555 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1560 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1561 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1562 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1564 * When peer becomes associated, init rate control as
1565 * well. Some drivers require rate control initialized
1566 * before drv_sta_state() is called.
1568 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1569 rate_control_rate_init(sta);
1571 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1576 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1577 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1578 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1579 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1580 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1587 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1588 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1589 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1590 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1595 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1596 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1597 test_sta_flag(sta, WLAN_STA_AUTH)) {
1598 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1606 static void sta_apply_mesh_params(struct ieee80211_local *local,
1607 struct sta_info *sta,
1608 struct station_parameters *params)
1610 #ifdef CONFIG_MAC80211_MESH
1611 struct ieee80211_sub_if_data *sdata = sta->sdata;
1614 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1615 switch (params->plink_state) {
1616 case NL80211_PLINK_ESTAB:
1617 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1618 changed = mesh_plink_inc_estab_count(sdata);
1619 sta->mesh->plink_state = params->plink_state;
1620 sta->mesh->aid = params->peer_aid;
1622 ieee80211_mps_sta_status_update(sta);
1623 changed |= ieee80211_mps_set_sta_local_pm(sta,
1624 sdata->u.mesh.mshcfg.power_mode);
1626 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1627 /* init at low value */
1628 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1631 case NL80211_PLINK_LISTEN:
1632 case NL80211_PLINK_BLOCKED:
1633 case NL80211_PLINK_OPN_SNT:
1634 case NL80211_PLINK_OPN_RCVD:
1635 case NL80211_PLINK_CNF_RCVD:
1636 case NL80211_PLINK_HOLDING:
1637 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1638 changed = mesh_plink_dec_estab_count(sdata);
1639 sta->mesh->plink_state = params->plink_state;
1641 ieee80211_mps_sta_status_update(sta);
1642 changed |= ieee80211_mps_set_sta_local_pm(sta,
1643 NL80211_MESH_POWER_UNKNOWN);
1651 switch (params->plink_action) {
1652 case NL80211_PLINK_ACTION_NO_ACTION:
1655 case NL80211_PLINK_ACTION_OPEN:
1656 changed |= mesh_plink_open(sta);
1658 case NL80211_PLINK_ACTION_BLOCK:
1659 changed |= mesh_plink_block(sta);
1663 if (params->local_pm)
1664 changed |= ieee80211_mps_set_sta_local_pm(sta,
1667 ieee80211_mbss_info_change_notify(sdata, changed);
1671 static int sta_link_apply_parameters(struct ieee80211_local *local,
1672 struct sta_info *sta, bool new_link,
1673 struct link_station_parameters *params)
1676 struct ieee80211_supported_band *sband;
1677 struct ieee80211_sub_if_data *sdata = sta->sdata;
1678 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1679 struct ieee80211_link_data *link =
1680 sdata_dereference(sdata->link[link_id], sdata);
1681 struct link_sta_info *link_sta =
1682 rcu_dereference_protected(sta->link[link_id],
1683 lockdep_is_held(&local->sta_mtx));
1686 * If there are no changes, then accept a link that doesn't exist,
1687 * unless it's a new link.
1689 if (params->link_id < 0 && !new_link &&
1690 !params->link_mac && !params->txpwr_set &&
1691 !params->supported_rates_len &&
1692 !params->ht_capa && !params->vht_capa &&
1693 !params->he_capa && !params->eht_capa &&
1694 !params->opmode_notif_used)
1697 if (!link || !link_sta)
1700 sband = ieee80211_get_link_sband(link);
1704 if (params->link_mac) {
1706 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1707 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1708 } else if (!ether_addr_equal(link_sta->addr,
1709 params->link_mac)) {
1712 } else if (new_link) {
1716 if (params->txpwr_set) {
1717 link_sta->pub->txpwr.type = params->txpwr.type;
1718 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1719 link_sta->pub->txpwr.power = params->txpwr.power;
1720 ret = drv_sta_set_txpwr(local, sdata, sta);
1725 if (params->supported_rates &&
1726 params->supported_rates_len) {
1727 ieee80211_parse_bitrates(link->conf->chandef.width,
1728 sband, params->supported_rates,
1729 params->supported_rates_len,
1730 &link_sta->pub->supp_rates[sband->band]);
1733 if (params->ht_capa)
1734 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1735 params->ht_capa, link_sta);
1737 /* VHT can override some HT caps such as the A-MSDU max length */
1738 if (params->vht_capa)
1739 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1740 params->vht_capa, link_sta);
1742 if (params->he_capa)
1743 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1744 (void *)params->he_capa,
1745 params->he_capa_len,
1746 (void *)params->he_6ghz_capa,
1749 if (params->eht_capa)
1750 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1751 (u8 *)params->he_capa,
1752 params->he_capa_len,
1754 params->eht_capa_len,
1757 if (params->opmode_notif_used) {
1758 /* returned value is only needed for rc update, but the
1759 * rc isn't initialized here yet, so ignore it
1761 __ieee80211_vht_handle_opmode(sdata, link_sta,
1762 params->opmode_notif,
1769 static int sta_apply_parameters(struct ieee80211_local *local,
1770 struct sta_info *sta,
1771 struct station_parameters *params)
1773 struct ieee80211_sub_if_data *sdata = sta->sdata;
1777 mask = params->sta_flags_mask;
1778 set = params->sta_flags_set;
1780 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1782 * In mesh mode, ASSOCIATED isn't part of the nl80211
1783 * API but must follow AUTHENTICATED for driver state.
1785 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1786 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1787 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1788 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1789 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1791 * TDLS -- everything follows authorized, but
1792 * only becoming authorized is possible, not
1795 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1796 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1797 BIT(NL80211_STA_FLAG_ASSOCIATED);
1798 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1799 BIT(NL80211_STA_FLAG_ASSOCIATED);
1803 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1804 local->hw.queues >= IEEE80211_NUM_ACS)
1805 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1807 /* auth flags will be set later for TDLS,
1808 * and for unassociated stations that move to associated */
1809 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1810 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1811 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1812 ret = sta_apply_auth_flags(local, sta, mask, set);
1817 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1818 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1819 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1821 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1824 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1825 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1826 if (set & BIT(NL80211_STA_FLAG_MFP))
1827 set_sta_flag(sta, WLAN_STA_MFP);
1829 clear_sta_flag(sta, WLAN_STA_MFP);
1832 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1833 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1834 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1836 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1839 /* mark TDLS channel switch support, if the AP allows it */
1840 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1841 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
1842 params->ext_capab_len >= 4 &&
1843 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1844 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1846 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1847 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1848 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1849 params->ext_capab_len >= 8 &&
1850 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1851 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1853 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1854 sta->sta.uapsd_queues = params->uapsd_queues;
1855 sta->sta.max_sp = params->max_sp;
1858 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
1859 params->ext_capab_len);
1862 * cfg80211 validates this (1-2007) and allows setting the AID
1863 * only when creating a new station entry
1866 sta->sta.aid = params->aid;
1869 * Some of the following updates would be racy if called on an
1870 * existing station, via ieee80211_change_station(). However,
1871 * all such changes are rejected by cfg80211 except for updates
1872 * changing the supported rates on an existing but not yet used
1876 if (params->listen_interval >= 0)
1877 sta->listen_interval = params->listen_interval;
1879 ret = sta_link_apply_parameters(local, sta, false,
1880 ¶ms->link_sta_params);
1884 if (params->support_p2p_ps >= 0)
1885 sta->sta.support_p2p_ps = params->support_p2p_ps;
1887 if (ieee80211_vif_is_mesh(&sdata->vif))
1888 sta_apply_mesh_params(local, sta, params);
1890 if (params->airtime_weight)
1891 sta->airtime_weight = params->airtime_weight;
1893 /* set the STA state after all sta info from usermode has been set */
1894 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1895 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1896 ret = sta_apply_auth_flags(local, sta, mask, set);
1901 /* Mark the STA as MLO if MLD MAC address is available */
1902 if (params->link_sta_params.mld_mac)
1903 sta->sta.mlo = true;
1908 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1910 struct station_parameters *params)
1912 struct ieee80211_local *local = wiphy_priv(wiphy);
1913 struct sta_info *sta;
1914 struct ieee80211_sub_if_data *sdata;
1918 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1920 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1921 sdata->vif.type != NL80211_IFTYPE_AP)
1924 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1926 if (ether_addr_equal(mac, sdata->vif.addr))
1929 if (!is_valid_ether_addr(mac))
1932 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1933 sdata->vif.type == NL80211_IFTYPE_STATION &&
1934 !sdata->u.mgd.associated)
1938 * If we have a link ID, it can be a non-MLO station on an AP MLD,
1939 * but we need to have a link_mac in that case as well, so use the
1940 * STA's MAC address in that case.
1942 if (params->link_sta_params.link_id >= 0)
1943 sta = sta_info_alloc_with_link(sdata, mac,
1944 params->link_sta_params.link_id,
1945 params->link_sta_params.link_mac ?: mac,
1948 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1953 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1954 sta->sta.tdls = true;
1956 /* Though the mutex is not needed here (since the station is not
1957 * visible yet), sta_apply_parameters (and inner functions) require
1958 * the mutex due to other paths.
1960 mutex_lock(&local->sta_mtx);
1961 err = sta_apply_parameters(local, sta, params);
1962 mutex_unlock(&local->sta_mtx);
1964 sta_info_free(local, sta);
1969 * for TDLS and for unassociated station, rate control should be
1970 * initialized only when rates are known and station is marked
1971 * authorized/associated
1973 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1974 test_sta_flag(sta, WLAN_STA_ASSOC))
1975 rate_control_rate_init(sta);
1977 return sta_info_insert(sta);
1980 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1981 struct station_del_parameters *params)
1983 struct ieee80211_sub_if_data *sdata;
1985 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1988 return sta_info_destroy_addr_bss(sdata, params->mac);
1990 sta_info_flush(sdata);
1994 static int ieee80211_change_station(struct wiphy *wiphy,
1995 struct net_device *dev, const u8 *mac,
1996 struct station_parameters *params)
1998 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1999 struct ieee80211_local *local = wiphy_priv(wiphy);
2000 struct sta_info *sta;
2001 struct ieee80211_sub_if_data *vlansdata;
2002 enum cfg80211_station_type statype;
2005 mutex_lock(&local->sta_mtx);
2007 sta = sta_info_get_bss(sdata, mac);
2013 switch (sdata->vif.type) {
2014 case NL80211_IFTYPE_MESH_POINT:
2015 if (sdata->u.mesh.user_mpm)
2016 statype = CFG80211_STA_MESH_PEER_USER;
2018 statype = CFG80211_STA_MESH_PEER_KERNEL;
2020 case NL80211_IFTYPE_ADHOC:
2021 statype = CFG80211_STA_IBSS;
2023 case NL80211_IFTYPE_STATION:
2024 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2025 statype = CFG80211_STA_AP_STA;
2028 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2029 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2031 statype = CFG80211_STA_TDLS_PEER_SETUP;
2033 case NL80211_IFTYPE_AP:
2034 case NL80211_IFTYPE_AP_VLAN:
2035 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2036 statype = CFG80211_STA_AP_CLIENT;
2038 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2045 err = cfg80211_check_station_change(wiphy, params, statype);
2049 if (params->vlan && params->vlan != sta->sdata->dev) {
2050 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2052 if (params->vlan->ieee80211_ptr->use_4addr) {
2053 if (vlansdata->u.vlan.sta) {
2058 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
2059 __ieee80211_check_fast_rx_iface(vlansdata);
2060 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2063 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2064 sta->sdata->u.vlan.sta) {
2065 ieee80211_clear_fast_rx(sta);
2066 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2069 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2070 ieee80211_vif_dec_num_mcast(sta->sdata);
2072 sta->sdata = vlansdata;
2073 ieee80211_check_fast_xmit(sta);
2075 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2076 ieee80211_vif_inc_num_mcast(sta->sdata);
2077 cfg80211_send_layer2_update(sta->sdata->dev,
2082 /* we use sta_info_get_bss() so this might be different */
2083 if (sdata != sta->sdata) {
2084 mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
2085 err = sta_apply_parameters(local, sta, params);
2086 mutex_unlock(&sta->sdata->wdev.mtx);
2088 err = sta_apply_parameters(local, sta, params);
2093 mutex_unlock(&local->sta_mtx);
2095 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2096 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2097 ieee80211_recalc_ps(local);
2098 ieee80211_recalc_ps_vif(sdata);
2103 mutex_unlock(&local->sta_mtx);
2107 #ifdef CONFIG_MAC80211_MESH
2108 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2109 const u8 *dst, const u8 *next_hop)
2111 struct ieee80211_sub_if_data *sdata;
2112 struct mesh_path *mpath;
2113 struct sta_info *sta;
2115 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2118 sta = sta_info_get(sdata, next_hop);
2124 mpath = mesh_path_add(sdata, dst);
2125 if (IS_ERR(mpath)) {
2127 return PTR_ERR(mpath);
2130 mesh_path_fix_nexthop(mpath, sta);
2136 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2139 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2142 return mesh_path_del(sdata, dst);
2144 mesh_path_flush_by_iface(sdata);
2148 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2149 const u8 *dst, const u8 *next_hop)
2151 struct ieee80211_sub_if_data *sdata;
2152 struct mesh_path *mpath;
2153 struct sta_info *sta;
2155 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2159 sta = sta_info_get(sdata, next_hop);
2165 mpath = mesh_path_lookup(sdata, dst);
2171 mesh_path_fix_nexthop(mpath, sta);
2177 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2178 struct mpath_info *pinfo)
2180 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2183 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2185 eth_zero_addr(next_hop);
2187 memset(pinfo, 0, sizeof(*pinfo));
2189 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2191 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2194 MPATH_INFO_EXPTIME |
2195 MPATH_INFO_DISCOVERY_TIMEOUT |
2196 MPATH_INFO_DISCOVERY_RETRIES |
2198 MPATH_INFO_HOP_COUNT |
2199 MPATH_INFO_PATH_CHANGE;
2201 pinfo->frame_qlen = mpath->frame_queue.qlen;
2202 pinfo->sn = mpath->sn;
2203 pinfo->metric = mpath->metric;
2204 if (time_before(jiffies, mpath->exp_time))
2205 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2206 pinfo->discovery_timeout =
2207 jiffies_to_msecs(mpath->discovery_timeout);
2208 pinfo->discovery_retries = mpath->discovery_retries;
2209 if (mpath->flags & MESH_PATH_ACTIVE)
2210 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2211 if (mpath->flags & MESH_PATH_RESOLVING)
2212 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2213 if (mpath->flags & MESH_PATH_SN_VALID)
2214 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2215 if (mpath->flags & MESH_PATH_FIXED)
2216 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2217 if (mpath->flags & MESH_PATH_RESOLVED)
2218 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2219 pinfo->hop_count = mpath->hop_count;
2220 pinfo->path_change_count = mpath->path_change_count;
2223 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2224 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2227 struct ieee80211_sub_if_data *sdata;
2228 struct mesh_path *mpath;
2230 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2233 mpath = mesh_path_lookup(sdata, dst);
2238 memcpy(dst, mpath->dst, ETH_ALEN);
2239 mpath_set_pinfo(mpath, next_hop, pinfo);
2244 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2245 int idx, u8 *dst, u8 *next_hop,
2246 struct mpath_info *pinfo)
2248 struct ieee80211_sub_if_data *sdata;
2249 struct mesh_path *mpath;
2251 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2254 mpath = mesh_path_lookup_by_idx(sdata, idx);
2259 memcpy(dst, mpath->dst, ETH_ALEN);
2260 mpath_set_pinfo(mpath, next_hop, pinfo);
2265 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2266 struct mpath_info *pinfo)
2268 memset(pinfo, 0, sizeof(*pinfo));
2269 memcpy(mpp, mpath->mpp, ETH_ALEN);
2271 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2274 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2275 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2278 struct ieee80211_sub_if_data *sdata;
2279 struct mesh_path *mpath;
2281 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2284 mpath = mpp_path_lookup(sdata, dst);
2289 memcpy(dst, mpath->dst, ETH_ALEN);
2290 mpp_set_pinfo(mpath, mpp, pinfo);
2295 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2296 int idx, u8 *dst, u8 *mpp,
2297 struct mpath_info *pinfo)
2299 struct ieee80211_sub_if_data *sdata;
2300 struct mesh_path *mpath;
2302 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2305 mpath = mpp_path_lookup_by_idx(sdata, idx);
2310 memcpy(dst, mpath->dst, ETH_ALEN);
2311 mpp_set_pinfo(mpath, mpp, pinfo);
2316 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2317 struct net_device *dev,
2318 struct mesh_config *conf)
2320 struct ieee80211_sub_if_data *sdata;
2321 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2323 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2327 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2329 return (mask >> (parm-1)) & 0x1;
2332 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2333 const struct mesh_setup *setup)
2336 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2337 struct ieee80211_sub_if_data, u.mesh);
2340 /* allocate information elements */
2343 if (setup->ie_len) {
2344 new_ie = kmemdup(setup->ie, setup->ie_len,
2349 ifmsh->ie_len = setup->ie_len;
2352 /* now copy the rest of the setup parameters */
2353 ifmsh->mesh_id_len = setup->mesh_id_len;
2354 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2355 ifmsh->mesh_sp_id = setup->sync_method;
2356 ifmsh->mesh_pp_id = setup->path_sel_proto;
2357 ifmsh->mesh_pm_id = setup->path_metric;
2358 ifmsh->user_mpm = setup->user_mpm;
2359 ifmsh->mesh_auth_id = setup->auth_id;
2360 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2361 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2362 if (setup->is_authenticated)
2363 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2364 if (setup->is_secure)
2365 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2367 /* mcast rate setting in Mesh Node */
2368 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2369 sizeof(setup->mcast_rate));
2370 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2372 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2373 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2375 sdata->beacon_rate_set = false;
2376 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2377 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2378 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2379 sdata->beacon_rateidx_mask[i] =
2380 setup->beacon_rate.control[i].legacy;
2381 if (sdata->beacon_rateidx_mask[i])
2382 sdata->beacon_rate_set = true;
2389 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2390 struct net_device *dev, u32 mask,
2391 const struct mesh_config *nconf)
2393 struct mesh_config *conf;
2394 struct ieee80211_sub_if_data *sdata;
2395 struct ieee80211_if_mesh *ifmsh;
2397 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2398 ifmsh = &sdata->u.mesh;
2400 /* Set the config options which we are interested in setting */
2401 conf = &(sdata->u.mesh.mshcfg);
2402 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2403 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2404 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2405 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2406 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2407 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2408 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2409 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2410 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2411 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2412 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2413 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2414 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2415 conf->element_ttl = nconf->element_ttl;
2416 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2417 if (ifmsh->user_mpm)
2419 conf->auto_open_plinks = nconf->auto_open_plinks;
2421 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2422 conf->dot11MeshNbrOffsetMaxNeighbor =
2423 nconf->dot11MeshNbrOffsetMaxNeighbor;
2424 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2425 conf->dot11MeshHWMPmaxPREQretries =
2426 nconf->dot11MeshHWMPmaxPREQretries;
2427 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2428 conf->path_refresh_time = nconf->path_refresh_time;
2429 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2430 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2431 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2432 conf->dot11MeshHWMPactivePathTimeout =
2433 nconf->dot11MeshHWMPactivePathTimeout;
2434 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2435 conf->dot11MeshHWMPpreqMinInterval =
2436 nconf->dot11MeshHWMPpreqMinInterval;
2437 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2438 conf->dot11MeshHWMPperrMinInterval =
2439 nconf->dot11MeshHWMPperrMinInterval;
2440 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2442 conf->dot11MeshHWMPnetDiameterTraversalTime =
2443 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2444 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2445 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2446 ieee80211_mesh_root_setup(ifmsh);
2448 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2449 /* our current gate announcement implementation rides on root
2450 * announcements, so require this ifmsh to also be a root node
2452 if (nconf->dot11MeshGateAnnouncementProtocol &&
2453 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2454 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2455 ieee80211_mesh_root_setup(ifmsh);
2457 conf->dot11MeshGateAnnouncementProtocol =
2458 nconf->dot11MeshGateAnnouncementProtocol;
2460 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2461 conf->dot11MeshHWMPRannInterval =
2462 nconf->dot11MeshHWMPRannInterval;
2463 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2464 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2465 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2466 /* our RSSI threshold implementation is supported only for
2467 * devices that report signal in dBm.
2469 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2471 conf->rssi_threshold = nconf->rssi_threshold;
2473 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2474 conf->ht_opmode = nconf->ht_opmode;
2475 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2476 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2479 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2480 conf->dot11MeshHWMPactivePathToRootTimeout =
2481 nconf->dot11MeshHWMPactivePathToRootTimeout;
2482 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2483 conf->dot11MeshHWMProotInterval =
2484 nconf->dot11MeshHWMProotInterval;
2485 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2486 conf->dot11MeshHWMPconfirmationInterval =
2487 nconf->dot11MeshHWMPconfirmationInterval;
2488 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2489 conf->power_mode = nconf->power_mode;
2490 ieee80211_mps_local_status_update(sdata);
2492 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2493 conf->dot11MeshAwakeWindowDuration =
2494 nconf->dot11MeshAwakeWindowDuration;
2495 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2496 conf->plink_timeout = nconf->plink_timeout;
2497 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2498 conf->dot11MeshConnectedToMeshGate =
2499 nconf->dot11MeshConnectedToMeshGate;
2500 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2501 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2502 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2503 conf->dot11MeshConnectedToAuthServer =
2504 nconf->dot11MeshConnectedToAuthServer;
2505 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2509 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2510 const struct mesh_config *conf,
2511 const struct mesh_setup *setup)
2513 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2514 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2517 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2518 err = copy_mesh_setup(ifmsh, setup);
2522 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2524 /* can mesh use other SMPS modes? */
2525 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2526 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2528 mutex_lock(&sdata->local->mtx);
2529 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
2530 IEEE80211_CHANCTX_SHARED);
2531 mutex_unlock(&sdata->local->mtx);
2535 return ieee80211_start_mesh(sdata);
2538 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2540 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2542 ieee80211_stop_mesh(sdata);
2543 mutex_lock(&sdata->local->mtx);
2544 ieee80211_link_release_channel(&sdata->deflink);
2545 kfree(sdata->u.mesh.ie);
2546 mutex_unlock(&sdata->local->mtx);
2552 static int ieee80211_change_bss(struct wiphy *wiphy,
2553 struct net_device *dev,
2554 struct bss_parameters *params)
2556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2557 struct ieee80211_supported_band *sband;
2560 if (!sdata_dereference(sdata->deflink.u.ap.beacon, sdata))
2563 sband = ieee80211_get_sband(sdata);
2567 if (params->use_cts_prot >= 0) {
2568 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2569 changed |= BSS_CHANGED_ERP_CTS_PROT;
2571 if (params->use_short_preamble >= 0) {
2572 sdata->vif.bss_conf.use_short_preamble =
2573 params->use_short_preamble;
2574 changed |= BSS_CHANGED_ERP_PREAMBLE;
2577 if (!sdata->vif.bss_conf.use_short_slot &&
2578 (sband->band == NL80211_BAND_5GHZ ||
2579 sband->band == NL80211_BAND_6GHZ)) {
2580 sdata->vif.bss_conf.use_short_slot = true;
2581 changed |= BSS_CHANGED_ERP_SLOT;
2584 if (params->use_short_slot_time >= 0) {
2585 sdata->vif.bss_conf.use_short_slot =
2586 params->use_short_slot_time;
2587 changed |= BSS_CHANGED_ERP_SLOT;
2590 if (params->basic_rates) {
2591 ieee80211_parse_bitrates(sdata->vif.bss_conf.chandef.width,
2592 wiphy->bands[sband->band],
2593 params->basic_rates,
2594 params->basic_rates_len,
2595 &sdata->vif.bss_conf.basic_rates);
2596 changed |= BSS_CHANGED_BASIC_RATES;
2597 ieee80211_check_rate_mask(&sdata->deflink);
2600 if (params->ap_isolate >= 0) {
2601 if (params->ap_isolate)
2602 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2604 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2605 ieee80211_check_fast_rx_iface(sdata);
2608 if (params->ht_opmode >= 0) {
2609 sdata->vif.bss_conf.ht_operation_mode =
2610 (u16) params->ht_opmode;
2611 changed |= BSS_CHANGED_HT;
2614 if (params->p2p_ctwindow >= 0) {
2615 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2616 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2617 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2618 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2619 changed |= BSS_CHANGED_P2P_PS;
2622 if (params->p2p_opp_ps > 0) {
2623 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2624 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2625 changed |= BSS_CHANGED_P2P_PS;
2626 } else if (params->p2p_opp_ps == 0) {
2627 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2628 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2629 changed |= BSS_CHANGED_P2P_PS;
2632 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
2637 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2638 struct net_device *dev,
2639 struct ieee80211_txq_params *params)
2641 struct ieee80211_local *local = wiphy_priv(wiphy);
2642 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2643 struct ieee80211_link_data *link =
2644 ieee80211_link_or_deflink(sdata, params->link_id, true);
2645 struct ieee80211_tx_queue_params p;
2647 if (!local->ops->conf_tx)
2650 if (local->hw.queues < IEEE80211_NUM_ACS)
2654 return PTR_ERR(link);
2656 memset(&p, 0, sizeof(p));
2657 p.aifs = params->aifs;
2658 p.cw_max = params->cwmax;
2659 p.cw_min = params->cwmin;
2660 p.txop = params->txop;
2663 * Setting tx queue params disables u-apsd because it's only
2664 * called in master mode.
2668 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2670 link->tx_conf[params->ac] = p;
2671 if (drv_conf_tx(local, link, params->ac, &p)) {
2672 wiphy_debug(local->hw.wiphy,
2673 "failed to set TX queue parameters for AC %d\n",
2678 ieee80211_link_info_change_notify(sdata, link,
2685 static int ieee80211_suspend(struct wiphy *wiphy,
2686 struct cfg80211_wowlan *wowlan)
2688 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2691 static int ieee80211_resume(struct wiphy *wiphy)
2693 return __ieee80211_resume(wiphy_priv(wiphy));
2696 #define ieee80211_suspend NULL
2697 #define ieee80211_resume NULL
2700 static int ieee80211_scan(struct wiphy *wiphy,
2701 struct cfg80211_scan_request *req)
2703 struct ieee80211_sub_if_data *sdata;
2705 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2707 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2708 case NL80211_IFTYPE_STATION:
2709 case NL80211_IFTYPE_ADHOC:
2710 case NL80211_IFTYPE_MESH_POINT:
2711 case NL80211_IFTYPE_P2P_CLIENT:
2712 case NL80211_IFTYPE_P2P_DEVICE:
2714 case NL80211_IFTYPE_P2P_GO:
2715 if (sdata->local->ops->hw_scan)
2718 * FIXME: implement NoA while scanning in software,
2719 * for now fall through to allow scanning only when
2720 * beaconing hasn't been configured yet
2723 case NL80211_IFTYPE_AP:
2725 * If the scan has been forced (and the driver supports
2726 * forcing), don't care about being beaconing already.
2727 * This will create problems to the attached stations (e.g. all
2728 * the frames sent while scanning on other channel will be
2731 if (sdata->deflink.u.ap.beacon &&
2732 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2733 !(req->flags & NL80211_SCAN_FLAG_AP)))
2736 case NL80211_IFTYPE_NAN:
2741 return ieee80211_request_scan(sdata, req);
2744 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2746 ieee80211_scan_cancel(wiphy_priv(wiphy));
2750 ieee80211_sched_scan_start(struct wiphy *wiphy,
2751 struct net_device *dev,
2752 struct cfg80211_sched_scan_request *req)
2754 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2756 if (!sdata->local->ops->sched_scan_start)
2759 return ieee80211_request_sched_scan_start(sdata, req);
2763 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2766 struct ieee80211_local *local = wiphy_priv(wiphy);
2768 if (!local->ops->sched_scan_stop)
2771 return ieee80211_request_sched_scan_stop(local);
2774 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2775 struct cfg80211_auth_request *req)
2777 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2780 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2781 struct cfg80211_assoc_request *req)
2783 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2786 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2787 struct cfg80211_deauth_request *req)
2789 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2792 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2793 struct cfg80211_disassoc_request *req)
2795 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2798 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2799 struct cfg80211_ibss_params *params)
2801 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2804 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2806 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2809 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2810 struct ocb_setup *setup)
2812 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2815 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2817 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2820 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2821 int rate[NUM_NL80211_BANDS])
2823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2825 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2826 sizeof(int) * NUM_NL80211_BANDS);
2828 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2829 BSS_CHANGED_MCAST_RATE);
2834 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2836 struct ieee80211_local *local = wiphy_priv(wiphy);
2839 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2840 ieee80211_check_fast_xmit_all(local);
2842 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2845 ieee80211_check_fast_xmit_all(local);
2850 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2851 (changed & WIPHY_PARAM_DYN_ACK)) {
2854 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2855 wiphy->coverage_class : -1;
2856 err = drv_set_coverage_class(local, coverage_class);
2862 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2863 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2869 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2870 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2872 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2874 if (changed & WIPHY_PARAM_RETRY_LONG) {
2875 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2877 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2880 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2881 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2883 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2884 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2885 WIPHY_PARAM_TXQ_QUANTUM))
2886 ieee80211_txq_set_params(local);
2891 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2892 struct wireless_dev *wdev,
2893 enum nl80211_tx_power_setting type, int mbm)
2895 struct ieee80211_local *local = wiphy_priv(wiphy);
2896 struct ieee80211_sub_if_data *sdata;
2897 enum nl80211_tx_power_setting txp_type = type;
2898 bool update_txp_type = false;
2899 bool has_monitor = false;
2902 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2904 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2905 sdata = wiphy_dereference(local->hw.wiphy,
2906 local->monitor_sdata);
2912 case NL80211_TX_POWER_AUTOMATIC:
2913 sdata->deflink.user_power_level =
2914 IEEE80211_UNSET_POWER_LEVEL;
2915 txp_type = NL80211_TX_POWER_LIMITED;
2917 case NL80211_TX_POWER_LIMITED:
2918 case NL80211_TX_POWER_FIXED:
2919 if (mbm < 0 || (mbm % 100))
2921 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
2925 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2926 update_txp_type = true;
2927 sdata->vif.bss_conf.txpower_type = txp_type;
2930 ieee80211_recalc_txpower(sdata, update_txp_type);
2936 case NL80211_TX_POWER_AUTOMATIC:
2937 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2938 txp_type = NL80211_TX_POWER_LIMITED;
2940 case NL80211_TX_POWER_LIMITED:
2941 case NL80211_TX_POWER_FIXED:
2942 if (mbm < 0 || (mbm % 100))
2944 local->user_power_level = MBM_TO_DBM(mbm);
2948 mutex_lock(&local->iflist_mtx);
2949 list_for_each_entry(sdata, &local->interfaces, list) {
2950 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2954 sdata->deflink.user_power_level = local->user_power_level;
2955 if (txp_type != sdata->vif.bss_conf.txpower_type)
2956 update_txp_type = true;
2957 sdata->vif.bss_conf.txpower_type = txp_type;
2959 list_for_each_entry(sdata, &local->interfaces, list) {
2960 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2962 ieee80211_recalc_txpower(sdata, update_txp_type);
2964 mutex_unlock(&local->iflist_mtx);
2967 sdata = wiphy_dereference(local->hw.wiphy,
2968 local->monitor_sdata);
2970 sdata->deflink.user_power_level = local->user_power_level;
2971 if (txp_type != sdata->vif.bss_conf.txpower_type)
2972 update_txp_type = true;
2973 sdata->vif.bss_conf.txpower_type = txp_type;
2975 ieee80211_recalc_txpower(sdata, update_txp_type);
2982 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2983 struct wireless_dev *wdev,
2986 struct ieee80211_local *local = wiphy_priv(wiphy);
2987 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2989 if (local->ops->get_txpower)
2990 return drv_get_txpower(local, sdata, dbm);
2992 if (!local->use_chanctx)
2993 *dbm = local->hw.conf.power_level;
2995 *dbm = sdata->vif.bss_conf.txpower;
3000 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3002 struct ieee80211_local *local = wiphy_priv(wiphy);
3004 drv_rfkill_poll(local);
3007 #ifdef CONFIG_NL80211_TESTMODE
3008 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3009 struct wireless_dev *wdev,
3010 void *data, int len)
3012 struct ieee80211_local *local = wiphy_priv(wiphy);
3013 struct ieee80211_vif *vif = NULL;
3015 if (!local->ops->testmode_cmd)
3019 struct ieee80211_sub_if_data *sdata;
3021 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3022 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3026 return local->ops->testmode_cmd(&local->hw, vif, data, len);
3029 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3030 struct sk_buff *skb,
3031 struct netlink_callback *cb,
3032 void *data, int len)
3034 struct ieee80211_local *local = wiphy_priv(wiphy);
3036 if (!local->ops->testmode_dump)
3039 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3043 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3044 struct ieee80211_link_data *link,
3045 enum ieee80211_smps_mode smps_mode)
3048 enum ieee80211_smps_mode old_req;
3050 struct sta_info *sta;
3051 bool tdls_peer_found = false;
3053 lockdep_assert_held(&sdata->wdev.mtx);
3055 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3058 old_req = link->u.mgd.req_smps;
3059 link->u.mgd.req_smps = smps_mode;
3061 if (old_req == smps_mode &&
3062 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3066 * If not associated, or current association is not an HT
3067 * association, there's no need to do anything, just store
3068 * the new value until we associate.
3070 if (!sdata->u.mgd.associated ||
3071 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
3074 ap = link->u.mgd.bssid;
3077 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3078 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3079 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3082 tdls_peer_found = true;
3087 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3088 if (tdls_peer_found || !sdata->u.mgd.powersave)
3089 smps_mode = IEEE80211_SMPS_OFF;
3091 smps_mode = IEEE80211_SMPS_DYNAMIC;
3094 /* send SM PS frame to AP */
3095 err = ieee80211_send_smps_action(sdata, smps_mode,
3098 link->u.mgd.req_smps = old_req;
3099 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3100 ieee80211_teardown_tdls_peers(sdata);
3105 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3106 bool enabled, int timeout)
3108 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3110 unsigned int link_id;
3112 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3115 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3118 if (enabled == sdata->u.mgd.powersave &&
3119 timeout == local->dynamic_ps_forced_timeout)
3122 sdata->u.mgd.powersave = enabled;
3123 local->dynamic_ps_forced_timeout = timeout;
3125 /* no change, but if automatic follow powersave */
3127 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3128 struct ieee80211_link_data *link;
3130 link = sdata_dereference(sdata->link[link_id], sdata);
3134 __ieee80211_request_smps_mgd(sdata, link,
3135 link->u.mgd.req_smps);
3137 sdata_unlock(sdata);
3139 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3140 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3142 ieee80211_recalc_ps(local);
3143 ieee80211_recalc_ps_vif(sdata);
3144 ieee80211_check_fast_rx_iface(sdata);
3149 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3150 struct net_device *dev,
3151 s32 rssi_thold, u32 rssi_hyst)
3153 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3154 struct ieee80211_vif *vif = &sdata->vif;
3155 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3157 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3158 rssi_hyst == bss_conf->cqm_rssi_hyst)
3161 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3162 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3165 bss_conf->cqm_rssi_thold = rssi_thold;
3166 bss_conf->cqm_rssi_hyst = rssi_hyst;
3167 bss_conf->cqm_rssi_low = 0;
3168 bss_conf->cqm_rssi_high = 0;
3169 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3171 /* tell the driver upon association, unless already associated */
3172 if (sdata->u.mgd.associated &&
3173 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3174 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3180 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3181 struct net_device *dev,
3182 s32 rssi_low, s32 rssi_high)
3184 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3185 struct ieee80211_vif *vif = &sdata->vif;
3186 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3188 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3191 bss_conf->cqm_rssi_low = rssi_low;
3192 bss_conf->cqm_rssi_high = rssi_high;
3193 bss_conf->cqm_rssi_thold = 0;
3194 bss_conf->cqm_rssi_hyst = 0;
3195 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3197 /* tell the driver upon association, unless already associated */
3198 if (sdata->u.mgd.associated &&
3199 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3200 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3206 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3207 struct net_device *dev,
3208 unsigned int link_id,
3210 const struct cfg80211_bitrate_mask *mask)
3212 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3213 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3216 if (!ieee80211_sdata_running(sdata))
3220 * If active validate the setting and reject it if it doesn't leave
3221 * at least one basic rate usable, since we really have to be able
3222 * to send something, and if we're an AP we have to be able to do
3223 * so at a basic rate so that all clients can receive it.
3225 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3226 sdata->vif.bss_conf.chandef.chan) {
3227 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3228 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3230 if (!(mask->control[band].legacy & basic_rates))
3234 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3235 ret = drv_set_bitrate_mask(local, sdata, mask);
3240 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3241 struct ieee80211_supported_band *sband = wiphy->bands[i];
3244 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3245 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3246 sizeof(mask->control[i].ht_mcs));
3247 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3248 mask->control[i].vht_mcs,
3249 sizeof(mask->control[i].vht_mcs));
3251 sdata->rc_has_mcs_mask[i] = false;
3252 sdata->rc_has_vht_mcs_mask[i] = false;
3256 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3257 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3258 sdata->rc_has_mcs_mask[i] = true;
3263 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3264 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3265 sdata->rc_has_vht_mcs_mask[i] = true;
3274 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3275 struct net_device *dev,
3276 struct cfg80211_chan_def *chandef,
3279 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3280 struct ieee80211_local *local = sdata->local;
3283 mutex_lock(&local->mtx);
3284 if (!list_empty(&local->roc_list) || local->scanning) {
3289 /* whatever, but channel contexts should not complain about that one */
3290 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3291 sdata->deflink.needed_rx_chains = local->rx_chains;
3293 err = ieee80211_link_use_channel(&sdata->deflink, chandef,
3294 IEEE80211_CHANCTX_SHARED);
3298 ieee80211_queue_delayed_work(&sdata->local->hw,
3299 &sdata->deflink.dfs_cac_timer_work,
3300 msecs_to_jiffies(cac_time_ms));
3303 mutex_unlock(&local->mtx);
3307 static void ieee80211_end_cac(struct wiphy *wiphy,
3308 struct net_device *dev)
3310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3311 struct ieee80211_local *local = sdata->local;
3313 mutex_lock(&local->mtx);
3314 list_for_each_entry(sdata, &local->interfaces, list) {
3315 /* it might be waiting for the local->mtx, but then
3316 * by the time it gets it, sdata->wdev.cac_started
3317 * will no longer be true
3319 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work);
3321 if (sdata->wdev.cac_started) {
3322 ieee80211_link_release_channel(&sdata->deflink);
3323 sdata->wdev.cac_started = false;
3326 mutex_unlock(&local->mtx);
3329 static struct cfg80211_beacon_data *
3330 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3332 struct cfg80211_beacon_data *new_beacon;
3336 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3337 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3338 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3339 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3341 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3345 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3346 new_beacon->mbssid_ies =
3347 kzalloc(struct_size(new_beacon->mbssid_ies,
3348 elem, beacon->mbssid_ies->cnt),
3350 if (!new_beacon->mbssid_ies) {
3356 pos = (u8 *)(new_beacon + 1);
3357 if (beacon->head_len) {
3358 new_beacon->head_len = beacon->head_len;
3359 new_beacon->head = pos;
3360 memcpy(pos, beacon->head, beacon->head_len);
3361 pos += beacon->head_len;
3363 if (beacon->tail_len) {
3364 new_beacon->tail_len = beacon->tail_len;
3365 new_beacon->tail = pos;
3366 memcpy(pos, beacon->tail, beacon->tail_len);
3367 pos += beacon->tail_len;
3369 if (beacon->beacon_ies_len) {
3370 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3371 new_beacon->beacon_ies = pos;
3372 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3373 pos += beacon->beacon_ies_len;
3375 if (beacon->proberesp_ies_len) {
3376 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3377 new_beacon->proberesp_ies = pos;
3378 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3379 pos += beacon->proberesp_ies_len;
3381 if (beacon->assocresp_ies_len) {
3382 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3383 new_beacon->assocresp_ies = pos;
3384 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3385 pos += beacon->assocresp_ies_len;
3387 if (beacon->probe_resp_len) {
3388 new_beacon->probe_resp_len = beacon->probe_resp_len;
3389 new_beacon->probe_resp = pos;
3390 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3391 pos += beacon->probe_resp_len;
3393 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3394 pos += ieee80211_copy_mbssid_beacon(pos,
3395 new_beacon->mbssid_ies,
3396 beacon->mbssid_ies);
3398 /* might copy -1, meaning no changes requested */
3399 new_beacon->ftm_responder = beacon->ftm_responder;
3401 new_beacon->lci_len = beacon->lci_len;
3402 new_beacon->lci = pos;
3403 memcpy(pos, beacon->lci, beacon->lci_len);
3404 pos += beacon->lci_len;
3406 if (beacon->civicloc) {
3407 new_beacon->civicloc_len = beacon->civicloc_len;
3408 new_beacon->civicloc = pos;
3409 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3410 pos += beacon->civicloc_len;
3416 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3418 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3419 struct ieee80211_local *local = sdata->local;
3423 if (vif->mbssid_tx_vif == vif) {
3424 /* Trigger ieee80211_csa_finish() on the non-transmitting
3425 * interfaces when channel switch is received on
3426 * transmitting interface
3428 struct ieee80211_sub_if_data *iter;
3430 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3431 if (!ieee80211_sdata_running(iter))
3434 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3437 ieee80211_queue_work(&iter->local->hw,
3438 &iter->deflink.csa_finalize_work);
3441 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
3445 EXPORT_SYMBOL(ieee80211_csa_finish);
3447 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3449 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3450 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3451 struct ieee80211_local *local = sdata->local;
3453 sdata->deflink.csa_block_tx = block_tx;
3454 sdata_info(sdata, "channel switch failed, disconnecting\n");
3455 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3457 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3459 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3464 switch (sdata->vif.type) {
3465 case NL80211_IFTYPE_AP:
3466 if (!sdata->deflink.u.ap.next_beacon)
3469 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3470 sdata->deflink.u.ap.next_beacon,
3472 ieee80211_free_next_beacon(&sdata->deflink);
3478 case NL80211_IFTYPE_ADHOC:
3479 err = ieee80211_ibss_finish_csa(sdata);
3484 #ifdef CONFIG_MAC80211_MESH
3485 case NL80211_IFTYPE_MESH_POINT:
3486 err = ieee80211_mesh_finish_csa(sdata);
3500 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3502 struct ieee80211_local *local = sdata->local;
3506 sdata_assert_lock(sdata);
3507 lockdep_assert_held(&local->mtx);
3508 lockdep_assert_held(&local->chanctx_mtx);
3511 * using reservation isn't immediate as it may be deferred until later
3512 * with multi-vif. once reservation is complete it will re-schedule the
3513 * work with no reserved_chanctx so verify chandef to check if it
3514 * completed successfully
3517 if (sdata->deflink.reserved_chanctx) {
3519 * with multi-vif csa driver may call ieee80211_csa_finish()
3520 * many times while waiting for other interfaces to use their
3523 if (sdata->deflink.reserved_ready)
3526 return ieee80211_link_use_reserved_context(&sdata->deflink);
3529 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3530 &sdata->deflink.csa_chandef))
3533 sdata->vif.bss_conf.csa_active = false;
3535 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3539 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
3541 if (sdata->deflink.csa_block_tx) {
3542 ieee80211_wake_vif_queues(local, sdata,
3543 IEEE80211_QUEUE_STOP_REASON_CSA);
3544 sdata->deflink.csa_block_tx = false;
3547 err = drv_post_channel_switch(sdata);
3551 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0);
3556 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3558 if (__ieee80211_csa_finalize(sdata)) {
3559 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3560 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3565 void ieee80211_csa_finalize_work(struct work_struct *work)
3567 struct ieee80211_sub_if_data *sdata =
3568 container_of(work, struct ieee80211_sub_if_data,
3569 deflink.csa_finalize_work);
3570 struct ieee80211_local *local = sdata->local;
3573 mutex_lock(&local->mtx);
3574 mutex_lock(&local->chanctx_mtx);
3576 /* AP might have been stopped while waiting for the lock. */
3577 if (!sdata->vif.bss_conf.csa_active)
3580 if (!ieee80211_sdata_running(sdata))
3583 ieee80211_csa_finalize(sdata);
3586 mutex_unlock(&local->chanctx_mtx);
3587 mutex_unlock(&local->mtx);
3588 sdata_unlock(sdata);
3591 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3592 struct cfg80211_csa_settings *params,
3595 struct ieee80211_csa_settings csa = {};
3598 switch (sdata->vif.type) {
3599 case NL80211_IFTYPE_AP:
3600 sdata->deflink.u.ap.next_beacon =
3601 cfg80211_beacon_dup(¶ms->beacon_after);
3602 if (!sdata->deflink.u.ap.next_beacon)
3606 * With a count of 0, we don't have to wait for any
3607 * TBTT before switching, so complete the CSA
3608 * immediately. In theory, with a count == 1 we
3609 * should delay the switch until just before the next
3610 * TBTT, but that would complicate things so we switch
3611 * immediately too. If we would delay the switch
3612 * until the next TBTT, we would have to set the probe
3615 * TODO: A channel switch with count <= 1 without
3616 * sending a CSA action frame is kind of useless,
3617 * because the clients won't know we're changing
3618 * channels. The action frame must be implemented
3619 * either here or in the userspace.
3621 if (params->count <= 1)
3624 if ((params->n_counter_offsets_beacon >
3625 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3626 (params->n_counter_offsets_presp >
3627 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3628 ieee80211_free_next_beacon(&sdata->deflink);
3632 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3633 csa.counter_offsets_presp = params->counter_offsets_presp;
3634 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3635 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3636 csa.count = params->count;
3638 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3639 ¶ms->beacon_csa, &csa,
3642 ieee80211_free_next_beacon(&sdata->deflink);
3648 case NL80211_IFTYPE_ADHOC:
3649 if (!sdata->vif.cfg.ibss_joined)
3652 if (params->chandef.width != sdata->u.ibss.chandef.width)
3655 switch (params->chandef.width) {
3656 case NL80211_CHAN_WIDTH_40:
3657 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3658 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3661 case NL80211_CHAN_WIDTH_5:
3662 case NL80211_CHAN_WIDTH_10:
3663 case NL80211_CHAN_WIDTH_20_NOHT:
3664 case NL80211_CHAN_WIDTH_20:
3670 /* changes into another band are not supported */
3671 if (sdata->u.ibss.chandef.chan->band !=
3672 params->chandef.chan->band)
3675 /* see comments in the NL80211_IFTYPE_AP block */
3676 if (params->count > 1) {
3677 err = ieee80211_ibss_csa_beacon(sdata, params);
3683 ieee80211_send_action_csa(sdata, params);
3686 #ifdef CONFIG_MAC80211_MESH
3687 case NL80211_IFTYPE_MESH_POINT: {
3688 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3690 /* changes into another band are not supported */
3691 if (sdata->vif.bss_conf.chandef.chan->band !=
3692 params->chandef.chan->band)
3695 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3696 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3697 if (!ifmsh->pre_value)
3698 ifmsh->pre_value = 1;
3703 /* see comments in the NL80211_IFTYPE_AP block */
3704 if (params->count > 1) {
3705 err = ieee80211_mesh_csa_beacon(sdata, params);
3707 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3713 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3714 ieee80211_send_action_csa(sdata, params);
3726 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3728 sdata->vif.bss_conf.color_change_active = false;
3730 ieee80211_free_next_beacon(&sdata->deflink);
3732 cfg80211_color_change_aborted_notify(sdata->dev);
3736 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3737 struct cfg80211_csa_settings *params)
3739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3740 struct ieee80211_local *local = sdata->local;
3741 struct ieee80211_channel_switch ch_switch;
3742 struct ieee80211_chanctx_conf *conf;
3743 struct ieee80211_chanctx *chanctx;
3747 sdata_assert_lock(sdata);
3748 lockdep_assert_held(&local->mtx);
3750 if (!list_empty(&local->roc_list) || local->scanning)
3753 if (sdata->wdev.cac_started)
3756 if (cfg80211_chandef_identical(¶ms->chandef,
3757 &sdata->vif.bss_conf.chandef))
3760 /* don't allow another channel switch if one is already active. */
3761 if (sdata->vif.bss_conf.csa_active)
3764 mutex_lock(&local->chanctx_mtx);
3765 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
3766 lockdep_is_held(&local->chanctx_mtx));
3772 if (params->chandef.chan->freq_offset) {
3773 /* this may work, but is untested */
3778 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3780 ch_switch.timestamp = 0;
3781 ch_switch.device_timestamp = 0;
3782 ch_switch.block_tx = params->block_tx;
3783 ch_switch.chandef = params->chandef;
3784 ch_switch.count = params->count;
3786 err = drv_pre_channel_switch(sdata, &ch_switch);
3790 err = ieee80211_link_reserve_chanctx(&sdata->deflink, ¶ms->chandef,
3792 params->radar_required);
3796 /* if reservation is invalid then this will fail */
3797 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3799 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3803 /* if there is a color change in progress, abort it */
3804 if (sdata->vif.bss_conf.color_change_active)
3805 ieee80211_color_change_abort(sdata);
3807 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3809 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3813 sdata->deflink.csa_chandef = params->chandef;
3814 sdata->deflink.csa_block_tx = params->block_tx;
3815 sdata->vif.bss_conf.csa_active = true;
3817 if (sdata->deflink.csa_block_tx)
3818 ieee80211_stop_vif_queues(local, sdata,
3819 IEEE80211_QUEUE_STOP_REASON_CSA);
3821 cfg80211_ch_switch_started_notify(sdata->dev,
3822 &sdata->deflink.csa_chandef, 0,
3823 params->count, params->block_tx);
3826 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3828 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3830 /* if the beacon didn't change, we can finalize immediately */
3831 ieee80211_csa_finalize(sdata);
3835 mutex_unlock(&local->chanctx_mtx);
3839 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3840 struct cfg80211_csa_settings *params)
3842 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3843 struct ieee80211_local *local = sdata->local;
3846 mutex_lock(&local->mtx);
3847 err = __ieee80211_channel_switch(wiphy, dev, params);
3848 mutex_unlock(&local->mtx);
3853 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3855 lockdep_assert_held(&local->mtx);
3857 local->roc_cookie_counter++;
3859 /* wow, you wrapped 64 bits ... more likely a bug */
3860 if (WARN_ON(local->roc_cookie_counter == 0))
3861 local->roc_cookie_counter++;
3863 return local->roc_cookie_counter;
3866 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3867 u64 *cookie, gfp_t gfp)
3869 unsigned long spin_flags;
3870 struct sk_buff *ack_skb;
3873 ack_skb = skb_copy(skb, gfp);
3877 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3878 id = idr_alloc(&local->ack_status_frames, ack_skb,
3879 1, 0x2000, GFP_ATOMIC);
3880 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3887 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3889 *cookie = ieee80211_mgmt_tx_cookie(local);
3890 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3896 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3897 struct wireless_dev *wdev,
3898 struct mgmt_frame_regs *upd)
3900 struct ieee80211_local *local = wiphy_priv(wiphy);
3901 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3902 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3903 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3904 bool global_change, intf_change;
3907 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3908 (local->rx_mcast_action_reg !=
3909 !!(upd->global_mcast_stypes & action_mask));
3910 local->probe_req_reg = upd->global_stypes & preq_mask;
3911 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3913 intf_change = (sdata->vif.probe_req_reg !=
3914 !!(upd->interface_stypes & preq_mask)) ||
3915 (sdata->vif.rx_mcast_action_reg !=
3916 !!(upd->interface_mcast_stypes & action_mask));
3917 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3918 sdata->vif.rx_mcast_action_reg =
3919 upd->interface_mcast_stypes & action_mask;
3921 if (!local->open_count)
3924 if (intf_change && ieee80211_sdata_running(sdata))
3925 drv_config_iface_filter(local, sdata,
3926 sdata->vif.probe_req_reg ?
3931 ieee80211_configure_filter(local);
3934 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3936 struct ieee80211_local *local = wiphy_priv(wiphy);
3941 return drv_set_antenna(local, tx_ant, rx_ant);
3944 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3946 struct ieee80211_local *local = wiphy_priv(wiphy);
3948 return drv_get_antenna(local, tx_ant, rx_ant);
3951 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3952 struct net_device *dev,
3953 struct cfg80211_gtk_rekey_data *data)
3955 struct ieee80211_local *local = wiphy_priv(wiphy);
3956 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3958 if (!local->ops->set_rekey_data)
3961 drv_set_rekey_data(local, sdata, data);
3966 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3967 const u8 *peer, u64 *cookie)
3969 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3970 struct ieee80211_local *local = sdata->local;
3971 struct ieee80211_qos_hdr *nullfunc;
3972 struct sk_buff *skb;
3973 int size = sizeof(*nullfunc);
3976 struct ieee80211_tx_info *info;
3977 struct sta_info *sta;
3978 struct ieee80211_chanctx_conf *chanctx_conf;
3979 enum nl80211_band band;
3982 /* the lock is needed to assign the cookie later */
3983 mutex_lock(&local->mtx);
3986 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3987 if (WARN_ON(!chanctx_conf)) {
3991 band = chanctx_conf->def.chan->band;
3992 sta = sta_info_get_bss(sdata, peer);
4001 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4002 IEEE80211_STYPE_QOS_NULLFUNC |
4003 IEEE80211_FCTL_FROMDS);
4006 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4007 IEEE80211_STYPE_NULLFUNC |
4008 IEEE80211_FCTL_FROMDS);
4011 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4019 skb_reserve(skb, local->hw.extra_tx_headroom);
4021 nullfunc = skb_put(skb, size);
4022 nullfunc->frame_control = fc;
4023 nullfunc->duration_id = 0;
4024 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4025 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4026 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4027 nullfunc->seq_ctrl = 0;
4029 info = IEEE80211_SKB_CB(skb);
4031 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4032 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4035 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4038 nullfunc->qos_ctrl = cpu_to_le16(7);
4040 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4047 ieee80211_xmit(sdata, sta, skb);
4053 mutex_unlock(&local->mtx);
4058 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4059 struct wireless_dev *wdev,
4060 unsigned int link_id,
4061 struct cfg80211_chan_def *chandef)
4063 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4064 struct ieee80211_local *local = wiphy_priv(wiphy);
4065 struct ieee80211_chanctx_conf *chanctx_conf;
4066 struct ieee80211_link_data *link;
4070 link = rcu_dereference(sdata->link[link_id]);
4076 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4078 *chandef = link->conf->chandef;
4080 } else if (local->open_count > 0 &&
4081 local->open_count == local->monitors &&
4082 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4083 if (local->use_chanctx)
4084 *chandef = local->monitor_chandef;
4086 *chandef = local->_oper_chandef;
4096 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4098 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4102 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4103 struct net_device *dev,
4104 struct cfg80211_qos_map *qos_map)
4106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4107 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4110 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4113 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4115 /* A NULL qos_map was passed to disable QoS mapping */
4119 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4120 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4122 kfree_rcu(old_qos_map, rcu_head);
4127 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4128 struct net_device *dev,
4129 unsigned int link_id,
4130 struct cfg80211_chan_def *chandef)
4132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4133 struct ieee80211_link_data *link;
4137 link = sdata_dereference(sdata->link[link_id], sdata);
4139 ret = ieee80211_link_change_bandwidth(link, chandef, &changed);
4141 ieee80211_link_info_change_notify(sdata, link, changed);
4146 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4147 u8 tsid, const u8 *peer, u8 up,
4150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4151 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4152 int ac = ieee802_1d_to_ac[up];
4154 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4157 if (!(sdata->wmm_acm & BIT(up)))
4160 if (ifmgd->tx_tspec[ac].admitted_time)
4163 if (admitted_time) {
4164 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4165 ifmgd->tx_tspec[ac].tsid = tsid;
4166 ifmgd->tx_tspec[ac].up = up;
4172 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4173 u8 tsid, const u8 *peer)
4175 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4176 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4177 struct ieee80211_local *local = wiphy_priv(wiphy);
4180 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4181 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4183 /* skip unused entries */
4184 if (!tx_tspec->admitted_time)
4187 if (tx_tspec->tsid != tsid)
4190 /* due to this new packets will be reassigned to non-ACM ACs */
4193 /* Make sure that all packets have been sent to avoid to
4194 * restore the QoS params on packets that are still on the
4198 ieee80211_flush_queues(local, sdata, false);
4200 /* restore the normal QoS parameters
4201 * (unconditionally to avoid races)
4203 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4204 tx_tspec->downgraded = false;
4205 ieee80211_sta_handle_tspec_ac_params(sdata);
4207 /* finally clear all the data */
4208 memset(tx_tspec, 0, sizeof(*tx_tspec));
4216 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4218 enum nl80211_nan_func_term_reason reason,
4221 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4222 struct cfg80211_nan_func *func;
4225 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4228 spin_lock_bh(&sdata->u.nan.func_lock);
4230 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4231 if (WARN_ON(!func)) {
4232 spin_unlock_bh(&sdata->u.nan.func_lock);
4236 cookie = func->cookie;
4237 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4239 spin_unlock_bh(&sdata->u.nan.func_lock);
4241 cfg80211_free_nan_func(func);
4243 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4244 reason, cookie, gfp);
4246 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4248 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4249 struct cfg80211_nan_match_params *match,
4252 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4253 struct cfg80211_nan_func *func;
4255 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4258 spin_lock_bh(&sdata->u.nan.func_lock);
4260 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4261 if (WARN_ON(!func)) {
4262 spin_unlock_bh(&sdata->u.nan.func_lock);
4265 match->cookie = func->cookie;
4267 spin_unlock_bh(&sdata->u.nan.func_lock);
4269 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4271 EXPORT_SYMBOL(ieee80211_nan_func_match);
4273 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4274 struct net_device *dev,
4277 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4279 sdata->u.ap.multicast_to_unicast = enabled;
4284 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4285 struct txq_info *txqi)
4287 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4288 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4289 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4292 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4293 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4294 txqstats->backlog_packets = txqi->tin.backlog_packets;
4297 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4298 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4299 txqstats->flows = txqi->tin.flows;
4302 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4303 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4304 txqstats->drops = txqi->cstats.drop_count;
4307 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4308 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4309 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4312 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4313 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4314 txqstats->overlimit = txqi->tin.overlimit;
4317 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4318 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4319 txqstats->collisions = txqi->tin.collisions;
4322 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4323 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4324 txqstats->tx_bytes = txqi->tin.tx_bytes;
4327 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4328 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4329 txqstats->tx_packets = txqi->tin.tx_packets;
4333 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4334 struct wireless_dev *wdev,
4335 struct cfg80211_txq_stats *txqstats)
4337 struct ieee80211_local *local = wiphy_priv(wiphy);
4338 struct ieee80211_sub_if_data *sdata;
4341 if (!local->ops->wake_tx_queue)
4344 spin_lock_bh(&local->fq.lock);
4348 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4349 if (!sdata->vif.txq) {
4353 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4356 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4357 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4358 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4359 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4360 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4361 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4362 txqstats->backlog_packets = local->fq.backlog;
4363 txqstats->backlog_bytes = local->fq.memory_usage;
4364 txqstats->overlimit = local->fq.overlimit;
4365 txqstats->overmemory = local->fq.overmemory;
4366 txqstats->collisions = local->fq.collisions;
4367 txqstats->max_flows = local->fq.flows_cnt;
4372 spin_unlock_bh(&local->fq.lock);
4378 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4379 struct net_device *dev,
4380 struct cfg80211_ftm_responder_stats *ftm_stats)
4382 struct ieee80211_local *local = wiphy_priv(wiphy);
4383 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4385 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4389 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4390 struct cfg80211_pmsr_request *request)
4392 struct ieee80211_local *local = wiphy_priv(wiphy);
4393 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4395 return drv_start_pmsr(local, sdata, request);
4399 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4400 struct cfg80211_pmsr_request *request)
4402 struct ieee80211_local *local = wiphy_priv(wiphy);
4403 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4405 return drv_abort_pmsr(local, sdata, request);
4408 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4409 struct net_device *dev,
4410 struct cfg80211_tid_config *tid_conf)
4412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4413 struct sta_info *sta;
4416 if (!sdata->local->ops->set_tid_config)
4419 if (!tid_conf->peer)
4420 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4422 mutex_lock(&sdata->local->sta_mtx);
4423 sta = sta_info_get_bss(sdata, tid_conf->peer);
4425 mutex_unlock(&sdata->local->sta_mtx);
4429 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4430 mutex_unlock(&sdata->local->sta_mtx);
4435 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4436 struct net_device *dev,
4437 const u8 *peer, u8 tids)
4439 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4440 struct sta_info *sta;
4443 if (!sdata->local->ops->reset_tid_config)
4447 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4449 mutex_lock(&sdata->local->sta_mtx);
4450 sta = sta_info_get_bss(sdata, peer);
4452 mutex_unlock(&sdata->local->sta_mtx);
4456 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4457 mutex_unlock(&sdata->local->sta_mtx);
4462 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4463 struct cfg80211_sar_specs *sar)
4465 struct ieee80211_local *local = wiphy_priv(wiphy);
4467 if (!local->ops->set_sar_specs)
4470 return local->ops->set_sar_specs(&local->hw, sar);
4474 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4477 switch (sdata->vif.type) {
4478 case NL80211_IFTYPE_AP: {
4481 if (!sdata->deflink.u.ap.next_beacon)
4484 ret = ieee80211_assign_beacon(sdata, &sdata->deflink,
4485 sdata->deflink.u.ap.next_beacon,
4487 ieee80211_free_next_beacon(&sdata->deflink);
4504 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4505 struct cfg80211_color_change_settings *params,
4508 struct ieee80211_color_change_settings color_change = {};
4511 switch (sdata->vif.type) {
4512 case NL80211_IFTYPE_AP:
4513 sdata->deflink.u.ap.next_beacon =
4514 cfg80211_beacon_dup(¶ms->beacon_next);
4515 if (!sdata->deflink.u.ap.next_beacon)
4518 if (params->count <= 1)
4521 color_change.counter_offset_beacon =
4522 params->counter_offset_beacon;
4523 color_change.counter_offset_presp =
4524 params->counter_offset_presp;
4525 color_change.count = params->count;
4527 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
4528 ¶ms->beacon_color_change,
4529 NULL, &color_change);
4531 ieee80211_free_next_beacon(&sdata->deflink);
4544 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4545 u8 color, int enable, u32 changed)
4547 sdata->vif.bss_conf.he_bss_color.color = color;
4548 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4549 changed |= BSS_CHANGED_HE_BSS_COLOR;
4551 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
4553 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4554 struct ieee80211_sub_if_data *child;
4556 mutex_lock(&sdata->local->iflist_mtx);
4557 list_for_each_entry(child, &sdata->local->interfaces, list) {
4558 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4559 child->vif.bss_conf.he_bss_color.color = color;
4560 child->vif.bss_conf.he_bss_color.enabled = enable;
4561 ieee80211_link_info_change_notify(child,
4563 BSS_CHANGED_HE_BSS_COLOR);
4566 mutex_unlock(&sdata->local->iflist_mtx);
4570 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4572 struct ieee80211_local *local = sdata->local;
4576 sdata_assert_lock(sdata);
4577 lockdep_assert_held(&local->mtx);
4579 sdata->vif.bss_conf.color_change_active = false;
4581 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4583 cfg80211_color_change_aborted_notify(sdata->dev);
4587 ieee80211_color_change_bss_config_notify(sdata,
4588 sdata->vif.bss_conf.color_change_color,
4590 cfg80211_color_change_notify(sdata->dev);
4595 void ieee80211_color_change_finalize_work(struct work_struct *work)
4597 struct ieee80211_sub_if_data *sdata =
4598 container_of(work, struct ieee80211_sub_if_data,
4599 deflink.color_change_finalize_work);
4600 struct ieee80211_local *local = sdata->local;
4603 mutex_lock(&local->mtx);
4605 /* AP might have been stopped while waiting for the lock. */
4606 if (!sdata->vif.bss_conf.color_change_active)
4609 if (!ieee80211_sdata_running(sdata))
4612 ieee80211_color_change_finalize(sdata);
4615 mutex_unlock(&local->mtx);
4616 sdata_unlock(sdata);
4619 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4621 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4623 ieee80211_queue_work(&sdata->local->hw,
4624 &sdata->deflink.color_change_finalize_work);
4626 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4629 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4630 u64 color_bitmap, gfp_t gfp)
4632 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4634 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
4637 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
4639 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4642 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4643 struct cfg80211_color_change_settings *params)
4645 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4646 struct ieee80211_local *local = sdata->local;
4650 sdata_assert_lock(sdata);
4652 if (sdata->vif.bss_conf.nontransmitted)
4655 mutex_lock(&local->mtx);
4657 /* don't allow another color change if one is already active or if csa
4660 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
4665 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4669 sdata->vif.bss_conf.color_change_active = true;
4670 sdata->vif.bss_conf.color_change_color = params->color;
4672 cfg80211_color_change_started_notify(sdata->dev, params->count);
4675 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4677 /* if the beacon didn't change, we can finalize immediately */
4678 ieee80211_color_change_finalize(sdata);
4681 mutex_unlock(&local->mtx);
4687 ieee80211_set_radar_background(struct wiphy *wiphy,
4688 struct cfg80211_chan_def *chandef)
4690 struct ieee80211_local *local = wiphy_priv(wiphy);
4692 if (!local->ops->set_radar_background)
4695 return local->ops->set_radar_background(&local->hw, chandef);
4698 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4699 struct wireless_dev *wdev,
4700 unsigned int link_id)
4702 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4704 if (wdev->use_4addr)
4707 return ieee80211_vif_set_links(sdata, wdev->valid_links);
4710 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4711 struct wireless_dev *wdev,
4712 unsigned int link_id)
4714 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4716 ieee80211_vif_set_links(sdata, wdev->valid_links);
4719 static int sta_add_link_station(struct ieee80211_local *local,
4720 struct ieee80211_sub_if_data *sdata,
4721 struct link_station_parameters *params)
4723 struct sta_info *sta;
4726 sta = sta_info_get_bss(sdata, params->mld_mac);
4730 if (!sta->sta.valid_links)
4733 if (sta->sta.valid_links & BIT(params->link_id))
4736 ret = ieee80211_sta_allocate_link(sta, params->link_id);
4740 ret = sta_link_apply_parameters(local, sta, true, params);
4742 ieee80211_sta_free_link(sta, params->link_id);
4746 /* ieee80211_sta_activate_link frees the link upon failure */
4747 return ieee80211_sta_activate_link(sta, params->link_id);
4751 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
4752 struct link_station_parameters *params)
4754 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4755 struct ieee80211_local *local = wiphy_priv(wiphy);
4758 mutex_lock(&sdata->local->sta_mtx);
4759 ret = sta_add_link_station(local, sdata, params);
4760 mutex_unlock(&sdata->local->sta_mtx);
4765 static int sta_mod_link_station(struct ieee80211_local *local,
4766 struct ieee80211_sub_if_data *sdata,
4767 struct link_station_parameters *params)
4769 struct sta_info *sta;
4771 sta = sta_info_get_bss(sdata, params->mld_mac);
4775 if (!(sta->sta.valid_links & BIT(params->link_id)))
4778 return sta_link_apply_parameters(local, sta, false, params);
4782 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
4783 struct link_station_parameters *params)
4785 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4786 struct ieee80211_local *local = wiphy_priv(wiphy);
4789 mutex_lock(&sdata->local->sta_mtx);
4790 ret = sta_mod_link_station(local, sdata, params);
4791 mutex_unlock(&sdata->local->sta_mtx);
4796 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
4797 struct link_station_del_parameters *params)
4799 struct sta_info *sta;
4801 sta = sta_info_get_bss(sdata, params->mld_mac);
4805 if (!(sta->sta.valid_links & BIT(params->link_id)))
4808 /* must not create a STA without links */
4809 if (sta->sta.valid_links == BIT(params->link_id))
4812 ieee80211_sta_remove_link(sta, params->link_id);
4818 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
4819 struct link_station_del_parameters *params)
4821 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4824 mutex_lock(&sdata->local->sta_mtx);
4825 ret = sta_del_link_station(sdata, params);
4826 mutex_unlock(&sdata->local->sta_mtx);
4831 const struct cfg80211_ops mac80211_config_ops = {
4832 .add_virtual_intf = ieee80211_add_iface,
4833 .del_virtual_intf = ieee80211_del_iface,
4834 .change_virtual_intf = ieee80211_change_iface,
4835 .start_p2p_device = ieee80211_start_p2p_device,
4836 .stop_p2p_device = ieee80211_stop_p2p_device,
4837 .add_key = ieee80211_add_key,
4838 .del_key = ieee80211_del_key,
4839 .get_key = ieee80211_get_key,
4840 .set_default_key = ieee80211_config_default_key,
4841 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4842 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4843 .start_ap = ieee80211_start_ap,
4844 .change_beacon = ieee80211_change_beacon,
4845 .stop_ap = ieee80211_stop_ap,
4846 .add_station = ieee80211_add_station,
4847 .del_station = ieee80211_del_station,
4848 .change_station = ieee80211_change_station,
4849 .get_station = ieee80211_get_station,
4850 .dump_station = ieee80211_dump_station,
4851 .dump_survey = ieee80211_dump_survey,
4852 #ifdef CONFIG_MAC80211_MESH
4853 .add_mpath = ieee80211_add_mpath,
4854 .del_mpath = ieee80211_del_mpath,
4855 .change_mpath = ieee80211_change_mpath,
4856 .get_mpath = ieee80211_get_mpath,
4857 .dump_mpath = ieee80211_dump_mpath,
4858 .get_mpp = ieee80211_get_mpp,
4859 .dump_mpp = ieee80211_dump_mpp,
4860 .update_mesh_config = ieee80211_update_mesh_config,
4861 .get_mesh_config = ieee80211_get_mesh_config,
4862 .join_mesh = ieee80211_join_mesh,
4863 .leave_mesh = ieee80211_leave_mesh,
4865 .join_ocb = ieee80211_join_ocb,
4866 .leave_ocb = ieee80211_leave_ocb,
4867 .change_bss = ieee80211_change_bss,
4868 .set_txq_params = ieee80211_set_txq_params,
4869 .set_monitor_channel = ieee80211_set_monitor_channel,
4870 .suspend = ieee80211_suspend,
4871 .resume = ieee80211_resume,
4872 .scan = ieee80211_scan,
4873 .abort_scan = ieee80211_abort_scan,
4874 .sched_scan_start = ieee80211_sched_scan_start,
4875 .sched_scan_stop = ieee80211_sched_scan_stop,
4876 .auth = ieee80211_auth,
4877 .assoc = ieee80211_assoc,
4878 .deauth = ieee80211_deauth,
4879 .disassoc = ieee80211_disassoc,
4880 .join_ibss = ieee80211_join_ibss,
4881 .leave_ibss = ieee80211_leave_ibss,
4882 .set_mcast_rate = ieee80211_set_mcast_rate,
4883 .set_wiphy_params = ieee80211_set_wiphy_params,
4884 .set_tx_power = ieee80211_set_tx_power,
4885 .get_tx_power = ieee80211_get_tx_power,
4886 .rfkill_poll = ieee80211_rfkill_poll,
4887 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4888 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4889 .set_power_mgmt = ieee80211_set_power_mgmt,
4890 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4891 .remain_on_channel = ieee80211_remain_on_channel,
4892 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4893 .mgmt_tx = ieee80211_mgmt_tx,
4894 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4895 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4896 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4897 .update_mgmt_frame_registrations =
4898 ieee80211_update_mgmt_frame_registrations,
4899 .set_antenna = ieee80211_set_antenna,
4900 .get_antenna = ieee80211_get_antenna,
4901 .set_rekey_data = ieee80211_set_rekey_data,
4902 .tdls_oper = ieee80211_tdls_oper,
4903 .tdls_mgmt = ieee80211_tdls_mgmt,
4904 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4905 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4906 .probe_client = ieee80211_probe_client,
4907 .set_noack_map = ieee80211_set_noack_map,
4909 .set_wakeup = ieee80211_set_wakeup,
4911 .get_channel = ieee80211_cfg_get_channel,
4912 .start_radar_detection = ieee80211_start_radar_detection,
4913 .end_cac = ieee80211_end_cac,
4914 .channel_switch = ieee80211_channel_switch,
4915 .set_qos_map = ieee80211_set_qos_map,
4916 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4917 .add_tx_ts = ieee80211_add_tx_ts,
4918 .del_tx_ts = ieee80211_del_tx_ts,
4919 .start_nan = ieee80211_start_nan,
4920 .stop_nan = ieee80211_stop_nan,
4921 .nan_change_conf = ieee80211_nan_change_conf,
4922 .add_nan_func = ieee80211_add_nan_func,
4923 .del_nan_func = ieee80211_del_nan_func,
4924 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4925 .tx_control_port = ieee80211_tx_control_port,
4926 .get_txq_stats = ieee80211_get_txq_stats,
4927 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4928 .start_pmsr = ieee80211_start_pmsr,
4929 .abort_pmsr = ieee80211_abort_pmsr,
4930 .probe_mesh_link = ieee80211_probe_mesh_link,
4931 .set_tid_config = ieee80211_set_tid_config,
4932 .reset_tid_config = ieee80211_reset_tid_config,
4933 .set_sar_specs = ieee80211_set_sar_specs,
4934 .color_change = ieee80211_color_change,
4935 .set_radar_background = ieee80211_set_radar_background,
4936 .add_intf_link = ieee80211_add_intf_link,
4937 .del_intf_link = ieee80211_del_intf_link,
4938 .add_link_station = ieee80211_add_link_station,
4939 .mod_link_station = ieee80211_mod_link_station,
4940 .del_link_station = ieee80211_del_link_station,