1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211 configuration hooks for cfg80211
5 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 * Copyright 2013-2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2015-2017 Intel Deutschland GmbH
8 * Copyright (C) 2018-2022 Intel Corporation
11 #include <linux/ieee80211.h>
12 #include <linux/nl80211.h>
13 #include <linux/rtnetlink.h>
14 #include <linux/slab.h>
15 #include <net/net_namespace.h>
16 #include <linux/rcupdate.h>
17 #include <linux/fips.h>
18 #include <linux/if_ether.h>
19 #include <net/cfg80211.h>
20 #include "ieee80211_i.h"
21 #include "driver-ops.h"
26 static struct ieee80211_link_data *
27 ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id,
30 struct ieee80211_link_data *link;
34 * For keys, if sdata is not an MLD, we might not use
35 * the return value at all (if it's not a pairwise key),
36 * so in that case (require_valid==false) don't error.
38 if (require_valid && sdata->vif.valid_links)
39 return ERR_PTR(-EINVAL);
41 return &sdata->deflink;
44 link = sdata_dereference(sdata->link[link_id], sdata);
46 return ERR_PTR(-ENOLINK);
50 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
51 struct vif_params *params)
53 bool mu_mimo_groups = false;
54 bool mu_mimo_follow = false;
56 if (params->vht_mumimo_groups) {
59 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
61 memcpy(sdata->vif.bss_conf.mu_group.membership,
62 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
63 memcpy(sdata->vif.bss_conf.mu_group.position,
64 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
65 WLAN_USER_POSITION_LEN);
66 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
67 BSS_CHANGED_MU_GROUPS);
68 /* don't care about endianness - just check for 0 */
69 memcpy(&membership, params->vht_mumimo_groups,
71 mu_mimo_groups = membership != 0;
74 if (params->vht_mumimo_follow_addr) {
76 is_valid_ether_addr(params->vht_mumimo_follow_addr);
77 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
78 params->vht_mumimo_follow_addr);
81 sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
84 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
85 struct vif_params *params)
87 struct ieee80211_local *local = sdata->local;
88 struct ieee80211_sub_if_data *monitor_sdata;
90 /* check flags first */
91 if (params->flags && ieee80211_sdata_running(sdata)) {
92 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
95 * Prohibit MONITOR_FLAG_COOK_FRAMES and
96 * MONITOR_FLAG_ACTIVE to be changed while the
98 * Else we would need to add a lot of cruft
99 * to update everything:
100 * cooked_mntrs, monitor and all fif_* counters
101 * reconfigure hardware
103 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
107 /* also validate MU-MIMO change */
108 monitor_sdata = wiphy_dereference(local->hw.wiphy,
109 local->monitor_sdata);
111 if (!monitor_sdata &&
112 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
115 /* apply all changes now - no failures allowed */
118 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
121 if (ieee80211_sdata_running(sdata)) {
122 ieee80211_adjust_monitor_flags(sdata, -1);
123 sdata->u.mntr.flags = params->flags;
124 ieee80211_adjust_monitor_flags(sdata, 1);
126 ieee80211_configure_filter(local);
129 * Because the interface is down, ieee80211_do_stop
130 * and ieee80211_do_open take care of "everything"
131 * mentioned in the comment above.
133 sdata->u.mntr.flags = params->flags;
140 static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
141 struct cfg80211_mbssid_config params,
142 struct ieee80211_bss_conf *link_conf)
144 struct ieee80211_sub_if_data *tx_sdata;
146 sdata->vif.mbssid_tx_vif = NULL;
147 link_conf->bssid_index = 0;
148 link_conf->nontransmitted = false;
149 link_conf->ema_ap = false;
151 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
154 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
158 if (tx_sdata == sdata) {
159 sdata->vif.mbssid_tx_vif = &sdata->vif;
161 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
162 link_conf->nontransmitted = true;
163 link_conf->bssid_index = params.index;
166 link_conf->ema_ap = true;
171 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
173 unsigned char name_assign_type,
174 enum nl80211_iftype type,
175 struct vif_params *params)
177 struct ieee80211_local *local = wiphy_priv(wiphy);
178 struct wireless_dev *wdev;
179 struct ieee80211_sub_if_data *sdata;
182 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
186 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
188 if (type == NL80211_IFTYPE_MONITOR) {
189 err = ieee80211_set_mon_options(sdata, params);
191 ieee80211_if_remove(sdata);
199 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
201 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
206 static int ieee80211_change_iface(struct wiphy *wiphy,
207 struct net_device *dev,
208 enum nl80211_iftype type,
209 struct vif_params *params)
211 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
212 struct ieee80211_local *local = sdata->local;
213 struct sta_info *sta;
216 ret = ieee80211_if_change_type(sdata, type);
220 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
221 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
222 ieee80211_check_fast_rx_iface(sdata);
223 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
224 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
226 if (params->use_4addr == ifmgd->use_4addr)
229 sdata->u.mgd.use_4addr = params->use_4addr;
230 if (!ifmgd->associated)
233 mutex_lock(&local->sta_mtx);
234 sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid);
236 drv_sta_set_4addr(local, sdata, &sta->sta,
238 mutex_unlock(&local->sta_mtx);
240 if (params->use_4addr)
241 ieee80211_send_4addr_nullfunc(local, sdata);
244 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
245 ret = ieee80211_set_mon_options(sdata, params);
253 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
254 struct wireless_dev *wdev)
256 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
259 mutex_lock(&sdata->local->chanctx_mtx);
260 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
261 mutex_unlock(&sdata->local->chanctx_mtx);
265 return ieee80211_do_open(wdev, true);
268 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
269 struct wireless_dev *wdev)
271 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
274 static int ieee80211_start_nan(struct wiphy *wiphy,
275 struct wireless_dev *wdev,
276 struct cfg80211_nan_conf *conf)
278 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
281 mutex_lock(&sdata->local->chanctx_mtx);
282 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
283 mutex_unlock(&sdata->local->chanctx_mtx);
287 ret = ieee80211_do_open(wdev, true);
291 ret = drv_start_nan(sdata->local, sdata, conf);
293 ieee80211_sdata_stop(sdata);
295 sdata->u.nan.conf = *conf;
300 static void ieee80211_stop_nan(struct wiphy *wiphy,
301 struct wireless_dev *wdev)
303 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
305 drv_stop_nan(sdata->local, sdata);
306 ieee80211_sdata_stop(sdata);
309 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
310 struct wireless_dev *wdev,
311 struct cfg80211_nan_conf *conf,
314 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
315 struct cfg80211_nan_conf new_conf;
318 if (sdata->vif.type != NL80211_IFTYPE_NAN)
321 if (!ieee80211_sdata_running(sdata))
324 new_conf = sdata->u.nan.conf;
326 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
327 new_conf.master_pref = conf->master_pref;
329 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
330 new_conf.bands = conf->bands;
332 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
334 sdata->u.nan.conf = new_conf;
339 static int ieee80211_add_nan_func(struct wiphy *wiphy,
340 struct wireless_dev *wdev,
341 struct cfg80211_nan_func *nan_func)
343 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
346 if (sdata->vif.type != NL80211_IFTYPE_NAN)
349 if (!ieee80211_sdata_running(sdata))
352 spin_lock_bh(&sdata->u.nan.func_lock);
354 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
355 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
357 spin_unlock_bh(&sdata->u.nan.func_lock);
362 nan_func->instance_id = ret;
364 WARN_ON(nan_func->instance_id == 0);
366 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
368 spin_lock_bh(&sdata->u.nan.func_lock);
369 idr_remove(&sdata->u.nan.function_inst_ids,
370 nan_func->instance_id);
371 spin_unlock_bh(&sdata->u.nan.func_lock);
377 static struct cfg80211_nan_func *
378 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
381 struct cfg80211_nan_func *func;
384 lockdep_assert_held(&sdata->u.nan.func_lock);
386 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
387 if (func->cookie == cookie)
394 static void ieee80211_del_nan_func(struct wiphy *wiphy,
395 struct wireless_dev *wdev, u64 cookie)
397 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
398 struct cfg80211_nan_func *func;
401 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
402 !ieee80211_sdata_running(sdata))
405 spin_lock_bh(&sdata->u.nan.func_lock);
407 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
409 instance_id = func->instance_id;
411 spin_unlock_bh(&sdata->u.nan.func_lock);
414 drv_del_nan_func(sdata->local, sdata, instance_id);
417 static int ieee80211_set_noack_map(struct wiphy *wiphy,
418 struct net_device *dev,
421 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
423 sdata->noack_map = noack_map;
425 ieee80211_check_fast_xmit_iface(sdata);
430 static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
431 const u8 *mac_addr, u8 key_idx)
433 struct ieee80211_local *local = sdata->local;
434 struct ieee80211_key *key;
435 struct sta_info *sta;
438 if (!wiphy_ext_feature_isset(local->hw.wiphy,
439 NL80211_EXT_FEATURE_EXT_KEY_ID))
442 sta = sta_info_get_bss(sdata, mac_addr);
447 if (sta->ptk_idx == key_idx)
450 mutex_lock(&local->key_mtx);
451 key = key_mtx_dereference(local, sta->ptk[key_idx]);
453 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
454 ret = ieee80211_set_tx_key(key);
456 mutex_unlock(&local->key_mtx);
460 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
461 int link_id, u8 key_idx, bool pairwise,
462 const u8 *mac_addr, struct key_params *params)
464 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
465 struct ieee80211_link_data *link =
466 ieee80211_link_or_deflink(sdata, link_id, false);
467 struct ieee80211_local *local = sdata->local;
468 struct sta_info *sta = NULL;
469 struct ieee80211_key *key;
472 if (!ieee80211_sdata_running(sdata))
476 return PTR_ERR(link);
478 if (pairwise && params->mode == NL80211_KEY_SET_TX)
479 return ieee80211_set_tx(sdata, mac_addr, key_idx);
481 /* reject WEP and TKIP keys if WEP failed to initialize */
482 switch (params->cipher) {
483 case WLAN_CIPHER_SUITE_WEP40:
484 case WLAN_CIPHER_SUITE_TKIP:
485 case WLAN_CIPHER_SUITE_WEP104:
488 if (WARN_ON_ONCE(fips_enabled))
495 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
496 params->key, params->seq_len, params->seq);
500 key->conf.link_id = link_id;
503 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
505 if (params->mode == NL80211_KEY_NO_TX)
506 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
508 mutex_lock(&local->sta_mtx);
511 sta = sta_info_get_bss(sdata, mac_addr);
513 * The ASSOC test makes sure the driver is ready to
514 * receive the key. When wpa_supplicant has roamed
515 * using FT, it attempts to set the key before
516 * association has completed, this rejects that attempt
517 * so it will set the key again after association.
519 * TODO: accept the key if we have a station entry and
520 * add it to the device after the station.
522 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
523 ieee80211_key_free_unused(key);
529 switch (sdata->vif.type) {
530 case NL80211_IFTYPE_STATION:
531 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
532 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
534 case NL80211_IFTYPE_AP:
535 case NL80211_IFTYPE_AP_VLAN:
536 /* Keys without a station are used for TX only */
537 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
538 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
540 case NL80211_IFTYPE_ADHOC:
543 case NL80211_IFTYPE_MESH_POINT:
544 #ifdef CONFIG_MAC80211_MESH
545 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
546 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
549 case NL80211_IFTYPE_WDS:
550 case NL80211_IFTYPE_MONITOR:
551 case NL80211_IFTYPE_P2P_DEVICE:
552 case NL80211_IFTYPE_NAN:
553 case NL80211_IFTYPE_UNSPECIFIED:
554 case NUM_NL80211_IFTYPES:
555 case NL80211_IFTYPE_P2P_CLIENT:
556 case NL80211_IFTYPE_P2P_GO:
557 case NL80211_IFTYPE_OCB:
558 /* shouldn't happen */
563 err = ieee80211_key_link(key, link, sta);
566 mutex_unlock(&local->sta_mtx);
571 static struct ieee80211_key *
572 ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
573 u8 key_idx, bool pairwise, const u8 *mac_addr)
575 struct ieee80211_local *local = sdata->local;
576 struct ieee80211_link_data *link = &sdata->deflink;
577 struct ieee80211_key *key;
580 link = rcu_dereference_check(sdata->link[link_id],
581 lockdep_is_held(&sdata->wdev.mtx));
587 struct sta_info *sta;
588 struct link_sta_info *link_sta;
590 sta = sta_info_get_bss(sdata, mac_addr);
595 link_sta = rcu_dereference_check(sta->link[link_id],
596 lockdep_is_held(&local->sta_mtx));
600 link_sta = &sta->deflink;
603 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
604 return rcu_dereference_check_key_mtx(local,
608 key_idx < NUM_DEFAULT_KEYS +
609 NUM_DEFAULT_MGMT_KEYS +
610 NUM_DEFAULT_BEACON_KEYS)
611 return rcu_dereference_check_key_mtx(local,
612 link_sta->gtk[key_idx]);
617 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
618 return rcu_dereference_check_key_mtx(local,
619 sdata->keys[key_idx]);
621 key = rcu_dereference_check_key_mtx(local, link->gtk[key_idx]);
625 /* or maybe it was a WEP key */
626 if (key_idx < NUM_DEFAULT_KEYS)
627 return rcu_dereference_check_key_mtx(local, sdata->keys[key_idx]);
632 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
633 int link_id, u8 key_idx, bool pairwise,
636 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
637 struct ieee80211_local *local = sdata->local;
638 struct ieee80211_key *key;
641 mutex_lock(&local->sta_mtx);
642 mutex_lock(&local->key_mtx);
644 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
650 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
654 mutex_unlock(&local->key_mtx);
655 mutex_unlock(&local->sta_mtx);
660 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
661 int link_id, u8 key_idx, bool pairwise,
662 const u8 *mac_addr, void *cookie,
663 void (*callback)(void *cookie,
664 struct key_params *params))
666 struct ieee80211_sub_if_data *sdata;
668 struct key_params params;
669 struct ieee80211_key *key;
674 struct ieee80211_key_seq kseq = {};
676 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
680 key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr);
684 memset(¶ms, 0, sizeof(params));
686 params.cipher = key->conf.cipher;
688 switch (key->conf.cipher) {
689 case WLAN_CIPHER_SUITE_TKIP:
690 pn64 = atomic64_read(&key->conf.tx_pn);
691 iv32 = TKIP_PN_TO_IV32(pn64);
692 iv16 = TKIP_PN_TO_IV16(pn64);
694 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
695 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
696 drv_get_key_seq(sdata->local, key, &kseq);
697 iv32 = kseq.tkip.iv32;
698 iv16 = kseq.tkip.iv16;
701 seq[0] = iv16 & 0xff;
702 seq[1] = (iv16 >> 8) & 0xff;
703 seq[2] = iv32 & 0xff;
704 seq[3] = (iv32 >> 8) & 0xff;
705 seq[4] = (iv32 >> 16) & 0xff;
706 seq[5] = (iv32 >> 24) & 0xff;
710 case WLAN_CIPHER_SUITE_CCMP:
711 case WLAN_CIPHER_SUITE_CCMP_256:
712 case WLAN_CIPHER_SUITE_AES_CMAC:
713 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
714 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
715 offsetof(typeof(kseq), aes_cmac));
717 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
718 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
719 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
720 offsetof(typeof(kseq), aes_gmac));
722 case WLAN_CIPHER_SUITE_GCMP:
723 case WLAN_CIPHER_SUITE_GCMP_256:
724 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
725 offsetof(typeof(kseq), gcmp));
727 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
728 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
729 drv_get_key_seq(sdata->local, key, &kseq);
730 memcpy(seq, kseq.ccmp.pn, 6);
732 pn64 = atomic64_read(&key->conf.tx_pn);
744 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
746 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
748 drv_get_key_seq(sdata->local, key, &kseq);
749 params.seq = kseq.hw.seq;
750 params.seq_len = kseq.hw.seq_len;
754 params.key = key->conf.key;
755 params.key_len = key->conf.keylen;
757 callback(cookie, ¶ms);
765 static int ieee80211_config_default_key(struct wiphy *wiphy,
766 struct net_device *dev,
767 int link_id, u8 key_idx, bool uni,
770 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
771 struct ieee80211_link_data *link =
772 ieee80211_link_or_deflink(sdata, link_id, false);
775 return PTR_ERR(link);
777 ieee80211_set_default_key(link, key_idx, uni, multi);
782 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
783 struct net_device *dev,
784 int link_id, u8 key_idx)
786 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
787 struct ieee80211_link_data *link =
788 ieee80211_link_or_deflink(sdata, link_id, true);
791 return PTR_ERR(link);
793 ieee80211_set_default_mgmt_key(link, key_idx);
798 static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
799 struct net_device *dev,
800 int link_id, u8 key_idx)
802 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
803 struct ieee80211_link_data *link =
804 ieee80211_link_or_deflink(sdata, link_id, true);
807 return PTR_ERR(link);
809 ieee80211_set_default_beacon_key(link, key_idx);
814 void sta_set_rate_info_tx(struct sta_info *sta,
815 const struct ieee80211_tx_rate *rate,
816 struct rate_info *rinfo)
819 if (rate->flags & IEEE80211_TX_RC_MCS) {
820 rinfo->flags |= RATE_INFO_FLAGS_MCS;
821 rinfo->mcs = rate->idx;
822 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
823 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
824 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
825 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
827 struct ieee80211_supported_band *sband;
828 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
831 sband = ieee80211_get_sband(sta->sdata);
832 WARN_ON_ONCE(sband && !sband->bitrates);
833 if (sband && sband->bitrates) {
834 brate = sband->bitrates[rate->idx].bitrate;
835 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
838 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
839 rinfo->bw = RATE_INFO_BW_40;
840 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
841 rinfo->bw = RATE_INFO_BW_80;
842 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
843 rinfo->bw = RATE_INFO_BW_160;
845 rinfo->bw = RATE_INFO_BW_20;
846 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
847 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
850 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
851 int idx, u8 *mac, struct station_info *sinfo)
853 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
854 struct ieee80211_local *local = sdata->local;
855 struct sta_info *sta;
858 mutex_lock(&local->sta_mtx);
860 sta = sta_info_get_by_idx(sdata, idx);
863 memcpy(mac, sta->sta.addr, ETH_ALEN);
864 sta_set_sinfo(sta, sinfo, true);
867 mutex_unlock(&local->sta_mtx);
872 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
873 int idx, struct survey_info *survey)
875 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
877 return drv_get_survey(local, idx, survey);
880 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
881 const u8 *mac, struct station_info *sinfo)
883 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
884 struct ieee80211_local *local = sdata->local;
885 struct sta_info *sta;
888 mutex_lock(&local->sta_mtx);
890 sta = sta_info_get_bss(sdata, mac);
893 sta_set_sinfo(sta, sinfo, true);
896 mutex_unlock(&local->sta_mtx);
901 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
902 struct cfg80211_chan_def *chandef)
904 struct ieee80211_local *local = wiphy_priv(wiphy);
905 struct ieee80211_sub_if_data *sdata;
908 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
911 mutex_lock(&local->mtx);
912 if (local->use_chanctx) {
913 sdata = wiphy_dereference(local->hw.wiphy,
914 local->monitor_sdata);
916 ieee80211_link_release_channel(&sdata->deflink);
917 ret = ieee80211_link_use_channel(&sdata->deflink,
919 IEEE80211_CHANCTX_EXCLUSIVE);
921 } else if (local->open_count == local->monitors) {
922 local->_oper_chandef = *chandef;
923 ieee80211_hw_config(local, 0);
927 local->monitor_chandef = *chandef;
928 mutex_unlock(&local->mtx);
934 ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
935 const u8 *resp, size_t resp_len,
936 const struct ieee80211_csa_settings *csa,
937 const struct ieee80211_color_change_settings *cca,
938 struct ieee80211_link_data *link)
940 struct probe_resp *new, *old;
942 if (!resp || !resp_len)
945 old = sdata_dereference(link->u.ap.probe_resp, sdata);
947 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
952 memcpy(new->data, resp, resp_len);
955 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
956 csa->n_counter_offsets_presp *
957 sizeof(new->cntdwn_counter_offsets[0]));
959 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
961 rcu_assign_pointer(link->u.ap.probe_resp, new);
963 kfree_rcu(old, rcu_head);
968 static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
969 struct cfg80211_fils_discovery *params,
970 struct ieee80211_link_data *link,
971 struct ieee80211_bss_conf *link_conf)
973 struct fils_discovery_data *new, *old = NULL;
974 struct ieee80211_fils_discovery *fd;
976 if (!params->tmpl || !params->tmpl_len)
979 fd = &link_conf->fils_discovery;
980 fd->min_interval = params->min_interval;
981 fd->max_interval = params->max_interval;
983 old = sdata_dereference(link->u.ap.fils_discovery, sdata);
984 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
987 new->len = params->tmpl_len;
988 memcpy(new->data, params->tmpl, params->tmpl_len);
989 rcu_assign_pointer(link->u.ap.fils_discovery, new);
992 kfree_rcu(old, rcu_head);
998 ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
999 struct cfg80211_unsol_bcast_probe_resp *params,
1000 struct ieee80211_link_data *link,
1001 struct ieee80211_bss_conf *link_conf)
1003 struct unsol_bcast_probe_resp_data *new, *old = NULL;
1005 if (!params->tmpl || !params->tmpl_len)
1008 old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata);
1009 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
1012 new->len = params->tmpl_len;
1013 memcpy(new->data, params->tmpl, params->tmpl_len);
1014 rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new);
1017 kfree_rcu(old, rcu_head);
1019 link_conf->unsol_bcast_probe_resp_interval = params->interval;
1024 static int ieee80211_set_ftm_responder_params(
1025 struct ieee80211_sub_if_data *sdata,
1026 const u8 *lci, size_t lci_len,
1027 const u8 *civicloc, size_t civicloc_len,
1028 struct ieee80211_bss_conf *link_conf)
1030 struct ieee80211_ftm_responder_params *new, *old;
1034 if (!lci_len && !civicloc_len)
1037 old = link_conf->ftmr_params;
1038 len = lci_len + civicloc_len;
1040 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
1044 pos = (u8 *)(new + 1);
1046 new->lci_len = lci_len;
1048 memcpy(pos, lci, lci_len);
1053 new->civicloc_len = civicloc_len;
1054 new->civicloc = pos;
1055 memcpy(pos, civicloc, civicloc_len);
1056 pos += civicloc_len;
1059 link_conf->ftmr_params = new;
1066 ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst,
1067 struct cfg80211_mbssid_elems *src)
1071 for (i = 0; i < src->cnt; i++) {
1072 memcpy(pos + offset, src->elem[i].data, src->elem[i].len);
1073 dst->elem[i].len = src->elem[i].len;
1074 dst->elem[i].data = pos + offset;
1075 offset += dst->elem[i].len;
1077 dst->cnt = src->cnt;
1082 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
1083 struct ieee80211_link_data *link,
1084 struct cfg80211_beacon_data *params,
1085 const struct ieee80211_csa_settings *csa,
1086 const struct ieee80211_color_change_settings *cca)
1088 struct cfg80211_mbssid_elems *mbssid = NULL;
1089 struct beacon_data *new, *old;
1090 int new_head_len, new_tail_len;
1092 u32 changed = BSS_CHANGED_BEACON;
1093 struct ieee80211_bss_conf *link_conf = link->conf;
1095 old = sdata_dereference(link->u.ap.beacon, sdata);
1097 /* Need to have a beacon head if we don't have one yet */
1098 if (!params->head && !old)
1101 /* new or old head? */
1103 new_head_len = params->head_len;
1105 new_head_len = old->head_len;
1107 /* new or old tail? */
1108 if (params->tail || !old)
1109 /* params->tail_len will be zero for !params->tail */
1110 new_tail_len = params->tail_len;
1112 new_tail_len = old->tail_len;
1114 size = sizeof(*new) + new_head_len + new_tail_len;
1116 /* new or old multiple BSSID elements? */
1117 if (params->mbssid_ies) {
1118 mbssid = params->mbssid_ies;
1119 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1120 size += ieee80211_get_mbssid_beacon_len(mbssid);
1121 } else if (old && old->mbssid_ies) {
1122 mbssid = old->mbssid_ies;
1123 size += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1124 size += ieee80211_get_mbssid_beacon_len(mbssid);
1127 new = kzalloc(size, GFP_KERNEL);
1131 /* start filling the new info now */
1134 * pointers go into the block we allocated,
1135 * memory is | beacon_data | head | tail | mbssid_ies
1137 new->head = ((u8 *) new) + sizeof(*new);
1138 new->tail = new->head + new_head_len;
1139 new->head_len = new_head_len;
1140 new->tail_len = new_tail_len;
1141 /* copy in optional mbssid_ies */
1143 u8 *pos = new->tail + new->tail_len;
1145 new->mbssid_ies = (void *)pos;
1146 pos += struct_size(new->mbssid_ies, elem, mbssid->cnt);
1147 ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, mbssid);
1148 /* update bssid_indicator */
1149 link_conf->bssid_indicator =
1150 ilog2(__roundup_pow_of_two(mbssid->cnt + 1));
1154 new->cntdwn_current_counter = csa->count;
1155 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
1156 csa->n_counter_offsets_beacon *
1157 sizeof(new->cntdwn_counter_offsets[0]));
1159 new->cntdwn_current_counter = cca->count;
1160 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
1165 memcpy(new->head, params->head, new_head_len);
1167 memcpy(new->head, old->head, new_head_len);
1169 /* copy in optional tail */
1171 memcpy(new->tail, params->tail, new_tail_len);
1174 memcpy(new->tail, old->tail, new_tail_len);
1176 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
1177 params->probe_resp_len, csa, cca, link);
1183 changed |= BSS_CHANGED_AP_PROBE_RESP;
1185 if (params->ftm_responder != -1) {
1186 link_conf->ftm_responder = params->ftm_responder;
1187 err = ieee80211_set_ftm_responder_params(sdata,
1191 params->civicloc_len,
1199 changed |= BSS_CHANGED_FTM_RESPONDER;
1202 rcu_assign_pointer(link->u.ap.beacon, new);
1203 sdata->u.ap.active = true;
1206 kfree_rcu(old, rcu_head);
1211 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1212 struct cfg80211_ap_settings *params)
1214 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1215 struct ieee80211_local *local = sdata->local;
1216 struct beacon_data *old;
1217 struct ieee80211_sub_if_data *vlan;
1218 u32 changed = BSS_CHANGED_BEACON_INT |
1219 BSS_CHANGED_BEACON_ENABLED |
1220 BSS_CHANGED_BEACON |
1221 BSS_CHANGED_P2P_PS |
1222 BSS_CHANGED_TXPOWER |
1225 int prev_beacon_int;
1226 unsigned int link_id = params->beacon.link_id;
1227 struct ieee80211_link_data *link;
1228 struct ieee80211_bss_conf *link_conf;
1230 link = sdata_dereference(sdata->link[link_id], sdata);
1234 link_conf = link->conf;
1236 old = sdata_dereference(link->u.ap.beacon, sdata);
1240 if (params->smps_mode != NL80211_SMPS_OFF)
1243 link->smps_mode = IEEE80211_SMPS_OFF;
1245 link->needed_rx_chains = sdata->local->rx_chains;
1247 prev_beacon_int = link_conf->beacon_int;
1248 link_conf->beacon_int = params->beacon_interval;
1250 if (params->he_cap && params->he_oper) {
1251 link_conf->he_support = true;
1252 link_conf->htc_trig_based_pkt_ext =
1253 le32_get_bits(params->he_oper->he_oper_params,
1254 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1255 link_conf->frame_time_rts_th =
1256 le32_get_bits(params->he_oper->he_oper_params,
1257 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
1258 changed |= BSS_CHANGED_HE_OBSS_PD;
1260 if (params->beacon.he_bss_color.enabled)
1261 changed |= BSS_CHANGED_HE_BSS_COLOR;
1264 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1265 params->mbssid_config.tx_wdev) {
1266 err = ieee80211_set_ap_mbssid_options(sdata,
1267 params->mbssid_config,
1273 mutex_lock(&local->mtx);
1274 err = ieee80211_link_use_channel(link, ¶ms->chandef,
1275 IEEE80211_CHANCTX_SHARED);
1277 ieee80211_link_copy_chanctx_to_vlans(link, false);
1278 mutex_unlock(&local->mtx);
1280 link_conf->beacon_int = prev_beacon_int;
1285 * Apply control port protocol, this allows us to
1286 * not encrypt dynamic WEP control frames.
1288 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1289 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
1290 sdata->control_port_over_nl80211 =
1291 params->crypto.control_port_over_nl80211;
1292 sdata->control_port_no_preauth =
1293 params->crypto.control_port_no_preauth;
1295 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1296 vlan->control_port_protocol =
1297 params->crypto.control_port_ethertype;
1298 vlan->control_port_no_encrypt =
1299 params->crypto.control_port_no_encrypt;
1300 vlan->control_port_over_nl80211 =
1301 params->crypto.control_port_over_nl80211;
1302 vlan->control_port_no_preauth =
1303 params->crypto.control_port_no_preauth;
1306 link_conf->dtim_period = params->dtim_period;
1307 link_conf->enable_beacon = true;
1308 link_conf->allow_p2p_go_ps = sdata->vif.p2p;
1309 link_conf->twt_responder = params->twt_responder;
1310 link_conf->he_obss_pd = params->he_obss_pd;
1311 link_conf->he_bss_color = params->beacon.he_bss_color;
1312 sdata->vif.cfg.s1g = params->chandef.chan->band ==
1315 sdata->vif.cfg.ssid_len = params->ssid_len;
1316 if (params->ssid_len)
1317 memcpy(sdata->vif.cfg.ssid, params->ssid,
1319 link_conf->hidden_ssid =
1320 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1322 memset(&link_conf->p2p_noa_attr, 0,
1323 sizeof(link_conf->p2p_noa_attr));
1324 link_conf->p2p_noa_attr.oppps_ctwindow =
1325 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1326 if (params->p2p_opp_ps)
1327 link_conf->p2p_noa_attr.oppps_ctwindow |=
1328 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1330 sdata->beacon_rate_set = false;
1331 if (wiphy_ext_feature_isset(local->hw.wiphy,
1332 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1333 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1334 sdata->beacon_rateidx_mask[i] =
1335 params->beacon_rate.control[i].legacy;
1336 if (sdata->beacon_rateidx_mask[i])
1337 sdata->beacon_rate_set = true;
1341 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1342 link_conf->beacon_tx_rate = params->beacon_rate;
1344 err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL);
1349 if (params->fils_discovery.max_interval) {
1350 err = ieee80211_set_fils_discovery(sdata,
1351 ¶ms->fils_discovery,
1355 changed |= BSS_CHANGED_FILS_DISCOVERY;
1358 if (params->unsol_bcast_probe_resp.interval) {
1359 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1360 ¶ms->unsol_bcast_probe_resp,
1364 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1367 err = drv_start_ap(sdata->local, sdata, link_conf);
1369 old = sdata_dereference(link->u.ap.beacon, sdata);
1372 kfree_rcu(old, rcu_head);
1373 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1374 sdata->u.ap.active = false;
1378 ieee80211_recalc_dtim(local, sdata);
1379 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID);
1380 ieee80211_link_info_change_notify(sdata, link, changed);
1382 netif_carrier_on(dev);
1383 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1384 netif_carrier_on(vlan->dev);
1389 mutex_lock(&local->mtx);
1390 ieee80211_link_release_channel(link);
1391 mutex_unlock(&local->mtx);
1396 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1397 struct cfg80211_beacon_data *params)
1399 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1400 struct ieee80211_link_data *link;
1401 struct beacon_data *old;
1403 struct ieee80211_bss_conf *link_conf;
1405 sdata_assert_lock(sdata);
1407 link = sdata_dereference(sdata->link[params->link_id], sdata);
1411 link_conf = link->conf;
1413 /* don't allow changing the beacon while a countdown is in place - offset
1414 * of channel switch counter may change
1416 if (link_conf->csa_active || link_conf->color_change_active)
1419 old = sdata_dereference(link->u.ap.beacon, sdata);
1423 err = ieee80211_assign_beacon(sdata, link, params, NULL, NULL);
1427 if (params->he_bss_color_valid &&
1428 params->he_bss_color.enabled != link_conf->he_bss_color.enabled) {
1429 link_conf->he_bss_color.enabled = params->he_bss_color.enabled;
1430 err |= BSS_CHANGED_HE_BSS_COLOR;
1433 ieee80211_link_info_change_notify(sdata, link, err);
1437 static void ieee80211_free_next_beacon(struct ieee80211_link_data *link)
1439 if (!link->u.ap.next_beacon)
1442 kfree(link->u.ap.next_beacon->mbssid_ies);
1443 kfree(link->u.ap.next_beacon);
1444 link->u.ap.next_beacon = NULL;
1447 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
1448 unsigned int link_id)
1450 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1451 struct ieee80211_sub_if_data *vlan;
1452 struct ieee80211_local *local = sdata->local;
1453 struct beacon_data *old_beacon;
1454 struct probe_resp *old_probe_resp;
1455 struct fils_discovery_data *old_fils_discovery;
1456 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
1457 struct cfg80211_chan_def chandef;
1458 struct ieee80211_link_data *link =
1459 sdata_dereference(sdata->link[link_id], sdata);
1460 struct ieee80211_bss_conf *link_conf = link->conf;
1462 sdata_assert_lock(sdata);
1464 old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
1467 old_probe_resp = sdata_dereference(link->u.ap.probe_resp,
1469 old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery,
1471 old_unsol_bcast_probe_resp =
1472 sdata_dereference(link->u.ap.unsol_bcast_probe_resp,
1475 /* abort any running channel switch */
1476 mutex_lock(&local->mtx);
1477 link_conf->csa_active = false;
1478 if (link->csa_block_tx) {
1479 ieee80211_wake_vif_queues(local, sdata,
1480 IEEE80211_QUEUE_STOP_REASON_CSA);
1481 link->csa_block_tx = false;
1484 mutex_unlock(&local->mtx);
1486 ieee80211_free_next_beacon(link);
1488 /* turn off carrier for this interface and dependent VLANs */
1489 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1490 netif_carrier_off(vlan->dev);
1491 netif_carrier_off(dev);
1493 /* remove beacon and probe response */
1494 sdata->u.ap.active = false;
1495 RCU_INIT_POINTER(link->u.ap.beacon, NULL);
1496 RCU_INIT_POINTER(link->u.ap.probe_resp, NULL);
1497 RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL);
1498 RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL);
1499 kfree_rcu(old_beacon, rcu_head);
1501 kfree_rcu(old_probe_resp, rcu_head);
1502 if (old_fils_discovery)
1503 kfree_rcu(old_fils_discovery, rcu_head);
1504 if (old_unsol_bcast_probe_resp)
1505 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
1507 kfree(link_conf->ftmr_params);
1508 link_conf->ftmr_params = NULL;
1510 __sta_info_flush(sdata, true);
1511 ieee80211_free_keys(sdata, true);
1513 link_conf->enable_beacon = false;
1514 sdata->beacon_rate_set = false;
1515 sdata->vif.cfg.ssid_len = 0;
1516 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1517 ieee80211_link_info_change_notify(sdata, link,
1518 BSS_CHANGED_BEACON_ENABLED);
1520 if (sdata->wdev.cac_started) {
1521 chandef = link_conf->chandef;
1522 cancel_delayed_work_sync(&link->dfs_cac_timer_work);
1523 cfg80211_cac_event(sdata->dev, &chandef,
1524 NL80211_RADAR_CAC_ABORTED,
1528 drv_stop_ap(sdata->local, sdata, link_conf);
1530 /* free all potentially still buffered bcast frames */
1531 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1532 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1534 mutex_lock(&local->mtx);
1535 ieee80211_link_copy_chanctx_to_vlans(link, true);
1536 ieee80211_link_release_channel(link);
1537 mutex_unlock(&local->mtx);
1542 static int sta_apply_auth_flags(struct ieee80211_local *local,
1543 struct sta_info *sta,
1548 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1549 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1550 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1551 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1556 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1557 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1558 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1560 * When peer becomes associated, init rate control as
1561 * well. Some drivers require rate control initialized
1562 * before drv_sta_state() is called.
1564 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1565 rate_control_rate_init(sta);
1567 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1572 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1573 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1574 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1575 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1576 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1583 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1584 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1585 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1586 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1591 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1592 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1593 test_sta_flag(sta, WLAN_STA_AUTH)) {
1594 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1602 static void sta_apply_mesh_params(struct ieee80211_local *local,
1603 struct sta_info *sta,
1604 struct station_parameters *params)
1606 #ifdef CONFIG_MAC80211_MESH
1607 struct ieee80211_sub_if_data *sdata = sta->sdata;
1610 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1611 switch (params->plink_state) {
1612 case NL80211_PLINK_ESTAB:
1613 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1614 changed = mesh_plink_inc_estab_count(sdata);
1615 sta->mesh->plink_state = params->plink_state;
1616 sta->mesh->aid = params->peer_aid;
1618 ieee80211_mps_sta_status_update(sta);
1619 changed |= ieee80211_mps_set_sta_local_pm(sta,
1620 sdata->u.mesh.mshcfg.power_mode);
1622 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1623 /* init at low value */
1624 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1627 case NL80211_PLINK_LISTEN:
1628 case NL80211_PLINK_BLOCKED:
1629 case NL80211_PLINK_OPN_SNT:
1630 case NL80211_PLINK_OPN_RCVD:
1631 case NL80211_PLINK_CNF_RCVD:
1632 case NL80211_PLINK_HOLDING:
1633 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1634 changed = mesh_plink_dec_estab_count(sdata);
1635 sta->mesh->plink_state = params->plink_state;
1637 ieee80211_mps_sta_status_update(sta);
1638 changed |= ieee80211_mps_set_sta_local_pm(sta,
1639 NL80211_MESH_POWER_UNKNOWN);
1647 switch (params->plink_action) {
1648 case NL80211_PLINK_ACTION_NO_ACTION:
1651 case NL80211_PLINK_ACTION_OPEN:
1652 changed |= mesh_plink_open(sta);
1654 case NL80211_PLINK_ACTION_BLOCK:
1655 changed |= mesh_plink_block(sta);
1659 if (params->local_pm)
1660 changed |= ieee80211_mps_set_sta_local_pm(sta,
1663 ieee80211_mbss_info_change_notify(sdata, changed);
1667 static int sta_link_apply_parameters(struct ieee80211_local *local,
1668 struct sta_info *sta, bool new_link,
1669 struct link_station_parameters *params)
1672 struct ieee80211_supported_band *sband;
1673 struct ieee80211_sub_if_data *sdata = sta->sdata;
1674 u32 link_id = params->link_id < 0 ? 0 : params->link_id;
1675 struct ieee80211_link_data *link =
1676 sdata_dereference(sdata->link[link_id], sdata);
1677 struct link_sta_info *link_sta =
1678 rcu_dereference_protected(sta->link[link_id],
1679 lockdep_is_held(&local->sta_mtx));
1682 * If there are no changes, then accept a link that doesn't exist,
1683 * unless it's a new link.
1685 if (params->link_id < 0 && !new_link &&
1686 !params->link_mac && !params->txpwr_set &&
1687 !params->supported_rates_len &&
1688 !params->ht_capa && !params->vht_capa &&
1689 !params->he_capa && !params->eht_capa &&
1690 !params->opmode_notif_used)
1693 if (!link || !link_sta)
1696 sband = ieee80211_get_link_sband(link);
1700 if (params->link_mac) {
1702 memcpy(link_sta->addr, params->link_mac, ETH_ALEN);
1703 memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN);
1704 } else if (!ether_addr_equal(link_sta->addr,
1705 params->link_mac)) {
1708 } else if (new_link) {
1712 if (params->txpwr_set) {
1713 link_sta->pub->txpwr.type = params->txpwr.type;
1714 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1715 link_sta->pub->txpwr.power = params->txpwr.power;
1716 ret = drv_sta_set_txpwr(local, sdata, sta);
1721 if (params->supported_rates &&
1722 params->supported_rates_len) {
1723 ieee80211_parse_bitrates(link->conf->chandef.width,
1724 sband, params->supported_rates,
1725 params->supported_rates_len,
1726 &link_sta->pub->supp_rates[sband->band]);
1729 if (params->ht_capa)
1730 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1731 params->ht_capa, link_sta);
1733 /* VHT can override some HT caps such as the A-MSDU max length */
1734 if (params->vht_capa)
1735 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1736 params->vht_capa, link_sta);
1738 if (params->he_capa)
1739 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1740 (void *)params->he_capa,
1741 params->he_capa_len,
1742 (void *)params->he_6ghz_capa,
1745 if (params->eht_capa)
1746 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
1747 (u8 *)params->he_capa,
1748 params->he_capa_len,
1750 params->eht_capa_len,
1753 if (params->opmode_notif_used) {
1754 /* returned value is only needed for rc update, but the
1755 * rc isn't initialized here yet, so ignore it
1757 __ieee80211_vht_handle_opmode(sdata, link_sta,
1758 params->opmode_notif,
1765 static int sta_apply_parameters(struct ieee80211_local *local,
1766 struct sta_info *sta,
1767 struct station_parameters *params)
1769 struct ieee80211_sub_if_data *sdata = sta->sdata;
1773 mask = params->sta_flags_mask;
1774 set = params->sta_flags_set;
1776 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1778 * In mesh mode, ASSOCIATED isn't part of the nl80211
1779 * API but must follow AUTHENTICATED for driver state.
1781 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1782 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1783 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1784 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1785 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1787 * TDLS -- everything follows authorized, but
1788 * only becoming authorized is possible, not
1791 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1792 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1793 BIT(NL80211_STA_FLAG_ASSOCIATED);
1794 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1795 BIT(NL80211_STA_FLAG_ASSOCIATED);
1799 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1800 local->hw.queues >= IEEE80211_NUM_ACS)
1801 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1803 /* auth flags will be set later for TDLS,
1804 * and for unassociated stations that move to associated */
1805 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1806 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1807 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1808 ret = sta_apply_auth_flags(local, sta, mask, set);
1813 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1814 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1815 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1817 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1820 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1821 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1822 if (set & BIT(NL80211_STA_FLAG_MFP))
1823 set_sta_flag(sta, WLAN_STA_MFP);
1825 clear_sta_flag(sta, WLAN_STA_MFP);
1828 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1829 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1830 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1832 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1835 /* mark TDLS channel switch support, if the AP allows it */
1836 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1837 !sdata->deflink.u.mgd.tdls_chan_switch_prohibited &&
1838 params->ext_capab_len >= 4 &&
1839 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1840 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1842 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1843 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1844 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1845 params->ext_capab_len >= 8 &&
1846 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1847 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1849 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1850 sta->sta.uapsd_queues = params->uapsd_queues;
1851 sta->sta.max_sp = params->max_sp;
1854 ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab,
1855 params->ext_capab_len);
1858 * cfg80211 validates this (1-2007) and allows setting the AID
1859 * only when creating a new station entry
1862 sta->sta.aid = params->aid;
1865 * Some of the following updates would be racy if called on an
1866 * existing station, via ieee80211_change_station(). However,
1867 * all such changes are rejected by cfg80211 except for updates
1868 * changing the supported rates on an existing but not yet used
1872 if (params->listen_interval >= 0)
1873 sta->listen_interval = params->listen_interval;
1875 ret = sta_link_apply_parameters(local, sta, false,
1876 ¶ms->link_sta_params);
1880 if (params->support_p2p_ps >= 0)
1881 sta->sta.support_p2p_ps = params->support_p2p_ps;
1883 if (ieee80211_vif_is_mesh(&sdata->vif))
1884 sta_apply_mesh_params(local, sta, params);
1886 if (params->airtime_weight)
1887 sta->airtime_weight = params->airtime_weight;
1889 /* set the STA state after all sta info from usermode has been set */
1890 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1891 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1892 ret = sta_apply_auth_flags(local, sta, mask, set);
1897 /* Mark the STA as MLO if MLD MAC address is available */
1898 if (params->link_sta_params.mld_mac)
1899 sta->sta.mlo = true;
1904 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1906 struct station_parameters *params)
1908 struct ieee80211_local *local = wiphy_priv(wiphy);
1909 struct sta_info *sta;
1910 struct ieee80211_sub_if_data *sdata;
1914 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1916 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1917 sdata->vif.type != NL80211_IFTYPE_AP)
1920 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1922 if (ether_addr_equal(mac, sdata->vif.addr))
1925 if (!is_valid_ether_addr(mac))
1928 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1929 sdata->vif.type == NL80211_IFTYPE_STATION &&
1930 !sdata->u.mgd.associated)
1934 * If we have a link ID, it can be a non-MLO station on an AP MLD,
1935 * but we need to have a link_mac in that case as well, so use the
1936 * STA's MAC address in that case.
1938 if (params->link_sta_params.link_id >= 0)
1939 sta = sta_info_alloc_with_link(sdata, mac,
1940 params->link_sta_params.link_id,
1941 params->link_sta_params.link_mac ?: mac,
1944 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1949 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1950 sta->sta.tdls = true;
1952 /* Though the mutex is not needed here (since the station is not
1953 * visible yet), sta_apply_parameters (and inner functions) require
1954 * the mutex due to other paths.
1956 mutex_lock(&local->sta_mtx);
1957 err = sta_apply_parameters(local, sta, params);
1958 mutex_unlock(&local->sta_mtx);
1960 sta_info_free(local, sta);
1965 * for TDLS and for unassociated station, rate control should be
1966 * initialized only when rates are known and station is marked
1967 * authorized/associated
1969 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1970 test_sta_flag(sta, WLAN_STA_ASSOC))
1971 rate_control_rate_init(sta);
1973 return sta_info_insert(sta);
1976 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1977 struct station_del_parameters *params)
1979 struct ieee80211_sub_if_data *sdata;
1981 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1984 return sta_info_destroy_addr_bss(sdata, params->mac);
1986 sta_info_flush(sdata);
1990 static int ieee80211_change_station(struct wiphy *wiphy,
1991 struct net_device *dev, const u8 *mac,
1992 struct station_parameters *params)
1994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1995 struct ieee80211_local *local = wiphy_priv(wiphy);
1996 struct sta_info *sta;
1997 struct ieee80211_sub_if_data *vlansdata;
1998 enum cfg80211_station_type statype;
2001 mutex_lock(&local->sta_mtx);
2003 sta = sta_info_get_bss(sdata, mac);
2009 switch (sdata->vif.type) {
2010 case NL80211_IFTYPE_MESH_POINT:
2011 if (sdata->u.mesh.user_mpm)
2012 statype = CFG80211_STA_MESH_PEER_USER;
2014 statype = CFG80211_STA_MESH_PEER_KERNEL;
2016 case NL80211_IFTYPE_ADHOC:
2017 statype = CFG80211_STA_IBSS;
2019 case NL80211_IFTYPE_STATION:
2020 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
2021 statype = CFG80211_STA_AP_STA;
2024 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2025 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
2027 statype = CFG80211_STA_TDLS_PEER_SETUP;
2029 case NL80211_IFTYPE_AP:
2030 case NL80211_IFTYPE_AP_VLAN:
2031 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2032 statype = CFG80211_STA_AP_CLIENT;
2034 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
2041 err = cfg80211_check_station_change(wiphy, params, statype);
2045 if (params->vlan && params->vlan != sta->sdata->dev) {
2046 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
2048 if (params->vlan->ieee80211_ptr->use_4addr) {
2049 if (vlansdata->u.vlan.sta) {
2054 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
2055 __ieee80211_check_fast_rx_iface(vlansdata);
2056 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
2059 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
2060 sta->sdata->u.vlan.sta) {
2061 ieee80211_clear_fast_rx(sta);
2062 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
2065 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2066 ieee80211_vif_dec_num_mcast(sta->sdata);
2068 sta->sdata = vlansdata;
2069 ieee80211_check_fast_xmit(sta);
2071 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
2072 ieee80211_vif_inc_num_mcast(sta->sdata);
2073 cfg80211_send_layer2_update(sta->sdata->dev,
2078 /* we use sta_info_get_bss() so this might be different */
2079 if (sdata != sta->sdata) {
2080 mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
2081 err = sta_apply_parameters(local, sta, params);
2082 mutex_unlock(&sta->sdata->wdev.mtx);
2084 err = sta_apply_parameters(local, sta, params);
2089 mutex_unlock(&local->sta_mtx);
2091 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2092 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
2093 ieee80211_recalc_ps(local);
2094 ieee80211_recalc_ps_vif(sdata);
2099 mutex_unlock(&local->sta_mtx);
2103 #ifdef CONFIG_MAC80211_MESH
2104 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
2105 const u8 *dst, const u8 *next_hop)
2107 struct ieee80211_sub_if_data *sdata;
2108 struct mesh_path *mpath;
2109 struct sta_info *sta;
2111 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2114 sta = sta_info_get(sdata, next_hop);
2120 mpath = mesh_path_add(sdata, dst);
2121 if (IS_ERR(mpath)) {
2123 return PTR_ERR(mpath);
2126 mesh_path_fix_nexthop(mpath, sta);
2132 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
2135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2138 return mesh_path_del(sdata, dst);
2140 mesh_path_flush_by_iface(sdata);
2144 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
2145 const u8 *dst, const u8 *next_hop)
2147 struct ieee80211_sub_if_data *sdata;
2148 struct mesh_path *mpath;
2149 struct sta_info *sta;
2151 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2155 sta = sta_info_get(sdata, next_hop);
2161 mpath = mesh_path_lookup(sdata, dst);
2167 mesh_path_fix_nexthop(mpath, sta);
2173 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
2174 struct mpath_info *pinfo)
2176 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
2179 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
2181 eth_zero_addr(next_hop);
2183 memset(pinfo, 0, sizeof(*pinfo));
2185 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
2187 pinfo->filled = MPATH_INFO_FRAME_QLEN |
2190 MPATH_INFO_EXPTIME |
2191 MPATH_INFO_DISCOVERY_TIMEOUT |
2192 MPATH_INFO_DISCOVERY_RETRIES |
2194 MPATH_INFO_HOP_COUNT |
2195 MPATH_INFO_PATH_CHANGE;
2197 pinfo->frame_qlen = mpath->frame_queue.qlen;
2198 pinfo->sn = mpath->sn;
2199 pinfo->metric = mpath->metric;
2200 if (time_before(jiffies, mpath->exp_time))
2201 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2202 pinfo->discovery_timeout =
2203 jiffies_to_msecs(mpath->discovery_timeout);
2204 pinfo->discovery_retries = mpath->discovery_retries;
2205 if (mpath->flags & MESH_PATH_ACTIVE)
2206 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2207 if (mpath->flags & MESH_PATH_RESOLVING)
2208 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
2209 if (mpath->flags & MESH_PATH_SN_VALID)
2210 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
2211 if (mpath->flags & MESH_PATH_FIXED)
2212 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
2213 if (mpath->flags & MESH_PATH_RESOLVED)
2214 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
2215 pinfo->hop_count = mpath->hop_count;
2216 pinfo->path_change_count = mpath->path_change_count;
2219 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2220 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2223 struct ieee80211_sub_if_data *sdata;
2224 struct mesh_path *mpath;
2226 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2229 mpath = mesh_path_lookup(sdata, dst);
2234 memcpy(dst, mpath->dst, ETH_ALEN);
2235 mpath_set_pinfo(mpath, next_hop, pinfo);
2240 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
2241 int idx, u8 *dst, u8 *next_hop,
2242 struct mpath_info *pinfo)
2244 struct ieee80211_sub_if_data *sdata;
2245 struct mesh_path *mpath;
2247 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2250 mpath = mesh_path_lookup_by_idx(sdata, idx);
2255 memcpy(dst, mpath->dst, ETH_ALEN);
2256 mpath_set_pinfo(mpath, next_hop, pinfo);
2261 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2262 struct mpath_info *pinfo)
2264 memset(pinfo, 0, sizeof(*pinfo));
2265 memcpy(mpp, mpath->mpp, ETH_ALEN);
2267 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
2270 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2271 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2274 struct ieee80211_sub_if_data *sdata;
2275 struct mesh_path *mpath;
2277 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2280 mpath = mpp_path_lookup(sdata, dst);
2285 memcpy(dst, mpath->dst, ETH_ALEN);
2286 mpp_set_pinfo(mpath, mpp, pinfo);
2291 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2292 int idx, u8 *dst, u8 *mpp,
2293 struct mpath_info *pinfo)
2295 struct ieee80211_sub_if_data *sdata;
2296 struct mesh_path *mpath;
2298 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2301 mpath = mpp_path_lookup_by_idx(sdata, idx);
2306 memcpy(dst, mpath->dst, ETH_ALEN);
2307 mpp_set_pinfo(mpath, mpp, pinfo);
2312 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
2313 struct net_device *dev,
2314 struct mesh_config *conf)
2316 struct ieee80211_sub_if_data *sdata;
2317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2319 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2323 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2325 return (mask >> (parm-1)) & 0x1;
2328 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2329 const struct mesh_setup *setup)
2332 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2333 struct ieee80211_sub_if_data, u.mesh);
2336 /* allocate information elements */
2339 if (setup->ie_len) {
2340 new_ie = kmemdup(setup->ie, setup->ie_len,
2345 ifmsh->ie_len = setup->ie_len;
2348 /* now copy the rest of the setup parameters */
2349 ifmsh->mesh_id_len = setup->mesh_id_len;
2350 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
2351 ifmsh->mesh_sp_id = setup->sync_method;
2352 ifmsh->mesh_pp_id = setup->path_sel_proto;
2353 ifmsh->mesh_pm_id = setup->path_metric;
2354 ifmsh->user_mpm = setup->user_mpm;
2355 ifmsh->mesh_auth_id = setup->auth_id;
2356 ifmsh->security = IEEE80211_MESH_SEC_NONE;
2357 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
2358 if (setup->is_authenticated)
2359 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2360 if (setup->is_secure)
2361 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
2363 /* mcast rate setting in Mesh Node */
2364 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2365 sizeof(setup->mcast_rate));
2366 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
2368 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2369 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2371 sdata->beacon_rate_set = false;
2372 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2373 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2374 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2375 sdata->beacon_rateidx_mask[i] =
2376 setup->beacon_rate.control[i].legacy;
2377 if (sdata->beacon_rateidx_mask[i])
2378 sdata->beacon_rate_set = true;
2385 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
2386 struct net_device *dev, u32 mask,
2387 const struct mesh_config *nconf)
2389 struct mesh_config *conf;
2390 struct ieee80211_sub_if_data *sdata;
2391 struct ieee80211_if_mesh *ifmsh;
2393 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2394 ifmsh = &sdata->u.mesh;
2396 /* Set the config options which we are interested in setting */
2397 conf = &(sdata->u.mesh.mshcfg);
2398 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2399 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2400 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2401 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2402 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2403 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2404 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2405 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2406 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2407 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2408 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2409 conf->dot11MeshTTL = nconf->dot11MeshTTL;
2410 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
2411 conf->element_ttl = nconf->element_ttl;
2412 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2413 if (ifmsh->user_mpm)
2415 conf->auto_open_plinks = nconf->auto_open_plinks;
2417 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2418 conf->dot11MeshNbrOffsetMaxNeighbor =
2419 nconf->dot11MeshNbrOffsetMaxNeighbor;
2420 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2421 conf->dot11MeshHWMPmaxPREQretries =
2422 nconf->dot11MeshHWMPmaxPREQretries;
2423 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2424 conf->path_refresh_time = nconf->path_refresh_time;
2425 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2426 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2427 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2428 conf->dot11MeshHWMPactivePathTimeout =
2429 nconf->dot11MeshHWMPactivePathTimeout;
2430 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2431 conf->dot11MeshHWMPpreqMinInterval =
2432 nconf->dot11MeshHWMPpreqMinInterval;
2433 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2434 conf->dot11MeshHWMPperrMinInterval =
2435 nconf->dot11MeshHWMPperrMinInterval;
2436 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2438 conf->dot11MeshHWMPnetDiameterTraversalTime =
2439 nconf->dot11MeshHWMPnetDiameterTraversalTime;
2440 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2441 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2442 ieee80211_mesh_root_setup(ifmsh);
2444 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2445 /* our current gate announcement implementation rides on root
2446 * announcements, so require this ifmsh to also be a root node
2448 if (nconf->dot11MeshGateAnnouncementProtocol &&
2449 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2450 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2451 ieee80211_mesh_root_setup(ifmsh);
2453 conf->dot11MeshGateAnnouncementProtocol =
2454 nconf->dot11MeshGateAnnouncementProtocol;
2456 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2457 conf->dot11MeshHWMPRannInterval =
2458 nconf->dot11MeshHWMPRannInterval;
2459 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2460 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2461 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2462 /* our RSSI threshold implementation is supported only for
2463 * devices that report signal in dBm.
2465 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2467 conf->rssi_threshold = nconf->rssi_threshold;
2469 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2470 conf->ht_opmode = nconf->ht_opmode;
2471 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2472 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2475 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2476 conf->dot11MeshHWMPactivePathToRootTimeout =
2477 nconf->dot11MeshHWMPactivePathToRootTimeout;
2478 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2479 conf->dot11MeshHWMProotInterval =
2480 nconf->dot11MeshHWMProotInterval;
2481 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2482 conf->dot11MeshHWMPconfirmationInterval =
2483 nconf->dot11MeshHWMPconfirmationInterval;
2484 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2485 conf->power_mode = nconf->power_mode;
2486 ieee80211_mps_local_status_update(sdata);
2488 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2489 conf->dot11MeshAwakeWindowDuration =
2490 nconf->dot11MeshAwakeWindowDuration;
2491 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2492 conf->plink_timeout = nconf->plink_timeout;
2493 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2494 conf->dot11MeshConnectedToMeshGate =
2495 nconf->dot11MeshConnectedToMeshGate;
2496 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2497 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
2498 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2499 conf->dot11MeshConnectedToAuthServer =
2500 nconf->dot11MeshConnectedToAuthServer;
2501 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2505 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2506 const struct mesh_config *conf,
2507 const struct mesh_setup *setup)
2509 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2510 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2513 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2514 err = copy_mesh_setup(ifmsh, setup);
2518 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2520 /* can mesh use other SMPS modes? */
2521 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2522 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
2524 mutex_lock(&sdata->local->mtx);
2525 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
2526 IEEE80211_CHANCTX_SHARED);
2527 mutex_unlock(&sdata->local->mtx);
2531 return ieee80211_start_mesh(sdata);
2534 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2536 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2538 ieee80211_stop_mesh(sdata);
2539 mutex_lock(&sdata->local->mtx);
2540 ieee80211_link_release_channel(&sdata->deflink);
2541 kfree(sdata->u.mesh.ie);
2542 mutex_unlock(&sdata->local->mtx);
2548 static int ieee80211_change_bss(struct wiphy *wiphy,
2549 struct net_device *dev,
2550 struct bss_parameters *params)
2552 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2553 struct ieee80211_supported_band *sband;
2556 if (!sdata_dereference(sdata->deflink.u.ap.beacon, sdata))
2559 sband = ieee80211_get_sband(sdata);
2563 if (params->use_cts_prot >= 0) {
2564 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2565 changed |= BSS_CHANGED_ERP_CTS_PROT;
2567 if (params->use_short_preamble >= 0) {
2568 sdata->vif.bss_conf.use_short_preamble =
2569 params->use_short_preamble;
2570 changed |= BSS_CHANGED_ERP_PREAMBLE;
2573 if (!sdata->vif.bss_conf.use_short_slot &&
2574 (sband->band == NL80211_BAND_5GHZ ||
2575 sband->band == NL80211_BAND_6GHZ)) {
2576 sdata->vif.bss_conf.use_short_slot = true;
2577 changed |= BSS_CHANGED_ERP_SLOT;
2580 if (params->use_short_slot_time >= 0) {
2581 sdata->vif.bss_conf.use_short_slot =
2582 params->use_short_slot_time;
2583 changed |= BSS_CHANGED_ERP_SLOT;
2586 if (params->basic_rates) {
2587 ieee80211_parse_bitrates(sdata->vif.bss_conf.chandef.width,
2588 wiphy->bands[sband->band],
2589 params->basic_rates,
2590 params->basic_rates_len,
2591 &sdata->vif.bss_conf.basic_rates);
2592 changed |= BSS_CHANGED_BASIC_RATES;
2593 ieee80211_check_rate_mask(&sdata->deflink);
2596 if (params->ap_isolate >= 0) {
2597 if (params->ap_isolate)
2598 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2600 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2601 ieee80211_check_fast_rx_iface(sdata);
2604 if (params->ht_opmode >= 0) {
2605 sdata->vif.bss_conf.ht_operation_mode =
2606 (u16) params->ht_opmode;
2607 changed |= BSS_CHANGED_HT;
2610 if (params->p2p_ctwindow >= 0) {
2611 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2612 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2613 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2614 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2615 changed |= BSS_CHANGED_P2P_PS;
2618 if (params->p2p_opp_ps > 0) {
2619 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2620 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2621 changed |= BSS_CHANGED_P2P_PS;
2622 } else if (params->p2p_opp_ps == 0) {
2623 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2624 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2625 changed |= BSS_CHANGED_P2P_PS;
2628 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
2633 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2634 struct net_device *dev,
2635 struct ieee80211_txq_params *params)
2637 struct ieee80211_local *local = wiphy_priv(wiphy);
2638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2639 struct ieee80211_link_data *link =
2640 ieee80211_link_or_deflink(sdata, params->link_id, true);
2641 struct ieee80211_tx_queue_params p;
2643 if (!local->ops->conf_tx)
2646 if (local->hw.queues < IEEE80211_NUM_ACS)
2650 return PTR_ERR(link);
2652 memset(&p, 0, sizeof(p));
2653 p.aifs = params->aifs;
2654 p.cw_max = params->cwmax;
2655 p.cw_min = params->cwmin;
2656 p.txop = params->txop;
2659 * Setting tx queue params disables u-apsd because it's only
2660 * called in master mode.
2664 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2666 link->tx_conf[params->ac] = p;
2667 if (drv_conf_tx(local, link, params->ac, &p)) {
2668 wiphy_debug(local->hw.wiphy,
2669 "failed to set TX queue parameters for AC %d\n",
2674 ieee80211_link_info_change_notify(sdata, link,
2681 static int ieee80211_suspend(struct wiphy *wiphy,
2682 struct cfg80211_wowlan *wowlan)
2684 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2687 static int ieee80211_resume(struct wiphy *wiphy)
2689 return __ieee80211_resume(wiphy_priv(wiphy));
2692 #define ieee80211_suspend NULL
2693 #define ieee80211_resume NULL
2696 static int ieee80211_scan(struct wiphy *wiphy,
2697 struct cfg80211_scan_request *req)
2699 struct ieee80211_sub_if_data *sdata;
2701 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2703 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2704 case NL80211_IFTYPE_STATION:
2705 case NL80211_IFTYPE_ADHOC:
2706 case NL80211_IFTYPE_MESH_POINT:
2707 case NL80211_IFTYPE_P2P_CLIENT:
2708 case NL80211_IFTYPE_P2P_DEVICE:
2710 case NL80211_IFTYPE_P2P_GO:
2711 if (sdata->local->ops->hw_scan)
2714 * FIXME: implement NoA while scanning in software,
2715 * for now fall through to allow scanning only when
2716 * beaconing hasn't been configured yet
2719 case NL80211_IFTYPE_AP:
2721 * If the scan has been forced (and the driver supports
2722 * forcing), don't care about being beaconing already.
2723 * This will create problems to the attached stations (e.g. all
2724 * the frames sent while scanning on other channel will be
2727 if (sdata->deflink.u.ap.beacon &&
2728 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2729 !(req->flags & NL80211_SCAN_FLAG_AP)))
2732 case NL80211_IFTYPE_NAN:
2737 return ieee80211_request_scan(sdata, req);
2740 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2742 ieee80211_scan_cancel(wiphy_priv(wiphy));
2746 ieee80211_sched_scan_start(struct wiphy *wiphy,
2747 struct net_device *dev,
2748 struct cfg80211_sched_scan_request *req)
2750 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2752 if (!sdata->local->ops->sched_scan_start)
2755 return ieee80211_request_sched_scan_start(sdata, req);
2759 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2762 struct ieee80211_local *local = wiphy_priv(wiphy);
2764 if (!local->ops->sched_scan_stop)
2767 return ieee80211_request_sched_scan_stop(local);
2770 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2771 struct cfg80211_auth_request *req)
2773 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2776 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2777 struct cfg80211_assoc_request *req)
2779 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2782 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2783 struct cfg80211_deauth_request *req)
2785 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2788 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2789 struct cfg80211_disassoc_request *req)
2791 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2794 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2795 struct cfg80211_ibss_params *params)
2797 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2800 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2802 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2805 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2806 struct ocb_setup *setup)
2808 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2811 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2813 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2816 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2817 int rate[NUM_NL80211_BANDS])
2819 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2821 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2822 sizeof(int) * NUM_NL80211_BANDS);
2824 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2825 BSS_CHANGED_MCAST_RATE);
2830 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2832 struct ieee80211_local *local = wiphy_priv(wiphy);
2835 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2836 ieee80211_check_fast_xmit_all(local);
2838 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2841 ieee80211_check_fast_xmit_all(local);
2846 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2847 (changed & WIPHY_PARAM_DYN_ACK)) {
2850 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2851 wiphy->coverage_class : -1;
2852 err = drv_set_coverage_class(local, coverage_class);
2858 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2859 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2865 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2866 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2868 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2870 if (changed & WIPHY_PARAM_RETRY_LONG) {
2871 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2873 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2876 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2877 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2879 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2880 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2881 WIPHY_PARAM_TXQ_QUANTUM))
2882 ieee80211_txq_set_params(local);
2887 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2888 struct wireless_dev *wdev,
2889 enum nl80211_tx_power_setting type, int mbm)
2891 struct ieee80211_local *local = wiphy_priv(wiphy);
2892 struct ieee80211_sub_if_data *sdata;
2893 enum nl80211_tx_power_setting txp_type = type;
2894 bool update_txp_type = false;
2895 bool has_monitor = false;
2898 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2900 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2901 sdata = wiphy_dereference(local->hw.wiphy,
2902 local->monitor_sdata);
2908 case NL80211_TX_POWER_AUTOMATIC:
2909 sdata->deflink.user_power_level =
2910 IEEE80211_UNSET_POWER_LEVEL;
2911 txp_type = NL80211_TX_POWER_LIMITED;
2913 case NL80211_TX_POWER_LIMITED:
2914 case NL80211_TX_POWER_FIXED:
2915 if (mbm < 0 || (mbm % 100))
2917 sdata->deflink.user_power_level = MBM_TO_DBM(mbm);
2921 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2922 update_txp_type = true;
2923 sdata->vif.bss_conf.txpower_type = txp_type;
2926 ieee80211_recalc_txpower(sdata, update_txp_type);
2932 case NL80211_TX_POWER_AUTOMATIC:
2933 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2934 txp_type = NL80211_TX_POWER_LIMITED;
2936 case NL80211_TX_POWER_LIMITED:
2937 case NL80211_TX_POWER_FIXED:
2938 if (mbm < 0 || (mbm % 100))
2940 local->user_power_level = MBM_TO_DBM(mbm);
2944 mutex_lock(&local->iflist_mtx);
2945 list_for_each_entry(sdata, &local->interfaces, list) {
2946 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2950 sdata->deflink.user_power_level = local->user_power_level;
2951 if (txp_type != sdata->vif.bss_conf.txpower_type)
2952 update_txp_type = true;
2953 sdata->vif.bss_conf.txpower_type = txp_type;
2955 list_for_each_entry(sdata, &local->interfaces, list) {
2956 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2958 ieee80211_recalc_txpower(sdata, update_txp_type);
2960 mutex_unlock(&local->iflist_mtx);
2963 sdata = wiphy_dereference(local->hw.wiphy,
2964 local->monitor_sdata);
2966 sdata->deflink.user_power_level = local->user_power_level;
2967 if (txp_type != sdata->vif.bss_conf.txpower_type)
2968 update_txp_type = true;
2969 sdata->vif.bss_conf.txpower_type = txp_type;
2971 ieee80211_recalc_txpower(sdata, update_txp_type);
2978 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2979 struct wireless_dev *wdev,
2982 struct ieee80211_local *local = wiphy_priv(wiphy);
2983 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2985 if (local->ops->get_txpower)
2986 return drv_get_txpower(local, sdata, dbm);
2988 if (!local->use_chanctx)
2989 *dbm = local->hw.conf.power_level;
2991 *dbm = sdata->vif.bss_conf.txpower;
2996 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2998 struct ieee80211_local *local = wiphy_priv(wiphy);
3000 drv_rfkill_poll(local);
3003 #ifdef CONFIG_NL80211_TESTMODE
3004 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
3005 struct wireless_dev *wdev,
3006 void *data, int len)
3008 struct ieee80211_local *local = wiphy_priv(wiphy);
3009 struct ieee80211_vif *vif = NULL;
3011 if (!local->ops->testmode_cmd)
3015 struct ieee80211_sub_if_data *sdata;
3017 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3018 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
3022 return local->ops->testmode_cmd(&local->hw, vif, data, len);
3025 static int ieee80211_testmode_dump(struct wiphy *wiphy,
3026 struct sk_buff *skb,
3027 struct netlink_callback *cb,
3028 void *data, int len)
3030 struct ieee80211_local *local = wiphy_priv(wiphy);
3032 if (!local->ops->testmode_dump)
3035 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
3039 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
3040 struct ieee80211_link_data *link,
3041 enum ieee80211_smps_mode smps_mode)
3044 enum ieee80211_smps_mode old_req;
3046 struct sta_info *sta;
3047 bool tdls_peer_found = false;
3049 lockdep_assert_held(&sdata->wdev.mtx);
3051 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
3054 old_req = link->u.mgd.req_smps;
3055 link->u.mgd.req_smps = smps_mode;
3057 if (old_req == smps_mode &&
3058 smps_mode != IEEE80211_SMPS_AUTOMATIC)
3062 * If not associated, or current association is not an HT
3063 * association, there's no need to do anything, just store
3064 * the new value until we associate.
3066 if (!sdata->u.mgd.associated ||
3067 link->conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
3070 ap = link->u.mgd.bssid;
3073 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
3074 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
3075 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
3078 tdls_peer_found = true;
3083 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
3084 if (tdls_peer_found || !sdata->u.mgd.powersave)
3085 smps_mode = IEEE80211_SMPS_OFF;
3087 smps_mode = IEEE80211_SMPS_DYNAMIC;
3090 /* send SM PS frame to AP */
3091 err = ieee80211_send_smps_action(sdata, smps_mode,
3094 link->u.mgd.req_smps = old_req;
3095 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
3096 ieee80211_teardown_tdls_peers(sdata);
3101 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
3102 bool enabled, int timeout)
3104 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3105 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3106 unsigned int link_id;
3108 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3111 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
3114 if (enabled == sdata->u.mgd.powersave &&
3115 timeout == local->dynamic_ps_forced_timeout)
3118 sdata->u.mgd.powersave = enabled;
3119 local->dynamic_ps_forced_timeout = timeout;
3121 /* no change, but if automatic follow powersave */
3123 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3124 struct ieee80211_link_data *link;
3126 link = sdata_dereference(sdata->link[link_id], sdata);
3130 __ieee80211_request_smps_mgd(sdata, link,
3131 link->u.mgd.req_smps);
3133 sdata_unlock(sdata);
3135 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
3136 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
3138 ieee80211_recalc_ps(local);
3139 ieee80211_recalc_ps_vif(sdata);
3140 ieee80211_check_fast_rx_iface(sdata);
3145 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
3146 struct net_device *dev,
3147 s32 rssi_thold, u32 rssi_hyst)
3149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3150 struct ieee80211_vif *vif = &sdata->vif;
3151 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3153 if (rssi_thold == bss_conf->cqm_rssi_thold &&
3154 rssi_hyst == bss_conf->cqm_rssi_hyst)
3157 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
3158 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
3161 bss_conf->cqm_rssi_thold = rssi_thold;
3162 bss_conf->cqm_rssi_hyst = rssi_hyst;
3163 bss_conf->cqm_rssi_low = 0;
3164 bss_conf->cqm_rssi_high = 0;
3165 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3167 /* tell the driver upon association, unless already associated */
3168 if (sdata->u.mgd.associated &&
3169 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3170 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3176 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
3177 struct net_device *dev,
3178 s32 rssi_low, s32 rssi_high)
3180 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3181 struct ieee80211_vif *vif = &sdata->vif;
3182 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3184 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
3187 bss_conf->cqm_rssi_low = rssi_low;
3188 bss_conf->cqm_rssi_high = rssi_high;
3189 bss_conf->cqm_rssi_thold = 0;
3190 bss_conf->cqm_rssi_hyst = 0;
3191 sdata->deflink.u.mgd.last_cqm_event_signal = 0;
3193 /* tell the driver upon association, unless already associated */
3194 if (sdata->u.mgd.associated &&
3195 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
3196 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3202 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3203 struct net_device *dev,
3204 unsigned int link_id,
3206 const struct cfg80211_bitrate_mask *mask)
3208 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3209 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
3212 if (!ieee80211_sdata_running(sdata))
3216 * If active validate the setting and reject it if it doesn't leave
3217 * at least one basic rate usable, since we really have to be able
3218 * to send something, and if we're an AP we have to be able to do
3219 * so at a basic rate so that all clients can receive it.
3221 if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) &&
3222 sdata->vif.bss_conf.chandef.chan) {
3223 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3224 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3226 if (!(mask->control[band].legacy & basic_rates))
3230 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3231 ret = drv_set_bitrate_mask(local, sdata, mask);
3236 for (i = 0; i < NUM_NL80211_BANDS; i++) {
3237 struct ieee80211_supported_band *sband = wiphy->bands[i];
3240 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
3241 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3242 sizeof(mask->control[i].ht_mcs));
3243 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3244 mask->control[i].vht_mcs,
3245 sizeof(mask->control[i].vht_mcs));
3247 sdata->rc_has_mcs_mask[i] = false;
3248 sdata->rc_has_vht_mcs_mask[i] = false;
3252 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
3253 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
3254 sdata->rc_has_mcs_mask[i] = true;
3259 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
3260 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
3261 sdata->rc_has_vht_mcs_mask[i] = true;
3270 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3271 struct net_device *dev,
3272 struct cfg80211_chan_def *chandef,
3275 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3276 struct ieee80211_local *local = sdata->local;
3279 mutex_lock(&local->mtx);
3280 if (!list_empty(&local->roc_list) || local->scanning) {
3285 /* whatever, but channel contexts should not complain about that one */
3286 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
3287 sdata->deflink.needed_rx_chains = local->rx_chains;
3289 err = ieee80211_link_use_channel(&sdata->deflink, chandef,
3290 IEEE80211_CHANCTX_SHARED);
3294 ieee80211_queue_delayed_work(&sdata->local->hw,
3295 &sdata->deflink.dfs_cac_timer_work,
3296 msecs_to_jiffies(cac_time_ms));
3299 mutex_unlock(&local->mtx);
3303 static void ieee80211_end_cac(struct wiphy *wiphy,
3304 struct net_device *dev)
3306 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3307 struct ieee80211_local *local = sdata->local;
3309 mutex_lock(&local->mtx);
3310 list_for_each_entry(sdata, &local->interfaces, list) {
3311 /* it might be waiting for the local->mtx, but then
3312 * by the time it gets it, sdata->wdev.cac_started
3313 * will no longer be true
3315 cancel_delayed_work(&sdata->deflink.dfs_cac_timer_work);
3317 if (sdata->wdev.cac_started) {
3318 ieee80211_link_release_channel(&sdata->deflink);
3319 sdata->wdev.cac_started = false;
3322 mutex_unlock(&local->mtx);
3325 static struct cfg80211_beacon_data *
3326 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3328 struct cfg80211_beacon_data *new_beacon;
3332 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3333 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3334 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len +
3335 ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies);
3337 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3341 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) {
3342 new_beacon->mbssid_ies =
3343 kzalloc(struct_size(new_beacon->mbssid_ies,
3344 elem, beacon->mbssid_ies->cnt),
3346 if (!new_beacon->mbssid_ies) {
3352 pos = (u8 *)(new_beacon + 1);
3353 if (beacon->head_len) {
3354 new_beacon->head_len = beacon->head_len;
3355 new_beacon->head = pos;
3356 memcpy(pos, beacon->head, beacon->head_len);
3357 pos += beacon->head_len;
3359 if (beacon->tail_len) {
3360 new_beacon->tail_len = beacon->tail_len;
3361 new_beacon->tail = pos;
3362 memcpy(pos, beacon->tail, beacon->tail_len);
3363 pos += beacon->tail_len;
3365 if (beacon->beacon_ies_len) {
3366 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3367 new_beacon->beacon_ies = pos;
3368 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3369 pos += beacon->beacon_ies_len;
3371 if (beacon->proberesp_ies_len) {
3372 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3373 new_beacon->proberesp_ies = pos;
3374 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3375 pos += beacon->proberesp_ies_len;
3377 if (beacon->assocresp_ies_len) {
3378 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3379 new_beacon->assocresp_ies = pos;
3380 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3381 pos += beacon->assocresp_ies_len;
3383 if (beacon->probe_resp_len) {
3384 new_beacon->probe_resp_len = beacon->probe_resp_len;
3385 new_beacon->probe_resp = pos;
3386 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3387 pos += beacon->probe_resp_len;
3389 if (beacon->mbssid_ies && beacon->mbssid_ies->cnt)
3390 pos += ieee80211_copy_mbssid_beacon(pos,
3391 new_beacon->mbssid_ies,
3392 beacon->mbssid_ies);
3394 /* might copy -1, meaning no changes requested */
3395 new_beacon->ftm_responder = beacon->ftm_responder;
3397 new_beacon->lci_len = beacon->lci_len;
3398 new_beacon->lci = pos;
3399 memcpy(pos, beacon->lci, beacon->lci_len);
3400 pos += beacon->lci_len;
3402 if (beacon->civicloc) {
3403 new_beacon->civicloc_len = beacon->civicloc_len;
3404 new_beacon->civicloc = pos;
3405 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3406 pos += beacon->civicloc_len;
3412 void ieee80211_csa_finish(struct ieee80211_vif *vif)
3414 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3415 struct ieee80211_local *local = sdata->local;
3419 if (vif->mbssid_tx_vif == vif) {
3420 /* Trigger ieee80211_csa_finish() on the non-transmitting
3421 * interfaces when channel switch is received on
3422 * transmitting interface
3424 struct ieee80211_sub_if_data *iter;
3426 list_for_each_entry_rcu(iter, &local->interfaces, list) {
3427 if (!ieee80211_sdata_running(iter))
3430 if (iter == sdata || iter->vif.mbssid_tx_vif != vif)
3433 ieee80211_queue_work(&iter->local->hw,
3434 &iter->deflink.csa_finalize_work);
3437 ieee80211_queue_work(&local->hw, &sdata->deflink.csa_finalize_work);
3441 EXPORT_SYMBOL(ieee80211_csa_finish);
3443 void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3445 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3446 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3447 struct ieee80211_local *local = sdata->local;
3449 sdata->deflink.csa_block_tx = block_tx;
3450 sdata_info(sdata, "channel switch failed, disconnecting\n");
3451 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3453 EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3455 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3460 switch (sdata->vif.type) {
3461 case NL80211_IFTYPE_AP:
3462 if (!sdata->deflink.u.ap.next_beacon)
3465 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3466 sdata->deflink.u.ap.next_beacon,
3468 ieee80211_free_next_beacon(&sdata->deflink);
3474 case NL80211_IFTYPE_ADHOC:
3475 err = ieee80211_ibss_finish_csa(sdata);
3480 #ifdef CONFIG_MAC80211_MESH
3481 case NL80211_IFTYPE_MESH_POINT:
3482 err = ieee80211_mesh_finish_csa(sdata);
3496 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3498 struct ieee80211_local *local = sdata->local;
3502 sdata_assert_lock(sdata);
3503 lockdep_assert_held(&local->mtx);
3504 lockdep_assert_held(&local->chanctx_mtx);
3507 * using reservation isn't immediate as it may be deferred until later
3508 * with multi-vif. once reservation is complete it will re-schedule the
3509 * work with no reserved_chanctx so verify chandef to check if it
3510 * completed successfully
3513 if (sdata->deflink.reserved_chanctx) {
3515 * with multi-vif csa driver may call ieee80211_csa_finish()
3516 * many times while waiting for other interfaces to use their
3519 if (sdata->deflink.reserved_ready)
3522 return ieee80211_link_use_reserved_context(&sdata->deflink);
3525 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3526 &sdata->deflink.csa_chandef))
3529 sdata->vif.bss_conf.csa_active = false;
3531 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3535 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
3537 if (sdata->deflink.csa_block_tx) {
3538 ieee80211_wake_vif_queues(local, sdata,
3539 IEEE80211_QUEUE_STOP_REASON_CSA);
3540 sdata->deflink.csa_block_tx = false;
3543 err = drv_post_channel_switch(sdata);
3547 cfg80211_ch_switch_notify(sdata->dev, &sdata->deflink.csa_chandef, 0);
3552 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3554 if (__ieee80211_csa_finalize(sdata)) {
3555 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3556 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3561 void ieee80211_csa_finalize_work(struct work_struct *work)
3563 struct ieee80211_sub_if_data *sdata =
3564 container_of(work, struct ieee80211_sub_if_data,
3565 deflink.csa_finalize_work);
3566 struct ieee80211_local *local = sdata->local;
3569 mutex_lock(&local->mtx);
3570 mutex_lock(&local->chanctx_mtx);
3572 /* AP might have been stopped while waiting for the lock. */
3573 if (!sdata->vif.bss_conf.csa_active)
3576 if (!ieee80211_sdata_running(sdata))
3579 ieee80211_csa_finalize(sdata);
3582 mutex_unlock(&local->chanctx_mtx);
3583 mutex_unlock(&local->mtx);
3584 sdata_unlock(sdata);
3587 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3588 struct cfg80211_csa_settings *params,
3591 struct ieee80211_csa_settings csa = {};
3594 switch (sdata->vif.type) {
3595 case NL80211_IFTYPE_AP:
3596 sdata->deflink.u.ap.next_beacon =
3597 cfg80211_beacon_dup(¶ms->beacon_after);
3598 if (!sdata->deflink.u.ap.next_beacon)
3602 * With a count of 0, we don't have to wait for any
3603 * TBTT before switching, so complete the CSA
3604 * immediately. In theory, with a count == 1 we
3605 * should delay the switch until just before the next
3606 * TBTT, but that would complicate things so we switch
3607 * immediately too. If we would delay the switch
3608 * until the next TBTT, we would have to set the probe
3611 * TODO: A channel switch with count <= 1 without
3612 * sending a CSA action frame is kind of useless,
3613 * because the clients won't know we're changing
3614 * channels. The action frame must be implemented
3615 * either here or in the userspace.
3617 if (params->count <= 1)
3620 if ((params->n_counter_offsets_beacon >
3621 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
3622 (params->n_counter_offsets_presp >
3623 IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) {
3624 ieee80211_free_next_beacon(&sdata->deflink);
3628 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3629 csa.counter_offsets_presp = params->counter_offsets_presp;
3630 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3631 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3632 csa.count = params->count;
3634 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
3635 ¶ms->beacon_csa, &csa,
3638 ieee80211_free_next_beacon(&sdata->deflink);
3644 case NL80211_IFTYPE_ADHOC:
3645 if (!sdata->vif.cfg.ibss_joined)
3648 if (params->chandef.width != sdata->u.ibss.chandef.width)
3651 switch (params->chandef.width) {
3652 case NL80211_CHAN_WIDTH_40:
3653 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3654 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3657 case NL80211_CHAN_WIDTH_5:
3658 case NL80211_CHAN_WIDTH_10:
3659 case NL80211_CHAN_WIDTH_20_NOHT:
3660 case NL80211_CHAN_WIDTH_20:
3666 /* changes into another band are not supported */
3667 if (sdata->u.ibss.chandef.chan->band !=
3668 params->chandef.chan->band)
3671 /* see comments in the NL80211_IFTYPE_AP block */
3672 if (params->count > 1) {
3673 err = ieee80211_ibss_csa_beacon(sdata, params);
3679 ieee80211_send_action_csa(sdata, params);
3682 #ifdef CONFIG_MAC80211_MESH
3683 case NL80211_IFTYPE_MESH_POINT: {
3684 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3686 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3689 /* changes into another band are not supported */
3690 if (sdata->vif.bss_conf.chandef.chan->band !=
3691 params->chandef.chan->band)
3694 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3695 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3696 if (!ifmsh->pre_value)
3697 ifmsh->pre_value = 1;
3702 /* see comments in the NL80211_IFTYPE_AP block */
3703 if (params->count > 1) {
3704 err = ieee80211_mesh_csa_beacon(sdata, params);
3706 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3712 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3713 ieee80211_send_action_csa(sdata, params);
3725 static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3727 sdata->vif.bss_conf.color_change_active = false;
3729 ieee80211_free_next_beacon(&sdata->deflink);
3731 cfg80211_color_change_aborted_notify(sdata->dev);
3735 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3736 struct cfg80211_csa_settings *params)
3738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3739 struct ieee80211_local *local = sdata->local;
3740 struct ieee80211_channel_switch ch_switch;
3741 struct ieee80211_chanctx_conf *conf;
3742 struct ieee80211_chanctx *chanctx;
3746 sdata_assert_lock(sdata);
3747 lockdep_assert_held(&local->mtx);
3749 if (!list_empty(&local->roc_list) || local->scanning)
3752 if (sdata->wdev.cac_started)
3755 if (cfg80211_chandef_identical(¶ms->chandef,
3756 &sdata->vif.bss_conf.chandef))
3759 /* don't allow another channel switch if one is already active. */
3760 if (sdata->vif.bss_conf.csa_active)
3763 mutex_lock(&local->chanctx_mtx);
3764 conf = rcu_dereference_protected(sdata->vif.bss_conf.chanctx_conf,
3765 lockdep_is_held(&local->chanctx_mtx));
3771 if (params->chandef.chan->freq_offset) {
3772 /* this may work, but is untested */
3777 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3779 ch_switch.timestamp = 0;
3780 ch_switch.device_timestamp = 0;
3781 ch_switch.block_tx = params->block_tx;
3782 ch_switch.chandef = params->chandef;
3783 ch_switch.count = params->count;
3785 err = drv_pre_channel_switch(sdata, &ch_switch);
3789 err = ieee80211_link_reserve_chanctx(&sdata->deflink, ¶ms->chandef,
3791 params->radar_required);
3795 /* if reservation is invalid then this will fail */
3796 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3798 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3802 /* if there is a color change in progress, abort it */
3803 if (sdata->vif.bss_conf.color_change_active)
3804 ieee80211_color_change_abort(sdata);
3806 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3808 ieee80211_link_unreserve_chanctx(&sdata->deflink);
3812 sdata->deflink.csa_chandef = params->chandef;
3813 sdata->deflink.csa_block_tx = params->block_tx;
3814 sdata->vif.bss_conf.csa_active = true;
3816 if (sdata->deflink.csa_block_tx)
3817 ieee80211_stop_vif_queues(local, sdata,
3818 IEEE80211_QUEUE_STOP_REASON_CSA);
3820 cfg80211_ch_switch_started_notify(sdata->dev,
3821 &sdata->deflink.csa_chandef,
3822 params->count, params->block_tx);
3825 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3827 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3829 /* if the beacon didn't change, we can finalize immediately */
3830 ieee80211_csa_finalize(sdata);
3834 mutex_unlock(&local->chanctx_mtx);
3838 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3839 struct cfg80211_csa_settings *params)
3841 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3842 struct ieee80211_local *local = sdata->local;
3845 mutex_lock(&local->mtx);
3846 err = __ieee80211_channel_switch(wiphy, dev, params);
3847 mutex_unlock(&local->mtx);
3852 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3854 lockdep_assert_held(&local->mtx);
3856 local->roc_cookie_counter++;
3858 /* wow, you wrapped 64 bits ... more likely a bug */
3859 if (WARN_ON(local->roc_cookie_counter == 0))
3860 local->roc_cookie_counter++;
3862 return local->roc_cookie_counter;
3865 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3866 u64 *cookie, gfp_t gfp)
3868 unsigned long spin_flags;
3869 struct sk_buff *ack_skb;
3872 ack_skb = skb_copy(skb, gfp);
3876 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3877 id = idr_alloc(&local->ack_status_frames, ack_skb,
3878 1, 0x2000, GFP_ATOMIC);
3879 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3886 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3888 *cookie = ieee80211_mgmt_tx_cookie(local);
3889 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3895 ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
3896 struct wireless_dev *wdev,
3897 struct mgmt_frame_regs *upd)
3899 struct ieee80211_local *local = wiphy_priv(wiphy);
3900 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3901 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
3902 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
3903 bool global_change, intf_change;
3906 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3907 (local->rx_mcast_action_reg !=
3908 !!(upd->global_mcast_stypes & action_mask));
3909 local->probe_req_reg = upd->global_stypes & preq_mask;
3910 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
3912 intf_change = (sdata->vif.probe_req_reg !=
3913 !!(upd->interface_stypes & preq_mask)) ||
3914 (sdata->vif.rx_mcast_action_reg !=
3915 !!(upd->interface_mcast_stypes & action_mask));
3916 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
3917 sdata->vif.rx_mcast_action_reg =
3918 upd->interface_mcast_stypes & action_mask;
3920 if (!local->open_count)
3923 if (intf_change && ieee80211_sdata_running(sdata))
3924 drv_config_iface_filter(local, sdata,
3925 sdata->vif.probe_req_reg ?
3930 ieee80211_configure_filter(local);
3933 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3935 struct ieee80211_local *local = wiphy_priv(wiphy);
3940 return drv_set_antenna(local, tx_ant, rx_ant);
3943 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3945 struct ieee80211_local *local = wiphy_priv(wiphy);
3947 return drv_get_antenna(local, tx_ant, rx_ant);
3950 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3951 struct net_device *dev,
3952 struct cfg80211_gtk_rekey_data *data)
3954 struct ieee80211_local *local = wiphy_priv(wiphy);
3955 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3957 if (!local->ops->set_rekey_data)
3960 drv_set_rekey_data(local, sdata, data);
3965 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3966 const u8 *peer, u64 *cookie)
3968 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3969 struct ieee80211_local *local = sdata->local;
3970 struct ieee80211_qos_hdr *nullfunc;
3971 struct sk_buff *skb;
3972 int size = sizeof(*nullfunc);
3975 struct ieee80211_tx_info *info;
3976 struct sta_info *sta;
3977 struct ieee80211_chanctx_conf *chanctx_conf;
3978 enum nl80211_band band;
3981 /* the lock is needed to assign the cookie later */
3982 mutex_lock(&local->mtx);
3985 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
3986 if (WARN_ON(!chanctx_conf)) {
3990 band = chanctx_conf->def.chan->band;
3991 sta = sta_info_get_bss(sdata, peer);
4000 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4001 IEEE80211_STYPE_QOS_NULLFUNC |
4002 IEEE80211_FCTL_FROMDS);
4005 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
4006 IEEE80211_STYPE_NULLFUNC |
4007 IEEE80211_FCTL_FROMDS);
4010 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
4018 skb_reserve(skb, local->hw.extra_tx_headroom);
4020 nullfunc = skb_put(skb, size);
4021 nullfunc->frame_control = fc;
4022 nullfunc->duration_id = 0;
4023 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
4024 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
4025 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
4026 nullfunc->seq_ctrl = 0;
4028 info = IEEE80211_SKB_CB(skb);
4030 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
4031 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
4034 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
4037 nullfunc->qos_ctrl = cpu_to_le16(7);
4039 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
4046 ieee80211_xmit(sdata, sta, skb);
4052 mutex_unlock(&local->mtx);
4057 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
4058 struct wireless_dev *wdev,
4059 unsigned int link_id,
4060 struct cfg80211_chan_def *chandef)
4062 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4063 struct ieee80211_local *local = wiphy_priv(wiphy);
4064 struct ieee80211_chanctx_conf *chanctx_conf;
4065 struct ieee80211_link_data *link;
4069 link = rcu_dereference(sdata->link[link_id]);
4075 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4077 *chandef = link->conf->chandef;
4079 } else if (local->open_count > 0 &&
4080 local->open_count == local->monitors &&
4081 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
4082 if (local->use_chanctx)
4083 *chandef = local->monitor_chandef;
4085 *chandef = local->_oper_chandef;
4095 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
4097 drv_set_wakeup(wiphy_priv(wiphy), enabled);
4101 static int ieee80211_set_qos_map(struct wiphy *wiphy,
4102 struct net_device *dev,
4103 struct cfg80211_qos_map *qos_map)
4105 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4106 struct mac80211_qos_map *new_qos_map, *old_qos_map;
4109 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
4112 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
4114 /* A NULL qos_map was passed to disable QoS mapping */
4118 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
4119 rcu_assign_pointer(sdata->qos_map, new_qos_map);
4121 kfree_rcu(old_qos_map, rcu_head);
4126 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
4127 struct net_device *dev,
4128 unsigned int link_id,
4129 struct cfg80211_chan_def *chandef)
4131 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4132 struct ieee80211_link_data *link;
4136 link = sdata_dereference(sdata->link[link_id], sdata);
4138 ret = ieee80211_link_change_bandwidth(link, chandef, &changed);
4140 ieee80211_link_info_change_notify(sdata, link, changed);
4145 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4146 u8 tsid, const u8 *peer, u8 up,
4149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4150 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4151 int ac = ieee802_1d_to_ac[up];
4153 if (sdata->vif.type != NL80211_IFTYPE_STATION)
4156 if (!(sdata->wmm_acm & BIT(up)))
4159 if (ifmgd->tx_tspec[ac].admitted_time)
4162 if (admitted_time) {
4163 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
4164 ifmgd->tx_tspec[ac].tsid = tsid;
4165 ifmgd->tx_tspec[ac].up = up;
4171 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
4172 u8 tsid, const u8 *peer)
4174 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4175 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4176 struct ieee80211_local *local = wiphy_priv(wiphy);
4179 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4180 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
4182 /* skip unused entries */
4183 if (!tx_tspec->admitted_time)
4186 if (tx_tspec->tsid != tsid)
4189 /* due to this new packets will be reassigned to non-ACM ACs */
4192 /* Make sure that all packets have been sent to avoid to
4193 * restore the QoS params on packets that are still on the
4197 ieee80211_flush_queues(local, sdata, false);
4199 /* restore the normal QoS parameters
4200 * (unconditionally to avoid races)
4202 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
4203 tx_tspec->downgraded = false;
4204 ieee80211_sta_handle_tspec_ac_params(sdata);
4206 /* finally clear all the data */
4207 memset(tx_tspec, 0, sizeof(*tx_tspec));
4215 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
4217 enum nl80211_nan_func_term_reason reason,
4220 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4221 struct cfg80211_nan_func *func;
4224 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4227 spin_lock_bh(&sdata->u.nan.func_lock);
4229 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
4230 if (WARN_ON(!func)) {
4231 spin_unlock_bh(&sdata->u.nan.func_lock);
4235 cookie = func->cookie;
4236 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
4238 spin_unlock_bh(&sdata->u.nan.func_lock);
4240 cfg80211_free_nan_func(func);
4242 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
4243 reason, cookie, gfp);
4245 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
4247 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
4248 struct cfg80211_nan_match_params *match,
4251 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4252 struct cfg80211_nan_func *func;
4254 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
4257 spin_lock_bh(&sdata->u.nan.func_lock);
4259 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
4260 if (WARN_ON(!func)) {
4261 spin_unlock_bh(&sdata->u.nan.func_lock);
4264 match->cookie = func->cookie;
4266 spin_unlock_bh(&sdata->u.nan.func_lock);
4268 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4270 EXPORT_SYMBOL(ieee80211_nan_func_match);
4272 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4273 struct net_device *dev,
4276 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4278 sdata->u.ap.multicast_to_unicast = enabled;
4283 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4284 struct txq_info *txqi)
4286 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4287 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4288 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4291 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4292 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4293 txqstats->backlog_packets = txqi->tin.backlog_packets;
4296 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4297 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4298 txqstats->flows = txqi->tin.flows;
4301 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4302 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4303 txqstats->drops = txqi->cstats.drop_count;
4306 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4307 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4308 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4311 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4312 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4313 txqstats->overlimit = txqi->tin.overlimit;
4316 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4317 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4318 txqstats->collisions = txqi->tin.collisions;
4321 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4322 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4323 txqstats->tx_bytes = txqi->tin.tx_bytes;
4326 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4327 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4328 txqstats->tx_packets = txqi->tin.tx_packets;
4332 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4333 struct wireless_dev *wdev,
4334 struct cfg80211_txq_stats *txqstats)
4336 struct ieee80211_local *local = wiphy_priv(wiphy);
4337 struct ieee80211_sub_if_data *sdata;
4340 if (!local->ops->wake_tx_queue)
4343 spin_lock_bh(&local->fq.lock);
4347 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4348 if (!sdata->vif.txq) {
4352 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4355 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4356 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4357 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4358 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4359 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4360 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4361 txqstats->backlog_packets = local->fq.backlog;
4362 txqstats->backlog_bytes = local->fq.memory_usage;
4363 txqstats->overlimit = local->fq.overlimit;
4364 txqstats->overmemory = local->fq.overmemory;
4365 txqstats->collisions = local->fq.collisions;
4366 txqstats->max_flows = local->fq.flows_cnt;
4371 spin_unlock_bh(&local->fq.lock);
4377 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4378 struct net_device *dev,
4379 struct cfg80211_ftm_responder_stats *ftm_stats)
4381 struct ieee80211_local *local = wiphy_priv(wiphy);
4382 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4384 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4388 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4389 struct cfg80211_pmsr_request *request)
4391 struct ieee80211_local *local = wiphy_priv(wiphy);
4392 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4394 return drv_start_pmsr(local, sdata, request);
4398 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4399 struct cfg80211_pmsr_request *request)
4401 struct ieee80211_local *local = wiphy_priv(wiphy);
4402 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4404 return drv_abort_pmsr(local, sdata, request);
4407 static int ieee80211_set_tid_config(struct wiphy *wiphy,
4408 struct net_device *dev,
4409 struct cfg80211_tid_config *tid_conf)
4411 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4412 struct sta_info *sta;
4415 if (!sdata->local->ops->set_tid_config)
4418 if (!tid_conf->peer)
4419 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4421 mutex_lock(&sdata->local->sta_mtx);
4422 sta = sta_info_get_bss(sdata, tid_conf->peer);
4424 mutex_unlock(&sdata->local->sta_mtx);
4428 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4429 mutex_unlock(&sdata->local->sta_mtx);
4434 static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4435 struct net_device *dev,
4436 const u8 *peer, u8 tids)
4438 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4439 struct sta_info *sta;
4442 if (!sdata->local->ops->reset_tid_config)
4446 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
4448 mutex_lock(&sdata->local->sta_mtx);
4449 sta = sta_info_get_bss(sdata, peer);
4451 mutex_unlock(&sdata->local->sta_mtx);
4455 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
4456 mutex_unlock(&sdata->local->sta_mtx);
4461 static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4462 struct cfg80211_sar_specs *sar)
4464 struct ieee80211_local *local = wiphy_priv(wiphy);
4466 if (!local->ops->set_sar_specs)
4469 return local->ops->set_sar_specs(&local->hw, sar);
4473 ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4476 switch (sdata->vif.type) {
4477 case NL80211_IFTYPE_AP: {
4480 if (!sdata->deflink.u.ap.next_beacon)
4483 ret = ieee80211_assign_beacon(sdata, &sdata->deflink,
4484 sdata->deflink.u.ap.next_beacon,
4486 ieee80211_free_next_beacon(&sdata->deflink);
4503 ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4504 struct cfg80211_color_change_settings *params,
4507 struct ieee80211_color_change_settings color_change = {};
4510 switch (sdata->vif.type) {
4511 case NL80211_IFTYPE_AP:
4512 sdata->deflink.u.ap.next_beacon =
4513 cfg80211_beacon_dup(¶ms->beacon_next);
4514 if (!sdata->deflink.u.ap.next_beacon)
4517 if (params->count <= 1)
4520 color_change.counter_offset_beacon =
4521 params->counter_offset_beacon;
4522 color_change.counter_offset_presp =
4523 params->counter_offset_presp;
4524 color_change.count = params->count;
4526 err = ieee80211_assign_beacon(sdata, &sdata->deflink,
4527 ¶ms->beacon_color_change,
4528 NULL, &color_change);
4530 ieee80211_free_next_beacon(&sdata->deflink);
4543 ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4544 u8 color, int enable, u32 changed)
4546 sdata->vif.bss_conf.he_bss_color.color = color;
4547 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4548 changed |= BSS_CHANGED_HE_BSS_COLOR;
4550 ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed);
4552 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4553 struct ieee80211_sub_if_data *child;
4555 mutex_lock(&sdata->local->iflist_mtx);
4556 list_for_each_entry(child, &sdata->local->interfaces, list) {
4557 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4558 child->vif.bss_conf.he_bss_color.color = color;
4559 child->vif.bss_conf.he_bss_color.enabled = enable;
4560 ieee80211_link_info_change_notify(child,
4562 BSS_CHANGED_HE_BSS_COLOR);
4565 mutex_unlock(&sdata->local->iflist_mtx);
4569 static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4571 struct ieee80211_local *local = sdata->local;
4575 sdata_assert_lock(sdata);
4576 lockdep_assert_held(&local->mtx);
4578 sdata->vif.bss_conf.color_change_active = false;
4580 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4582 cfg80211_color_change_aborted_notify(sdata->dev);
4586 ieee80211_color_change_bss_config_notify(sdata,
4587 sdata->vif.bss_conf.color_change_color,
4589 cfg80211_color_change_notify(sdata->dev);
4594 void ieee80211_color_change_finalize_work(struct work_struct *work)
4596 struct ieee80211_sub_if_data *sdata =
4597 container_of(work, struct ieee80211_sub_if_data,
4598 deflink.color_change_finalize_work);
4599 struct ieee80211_local *local = sdata->local;
4602 mutex_lock(&local->mtx);
4604 /* AP might have been stopped while waiting for the lock. */
4605 if (!sdata->vif.bss_conf.color_change_active)
4608 if (!ieee80211_sdata_running(sdata))
4611 ieee80211_color_change_finalize(sdata);
4614 mutex_unlock(&local->mtx);
4615 sdata_unlock(sdata);
4618 void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4620 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4622 ieee80211_queue_work(&sdata->local->hw,
4623 &sdata->deflink.color_change_finalize_work);
4625 EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4628 ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4629 u64 color_bitmap, gfp_t gfp)
4631 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4633 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active)
4636 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap, gfp);
4638 EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4641 ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4642 struct cfg80211_color_change_settings *params)
4644 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4645 struct ieee80211_local *local = sdata->local;
4649 sdata_assert_lock(sdata);
4651 if (sdata->vif.bss_conf.nontransmitted)
4654 mutex_lock(&local->mtx);
4656 /* don't allow another color change if one is already active or if csa
4659 if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) {
4664 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4668 sdata->vif.bss_conf.color_change_active = true;
4669 sdata->vif.bss_conf.color_change_color = params->color;
4671 cfg80211_color_change_started_notify(sdata->dev, params->count);
4674 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4676 /* if the beacon didn't change, we can finalize immediately */
4677 ieee80211_color_change_finalize(sdata);
4680 mutex_unlock(&local->mtx);
4686 ieee80211_set_radar_background(struct wiphy *wiphy,
4687 struct cfg80211_chan_def *chandef)
4689 struct ieee80211_local *local = wiphy_priv(wiphy);
4691 if (!local->ops->set_radar_background)
4694 return local->ops->set_radar_background(&local->hw, chandef);
4697 static int ieee80211_add_intf_link(struct wiphy *wiphy,
4698 struct wireless_dev *wdev,
4699 unsigned int link_id)
4701 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4703 return ieee80211_vif_set_links(sdata, wdev->valid_links);
4706 static void ieee80211_del_intf_link(struct wiphy *wiphy,
4707 struct wireless_dev *wdev,
4708 unsigned int link_id)
4710 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4712 ieee80211_vif_set_links(sdata, wdev->valid_links);
4715 static int sta_add_link_station(struct ieee80211_local *local,
4716 struct ieee80211_sub_if_data *sdata,
4717 struct link_station_parameters *params)
4719 struct sta_info *sta;
4722 sta = sta_info_get_bss(sdata, params->mld_mac);
4726 if (!sta->sta.valid_links)
4729 if (sta->sta.valid_links & BIT(params->link_id))
4732 ret = ieee80211_sta_allocate_link(sta, params->link_id);
4736 ret = sta_link_apply_parameters(local, sta, true, params);
4738 ieee80211_sta_free_link(sta, params->link_id);
4742 /* ieee80211_sta_activate_link frees the link upon failure */
4743 return ieee80211_sta_activate_link(sta, params->link_id);
4747 ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev,
4748 struct link_station_parameters *params)
4750 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4751 struct ieee80211_local *local = wiphy_priv(wiphy);
4754 mutex_lock(&sdata->local->sta_mtx);
4755 ret = sta_add_link_station(local, sdata, params);
4756 mutex_unlock(&sdata->local->sta_mtx);
4761 static int sta_mod_link_station(struct ieee80211_local *local,
4762 struct ieee80211_sub_if_data *sdata,
4763 struct link_station_parameters *params)
4765 struct sta_info *sta;
4767 sta = sta_info_get_bss(sdata, params->mld_mac);
4771 if (!(sta->sta.valid_links & BIT(params->link_id)))
4774 return sta_link_apply_parameters(local, sta, false, params);
4778 ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev,
4779 struct link_station_parameters *params)
4781 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4782 struct ieee80211_local *local = wiphy_priv(wiphy);
4785 mutex_lock(&sdata->local->sta_mtx);
4786 ret = sta_mod_link_station(local, sdata, params);
4787 mutex_unlock(&sdata->local->sta_mtx);
4792 static int sta_del_link_station(struct ieee80211_sub_if_data *sdata,
4793 struct link_station_del_parameters *params)
4795 struct sta_info *sta;
4797 sta = sta_info_get_bss(sdata, params->mld_mac);
4801 if (!(sta->sta.valid_links & BIT(params->link_id)))
4804 /* must not create a STA without links */
4805 if (sta->sta.valid_links == BIT(params->link_id))
4808 ieee80211_sta_remove_link(sta, params->link_id);
4814 ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev,
4815 struct link_station_del_parameters *params)
4817 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4820 mutex_lock(&sdata->local->sta_mtx);
4821 ret = sta_del_link_station(sdata, params);
4822 mutex_unlock(&sdata->local->sta_mtx);
4827 const struct cfg80211_ops mac80211_config_ops = {
4828 .add_virtual_intf = ieee80211_add_iface,
4829 .del_virtual_intf = ieee80211_del_iface,
4830 .change_virtual_intf = ieee80211_change_iface,
4831 .start_p2p_device = ieee80211_start_p2p_device,
4832 .stop_p2p_device = ieee80211_stop_p2p_device,
4833 .add_key = ieee80211_add_key,
4834 .del_key = ieee80211_del_key,
4835 .get_key = ieee80211_get_key,
4836 .set_default_key = ieee80211_config_default_key,
4837 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
4838 .set_default_beacon_key = ieee80211_config_default_beacon_key,
4839 .start_ap = ieee80211_start_ap,
4840 .change_beacon = ieee80211_change_beacon,
4841 .stop_ap = ieee80211_stop_ap,
4842 .add_station = ieee80211_add_station,
4843 .del_station = ieee80211_del_station,
4844 .change_station = ieee80211_change_station,
4845 .get_station = ieee80211_get_station,
4846 .dump_station = ieee80211_dump_station,
4847 .dump_survey = ieee80211_dump_survey,
4848 #ifdef CONFIG_MAC80211_MESH
4849 .add_mpath = ieee80211_add_mpath,
4850 .del_mpath = ieee80211_del_mpath,
4851 .change_mpath = ieee80211_change_mpath,
4852 .get_mpath = ieee80211_get_mpath,
4853 .dump_mpath = ieee80211_dump_mpath,
4854 .get_mpp = ieee80211_get_mpp,
4855 .dump_mpp = ieee80211_dump_mpp,
4856 .update_mesh_config = ieee80211_update_mesh_config,
4857 .get_mesh_config = ieee80211_get_mesh_config,
4858 .join_mesh = ieee80211_join_mesh,
4859 .leave_mesh = ieee80211_leave_mesh,
4861 .join_ocb = ieee80211_join_ocb,
4862 .leave_ocb = ieee80211_leave_ocb,
4863 .change_bss = ieee80211_change_bss,
4864 .set_txq_params = ieee80211_set_txq_params,
4865 .set_monitor_channel = ieee80211_set_monitor_channel,
4866 .suspend = ieee80211_suspend,
4867 .resume = ieee80211_resume,
4868 .scan = ieee80211_scan,
4869 .abort_scan = ieee80211_abort_scan,
4870 .sched_scan_start = ieee80211_sched_scan_start,
4871 .sched_scan_stop = ieee80211_sched_scan_stop,
4872 .auth = ieee80211_auth,
4873 .assoc = ieee80211_assoc,
4874 .deauth = ieee80211_deauth,
4875 .disassoc = ieee80211_disassoc,
4876 .join_ibss = ieee80211_join_ibss,
4877 .leave_ibss = ieee80211_leave_ibss,
4878 .set_mcast_rate = ieee80211_set_mcast_rate,
4879 .set_wiphy_params = ieee80211_set_wiphy_params,
4880 .set_tx_power = ieee80211_set_tx_power,
4881 .get_tx_power = ieee80211_get_tx_power,
4882 .rfkill_poll = ieee80211_rfkill_poll,
4883 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
4884 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
4885 .set_power_mgmt = ieee80211_set_power_mgmt,
4886 .set_bitrate_mask = ieee80211_set_bitrate_mask,
4887 .remain_on_channel = ieee80211_remain_on_channel,
4888 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
4889 .mgmt_tx = ieee80211_mgmt_tx,
4890 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
4891 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
4892 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
4893 .update_mgmt_frame_registrations =
4894 ieee80211_update_mgmt_frame_registrations,
4895 .set_antenna = ieee80211_set_antenna,
4896 .get_antenna = ieee80211_get_antenna,
4897 .set_rekey_data = ieee80211_set_rekey_data,
4898 .tdls_oper = ieee80211_tdls_oper,
4899 .tdls_mgmt = ieee80211_tdls_mgmt,
4900 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4901 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
4902 .probe_client = ieee80211_probe_client,
4903 .set_noack_map = ieee80211_set_noack_map,
4905 .set_wakeup = ieee80211_set_wakeup,
4907 .get_channel = ieee80211_cfg_get_channel,
4908 .start_radar_detection = ieee80211_start_radar_detection,
4909 .end_cac = ieee80211_end_cac,
4910 .channel_switch = ieee80211_channel_switch,
4911 .set_qos_map = ieee80211_set_qos_map,
4912 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
4913 .add_tx_ts = ieee80211_add_tx_ts,
4914 .del_tx_ts = ieee80211_del_tx_ts,
4915 .start_nan = ieee80211_start_nan,
4916 .stop_nan = ieee80211_stop_nan,
4917 .nan_change_conf = ieee80211_nan_change_conf,
4918 .add_nan_func = ieee80211_add_nan_func,
4919 .del_nan_func = ieee80211_del_nan_func,
4920 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
4921 .tx_control_port = ieee80211_tx_control_port,
4922 .get_txq_stats = ieee80211_get_txq_stats,
4923 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
4924 .start_pmsr = ieee80211_start_pmsr,
4925 .abort_pmsr = ieee80211_abort_pmsr,
4926 .probe_mesh_link = ieee80211_probe_mesh_link,
4927 .set_tid_config = ieee80211_set_tid_config,
4928 .reset_tid_config = ieee80211_reset_tid_config,
4929 .set_sar_specs = ieee80211_set_sar_specs,
4930 .color_change = ieee80211_color_change,
4931 .set_radar_background = ieee80211_set_radar_background,
4932 .add_intf_link = ieee80211_add_intf_link,
4933 .del_intf_link = ieee80211_del_intf_link,
4934 .add_link_station = ieee80211_add_link_station,
4935 .mod_link_station = ieee80211_mod_link_station,
4936 .del_link_station = ieee80211_del_link_station,