2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2015 Intel Mobile Communications GmbH
6 * Copyright (C) 2015-2017 Intel Deutschland GmbH
7 * Copyright (C) 2018 Intel Corporation
9 * This file is GPLv2 as found in COPYING.
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/slab.h>
16 #include <net/net_namespace.h>
17 #include <linux/rcupdate.h>
18 #include <linux/if_ether.h>
19 #include <net/cfg80211.h>
20 #include "ieee80211_i.h"
21 #include "driver-ops.h"
26 static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
27 struct vif_params *params)
29 bool mu_mimo_groups = false;
30 bool mu_mimo_follow = false;
32 if (params->vht_mumimo_groups) {
35 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
37 memcpy(sdata->vif.bss_conf.mu_group.membership,
38 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
39 memcpy(sdata->vif.bss_conf.mu_group.position,
40 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
41 WLAN_USER_POSITION_LEN);
42 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
43 /* don't care about endianness - just check for 0 */
44 memcpy(&membership, params->vht_mumimo_groups,
46 mu_mimo_groups = membership != 0;
49 if (params->vht_mumimo_follow_addr) {
51 is_valid_ether_addr(params->vht_mumimo_follow_addr);
52 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
53 params->vht_mumimo_follow_addr);
56 sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
59 static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
60 struct vif_params *params)
62 struct ieee80211_local *local = sdata->local;
63 struct ieee80211_sub_if_data *monitor_sdata;
65 /* check flags first */
66 if (params->flags && ieee80211_sdata_running(sdata)) {
67 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
70 * Prohibit MONITOR_FLAG_COOK_FRAMES and
71 * MONITOR_FLAG_ACTIVE to be changed while the
73 * Else we would need to add a lot of cruft
74 * to update everything:
75 * cooked_mntrs, monitor and all fif_* counters
76 * reconfigure hardware
78 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
82 /* also validate MU-MIMO change */
83 monitor_sdata = rtnl_dereference(local->monitor_sdata);
86 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
89 /* apply all changes now - no failures allowed */
92 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
95 if (ieee80211_sdata_running(sdata)) {
96 ieee80211_adjust_monitor_flags(sdata, -1);
97 sdata->u.mntr.flags = params->flags;
98 ieee80211_adjust_monitor_flags(sdata, 1);
100 ieee80211_configure_filter(local);
103 * Because the interface is down, ieee80211_do_stop
104 * and ieee80211_do_open take care of "everything"
105 * mentioned in the comment above.
107 sdata->u.mntr.flags = params->flags;
114 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
116 unsigned char name_assign_type,
117 enum nl80211_iftype type,
118 struct vif_params *params)
120 struct ieee80211_local *local = wiphy_priv(wiphy);
121 struct wireless_dev *wdev;
122 struct ieee80211_sub_if_data *sdata;
125 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
129 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
131 if (type == NL80211_IFTYPE_MONITOR) {
132 err = ieee80211_set_mon_options(sdata, params);
134 ieee80211_if_remove(sdata);
142 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
144 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
149 static int ieee80211_change_iface(struct wiphy *wiphy,
150 struct net_device *dev,
151 enum nl80211_iftype type,
152 struct vif_params *params)
154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
157 ret = ieee80211_if_change_type(sdata, type);
161 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
162 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
163 ieee80211_check_fast_rx_iface(sdata);
164 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
165 sdata->u.mgd.use_4addr = params->use_4addr;
168 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
169 ret = ieee80211_set_mon_options(sdata, params);
177 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
178 struct wireless_dev *wdev)
180 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
183 mutex_lock(&sdata->local->chanctx_mtx);
184 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
185 mutex_unlock(&sdata->local->chanctx_mtx);
189 return ieee80211_do_open(wdev, true);
192 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
193 struct wireless_dev *wdev)
195 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
198 static int ieee80211_start_nan(struct wiphy *wiphy,
199 struct wireless_dev *wdev,
200 struct cfg80211_nan_conf *conf)
202 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
205 mutex_lock(&sdata->local->chanctx_mtx);
206 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
207 mutex_unlock(&sdata->local->chanctx_mtx);
211 ret = ieee80211_do_open(wdev, true);
215 ret = drv_start_nan(sdata->local, sdata, conf);
217 ieee80211_sdata_stop(sdata);
219 sdata->u.nan.conf = *conf;
224 static void ieee80211_stop_nan(struct wiphy *wiphy,
225 struct wireless_dev *wdev)
227 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
229 drv_stop_nan(sdata->local, sdata);
230 ieee80211_sdata_stop(sdata);
233 static int ieee80211_nan_change_conf(struct wiphy *wiphy,
234 struct wireless_dev *wdev,
235 struct cfg80211_nan_conf *conf,
238 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
239 struct cfg80211_nan_conf new_conf;
242 if (sdata->vif.type != NL80211_IFTYPE_NAN)
245 if (!ieee80211_sdata_running(sdata))
248 new_conf = sdata->u.nan.conf;
250 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
251 new_conf.master_pref = conf->master_pref;
253 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
254 new_conf.bands = conf->bands;
256 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
258 sdata->u.nan.conf = new_conf;
263 static int ieee80211_add_nan_func(struct wiphy *wiphy,
264 struct wireless_dev *wdev,
265 struct cfg80211_nan_func *nan_func)
267 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
270 if (sdata->vif.type != NL80211_IFTYPE_NAN)
273 if (!ieee80211_sdata_running(sdata))
276 spin_lock_bh(&sdata->u.nan.func_lock);
278 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
279 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
281 spin_unlock_bh(&sdata->u.nan.func_lock);
286 nan_func->instance_id = ret;
288 WARN_ON(nan_func->instance_id == 0);
290 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
292 spin_lock_bh(&sdata->u.nan.func_lock);
293 idr_remove(&sdata->u.nan.function_inst_ids,
294 nan_func->instance_id);
295 spin_unlock_bh(&sdata->u.nan.func_lock);
301 static struct cfg80211_nan_func *
302 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
305 struct cfg80211_nan_func *func;
308 lockdep_assert_held(&sdata->u.nan.func_lock);
310 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
311 if (func->cookie == cookie)
318 static void ieee80211_del_nan_func(struct wiphy *wiphy,
319 struct wireless_dev *wdev, u64 cookie)
321 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
322 struct cfg80211_nan_func *func;
325 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
326 !ieee80211_sdata_running(sdata))
329 spin_lock_bh(&sdata->u.nan.func_lock);
331 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
333 instance_id = func->instance_id;
335 spin_unlock_bh(&sdata->u.nan.func_lock);
338 drv_del_nan_func(sdata->local, sdata, instance_id);
341 static int ieee80211_set_noack_map(struct wiphy *wiphy,
342 struct net_device *dev,
345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
347 sdata->noack_map = noack_map;
349 ieee80211_check_fast_xmit_iface(sdata);
354 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
355 u8 key_idx, bool pairwise, const u8 *mac_addr,
356 struct key_params *params)
358 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
359 struct ieee80211_local *local = sdata->local;
360 struct sta_info *sta = NULL;
361 const struct ieee80211_cipher_scheme *cs = NULL;
362 struct ieee80211_key *key;
365 if (!ieee80211_sdata_running(sdata))
368 /* reject WEP and TKIP keys if WEP failed to initialize */
369 switch (params->cipher) {
370 case WLAN_CIPHER_SUITE_WEP40:
371 case WLAN_CIPHER_SUITE_TKIP:
372 case WLAN_CIPHER_SUITE_WEP104:
373 if (IS_ERR(local->wep_tx_tfm))
376 case WLAN_CIPHER_SUITE_CCMP:
377 case WLAN_CIPHER_SUITE_CCMP_256:
378 case WLAN_CIPHER_SUITE_AES_CMAC:
379 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
380 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
381 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
382 case WLAN_CIPHER_SUITE_GCMP:
383 case WLAN_CIPHER_SUITE_GCMP_256:
386 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
390 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
391 params->key, params->seq_len, params->seq,
397 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
399 mutex_lock(&local->sta_mtx);
402 sta = sta_info_get_bss(sdata, mac_addr);
404 * The ASSOC test makes sure the driver is ready to
405 * receive the key. When wpa_supplicant has roamed
406 * using FT, it attempts to set the key before
407 * association has completed, this rejects that attempt
408 * so it will set the key again after association.
410 * TODO: accept the key if we have a station entry and
411 * add it to the device after the station.
413 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
414 ieee80211_key_free_unused(key);
420 switch (sdata->vif.type) {
421 case NL80211_IFTYPE_STATION:
422 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
423 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
425 case NL80211_IFTYPE_AP:
426 case NL80211_IFTYPE_AP_VLAN:
427 /* Keys without a station are used for TX only */
428 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
429 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
431 case NL80211_IFTYPE_ADHOC:
434 case NL80211_IFTYPE_MESH_POINT:
435 #ifdef CONFIG_MAC80211_MESH
436 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
437 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
440 case NL80211_IFTYPE_WDS:
441 case NL80211_IFTYPE_MONITOR:
442 case NL80211_IFTYPE_P2P_DEVICE:
443 case NL80211_IFTYPE_NAN:
444 case NL80211_IFTYPE_UNSPECIFIED:
445 case NUM_NL80211_IFTYPES:
446 case NL80211_IFTYPE_P2P_CLIENT:
447 case NL80211_IFTYPE_P2P_GO:
448 case NL80211_IFTYPE_OCB:
449 /* shouldn't happen */
455 sta->cipher_scheme = cs;
457 err = ieee80211_key_link(key, sdata, sta);
460 mutex_unlock(&local->sta_mtx);
465 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
466 u8 key_idx, bool pairwise, const u8 *mac_addr)
468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
469 struct ieee80211_local *local = sdata->local;
470 struct sta_info *sta;
471 struct ieee80211_key *key = NULL;
474 mutex_lock(&local->sta_mtx);
475 mutex_lock(&local->key_mtx);
480 sta = sta_info_get_bss(sdata, mac_addr);
485 key = key_mtx_dereference(local, sta->ptk[key_idx]);
487 key = key_mtx_dereference(local, sta->gtk[key_idx]);
489 key = key_mtx_dereference(local, sdata->keys[key_idx]);
496 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
500 mutex_unlock(&local->key_mtx);
501 mutex_unlock(&local->sta_mtx);
506 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
507 u8 key_idx, bool pairwise, const u8 *mac_addr,
509 void (*callback)(void *cookie,
510 struct key_params *params))
512 struct ieee80211_sub_if_data *sdata;
513 struct sta_info *sta = NULL;
515 struct key_params params;
516 struct ieee80211_key *key = NULL;
521 struct ieee80211_key_seq kseq = {};
523 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
528 sta = sta_info_get_bss(sdata, mac_addr);
532 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
533 key = rcu_dereference(sta->ptk[key_idx]);
534 else if (!pairwise &&
535 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
536 key = rcu_dereference(sta->gtk[key_idx]);
538 key = rcu_dereference(sdata->keys[key_idx]);
543 memset(¶ms, 0, sizeof(params));
545 params.cipher = key->conf.cipher;
547 switch (key->conf.cipher) {
548 case WLAN_CIPHER_SUITE_TKIP:
549 pn64 = atomic64_read(&key->conf.tx_pn);
550 iv32 = TKIP_PN_TO_IV32(pn64);
551 iv16 = TKIP_PN_TO_IV16(pn64);
553 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
554 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
555 drv_get_key_seq(sdata->local, key, &kseq);
556 iv32 = kseq.tkip.iv32;
557 iv16 = kseq.tkip.iv16;
560 seq[0] = iv16 & 0xff;
561 seq[1] = (iv16 >> 8) & 0xff;
562 seq[2] = iv32 & 0xff;
563 seq[3] = (iv32 >> 8) & 0xff;
564 seq[4] = (iv32 >> 16) & 0xff;
565 seq[5] = (iv32 >> 24) & 0xff;
569 case WLAN_CIPHER_SUITE_CCMP:
570 case WLAN_CIPHER_SUITE_CCMP_256:
571 case WLAN_CIPHER_SUITE_AES_CMAC:
572 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
573 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
574 offsetof(typeof(kseq), aes_cmac));
576 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
577 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
578 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
579 offsetof(typeof(kseq), aes_gmac));
581 case WLAN_CIPHER_SUITE_GCMP:
582 case WLAN_CIPHER_SUITE_GCMP_256:
583 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
584 offsetof(typeof(kseq), gcmp));
586 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
587 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
588 drv_get_key_seq(sdata->local, key, &kseq);
589 memcpy(seq, kseq.ccmp.pn, 6);
591 pn64 = atomic64_read(&key->conf.tx_pn);
603 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
605 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
607 drv_get_key_seq(sdata->local, key, &kseq);
608 params.seq = kseq.hw.seq;
609 params.seq_len = kseq.hw.seq_len;
613 params.key = key->conf.key;
614 params.key_len = key->conf.keylen;
616 callback(cookie, ¶ms);
624 static int ieee80211_config_default_key(struct wiphy *wiphy,
625 struct net_device *dev,
626 u8 key_idx, bool uni,
629 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
631 ieee80211_set_default_key(sdata, key_idx, uni, multi);
636 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
637 struct net_device *dev,
640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
642 ieee80211_set_default_mgmt_key(sdata, key_idx);
647 void sta_set_rate_info_tx(struct sta_info *sta,
648 const struct ieee80211_tx_rate *rate,
649 struct rate_info *rinfo)
652 if (rate->flags & IEEE80211_TX_RC_MCS) {
653 rinfo->flags |= RATE_INFO_FLAGS_MCS;
654 rinfo->mcs = rate->idx;
655 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
656 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
657 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
658 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
660 struct ieee80211_supported_band *sband;
661 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
664 sband = ieee80211_get_sband(sta->sdata);
666 brate = sband->bitrates[rate->idx].bitrate;
667 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
670 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
671 rinfo->bw = RATE_INFO_BW_40;
672 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
673 rinfo->bw = RATE_INFO_BW_80;
674 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
675 rinfo->bw = RATE_INFO_BW_160;
677 rinfo->bw = RATE_INFO_BW_20;
678 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
679 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
682 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
683 int idx, u8 *mac, struct station_info *sinfo)
685 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
686 struct ieee80211_local *local = sdata->local;
687 struct sta_info *sta;
690 mutex_lock(&local->sta_mtx);
692 sta = sta_info_get_by_idx(sdata, idx);
695 memcpy(mac, sta->sta.addr, ETH_ALEN);
696 sta_set_sinfo(sta, sinfo, true);
699 mutex_unlock(&local->sta_mtx);
704 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
705 int idx, struct survey_info *survey)
707 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
709 return drv_get_survey(local, idx, survey);
712 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
713 const u8 *mac, struct station_info *sinfo)
715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
716 struct ieee80211_local *local = sdata->local;
717 struct sta_info *sta;
720 mutex_lock(&local->sta_mtx);
722 sta = sta_info_get_bss(sdata, mac);
725 sta_set_sinfo(sta, sinfo, true);
728 mutex_unlock(&local->sta_mtx);
733 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
734 struct cfg80211_chan_def *chandef)
736 struct ieee80211_local *local = wiphy_priv(wiphy);
737 struct ieee80211_sub_if_data *sdata;
740 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
743 mutex_lock(&local->mtx);
744 if (local->use_chanctx) {
745 sdata = rtnl_dereference(local->monitor_sdata);
747 ieee80211_vif_release_channel(sdata);
748 ret = ieee80211_vif_use_channel(sdata, chandef,
749 IEEE80211_CHANCTX_EXCLUSIVE);
751 } else if (local->open_count == local->monitors) {
752 local->_oper_chandef = *chandef;
753 ieee80211_hw_config(local, 0);
757 local->monitor_chandef = *chandef;
758 mutex_unlock(&local->mtx);
763 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
764 const u8 *resp, size_t resp_len,
765 const struct ieee80211_csa_settings *csa)
767 struct probe_resp *new, *old;
769 if (!resp || !resp_len)
772 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
774 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
779 memcpy(new->data, resp, resp_len);
782 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
783 csa->n_counter_offsets_presp *
784 sizeof(new->csa_counter_offsets[0]));
786 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
788 kfree_rcu(old, rcu_head);
793 static int ieee80211_set_ftm_responder_params(
794 struct ieee80211_sub_if_data *sdata,
795 const u8 *lci, size_t lci_len,
796 const u8 *civicloc, size_t civicloc_len)
798 struct ieee80211_ftm_responder_params *new, *old;
799 struct ieee80211_bss_conf *bss_conf;
803 if (!lci_len && !civicloc_len)
806 bss_conf = &sdata->vif.bss_conf;
807 old = bss_conf->ftmr_params;
808 len = lci_len + civicloc_len;
810 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
814 pos = (u8 *)(new + 1);
816 new->lci_len = lci_len;
818 memcpy(pos, lci, lci_len);
823 new->civicloc_len = civicloc_len;
825 memcpy(pos, civicloc, civicloc_len);
829 bss_conf->ftmr_params = new;
835 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
836 struct cfg80211_beacon_data *params,
837 const struct ieee80211_csa_settings *csa)
839 struct beacon_data *new, *old;
840 int new_head_len, new_tail_len;
842 u32 changed = BSS_CHANGED_BEACON;
844 old = sdata_dereference(sdata->u.ap.beacon, sdata);
847 /* Need to have a beacon head if we don't have one yet */
848 if (!params->head && !old)
851 /* new or old head? */
853 new_head_len = params->head_len;
855 new_head_len = old->head_len;
857 /* new or old tail? */
858 if (params->tail || !old)
859 /* params->tail_len will be zero for !params->tail */
860 new_tail_len = params->tail_len;
862 new_tail_len = old->tail_len;
864 size = sizeof(*new) + new_head_len + new_tail_len;
866 new = kzalloc(size, GFP_KERNEL);
870 /* start filling the new info now */
873 * pointers go into the block we allocated,
874 * memory is | beacon_data | head | tail |
876 new->head = ((u8 *) new) + sizeof(*new);
877 new->tail = new->head + new_head_len;
878 new->head_len = new_head_len;
879 new->tail_len = new_tail_len;
882 new->csa_current_counter = csa->count;
883 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
884 csa->n_counter_offsets_beacon *
885 sizeof(new->csa_counter_offsets[0]));
890 memcpy(new->head, params->head, new_head_len);
892 memcpy(new->head, old->head, new_head_len);
894 /* copy in optional tail */
896 memcpy(new->tail, params->tail, new_tail_len);
899 memcpy(new->tail, old->tail, new_tail_len);
901 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
902 params->probe_resp_len, csa);
906 changed |= BSS_CHANGED_AP_PROBE_RESP;
908 if (params->ftm_responder != -1) {
909 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
910 err = ieee80211_set_ftm_responder_params(sdata,
914 params->civicloc_len);
919 changed |= BSS_CHANGED_FTM_RESPONDER;
922 rcu_assign_pointer(sdata->u.ap.beacon, new);
925 kfree_rcu(old, rcu_head);
930 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
931 struct cfg80211_ap_settings *params)
933 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
934 struct ieee80211_local *local = sdata->local;
935 struct beacon_data *old;
936 struct ieee80211_sub_if_data *vlan;
937 u32 changed = BSS_CHANGED_BEACON_INT |
938 BSS_CHANGED_BEACON_ENABLED |
945 old = sdata_dereference(sdata->u.ap.beacon, sdata);
949 switch (params->smps_mode) {
950 case NL80211_SMPS_OFF:
951 sdata->smps_mode = IEEE80211_SMPS_OFF;
953 case NL80211_SMPS_STATIC:
954 sdata->smps_mode = IEEE80211_SMPS_STATIC;
956 case NL80211_SMPS_DYNAMIC:
957 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
962 sdata->u.ap.req_smps = sdata->smps_mode;
964 sdata->needed_rx_chains = sdata->local->rx_chains;
966 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
969 sdata->vif.bss_conf.he_support = true;
971 mutex_lock(&local->mtx);
972 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
973 IEEE80211_CHANCTX_SHARED);
975 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
976 mutex_unlock(&local->mtx);
981 * Apply control port protocol, this allows us to
982 * not encrypt dynamic WEP control frames.
984 sdata->control_port_protocol = params->crypto.control_port_ethertype;
985 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
986 sdata->control_port_over_nl80211 =
987 params->crypto.control_port_over_nl80211;
988 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
992 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
993 vlan->control_port_protocol =
994 params->crypto.control_port_ethertype;
995 vlan->control_port_no_encrypt =
996 params->crypto.control_port_no_encrypt;
997 vlan->control_port_over_nl80211 =
998 params->crypto.control_port_over_nl80211;
999 vlan->encrypt_headroom =
1000 ieee80211_cs_headroom(sdata->local,
1005 sdata->vif.bss_conf.dtim_period = params->dtim_period;
1006 sdata->vif.bss_conf.enable_beacon = true;
1007 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
1009 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1010 if (params->ssid_len)
1011 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1013 sdata->vif.bss_conf.hidden_ssid =
1014 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1016 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1017 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1018 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1019 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1020 if (params->p2p_opp_ps)
1021 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1022 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1024 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL);
1026 ieee80211_vif_release_channel(sdata);
1031 err = drv_start_ap(sdata->local, sdata);
1033 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1036 kfree_rcu(old, rcu_head);
1037 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1038 ieee80211_vif_release_channel(sdata);
1042 ieee80211_recalc_dtim(local, sdata);
1043 ieee80211_bss_info_change_notify(sdata, changed);
1045 netif_carrier_on(dev);
1046 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1047 netif_carrier_on(vlan->dev);
1052 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1053 struct cfg80211_beacon_data *params)
1055 struct ieee80211_sub_if_data *sdata;
1056 struct beacon_data *old;
1059 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1060 sdata_assert_lock(sdata);
1062 /* don't allow changing the beacon while CSA is in place - offset
1063 * of channel switch counter may change
1065 if (sdata->vif.csa_active)
1068 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1072 err = ieee80211_assign_beacon(sdata, params, NULL);
1075 ieee80211_bss_info_change_notify(sdata, err);
1079 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
1081 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1082 struct ieee80211_sub_if_data *vlan;
1083 struct ieee80211_local *local = sdata->local;
1084 struct beacon_data *old_beacon;
1085 struct probe_resp *old_probe_resp;
1086 struct cfg80211_chan_def chandef;
1088 sdata_assert_lock(sdata);
1090 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
1093 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
1095 /* abort any running channel switch */
1096 mutex_lock(&local->mtx);
1097 sdata->vif.csa_active = false;
1098 if (sdata->csa_block_tx) {
1099 ieee80211_wake_vif_queues(local, sdata,
1100 IEEE80211_QUEUE_STOP_REASON_CSA);
1101 sdata->csa_block_tx = false;
1104 mutex_unlock(&local->mtx);
1106 kfree(sdata->u.ap.next_beacon);
1107 sdata->u.ap.next_beacon = NULL;
1109 /* turn off carrier for this interface and dependent VLANs */
1110 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1111 netif_carrier_off(vlan->dev);
1112 netif_carrier_off(dev);
1114 /* remove beacon and probe response */
1115 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1116 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1117 kfree_rcu(old_beacon, rcu_head);
1119 kfree_rcu(old_probe_resp, rcu_head);
1120 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
1122 kfree(sdata->vif.bss_conf.ftmr_params);
1123 sdata->vif.bss_conf.ftmr_params = NULL;
1125 __sta_info_flush(sdata, true);
1126 ieee80211_free_keys(sdata, true);
1128 sdata->vif.bss_conf.enable_beacon = false;
1129 sdata->vif.bss_conf.ssid_len = 0;
1130 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1131 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1133 if (sdata->wdev.cac_started) {
1134 chandef = sdata->vif.bss_conf.chandef;
1135 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1136 cfg80211_cac_event(sdata->dev, &chandef,
1137 NL80211_RADAR_CAC_ABORTED,
1141 drv_stop_ap(sdata->local, sdata);
1143 /* free all potentially still buffered bcast frames */
1144 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1145 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
1147 mutex_lock(&local->mtx);
1148 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
1149 ieee80211_vif_release_channel(sdata);
1150 mutex_unlock(&local->mtx);
1155 static int sta_apply_auth_flags(struct ieee80211_local *local,
1156 struct sta_info *sta,
1161 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1162 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1163 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1164 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1169 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1170 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1171 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1173 * When peer becomes associated, init rate control as
1174 * well. Some drivers require rate control initialized
1175 * before drv_sta_state() is called.
1177 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
1178 rate_control_rate_init(sta);
1180 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1185 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1186 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1187 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1188 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1189 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1196 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1197 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1198 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1199 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1204 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1205 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1206 test_sta_flag(sta, WLAN_STA_AUTH)) {
1207 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1215 static void sta_apply_mesh_params(struct ieee80211_local *local,
1216 struct sta_info *sta,
1217 struct station_parameters *params)
1219 #ifdef CONFIG_MAC80211_MESH
1220 struct ieee80211_sub_if_data *sdata = sta->sdata;
1223 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1224 switch (params->plink_state) {
1225 case NL80211_PLINK_ESTAB:
1226 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1227 changed = mesh_plink_inc_estab_count(sdata);
1228 sta->mesh->plink_state = params->plink_state;
1229 sta->mesh->aid = params->peer_aid;
1231 ieee80211_mps_sta_status_update(sta);
1232 changed |= ieee80211_mps_set_sta_local_pm(sta,
1233 sdata->u.mesh.mshcfg.power_mode);
1235 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1236 /* init at low value */
1237 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1240 case NL80211_PLINK_LISTEN:
1241 case NL80211_PLINK_BLOCKED:
1242 case NL80211_PLINK_OPN_SNT:
1243 case NL80211_PLINK_OPN_RCVD:
1244 case NL80211_PLINK_CNF_RCVD:
1245 case NL80211_PLINK_HOLDING:
1246 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1247 changed = mesh_plink_dec_estab_count(sdata);
1248 sta->mesh->plink_state = params->plink_state;
1250 ieee80211_mps_sta_status_update(sta);
1251 changed |= ieee80211_mps_set_sta_local_pm(sta,
1252 NL80211_MESH_POWER_UNKNOWN);
1260 switch (params->plink_action) {
1261 case NL80211_PLINK_ACTION_NO_ACTION:
1264 case NL80211_PLINK_ACTION_OPEN:
1265 changed |= mesh_plink_open(sta);
1267 case NL80211_PLINK_ACTION_BLOCK:
1268 changed |= mesh_plink_block(sta);
1272 if (params->local_pm)
1273 changed |= ieee80211_mps_set_sta_local_pm(sta,
1276 ieee80211_mbss_info_change_notify(sdata, changed);
1280 static int sta_apply_parameters(struct ieee80211_local *local,
1281 struct sta_info *sta,
1282 struct station_parameters *params)
1285 struct ieee80211_supported_band *sband;
1286 struct ieee80211_sub_if_data *sdata = sta->sdata;
1289 sband = ieee80211_get_sband(sdata);
1293 mask = params->sta_flags_mask;
1294 set = params->sta_flags_set;
1296 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1298 * In mesh mode, ASSOCIATED isn't part of the nl80211
1299 * API but must follow AUTHENTICATED for driver state.
1301 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1302 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1303 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1304 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1305 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1307 * TDLS -- everything follows authorized, but
1308 * only becoming authorized is possible, not
1311 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1312 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1313 BIT(NL80211_STA_FLAG_ASSOCIATED);
1314 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1315 BIT(NL80211_STA_FLAG_ASSOCIATED);
1319 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1320 local->hw.queues >= IEEE80211_NUM_ACS)
1321 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1323 /* auth flags will be set later for TDLS,
1324 * and for unassociated stations that move to assocaited */
1325 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1326 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1327 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1328 ret = sta_apply_auth_flags(local, sta, mask, set);
1333 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1334 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1335 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1337 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1340 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1341 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1342 if (set & BIT(NL80211_STA_FLAG_MFP))
1343 set_sta_flag(sta, WLAN_STA_MFP);
1345 clear_sta_flag(sta, WLAN_STA_MFP);
1348 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1349 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1350 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1352 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1355 /* mark TDLS channel switch support, if the AP allows it */
1356 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1357 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1358 params->ext_capab_len >= 4 &&
1359 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1360 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1362 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1363 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1364 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1365 params->ext_capab_len >= 8 &&
1366 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1367 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1369 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1370 sta->sta.uapsd_queues = params->uapsd_queues;
1371 sta->sta.max_sp = params->max_sp;
1374 /* The sender might not have sent the last bit, consider it to be 0 */
1375 if (params->ext_capab_len >= 8) {
1376 u8 val = (params->ext_capab[7] &
1377 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1379 /* we did get all the bits, take the MSB as well */
1380 if (params->ext_capab_len >= 9) {
1381 u8 val_msb = params->ext_capab[8] &
1382 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1389 sta->sta.max_amsdu_subframes = 32;
1392 sta->sta.max_amsdu_subframes = 16;
1395 sta->sta.max_amsdu_subframes = 8;
1398 sta->sta.max_amsdu_subframes = 0;
1403 * cfg80211 validates this (1-2007) and allows setting the AID
1404 * only when creating a new station entry
1407 sta->sta.aid = params->aid;
1410 * Some of the following updates would be racy if called on an
1411 * existing station, via ieee80211_change_station(). However,
1412 * all such changes are rejected by cfg80211 except for updates
1413 * changing the supported rates on an existing but not yet used
1417 if (params->listen_interval >= 0)
1418 sta->listen_interval = params->listen_interval;
1420 if (params->supported_rates) {
1421 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1422 sband, params->supported_rates,
1423 params->supported_rates_len,
1424 &sta->sta.supp_rates[sband->band]);
1427 if (params->ht_capa)
1428 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1429 params->ht_capa, sta);
1431 /* VHT can override some HT caps such as the A-MSDU max length */
1432 if (params->vht_capa)
1433 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1434 params->vht_capa, sta);
1436 if (params->he_capa)
1437 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1438 (void *)params->he_capa,
1439 params->he_capa_len, sta);
1441 if (params->opmode_notif_used) {
1442 /* returned value is only needed for rc update, but the
1443 * rc isn't initialized here yet, so ignore it
1445 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1449 if (params->support_p2p_ps >= 0)
1450 sta->sta.support_p2p_ps = params->support_p2p_ps;
1452 if (ieee80211_vif_is_mesh(&sdata->vif))
1453 sta_apply_mesh_params(local, sta, params);
1455 if (params->airtime_weight)
1456 sta->airtime_weight = params->airtime_weight;
1458 /* set the STA state after all sta info from usermode has been set */
1459 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1460 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1461 ret = sta_apply_auth_flags(local, sta, mask, set);
1469 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1471 struct station_parameters *params)
1473 struct ieee80211_local *local = wiphy_priv(wiphy);
1474 struct sta_info *sta;
1475 struct ieee80211_sub_if_data *sdata;
1480 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1482 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1483 sdata->vif.type != NL80211_IFTYPE_AP)
1486 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1488 if (ether_addr_equal(mac, sdata->vif.addr))
1491 if (is_multicast_ether_addr(mac))
1494 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1498 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1499 sta->sta.tdls = true;
1501 if (sta->sta.tdls && sdata->vif.type == NL80211_IFTYPE_STATION &&
1502 !sdata->u.mgd.associated)
1505 err = sta_apply_parameters(local, sta, params);
1507 sta_info_free(local, sta);
1512 * for TDLS and for unassociated station, rate control should be
1513 * initialized only when rates are known and station is marked
1514 * authorized/associated
1516 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1517 test_sta_flag(sta, WLAN_STA_ASSOC))
1518 rate_control_rate_init(sta);
1520 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1521 sdata->vif.type == NL80211_IFTYPE_AP;
1523 err = sta_info_insert_rcu(sta);
1530 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1537 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1538 struct station_del_parameters *params)
1540 struct ieee80211_sub_if_data *sdata;
1542 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1545 return sta_info_destroy_addr_bss(sdata, params->mac);
1547 sta_info_flush(sdata);
1551 static int ieee80211_change_station(struct wiphy *wiphy,
1552 struct net_device *dev, const u8 *mac,
1553 struct station_parameters *params)
1555 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1556 struct ieee80211_local *local = wiphy_priv(wiphy);
1557 struct sta_info *sta;
1558 struct ieee80211_sub_if_data *vlansdata;
1559 enum cfg80211_station_type statype;
1562 mutex_lock(&local->sta_mtx);
1564 sta = sta_info_get_bss(sdata, mac);
1570 switch (sdata->vif.type) {
1571 case NL80211_IFTYPE_MESH_POINT:
1572 if (sdata->u.mesh.user_mpm)
1573 statype = CFG80211_STA_MESH_PEER_USER;
1575 statype = CFG80211_STA_MESH_PEER_KERNEL;
1577 case NL80211_IFTYPE_ADHOC:
1578 statype = CFG80211_STA_IBSS;
1580 case NL80211_IFTYPE_STATION:
1581 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1582 statype = CFG80211_STA_AP_STA;
1585 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1586 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1588 statype = CFG80211_STA_TDLS_PEER_SETUP;
1590 case NL80211_IFTYPE_AP:
1591 case NL80211_IFTYPE_AP_VLAN:
1592 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1593 statype = CFG80211_STA_AP_CLIENT;
1595 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1602 err = cfg80211_check_station_change(wiphy, params, statype);
1606 if (params->vlan && params->vlan != sta->sdata->dev) {
1607 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1609 if (params->vlan->ieee80211_ptr->use_4addr) {
1610 if (vlansdata->u.vlan.sta) {
1615 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1616 __ieee80211_check_fast_rx_iface(vlansdata);
1619 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1620 sta->sdata->u.vlan.sta)
1621 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1623 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1624 ieee80211_vif_dec_num_mcast(sta->sdata);
1626 sta->sdata = vlansdata;
1627 ieee80211_check_fast_xmit(sta);
1629 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1630 ieee80211_vif_inc_num_mcast(sta->sdata);
1632 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
1635 err = sta_apply_parameters(local, sta, params);
1639 mutex_unlock(&local->sta_mtx);
1641 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1642 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1643 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1644 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1645 sta_info_tx_streams(sta) != 1) {
1647 "%pM just authorized and MIMO capable - update SMPS\n",
1649 ieee80211_send_smps_action(sta->sdata,
1650 sta->sdata->bss->req_smps,
1652 sta->sdata->vif.bss_conf.bssid);
1655 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1656 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1657 ieee80211_recalc_ps(local);
1658 ieee80211_recalc_ps_vif(sdata);
1663 mutex_unlock(&local->sta_mtx);
1667 #ifdef CONFIG_MAC80211_MESH
1668 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1669 const u8 *dst, const u8 *next_hop)
1671 struct ieee80211_sub_if_data *sdata;
1672 struct mesh_path *mpath;
1673 struct sta_info *sta;
1675 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1678 sta = sta_info_get(sdata, next_hop);
1684 mpath = mesh_path_add(sdata, dst);
1685 if (IS_ERR(mpath)) {
1687 return PTR_ERR(mpath);
1690 mesh_path_fix_nexthop(mpath, sta);
1696 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1699 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1702 return mesh_path_del(sdata, dst);
1704 mesh_path_flush_by_iface(sdata);
1708 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1709 const u8 *dst, const u8 *next_hop)
1711 struct ieee80211_sub_if_data *sdata;
1712 struct mesh_path *mpath;
1713 struct sta_info *sta;
1715 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1719 sta = sta_info_get(sdata, next_hop);
1725 mpath = mesh_path_lookup(sdata, dst);
1731 mesh_path_fix_nexthop(mpath, sta);
1737 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1738 struct mpath_info *pinfo)
1740 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1743 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1745 eth_zero_addr(next_hop);
1747 memset(pinfo, 0, sizeof(*pinfo));
1749 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
1751 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1754 MPATH_INFO_EXPTIME |
1755 MPATH_INFO_DISCOVERY_TIMEOUT |
1756 MPATH_INFO_DISCOVERY_RETRIES |
1758 MPATH_INFO_HOP_COUNT |
1759 MPATH_INFO_PATH_CHANGE;
1761 pinfo->frame_qlen = mpath->frame_queue.qlen;
1762 pinfo->sn = mpath->sn;
1763 pinfo->metric = mpath->metric;
1764 if (time_before(jiffies, mpath->exp_time))
1765 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1766 pinfo->discovery_timeout =
1767 jiffies_to_msecs(mpath->discovery_timeout);
1768 pinfo->discovery_retries = mpath->discovery_retries;
1769 if (mpath->flags & MESH_PATH_ACTIVE)
1770 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1771 if (mpath->flags & MESH_PATH_RESOLVING)
1772 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1773 if (mpath->flags & MESH_PATH_SN_VALID)
1774 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1775 if (mpath->flags & MESH_PATH_FIXED)
1776 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1777 if (mpath->flags & MESH_PATH_RESOLVED)
1778 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1779 pinfo->hop_count = mpath->hop_count;
1780 pinfo->path_change_count = mpath->path_change_count;
1783 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1784 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1787 struct ieee80211_sub_if_data *sdata;
1788 struct mesh_path *mpath;
1790 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1793 mpath = mesh_path_lookup(sdata, dst);
1798 memcpy(dst, mpath->dst, ETH_ALEN);
1799 mpath_set_pinfo(mpath, next_hop, pinfo);
1804 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1805 int idx, u8 *dst, u8 *next_hop,
1806 struct mpath_info *pinfo)
1808 struct ieee80211_sub_if_data *sdata;
1809 struct mesh_path *mpath;
1811 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1814 mpath = mesh_path_lookup_by_idx(sdata, idx);
1819 memcpy(dst, mpath->dst, ETH_ALEN);
1820 mpath_set_pinfo(mpath, next_hop, pinfo);
1825 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1826 struct mpath_info *pinfo)
1828 memset(pinfo, 0, sizeof(*pinfo));
1829 memcpy(mpp, mpath->mpp, ETH_ALEN);
1831 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
1834 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1835 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1838 struct ieee80211_sub_if_data *sdata;
1839 struct mesh_path *mpath;
1841 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1844 mpath = mpp_path_lookup(sdata, dst);
1849 memcpy(dst, mpath->dst, ETH_ALEN);
1850 mpp_set_pinfo(mpath, mpp, pinfo);
1855 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1856 int idx, u8 *dst, u8 *mpp,
1857 struct mpath_info *pinfo)
1859 struct ieee80211_sub_if_data *sdata;
1860 struct mesh_path *mpath;
1862 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1865 mpath = mpp_path_lookup_by_idx(sdata, idx);
1870 memcpy(dst, mpath->dst, ETH_ALEN);
1871 mpp_set_pinfo(mpath, mpp, pinfo);
1876 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1877 struct net_device *dev,
1878 struct mesh_config *conf)
1880 struct ieee80211_sub_if_data *sdata;
1881 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1883 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1887 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1889 return (mask >> (parm-1)) & 0x1;
1892 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1893 const struct mesh_setup *setup)
1897 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1898 struct ieee80211_sub_if_data, u.mesh);
1900 /* allocate information elements */
1904 if (setup->ie_len) {
1905 new_ie = kmemdup(setup->ie, setup->ie_len,
1910 ifmsh->ie_len = setup->ie_len;
1914 /* now copy the rest of the setup parameters */
1915 ifmsh->mesh_id_len = setup->mesh_id_len;
1916 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1917 ifmsh->mesh_sp_id = setup->sync_method;
1918 ifmsh->mesh_pp_id = setup->path_sel_proto;
1919 ifmsh->mesh_pm_id = setup->path_metric;
1920 ifmsh->user_mpm = setup->user_mpm;
1921 ifmsh->mesh_auth_id = setup->auth_id;
1922 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1923 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
1924 if (setup->is_authenticated)
1925 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1926 if (setup->is_secure)
1927 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1929 /* mcast rate setting in Mesh Node */
1930 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1931 sizeof(setup->mcast_rate));
1932 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1934 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1935 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1940 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1941 struct net_device *dev, u32 mask,
1942 const struct mesh_config *nconf)
1944 struct mesh_config *conf;
1945 struct ieee80211_sub_if_data *sdata;
1946 struct ieee80211_if_mesh *ifmsh;
1948 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1949 ifmsh = &sdata->u.mesh;
1951 /* Set the config options which we are interested in setting */
1952 conf = &(sdata->u.mesh.mshcfg);
1953 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1954 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1955 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1956 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1957 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1958 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1959 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1960 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1961 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1962 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1963 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1964 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1965 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1966 conf->element_ttl = nconf->element_ttl;
1967 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1968 if (ifmsh->user_mpm)
1970 conf->auto_open_plinks = nconf->auto_open_plinks;
1972 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1973 conf->dot11MeshNbrOffsetMaxNeighbor =
1974 nconf->dot11MeshNbrOffsetMaxNeighbor;
1975 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1976 conf->dot11MeshHWMPmaxPREQretries =
1977 nconf->dot11MeshHWMPmaxPREQretries;
1978 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1979 conf->path_refresh_time = nconf->path_refresh_time;
1980 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1981 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1982 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1983 conf->dot11MeshHWMPactivePathTimeout =
1984 nconf->dot11MeshHWMPactivePathTimeout;
1985 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1986 conf->dot11MeshHWMPpreqMinInterval =
1987 nconf->dot11MeshHWMPpreqMinInterval;
1988 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1989 conf->dot11MeshHWMPperrMinInterval =
1990 nconf->dot11MeshHWMPperrMinInterval;
1991 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1993 conf->dot11MeshHWMPnetDiameterTraversalTime =
1994 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1996 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1997 ieee80211_mesh_root_setup(ifmsh);
1999 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
2000 /* our current gate announcement implementation rides on root
2001 * announcements, so require this ifmsh to also be a root node
2003 if (nconf->dot11MeshGateAnnouncementProtocol &&
2004 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2005 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
2006 ieee80211_mesh_root_setup(ifmsh);
2008 conf->dot11MeshGateAnnouncementProtocol =
2009 nconf->dot11MeshGateAnnouncementProtocol;
2011 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
2012 conf->dot11MeshHWMPRannInterval =
2013 nconf->dot11MeshHWMPRannInterval;
2014 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2015 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
2016 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2017 /* our RSSI threshold implementation is supported only for
2018 * devices that report signal in dBm.
2020 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
2022 conf->rssi_threshold = nconf->rssi_threshold;
2024 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2025 conf->ht_opmode = nconf->ht_opmode;
2026 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2027 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2029 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2030 conf->dot11MeshHWMPactivePathToRootTimeout =
2031 nconf->dot11MeshHWMPactivePathToRootTimeout;
2032 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2033 conf->dot11MeshHWMProotInterval =
2034 nconf->dot11MeshHWMProotInterval;
2035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2036 conf->dot11MeshHWMPconfirmationInterval =
2037 nconf->dot11MeshHWMPconfirmationInterval;
2038 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2039 conf->power_mode = nconf->power_mode;
2040 ieee80211_mps_local_status_update(sdata);
2042 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
2043 conf->dot11MeshAwakeWindowDuration =
2044 nconf->dot11MeshAwakeWindowDuration;
2045 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2046 conf->plink_timeout = nconf->plink_timeout;
2047 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2048 conf->dot11MeshConnectedToMeshGate =
2049 nconf->dot11MeshConnectedToMeshGate;
2050 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
2054 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2055 const struct mesh_config *conf,
2056 const struct mesh_setup *setup)
2058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2059 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2062 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2063 err = copy_mesh_setup(ifmsh, setup);
2067 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2069 /* can mesh use other SMPS modes? */
2070 sdata->smps_mode = IEEE80211_SMPS_OFF;
2071 sdata->needed_rx_chains = sdata->local->rx_chains;
2073 mutex_lock(&sdata->local->mtx);
2074 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
2075 IEEE80211_CHANCTX_SHARED);
2076 mutex_unlock(&sdata->local->mtx);
2080 return ieee80211_start_mesh(sdata);
2083 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2085 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2087 ieee80211_stop_mesh(sdata);
2088 mutex_lock(&sdata->local->mtx);
2089 ieee80211_vif_release_channel(sdata);
2090 mutex_unlock(&sdata->local->mtx);
2096 static int ieee80211_change_bss(struct wiphy *wiphy,
2097 struct net_device *dev,
2098 struct bss_parameters *params)
2100 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2101 struct ieee80211_supported_band *sband;
2104 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
2107 sband = ieee80211_get_sband(sdata);
2111 if (params->use_cts_prot >= 0) {
2112 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
2113 changed |= BSS_CHANGED_ERP_CTS_PROT;
2115 if (params->use_short_preamble >= 0) {
2116 sdata->vif.bss_conf.use_short_preamble =
2117 params->use_short_preamble;
2118 changed |= BSS_CHANGED_ERP_PREAMBLE;
2121 if (!sdata->vif.bss_conf.use_short_slot &&
2122 sband->band == NL80211_BAND_5GHZ) {
2123 sdata->vif.bss_conf.use_short_slot = true;
2124 changed |= BSS_CHANGED_ERP_SLOT;
2127 if (params->use_short_slot_time >= 0) {
2128 sdata->vif.bss_conf.use_short_slot =
2129 params->use_short_slot_time;
2130 changed |= BSS_CHANGED_ERP_SLOT;
2133 if (params->basic_rates) {
2134 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2135 wiphy->bands[sband->band],
2136 params->basic_rates,
2137 params->basic_rates_len,
2138 &sdata->vif.bss_conf.basic_rates);
2139 changed |= BSS_CHANGED_BASIC_RATES;
2140 ieee80211_check_rate_mask(sdata);
2143 if (params->ap_isolate >= 0) {
2144 if (params->ap_isolate)
2145 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2147 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2148 ieee80211_check_fast_rx_iface(sdata);
2151 if (params->ht_opmode >= 0) {
2152 sdata->vif.bss_conf.ht_operation_mode =
2153 (u16) params->ht_opmode;
2154 changed |= BSS_CHANGED_HT;
2157 if (params->p2p_ctwindow >= 0) {
2158 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2159 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2160 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2161 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2162 changed |= BSS_CHANGED_P2P_PS;
2165 if (params->p2p_opp_ps > 0) {
2166 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2167 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2168 changed |= BSS_CHANGED_P2P_PS;
2169 } else if (params->p2p_opp_ps == 0) {
2170 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2171 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
2172 changed |= BSS_CHANGED_P2P_PS;
2175 ieee80211_bss_info_change_notify(sdata, changed);
2180 static int ieee80211_set_txq_params(struct wiphy *wiphy,
2181 struct net_device *dev,
2182 struct ieee80211_txq_params *params)
2184 struct ieee80211_local *local = wiphy_priv(wiphy);
2185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2186 struct ieee80211_tx_queue_params p;
2188 if (!local->ops->conf_tx)
2191 if (local->hw.queues < IEEE80211_NUM_ACS)
2194 memset(&p, 0, sizeof(p));
2195 p.aifs = params->aifs;
2196 p.cw_max = params->cwmax;
2197 p.cw_min = params->cwmin;
2198 p.txop = params->txop;
2201 * Setting tx queue params disables u-apsd because it's only
2202 * called in master mode.
2206 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2208 sdata->tx_conf[params->ac] = p;
2209 if (drv_conf_tx(local, sdata, params->ac, &p)) {
2210 wiphy_debug(local->hw.wiphy,
2211 "failed to set TX queue parameters for AC %d\n",
2216 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2222 static int ieee80211_suspend(struct wiphy *wiphy,
2223 struct cfg80211_wowlan *wowlan)
2225 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
2228 static int ieee80211_resume(struct wiphy *wiphy)
2230 return __ieee80211_resume(wiphy_priv(wiphy));
2233 #define ieee80211_suspend NULL
2234 #define ieee80211_resume NULL
2237 static int ieee80211_scan(struct wiphy *wiphy,
2238 struct cfg80211_scan_request *req)
2240 struct ieee80211_sub_if_data *sdata;
2242 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2244 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2245 case NL80211_IFTYPE_STATION:
2246 case NL80211_IFTYPE_ADHOC:
2247 case NL80211_IFTYPE_MESH_POINT:
2248 case NL80211_IFTYPE_P2P_CLIENT:
2249 case NL80211_IFTYPE_P2P_DEVICE:
2251 case NL80211_IFTYPE_P2P_GO:
2252 if (sdata->local->ops->hw_scan)
2255 * FIXME: implement NoA while scanning in software,
2256 * for now fall through to allow scanning only when
2257 * beaconing hasn't been configured yet
2260 case NL80211_IFTYPE_AP:
2262 * If the scan has been forced (and the driver supports
2263 * forcing), don't care about being beaconing already.
2264 * This will create problems to the attached stations (e.g. all
2265 * the frames sent while scanning on other channel will be
2268 if (sdata->u.ap.beacon &&
2269 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2270 !(req->flags & NL80211_SCAN_FLAG_AP)))
2273 case NL80211_IFTYPE_NAN:
2278 return ieee80211_request_scan(sdata, req);
2281 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2283 ieee80211_scan_cancel(wiphy_priv(wiphy));
2287 ieee80211_sched_scan_start(struct wiphy *wiphy,
2288 struct net_device *dev,
2289 struct cfg80211_sched_scan_request *req)
2291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2293 if (!sdata->local->ops->sched_scan_start)
2296 return ieee80211_request_sched_scan_start(sdata, req);
2300 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2303 struct ieee80211_local *local = wiphy_priv(wiphy);
2305 if (!local->ops->sched_scan_stop)
2308 return ieee80211_request_sched_scan_stop(local);
2311 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2312 struct cfg80211_auth_request *req)
2314 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2317 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2318 struct cfg80211_assoc_request *req)
2320 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2323 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2324 struct cfg80211_deauth_request *req)
2326 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2329 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2330 struct cfg80211_disassoc_request *req)
2332 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2335 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2336 struct cfg80211_ibss_params *params)
2338 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2341 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2343 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2346 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2347 struct ocb_setup *setup)
2349 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2352 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2354 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2357 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2358 int rate[NUM_NL80211_BANDS])
2360 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2362 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2363 sizeof(int) * NUM_NL80211_BANDS);
2365 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2370 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2372 struct ieee80211_local *local = wiphy_priv(wiphy);
2375 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2376 ieee80211_check_fast_xmit_all(local);
2378 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2381 ieee80211_check_fast_xmit_all(local);
2386 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2387 (changed & WIPHY_PARAM_DYN_ACK)) {
2390 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2391 wiphy->coverage_class : -1;
2392 err = drv_set_coverage_class(local, coverage_class);
2398 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2399 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2405 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2406 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2408 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2410 if (changed & WIPHY_PARAM_RETRY_LONG) {
2411 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2413 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2416 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2417 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2419 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2420 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2421 WIPHY_PARAM_TXQ_QUANTUM))
2422 ieee80211_txq_set_params(local);
2427 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2428 struct wireless_dev *wdev,
2429 enum nl80211_tx_power_setting type, int mbm)
2431 struct ieee80211_local *local = wiphy_priv(wiphy);
2432 struct ieee80211_sub_if_data *sdata;
2433 enum nl80211_tx_power_setting txp_type = type;
2434 bool update_txp_type = false;
2435 bool has_monitor = false;
2438 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2440 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2441 sdata = rtnl_dereference(local->monitor_sdata);
2447 case NL80211_TX_POWER_AUTOMATIC:
2448 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2449 txp_type = NL80211_TX_POWER_LIMITED;
2451 case NL80211_TX_POWER_LIMITED:
2452 case NL80211_TX_POWER_FIXED:
2453 if (mbm < 0 || (mbm % 100))
2455 sdata->user_power_level = MBM_TO_DBM(mbm);
2459 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2460 update_txp_type = true;
2461 sdata->vif.bss_conf.txpower_type = txp_type;
2464 ieee80211_recalc_txpower(sdata, update_txp_type);
2470 case NL80211_TX_POWER_AUTOMATIC:
2471 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2472 txp_type = NL80211_TX_POWER_LIMITED;
2474 case NL80211_TX_POWER_LIMITED:
2475 case NL80211_TX_POWER_FIXED:
2476 if (mbm < 0 || (mbm % 100))
2478 local->user_power_level = MBM_TO_DBM(mbm);
2482 mutex_lock(&local->iflist_mtx);
2483 list_for_each_entry(sdata, &local->interfaces, list) {
2484 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2488 sdata->user_power_level = local->user_power_level;
2489 if (txp_type != sdata->vif.bss_conf.txpower_type)
2490 update_txp_type = true;
2491 sdata->vif.bss_conf.txpower_type = txp_type;
2493 list_for_each_entry(sdata, &local->interfaces, list) {
2494 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2496 ieee80211_recalc_txpower(sdata, update_txp_type);
2498 mutex_unlock(&local->iflist_mtx);
2501 sdata = rtnl_dereference(local->monitor_sdata);
2503 sdata->user_power_level = local->user_power_level;
2504 if (txp_type != sdata->vif.bss_conf.txpower_type)
2505 update_txp_type = true;
2506 sdata->vif.bss_conf.txpower_type = txp_type;
2508 ieee80211_recalc_txpower(sdata, update_txp_type);
2515 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2516 struct wireless_dev *wdev,
2519 struct ieee80211_local *local = wiphy_priv(wiphy);
2520 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2522 if (local->ops->get_txpower)
2523 return drv_get_txpower(local, sdata, dbm);
2525 if (!local->use_chanctx)
2526 *dbm = local->hw.conf.power_level;
2528 *dbm = sdata->vif.bss_conf.txpower;
2533 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2536 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2538 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2543 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2545 struct ieee80211_local *local = wiphy_priv(wiphy);
2547 drv_rfkill_poll(local);
2550 #ifdef CONFIG_NL80211_TESTMODE
2551 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2552 struct wireless_dev *wdev,
2553 void *data, int len)
2555 struct ieee80211_local *local = wiphy_priv(wiphy);
2556 struct ieee80211_vif *vif = NULL;
2558 if (!local->ops->testmode_cmd)
2562 struct ieee80211_sub_if_data *sdata;
2564 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2565 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2569 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2572 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2573 struct sk_buff *skb,
2574 struct netlink_callback *cb,
2575 void *data, int len)
2577 struct ieee80211_local *local = wiphy_priv(wiphy);
2579 if (!local->ops->testmode_dump)
2582 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2586 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2587 enum ieee80211_smps_mode smps_mode)
2589 struct sta_info *sta;
2590 enum ieee80211_smps_mode old_req;
2592 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2595 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2598 old_req = sdata->u.ap.req_smps;
2599 sdata->u.ap.req_smps = smps_mode;
2601 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2602 if (old_req == smps_mode ||
2603 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2607 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2608 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2610 mutex_lock(&sdata->local->sta_mtx);
2611 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2613 * Only stations associated to our AP and
2616 if (sta->sdata->bss != &sdata->u.ap)
2619 /* This station doesn't support MIMO - skip it */
2620 if (sta_info_tx_streams(sta) == 1)
2624 * Don't wake up a STA just to send the action frame
2625 * unless we are getting more restrictive.
2627 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2628 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2630 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2636 * If the STA is not authorized, wait until it gets
2637 * authorized and the action frame will be sent then.
2639 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2642 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2643 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2644 sdata->vif.bss_conf.bssid);
2646 mutex_unlock(&sdata->local->sta_mtx);
2648 sdata->smps_mode = smps_mode;
2649 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2654 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2655 enum ieee80211_smps_mode smps_mode)
2658 enum ieee80211_smps_mode old_req;
2660 struct sta_info *sta;
2661 bool tdls_peer_found = false;
2663 lockdep_assert_held(&sdata->wdev.mtx);
2665 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2668 old_req = sdata->u.mgd.req_smps;
2669 sdata->u.mgd.req_smps = smps_mode;
2671 if (old_req == smps_mode &&
2672 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2676 * If not associated, or current association is not an HT
2677 * association, there's no need to do anything, just store
2678 * the new value until we associate.
2680 if (!sdata->u.mgd.associated ||
2681 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2684 ap = sdata->u.mgd.associated->bssid;
2687 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2688 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2689 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2692 tdls_peer_found = true;
2697 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2698 if (tdls_peer_found || !sdata->u.mgd.powersave)
2699 smps_mode = IEEE80211_SMPS_OFF;
2701 smps_mode = IEEE80211_SMPS_DYNAMIC;
2704 /* send SM PS frame to AP */
2705 err = ieee80211_send_smps_action(sdata, smps_mode,
2708 sdata->u.mgd.req_smps = old_req;
2709 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2710 ieee80211_teardown_tdls_peers(sdata);
2715 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2716 bool enabled, int timeout)
2718 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2719 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2721 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2724 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2727 if (enabled == sdata->u.mgd.powersave &&
2728 timeout == local->dynamic_ps_forced_timeout)
2731 sdata->u.mgd.powersave = enabled;
2732 local->dynamic_ps_forced_timeout = timeout;
2734 /* no change, but if automatic follow powersave */
2736 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2737 sdata_unlock(sdata);
2739 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
2740 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2742 ieee80211_recalc_ps(local);
2743 ieee80211_recalc_ps_vif(sdata);
2744 ieee80211_check_fast_rx_iface(sdata);
2749 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2750 struct net_device *dev,
2751 s32 rssi_thold, u32 rssi_hyst)
2753 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2754 struct ieee80211_vif *vif = &sdata->vif;
2755 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2757 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2758 rssi_hyst == bss_conf->cqm_rssi_hyst)
2761 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2762 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2765 bss_conf->cqm_rssi_thold = rssi_thold;
2766 bss_conf->cqm_rssi_hyst = rssi_hyst;
2767 bss_conf->cqm_rssi_low = 0;
2768 bss_conf->cqm_rssi_high = 0;
2769 sdata->u.mgd.last_cqm_event_signal = 0;
2771 /* tell the driver upon association, unless already associated */
2772 if (sdata->u.mgd.associated &&
2773 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2774 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2779 static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2780 struct net_device *dev,
2781 s32 rssi_low, s32 rssi_high)
2783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2784 struct ieee80211_vif *vif = &sdata->vif;
2785 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2787 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2790 bss_conf->cqm_rssi_low = rssi_low;
2791 bss_conf->cqm_rssi_high = rssi_high;
2792 bss_conf->cqm_rssi_thold = 0;
2793 bss_conf->cqm_rssi_hyst = 0;
2794 sdata->u.mgd.last_cqm_event_signal = 0;
2796 /* tell the driver upon association, unless already associated */
2797 if (sdata->u.mgd.associated &&
2798 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2799 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2804 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2805 struct net_device *dev,
2807 const struct cfg80211_bitrate_mask *mask)
2809 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2813 if (!ieee80211_sdata_running(sdata))
2817 * If active validate the setting and reject it if it doesn't leave
2818 * at least one basic rate usable, since we really have to be able
2819 * to send something, and if we're an AP we have to be able to do
2820 * so at a basic rate so that all clients can receive it.
2822 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
2823 sdata->vif.bss_conf.chandef.chan) {
2824 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2825 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
2827 if (!(mask->control[band].legacy & basic_rates))
2831 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2832 ret = drv_set_bitrate_mask(local, sdata, mask);
2837 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2838 struct ieee80211_supported_band *sband = wiphy->bands[i];
2841 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2842 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2843 sizeof(mask->control[i].ht_mcs));
2844 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2845 mask->control[i].vht_mcs,
2846 sizeof(mask->control[i].vht_mcs));
2848 sdata->rc_has_mcs_mask[i] = false;
2849 sdata->rc_has_vht_mcs_mask[i] = false;
2853 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
2854 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2855 sdata->rc_has_mcs_mask[i] = true;
2860 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2861 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2862 sdata->rc_has_vht_mcs_mask[i] = true;
2871 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2872 struct net_device *dev,
2873 struct cfg80211_chan_def *chandef,
2876 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2877 struct ieee80211_local *local = sdata->local;
2880 mutex_lock(&local->mtx);
2881 if (!list_empty(&local->roc_list) || local->scanning) {
2886 /* whatever, but channel contexts should not complain about that one */
2887 sdata->smps_mode = IEEE80211_SMPS_OFF;
2888 sdata->needed_rx_chains = local->rx_chains;
2890 err = ieee80211_vif_use_channel(sdata, chandef,
2891 IEEE80211_CHANCTX_SHARED);
2895 ieee80211_queue_delayed_work(&sdata->local->hw,
2896 &sdata->dfs_cac_timer_work,
2897 msecs_to_jiffies(cac_time_ms));
2900 mutex_unlock(&local->mtx);
2904 static struct cfg80211_beacon_data *
2905 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2907 struct cfg80211_beacon_data *new_beacon;
2911 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2912 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2913 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
2915 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2919 pos = (u8 *)(new_beacon + 1);
2920 if (beacon->head_len) {
2921 new_beacon->head_len = beacon->head_len;
2922 new_beacon->head = pos;
2923 memcpy(pos, beacon->head, beacon->head_len);
2924 pos += beacon->head_len;
2926 if (beacon->tail_len) {
2927 new_beacon->tail_len = beacon->tail_len;
2928 new_beacon->tail = pos;
2929 memcpy(pos, beacon->tail, beacon->tail_len);
2930 pos += beacon->tail_len;
2932 if (beacon->beacon_ies_len) {
2933 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2934 new_beacon->beacon_ies = pos;
2935 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2936 pos += beacon->beacon_ies_len;
2938 if (beacon->proberesp_ies_len) {
2939 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2940 new_beacon->proberesp_ies = pos;
2941 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2942 pos += beacon->proberesp_ies_len;
2944 if (beacon->assocresp_ies_len) {
2945 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2946 new_beacon->assocresp_ies = pos;
2947 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2948 pos += beacon->assocresp_ies_len;
2950 if (beacon->probe_resp_len) {
2951 new_beacon->probe_resp_len = beacon->probe_resp_len;
2952 new_beacon->probe_resp = pos;
2953 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2954 pos += beacon->probe_resp_len;
2957 /* might copy -1, meaning no changes requested */
2958 new_beacon->ftm_responder = beacon->ftm_responder;
2960 new_beacon->lci_len = beacon->lci_len;
2961 new_beacon->lci = pos;
2962 memcpy(pos, beacon->lci, beacon->lci_len);
2963 pos += beacon->lci_len;
2965 if (beacon->civicloc) {
2966 new_beacon->civicloc_len = beacon->civicloc_len;
2967 new_beacon->civicloc = pos;
2968 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
2969 pos += beacon->civicloc_len;
2975 void ieee80211_csa_finish(struct ieee80211_vif *vif)
2977 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2979 ieee80211_queue_work(&sdata->local->hw,
2980 &sdata->csa_finalize_work);
2982 EXPORT_SYMBOL(ieee80211_csa_finish);
2984 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2989 switch (sdata->vif.type) {
2990 case NL80211_IFTYPE_AP:
2991 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2993 kfree(sdata->u.ap.next_beacon);
2994 sdata->u.ap.next_beacon = NULL;
3000 case NL80211_IFTYPE_ADHOC:
3001 err = ieee80211_ibss_finish_csa(sdata);
3006 #ifdef CONFIG_MAC80211_MESH
3007 case NL80211_IFTYPE_MESH_POINT:
3008 err = ieee80211_mesh_finish_csa(sdata);
3022 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3024 struct ieee80211_local *local = sdata->local;
3028 sdata_assert_lock(sdata);
3029 lockdep_assert_held(&local->mtx);
3030 lockdep_assert_held(&local->chanctx_mtx);
3033 * using reservation isn't immediate as it may be deferred until later
3034 * with multi-vif. once reservation is complete it will re-schedule the
3035 * work with no reserved_chanctx so verify chandef to check if it
3036 * completed successfully
3039 if (sdata->reserved_chanctx) {
3041 * with multi-vif csa driver may call ieee80211_csa_finish()
3042 * many times while waiting for other interfaces to use their
3045 if (sdata->reserved_ready)
3048 return ieee80211_vif_use_reserved_context(sdata);
3051 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3052 &sdata->csa_chandef))
3055 sdata->vif.csa_active = false;
3057 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3061 ieee80211_bss_info_change_notify(sdata, changed);
3063 if (sdata->csa_block_tx) {
3064 ieee80211_wake_vif_queues(local, sdata,
3065 IEEE80211_QUEUE_STOP_REASON_CSA);
3066 sdata->csa_block_tx = false;
3069 err = drv_post_channel_switch(sdata);
3073 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3078 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3080 if (__ieee80211_csa_finalize(sdata)) {
3081 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3082 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3087 void ieee80211_csa_finalize_work(struct work_struct *work)
3089 struct ieee80211_sub_if_data *sdata =
3090 container_of(work, struct ieee80211_sub_if_data,
3092 struct ieee80211_local *local = sdata->local;
3095 mutex_lock(&local->mtx);
3096 mutex_lock(&local->chanctx_mtx);
3098 /* AP might have been stopped while waiting for the lock. */
3099 if (!sdata->vif.csa_active)
3102 if (!ieee80211_sdata_running(sdata))
3105 ieee80211_csa_finalize(sdata);
3108 mutex_unlock(&local->chanctx_mtx);
3109 mutex_unlock(&local->mtx);
3110 sdata_unlock(sdata);
3113 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3114 struct cfg80211_csa_settings *params,
3117 struct ieee80211_csa_settings csa = {};
3120 switch (sdata->vif.type) {
3121 case NL80211_IFTYPE_AP:
3122 sdata->u.ap.next_beacon =
3123 cfg80211_beacon_dup(¶ms->beacon_after);
3124 if (!sdata->u.ap.next_beacon)
3128 * With a count of 0, we don't have to wait for any
3129 * TBTT before switching, so complete the CSA
3130 * immediately. In theory, with a count == 1 we
3131 * should delay the switch until just before the next
3132 * TBTT, but that would complicate things so we switch
3133 * immediately too. If we would delay the switch
3134 * until the next TBTT, we would have to set the probe
3137 * TODO: A channel switch with count <= 1 without
3138 * sending a CSA action frame is kind of useless,
3139 * because the clients won't know we're changing
3140 * channels. The action frame must be implemented
3141 * either here or in the userspace.
3143 if (params->count <= 1)
3146 if ((params->n_counter_offsets_beacon >
3147 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3148 (params->n_counter_offsets_presp >
3149 IEEE80211_MAX_CSA_COUNTERS_NUM))
3152 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3153 csa.counter_offsets_presp = params->counter_offsets_presp;
3154 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3155 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3156 csa.count = params->count;
3158 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa);
3160 kfree(sdata->u.ap.next_beacon);
3166 case NL80211_IFTYPE_ADHOC:
3167 if (!sdata->vif.bss_conf.ibss_joined)
3170 if (params->chandef.width != sdata->u.ibss.chandef.width)
3173 switch (params->chandef.width) {
3174 case NL80211_CHAN_WIDTH_40:
3175 if (cfg80211_get_chandef_type(¶ms->chandef) !=
3176 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3178 case NL80211_CHAN_WIDTH_5:
3179 case NL80211_CHAN_WIDTH_10:
3180 case NL80211_CHAN_WIDTH_20_NOHT:
3181 case NL80211_CHAN_WIDTH_20:
3187 /* changes into another band are not supported */
3188 if (sdata->u.ibss.chandef.chan->band !=
3189 params->chandef.chan->band)
3192 /* see comments in the NL80211_IFTYPE_AP block */
3193 if (params->count > 1) {
3194 err = ieee80211_ibss_csa_beacon(sdata, params);
3200 ieee80211_send_action_csa(sdata, params);
3203 #ifdef CONFIG_MAC80211_MESH
3204 case NL80211_IFTYPE_MESH_POINT: {
3205 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3207 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3210 /* changes into another band are not supported */
3211 if (sdata->vif.bss_conf.chandef.chan->band !=
3212 params->chandef.chan->band)
3215 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3216 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3217 if (!ifmsh->pre_value)
3218 ifmsh->pre_value = 1;
3223 /* see comments in the NL80211_IFTYPE_AP block */
3224 if (params->count > 1) {
3225 err = ieee80211_mesh_csa_beacon(sdata, params);
3227 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3233 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3234 ieee80211_send_action_csa(sdata, params);
3247 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3248 struct cfg80211_csa_settings *params)
3250 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3251 struct ieee80211_local *local = sdata->local;
3252 struct ieee80211_channel_switch ch_switch;
3253 struct ieee80211_chanctx_conf *conf;
3254 struct ieee80211_chanctx *chanctx;
3258 sdata_assert_lock(sdata);
3259 lockdep_assert_held(&local->mtx);
3261 if (!list_empty(&local->roc_list) || local->scanning)
3264 if (sdata->wdev.cac_started)
3267 if (cfg80211_chandef_identical(¶ms->chandef,
3268 &sdata->vif.bss_conf.chandef))
3271 /* don't allow another channel switch if one is already active. */
3272 if (sdata->vif.csa_active)
3275 mutex_lock(&local->chanctx_mtx);
3276 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3277 lockdep_is_held(&local->chanctx_mtx));
3283 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3285 ch_switch.timestamp = 0;
3286 ch_switch.device_timestamp = 0;
3287 ch_switch.block_tx = params->block_tx;
3288 ch_switch.chandef = params->chandef;
3289 ch_switch.count = params->count;
3291 err = drv_pre_channel_switch(sdata, &ch_switch);
3295 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
3297 params->radar_required);
3301 /* if reservation is invalid then this will fail */
3302 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3304 ieee80211_vif_unreserve_chanctx(sdata);
3308 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3310 ieee80211_vif_unreserve_chanctx(sdata);
3314 sdata->csa_chandef = params->chandef;
3315 sdata->csa_block_tx = params->block_tx;
3316 sdata->vif.csa_active = true;
3318 if (sdata->csa_block_tx)
3319 ieee80211_stop_vif_queues(local, sdata,
3320 IEEE80211_QUEUE_STOP_REASON_CSA);
3322 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3326 ieee80211_bss_info_change_notify(sdata, changed);
3327 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3329 /* if the beacon didn't change, we can finalize immediately */
3330 ieee80211_csa_finalize(sdata);
3334 mutex_unlock(&local->chanctx_mtx);
3338 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3339 struct cfg80211_csa_settings *params)
3341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3342 struct ieee80211_local *local = sdata->local;
3345 mutex_lock(&local->mtx);
3346 err = __ieee80211_channel_switch(wiphy, dev, params);
3347 mutex_unlock(&local->mtx);
3352 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3354 lockdep_assert_held(&local->mtx);
3356 local->roc_cookie_counter++;
3358 /* wow, you wrapped 64 bits ... more likely a bug */
3359 if (WARN_ON(local->roc_cookie_counter == 0))
3360 local->roc_cookie_counter++;
3362 return local->roc_cookie_counter;
3365 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3366 u64 *cookie, gfp_t gfp)
3368 unsigned long spin_flags;
3369 struct sk_buff *ack_skb;
3372 ack_skb = skb_copy(skb, gfp);
3376 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3377 id = idr_alloc(&local->ack_status_frames, ack_skb,
3378 1, 0x10000, GFP_ATOMIC);
3379 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3386 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3388 *cookie = ieee80211_mgmt_tx_cookie(local);
3389 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3394 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3395 struct wireless_dev *wdev,
3396 u16 frame_type, bool reg)
3398 struct ieee80211_local *local = wiphy_priv(wiphy);
3399 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3401 switch (frame_type) {
3402 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3404 local->probe_req_reg++;
3405 sdata->vif.probe_req_reg++;
3407 if (local->probe_req_reg)
3408 local->probe_req_reg--;
3410 if (sdata->vif.probe_req_reg)
3411 sdata->vif.probe_req_reg--;
3414 if (!local->open_count)
3417 if (sdata->vif.probe_req_reg == 1)
3418 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3420 else if (sdata->vif.probe_req_reg == 0)
3421 drv_config_iface_filter(local, sdata, 0,
3424 ieee80211_configure_filter(local);
3431 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3433 struct ieee80211_local *local = wiphy_priv(wiphy);
3438 return drv_set_antenna(local, tx_ant, rx_ant);
3441 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3443 struct ieee80211_local *local = wiphy_priv(wiphy);
3445 return drv_get_antenna(local, tx_ant, rx_ant);
3448 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3449 struct net_device *dev,
3450 struct cfg80211_gtk_rekey_data *data)
3452 struct ieee80211_local *local = wiphy_priv(wiphy);
3453 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3455 if (!local->ops->set_rekey_data)
3458 drv_set_rekey_data(local, sdata, data);
3463 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3464 const u8 *peer, u64 *cookie)
3466 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3467 struct ieee80211_local *local = sdata->local;
3468 struct ieee80211_qos_hdr *nullfunc;
3469 struct sk_buff *skb;
3470 int size = sizeof(*nullfunc);
3473 struct ieee80211_tx_info *info;
3474 struct sta_info *sta;
3475 struct ieee80211_chanctx_conf *chanctx_conf;
3476 enum nl80211_band band;
3479 /* the lock is needed to assign the cookie later */
3480 mutex_lock(&local->mtx);
3483 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3484 if (WARN_ON(!chanctx_conf)) {
3488 band = chanctx_conf->def.chan->band;
3489 sta = sta_info_get_bss(sdata, peer);
3498 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3499 IEEE80211_STYPE_QOS_NULLFUNC |
3500 IEEE80211_FCTL_FROMDS);
3503 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3504 IEEE80211_STYPE_NULLFUNC |
3505 IEEE80211_FCTL_FROMDS);
3508 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3516 skb_reserve(skb, local->hw.extra_tx_headroom);
3518 nullfunc = skb_put(skb, size);
3519 nullfunc->frame_control = fc;
3520 nullfunc->duration_id = 0;
3521 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3522 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3523 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3524 nullfunc->seq_ctrl = 0;
3526 info = IEEE80211_SKB_CB(skb);
3528 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3529 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3532 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3535 nullfunc->qos_ctrl = cpu_to_le16(7);
3537 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3544 ieee80211_xmit(sdata, sta, skb, 0);
3550 mutex_unlock(&local->mtx);
3555 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3556 struct wireless_dev *wdev,
3557 struct cfg80211_chan_def *chandef)
3559 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3560 struct ieee80211_local *local = wiphy_priv(wiphy);
3561 struct ieee80211_chanctx_conf *chanctx_conf;
3565 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3567 *chandef = sdata->vif.bss_conf.chandef;
3569 } else if (local->open_count > 0 &&
3570 local->open_count == local->monitors &&
3571 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3572 if (local->use_chanctx)
3573 *chandef = local->monitor_chandef;
3575 *chandef = local->_oper_chandef;
3584 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3586 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3590 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3591 struct net_device *dev,
3592 struct cfg80211_qos_map *qos_map)
3594 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3595 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3598 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3601 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3603 /* A NULL qos_map was passed to disable QoS mapping */
3607 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3608 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3610 kfree_rcu(old_qos_map, rcu_head);
3615 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3616 struct net_device *dev,
3617 struct cfg80211_chan_def *chandef)
3619 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3623 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3625 ieee80211_bss_info_change_notify(sdata, changed);
3630 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3631 u8 tsid, const u8 *peer, u8 up,
3634 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3635 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3636 int ac = ieee802_1d_to_ac[up];
3638 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3641 if (!(sdata->wmm_acm & BIT(up)))
3644 if (ifmgd->tx_tspec[ac].admitted_time)
3647 if (admitted_time) {
3648 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3649 ifmgd->tx_tspec[ac].tsid = tsid;
3650 ifmgd->tx_tspec[ac].up = up;
3656 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3657 u8 tsid, const u8 *peer)
3659 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3660 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3661 struct ieee80211_local *local = wiphy_priv(wiphy);
3664 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3665 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3667 /* skip unused entries */
3668 if (!tx_tspec->admitted_time)
3671 if (tx_tspec->tsid != tsid)
3674 /* due to this new packets will be reassigned to non-ACM ACs */
3677 /* Make sure that all packets have been sent to avoid to
3678 * restore the QoS params on packets that are still on the
3682 ieee80211_flush_queues(local, sdata, false);
3684 /* restore the normal QoS parameters
3685 * (unconditionally to avoid races)
3687 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3688 tx_tspec->downgraded = false;
3689 ieee80211_sta_handle_tspec_ac_params(sdata);
3691 /* finally clear all the data */
3692 memset(tx_tspec, 0, sizeof(*tx_tspec));
3700 void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3702 enum nl80211_nan_func_term_reason reason,
3705 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3706 struct cfg80211_nan_func *func;
3709 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3712 spin_lock_bh(&sdata->u.nan.func_lock);
3714 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3715 if (WARN_ON(!func)) {
3716 spin_unlock_bh(&sdata->u.nan.func_lock);
3720 cookie = func->cookie;
3721 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3723 spin_unlock_bh(&sdata->u.nan.func_lock);
3725 cfg80211_free_nan_func(func);
3727 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3728 reason, cookie, gfp);
3730 EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3732 void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3733 struct cfg80211_nan_match_params *match,
3736 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3737 struct cfg80211_nan_func *func;
3739 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3742 spin_lock_bh(&sdata->u.nan.func_lock);
3744 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3745 if (WARN_ON(!func)) {
3746 spin_unlock_bh(&sdata->u.nan.func_lock);
3749 match->cookie = func->cookie;
3751 spin_unlock_bh(&sdata->u.nan.func_lock);
3753 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
3755 EXPORT_SYMBOL(ieee80211_nan_func_match);
3757 static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
3758 struct net_device *dev,
3761 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3763 sdata->u.ap.multicast_to_unicast = enabled;
3768 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
3769 struct txq_info *txqi)
3771 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
3772 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
3773 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
3776 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
3777 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
3778 txqstats->backlog_packets = txqi->tin.backlog_packets;
3781 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
3782 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
3783 txqstats->flows = txqi->tin.flows;
3786 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
3787 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
3788 txqstats->drops = txqi->cstats.drop_count;
3791 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
3792 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
3793 txqstats->ecn_marks = txqi->cstats.ecn_mark;
3796 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
3797 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
3798 txqstats->overlimit = txqi->tin.overlimit;
3801 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
3802 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
3803 txqstats->collisions = txqi->tin.collisions;
3806 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
3807 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
3808 txqstats->tx_bytes = txqi->tin.tx_bytes;
3811 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
3812 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
3813 txqstats->tx_packets = txqi->tin.tx_packets;
3817 static int ieee80211_get_txq_stats(struct wiphy *wiphy,
3818 struct wireless_dev *wdev,
3819 struct cfg80211_txq_stats *txqstats)
3821 struct ieee80211_local *local = wiphy_priv(wiphy);
3822 struct ieee80211_sub_if_data *sdata;
3825 if (!local->ops->wake_tx_queue)
3828 spin_lock_bh(&local->fq.lock);
3832 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3833 if (!sdata->vif.txq) {
3837 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
3840 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
3841 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
3842 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
3843 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
3844 BIT(NL80211_TXQ_STATS_COLLISIONS) |
3845 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
3846 txqstats->backlog_packets = local->fq.backlog;
3847 txqstats->backlog_bytes = local->fq.memory_usage;
3848 txqstats->overlimit = local->fq.overlimit;
3849 txqstats->overmemory = local->fq.overmemory;
3850 txqstats->collisions = local->fq.collisions;
3851 txqstats->max_flows = local->fq.flows_cnt;
3856 spin_unlock_bh(&local->fq.lock);
3862 ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
3863 struct net_device *dev,
3864 struct cfg80211_ftm_responder_stats *ftm_stats)
3866 struct ieee80211_local *local = wiphy_priv(wiphy);
3867 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3869 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
3873 ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3874 struct cfg80211_pmsr_request *request)
3876 struct ieee80211_local *local = wiphy_priv(wiphy);
3877 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3879 return drv_start_pmsr(local, sdata, request);
3883 ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3884 struct cfg80211_pmsr_request *request)
3886 struct ieee80211_local *local = wiphy_priv(wiphy);
3887 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3889 return drv_abort_pmsr(local, sdata, request);
3892 const struct cfg80211_ops mac80211_config_ops = {
3893 .add_virtual_intf = ieee80211_add_iface,
3894 .del_virtual_intf = ieee80211_del_iface,
3895 .change_virtual_intf = ieee80211_change_iface,
3896 .start_p2p_device = ieee80211_start_p2p_device,
3897 .stop_p2p_device = ieee80211_stop_p2p_device,
3898 .add_key = ieee80211_add_key,
3899 .del_key = ieee80211_del_key,
3900 .get_key = ieee80211_get_key,
3901 .set_default_key = ieee80211_config_default_key,
3902 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3903 .start_ap = ieee80211_start_ap,
3904 .change_beacon = ieee80211_change_beacon,
3905 .stop_ap = ieee80211_stop_ap,
3906 .add_station = ieee80211_add_station,
3907 .del_station = ieee80211_del_station,
3908 .change_station = ieee80211_change_station,
3909 .get_station = ieee80211_get_station,
3910 .dump_station = ieee80211_dump_station,
3911 .dump_survey = ieee80211_dump_survey,
3912 #ifdef CONFIG_MAC80211_MESH
3913 .add_mpath = ieee80211_add_mpath,
3914 .del_mpath = ieee80211_del_mpath,
3915 .change_mpath = ieee80211_change_mpath,
3916 .get_mpath = ieee80211_get_mpath,
3917 .dump_mpath = ieee80211_dump_mpath,
3918 .get_mpp = ieee80211_get_mpp,
3919 .dump_mpp = ieee80211_dump_mpp,
3920 .update_mesh_config = ieee80211_update_mesh_config,
3921 .get_mesh_config = ieee80211_get_mesh_config,
3922 .join_mesh = ieee80211_join_mesh,
3923 .leave_mesh = ieee80211_leave_mesh,
3925 .join_ocb = ieee80211_join_ocb,
3926 .leave_ocb = ieee80211_leave_ocb,
3927 .change_bss = ieee80211_change_bss,
3928 .set_txq_params = ieee80211_set_txq_params,
3929 .set_monitor_channel = ieee80211_set_monitor_channel,
3930 .suspend = ieee80211_suspend,
3931 .resume = ieee80211_resume,
3932 .scan = ieee80211_scan,
3933 .abort_scan = ieee80211_abort_scan,
3934 .sched_scan_start = ieee80211_sched_scan_start,
3935 .sched_scan_stop = ieee80211_sched_scan_stop,
3936 .auth = ieee80211_auth,
3937 .assoc = ieee80211_assoc,
3938 .deauth = ieee80211_deauth,
3939 .disassoc = ieee80211_disassoc,
3940 .join_ibss = ieee80211_join_ibss,
3941 .leave_ibss = ieee80211_leave_ibss,
3942 .set_mcast_rate = ieee80211_set_mcast_rate,
3943 .set_wiphy_params = ieee80211_set_wiphy_params,
3944 .set_tx_power = ieee80211_set_tx_power,
3945 .get_tx_power = ieee80211_get_tx_power,
3946 .set_wds_peer = ieee80211_set_wds_peer,
3947 .rfkill_poll = ieee80211_rfkill_poll,
3948 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3949 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3950 .set_power_mgmt = ieee80211_set_power_mgmt,
3951 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3952 .remain_on_channel = ieee80211_remain_on_channel,
3953 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3954 .mgmt_tx = ieee80211_mgmt_tx,
3955 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3956 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3957 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
3958 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3959 .set_antenna = ieee80211_set_antenna,
3960 .get_antenna = ieee80211_get_antenna,
3961 .set_rekey_data = ieee80211_set_rekey_data,
3962 .tdls_oper = ieee80211_tdls_oper,
3963 .tdls_mgmt = ieee80211_tdls_mgmt,
3964 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3965 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
3966 .probe_client = ieee80211_probe_client,
3967 .set_noack_map = ieee80211_set_noack_map,
3969 .set_wakeup = ieee80211_set_wakeup,
3971 .get_channel = ieee80211_cfg_get_channel,
3972 .start_radar_detection = ieee80211_start_radar_detection,
3973 .channel_switch = ieee80211_channel_switch,
3974 .set_qos_map = ieee80211_set_qos_map,
3975 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
3976 .add_tx_ts = ieee80211_add_tx_ts,
3977 .del_tx_ts = ieee80211_del_tx_ts,
3978 .start_nan = ieee80211_start_nan,
3979 .stop_nan = ieee80211_stop_nan,
3980 .nan_change_conf = ieee80211_nan_change_conf,
3981 .add_nan_func = ieee80211_add_nan_func,
3982 .del_nan_func = ieee80211_del_nan_func,
3983 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
3984 .tx_control_port = ieee80211_tx_control_port,
3985 .get_txq_stats = ieee80211_get_txq_stats,
3986 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
3987 .start_pmsr = ieee80211_start_pmsr,
3988 .abort_pmsr = ieee80211_abort_pmsr,