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;
150 link_conf->bssid_indicator = 0;
152 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
155 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
159 if (tx_sdata == sdata) {
160 sdata->vif.mbssid_tx_vif = &sdata->vif;
162 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
163 link_conf->nontransmitted = true;
164 link_conf->bssid_index = params.index;
167 link_conf->ema_ap = true;
172 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
174 unsigned char name_assign_type,
175 enum nl80211_iftype type,
176 struct vif_params *params)
178 struct ieee80211_local *local = wiphy_priv(wiphy);
179 struct wireless_dev *wdev;
180 struct ieee80211_sub_if_data *sdata;
183 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
187 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
189 if (type == NL80211_IFTYPE_MONITOR) {
190 err = ieee80211_set_mon_options(sdata, params);
192 ieee80211_if_remove(sdata);
200 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
202 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
207 static int ieee80211_change_iface(struct wiphy *wiphy,
208 struct net_device *dev,
209 enum nl80211_iftype type,
210 struct vif_params *params)
212 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
213 struct ieee80211_local *local = sdata->local;
214 struct sta_info *sta;
217 ret = ieee80211_if_change_type(sdata, type);
221 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
222 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
223 ieee80211_check_fast_rx_iface(sdata);
224 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
225 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
227 if (params->use_4addr == ifmgd->use_4addr)
230 /* FIXME: no support for 4-addr MLO yet */
231 if (sdata->vif.valid_links)
234 sdata->u.mgd.use_4addr = params->use_4addr;
235 if (!ifmgd->associated)
238 mutex_lock(&local->sta_mtx);
239 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
241 drv_sta_set_4addr(local, sdata, &sta->sta,
243 mutex_unlock(&local->sta_mtx);
245 if (params->use_4addr)
246 ieee80211_send_4addr_nullfunc(local, sdata);
249 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
250 ret = ieee80211_set_mon_options(sdata, params);
258 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
259 struct wireless_dev *wdev)
261 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
264 mutex_lock(&sdata->local->chanctx_mtx);
265 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
266 mutex_unlock(&sdata->local->chanctx_mtx);
270 return ieee80211_do_open(wdev, true);
273 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
274 struct wireless_dev *wdev)
276 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
279 static int ieee80211_start_nan(struct wiphy *wiphy,
280 struct wireless_dev *wdev,
281 struct cfg80211_nan_conf *conf)
283 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
286 mutex_lock(&sdata->local->chanctx_mtx);
287 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
288 mutex_unlock(&sdata->local->chanctx_mtx);
292 ret = ieee80211_do_open(wdev, true);
296 ret = drv_start_nan(sdata->local, sdata, conf);
298 ieee80211_sdata_stop(sdata);
300 sdata->u.nan.conf = *conf;
305 static void ieee80211_stop_nan(struct wiphy *wiphy,
306 struct wireless_dev *wdev)
308 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
310 drv_stop_nan(sdata->local, sdata);
311 ieee80211_sdata_stop(sdata);
314 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
315 struct wireless_dev *wdev,
316 struct cfg80211_nan_conf *conf,
319 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
320 struct cfg80211_nan_conf new_conf;
323 if (sdata->vif.type != NL80211_IFTYPE_NAN)
326 if (!ieee80211_sdata_running(sdata))
329 new_conf = sdata->u.nan.conf;
331 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
332 new_conf.master_pref = conf->master_pref;
334 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
335 new_conf.bands = conf->bands;
337 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
339 sdata->u.nan.conf = new_conf;
344 static int ieee80211_add_nan_func(struct wiphy *wiphy,
345 struct wireless_dev *wdev,
346 struct cfg80211_nan_func *nan_func)
348 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
351 if (sdata->vif.type != NL80211_IFTYPE_NAN)
354 if (!ieee80211_sdata_running(sdata))
357 spin_lock_bh(&sdata->u.nan.func_lock);
359 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
360 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
362 spin_unlock_bh(&sdata->u.nan.func_lock);
367 nan_func->instance_id = ret;
369 WARN_ON(nan_func->instance_id == 0);
371 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
373 spin_lock_bh(&sdata->u.nan.func_lock);
374 idr_remove(&sdata->u.nan.function_inst_ids,
375 nan_func->instance_id);
376 spin_unlock_bh(&sdata->u.nan.func_lock);
382 static struct cfg80211_nan_func *
383 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
386 struct cfg80211_nan_func *func;
389 lockdep_assert_held(&sdata->u.nan.func_lock);
391 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
392 if (func->cookie == cookie)
399 static void ieee80211_del_nan_func(struct wiphy *wiphy,
400 struct wireless_dev *wdev, u64 cookie)
402 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
403 struct cfg80211_nan_func *func;
406 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
407 !ieee80211_sdata_running(sdata))
410 spin_lock_bh(&sdata->u.nan.func_lock);
412 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
414 instance_id = func->instance_id;
416 spin_unlock_bh(&sdata->u.nan.func_lock);
419 drv_del_nan_func(sdata->local, sdata, instance_id);
422 static int ieee80211_set_noack_map(struct wiphy *wiphy,
423 struct net_device *dev,
426 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
428 sdata->noack_map = noack_map;
430 ieee80211_check_fast_xmit_iface(sdata);
435 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
436 const u8 *mac_addr, u8 key_idx)
438 struct ieee80211_local *local = sdata->local;
439 struct ieee80211_key *key;
440 struct sta_info *sta;
443 if (!wiphy_ext_feature_isset(local->hw.wiphy,
444 NL80211_EXT_FEATURE_EXT_KEY_ID))
447 sta = sta_info_get_bss(sdata, mac_addr);
452 if (sta->ptk_idx == key_idx)
455 mutex_lock(&local->key_mtx);
456 key = key_mtx_dereference(local, sta->ptk[key_idx]);
458 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
459 ret = ieee80211_set_tx_key(key);
461 mutex_unlock(&local->key_mtx);
465 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
466 int link_id, u8 key_idx, bool pairwise,
467 const u8 *mac_addr, struct key_params *params)
469 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
470 struct ieee80211_link_data *link =
471 ieee80211_link_or_deflink(sdata, link_id, false);
472 struct ieee80211_local *local = sdata->local;
473 struct sta_info *sta = NULL;
474 struct ieee80211_key *key;
477 if (!ieee80211_sdata_running(sdata))
481 return PTR_ERR(link);
483 if (pairwise && params->mode == NL80211_KEY_SET_TX)
484 return ieee80211_set_tx(sdata, mac_addr, key_idx);
486 /* reject WEP and TKIP keys if WEP failed to initialize */
487 switch (params->cipher) {
488 case WLAN_CIPHER_SUITE_WEP40:
489 case WLAN_CIPHER_SUITE_TKIP:
490 case WLAN_CIPHER_SUITE_WEP104:
493 if (WARN_ON_ONCE(fips_enabled))
500 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
501 params->key, params->seq_len, params->seq);
505 key->conf.link_id = link_id;
508 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
510 if (params->mode == NL80211_KEY_NO_TX)
511 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
513 mutex_lock(&local->sta_mtx);
516 sta = sta_info_get_bss(sdata, mac_addr);
518 * The ASSOC test makes sure the driver is ready to
519 * receive the key. When wpa_supplicant has roamed
520 * using FT, it attempts to set the key before
521 * association has completed, this rejects that attempt
522 * so it will set the key again after association.
524 * TODO: accept the key if we have a station entry and
525 * add it to the device after the station.
527 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
528 ieee80211_key_free_unused(key);
534 switch (sdata->vif.type) {
535 case NL80211_IFTYPE_STATION:
536 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
537 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
539 case NL80211_IFTYPE_AP:
540 case NL80211_IFTYPE_AP_VLAN:
541 /* Keys without a station are used for TX only */
542 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
543 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
545 case NL80211_IFTYPE_ADHOC:
548 case NL80211_IFTYPE_MESH_POINT:
549 #ifdef CONFIG_MAC80211_MESH
550 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
551 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
554 case NL80211_IFTYPE_WDS:
555 case NL80211_IFTYPE_MONITOR:
556 case NL80211_IFTYPE_P2P_DEVICE:
557 case NL80211_IFTYPE_NAN:
558 case NL80211_IFTYPE_UNSPECIFIED:
559 case NUM_NL80211_IFTYPES:
560 case NL80211_IFTYPE_P2P_CLIENT:
561 case NL80211_IFTYPE_P2P_GO:
562 case NL80211_IFTYPE_OCB:
563 /* shouldn't happen */
568 err = ieee80211_key_link(key, link, sta);
569 /* KRACK protection, shouldn't happen but just silently accept key */
570 if (err == -EALREADY)
574 mutex_unlock(&local->sta_mtx);
579 static struct ieee80211_key *
580 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
581 u8 key_idx, bool pairwise, const u8 *mac_addr)
583 struct ieee80211_local *local __maybe_unused = sdata->local;
584 struct ieee80211_link_data *link = &sdata->deflink;
585 struct ieee80211_key *key;
588 link = rcu_dereference_check(sdata->link[link_id],
589 lockdep_is_held(&sdata->wdev.mtx));
595 struct sta_info *sta;
596 struct link_sta_info *link_sta;
598 sta = sta_info_get_bss(sdata, mac_addr);
603 link_sta = rcu_dereference_check(sta->link[link_id],
604 lockdep_is_held(&local->sta_mtx));
608 link_sta = &sta->deflink;
611 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
612 return rcu_dereference_check_key_mtx(local,
616 key_idx < NUM_DEFAULT_KEYS +
617 NUM_DEFAULT_MGMT_KEYS +
618 NUM_DEFAULT_BEACON_KEYS)
619 return rcu_dereference_check_key_mtx(local,
620 link_sta->gtk[key_idx]);
625 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
626 return rcu_dereference_check_key_mtx(local,
627 sdata->keys[key_idx]);
629 key = rcu_dereference_check_key_mtx(local, link->gtk[key_idx]);
633 /* or maybe it was a WEP key */
634 if (key_idx < NUM_DEFAULT_KEYS)
635 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]);
640 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
641 int link_id, u8 key_idx, bool pairwise,
644 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
645 struct ieee80211_local *local = sdata->local;
646 struct ieee80211_key *key;
649 mutex_lock(&local->sta_mtx);
650 mutex_lock(&local->key_mtx);
652 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
658 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
662 mutex_unlock(&local->key_mtx);
663 mutex_unlock(&local->sta_mtx);
668 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
669 int link_id, u8 key_idx, bool pairwise,
670 const u8 *mac_addr, void *cookie,
671 void (*callback)(void *cookie,
672 struct key_params *params))
674 struct ieee80211_sub_if_data *sdata;
676 struct key_params params;
677 struct ieee80211_key *key;
682 struct ieee80211_key_seq kseq = {};
684 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
688 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
692 memset(¶ms, 0, sizeof(params));
694 params.cipher = key->conf.cipher;
696 switch (key->conf.cipher) {
697 case WLAN_CIPHER_SUITE_TKIP:
698 pn64 = atomic64_read(&key->conf.tx_pn);
699 iv32 = TKIP_PN_TO_IV32(pn64);
700 iv16 = TKIP_PN_TO_IV16(pn64);
702 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
703 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
704 drv_get_key_seq(sdata->local, key, &kseq);
705 iv32 = kseq.tkip.iv32;
706 iv16 = kseq.tkip.iv16;
709 seq[0] = iv16 & 0xff;
710 seq[1] = (iv16 >> 8) & 0xff;
711 seq[2] = iv32 & 0xff;
712 seq[3] = (iv32 >> 8) & 0xff;
713 seq[4] = (iv32 >> 16) & 0xff;
714 seq[5] = (iv32 >> 24) & 0xff;
718 case WLAN_CIPHER_SUITE_CCMP:
719 case WLAN_CIPHER_SUITE_CCMP_256:
720 case WLAN_CIPHER_SUITE_AES_CMAC:
721 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
722 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
723 offsetof(typeof(kseq), aes_cmac));
725 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
726 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
727 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
728 offsetof(typeof(kseq), aes_gmac));
730 case WLAN_CIPHER_SUITE_GCMP:
731 case WLAN_CIPHER_SUITE_GCMP_256:
732 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
733 offsetof(typeof(kseq), gcmp));
735 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
736 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
737 drv_get_key_seq(sdata->local, key, &kseq);
738 memcpy(seq, kseq.ccmp.pn, 6);
740 pn64 = atomic64_read(&key->conf.tx_pn);
752 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
754 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
756 drv_get_key_seq(sdata->local, key, &kseq);
757 params.seq = kseq.hw.seq;
758 params.seq_len = kseq.hw.seq_len;
762 params.key = key->conf.key;
763 params.key_len = key->conf.keylen;
765 callback(cookie, ¶ms);
773 static int ieee80211_config_default_key(struct wiphy *wiphy,
774 struct net_device *dev,
775 int link_id, u8 key_idx, bool uni,
778 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
779 struct ieee80211_link_data *link =
780 ieee80211_link_or_deflink(sdata, link_id, false);
783 return PTR_ERR(link);
785 ieee80211_set_default_key(link, key_idx, uni, multi);
790 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
791 struct net_device *dev,
792 int link_id, u8 key_idx)
794 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
795 struct ieee80211_link_data *link =
796 ieee80211_link_or_deflink(sdata, link_id, true);
799 return PTR_ERR(link);
801 ieee80211_set_default_mgmt_key(link, key_idx);
806 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
807 struct net_device *dev,
808 int link_id, u8 key_idx)
810 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
811 struct ieee80211_link_data *link =
812 ieee80211_link_or_deflink(sdata, link_id, true);
815 return PTR_ERR(link);
817 ieee80211_set_default_beacon_key(link, key_idx);
822 void sta_set_rate_info_tx(struct sta_info *sta,
823 const struct ieee80211_tx_rate *rate,
824 struct rate_info *rinfo)
827 if (rate->flags & IEEE80211_TX_RC_MCS) {
828 rinfo->flags |= RATE_INFO_FLAGS_MCS;
829 rinfo->mcs = rate->idx;
830 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
831 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
832 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
833 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
835 struct ieee80211_supported_band *sband;
836 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
839 sband = ieee80211_get_sband(sta->sdata);
840 WARN_ON_ONCE(sband && !sband->bitrates);
841 if (sband && sband->bitrates) {
842 brate = sband->bitrates[rate->idx].bitrate;
843 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
846 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
847 rinfo->bw = RATE_INFO_BW_40;
848 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
849 rinfo->bw = RATE_INFO_BW_80;
850 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
851 rinfo->bw = RATE_INFO_BW_160;
853 rinfo->bw = RATE_INFO_BW_20;
854 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
855 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
858 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
859 int idx, u8 *mac, struct station_info *sinfo)
861 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
862 struct ieee80211_local *local = sdata->local;
863 struct sta_info *sta;
866 mutex_lock(&local->sta_mtx);
868 sta = sta_info_get_by_idx(sdata, idx);
871 memcpy(mac, sta->sta.addr, ETH_ALEN);
872 sta_set_sinfo(sta, sinfo, true);
875 mutex_unlock(&local->sta_mtx);
880 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
881 int idx, struct survey_info *survey)
883 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
885 return drv_get_survey(local, idx, survey);
888 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
889 const u8 *mac, struct station_info *sinfo)
891 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
892 struct ieee80211_local *local = sdata->local;
893 struct sta_info *sta;
896 mutex_lock(&local->sta_mtx);
898 sta = sta_info_get_bss(sdata, mac);
901 sta_set_sinfo(sta, sinfo, true);
904 mutex_unlock(&local->sta_mtx);
909 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
910 struct cfg80211_chan_def *chandef)
912 struct ieee80211_local *local = wiphy_priv(wiphy);
913 struct ieee80211_sub_if_data *sdata;
916 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
919 mutex_lock(&local->mtx);
920 if (local->use_chanctx) {
921 sdata = wiphy_dereference(local->hw.wiphy,
922 local->monitor_sdata);
924 ieee80211_link_release_channel(&sdata->deflink);
925 ret = ieee80211_link_use_channel(&sdata->deflink,
927 IEEE80211_CHANCTX_EXCLUSIVE);
929 } else if (local->open_count == local->monitors) {
930 local->_oper_chandef = *chandef;
931 ieee80211_hw_config(local, 0);
935 local->monitor_chandef = *chandef;
936 mutex_unlock(&local->mtx);
942 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
943 const u8 *resp, size_t resp_len,
944 const struct ieee80211_csa_settings *csa,
945 const struct ieee80211_color_change_settings *cca,
946 struct ieee80211_link_data *link)
948 struct probe_resp *new, *old;
950 if (!resp || !resp_len)
953 old = sdata_dereference(link->u.ap.probe_resp, sdata);
955 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
960 memcpy(new->data, resp, resp_len);
963 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
964 csa->n_counter_offsets_presp *
965 sizeof(new->cntdwn_counter_offsets[0]));
967 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
969 rcu_assign_pointer(link->u.ap.probe_resp, new);
971 kfree_rcu(old, rcu_head);
976 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
977 struct cfg80211_fils_discovery *params,
978 struct ieee80211_link_data *link,
979 struct ieee80211_bss_conf *link_conf)
981 struct fils_discovery_data *new, *old = NULL;
982 struct ieee80211_fils_discovery *fd;
984 if (!params->tmpl || !params->tmpl_len)
987 fd = &link_conf->fils_discovery;
988 fd->min_interval = params->min_interval;
989 fd->max_interval = params->max_interval;
991 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
992 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
995 new->len = params->tmpl_len;
996 memcpy(new->data, params->tmpl, params->tmpl_len);
997 rcu_assign_pointer(link->u.ap.fils_discovery, new);
1000 kfree_rcu(old, rcu_head);
1006 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
1007 struct cfg80211_unsol_bcast_probe_resp *params,
1008 struct ieee80211_link_data *link,
1009 struct ieee80211_bss_conf *link_conf)
1011 struct unsol_bcast_probe_resp_data *new, *old = NULL;
1013 if (!params->tmpl || !params->tmpl_len)
1016 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
1017 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1020 new->len = params->tmpl_len;
1021 memcpy(new->data, params->tmpl, params->tmpl_len);
1022 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
1025 kfree_rcu(old, rcu_head);
1027 link_conf->unsol_bcast_probe_resp_interval = params->interval;
1032 static int ieee80211_set_ftm_responder_params(
1033 struct ieee80211_sub_if_data *sdata,
1034 const u8 *lci, size_t lci_len,
1035 const u8 *civicloc, size_t civicloc_len,
1036 struct ieee80211_bss_conf *link_conf)
1038 struct ieee80211_ftm_responder_params *new, *old;
1042 if (!lci_len && !civicloc_len)
1045 old = link_conf->ftmr_params;
1046 len = lci_len + civicloc_len;
1048 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
1052 pos = (u8 *)(new + 1);
1054 new->lci_len = lci_len;
1056 memcpy(pos, lci, lci_len);
1061 new->civicloc_len = civicloc_len;
1062 new->civicloc = pos;
1063 memcpy(pos, civicloc, civicloc_len);
1064 pos += civicloc_len;
1067 link_conf->ftmr_params = new;
1074 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
1075 struct cfg80211_mbssid_elems *src)
1079 for (i = 0; i < src->cnt; i++) {
1080 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1081 dst->elem[i].len = src->elem[i].len;
1082 dst->elem[i].data = pos + offset;
1083 offset += dst->elem[i].len;
1085 dst->cnt = src->cnt;
1090 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1091 struct ieee80211_link_data *link,
1092 struct cfg80211_beacon_data *params,
1093 const struct ieee80211_csa_settings *csa,
1094 const struct ieee80211_color_change_settings *cca)
1096 struct cfg80211_mbssid_elems *mbssid = NULL;
1097 struct beacon_data *new, *old;
1098 int new_head_len, new_tail_len;
1100 u32 changed = BSS_CHANGED_BEACON;
1101 struct ieee80211_bss_conf *link_conf = link->conf;
1103 old = sdata_dereference(link->u.ap.beacon, sdata);
1105 /* Need to have a beacon head if we don't have one yet */
1106 if (!params->head && !old)
1109 /* new or old head? */
1111 new_head_len = params->head_len;
1113 new_head_len = old->head_len;
1115 /* new or old tail? */
1116 if (params->tail || !old)
1117 /* params->tail_len will be zero for !params->tail */
1118 new_tail_len = params->tail_len;
1120 new_tail_len = old->tail_len;
1122 size = sizeof(*new) + new_head_len + new_tail_len;
1124 /* new or old multiple BSSID elements? */
1125 if (params->mbssid_ies) {
1126 mbssid = params->mbssid_ies;
1127 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1128 size += ieee80211_get_mbssid_beacon_len(mbssid);
1129 } else if (old && old->mbssid_ies) {
1130 mbssid = old->mbssid_ies;
1131 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1132 size += ieee80211_get_mbssid_beacon_len(mbssid);
1135 new = kzalloc(size, GFP_KERNEL);
1139 /* start filling the new info now */
1142 * pointers go into the block we allocated,
1143 * memory is | beacon_data | head | tail | mbssid_ies
1145 new->head = ((u8 *) new) + sizeof(*new);
1146 new->tail = new->head + new_head_len;
1147 new->head_len = new_head_len;
1148 new->tail_len = new_tail_len;
1149 /* copy in optional mbssid_ies */
1151 u8 *pos = new->tail + new->tail_len;
1153 new->mbssid_ies = (void *)pos;
1154 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1155 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1156 /* update bssid_indicator */
1157 link_conf->bssid_indicator =
1158 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1162 new->cntdwn_current_counter = csa->count;
1163 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1164 csa->n_counter_offsets_beacon *
1165 sizeof(new->cntdwn_counter_offsets[0]));
1167 new->cntdwn_current_counter = cca->count;
1168 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1173 memcpy(new->head, params->head, new_head_len);
1175 memcpy(new->head, old->head, new_head_len);
1177 /* copy in optional tail */
1179 memcpy(new->tail, params->tail, new_tail_len);
1182 memcpy(new->tail, old->tail, new_tail_len);
1184 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1185 params->probe_resp_len, csa, cca, link);
1191 changed |= BSS_CHANGED_AP_PROBE_RESP;
1193 if (params->ftm_responder != -1) {
1194 link_conf->ftm_responder = params->ftm_responder;
1195 err = ieee80211_set_ftm_responder_params(sdata,
1199 params->civicloc_len,
1207 changed |= BSS_CHANGED_FTM_RESPONDER;
1210 rcu_assign_pointer(link->u.ap.beacon, new);
1211 sdata->u.ap.active = true;
1214 kfree_rcu(old, rcu_head);
1219 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1220 struct cfg80211_ap_settings *params)
1222 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1223 struct ieee80211_local *local = sdata->local;
1224 struct beacon_data *old;
1225 struct ieee80211_sub_if_data *vlan;
1226 u32 changed = BSS_CHANGED_BEACON_INT |
1227 BSS_CHANGED_BEACON_ENABLED |
1228 BSS_CHANGED_BEACON |
1229 BSS_CHANGED_P2P_PS |
1230 BSS_CHANGED_TXPOWER |
1233 int prev_beacon_int;
1234 unsigned int link_id = params->beacon.link_id;
1235 struct ieee80211_link_data *link;
1236 struct ieee80211_bss_conf *link_conf;
1238 link = sdata_dereference(sdata->link[link_id], sdata);
1242 link_conf = link->conf;
1244 old = sdata_dereference(link->u.ap.beacon, sdata);
1248 if (params->smps_mode != NL80211_SMPS_OFF)
1251 link->smps_mode = IEEE80211_SMPS_OFF;
1253 link->needed_rx_chains = sdata->local->rx_chains;
1255 prev_beacon_int = link_conf->beacon_int;
1256 link_conf->beacon_int = params->beacon_interval;
1258 if (params->he_cap && params->he_oper) {
1259 link_conf->he_support = true;
1260 link_conf->htc_trig_based_pkt_ext =
1261 le32_get_bits(params->he_oper->he_oper_params,
1262 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1263 link_conf->frame_time_rts_th =
1264 le32_get_bits(params->he_oper->he_oper_params,
1265 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1266 changed |= BSS_CHANGED_HE_OBSS_PD;
1268 if (params->beacon.he_bss_color.enabled)
1269 changed |= BSS_CHANGED_HE_BSS_COLOR;
1272 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1273 params->mbssid_config.tx_wdev) {
1274 err = ieee80211_set_ap_mbssid_options(sdata,
1275 params->mbssid_config,
1281 mutex_lock(&local->mtx);
1282 err = ieee80211_link_use_channel(link, ¶ms->chandef,
1283 IEEE80211_CHANCTX_SHARED);
1285 ieee80211_link_copy_chanctx_to_vlans(link, false);
1286 mutex_unlock(&local->mtx);
1288 link_conf->beacon_int = prev_beacon_int;
1293 * Apply control port protocol, this allows us to
1294 * not encrypt dynamic WEP control frames.
1296 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1297 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1298 sdata->control_port_over_nl80211 =
1299 params->crypto.control_port_over_nl80211;
1300 sdata->control_port_no_preauth =
1301 params->crypto.control_port_no_preauth;
1303 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1304 vlan->control_port_protocol =
1305 params->crypto.control_port_ethertype;
1306 vlan->control_port_no_encrypt =
1307 params->crypto.control_port_no_encrypt;
1308 vlan->control_port_over_nl80211 =
1309 params->crypto.control_port_over_nl80211;
1310 vlan->control_port_no_preauth =
1311 params->crypto.control_port_no_preauth;
1314 link_conf->dtim_period = params->dtim_period;
1315 link_conf->enable_beacon = true;
1316 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1317 link_conf->twt_responder = params->twt_responder;
1318 link_conf->he_obss_pd = params->he_obss_pd;
1319 link_conf->he_bss_color = params->beacon.he_bss_color;
1320 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1323 sdata->vif.cfg.ssid_len = params->ssid_len;
1324 if (params->ssid_len)
1325 memcpy(sdata->vif.cfg.ssid, params->ssid,
1327 link_conf->hidden_ssid =
1328 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1330 memset(&link_conf->p2p_noa_attr, 0,
1331 sizeof(link_conf->p2p_noa_attr));
1332 link_conf->p2p_noa_attr.oppps_ctwindow =
1333 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1334 if (params->p2p_opp_ps)
1335 link_conf->p2p_noa_attr.oppps_ctwindow |=
1336 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1338 sdata->beacon_rate_set = false;
1339 if (wiphy_ext_feature_isset(local->hw.wiphy,
1340 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1341 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1342 sdata->beacon_rateidx_mask[i] =
1343 params->beacon_rate.control[i].legacy;
1344 if (sdata->beacon_rateidx_mask[i])
1345 sdata->beacon_rate_set = true;
1349 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1350 link_conf->beacon_tx_rate = params->beacon_rate;
1352 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL);
1357 if (params->fils_discovery.max_interval) {
1358 err = ieee80211_set_fils_discovery(sdata,
1359 ¶ms->fils_discovery,
1363 changed |= BSS_CHANGED_FILS_DISCOVERY;
1366 if (params->unsol_bcast_probe_resp.interval) {
1367 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1368 ¶ms->unsol_bcast_probe_resp,
1372 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1375 err = drv_start_ap(sdata->local, sdata, link_conf);
1377 old = sdata_dereference(link->u.ap.beacon, sdata);
1380 kfree_rcu(old, rcu_head);
1381 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1382 sdata->u.ap.active = false;
1386 ieee80211_recalc_dtim(local, sdata);
1387 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1388 ieee80211_link_info_change_notify(sdata, link, changed);
1390 netif_carrier_on(dev);
1391 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1392 netif_carrier_on(vlan->dev);
1397 mutex_lock(&local->mtx);
1398 ieee80211_link_release_channel(link);
1399 mutex_unlock(&local->mtx);
1404 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1405 struct cfg80211_beacon_data *params)
1407 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1408 struct ieee80211_link_data *link;
1409 struct beacon_data *old;
1411 struct ieee80211_bss_conf *link_conf;
1413 sdata_assert_lock(sdata);
1415 link = sdata_dereference(sdata->link[params->link_id], sdata);
1419 link_conf = link->conf;
1421 /* don't allow changing the beacon while a countdown is in place - offset
1422 * of channel switch counter may change
1424 if (link_conf->csa_active || link_conf->color_change_active)
1427 old = sdata_dereference(link->u.ap.beacon, sdata);
1431 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL);
1435 if (params->he_bss_color_valid &&
1436 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1437 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1438 err |= BSS_CHANGED_HE_BSS_COLOR;
1441 ieee80211_link_info_change_notify(sdata, link, err);
1445 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1447 if (!link->u.ap.next_beacon)
1450 kfree(link->u.ap.next_beacon->mbssid_ies);
1451 kfree(link->u.ap.next_beacon);
1452 link->u.ap.next_beacon = NULL;
1455 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1456 unsigned int link_id)
1458 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1459 struct ieee80211_sub_if_data *vlan;
1460 struct ieee80211_local *local = sdata->local;
1461 struct beacon_data *old_beacon;
1462 struct probe_resp *old_probe_resp;
1463 struct fils_discovery_data *old_fils_discovery;
1464 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1465 struct cfg80211_chan_def chandef;
1466 struct ieee80211_link_data *link =
1467 sdata_dereference(sdata->link[link_id], sdata);
1468 struct ieee80211_bss_conf *link_conf = link->conf;
1470 sdata_assert_lock(sdata);
1472 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1475 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1477 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1479 old_unsol_bcast_probe_resp =
1480 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1483 /* abort any running channel switch or color change */
1484 mutex_lock(&local->mtx);
1485 link_conf->csa_active = false;
1486 link_conf->color_change_active = false;
1487 if (link->csa_block_tx) {
1488 ieee80211_wake_vif_queues(local, sdata,
1489 IEEE80211_QUEUE_STOP_REASON_CSA);
1490 link->csa_block_tx = false;
1493 mutex_unlock(&local->mtx);
1495 ieee80211_free_next_beacon(link);
1497 /* turn off carrier for this interface and dependent VLANs */
1498 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1499 netif_carrier_off(vlan->dev);
1500 netif_carrier_off(dev);
1502 /* remove beacon and probe response */
1503 sdata->u.ap.active = false;
1504 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1505 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1506 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1507 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1508 kfree_rcu(old_beacon, rcu_head);
1510 kfree_rcu(old_probe_resp, rcu_head);
1511 if (old_fils_discovery)
1512 kfree_rcu(old_fils_discovery, rcu_head);
1513 if (old_unsol_bcast_probe_resp)
1514 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1516 kfree(link_conf->ftmr_params);
1517 link_conf->ftmr_params = NULL;
1519 sdata->vif.mbssid_tx_vif = NULL;
1520 link_conf->bssid_index = 0;
1521 link_conf->nontransmitted = false;
1522 link_conf->ema_ap = false;
1523 link_conf->bssid_indicator = 0;
1525 __sta_info_flush(sdata, true);
1526 ieee80211_free_keys(sdata, true);
1528 link_conf->enable_beacon = false;
1529 sdata->beacon_rate_set = false;
1530 sdata->vif.cfg.ssid_len = 0;
1531 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1532 ieee80211_link_info_change_notify(sdata, link,
1533 BSS_CHANGED_BEACON_ENABLED);
1535 if (sdata->wdev.cac_started) {
1536 chandef = link_conf->chandef;
1537 cancel_delayed_work_sync(&link->dfs_cac_timer_work);
1538 cfg80211_cac_event(sdata->dev, &chandef,
1539 NL80211_RADAR_CAC_ABORTED,
1543 drv_stop_ap(sdata->local, sdata, link_conf);
1545 /* free all potentially still buffered bcast frames */
1546 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1547 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1549 mutex_lock(&local->mtx);
1550 ieee80211_link_copy_chanctx_to_vlans(link, true);
1551 ieee80211_link_release_channel(link);
1552 mutex_unlock(&local->mtx);
1557 static int sta_apply_auth_flags(struct ieee80211_local *local,
1558 struct sta_info *sta,
1563 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1564 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1565 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1566 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1571 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1572 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1573 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1575 * When peer becomes associated, init rate control as
1576 * well. Some drivers require rate control initialized
1577 * before drv_sta_state() is called.
1579 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1580 rate_control_rate_init(sta);
1582 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1587 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1588 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1589 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1590 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1591 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1598 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1599 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1600 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1601 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1606 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1607 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1608 test_sta_flag(sta, WLAN_STA_AUTH)) {
1609 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1617 static void sta_apply_mesh_params(struct ieee80211_local *local,
1618 struct sta_info *sta,
1619 struct station_parameters *params)
1621 #ifdef CONFIG_MAC80211_MESH
1622 struct ieee80211_sub_if_data *sdata = sta->sdata;
1625 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1626 switch (params->plink_state) {
1627 case NL80211_PLINK_ESTAB:
1628 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1629 changed = mesh_plink_inc_estab_count(sdata);
1630 sta->mesh->plink_state = params->plink_state;
1631 sta->mesh->aid = params->peer_aid;
1633 ieee80211_mps_sta_status_update(sta);
1634 changed |= ieee80211_mps_set_sta_local_pm(sta,
1635 sdata->u.mesh.mshcfg.power_mode);
1637 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1638 /* init at low value */
1639 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1642 case NL80211_PLINK_LISTEN:
1643 case NL80211_PLINK_BLOCKED:
1644 case NL80211_PLINK_OPN_SNT:
1645 case NL80211_PLINK_OPN_RCVD:
1646 case NL80211_PLINK_CNF_RCVD:
1647 case NL80211_PLINK_HOLDING:
1648 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1649 changed = mesh_plink_dec_estab_count(sdata);
1650 sta->mesh->plink_state = params->plink_state;
1652 ieee80211_mps_sta_status_update(sta);
1653 changed |= ieee80211_mps_set_sta_local_pm(sta,
1654 NL80211_MESH_POWER_UNKNOWN);
1662 switch (params->plink_action) {
1663 case NL80211_PLINK_ACTION_NO_ACTION:
1666 case NL80211_PLINK_ACTION_OPEN:
1667 changed |= mesh_plink_open(sta);
1669 case NL80211_PLINK_ACTION_BLOCK:
1670 changed |= mesh_plink_block(sta);
1674 if (params->local_pm)
1675 changed |= ieee80211_mps_set_sta_local_pm(sta,
1678 ieee80211_mbss_info_change_notify(sdata, changed);
1682 static int sta_link_apply_parameters(struct ieee80211_local *local,
1683 struct sta_info *sta, bool new_link,
1684 struct link_station_parameters *params)
1687 struct ieee80211_supported_band *sband;
1688 struct ieee80211_sub_if_data *sdata = sta->sdata;
1689 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1690 struct ieee80211_link_data *link =
1691 sdata_dereference(sdata->link[link_id], sdata);
1692 struct link_sta_info *link_sta =
1693 rcu_dereference_protected(sta->link[link_id],
1694 lockdep_is_held(&local->sta_mtx));
1697 * If there are no changes, then accept a link that exist,
1698 * unless it's a new link.
1700 if (params->link_id >= 0 && !new_link &&
1701 !params->link_mac && !params->txpwr_set &&
1702 !params->supported_rates_len &&
1703 !params->ht_capa && !params->vht_capa &&
1704 !params->he_capa && !params->eht_capa &&
1705 !params->opmode_notif_used)
1708 if (!link || !link_sta)
1711 sband = ieee80211_get_link_sband(link);
1715 if (params->link_mac) {
1717 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1718 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1719 } else if (!ether_addr_equal(link_sta->addr,
1720 params->link_mac)) {
1723 } else if (new_link) {
1727 if (params->txpwr_set) {
1728 link_sta->pub->txpwr.type = params->txpwr.type;
1729 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1730 link_sta->pub->txpwr.power = params->txpwr.power;
1731 ret = drv_sta_set_txpwr(local, sdata, sta);
1736 if (params->supported_rates &&
1737 params->supported_rates_len) {
1738 ieee80211_parse_bitrates(link->conf->chandef.width,
1739 sband, params->supported_rates,
1740 params->supported_rates_len,
1741 &link_sta->pub->supp_rates[sband->band]);
1744 if (params->ht_capa)
1745 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1746 params->ht_capa, link_sta);
1748 /* VHT can override some HT caps such as the A-MSDU max length */
1749 if (params->vht_capa)
1750 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1751 params->vht_capa, NULL,
1754 if (params->he_capa)
1755 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1756 (void *)params->he_capa,
1757 params->he_capa_len,
1758 (void *)params->he_6ghz_capa,
1761 if (params->eht_capa)
1762 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1763 (u8 *)params->he_capa,
1764 params->he_capa_len,
1766 params->eht_capa_len,
1769 if (params->opmode_notif_used) {
1770 /* returned value is only needed for rc update, but the
1771 * rc isn't initialized here yet, so ignore it
1773 __ieee80211_vht_handle_opmode(sdata, link_sta,
1774 params->opmode_notif,
1778 ieee80211_sta_set_rx_nss(link_sta);
1783 static int sta_apply_parameters(struct ieee80211_local *local,
1784 struct sta_info *sta,
1785 struct station_parameters *params)
1787 struct ieee80211_sub_if_data *sdata = sta->sdata;
1791 mask = params->sta_flags_mask;
1792 set = params->sta_flags_set;
1794 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1796 * In mesh mode, ASSOCIATED isn't part of the nl80211
1797 * API but must follow AUTHENTICATED for driver state.
1799 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1800 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1801 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1802 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1803 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1805 * TDLS -- everything follows authorized, but
1806 * only becoming authorized is possible, not
1809 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1810 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1811 BIT(NL80211_STA_FLAG_ASSOCIATED);
1812 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1813 BIT(NL80211_STA_FLAG_ASSOCIATED);
1817 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1818 local->hw.queues >= IEEE80211_NUM_ACS)
1819 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1821 /* auth flags will be set later for TDLS,
1822 * and for unassociated stations that move to associated */
1823 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1824 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1825 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1826 ret = sta_apply_auth_flags(local, sta, mask, set);
1831 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1832 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1833 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1835 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1838 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1839 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1840 if (set & BIT(NL80211_STA_FLAG_MFP))
1841 set_sta_flag(sta, WLAN_STA_MFP);
1843 clear_sta_flag(sta, WLAN_STA_MFP);
1846 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1847 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1848 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1850 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1853 /* mark TDLS channel switch support, if the AP allows it */
1854 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1855 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
1856 params->ext_capab_len >= 4 &&
1857 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1858 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1860 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1861 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1862 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1863 params->ext_capab_len >= 8 &&
1864 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1865 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1867 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1868 sta->sta.uapsd_queues = params->uapsd_queues;
1869 sta->sta.max_sp = params->max_sp;
1872 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
1873 params->ext_capab_len);
1876 * cfg80211 validates this (1-2007) and allows setting the AID
1877 * only when creating a new station entry
1880 sta->sta.aid = params->aid;
1883 * Some of the following updates would be racy if called on an
1884 * existing station, via ieee80211_change_station(). However,
1885 * all such changes are rejected by cfg80211 except for updates
1886 * changing the supported rates on an existing but not yet used
1890 if (params->listen_interval >= 0)
1891 sta->listen_interval = params->listen_interval;
1893 ret = sta_link_apply_parameters(local, sta, false,
1894 ¶ms->link_sta_params);
1898 if (params->support_p2p_ps >= 0)
1899 sta->sta.support_p2p_ps = params->support_p2p_ps;
1901 if (ieee80211_vif_is_mesh(&sdata->vif))
1902 sta_apply_mesh_params(local, sta, params);
1904 if (params->airtime_weight)
1905 sta->airtime_weight = params->airtime_weight;
1907 /* set the STA state after all sta info from usermode has been set */
1908 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1909 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1910 ret = sta_apply_auth_flags(local, sta, mask, set);
1915 /* Mark the STA as MLO if MLD MAC address is available */
1916 if (params->link_sta_params.mld_mac)
1917 sta->sta.mlo = true;
1922 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1924 struct station_parameters *params)
1926 struct ieee80211_local *local = wiphy_priv(wiphy);
1927 struct sta_info *sta;
1928 struct ieee80211_sub_if_data *sdata;
1932 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1934 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1935 sdata->vif.type != NL80211_IFTYPE_AP)
1938 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1940 if (ether_addr_equal(mac, sdata->vif.addr))
1943 if (!is_valid_ether_addr(mac))
1946 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1947 sdata->vif.type == NL80211_IFTYPE_STATION &&
1948 !sdata->u.mgd.associated)
1952 * If we have a link ID, it can be a non-MLO station on an AP MLD,
1953 * but we need to have a link_mac in that case as well, so use the
1954 * STA's MAC address in that case.
1956 if (params->link_sta_params.link_id >= 0)
1957 sta = sta_info_alloc_with_link(sdata, mac,
1958 params->link_sta_params.link_id,
1959 params->link_sta_params.link_mac ?: mac,
1962 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1967 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1968 sta->sta.tdls = true;
1970 /* Though the mutex is not needed here (since the station is not
1971 * visible yet), sta_apply_parameters (and inner functions) require
1972 * the mutex due to other paths.
1974 mutex_lock(&local->sta_mtx);
1975 err = sta_apply_parameters(local, sta, params);
1976 mutex_unlock(&local->sta_mtx);
1978 sta_info_free(local, sta);
1983 * for TDLS and for unassociated station, rate control should be
1984 * initialized only when rates are known and station is marked
1985 * authorized/associated
1987 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1988 test_sta_flag(sta, WLAN_STA_ASSOC))
1989 rate_control_rate_init(sta);
1991 return sta_info_insert(sta);
1994 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1995 struct station_del_parameters *params)
1997 struct ieee80211_sub_if_data *sdata;
1999 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2002 return sta_info_destroy_addr_bss(sdata, params->mac);
2004 sta_info_flush(sdata);
2008 static int ieee80211_change_station(struct wiphy *wiphy,
2009 struct net_device *dev, const u8 *mac,
2010 struct station_parameters *params)
2012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2013 struct ieee80211_local *local = wiphy_priv(wiphy);
2014 struct sta_info *sta;
2015 struct ieee80211_sub_if_data *vlansdata;
2016 enum cfg80211_station_type statype;
2019 mutex_lock(&local->sta_mtx);
2021 sta = sta_info_get_bss(sdata, mac);
2027 switch (sdata->vif.type) {
2028 case NL80211_IFTYPE_MESH_POINT:
2029 if (sdata->u.mesh.user_mpm)
2030 statype = CFG80211_STA_MESH_PEER_USER;
2032 statype = CFG80211_STA_MESH_PEER_KERNEL;
2034 case NL80211_IFTYPE_ADHOC:
2035 statype = CFG80211_STA_IBSS;
2037 case NL80211_IFTYPE_STATION:
2038 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2039 statype = CFG80211_STA_AP_STA;
2042 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2043 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2045 statype = CFG80211_STA_TDLS_PEER_SETUP;
2047 case NL80211_IFTYPE_AP:
2048 case NL80211_IFTYPE_AP_VLAN:
2049 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2050 statype = CFG80211_STA_AP_CLIENT;
2052 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2059 err = cfg80211_check_station_change(wiphy, params, statype);
2063 if (params->vlan && params->vlan != sta->sdata->dev) {
2064 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2066 if (params->vlan->ieee80211_ptr->use_4addr) {
2067 if (vlansdata->u.vlan.sta) {
2072 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
2073 __ieee80211_check_fast_rx_iface(vlansdata);
2074 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2077 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2078 sta->sdata->u.vlan.sta)
2079 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2081 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2082 ieee80211_vif_dec_num_mcast(sta->sdata);
2084 sta->sdata = vlansdata;
2085 ieee80211_check_fast_rx(sta);
2086 ieee80211_check_fast_xmit(sta);
2088 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2089 ieee80211_vif_inc_num_mcast(sta->sdata);
2090 cfg80211_send_layer2_update(sta->sdata->dev,
2095 /* we use sta_info_get_bss() so this might be different */
2096 if (sdata != sta->sdata) {
2097 mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
2098 err = sta_apply_parameters(local, sta, params);
2099 mutex_unlock(&sta->sdata->wdev.mtx);
2101 err = sta_apply_parameters(local, sta, params);
2106 mutex_unlock(&local->sta_mtx);
2108 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2109 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2110 ieee80211_recalc_ps(local);
2111 ieee80211_recalc_ps_vif(sdata);
2116 mutex_unlock(&local->sta_mtx);
2120 #ifdef CONFIG_MAC80211_MESH
2121 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2122 const u8 *dst, const u8 *next_hop)
2124 struct ieee80211_sub_if_data *sdata;
2125 struct mesh_path *mpath;
2126 struct sta_info *sta;
2128 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2131 sta = sta_info_get(sdata, next_hop);
2137 mpath = mesh_path_add(sdata, dst);
2138 if (IS_ERR(mpath)) {
2140 return PTR_ERR(mpath);
2143 mesh_path_fix_nexthop(mpath, sta);
2149 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2152 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2155 return mesh_path_del(sdata, dst);
2157 mesh_path_flush_by_iface(sdata);
2161 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2162 const u8 *dst, const u8 *next_hop)
2164 struct ieee80211_sub_if_data *sdata;
2165 struct mesh_path *mpath;
2166 struct sta_info *sta;
2168 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2172 sta = sta_info_get(sdata, next_hop);
2178 mpath = mesh_path_lookup(sdata, dst);
2184 mesh_path_fix_nexthop(mpath, sta);
2190 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2191 struct mpath_info *pinfo)
2193 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2196 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2198 eth_zero_addr(next_hop);
2200 memset(pinfo, 0, sizeof(*pinfo));
2202 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2204 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2207 MPATH_INFO_EXPTIME |
2208 MPATH_INFO_DISCOVERY_TIMEOUT |
2209 MPATH_INFO_DISCOVERY_RETRIES |
2211 MPATH_INFO_HOP_COUNT |
2212 MPATH_INFO_PATH_CHANGE;
2214 pinfo->frame_qlen = mpath->frame_queue.qlen;
2215 pinfo->sn = mpath->sn;
2216 pinfo->metric = mpath->metric;
2217 if (time_before(jiffies, mpath->exp_time))
2218 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2219 pinfo->discovery_timeout =
2220 jiffies_to_msecs(mpath->discovery_timeout);
2221 pinfo->discovery_retries = mpath->discovery_retries;
2222 if (mpath->flags & MESH_PATH_ACTIVE)
2223 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2224 if (mpath->flags & MESH_PATH_RESOLVING)
2225 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2226 if (mpath->flags & MESH_PATH_SN_VALID)
2227 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2228 if (mpath->flags & MESH_PATH_FIXED)
2229 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2230 if (mpath->flags & MESH_PATH_RESOLVED)
2231 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2232 pinfo->hop_count = mpath->hop_count;
2233 pinfo->path_change_count = mpath->path_change_count;
2236 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2237 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2240 struct ieee80211_sub_if_data *sdata;
2241 struct mesh_path *mpath;
2243 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2246 mpath = mesh_path_lookup(sdata, dst);
2251 memcpy(dst, mpath->dst, ETH_ALEN);
2252 mpath_set_pinfo(mpath, next_hop, pinfo);
2257 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2258 int idx, u8 *dst, u8 *next_hop,
2259 struct mpath_info *pinfo)
2261 struct ieee80211_sub_if_data *sdata;
2262 struct mesh_path *mpath;
2264 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2267 mpath = mesh_path_lookup_by_idx(sdata, idx);
2272 memcpy(dst, mpath->dst, ETH_ALEN);
2273 mpath_set_pinfo(mpath, next_hop, pinfo);
2278 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2279 struct mpath_info *pinfo)
2281 memset(pinfo, 0, sizeof(*pinfo));
2282 memcpy(mpp, mpath->mpp, ETH_ALEN);
2284 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2287 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2288 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2291 struct ieee80211_sub_if_data *sdata;
2292 struct mesh_path *mpath;
2294 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2297 mpath = mpp_path_lookup(sdata, dst);
2302 memcpy(dst, mpath->dst, ETH_ALEN);
2303 mpp_set_pinfo(mpath, mpp, pinfo);
2308 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2309 int idx, u8 *dst, u8 *mpp,
2310 struct mpath_info *pinfo)
2312 struct ieee80211_sub_if_data *sdata;
2313 struct mesh_path *mpath;
2315 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2318 mpath = mpp_path_lookup_by_idx(sdata, idx);
2323 memcpy(dst, mpath->dst, ETH_ALEN);
2324 mpp_set_pinfo(mpath, mpp, pinfo);
2329 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2330 struct net_device *dev,
2331 struct mesh_config *conf)
2333 struct ieee80211_sub_if_data *sdata;
2334 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2336 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2340 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2342 return (mask >> (parm-1)) & 0x1;
2345 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2346 const struct mesh_setup *setup)
2349 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2350 struct ieee80211_sub_if_data, u.mesh);
2353 /* allocate information elements */
2356 if (setup->ie_len) {
2357 new_ie = kmemdup(setup->ie, setup->ie_len,
2362 ifmsh->ie_len = setup->ie_len;
2365 /* now copy the rest of the setup parameters */
2366 ifmsh->mesh_id_len = setup->mesh_id_len;
2367 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2368 ifmsh->mesh_sp_id = setup->sync_method;
2369 ifmsh->mesh_pp_id = setup->path_sel_proto;
2370 ifmsh->mesh_pm_id = setup->path_metric;
2371 ifmsh->user_mpm = setup->user_mpm;
2372 ifmsh->mesh_auth_id = setup->auth_id;
2373 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2374 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2375 if (setup->is_authenticated)
2376 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2377 if (setup->is_secure)
2378 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2380 /* mcast rate setting in Mesh Node */
2381 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2382 sizeof(setup->mcast_rate));
2383 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2385 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2386 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2388 sdata->beacon_rate_set = false;
2389 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2390 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2391 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2392 sdata->beacon_rateidx_mask[i] =
2393 setup->beacon_rate.control[i].legacy;
2394 if (sdata->beacon_rateidx_mask[i])
2395 sdata->beacon_rate_set = true;
2402 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2403 struct net_device *dev, u32 mask,
2404 const struct mesh_config *nconf)
2406 struct mesh_config *conf;
2407 struct ieee80211_sub_if_data *sdata;
2408 struct ieee80211_if_mesh *ifmsh;
2410 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2411 ifmsh = &sdata->u.mesh;
2413 /* Set the config options which we are interested in setting */
2414 conf = &(sdata->u.mesh.mshcfg);
2415 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2416 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2417 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2418 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2419 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2420 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2421 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2422 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2423 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2424 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2425 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2426 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2427 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2428 conf->element_ttl = nconf->element_ttl;
2429 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2430 if (ifmsh->user_mpm)
2432 conf->auto_open_plinks = nconf->auto_open_plinks;
2434 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2435 conf->dot11MeshNbrOffsetMaxNeighbor =
2436 nconf->dot11MeshNbrOffsetMaxNeighbor;
2437 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2438 conf->dot11MeshHWMPmaxPREQretries =
2439 nconf->dot11MeshHWMPmaxPREQretries;
2440 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2441 conf->path_refresh_time = nconf->path_refresh_time;
2442 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2443 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2444 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2445 conf->dot11MeshHWMPactivePathTimeout =
2446 nconf->dot11MeshHWMPactivePathTimeout;
2447 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2448 conf->dot11MeshHWMPpreqMinInterval =
2449 nconf->dot11MeshHWMPpreqMinInterval;
2450 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2451 conf->dot11MeshHWMPperrMinInterval =
2452 nconf->dot11MeshHWMPperrMinInterval;
2453 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2455 conf->dot11MeshHWMPnetDiameterTraversalTime =
2456 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2457 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2458 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2459 ieee80211_mesh_root_setup(ifmsh);
2461 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2462 /* our current gate announcement implementation rides on root
2463 * announcements, so require this ifmsh to also be a root node
2465 if (nconf->dot11MeshGateAnnouncementProtocol &&
2466 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2467 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2468 ieee80211_mesh_root_setup(ifmsh);
2470 conf->dot11MeshGateAnnouncementProtocol =
2471 nconf->dot11MeshGateAnnouncementProtocol;
2473 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2474 conf->dot11MeshHWMPRannInterval =
2475 nconf->dot11MeshHWMPRannInterval;
2476 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2477 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2478 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2479 /* our RSSI threshold implementation is supported only for
2480 * devices that report signal in dBm.
2482 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2484 conf->rssi_threshold = nconf->rssi_threshold;
2486 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2487 conf->ht_opmode = nconf->ht_opmode;
2488 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2489 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2492 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2493 conf->dot11MeshHWMPactivePathToRootTimeout =
2494 nconf->dot11MeshHWMPactivePathToRootTimeout;
2495 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2496 conf->dot11MeshHWMProotInterval =
2497 nconf->dot11MeshHWMProotInterval;
2498 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2499 conf->dot11MeshHWMPconfirmationInterval =
2500 nconf->dot11MeshHWMPconfirmationInterval;
2501 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2502 conf->power_mode = nconf->power_mode;
2503 ieee80211_mps_local_status_update(sdata);
2505 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2506 conf->dot11MeshAwakeWindowDuration =
2507 nconf->dot11MeshAwakeWindowDuration;
2508 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2509 conf->plink_timeout = nconf->plink_timeout;
2510 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2511 conf->dot11MeshConnectedToMeshGate =
2512 nconf->dot11MeshConnectedToMeshGate;
2513 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2514 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2515 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2516 conf->dot11MeshConnectedToAuthServer =
2517 nconf->dot11MeshConnectedToAuthServer;
2518 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2522 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2523 const struct mesh_config *conf,
2524 const struct mesh_setup *setup)
2526 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2527 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2530 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2531 err = copy_mesh_setup(ifmsh, setup);
2535 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2537 /* can mesh use other SMPS modes? */
2538 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2539 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2541 mutex_lock(&sdata->local->mtx);
2542 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
2543 IEEE80211_CHANCTX_SHARED);
2544 mutex_unlock(&sdata->local->mtx);
2548 return ieee80211_start_mesh(sdata);
2551 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2553 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2555 ieee80211_stop_mesh(sdata);
2556 mutex_lock(&sdata->local->mtx);
2557 ieee80211_link_release_channel(&sdata->deflink);
2558 kfree(sdata->u.mesh.ie);
2559 mutex_unlock(&sdata->local->mtx);
2565 static int ieee80211_change_bss(struct wiphy *wiphy,
2566 struct net_device *dev,
2567 struct bss_parameters *params)
2569 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2570 struct ieee80211_supported_band *sband;
2573 if (!sdata_dereference(sdata->deflink.u.ap.beacon, sdata))
2576 sband = ieee80211_get_sband(sdata);
2580 if (params->use_cts_prot >= 0) {
2581 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2582 changed |= BSS_CHANGED_ERP_CTS_PROT;
2584 if (params->use_short_preamble >= 0) {
2585 sdata->vif.bss_conf.use_short_preamble =
2586 params->use_short_preamble;
2587 changed |= BSS_CHANGED_ERP_PREAMBLE;
2590 if (!sdata->vif.bss_conf.use_short_slot &&
2591 (sband->band == NL80211_BAND_5GHZ ||
2592 sband->band == NL80211_BAND_6GHZ)) {
2593 sdata->vif.bss_conf.use_short_slot = true;
2594 changed |= BSS_CHANGED_ERP_SLOT;
2597 if (params->use_short_slot_time >= 0) {
2598 sdata->vif.bss_conf.use_short_slot =
2599 params->use_short_slot_time;
2600 changed |= BSS_CHANGED_ERP_SLOT;
2603 if (params->basic_rates) {
2604 ieee80211_parse_bitrates(sdata->vif.bss_conf.chandef.width,
2605 wiphy->bands[sband->band],
2606 params->basic_rates,
2607 params->basic_rates_len,
2608 &sdata->vif.bss_conf.basic_rates);
2609 changed |= BSS_CHANGED_BASIC_RATES;
2610 ieee80211_check_rate_mask(&sdata->deflink);
2613 if (params->ap_isolate >= 0) {
2614 if (params->ap_isolate)
2615 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2617 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2618 ieee80211_check_fast_rx_iface(sdata);
2621 if (params->ht_opmode >= 0) {
2622 sdata->vif.bss_conf.ht_operation_mode =
2623 (u16) params->ht_opmode;
2624 changed |= BSS_CHANGED_HT;
2627 if (params->p2p_ctwindow >= 0) {
2628 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2629 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2630 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2631 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2632 changed |= BSS_CHANGED_P2P_PS;
2635 if (params->p2p_opp_ps > 0) {
2636 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2637 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2638 changed |= BSS_CHANGED_P2P_PS;
2639 } else if (params->p2p_opp_ps == 0) {
2640 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2641 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2642 changed |= BSS_CHANGED_P2P_PS;
2645 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
2650 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2651 struct net_device *dev,
2652 struct ieee80211_txq_params *params)
2654 struct ieee80211_local *local = wiphy_priv(wiphy);
2655 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2656 struct ieee80211_link_data *link =
2657 ieee80211_link_or_deflink(sdata, params->link_id, true);
2658 struct ieee80211_tx_queue_params p;
2660 if (!local->ops->conf_tx)
2663 if (local->hw.queues < IEEE80211_NUM_ACS)
2667 return PTR_ERR(link);
2669 memset(&p, 0, sizeof(p));
2670 p.aifs = params->aifs;
2671 p.cw_max = params->cwmax;
2672 p.cw_min = params->cwmin;
2673 p.txop = params->txop;
2676 * Setting tx queue params disables u-apsd because it's only
2677 * called in master mode.
2681 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2683 link->tx_conf[params->ac] = p;
2684 if (drv_conf_tx(local, link, params->ac, &p)) {
2685 wiphy_debug(local->hw.wiphy,
2686 "failed to set TX queue parameters for AC %d\n",
2691 ieee80211_link_info_change_notify(sdata, link,
2698 static int ieee80211_suspend(struct wiphy *wiphy,
2699 struct cfg80211_wowlan *wowlan)
2701 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2704 static int ieee80211_resume(struct wiphy *wiphy)
2706 return __ieee80211_resume(wiphy_priv(wiphy));
2709 #define ieee80211_suspend NULL
2710 #define ieee80211_resume NULL
2713 static int ieee80211_scan(struct wiphy *wiphy,
2714 struct cfg80211_scan_request *req)
2716 struct ieee80211_sub_if_data *sdata;
2718 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2720 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2721 case NL80211_IFTYPE_STATION:
2722 case NL80211_IFTYPE_ADHOC:
2723 case NL80211_IFTYPE_MESH_POINT:
2724 case NL80211_IFTYPE_P2P_CLIENT:
2725 case NL80211_IFTYPE_P2P_DEVICE:
2727 case NL80211_IFTYPE_P2P_GO:
2728 if (sdata->local->ops->hw_scan)
2731 * FIXME: implement NoA while scanning in software,
2732 * for now fall through to allow scanning only when
2733 * beaconing hasn't been configured yet
2736 case NL80211_IFTYPE_AP:
2738 * If the scan has been forced (and the driver supports
2739 * forcing), don't care about being beaconing already.
2740 * This will create problems to the attached stations (e.g. all
2741 * the frames sent while scanning on other channel will be
2744 if (sdata->deflink.u.ap.beacon &&
2745 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2746 !(req->flags & NL80211_SCAN_FLAG_AP)))
2749 case NL80211_IFTYPE_NAN:
2754 return ieee80211_request_scan(sdata, req);
2757 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2759 ieee80211_scan_cancel(wiphy_priv(wiphy));
2763 ieee80211_sched_scan_start(struct wiphy *wiphy,
2764 struct net_device *dev,
2765 struct cfg80211_sched_scan_request *req)
2767 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2769 if (!sdata->local->ops->sched_scan_start)
2772 return ieee80211_request_sched_scan_start(sdata, req);
2776 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2779 struct ieee80211_local *local = wiphy_priv(wiphy);
2781 if (!local->ops->sched_scan_stop)
2784 return ieee80211_request_sched_scan_stop(local);
2787 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2788 struct cfg80211_auth_request *req)
2790 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2793 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2794 struct cfg80211_assoc_request *req)
2796 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2799 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2800 struct cfg80211_deauth_request *req)
2802 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2805 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2806 struct cfg80211_disassoc_request *req)
2808 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2811 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2812 struct cfg80211_ibss_params *params)
2814 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2817 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2819 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2822 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2823 struct ocb_setup *setup)
2825 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2828 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2830 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2833 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2834 int rate[NUM_NL80211_BANDS])
2836 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2838 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2839 sizeof(int) * NUM_NL80211_BANDS);
2841 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2842 BSS_CHANGED_MCAST_RATE);
2847 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2849 struct ieee80211_local *local = wiphy_priv(wiphy);
2852 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2853 ieee80211_check_fast_xmit_all(local);
2855 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2858 ieee80211_check_fast_xmit_all(local);
2863 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2864 (changed & WIPHY_PARAM_DYN_ACK)) {
2867 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2868 wiphy->coverage_class : -1;
2869 err = drv_set_coverage_class(local, coverage_class);
2875 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2876 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2882 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2883 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2885 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2887 if (changed & WIPHY_PARAM_RETRY_LONG) {
2888 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2890 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2893 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2894 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2896 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2897 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2898 WIPHY_PARAM_TXQ_QUANTUM))
2899 ieee80211_txq_set_params(local);
2904 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2905 struct wireless_dev *wdev,
2906 enum nl80211_tx_power_setting type, int mbm)
2908 struct ieee80211_local *local = wiphy_priv(wiphy);
2909 struct ieee80211_sub_if_data *sdata;
2910 enum nl80211_tx_power_setting txp_type = type;
2911 bool update_txp_type = false;
2912 bool has_monitor = false;
2915 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2917 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2918 sdata = wiphy_dereference(local->hw.wiphy,
2919 local->monitor_sdata);
2925 case NL80211_TX_POWER_AUTOMATIC:
2926 sdata->deflink.user_power_level =
2927 IEEE80211_UNSET_POWER_LEVEL;
2928 txp_type = NL80211_TX_POWER_LIMITED;
2930 case NL80211_TX_POWER_LIMITED:
2931 case NL80211_TX_POWER_FIXED:
2932 if (mbm < 0 || (mbm % 100))
2934 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
2938 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2939 update_txp_type = true;
2940 sdata->vif.bss_conf.txpower_type = txp_type;
2943 ieee80211_recalc_txpower(sdata, update_txp_type);
2949 case NL80211_TX_POWER_AUTOMATIC:
2950 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2951 txp_type = NL80211_TX_POWER_LIMITED;
2953 case NL80211_TX_POWER_LIMITED:
2954 case NL80211_TX_POWER_FIXED:
2955 if (mbm < 0 || (mbm % 100))
2957 local->user_power_level = MBM_TO_DBM(mbm);
2961 mutex_lock(&local->iflist_mtx);
2962 list_for_each_entry(sdata, &local->interfaces, list) {
2963 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2967 sdata->deflink.user_power_level = local->user_power_level;
2968 if (txp_type != sdata->vif.bss_conf.txpower_type)
2969 update_txp_type = true;
2970 sdata->vif.bss_conf.txpower_type = txp_type;
2972 list_for_each_entry(sdata, &local->interfaces, list) {
2973 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2975 ieee80211_recalc_txpower(sdata, update_txp_type);
2977 mutex_unlock(&local->iflist_mtx);
2980 sdata = wiphy_dereference(local->hw.wiphy,
2981 local->monitor_sdata);
2983 sdata->deflink.user_power_level = local->user_power_level;
2984 if (txp_type != sdata->vif.bss_conf.txpower_type)
2985 update_txp_type = true;
2986 sdata->vif.bss_conf.txpower_type = txp_type;
2988 ieee80211_recalc_txpower(sdata, update_txp_type);
2995 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2996 struct wireless_dev *wdev,
2999 struct ieee80211_local *local = wiphy_priv(wiphy);
3000 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3002 if (local->ops->get_txpower)
3003 return drv_get_txpower(local, sdata, dbm);
3005 if (!local->use_chanctx)
3006 *dbm = local->hw.conf.power_level;
3008 *dbm = sdata->vif.bss_conf.txpower;
3010 /* INT_MIN indicates no power level was set yet */
3011 if (*dbm == INT_MIN)
3017 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
3019 struct ieee80211_local *local = wiphy_priv(wiphy);
3021 drv_rfkill_poll(local);
3024 #ifdef CONFIG_NL80211_TESTMODE
3025 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3026 struct wireless_dev *wdev,
3027 void *data, int len)
3029 struct ieee80211_local *local = wiphy_priv(wiphy);
3030 struct ieee80211_vif *vif = NULL;
3032 if (!local->ops->testmode_cmd)
3036 struct ieee80211_sub_if_data *sdata;
3038 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3039 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3043 return local->ops->testmode_cmd(&local->hw, vif, data, len);
3046 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3047 struct sk_buff *skb,
3048 struct netlink_callback *cb,
3049 void *data, int len)
3051 struct ieee80211_local *local = wiphy_priv(wiphy);
3053 if (!local->ops->testmode_dump)
3056 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3060 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3061 struct ieee80211_link_data *link,
3062 enum ieee80211_smps_mode smps_mode)
3065 enum ieee80211_smps_mode old_req;
3067 struct sta_info *sta;
3068 bool tdls_peer_found = false;
3070 lockdep_assert_held(&sdata->wdev.mtx);
3072 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3075 old_req = link->u.mgd.req_smps;
3076 link->u.mgd.req_smps = smps_mode;
3078 if (old_req == smps_mode &&
3079 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3083 * If not associated, or current association is not an HT
3084 * association, there's no need to do anything, just store
3085 * the new value until we associate.
3087 if (!sdata->u.mgd.associated ||
3088 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
3091 ap = link->u.mgd.bssid;
3094 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3095 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3096 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3099 tdls_peer_found = true;
3104 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3105 if (tdls_peer_found || !sdata->u.mgd.powersave)
3106 smps_mode = IEEE80211_SMPS_OFF;
3108 smps_mode = IEEE80211_SMPS_DYNAMIC;
3111 /* send SM PS frame to AP */
3112 err = ieee80211_send_smps_action(sdata, smps_mode,
3115 link->u.mgd.req_smps = old_req;
3116 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3117 ieee80211_teardown_tdls_peers(sdata);
3122 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3123 bool enabled, int timeout)
3125 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3126 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3127 unsigned int link_id;
3129 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3132 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3135 if (enabled == sdata->u.mgd.powersave &&
3136 timeout == local->dynamic_ps_forced_timeout)
3139 sdata->u.mgd.powersave = enabled;
3140 local->dynamic_ps_forced_timeout = timeout;
3142 /* no change, but if automatic follow powersave */
3144 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3145 struct ieee80211_link_data *link;
3147 link = sdata_dereference(sdata->link[link_id], sdata);
3151 __ieee80211_request_smps_mgd(sdata, link,
3152 link->u.mgd.req_smps);
3154 sdata_unlock(sdata);
3156 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3157 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3159 ieee80211_recalc_ps(local);
3160 ieee80211_recalc_ps_vif(sdata);
3161 ieee80211_check_fast_rx_iface(sdata);
3166 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3167 struct net_device *dev,
3168 s32 rssi_thold, u32 rssi_hyst)
3170 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3171 struct ieee80211_vif *vif = &sdata->vif;
3172 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3174 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3175 rssi_hyst == bss_conf->cqm_rssi_hyst)
3178 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3179 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3182 bss_conf->cqm_rssi_thold = rssi_thold;
3183 bss_conf->cqm_rssi_hyst = rssi_hyst;
3184 bss_conf->cqm_rssi_low = 0;
3185 bss_conf->cqm_rssi_high = 0;
3186 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3188 /* tell the driver upon association, unless already associated */
3189 if (sdata->u.mgd.associated &&
3190 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3191 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3197 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3198 struct net_device *dev,
3199 s32 rssi_low, s32 rssi_high)
3201 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3202 struct ieee80211_vif *vif = &sdata->vif;
3203 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3205 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3208 bss_conf->cqm_rssi_low = rssi_low;
3209 bss_conf->cqm_rssi_high = rssi_high;
3210 bss_conf->cqm_rssi_thold = 0;
3211 bss_conf->cqm_rssi_hyst = 0;
3212 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3214 /* tell the driver upon association, unless already associated */
3215 if (sdata->u.mgd.associated &&
3216 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3217 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3223 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3224 struct net_device *dev,
3225 unsigned int link_id,
3227 const struct cfg80211_bitrate_mask *mask)
3229 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3230 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3233 if (!ieee80211_sdata_running(sdata))
3237 * If active validate the setting and reject it if it doesn't leave
3238 * at least one basic rate usable, since we really have to be able
3239 * to send something, and if we're an AP we have to be able to do
3240 * so at a basic rate so that all clients can receive it.
3242 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3243 sdata->vif.bss_conf.chandef.chan) {
3244 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3245 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3247 if (!(mask->control[band].legacy & basic_rates))
3251 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3252 ret = drv_set_bitrate_mask(local, sdata, mask);
3257 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3258 struct ieee80211_supported_band *sband = wiphy->bands[i];
3261 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3262 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3263 sizeof(mask->control[i].ht_mcs));
3264 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3265 mask->control[i].vht_mcs,
3266 sizeof(mask->control[i].vht_mcs));
3268 sdata->rc_has_mcs_mask[i] = false;
3269 sdata->rc_has_vht_mcs_mask[i] = false;
3273 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3274 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3275 sdata->rc_has_mcs_mask[i] = true;
3280 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3281 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3282 sdata->rc_has_vht_mcs_mask[i] = true;
3291 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3292 struct net_device *dev,
3293 struct cfg80211_chan_def *chandef,
3296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3297 struct ieee80211_local *local = sdata->local;
3300 mutex_lock(&local->mtx);
3301 if (!list_empty(&local->roc_list) || local->scanning) {
3306 /* whatever, but channel contexts should not complain about that one */
3307 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3308 sdata->deflink.needed_rx_chains = local->rx_chains;
3310 err = ieee80211_link_use_channel(&sdata->deflink, chandef,
3311 IEEE80211_CHANCTX_SHARED);
3315 ieee80211_queue_delayed_work(&sdata->local->hw,
3316 &sdata->deflink.dfs_cac_timer_work,
3317 msecs_to_jiffies(cac_time_ms));
3320 mutex_unlock(&local->mtx);
3324 static void ieee80211_end_cac(struct wiphy *wiphy,
3325 struct net_device *dev)
3327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3328 struct ieee80211_local *local = sdata->local;
3330 mutex_lock(&local->mtx);
3331 list_for_each_entry(sdata, &local->interfaces, list) {
3332 /* it might be waiting for the local->mtx, but then
3333 * by the time it gets it, sdata->wdev.cac_started
3334 * will no longer be true
3336 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work);
3338 if (sdata->wdev.cac_started) {
3339 ieee80211_link_release_channel(&sdata->deflink);
3340 sdata->wdev.cac_started = false;
3343 mutex_unlock(&local->mtx);
3346 static struct cfg80211_beacon_data *
3347 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3349 struct cfg80211_beacon_data *new_beacon;
3353 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3354 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3355 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3356 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3358 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3362 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3363 new_beacon->mbssid_ies =
3364 kzalloc(struct_size(new_beacon->mbssid_ies,
3365 elem, beacon->mbssid_ies->cnt),
3367 if (!new_beacon->mbssid_ies) {
3373 pos = (u8 *)(new_beacon + 1);
3374 if (beacon->head_len) {
3375 new_beacon->head_len = beacon->head_len;
3376 new_beacon->head = pos;
3377 memcpy(pos, beacon->head, beacon->head_len);
3378 pos += beacon->head_len;
3380 if (beacon->tail_len) {
3381 new_beacon->tail_len = beacon->tail_len;
3382 new_beacon->tail = pos;
3383 memcpy(pos, beacon->tail, beacon->tail_len);
3384 pos += beacon->tail_len;
3386 if (beacon->beacon_ies_len) {
3387 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3388 new_beacon->beacon_ies = pos;
3389 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3390 pos += beacon->beacon_ies_len;
3392 if (beacon->proberesp_ies_len) {
3393 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3394 new_beacon->proberesp_ies = pos;
3395 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3396 pos += beacon->proberesp_ies_len;
3398 if (beacon->assocresp_ies_len) {
3399 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3400 new_beacon->assocresp_ies = pos;
3401 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3402 pos += beacon->assocresp_ies_len;
3404 if (beacon->probe_resp_len) {
3405 new_beacon->probe_resp_len = beacon->probe_resp_len;
3406 new_beacon->probe_resp = pos;
3407 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3408 pos += beacon->probe_resp_len;
3410 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3411 pos += ieee80211_copy_mbssid_beacon(pos,
3412 new_beacon->mbssid_ies,
3413 beacon->mbssid_ies);
3415 /* might copy -1, meaning no changes requested */
3416 new_beacon->ftm_responder = beacon->ftm_responder;
3418 new_beacon->lci_len = beacon->lci_len;
3419 new_beacon->lci = pos;
3420 memcpy(pos, beacon->lci, beacon->lci_len);
3421 pos += beacon->lci_len;
3423 if (beacon->civicloc) {
3424 new_beacon->civicloc_len = beacon->civicloc_len;
3425 new_beacon->civicloc = pos;
3426 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3427 pos += beacon->civicloc_len;
3433 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3435 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3436 struct ieee80211_local *local = sdata->local;
3440 if (vif->mbssid_tx_vif == vif) {
3441 /* Trigger ieee80211_csa_finish() on the non-transmitting
3442 * interfaces when channel switch is received on
3443 * transmitting interface
3445 struct ieee80211_sub_if_data *iter;
3447 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3448 if (!ieee80211_sdata_running(iter))
3451 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3454 ieee80211_queue_work(&iter->local->hw,
3455 &iter->deflink.csa_finalize_work);
3458 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
3462 EXPORT_SYMBOL(ieee80211_csa_finish);
3464 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3466 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3467 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3468 struct ieee80211_local *local = sdata->local;
3470 sdata->deflink.csa_block_tx = block_tx;
3471 sdata_info(sdata, "channel switch failed, disconnecting\n");
3472 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3474 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3476 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3481 switch (sdata->vif.type) {
3482 case NL80211_IFTYPE_AP:
3483 if (!sdata->deflink.u.ap.next_beacon)
3486 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3487 sdata->deflink.u.ap.next_beacon,
3489 ieee80211_free_next_beacon(&sdata->deflink);
3495 case NL80211_IFTYPE_ADHOC:
3496 err = ieee80211_ibss_finish_csa(sdata);
3501 #ifdef CONFIG_MAC80211_MESH
3502 case NL80211_IFTYPE_MESH_POINT:
3503 err = ieee80211_mesh_finish_csa(sdata);
3517 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3519 struct ieee80211_local *local = sdata->local;
3523 sdata_assert_lock(sdata);
3524 lockdep_assert_held(&local->mtx);
3525 lockdep_assert_held(&local->chanctx_mtx);
3528 * using reservation isn't immediate as it may be deferred until later
3529 * with multi-vif. once reservation is complete it will re-schedule the
3530 * work with no reserved_chanctx so verify chandef to check if it
3531 * completed successfully
3534 if (sdata->deflink.reserved_chanctx) {
3536 * with multi-vif csa driver may call ieee80211_csa_finish()
3537 * many times while waiting for other interfaces to use their
3540 if (sdata->deflink.reserved_ready)
3543 return ieee80211_link_use_reserved_context(&sdata->deflink);
3546 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3547 &sdata->deflink.csa_chandef))
3550 sdata->vif.bss_conf.csa_active = false;
3552 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3556 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
3558 if (sdata->deflink.csa_block_tx) {
3559 ieee80211_wake_vif_queues(local, sdata,
3560 IEEE80211_QUEUE_STOP_REASON_CSA);
3561 sdata->deflink.csa_block_tx = false;
3564 err = drv_post_channel_switch(sdata);
3568 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0);
3573 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3575 if (__ieee80211_csa_finalize(sdata)) {
3576 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3577 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3582 void ieee80211_csa_finalize_work(struct work_struct *work)
3584 struct ieee80211_sub_if_data *sdata =
3585 container_of(work, struct ieee80211_sub_if_data,
3586 deflink.csa_finalize_work);
3587 struct ieee80211_local *local = sdata->local;
3590 mutex_lock(&local->mtx);
3591 mutex_lock(&local->chanctx_mtx);
3593 /* AP might have been stopped while waiting for the lock. */
3594 if (!sdata->vif.bss_conf.csa_active)
3597 if (!ieee80211_sdata_running(sdata))
3600 ieee80211_csa_finalize(sdata);
3603 mutex_unlock(&local->chanctx_mtx);
3604 mutex_unlock(&local->mtx);
3605 sdata_unlock(sdata);
3608 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3609 struct cfg80211_csa_settings *params,
3612 struct ieee80211_csa_settings csa = {};
3615 switch (sdata->vif.type) {
3616 case NL80211_IFTYPE_AP:
3617 sdata->deflink.u.ap.next_beacon =
3618 cfg80211_beacon_dup(¶ms->beacon_after);
3619 if (!sdata->deflink.u.ap.next_beacon)
3623 * With a count of 0, we don't have to wait for any
3624 * TBTT before switching, so complete the CSA
3625 * immediately. In theory, with a count == 1 we
3626 * should delay the switch until just before the next
3627 * TBTT, but that would complicate things so we switch
3628 * immediately too. If we would delay the switch
3629 * until the next TBTT, we would have to set the probe
3632 * TODO: A channel switch with count <= 1 without
3633 * sending a CSA action frame is kind of useless,
3634 * because the clients won't know we're changing
3635 * channels. The action frame must be implemented
3636 * either here or in the userspace.
3638 if (params->count <= 1)
3641 if ((params->n_counter_offsets_beacon >
3642 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3643 (params->n_counter_offsets_presp >
3644 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3645 ieee80211_free_next_beacon(&sdata->deflink);
3649 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3650 csa.counter_offsets_presp = params->counter_offsets_presp;
3651 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3652 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3653 csa.count = params->count;
3655 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3656 ¶ms->beacon_csa, &csa,
3659 ieee80211_free_next_beacon(&sdata->deflink);
3665 case NL80211_IFTYPE_ADHOC:
3666 if (!sdata->vif.cfg.ibss_joined)
3669 if (params->chandef.width != sdata->u.ibss.chandef.width)
3672 switch (params->chandef.width) {
3673 case NL80211_CHAN_WIDTH_40:
3674 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3675 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3678 case NL80211_CHAN_WIDTH_5:
3679 case NL80211_CHAN_WIDTH_10:
3680 case NL80211_CHAN_WIDTH_20_NOHT:
3681 case NL80211_CHAN_WIDTH_20:
3687 /* changes into another band are not supported */
3688 if (sdata->u.ibss.chandef.chan->band !=
3689 params->chandef.chan->band)
3692 /* see comments in the NL80211_IFTYPE_AP block */
3693 if (params->count > 1) {
3694 err = ieee80211_ibss_csa_beacon(sdata, params);
3700 ieee80211_send_action_csa(sdata, params);
3703 #ifdef CONFIG_MAC80211_MESH
3704 case NL80211_IFTYPE_MESH_POINT: {
3705 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3707 /* changes into another band are not supported */
3708 if (sdata->vif.bss_conf.chandef.chan->band !=
3709 params->chandef.chan->band)
3712 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3713 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3714 if (!ifmsh->pre_value)
3715 ifmsh->pre_value = 1;
3720 /* see comments in the NL80211_IFTYPE_AP block */
3721 if (params->count > 1) {
3722 err = ieee80211_mesh_csa_beacon(sdata, params);
3724 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3730 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3731 ieee80211_send_action_csa(sdata, params);
3743 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3745 sdata->vif.bss_conf.color_change_active = false;
3747 ieee80211_free_next_beacon(&sdata->deflink);
3749 cfg80211_color_change_aborted_notify(sdata->dev);
3753 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3754 struct cfg80211_csa_settings *params)
3756 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3757 struct ieee80211_local *local = sdata->local;
3758 struct ieee80211_channel_switch ch_switch;
3759 struct ieee80211_chanctx_conf *conf;
3760 struct ieee80211_chanctx *chanctx;
3764 sdata_assert_lock(sdata);
3765 lockdep_assert_held(&local->mtx);
3767 if (!list_empty(&local->roc_list) || local->scanning)
3770 if (sdata->wdev.cac_started)
3773 if (cfg80211_chandef_identical(¶ms->chandef,
3774 &sdata->vif.bss_conf.chandef))
3777 /* don't allow another channel switch if one is already active. */
3778 if (sdata->vif.bss_conf.csa_active)
3781 mutex_lock(&local->chanctx_mtx);
3782 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
3783 lockdep_is_held(&local->chanctx_mtx));
3789 if (params->chandef.chan->freq_offset) {
3790 /* this may work, but is untested */
3795 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3797 ch_switch.timestamp = 0;
3798 ch_switch.device_timestamp = 0;
3799 ch_switch.block_tx = params->block_tx;
3800 ch_switch.chandef = params->chandef;
3801 ch_switch.count = params->count;
3803 err = drv_pre_channel_switch(sdata, &ch_switch);
3807 err = ieee80211_link_reserve_chanctx(&sdata->deflink, ¶ms->chandef,
3809 params->radar_required);
3813 /* if reservation is invalid then this will fail */
3814 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3816 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3820 /* if there is a color change in progress, abort it */
3821 if (sdata->vif.bss_conf.color_change_active)
3822 ieee80211_color_change_abort(sdata);
3824 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3826 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3830 sdata->deflink.csa_chandef = params->chandef;
3831 sdata->deflink.csa_block_tx = params->block_tx;
3832 sdata->vif.bss_conf.csa_active = true;
3834 if (sdata->deflink.csa_block_tx)
3835 ieee80211_stop_vif_queues(local, sdata,
3836 IEEE80211_QUEUE_STOP_REASON_CSA);
3838 cfg80211_ch_switch_started_notify(sdata->dev,
3839 &sdata->deflink.csa_chandef, 0,
3840 params->count, params->block_tx);
3843 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3845 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3847 /* if the beacon didn't change, we can finalize immediately */
3848 ieee80211_csa_finalize(sdata);
3852 mutex_unlock(&local->chanctx_mtx);
3856 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3857 struct cfg80211_csa_settings *params)
3859 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3860 struct ieee80211_local *local = sdata->local;
3863 mutex_lock(&local->mtx);
3864 err = __ieee80211_channel_switch(wiphy, dev, params);
3865 mutex_unlock(&local->mtx);
3870 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3872 lockdep_assert_held(&local->mtx);
3874 local->roc_cookie_counter++;
3876 /* wow, you wrapped 64 bits ... more likely a bug */
3877 if (WARN_ON(local->roc_cookie_counter == 0))
3878 local->roc_cookie_counter++;
3880 return local->roc_cookie_counter;
3883 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3884 u64 *cookie, gfp_t gfp)
3886 unsigned long spin_flags;
3887 struct sk_buff *ack_skb;
3890 ack_skb = skb_copy(skb, gfp);
3894 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3895 id = idr_alloc(&local->ack_status_frames, ack_skb,
3896 1, 0x2000, GFP_ATOMIC);
3897 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3904 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3906 *cookie = ieee80211_mgmt_tx_cookie(local);
3907 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3913 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3914 struct wireless_dev *wdev,
3915 struct mgmt_frame_regs *upd)
3917 struct ieee80211_local *local = wiphy_priv(wiphy);
3918 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3919 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3920 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3921 bool global_change, intf_change;
3924 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3925 (local->rx_mcast_action_reg !=
3926 !!(upd->global_mcast_stypes & action_mask));
3927 local->probe_req_reg = upd->global_stypes & preq_mask;
3928 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3930 intf_change = (sdata->vif.probe_req_reg !=
3931 !!(upd->interface_stypes & preq_mask)) ||
3932 (sdata->vif.rx_mcast_action_reg !=
3933 !!(upd->interface_mcast_stypes & action_mask));
3934 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3935 sdata->vif.rx_mcast_action_reg =
3936 upd->interface_mcast_stypes & action_mask;
3938 if (!local->open_count)
3941 if (intf_change && ieee80211_sdata_running(sdata))
3942 drv_config_iface_filter(local, sdata,
3943 sdata->vif.probe_req_reg ?
3948 ieee80211_configure_filter(local);
3951 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3953 struct ieee80211_local *local = wiphy_priv(wiphy);
3958 return drv_set_antenna(local, tx_ant, rx_ant);
3961 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3963 struct ieee80211_local *local = wiphy_priv(wiphy);
3965 return drv_get_antenna(local, tx_ant, rx_ant);
3968 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3969 struct net_device *dev,
3970 struct cfg80211_gtk_rekey_data *data)
3972 struct ieee80211_local *local = wiphy_priv(wiphy);
3973 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3975 if (!local->ops->set_rekey_data)
3978 drv_set_rekey_data(local, sdata, data);
3983 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3984 const u8 *peer, u64 *cookie)
3986 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3987 struct ieee80211_local *local = sdata->local;
3988 struct ieee80211_qos_hdr *nullfunc;
3989 struct sk_buff *skb;
3990 int size = sizeof(*nullfunc);
3993 struct ieee80211_tx_info *info;
3994 struct sta_info *sta;
3995 struct ieee80211_chanctx_conf *chanctx_conf;
3996 enum nl80211_band band;
3999 /* the lock is needed to assign the cookie later */
4000 mutex_lock(&local->mtx);
4003 sta = sta_info_get_bss(sdata, peer);
4011 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
4012 if (WARN_ON(!chanctx_conf)) {
4016 band = chanctx_conf->def.chan->band;
4019 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4020 IEEE80211_STYPE_QOS_NULLFUNC |
4021 IEEE80211_FCTL_FROMDS);
4024 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4025 IEEE80211_STYPE_NULLFUNC |
4026 IEEE80211_FCTL_FROMDS);
4029 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4037 skb_reserve(skb, local->hw.extra_tx_headroom);
4039 nullfunc = skb_put(skb, size);
4040 nullfunc->frame_control = fc;
4041 nullfunc->duration_id = 0;
4042 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4043 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4044 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4045 nullfunc->seq_ctrl = 0;
4047 info = IEEE80211_SKB_CB(skb);
4049 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4050 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4053 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4056 nullfunc->qos_ctrl = cpu_to_le16(7);
4058 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4065 ieee80211_xmit(sdata, sta, skb);
4071 mutex_unlock(&local->mtx);
4076 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4077 struct wireless_dev *wdev,
4078 unsigned int link_id,
4079 struct cfg80211_chan_def *chandef)
4081 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4082 struct ieee80211_local *local = wiphy_priv(wiphy);
4083 struct ieee80211_chanctx_conf *chanctx_conf;
4084 struct ieee80211_link_data *link;
4088 link = rcu_dereference(sdata->link[link_id]);
4094 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4096 *chandef = link->conf->chandef;
4098 } else if (local->open_count > 0 &&
4099 local->open_count == local->monitors &&
4100 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4101 if (local->use_chanctx)
4102 *chandef = local->monitor_chandef;
4104 *chandef = local->_oper_chandef;
4114 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4116 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4120 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4121 struct net_device *dev,
4122 struct cfg80211_qos_map *qos_map)
4124 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4125 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4128 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4131 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4133 /* A NULL qos_map was passed to disable QoS mapping */
4137 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4138 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4140 kfree_rcu(old_qos_map, rcu_head);
4145 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4146 struct net_device *dev,
4147 unsigned int link_id,
4148 struct cfg80211_chan_def *chandef)
4150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4151 struct ieee80211_link_data *link;
4155 link = sdata_dereference(sdata->link[link_id], sdata);
4157 ret = ieee80211_link_change_bandwidth(link, chandef, &changed);
4159 ieee80211_link_info_change_notify(sdata, link, changed);
4164 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4165 u8 tsid, const u8 *peer, u8 up,
4168 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4169 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4170 int ac = ieee802_1d_to_ac[up];
4172 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4175 if (!(sdata->wmm_acm & BIT(up)))
4178 if (ifmgd->tx_tspec[ac].admitted_time)
4181 if (admitted_time) {
4182 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4183 ifmgd->tx_tspec[ac].tsid = tsid;
4184 ifmgd->tx_tspec[ac].up = up;
4190 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4191 u8 tsid, const u8 *peer)
4193 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4194 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4195 struct ieee80211_local *local = wiphy_priv(wiphy);
4198 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4199 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4201 /* skip unused entries */
4202 if (!tx_tspec->admitted_time)
4205 if (tx_tspec->tsid != tsid)
4208 /* due to this new packets will be reassigned to non-ACM ACs */
4211 /* Make sure that all packets have been sent to avoid to
4212 * restore the QoS params on packets that are still on the
4216 ieee80211_flush_queues(local, sdata, false);
4218 /* restore the normal QoS parameters
4219 * (unconditionally to avoid races)
4221 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4222 tx_tspec->downgraded = false;
4223 ieee80211_sta_handle_tspec_ac_params(sdata);
4225 /* finally clear all the data */
4226 memset(tx_tspec, 0, sizeof(*tx_tspec));
4234 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4236 enum nl80211_nan_func_term_reason reason,
4239 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4240 struct cfg80211_nan_func *func;
4243 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4246 spin_lock_bh(&sdata->u.nan.func_lock);
4248 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4249 if (WARN_ON(!func)) {
4250 spin_unlock_bh(&sdata->u.nan.func_lock);
4254 cookie = func->cookie;
4255 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4257 spin_unlock_bh(&sdata->u.nan.func_lock);
4259 cfg80211_free_nan_func(func);
4261 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4262 reason, cookie, gfp);
4264 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4266 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4267 struct cfg80211_nan_match_params *match,
4270 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4271 struct cfg80211_nan_func *func;
4273 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4276 spin_lock_bh(&sdata->u.nan.func_lock);
4278 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4279 if (WARN_ON(!func)) {
4280 spin_unlock_bh(&sdata->u.nan.func_lock);
4283 match->cookie = func->cookie;
4285 spin_unlock_bh(&sdata->u.nan.func_lock);
4287 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4289 EXPORT_SYMBOL(ieee80211_nan_func_match);
4291 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4292 struct net_device *dev,
4295 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4297 sdata->u.ap.multicast_to_unicast = enabled;
4302 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4303 struct txq_info *txqi)
4305 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4306 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4307 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4310 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4311 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4312 txqstats->backlog_packets = txqi->tin.backlog_packets;
4315 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4316 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4317 txqstats->flows = txqi->tin.flows;
4320 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4321 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4322 txqstats->drops = txqi->cstats.drop_count;
4325 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4326 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4327 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4330 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4331 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4332 txqstats->overlimit = txqi->tin.overlimit;
4335 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4336 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4337 txqstats->collisions = txqi->tin.collisions;
4340 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4341 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4342 txqstats->tx_bytes = txqi->tin.tx_bytes;
4345 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4346 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4347 txqstats->tx_packets = txqi->tin.tx_packets;
4351 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4352 struct wireless_dev *wdev,
4353 struct cfg80211_txq_stats *txqstats)
4355 struct ieee80211_local *local = wiphy_priv(wiphy);
4356 struct ieee80211_sub_if_data *sdata;
4359 if (!local->ops->wake_tx_queue)
4362 spin_lock_bh(&local->fq.lock);
4366 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4367 if (!sdata->vif.txq) {
4371 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4374 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4375 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4376 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4377 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4378 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4379 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4380 txqstats->backlog_packets = local->fq.backlog;
4381 txqstats->backlog_bytes = local->fq.memory_usage;
4382 txqstats->overlimit = local->fq.overlimit;
4383 txqstats->overmemory = local->fq.overmemory;
4384 txqstats->collisions = local->fq.collisions;
4385 txqstats->max_flows = local->fq.flows_cnt;
4390 spin_unlock_bh(&local->fq.lock);
4396 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4397 struct net_device *dev,
4398 struct cfg80211_ftm_responder_stats *ftm_stats)
4400 struct ieee80211_local *local = wiphy_priv(wiphy);
4401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4403 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4407 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4408 struct cfg80211_pmsr_request *request)
4410 struct ieee80211_local *local = wiphy_priv(wiphy);
4411 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4413 return drv_start_pmsr(local, sdata, request);
4417 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4418 struct cfg80211_pmsr_request *request)
4420 struct ieee80211_local *local = wiphy_priv(wiphy);
4421 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4423 return drv_abort_pmsr(local, sdata, request);
4426 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4427 struct net_device *dev,
4428 struct cfg80211_tid_config *tid_conf)
4430 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4431 struct sta_info *sta;
4434 if (!sdata->local->ops->set_tid_config)
4437 if (!tid_conf->peer)
4438 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4440 mutex_lock(&sdata->local->sta_mtx);
4441 sta = sta_info_get_bss(sdata, tid_conf->peer);
4443 mutex_unlock(&sdata->local->sta_mtx);
4447 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4448 mutex_unlock(&sdata->local->sta_mtx);
4453 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4454 struct net_device *dev,
4455 const u8 *peer, u8 tids)
4457 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4458 struct sta_info *sta;
4461 if (!sdata->local->ops->reset_tid_config)
4465 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4467 mutex_lock(&sdata->local->sta_mtx);
4468 sta = sta_info_get_bss(sdata, peer);
4470 mutex_unlock(&sdata->local->sta_mtx);
4474 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4475 mutex_unlock(&sdata->local->sta_mtx);
4480 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4481 struct cfg80211_sar_specs *sar)
4483 struct ieee80211_local *local = wiphy_priv(wiphy);
4485 if (!local->ops->set_sar_specs)
4488 return local->ops->set_sar_specs(&local->hw, sar);
4492 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4495 switch (sdata->vif.type) {
4496 case NL80211_IFTYPE_AP: {
4499 if (!sdata->deflink.u.ap.next_beacon)
4502 ret = ieee80211_assign_beacon(sdata, &sdata->deflink,
4503 sdata->deflink.u.ap.next_beacon,
4505 ieee80211_free_next_beacon(&sdata->deflink);
4522 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4523 struct cfg80211_color_change_settings *params,
4526 struct ieee80211_color_change_settings color_change = {};
4529 switch (sdata->vif.type) {
4530 case NL80211_IFTYPE_AP:
4531 sdata->deflink.u.ap.next_beacon =
4532 cfg80211_beacon_dup(¶ms->beacon_next);
4533 if (!sdata->deflink.u.ap.next_beacon)
4536 if (params->count <= 1)
4539 color_change.counter_offset_beacon =
4540 params->counter_offset_beacon;
4541 color_change.counter_offset_presp =
4542 params->counter_offset_presp;
4543 color_change.count = params->count;
4545 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
4546 ¶ms->beacon_color_change,
4547 NULL, &color_change);
4549 ieee80211_free_next_beacon(&sdata->deflink);
4562 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4563 u8 color, int enable, u32 changed)
4565 sdata->vif.bss_conf.he_bss_color.color = color;
4566 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4567 changed |= BSS_CHANGED_HE_BSS_COLOR;
4569 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
4571 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4572 struct ieee80211_sub_if_data *child;
4574 mutex_lock(&sdata->local->iflist_mtx);
4575 list_for_each_entry(child, &sdata->local->interfaces, list) {
4576 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4577 child->vif.bss_conf.he_bss_color.color = color;
4578 child->vif.bss_conf.he_bss_color.enabled = enable;
4579 ieee80211_link_info_change_notify(child,
4581 BSS_CHANGED_HE_BSS_COLOR);
4584 mutex_unlock(&sdata->local->iflist_mtx);
4588 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4590 struct ieee80211_local *local = sdata->local;
4594 sdata_assert_lock(sdata);
4595 lockdep_assert_held(&local->mtx);
4597 sdata->vif.bss_conf.color_change_active = false;
4599 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4601 cfg80211_color_change_aborted_notify(sdata->dev);
4605 ieee80211_color_change_bss_config_notify(sdata,
4606 sdata->vif.bss_conf.color_change_color,
4608 cfg80211_color_change_notify(sdata->dev);
4613 void ieee80211_color_change_finalize_work(struct work_struct *work)
4615 struct ieee80211_sub_if_data *sdata =
4616 container_of(work, struct ieee80211_sub_if_data,
4617 deflink.color_change_finalize_work);
4618 struct ieee80211_local *local = sdata->local;
4621 mutex_lock(&local->mtx);
4623 /* AP might have been stopped while waiting for the lock. */
4624 if (!sdata->vif.bss_conf.color_change_active)
4627 if (!ieee80211_sdata_running(sdata))
4630 ieee80211_color_change_finalize(sdata);
4633 mutex_unlock(&local->mtx);
4634 sdata_unlock(sdata);
4637 void ieee80211_color_collision_detection_work(struct work_struct *work)
4639 struct delayed_work *delayed_work = to_delayed_work(work);
4640 struct ieee80211_link_data *link =
4641 container_of(delayed_work, struct ieee80211_link_data,
4642 color_collision_detect_work);
4643 struct ieee80211_sub_if_data *sdata = link->sdata;
4646 cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap,
4648 sdata_unlock(sdata);
4651 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4653 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4655 ieee80211_queue_work(&sdata->local->hw,
4656 &sdata->deflink.color_change_finalize_work);
4658 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4661 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4662 u64 color_bitmap, gfp_t gfp)
4664 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4665 struct ieee80211_link_data *link = &sdata->deflink;
4667 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
4670 if (delayed_work_pending(&link->color_collision_detect_work))
4673 link->color_bitmap = color_bitmap;
4674 /* queue the color collision detection event every 500 ms in order to
4675 * avoid sending too much netlink messages to userspace.
4677 ieee80211_queue_delayed_work(&sdata->local->hw,
4678 &link->color_collision_detect_work,
4679 msecs_to_jiffies(500));
4681 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4684 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4685 struct cfg80211_color_change_settings *params)
4687 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4688 struct ieee80211_local *local = sdata->local;
4692 sdata_assert_lock(sdata);
4694 if (sdata->vif.bss_conf.nontransmitted)
4697 mutex_lock(&local->mtx);
4699 /* don't allow another color change if one is already active or if csa
4702 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
4707 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4711 sdata->vif.bss_conf.color_change_active = true;
4712 sdata->vif.bss_conf.color_change_color = params->color;
4714 cfg80211_color_change_started_notify(sdata->dev, params->count);
4717 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4719 /* if the beacon didn't change, we can finalize immediately */
4720 ieee80211_color_change_finalize(sdata);
4723 mutex_unlock(&local->mtx);
4729 ieee80211_set_radar_background(struct wiphy *wiphy,
4730 struct cfg80211_chan_def *chandef)
4732 struct ieee80211_local *local = wiphy_priv(wiphy);
4734 if (!local->ops->set_radar_background)
4737 return local->ops->set_radar_background(&local->hw, chandef);
4740 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4741 struct wireless_dev *wdev,
4742 unsigned int link_id)
4744 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4747 if (wdev->use_4addr)
4750 mutex_lock(&sdata->local->mtx);
4751 res = ieee80211_vif_set_links(sdata, wdev->valid_links);
4752 mutex_unlock(&sdata->local->mtx);
4757 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4758 struct wireless_dev *wdev,
4759 unsigned int link_id)
4761 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4763 mutex_lock(&sdata->local->mtx);
4764 ieee80211_vif_set_links(sdata, wdev->valid_links);
4765 mutex_unlock(&sdata->local->mtx);
4768 static int sta_add_link_station(struct ieee80211_local *local,
4769 struct ieee80211_sub_if_data *sdata,
4770 struct link_station_parameters *params)
4772 struct sta_info *sta;
4775 sta = sta_info_get_bss(sdata, params->mld_mac);
4779 if (!sta->sta.valid_links)
4782 if (sta->sta.valid_links & BIT(params->link_id))
4785 ret = ieee80211_sta_allocate_link(sta, params->link_id);
4789 ret = sta_link_apply_parameters(local, sta, true, params);
4791 ieee80211_sta_free_link(sta, params->link_id);
4795 /* ieee80211_sta_activate_link frees the link upon failure */
4796 return ieee80211_sta_activate_link(sta, params->link_id);
4800 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
4801 struct link_station_parameters *params)
4803 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4804 struct ieee80211_local *local = wiphy_priv(wiphy);
4807 mutex_lock(&sdata->local->sta_mtx);
4808 ret = sta_add_link_station(local, sdata, params);
4809 mutex_unlock(&sdata->local->sta_mtx);
4814 static int sta_mod_link_station(struct ieee80211_local *local,
4815 struct ieee80211_sub_if_data *sdata,
4816 struct link_station_parameters *params)
4818 struct sta_info *sta;
4820 sta = sta_info_get_bss(sdata, params->mld_mac);
4824 if (!(sta->sta.valid_links & BIT(params->link_id)))
4827 return sta_link_apply_parameters(local, sta, false, params);
4831 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
4832 struct link_station_parameters *params)
4834 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4835 struct ieee80211_local *local = wiphy_priv(wiphy);
4838 mutex_lock(&sdata->local->sta_mtx);
4839 ret = sta_mod_link_station(local, sdata, params);
4840 mutex_unlock(&sdata->local->sta_mtx);
4845 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
4846 struct link_station_del_parameters *params)
4848 struct sta_info *sta;
4850 sta = sta_info_get_bss(sdata, params->mld_mac);
4854 if (!(sta->sta.valid_links & BIT(params->link_id)))
4857 /* must not create a STA without links */
4858 if (sta->sta.valid_links == BIT(params->link_id))
4861 ieee80211_sta_remove_link(sta, params->link_id);
4867 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
4868 struct link_station_del_parameters *params)
4870 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4873 mutex_lock(&sdata->local->sta_mtx);
4874 ret = sta_del_link_station(sdata, params);
4875 mutex_unlock(&sdata->local->sta_mtx);
4880 const struct cfg80211_ops mac80211_config_ops = {
4881 .add_virtual_intf = ieee80211_add_iface,
4882 .del_virtual_intf = ieee80211_del_iface,
4883 .change_virtual_intf = ieee80211_change_iface,
4884 .start_p2p_device = ieee80211_start_p2p_device,
4885 .stop_p2p_device = ieee80211_stop_p2p_device,
4886 .add_key = ieee80211_add_key,
4887 .del_key = ieee80211_del_key,
4888 .get_key = ieee80211_get_key,
4889 .set_default_key = ieee80211_config_default_key,
4890 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4891 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4892 .start_ap = ieee80211_start_ap,
4893 .change_beacon = ieee80211_change_beacon,
4894 .stop_ap = ieee80211_stop_ap,
4895 .add_station = ieee80211_add_station,
4896 .del_station = ieee80211_del_station,
4897 .change_station = ieee80211_change_station,
4898 .get_station = ieee80211_get_station,
4899 .dump_station = ieee80211_dump_station,
4900 .dump_survey = ieee80211_dump_survey,
4901 #ifdef CONFIG_MAC80211_MESH
4902 .add_mpath = ieee80211_add_mpath,
4903 .del_mpath = ieee80211_del_mpath,
4904 .change_mpath = ieee80211_change_mpath,
4905 .get_mpath = ieee80211_get_mpath,
4906 .dump_mpath = ieee80211_dump_mpath,
4907 .get_mpp = ieee80211_get_mpp,
4908 .dump_mpp = ieee80211_dump_mpp,
4909 .update_mesh_config = ieee80211_update_mesh_config,
4910 .get_mesh_config = ieee80211_get_mesh_config,
4911 .join_mesh = ieee80211_join_mesh,
4912 .leave_mesh = ieee80211_leave_mesh,
4914 .join_ocb = ieee80211_join_ocb,
4915 .leave_ocb = ieee80211_leave_ocb,
4916 .change_bss = ieee80211_change_bss,
4917 .set_txq_params = ieee80211_set_txq_params,
4918 .set_monitor_channel = ieee80211_set_monitor_channel,
4919 .suspend = ieee80211_suspend,
4920 .resume = ieee80211_resume,
4921 .scan = ieee80211_scan,
4922 .abort_scan = ieee80211_abort_scan,
4923 .sched_scan_start = ieee80211_sched_scan_start,
4924 .sched_scan_stop = ieee80211_sched_scan_stop,
4925 .auth = ieee80211_auth,
4926 .assoc = ieee80211_assoc,
4927 .deauth = ieee80211_deauth,
4928 .disassoc = ieee80211_disassoc,
4929 .join_ibss = ieee80211_join_ibss,
4930 .leave_ibss = ieee80211_leave_ibss,
4931 .set_mcast_rate = ieee80211_set_mcast_rate,
4932 .set_wiphy_params = ieee80211_set_wiphy_params,
4933 .set_tx_power = ieee80211_set_tx_power,
4934 .get_tx_power = ieee80211_get_tx_power,
4935 .rfkill_poll = ieee80211_rfkill_poll,
4936 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4937 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4938 .set_power_mgmt = ieee80211_set_power_mgmt,
4939 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4940 .remain_on_channel = ieee80211_remain_on_channel,
4941 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4942 .mgmt_tx = ieee80211_mgmt_tx,
4943 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4944 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4945 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4946 .update_mgmt_frame_registrations =
4947 ieee80211_update_mgmt_frame_registrations,
4948 .set_antenna = ieee80211_set_antenna,
4949 .get_antenna = ieee80211_get_antenna,
4950 .set_rekey_data = ieee80211_set_rekey_data,
4951 .tdls_oper = ieee80211_tdls_oper,
4952 .tdls_mgmt = ieee80211_tdls_mgmt,
4953 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4954 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4955 .probe_client = ieee80211_probe_client,
4956 .set_noack_map = ieee80211_set_noack_map,
4958 .set_wakeup = ieee80211_set_wakeup,
4960 .get_channel = ieee80211_cfg_get_channel,
4961 .start_radar_detection = ieee80211_start_radar_detection,
4962 .end_cac = ieee80211_end_cac,
4963 .channel_switch = ieee80211_channel_switch,
4964 .set_qos_map = ieee80211_set_qos_map,
4965 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4966 .add_tx_ts = ieee80211_add_tx_ts,
4967 .del_tx_ts = ieee80211_del_tx_ts,
4968 .start_nan = ieee80211_start_nan,
4969 .stop_nan = ieee80211_stop_nan,
4970 .nan_change_conf = ieee80211_nan_change_conf,
4971 .add_nan_func = ieee80211_add_nan_func,
4972 .del_nan_func = ieee80211_del_nan_func,
4973 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4974 .tx_control_port = ieee80211_tx_control_port,
4975 .get_txq_stats = ieee80211_get_txq_stats,
4976 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4977 .start_pmsr = ieee80211_start_pmsr,
4978 .abort_pmsr = ieee80211_abort_pmsr,
4979 .probe_mesh_link = ieee80211_probe_mesh_link,
4980 .set_tid_config = ieee80211_set_tid_config,
4981 .reset_tid_config = ieee80211_reset_tid_config,
4982 .set_sar_specs = ieee80211_set_sar_specs,
4983 .color_change = ieee80211_color_change,
4984 .set_radar_background = ieee80211_set_radar_background,
4985 .add_intf_link = ieee80211_add_intf_link,
4986 .del_intf_link = ieee80211_del_intf_link,
4987 .add_link_station = ieee80211_add_link_station,
4988 .mod_link_station = ieee80211_mod_link_station,
4989 .del_link_station = ieee80211_del_link_station,