2 * mac80211 configuration hooks for cfg80211
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2015 Intel Mobile Communications GmbH
7 * This file is GPLv2 as found in COPYING.
10 #include <linux/ieee80211.h>
11 #include <linux/nl80211.h>
12 #include <linux/rtnetlink.h>
13 #include <linux/slab.h>
14 #include <net/net_namespace.h>
15 #include <linux/rcupdate.h>
16 #include <linux/if_ether.h>
17 #include <net/cfg80211.h>
18 #include "ieee80211_i.h"
19 #include "driver-ops.h"
24 static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
26 unsigned char name_assign_type,
27 enum nl80211_iftype type,
29 struct vif_params *params)
31 struct ieee80211_local *local = wiphy_priv(wiphy);
32 struct wireless_dev *wdev;
33 struct ieee80211_sub_if_data *sdata;
36 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
40 if (type == NL80211_IFTYPE_MONITOR && flags) {
41 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
42 sdata->u.mntr.flags = *flags;
48 static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
50 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
55 static int ieee80211_change_iface(struct wiphy *wiphy,
56 struct net_device *dev,
57 enum nl80211_iftype type, u32 *flags,
58 struct vif_params *params)
60 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63 ret = ieee80211_if_change_type(sdata, type);
67 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0) {
69 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
70 ieee80211_check_fast_rx_iface(sdata);
71 } else if (type == NL80211_IFTYPE_STATION &&
72 params && params->use_4addr >= 0) {
73 sdata->u.mgd.use_4addr = params->use_4addr;
76 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
77 struct ieee80211_local *local = sdata->local;
78 struct ieee80211_sub_if_data *monitor_sdata;
79 u32 mu_mntr_cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
81 monitor_sdata = rtnl_dereference(local->monitor_sdata);
83 wiphy_ext_feature_isset(wiphy, mu_mntr_cap_flag)) {
84 memcpy(monitor_sdata->vif.bss_conf.mu_group.membership,
85 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
86 memcpy(monitor_sdata->vif.bss_conf.mu_group.position,
87 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
88 WLAN_USER_POSITION_LEN);
89 monitor_sdata->vif.mu_mimo_owner = true;
90 ieee80211_bss_info_change_notify(monitor_sdata,
91 BSS_CHANGED_MU_GROUPS);
93 ether_addr_copy(monitor_sdata->u.mntr.mu_follow_addr,
100 if (ieee80211_sdata_running(sdata)) {
101 u32 mask = MONITOR_FLAG_COOK_FRAMES |
105 * Prohibit MONITOR_FLAG_COOK_FRAMES and
106 * MONITOR_FLAG_ACTIVE to be changed while the
108 * Else we would need to add a lot of cruft
109 * to update everything:
110 * cooked_mntrs, monitor and all fif_* counters
111 * reconfigure hardware
113 if ((*flags & mask) != (sdata->u.mntr.flags & mask))
116 ieee80211_adjust_monitor_flags(sdata, -1);
117 sdata->u.mntr.flags = *flags;
118 ieee80211_adjust_monitor_flags(sdata, 1);
120 ieee80211_configure_filter(local);
123 * Because the interface is down, ieee80211_do_stop
124 * and ieee80211_do_open take care of "everything"
125 * mentioned in the comment above.
127 sdata->u.mntr.flags = *flags;
134 static int ieee80211_start_p2p_device(struct wiphy *wiphy,
135 struct wireless_dev *wdev)
137 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
140 mutex_lock(&sdata->local->chanctx_mtx);
141 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
142 mutex_unlock(&sdata->local->chanctx_mtx);
146 return ieee80211_do_open(wdev, true);
149 static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
150 struct wireless_dev *wdev)
152 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
155 static int ieee80211_set_noack_map(struct wiphy *wiphy,
156 struct net_device *dev,
159 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
161 sdata->noack_map = noack_map;
163 ieee80211_check_fast_xmit_iface(sdata);
168 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
169 u8 key_idx, bool pairwise, const u8 *mac_addr,
170 struct key_params *params)
172 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
173 struct ieee80211_local *local = sdata->local;
174 struct sta_info *sta = NULL;
175 const struct ieee80211_cipher_scheme *cs = NULL;
176 struct ieee80211_key *key;
179 if (!ieee80211_sdata_running(sdata))
182 /* reject WEP and TKIP keys if WEP failed to initialize */
183 switch (params->cipher) {
184 case WLAN_CIPHER_SUITE_WEP40:
185 case WLAN_CIPHER_SUITE_TKIP:
186 case WLAN_CIPHER_SUITE_WEP104:
187 if (IS_ERR(local->wep_tx_tfm))
190 case WLAN_CIPHER_SUITE_CCMP:
191 case WLAN_CIPHER_SUITE_CCMP_256:
192 case WLAN_CIPHER_SUITE_AES_CMAC:
193 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
194 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
195 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
196 case WLAN_CIPHER_SUITE_GCMP:
197 case WLAN_CIPHER_SUITE_GCMP_256:
200 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
204 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
205 params->key, params->seq_len, params->seq,
211 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
213 mutex_lock(&local->sta_mtx);
216 if (ieee80211_vif_is_mesh(&sdata->vif))
217 sta = sta_info_get(sdata, mac_addr);
219 sta = sta_info_get_bss(sdata, mac_addr);
221 * The ASSOC test makes sure the driver is ready to
222 * receive the key. When wpa_supplicant has roamed
223 * using FT, it attempts to set the key before
224 * association has completed, this rejects that attempt
225 * so it will set the key again after association.
227 * TODO: accept the key if we have a station entry and
228 * add it to the device after the station.
230 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
231 ieee80211_key_free_unused(key);
237 switch (sdata->vif.type) {
238 case NL80211_IFTYPE_STATION:
239 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
240 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
242 case NL80211_IFTYPE_AP:
243 case NL80211_IFTYPE_AP_VLAN:
244 /* Keys without a station are used for TX only */
245 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
246 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
248 case NL80211_IFTYPE_ADHOC:
251 case NL80211_IFTYPE_MESH_POINT:
252 #ifdef CONFIG_MAC80211_MESH
253 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
254 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
257 case NL80211_IFTYPE_WDS:
258 case NL80211_IFTYPE_MONITOR:
259 case NL80211_IFTYPE_P2P_DEVICE:
260 case NL80211_IFTYPE_UNSPECIFIED:
261 case NUM_NL80211_IFTYPES:
262 case NL80211_IFTYPE_P2P_CLIENT:
263 case NL80211_IFTYPE_P2P_GO:
264 case NL80211_IFTYPE_OCB:
265 /* shouldn't happen */
271 sta->cipher_scheme = cs;
273 err = ieee80211_key_link(key, sdata, sta);
276 mutex_unlock(&local->sta_mtx);
281 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
282 u8 key_idx, bool pairwise, const u8 *mac_addr)
284 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
285 struct ieee80211_local *local = sdata->local;
286 struct sta_info *sta;
287 struct ieee80211_key *key = NULL;
290 mutex_lock(&local->sta_mtx);
291 mutex_lock(&local->key_mtx);
296 sta = sta_info_get_bss(sdata, mac_addr);
301 key = key_mtx_dereference(local, sta->ptk[key_idx]);
303 key = key_mtx_dereference(local, sta->gtk[key_idx]);
305 key = key_mtx_dereference(local, sdata->keys[key_idx]);
312 ieee80211_key_free(key, true);
316 mutex_unlock(&local->key_mtx);
317 mutex_unlock(&local->sta_mtx);
322 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
323 u8 key_idx, bool pairwise, const u8 *mac_addr,
325 void (*callback)(void *cookie,
326 struct key_params *params))
328 struct ieee80211_sub_if_data *sdata;
329 struct sta_info *sta = NULL;
331 struct key_params params;
332 struct ieee80211_key *key = NULL;
337 struct ieee80211_key_seq kseq = {};
339 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
344 sta = sta_info_get_bss(sdata, mac_addr);
348 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
349 key = rcu_dereference(sta->ptk[key_idx]);
350 else if (!pairwise &&
351 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
352 key = rcu_dereference(sta->gtk[key_idx]);
354 key = rcu_dereference(sdata->keys[key_idx]);
359 memset(¶ms, 0, sizeof(params));
361 params.cipher = key->conf.cipher;
363 switch (key->conf.cipher) {
364 case WLAN_CIPHER_SUITE_TKIP:
365 pn64 = atomic64_read(&key->conf.tx_pn);
366 iv32 = TKIP_PN_TO_IV32(pn64);
367 iv16 = TKIP_PN_TO_IV16(pn64);
369 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
370 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
371 drv_get_key_seq(sdata->local, key, &kseq);
372 iv32 = kseq.tkip.iv32;
373 iv16 = kseq.tkip.iv16;
376 seq[0] = iv16 & 0xff;
377 seq[1] = (iv16 >> 8) & 0xff;
378 seq[2] = iv32 & 0xff;
379 seq[3] = (iv32 >> 8) & 0xff;
380 seq[4] = (iv32 >> 16) & 0xff;
381 seq[5] = (iv32 >> 24) & 0xff;
385 case WLAN_CIPHER_SUITE_CCMP:
386 case WLAN_CIPHER_SUITE_CCMP_256:
387 case WLAN_CIPHER_SUITE_AES_CMAC:
388 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
389 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
390 offsetof(typeof(kseq), aes_cmac));
391 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
392 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
393 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
394 offsetof(typeof(kseq), aes_gmac));
395 case WLAN_CIPHER_SUITE_GCMP:
396 case WLAN_CIPHER_SUITE_GCMP_256:
397 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
398 offsetof(typeof(kseq), gcmp));
400 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
401 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
402 drv_get_key_seq(sdata->local, key, &kseq);
403 memcpy(seq, kseq.ccmp.pn, 6);
405 pn64 = atomic64_read(&key->conf.tx_pn);
417 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
419 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
421 drv_get_key_seq(sdata->local, key, &kseq);
422 params.seq = kseq.hw.seq;
423 params.seq_len = kseq.hw.seq_len;
427 params.key = key->conf.key;
428 params.key_len = key->conf.keylen;
430 callback(cookie, ¶ms);
438 static int ieee80211_config_default_key(struct wiphy *wiphy,
439 struct net_device *dev,
440 u8 key_idx, bool uni,
443 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
445 ieee80211_set_default_key(sdata, key_idx, uni, multi);
450 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
451 struct net_device *dev,
454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
456 ieee80211_set_default_mgmt_key(sdata, key_idx);
461 void sta_set_rate_info_tx(struct sta_info *sta,
462 const struct ieee80211_tx_rate *rate,
463 struct rate_info *rinfo)
466 if (rate->flags & IEEE80211_TX_RC_MCS) {
467 rinfo->flags |= RATE_INFO_FLAGS_MCS;
468 rinfo->mcs = rate->idx;
469 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
470 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
471 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
472 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
474 struct ieee80211_supported_band *sband;
475 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
478 sband = sta->local->hw.wiphy->bands[
479 ieee80211_get_sdata_band(sta->sdata)];
480 brate = sband->bitrates[rate->idx].bitrate;
481 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
483 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
484 rinfo->bw = RATE_INFO_BW_40;
485 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
486 rinfo->bw = RATE_INFO_BW_80;
487 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
488 rinfo->bw = RATE_INFO_BW_160;
490 rinfo->bw = RATE_INFO_BW_20;
491 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
492 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
495 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
496 int idx, u8 *mac, struct station_info *sinfo)
498 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
499 struct ieee80211_local *local = sdata->local;
500 struct sta_info *sta;
503 mutex_lock(&local->sta_mtx);
505 sta = sta_info_get_by_idx(sdata, idx);
508 memcpy(mac, sta->sta.addr, ETH_ALEN);
509 sta_set_sinfo(sta, sinfo);
512 mutex_unlock(&local->sta_mtx);
517 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
518 int idx, struct survey_info *survey)
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
522 return drv_get_survey(local, idx, survey);
525 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
526 const u8 *mac, struct station_info *sinfo)
528 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
529 struct ieee80211_local *local = sdata->local;
530 struct sta_info *sta;
533 mutex_lock(&local->sta_mtx);
535 sta = sta_info_get_bss(sdata, mac);
538 sta_set_sinfo(sta, sinfo);
541 mutex_unlock(&local->sta_mtx);
546 static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
547 struct cfg80211_chan_def *chandef)
549 struct ieee80211_local *local = wiphy_priv(wiphy);
550 struct ieee80211_sub_if_data *sdata;
553 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
556 mutex_lock(&local->mtx);
557 mutex_lock(&local->iflist_mtx);
558 if (local->use_chanctx) {
559 sdata = rcu_dereference_protected(
560 local->monitor_sdata,
561 lockdep_is_held(&local->iflist_mtx));
563 ieee80211_vif_release_channel(sdata);
564 ret = ieee80211_vif_use_channel(sdata, chandef,
565 IEEE80211_CHANCTX_EXCLUSIVE);
567 } else if (local->open_count == local->monitors) {
568 local->_oper_chandef = *chandef;
569 ieee80211_hw_config(local, 0);
573 local->monitor_chandef = *chandef;
574 mutex_unlock(&local->iflist_mtx);
575 mutex_unlock(&local->mtx);
580 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
581 const u8 *resp, size_t resp_len,
582 const struct ieee80211_csa_settings *csa)
584 struct probe_resp *new, *old;
586 if (!resp || !resp_len)
589 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
591 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
596 memcpy(new->data, resp, resp_len);
599 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
600 csa->n_counter_offsets_presp *
601 sizeof(new->csa_counter_offsets[0]));
603 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
605 kfree_rcu(old, rcu_head);
610 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
611 struct cfg80211_beacon_data *params,
612 const struct ieee80211_csa_settings *csa)
614 struct beacon_data *new, *old;
615 int new_head_len, new_tail_len;
617 u32 changed = BSS_CHANGED_BEACON;
619 old = sdata_dereference(sdata->u.ap.beacon, sdata);
622 /* Need to have a beacon head if we don't have one yet */
623 if (!params->head && !old)
626 /* new or old head? */
628 new_head_len = params->head_len;
630 new_head_len = old->head_len;
632 /* new or old tail? */
633 if (params->tail || !old)
634 /* params->tail_len will be zero for !params->tail */
635 new_tail_len = params->tail_len;
637 new_tail_len = old->tail_len;
639 size = sizeof(*new) + new_head_len + new_tail_len;
641 new = kzalloc(size, GFP_KERNEL);
645 /* start filling the new info now */
648 * pointers go into the block we allocated,
649 * memory is | beacon_data | head | tail |
651 new->head = ((u8 *) new) + sizeof(*new);
652 new->tail = new->head + new_head_len;
653 new->head_len = new_head_len;
654 new->tail_len = new_tail_len;
657 new->csa_current_counter = csa->count;
658 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
659 csa->n_counter_offsets_beacon *
660 sizeof(new->csa_counter_offsets[0]));
665 memcpy(new->head, params->head, new_head_len);
667 memcpy(new->head, old->head, new_head_len);
669 /* copy in optional tail */
671 memcpy(new->tail, params->tail, new_tail_len);
674 memcpy(new->tail, old->tail, new_tail_len);
676 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
677 params->probe_resp_len, csa);
681 changed |= BSS_CHANGED_AP_PROBE_RESP;
683 rcu_assign_pointer(sdata->u.ap.beacon, new);
686 kfree_rcu(old, rcu_head);
691 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
692 struct cfg80211_ap_settings *params)
694 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
695 struct ieee80211_local *local = sdata->local;
696 struct beacon_data *old;
697 struct ieee80211_sub_if_data *vlan;
698 u32 changed = BSS_CHANGED_BEACON_INT |
699 BSS_CHANGED_BEACON_ENABLED |
706 old = sdata_dereference(sdata->u.ap.beacon, sdata);
710 switch (params->smps_mode) {
711 case NL80211_SMPS_OFF:
712 sdata->smps_mode = IEEE80211_SMPS_OFF;
714 case NL80211_SMPS_STATIC:
715 sdata->smps_mode = IEEE80211_SMPS_STATIC;
717 case NL80211_SMPS_DYNAMIC:
718 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
723 sdata->needed_rx_chains = sdata->local->rx_chains;
725 mutex_lock(&local->mtx);
726 err = ieee80211_vif_use_channel(sdata, ¶ms->chandef,
727 IEEE80211_CHANCTX_SHARED);
729 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
730 mutex_unlock(&local->mtx);
735 * Apply control port protocol, this allows us to
736 * not encrypt dynamic WEP control frames.
738 sdata->control_port_protocol = params->crypto.control_port_ethertype;
739 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
740 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
744 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
745 vlan->control_port_protocol =
746 params->crypto.control_port_ethertype;
747 vlan->control_port_no_encrypt =
748 params->crypto.control_port_no_encrypt;
749 vlan->encrypt_headroom =
750 ieee80211_cs_headroom(sdata->local,
755 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
756 sdata->vif.bss_conf.dtim_period = params->dtim_period;
757 sdata->vif.bss_conf.enable_beacon = true;
758 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
760 sdata->vif.bss_conf.ssid_len = params->ssid_len;
761 if (params->ssid_len)
762 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
764 sdata->vif.bss_conf.hidden_ssid =
765 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
767 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
768 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
769 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
770 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
771 if (params->p2p_opp_ps)
772 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
773 IEEE80211_P2P_OPPPS_ENABLE_BIT;
775 err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL);
777 ieee80211_vif_release_channel(sdata);
782 err = drv_start_ap(sdata->local, sdata);
784 old = sdata_dereference(sdata->u.ap.beacon, sdata);
787 kfree_rcu(old, rcu_head);
788 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
789 ieee80211_vif_release_channel(sdata);
793 ieee80211_recalc_dtim(local, sdata);
794 ieee80211_bss_info_change_notify(sdata, changed);
796 netif_carrier_on(dev);
797 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
798 netif_carrier_on(vlan->dev);
803 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
804 struct cfg80211_beacon_data *params)
806 struct ieee80211_sub_if_data *sdata;
807 struct beacon_data *old;
810 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
811 sdata_assert_lock(sdata);
813 /* don't allow changing the beacon while CSA is in place - offset
814 * of channel switch counter may change
816 if (sdata->vif.csa_active)
819 old = sdata_dereference(sdata->u.ap.beacon, sdata);
823 err = ieee80211_assign_beacon(sdata, params, NULL);
826 ieee80211_bss_info_change_notify(sdata, err);
830 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
832 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
833 struct ieee80211_sub_if_data *vlan;
834 struct ieee80211_local *local = sdata->local;
835 struct beacon_data *old_beacon;
836 struct probe_resp *old_probe_resp;
837 struct cfg80211_chan_def chandef;
839 sdata_assert_lock(sdata);
841 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
844 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
846 /* abort any running channel switch */
847 mutex_lock(&local->mtx);
848 sdata->vif.csa_active = false;
849 if (sdata->csa_block_tx) {
850 ieee80211_wake_vif_queues(local, sdata,
851 IEEE80211_QUEUE_STOP_REASON_CSA);
852 sdata->csa_block_tx = false;
855 mutex_unlock(&local->mtx);
857 kfree(sdata->u.ap.next_beacon);
858 sdata->u.ap.next_beacon = NULL;
860 /* turn off carrier for this interface and dependent VLANs */
861 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
862 netif_carrier_off(vlan->dev);
863 netif_carrier_off(dev);
865 /* remove beacon and probe response */
866 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
867 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
868 kfree_rcu(old_beacon, rcu_head);
870 kfree_rcu(old_probe_resp, rcu_head);
871 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
873 __sta_info_flush(sdata, true);
874 ieee80211_free_keys(sdata, true);
876 sdata->vif.bss_conf.enable_beacon = false;
877 sdata->vif.bss_conf.ssid_len = 0;
878 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
879 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
881 if (sdata->wdev.cac_started) {
882 chandef = sdata->vif.bss_conf.chandef;
883 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
884 cfg80211_cac_event(sdata->dev, &chandef,
885 NL80211_RADAR_CAC_ABORTED,
889 drv_stop_ap(sdata->local, sdata);
891 /* free all potentially still buffered bcast frames */
892 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
893 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
895 mutex_lock(&local->mtx);
896 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
897 ieee80211_vif_release_channel(sdata);
898 mutex_unlock(&local->mtx);
903 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
904 struct iapp_layer2_update {
905 u8 da[ETH_ALEN]; /* broadcast */
906 u8 sa[ETH_ALEN]; /* STA addr */
914 static void ieee80211_send_layer2_update(struct sta_info *sta)
916 struct iapp_layer2_update *msg;
919 /* Send Level 2 Update Frame to update forwarding tables in layer 2
922 skb = dev_alloc_skb(sizeof(*msg));
925 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
927 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
928 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
930 eth_broadcast_addr(msg->da);
931 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
934 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
935 msg->control = 0xaf; /* XID response lsb.1111F101.
936 * F=0 (no poll command; unsolicited frame) */
937 msg->xid_info[0] = 0x81; /* XID format identifier */
938 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
939 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
941 skb->dev = sta->sdata->dev;
942 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
943 memset(skb->cb, 0, sizeof(skb->cb));
947 static int sta_apply_auth_flags(struct ieee80211_local *local,
948 struct sta_info *sta,
953 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
954 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
955 !test_sta_flag(sta, WLAN_STA_AUTH)) {
956 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
961 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
962 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
963 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
965 * When peer becomes associated, init rate control as
966 * well. Some drivers require rate control initialized
967 * before drv_sta_state() is called.
969 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
970 rate_control_rate_init(sta);
972 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
977 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
978 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
979 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
980 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
981 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
988 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
989 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
990 test_sta_flag(sta, WLAN_STA_ASSOC)) {
991 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
996 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
997 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
998 test_sta_flag(sta, WLAN_STA_AUTH)) {
999 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1007 static void sta_apply_mesh_params(struct ieee80211_local *local,
1008 struct sta_info *sta,
1009 struct station_parameters *params)
1011 #ifdef CONFIG_MAC80211_MESH
1012 struct ieee80211_sub_if_data *sdata = sta->sdata;
1015 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1016 switch (params->plink_state) {
1017 case NL80211_PLINK_ESTAB:
1018 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1019 changed = mesh_plink_inc_estab_count(sdata);
1020 sta->mesh->plink_state = params->plink_state;
1021 sta->mesh->aid = params->peer_aid;
1023 ieee80211_mps_sta_status_update(sta);
1024 changed |= ieee80211_mps_set_sta_local_pm(sta,
1025 sdata->u.mesh.mshcfg.power_mode);
1027 case NL80211_PLINK_LISTEN:
1028 case NL80211_PLINK_BLOCKED:
1029 case NL80211_PLINK_OPN_SNT:
1030 case NL80211_PLINK_OPN_RCVD:
1031 case NL80211_PLINK_CNF_RCVD:
1032 case NL80211_PLINK_HOLDING:
1033 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1034 changed = mesh_plink_dec_estab_count(sdata);
1035 sta->mesh->plink_state = params->plink_state;
1037 ieee80211_mps_sta_status_update(sta);
1038 changed |= ieee80211_mps_set_sta_local_pm(sta,
1039 NL80211_MESH_POWER_UNKNOWN);
1047 switch (params->plink_action) {
1048 case NL80211_PLINK_ACTION_NO_ACTION:
1051 case NL80211_PLINK_ACTION_OPEN:
1052 changed |= mesh_plink_open(sta);
1054 case NL80211_PLINK_ACTION_BLOCK:
1055 changed |= mesh_plink_block(sta);
1059 if (params->local_pm)
1060 changed |= ieee80211_mps_set_sta_local_pm(sta,
1063 ieee80211_mbss_info_change_notify(sdata, changed);
1067 static int sta_apply_parameters(struct ieee80211_local *local,
1068 struct sta_info *sta,
1069 struct station_parameters *params)
1072 struct ieee80211_supported_band *sband;
1073 struct ieee80211_sub_if_data *sdata = sta->sdata;
1074 enum nl80211_band band = ieee80211_get_sdata_band(sdata);
1077 sband = local->hw.wiphy->bands[band];
1079 mask = params->sta_flags_mask;
1080 set = params->sta_flags_set;
1082 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1084 * In mesh mode, ASSOCIATED isn't part of the nl80211
1085 * API but must follow AUTHENTICATED for driver state.
1087 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1088 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1089 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1090 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1091 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1093 * TDLS -- everything follows authorized, but
1094 * only becoming authorized is possible, not
1097 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1098 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1099 BIT(NL80211_STA_FLAG_ASSOCIATED);
1100 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1101 BIT(NL80211_STA_FLAG_ASSOCIATED);
1105 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1106 local->hw.queues >= IEEE80211_NUM_ACS)
1107 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1109 /* auth flags will be set later for TDLS,
1110 * and for unassociated stations that move to assocaited */
1111 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1112 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1113 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
1114 ret = sta_apply_auth_flags(local, sta, mask, set);
1119 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
1120 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
1121 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1123 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1126 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
1127 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
1128 if (set & BIT(NL80211_STA_FLAG_MFP))
1129 set_sta_flag(sta, WLAN_STA_MFP);
1131 clear_sta_flag(sta, WLAN_STA_MFP);
1134 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1135 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1136 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1138 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
1141 /* mark TDLS channel switch support, if the AP allows it */
1142 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1143 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1144 params->ext_capab_len >= 4 &&
1145 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1146 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1148 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1149 !sdata->u.mgd.tdls_wider_bw_prohibited &&
1150 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1151 params->ext_capab_len >= 8 &&
1152 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1153 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1155 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1156 sta->sta.uapsd_queues = params->uapsd_queues;
1157 sta->sta.max_sp = params->max_sp;
1160 /* The sender might not have sent the last bit, consider it to be 0 */
1161 if (params->ext_capab_len >= 8) {
1162 u8 val = (params->ext_capab[7] &
1163 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1165 /* we did get all the bits, take the MSB as well */
1166 if (params->ext_capab_len >= 9) {
1167 u8 val_msb = params->ext_capab[8] &
1168 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1175 sta->sta.max_amsdu_subframes = 32;
1178 sta->sta.max_amsdu_subframes = 16;
1181 sta->sta.max_amsdu_subframes = 8;
1184 sta->sta.max_amsdu_subframes = 0;
1189 * cfg80211 validates this (1-2007) and allows setting the AID
1190 * only when creating a new station entry
1193 sta->sta.aid = params->aid;
1196 * Some of the following updates would be racy if called on an
1197 * existing station, via ieee80211_change_station(). However,
1198 * all such changes are rejected by cfg80211 except for updates
1199 * changing the supported rates on an existing but not yet used
1203 if (params->listen_interval >= 0)
1204 sta->listen_interval = params->listen_interval;
1206 if (params->supported_rates) {
1207 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1208 sband, params->supported_rates,
1209 params->supported_rates_len,
1210 &sta->sta.supp_rates[band]);
1213 if (params->ht_capa)
1214 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1215 params->ht_capa, sta);
1217 /* VHT can override some HT caps such as the A-MSDU max length */
1218 if (params->vht_capa)
1219 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1220 params->vht_capa, sta);
1222 if (params->opmode_notif_used) {
1223 /* returned value is only needed for rc update, but the
1224 * rc isn't initialized here yet, so ignore it
1226 __ieee80211_vht_handle_opmode(sdata, sta,
1227 params->opmode_notif, band);
1230 if (params->support_p2p_ps >= 0)
1231 sta->sta.support_p2p_ps = params->support_p2p_ps;
1233 if (ieee80211_vif_is_mesh(&sdata->vif))
1234 sta_apply_mesh_params(local, sta, params);
1236 /* set the STA state after all sta info from usermode has been set */
1237 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1238 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
1239 ret = sta_apply_auth_flags(local, sta, mask, set);
1247 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1249 struct station_parameters *params)
1251 struct ieee80211_local *local = wiphy_priv(wiphy);
1252 struct sta_info *sta;
1253 struct ieee80211_sub_if_data *sdata;
1258 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1260 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1261 sdata->vif.type != NL80211_IFTYPE_AP)
1264 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1266 if (ether_addr_equal(mac, sdata->vif.addr))
1269 if (is_multicast_ether_addr(mac))
1272 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
1276 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1277 sta->sta.tdls = true;
1279 err = sta_apply_parameters(local, sta, params);
1281 sta_info_free(local, sta);
1286 * for TDLS and for unassociated station, rate control should be
1287 * initialized only when rates are known and station is marked
1288 * authorized/associated
1290 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1291 test_sta_flag(sta, WLAN_STA_ASSOC))
1292 rate_control_rate_init(sta);
1294 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1295 sdata->vif.type == NL80211_IFTYPE_AP;
1297 err = sta_info_insert_rcu(sta);
1304 ieee80211_send_layer2_update(sta);
1311 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1312 struct station_del_parameters *params)
1314 struct ieee80211_sub_if_data *sdata;
1316 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1319 return sta_info_destroy_addr_bss(sdata, params->mac);
1321 sta_info_flush(sdata);
1325 static int ieee80211_change_station(struct wiphy *wiphy,
1326 struct net_device *dev, const u8 *mac,
1327 struct station_parameters *params)
1329 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1330 struct ieee80211_local *local = wiphy_priv(wiphy);
1331 struct sta_info *sta;
1332 struct ieee80211_sub_if_data *vlansdata;
1333 enum cfg80211_station_type statype;
1336 mutex_lock(&local->sta_mtx);
1338 sta = sta_info_get_bss(sdata, mac);
1344 switch (sdata->vif.type) {
1345 case NL80211_IFTYPE_MESH_POINT:
1346 if (sdata->u.mesh.user_mpm)
1347 statype = CFG80211_STA_MESH_PEER_USER;
1349 statype = CFG80211_STA_MESH_PEER_KERNEL;
1351 case NL80211_IFTYPE_ADHOC:
1352 statype = CFG80211_STA_IBSS;
1354 case NL80211_IFTYPE_STATION:
1355 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1356 statype = CFG80211_STA_AP_STA;
1359 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1360 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1362 statype = CFG80211_STA_TDLS_PEER_SETUP;
1364 case NL80211_IFTYPE_AP:
1365 case NL80211_IFTYPE_AP_VLAN:
1366 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1367 statype = CFG80211_STA_AP_CLIENT;
1369 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
1376 err = cfg80211_check_station_change(wiphy, params, statype);
1380 if (params->vlan && params->vlan != sta->sdata->dev) {
1381 bool prev_4addr = false;
1382 bool new_4addr = false;
1384 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1386 if (params->vlan->ieee80211_ptr->use_4addr) {
1387 if (vlansdata->u.vlan.sta) {
1392 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1394 __ieee80211_check_fast_rx_iface(vlansdata);
1397 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1398 sta->sdata->u.vlan.sta) {
1399 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1403 sta->sdata = vlansdata;
1404 ieee80211_check_fast_xmit(sta);
1406 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1407 prev_4addr != new_4addr) {
1409 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1411 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1414 ieee80211_send_layer2_update(sta);
1417 err = sta_apply_parameters(local, sta, params);
1421 mutex_unlock(&local->sta_mtx);
1423 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1424 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1425 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1426 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1427 sta_info_tx_streams(sta) != 1) {
1429 "%pM just authorized and MIMO capable - update SMPS\n",
1431 ieee80211_send_smps_action(sta->sdata,
1432 sta->sdata->bss->req_smps,
1434 sta->sdata->vif.bss_conf.bssid);
1437 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1438 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1439 ieee80211_recalc_ps(local);
1440 ieee80211_recalc_ps_vif(sdata);
1445 mutex_unlock(&local->sta_mtx);
1449 #ifdef CONFIG_MAC80211_MESH
1450 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1451 const u8 *dst, const u8 *next_hop)
1453 struct ieee80211_sub_if_data *sdata;
1454 struct mesh_path *mpath;
1455 struct sta_info *sta;
1457 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1460 sta = sta_info_get(sdata, next_hop);
1466 mpath = mesh_path_add(sdata, dst);
1467 if (IS_ERR(mpath)) {
1469 return PTR_ERR(mpath);
1472 mesh_path_fix_nexthop(mpath, sta);
1478 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1481 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1484 return mesh_path_del(sdata, dst);
1486 mesh_path_flush_by_iface(sdata);
1490 static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1491 const u8 *dst, const u8 *next_hop)
1493 struct ieee80211_sub_if_data *sdata;
1494 struct mesh_path *mpath;
1495 struct sta_info *sta;
1497 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1501 sta = sta_info_get(sdata, next_hop);
1507 mpath = mesh_path_lookup(sdata, dst);
1513 mesh_path_fix_nexthop(mpath, sta);
1519 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1520 struct mpath_info *pinfo)
1522 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1525 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1527 eth_zero_addr(next_hop);
1529 memset(pinfo, 0, sizeof(*pinfo));
1531 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
1533 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1536 MPATH_INFO_EXPTIME |
1537 MPATH_INFO_DISCOVERY_TIMEOUT |
1538 MPATH_INFO_DISCOVERY_RETRIES |
1541 pinfo->frame_qlen = mpath->frame_queue.qlen;
1542 pinfo->sn = mpath->sn;
1543 pinfo->metric = mpath->metric;
1544 if (time_before(jiffies, mpath->exp_time))
1545 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1546 pinfo->discovery_timeout =
1547 jiffies_to_msecs(mpath->discovery_timeout);
1548 pinfo->discovery_retries = mpath->discovery_retries;
1549 if (mpath->flags & MESH_PATH_ACTIVE)
1550 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1551 if (mpath->flags & MESH_PATH_RESOLVING)
1552 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1553 if (mpath->flags & MESH_PATH_SN_VALID)
1554 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1555 if (mpath->flags & MESH_PATH_FIXED)
1556 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1557 if (mpath->flags & MESH_PATH_RESOLVED)
1558 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
1561 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1562 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1565 struct ieee80211_sub_if_data *sdata;
1566 struct mesh_path *mpath;
1568 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1571 mpath = mesh_path_lookup(sdata, dst);
1576 memcpy(dst, mpath->dst, ETH_ALEN);
1577 mpath_set_pinfo(mpath, next_hop, pinfo);
1582 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1583 int idx, u8 *dst, u8 *next_hop,
1584 struct mpath_info *pinfo)
1586 struct ieee80211_sub_if_data *sdata;
1587 struct mesh_path *mpath;
1589 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1592 mpath = mesh_path_lookup_by_idx(sdata, idx);
1597 memcpy(dst, mpath->dst, ETH_ALEN);
1598 mpath_set_pinfo(mpath, next_hop, pinfo);
1603 static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1604 struct mpath_info *pinfo)
1606 memset(pinfo, 0, sizeof(*pinfo));
1607 memcpy(mpp, mpath->mpp, ETH_ALEN);
1609 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
1612 static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1613 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1616 struct ieee80211_sub_if_data *sdata;
1617 struct mesh_path *mpath;
1619 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1622 mpath = mpp_path_lookup(sdata, dst);
1627 memcpy(dst, mpath->dst, ETH_ALEN);
1628 mpp_set_pinfo(mpath, mpp, pinfo);
1633 static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1634 int idx, u8 *dst, u8 *mpp,
1635 struct mpath_info *pinfo)
1637 struct ieee80211_sub_if_data *sdata;
1638 struct mesh_path *mpath;
1640 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1643 mpath = mpp_path_lookup_by_idx(sdata, idx);
1648 memcpy(dst, mpath->dst, ETH_ALEN);
1649 mpp_set_pinfo(mpath, mpp, pinfo);
1654 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1655 struct net_device *dev,
1656 struct mesh_config *conf)
1658 struct ieee80211_sub_if_data *sdata;
1659 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1661 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1665 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1667 return (mask >> (parm-1)) & 0x1;
1670 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1671 const struct mesh_setup *setup)
1675 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1676 struct ieee80211_sub_if_data, u.mesh);
1678 /* allocate information elements */
1682 if (setup->ie_len) {
1683 new_ie = kmemdup(setup->ie, setup->ie_len,
1688 ifmsh->ie_len = setup->ie_len;
1692 /* now copy the rest of the setup parameters */
1693 ifmsh->mesh_id_len = setup->mesh_id_len;
1694 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1695 ifmsh->mesh_sp_id = setup->sync_method;
1696 ifmsh->mesh_pp_id = setup->path_sel_proto;
1697 ifmsh->mesh_pm_id = setup->path_metric;
1698 ifmsh->user_mpm = setup->user_mpm;
1699 ifmsh->mesh_auth_id = setup->auth_id;
1700 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1701 if (setup->is_authenticated)
1702 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1703 if (setup->is_secure)
1704 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1706 /* mcast rate setting in Mesh Node */
1707 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1708 sizeof(setup->mcast_rate));
1709 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
1711 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1712 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1717 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1718 struct net_device *dev, u32 mask,
1719 const struct mesh_config *nconf)
1721 struct mesh_config *conf;
1722 struct ieee80211_sub_if_data *sdata;
1723 struct ieee80211_if_mesh *ifmsh;
1725 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1726 ifmsh = &sdata->u.mesh;
1728 /* Set the config options which we are interested in setting */
1729 conf = &(sdata->u.mesh.mshcfg);
1730 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1731 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1732 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1733 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1734 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1735 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1736 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1737 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1738 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1739 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1740 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1741 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1742 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1743 conf->element_ttl = nconf->element_ttl;
1744 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1745 if (ifmsh->user_mpm)
1747 conf->auto_open_plinks = nconf->auto_open_plinks;
1749 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1750 conf->dot11MeshNbrOffsetMaxNeighbor =
1751 nconf->dot11MeshNbrOffsetMaxNeighbor;
1752 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1753 conf->dot11MeshHWMPmaxPREQretries =
1754 nconf->dot11MeshHWMPmaxPREQretries;
1755 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1756 conf->path_refresh_time = nconf->path_refresh_time;
1757 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1758 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1759 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1760 conf->dot11MeshHWMPactivePathTimeout =
1761 nconf->dot11MeshHWMPactivePathTimeout;
1762 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1763 conf->dot11MeshHWMPpreqMinInterval =
1764 nconf->dot11MeshHWMPpreqMinInterval;
1765 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1766 conf->dot11MeshHWMPperrMinInterval =
1767 nconf->dot11MeshHWMPperrMinInterval;
1768 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1770 conf->dot11MeshHWMPnetDiameterTraversalTime =
1771 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1772 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1773 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1774 ieee80211_mesh_root_setup(ifmsh);
1776 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1777 /* our current gate announcement implementation rides on root
1778 * announcements, so require this ifmsh to also be a root node
1780 if (nconf->dot11MeshGateAnnouncementProtocol &&
1781 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1782 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
1783 ieee80211_mesh_root_setup(ifmsh);
1785 conf->dot11MeshGateAnnouncementProtocol =
1786 nconf->dot11MeshGateAnnouncementProtocol;
1788 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
1789 conf->dot11MeshHWMPRannInterval =
1790 nconf->dot11MeshHWMPRannInterval;
1791 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1792 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1793 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1794 /* our RSSI threshold implementation is supported only for
1795 * devices that report signal in dBm.
1797 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
1799 conf->rssi_threshold = nconf->rssi_threshold;
1801 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1802 conf->ht_opmode = nconf->ht_opmode;
1803 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1804 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1806 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1807 conf->dot11MeshHWMPactivePathToRootTimeout =
1808 nconf->dot11MeshHWMPactivePathToRootTimeout;
1809 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1810 conf->dot11MeshHWMProotInterval =
1811 nconf->dot11MeshHWMProotInterval;
1812 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1813 conf->dot11MeshHWMPconfirmationInterval =
1814 nconf->dot11MeshHWMPconfirmationInterval;
1815 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1816 conf->power_mode = nconf->power_mode;
1817 ieee80211_mps_local_status_update(sdata);
1819 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
1820 conf->dot11MeshAwakeWindowDuration =
1821 nconf->dot11MeshAwakeWindowDuration;
1822 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1823 conf->plink_timeout = nconf->plink_timeout;
1824 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
1828 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1829 const struct mesh_config *conf,
1830 const struct mesh_setup *setup)
1832 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1833 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1836 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1837 err = copy_mesh_setup(ifmsh, setup);
1841 /* can mesh use other SMPS modes? */
1842 sdata->smps_mode = IEEE80211_SMPS_OFF;
1843 sdata->needed_rx_chains = sdata->local->rx_chains;
1845 mutex_lock(&sdata->local->mtx);
1846 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1847 IEEE80211_CHANCTX_SHARED);
1848 mutex_unlock(&sdata->local->mtx);
1852 return ieee80211_start_mesh(sdata);
1855 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1859 ieee80211_stop_mesh(sdata);
1860 mutex_lock(&sdata->local->mtx);
1861 ieee80211_vif_release_channel(sdata);
1862 mutex_unlock(&sdata->local->mtx);
1868 static int ieee80211_change_bss(struct wiphy *wiphy,
1869 struct net_device *dev,
1870 struct bss_parameters *params)
1872 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1873 enum nl80211_band band;
1876 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
1879 band = ieee80211_get_sdata_band(sdata);
1881 if (params->use_cts_prot >= 0) {
1882 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1883 changed |= BSS_CHANGED_ERP_CTS_PROT;
1885 if (params->use_short_preamble >= 0) {
1886 sdata->vif.bss_conf.use_short_preamble =
1887 params->use_short_preamble;
1888 changed |= BSS_CHANGED_ERP_PREAMBLE;
1891 if (!sdata->vif.bss_conf.use_short_slot &&
1892 band == NL80211_BAND_5GHZ) {
1893 sdata->vif.bss_conf.use_short_slot = true;
1894 changed |= BSS_CHANGED_ERP_SLOT;
1897 if (params->use_short_slot_time >= 0) {
1898 sdata->vif.bss_conf.use_short_slot =
1899 params->use_short_slot_time;
1900 changed |= BSS_CHANGED_ERP_SLOT;
1903 if (params->basic_rates) {
1904 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1906 params->basic_rates,
1907 params->basic_rates_len,
1908 &sdata->vif.bss_conf.basic_rates);
1909 changed |= BSS_CHANGED_BASIC_RATES;
1912 if (params->ap_isolate >= 0) {
1913 if (params->ap_isolate)
1914 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1916 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1917 ieee80211_check_fast_rx_iface(sdata);
1920 if (params->ht_opmode >= 0) {
1921 sdata->vif.bss_conf.ht_operation_mode =
1922 (u16) params->ht_opmode;
1923 changed |= BSS_CHANGED_HT;
1926 if (params->p2p_ctwindow >= 0) {
1927 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1928 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1929 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1930 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1931 changed |= BSS_CHANGED_P2P_PS;
1934 if (params->p2p_opp_ps > 0) {
1935 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1936 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1937 changed |= BSS_CHANGED_P2P_PS;
1938 } else if (params->p2p_opp_ps == 0) {
1939 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1940 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
1941 changed |= BSS_CHANGED_P2P_PS;
1944 ieee80211_bss_info_change_notify(sdata, changed);
1949 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1950 struct net_device *dev,
1951 struct ieee80211_txq_params *params)
1953 struct ieee80211_local *local = wiphy_priv(wiphy);
1954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1955 struct ieee80211_tx_queue_params p;
1957 if (!local->ops->conf_tx)
1960 if (local->hw.queues < IEEE80211_NUM_ACS)
1963 memset(&p, 0, sizeof(p));
1964 p.aifs = params->aifs;
1965 p.cw_max = params->cwmax;
1966 p.cw_min = params->cwmin;
1967 p.txop = params->txop;
1970 * Setting tx queue params disables u-apsd because it's only
1971 * called in master mode.
1975 sdata->tx_conf[params->ac] = p;
1976 if (drv_conf_tx(local, sdata, params->ac, &p)) {
1977 wiphy_debug(local->hw.wiphy,
1978 "failed to set TX queue parameters for AC %d\n",
1983 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1989 static int ieee80211_suspend(struct wiphy *wiphy,
1990 struct cfg80211_wowlan *wowlan)
1992 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1995 static int ieee80211_resume(struct wiphy *wiphy)
1997 return __ieee80211_resume(wiphy_priv(wiphy));
2000 #define ieee80211_suspend NULL
2001 #define ieee80211_resume NULL
2004 static int ieee80211_scan(struct wiphy *wiphy,
2005 struct cfg80211_scan_request *req)
2007 struct ieee80211_sub_if_data *sdata;
2009 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
2011 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2012 case NL80211_IFTYPE_STATION:
2013 case NL80211_IFTYPE_ADHOC:
2014 case NL80211_IFTYPE_MESH_POINT:
2015 case NL80211_IFTYPE_P2P_CLIENT:
2016 case NL80211_IFTYPE_P2P_DEVICE:
2018 case NL80211_IFTYPE_P2P_GO:
2019 if (sdata->local->ops->hw_scan)
2022 * FIXME: implement NoA while scanning in software,
2023 * for now fall through to allow scanning only when
2024 * beaconing hasn't been configured yet
2026 case NL80211_IFTYPE_AP:
2028 * If the scan has been forced (and the driver supports
2029 * forcing), don't care about being beaconing already.
2030 * This will create problems to the attached stations (e.g. all
2031 * the frames sent while scanning on other channel will be
2034 if (sdata->u.ap.beacon &&
2035 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2036 !(req->flags & NL80211_SCAN_FLAG_AP)))
2043 return ieee80211_request_scan(sdata, req);
2046 static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2048 ieee80211_scan_cancel(wiphy_priv(wiphy));
2052 ieee80211_sched_scan_start(struct wiphy *wiphy,
2053 struct net_device *dev,
2054 struct cfg80211_sched_scan_request *req)
2056 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2058 if (!sdata->local->ops->sched_scan_start)
2061 return ieee80211_request_sched_scan_start(sdata, req);
2065 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
2067 struct ieee80211_local *local = wiphy_priv(wiphy);
2069 if (!local->ops->sched_scan_stop)
2072 return ieee80211_request_sched_scan_stop(local);
2075 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2076 struct cfg80211_auth_request *req)
2078 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2081 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2082 struct cfg80211_assoc_request *req)
2084 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2087 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
2088 struct cfg80211_deauth_request *req)
2090 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
2093 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
2094 struct cfg80211_disassoc_request *req)
2096 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
2099 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2100 struct cfg80211_ibss_params *params)
2102 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
2105 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2107 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2110 static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2111 struct ocb_setup *setup)
2113 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2116 static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2118 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2121 static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2122 int rate[NUM_NL80211_BANDS])
2124 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2126 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2127 sizeof(int) * NUM_NL80211_BANDS);
2132 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2134 struct ieee80211_local *local = wiphy_priv(wiphy);
2137 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2138 ieee80211_check_fast_xmit_all(local);
2140 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2143 ieee80211_check_fast_xmit_all(local);
2148 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2149 (changed & WIPHY_PARAM_DYN_ACK)) {
2152 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2153 wiphy->coverage_class : -1;
2154 err = drv_set_coverage_class(local, coverage_class);
2160 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
2161 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
2167 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2168 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2170 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
2172 if (changed & WIPHY_PARAM_RETRY_LONG) {
2173 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2175 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
2178 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2179 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2184 static int ieee80211_set_tx_power(struct wiphy *wiphy,
2185 struct wireless_dev *wdev,
2186 enum nl80211_tx_power_setting type, int mbm)
2188 struct ieee80211_local *local = wiphy_priv(wiphy);
2189 struct ieee80211_sub_if_data *sdata;
2190 enum nl80211_tx_power_setting txp_type = type;
2191 bool update_txp_type = false;
2194 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2197 case NL80211_TX_POWER_AUTOMATIC:
2198 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2199 txp_type = NL80211_TX_POWER_LIMITED;
2201 case NL80211_TX_POWER_LIMITED:
2202 case NL80211_TX_POWER_FIXED:
2203 if (mbm < 0 || (mbm % 100))
2205 sdata->user_power_level = MBM_TO_DBM(mbm);
2209 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2210 update_txp_type = true;
2211 sdata->vif.bss_conf.txpower_type = txp_type;
2214 ieee80211_recalc_txpower(sdata, update_txp_type);
2220 case NL80211_TX_POWER_AUTOMATIC:
2221 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2222 txp_type = NL80211_TX_POWER_LIMITED;
2224 case NL80211_TX_POWER_LIMITED:
2225 case NL80211_TX_POWER_FIXED:
2226 if (mbm < 0 || (mbm % 100))
2228 local->user_power_level = MBM_TO_DBM(mbm);
2232 mutex_lock(&local->iflist_mtx);
2233 list_for_each_entry(sdata, &local->interfaces, list) {
2234 sdata->user_power_level = local->user_power_level;
2235 if (txp_type != sdata->vif.bss_conf.txpower_type)
2236 update_txp_type = true;
2237 sdata->vif.bss_conf.txpower_type = txp_type;
2239 list_for_each_entry(sdata, &local->interfaces, list)
2240 ieee80211_recalc_txpower(sdata, update_txp_type);
2241 mutex_unlock(&local->iflist_mtx);
2246 static int ieee80211_get_tx_power(struct wiphy *wiphy,
2247 struct wireless_dev *wdev,
2250 struct ieee80211_local *local = wiphy_priv(wiphy);
2251 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2253 if (local->ops->get_txpower)
2254 return drv_get_txpower(local, sdata, dbm);
2256 if (!local->use_chanctx)
2257 *dbm = local->hw.conf.power_level;
2259 *dbm = sdata->vif.bss_conf.txpower;
2264 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
2267 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2269 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2274 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2276 struct ieee80211_local *local = wiphy_priv(wiphy);
2278 drv_rfkill_poll(local);
2281 #ifdef CONFIG_NL80211_TESTMODE
2282 static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2283 struct wireless_dev *wdev,
2284 void *data, int len)
2286 struct ieee80211_local *local = wiphy_priv(wiphy);
2287 struct ieee80211_vif *vif = NULL;
2289 if (!local->ops->testmode_cmd)
2293 struct ieee80211_sub_if_data *sdata;
2295 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2296 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2300 return local->ops->testmode_cmd(&local->hw, vif, data, len);
2303 static int ieee80211_testmode_dump(struct wiphy *wiphy,
2304 struct sk_buff *skb,
2305 struct netlink_callback *cb,
2306 void *data, int len)
2308 struct ieee80211_local *local = wiphy_priv(wiphy);
2310 if (!local->ops->testmode_dump)
2313 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2317 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2318 enum ieee80211_smps_mode smps_mode)
2320 struct sta_info *sta;
2321 enum ieee80211_smps_mode old_req;
2323 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2326 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2329 old_req = sdata->u.ap.req_smps;
2330 sdata->u.ap.req_smps = smps_mode;
2332 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2333 if (old_req == smps_mode ||
2334 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2337 /* If no associated stations, there's no need to do anything */
2338 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2339 sdata->smps_mode = smps_mode;
2340 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2345 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2346 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2348 mutex_lock(&sdata->local->sta_mtx);
2349 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2351 * Only stations associated to our AP and
2354 if (sta->sdata->bss != &sdata->u.ap)
2357 /* This station doesn't support MIMO - skip it */
2358 if (sta_info_tx_streams(sta) == 1)
2362 * Don't wake up a STA just to send the action frame
2363 * unless we are getting more restrictive.
2365 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2366 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2368 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2374 * If the STA is not authorized, wait until it gets
2375 * authorized and the action frame will be sent then.
2377 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2380 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2381 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2382 sdata->vif.bss_conf.bssid);
2384 mutex_unlock(&sdata->local->sta_mtx);
2386 sdata->smps_mode = smps_mode;
2387 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2392 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2393 enum ieee80211_smps_mode smps_mode)
2396 enum ieee80211_smps_mode old_req;
2398 struct sta_info *sta;
2399 bool tdls_peer_found = false;
2401 lockdep_assert_held(&sdata->wdev.mtx);
2403 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2406 old_req = sdata->u.mgd.req_smps;
2407 sdata->u.mgd.req_smps = smps_mode;
2409 if (old_req == smps_mode &&
2410 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2414 * If not associated, or current association is not an HT
2415 * association, there's no need to do anything, just store
2416 * the new value until we associate.
2418 if (!sdata->u.mgd.associated ||
2419 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2422 ap = sdata->u.mgd.associated->bssid;
2425 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2426 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2427 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2430 tdls_peer_found = true;
2435 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2436 if (tdls_peer_found || !sdata->u.mgd.powersave)
2437 smps_mode = IEEE80211_SMPS_OFF;
2439 smps_mode = IEEE80211_SMPS_DYNAMIC;
2442 /* send SM PS frame to AP */
2443 err = ieee80211_send_smps_action(sdata, smps_mode,
2446 sdata->u.mgd.req_smps = old_req;
2447 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2448 ieee80211_teardown_tdls_peers(sdata);
2453 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2454 bool enabled, int timeout)
2456 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2459 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2462 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
2465 if (enabled == sdata->u.mgd.powersave &&
2466 timeout == local->dynamic_ps_forced_timeout)
2469 sdata->u.mgd.powersave = enabled;
2470 local->dynamic_ps_forced_timeout = timeout;
2472 /* no change, but if automatic follow powersave */
2474 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
2475 sdata_unlock(sdata);
2477 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
2478 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2480 ieee80211_recalc_ps(local);
2481 ieee80211_recalc_ps_vif(sdata);
2486 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2487 struct net_device *dev,
2488 s32 rssi_thold, u32 rssi_hyst)
2490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2491 struct ieee80211_vif *vif = &sdata->vif;
2492 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2494 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2495 rssi_hyst == bss_conf->cqm_rssi_hyst)
2498 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2499 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2502 bss_conf->cqm_rssi_thold = rssi_thold;
2503 bss_conf->cqm_rssi_hyst = rssi_hyst;
2504 sdata->u.mgd.last_cqm_event_signal = 0;
2506 /* tell the driver upon association, unless already associated */
2507 if (sdata->u.mgd.associated &&
2508 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2509 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2514 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2515 struct net_device *dev,
2517 const struct cfg80211_bitrate_mask *mask)
2519 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2523 if (!ieee80211_sdata_running(sdata))
2526 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2527 ret = drv_set_bitrate_mask(local, sdata, mask);
2532 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2533 struct ieee80211_supported_band *sband = wiphy->bands[i];
2536 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
2537 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2538 sizeof(mask->control[i].ht_mcs));
2539 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2540 mask->control[i].vht_mcs,
2541 sizeof(mask->control[i].vht_mcs));
2543 sdata->rc_has_mcs_mask[i] = false;
2544 sdata->rc_has_vht_mcs_mask[i] = false;
2548 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
2549 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2550 sdata->rc_has_mcs_mask[i] = true;
2555 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2556 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2557 sdata->rc_has_vht_mcs_mask[i] = true;
2566 static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2567 struct net_device *dev,
2568 struct cfg80211_chan_def *chandef,
2571 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2572 struct ieee80211_local *local = sdata->local;
2575 mutex_lock(&local->mtx);
2576 if (!list_empty(&local->roc_list) || local->scanning) {
2581 /* whatever, but channel contexts should not complain about that one */
2582 sdata->smps_mode = IEEE80211_SMPS_OFF;
2583 sdata->needed_rx_chains = local->rx_chains;
2585 err = ieee80211_vif_use_channel(sdata, chandef,
2586 IEEE80211_CHANCTX_SHARED);
2590 ieee80211_queue_delayed_work(&sdata->local->hw,
2591 &sdata->dfs_cac_timer_work,
2592 msecs_to_jiffies(cac_time_ms));
2595 mutex_unlock(&local->mtx);
2599 static struct cfg80211_beacon_data *
2600 cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2602 struct cfg80211_beacon_data *new_beacon;
2606 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2607 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2608 beacon->probe_resp_len;
2610 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2614 pos = (u8 *)(new_beacon + 1);
2615 if (beacon->head_len) {
2616 new_beacon->head_len = beacon->head_len;
2617 new_beacon->head = pos;
2618 memcpy(pos, beacon->head, beacon->head_len);
2619 pos += beacon->head_len;
2621 if (beacon->tail_len) {
2622 new_beacon->tail_len = beacon->tail_len;
2623 new_beacon->tail = pos;
2624 memcpy(pos, beacon->tail, beacon->tail_len);
2625 pos += beacon->tail_len;
2627 if (beacon->beacon_ies_len) {
2628 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2629 new_beacon->beacon_ies = pos;
2630 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2631 pos += beacon->beacon_ies_len;
2633 if (beacon->proberesp_ies_len) {
2634 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2635 new_beacon->proberesp_ies = pos;
2636 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2637 pos += beacon->proberesp_ies_len;
2639 if (beacon->assocresp_ies_len) {
2640 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2641 new_beacon->assocresp_ies = pos;
2642 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2643 pos += beacon->assocresp_ies_len;
2645 if (beacon->probe_resp_len) {
2646 new_beacon->probe_resp_len = beacon->probe_resp_len;
2647 beacon->probe_resp = pos;
2648 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2649 pos += beacon->probe_resp_len;
2655 void ieee80211_csa_finish(struct ieee80211_vif *vif)
2657 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2659 ieee80211_queue_work(&sdata->local->hw,
2660 &sdata->csa_finalize_work);
2662 EXPORT_SYMBOL(ieee80211_csa_finish);
2664 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2669 switch (sdata->vif.type) {
2670 case NL80211_IFTYPE_AP:
2671 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2673 kfree(sdata->u.ap.next_beacon);
2674 sdata->u.ap.next_beacon = NULL;
2680 case NL80211_IFTYPE_ADHOC:
2681 err = ieee80211_ibss_finish_csa(sdata);
2686 #ifdef CONFIG_MAC80211_MESH
2687 case NL80211_IFTYPE_MESH_POINT:
2688 err = ieee80211_mesh_finish_csa(sdata);
2702 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2704 struct ieee80211_local *local = sdata->local;
2708 sdata_assert_lock(sdata);
2709 lockdep_assert_held(&local->mtx);
2710 lockdep_assert_held(&local->chanctx_mtx);
2713 * using reservation isn't immediate as it may be deferred until later
2714 * with multi-vif. once reservation is complete it will re-schedule the
2715 * work with no reserved_chanctx so verify chandef to check if it
2716 * completed successfully
2719 if (sdata->reserved_chanctx) {
2721 * with multi-vif csa driver may call ieee80211_csa_finish()
2722 * many times while waiting for other interfaces to use their
2725 if (sdata->reserved_ready)
2728 return ieee80211_vif_use_reserved_context(sdata);
2731 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2732 &sdata->csa_chandef))
2735 sdata->vif.csa_active = false;
2737 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2741 ieee80211_bss_info_change_notify(sdata, changed);
2743 if (sdata->csa_block_tx) {
2744 ieee80211_wake_vif_queues(local, sdata,
2745 IEEE80211_QUEUE_STOP_REASON_CSA);
2746 sdata->csa_block_tx = false;
2749 err = drv_post_channel_switch(sdata);
2753 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2758 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2760 if (__ieee80211_csa_finalize(sdata)) {
2761 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2762 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2767 void ieee80211_csa_finalize_work(struct work_struct *work)
2769 struct ieee80211_sub_if_data *sdata =
2770 container_of(work, struct ieee80211_sub_if_data,
2772 struct ieee80211_local *local = sdata->local;
2775 mutex_lock(&local->mtx);
2776 mutex_lock(&local->chanctx_mtx);
2778 /* AP might have been stopped while waiting for the lock. */
2779 if (!sdata->vif.csa_active)
2782 if (!ieee80211_sdata_running(sdata))
2785 ieee80211_csa_finalize(sdata);
2788 mutex_unlock(&local->chanctx_mtx);
2789 mutex_unlock(&local->mtx);
2790 sdata_unlock(sdata);
2793 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2794 struct cfg80211_csa_settings *params,
2797 struct ieee80211_csa_settings csa = {};
2800 switch (sdata->vif.type) {
2801 case NL80211_IFTYPE_AP:
2802 sdata->u.ap.next_beacon =
2803 cfg80211_beacon_dup(¶ms->beacon_after);
2804 if (!sdata->u.ap.next_beacon)
2808 * With a count of 0, we don't have to wait for any
2809 * TBTT before switching, so complete the CSA
2810 * immediately. In theory, with a count == 1 we
2811 * should delay the switch until just before the next
2812 * TBTT, but that would complicate things so we switch
2813 * immediately too. If we would delay the switch
2814 * until the next TBTT, we would have to set the probe
2817 * TODO: A channel switch with count <= 1 without
2818 * sending a CSA action frame is kind of useless,
2819 * because the clients won't know we're changing
2820 * channels. The action frame must be implemented
2821 * either here or in the userspace.
2823 if (params->count <= 1)
2826 if ((params->n_counter_offsets_beacon >
2827 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
2828 (params->n_counter_offsets_presp >
2829 IEEE80211_MAX_CSA_COUNTERS_NUM))
2832 csa.counter_offsets_beacon = params->counter_offsets_beacon;
2833 csa.counter_offsets_presp = params->counter_offsets_presp;
2834 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2835 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2836 csa.count = params->count;
2838 err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa);
2840 kfree(sdata->u.ap.next_beacon);
2846 case NL80211_IFTYPE_ADHOC:
2847 if (!sdata->vif.bss_conf.ibss_joined)
2850 if (params->chandef.width != sdata->u.ibss.chandef.width)
2853 switch (params->chandef.width) {
2854 case NL80211_CHAN_WIDTH_40:
2855 if (cfg80211_get_chandef_type(¶ms->chandef) !=
2856 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
2858 case NL80211_CHAN_WIDTH_5:
2859 case NL80211_CHAN_WIDTH_10:
2860 case NL80211_CHAN_WIDTH_20_NOHT:
2861 case NL80211_CHAN_WIDTH_20:
2867 /* changes into another band are not supported */
2868 if (sdata->u.ibss.chandef.chan->band !=
2869 params->chandef.chan->band)
2872 /* see comments in the NL80211_IFTYPE_AP block */
2873 if (params->count > 1) {
2874 err = ieee80211_ibss_csa_beacon(sdata, params);
2880 ieee80211_send_action_csa(sdata, params);
2883 #ifdef CONFIG_MAC80211_MESH
2884 case NL80211_IFTYPE_MESH_POINT: {
2885 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2887 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
2890 /* changes into another band are not supported */
2891 if (sdata->vif.bss_conf.chandef.chan->band !=
2892 params->chandef.chan->band)
2895 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
2896 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
2897 if (!ifmsh->pre_value)
2898 ifmsh->pre_value = 1;
2903 /* see comments in the NL80211_IFTYPE_AP block */
2904 if (params->count > 1) {
2905 err = ieee80211_mesh_csa_beacon(sdata, params);
2907 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
2913 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
2914 ieee80211_send_action_csa(sdata, params);
2927 __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
2928 struct cfg80211_csa_settings *params)
2930 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2931 struct ieee80211_local *local = sdata->local;
2932 struct ieee80211_channel_switch ch_switch;
2933 struct ieee80211_chanctx_conf *conf;
2934 struct ieee80211_chanctx *chanctx;
2938 sdata_assert_lock(sdata);
2939 lockdep_assert_held(&local->mtx);
2941 if (!list_empty(&local->roc_list) || local->scanning)
2944 if (sdata->wdev.cac_started)
2947 if (cfg80211_chandef_identical(¶ms->chandef,
2948 &sdata->vif.bss_conf.chandef))
2951 /* don't allow another channel switch if one is already active. */
2952 if (sdata->vif.csa_active)
2955 mutex_lock(&local->chanctx_mtx);
2956 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
2957 lockdep_is_held(&local->chanctx_mtx));
2963 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
2969 ch_switch.timestamp = 0;
2970 ch_switch.device_timestamp = 0;
2971 ch_switch.block_tx = params->block_tx;
2972 ch_switch.chandef = params->chandef;
2973 ch_switch.count = params->count;
2975 err = drv_pre_channel_switch(sdata, &ch_switch);
2979 err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef,
2981 params->radar_required);
2985 /* if reservation is invalid then this will fail */
2986 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
2988 ieee80211_vif_unreserve_chanctx(sdata);
2992 err = ieee80211_set_csa_beacon(sdata, params, &changed);
2994 ieee80211_vif_unreserve_chanctx(sdata);
2998 sdata->csa_chandef = params->chandef;
2999 sdata->csa_block_tx = params->block_tx;
3000 sdata->vif.csa_active = true;
3002 if (sdata->csa_block_tx)
3003 ieee80211_stop_vif_queues(local, sdata,
3004 IEEE80211_QUEUE_STOP_REASON_CSA);
3006 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3010 ieee80211_bss_info_change_notify(sdata, changed);
3011 drv_channel_switch_beacon(sdata, ¶ms->chandef);
3013 /* if the beacon didn't change, we can finalize immediately */
3014 ieee80211_csa_finalize(sdata);
3018 mutex_unlock(&local->chanctx_mtx);
3022 int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3023 struct cfg80211_csa_settings *params)
3025 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3026 struct ieee80211_local *local = sdata->local;
3029 mutex_lock(&local->mtx);
3030 err = __ieee80211_channel_switch(wiphy, dev, params);
3031 mutex_unlock(&local->mtx);
3036 u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3038 lockdep_assert_held(&local->mtx);
3040 local->roc_cookie_counter++;
3042 /* wow, you wrapped 64 bits ... more likely a bug */
3043 if (WARN_ON(local->roc_cookie_counter == 0))
3044 local->roc_cookie_counter++;
3046 return local->roc_cookie_counter;
3049 int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3050 u64 *cookie, gfp_t gfp)
3052 unsigned long spin_flags;
3053 struct sk_buff *ack_skb;
3056 ack_skb = skb_copy(skb, gfp);
3060 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3061 id = idr_alloc(&local->ack_status_frames, ack_skb,
3062 1, 0x10000, GFP_ATOMIC);
3063 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3070 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3072 *cookie = ieee80211_mgmt_tx_cookie(local);
3073 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3078 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
3079 struct wireless_dev *wdev,
3080 u16 frame_type, bool reg)
3082 struct ieee80211_local *local = wiphy_priv(wiphy);
3083 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3085 switch (frame_type) {
3086 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3088 local->probe_req_reg++;
3089 sdata->vif.probe_req_reg++;
3091 if (local->probe_req_reg)
3092 local->probe_req_reg--;
3094 if (sdata->vif.probe_req_reg)
3095 sdata->vif.probe_req_reg--;
3098 if (!local->open_count)
3101 if (sdata->vif.probe_req_reg == 1)
3102 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3104 else if (sdata->vif.probe_req_reg == 0)
3105 drv_config_iface_filter(local, sdata, 0,
3108 ieee80211_configure_filter(local);
3115 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3117 struct ieee80211_local *local = wiphy_priv(wiphy);
3122 return drv_set_antenna(local, tx_ant, rx_ant);
3125 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3127 struct ieee80211_local *local = wiphy_priv(wiphy);
3129 return drv_get_antenna(local, tx_ant, rx_ant);
3132 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3133 struct net_device *dev,
3134 struct cfg80211_gtk_rekey_data *data)
3136 struct ieee80211_local *local = wiphy_priv(wiphy);
3137 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3139 if (!local->ops->set_rekey_data)
3142 drv_set_rekey_data(local, sdata, data);
3147 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3148 const u8 *peer, u64 *cookie)
3150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3151 struct ieee80211_local *local = sdata->local;
3152 struct ieee80211_qos_hdr *nullfunc;
3153 struct sk_buff *skb;
3154 int size = sizeof(*nullfunc);
3157 struct ieee80211_tx_info *info;
3158 struct sta_info *sta;
3159 struct ieee80211_chanctx_conf *chanctx_conf;
3160 enum nl80211_band band;
3163 /* the lock is needed to assign the cookie later */
3164 mutex_lock(&local->mtx);
3167 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3168 if (WARN_ON(!chanctx_conf)) {
3172 band = chanctx_conf->def.chan->band;
3173 sta = sta_info_get_bss(sdata, peer);
3182 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3183 IEEE80211_STYPE_QOS_NULLFUNC |
3184 IEEE80211_FCTL_FROMDS);
3187 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3188 IEEE80211_STYPE_NULLFUNC |
3189 IEEE80211_FCTL_FROMDS);
3192 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3200 skb_reserve(skb, local->hw.extra_tx_headroom);
3202 nullfunc = (void *) skb_put(skb, size);
3203 nullfunc->frame_control = fc;
3204 nullfunc->duration_id = 0;
3205 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3206 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3207 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3208 nullfunc->seq_ctrl = 0;
3210 info = IEEE80211_SKB_CB(skb);
3212 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3213 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3216 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3219 nullfunc->qos_ctrl = cpu_to_le16(7);
3221 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3228 ieee80211_xmit(sdata, sta, skb);
3234 mutex_unlock(&local->mtx);
3239 static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3240 struct wireless_dev *wdev,
3241 struct cfg80211_chan_def *chandef)
3243 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3244 struct ieee80211_local *local = wiphy_priv(wiphy);
3245 struct ieee80211_chanctx_conf *chanctx_conf;
3249 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3251 *chandef = sdata->vif.bss_conf.chandef;
3253 } else if (local->open_count > 0 &&
3254 local->open_count == local->monitors &&
3255 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3256 if (local->use_chanctx)
3257 *chandef = local->monitor_chandef;
3259 *chandef = local->_oper_chandef;
3268 static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3270 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3274 static int ieee80211_set_qos_map(struct wiphy *wiphy,
3275 struct net_device *dev,
3276 struct cfg80211_qos_map *qos_map)
3278 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3279 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3282 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3285 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3287 /* A NULL qos_map was passed to disable QoS mapping */
3291 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
3292 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3294 kfree_rcu(old_qos_map, rcu_head);
3299 static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3300 struct net_device *dev,
3301 struct cfg80211_chan_def *chandef)
3303 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3307 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3309 ieee80211_bss_info_change_notify(sdata, changed);
3314 static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3315 u8 tsid, const u8 *peer, u8 up,
3318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3319 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3320 int ac = ieee802_1d_to_ac[up];
3322 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3325 if (!(sdata->wmm_acm & BIT(up)))
3328 if (ifmgd->tx_tspec[ac].admitted_time)
3331 if (admitted_time) {
3332 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3333 ifmgd->tx_tspec[ac].tsid = tsid;
3334 ifmgd->tx_tspec[ac].up = up;
3340 static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3341 u8 tsid, const u8 *peer)
3343 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3344 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3345 struct ieee80211_local *local = wiphy_priv(wiphy);
3348 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3349 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3351 /* skip unused entries */
3352 if (!tx_tspec->admitted_time)
3355 if (tx_tspec->tsid != tsid)
3358 /* due to this new packets will be reassigned to non-ACM ACs */
3361 /* Make sure that all packets have been sent to avoid to
3362 * restore the QoS params on packets that are still on the
3366 ieee80211_flush_queues(local, sdata, false);
3368 /* restore the normal QoS parameters
3369 * (unconditionally to avoid races)
3371 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3372 tx_tspec->downgraded = false;
3373 ieee80211_sta_handle_tspec_ac_params(sdata);
3375 /* finally clear all the data */
3376 memset(tx_tspec, 0, sizeof(*tx_tspec));
3384 const struct cfg80211_ops mac80211_config_ops = {
3385 .add_virtual_intf = ieee80211_add_iface,
3386 .del_virtual_intf = ieee80211_del_iface,
3387 .change_virtual_intf = ieee80211_change_iface,
3388 .start_p2p_device = ieee80211_start_p2p_device,
3389 .stop_p2p_device = ieee80211_stop_p2p_device,
3390 .add_key = ieee80211_add_key,
3391 .del_key = ieee80211_del_key,
3392 .get_key = ieee80211_get_key,
3393 .set_default_key = ieee80211_config_default_key,
3394 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
3395 .start_ap = ieee80211_start_ap,
3396 .change_beacon = ieee80211_change_beacon,
3397 .stop_ap = ieee80211_stop_ap,
3398 .add_station = ieee80211_add_station,
3399 .del_station = ieee80211_del_station,
3400 .change_station = ieee80211_change_station,
3401 .get_station = ieee80211_get_station,
3402 .dump_station = ieee80211_dump_station,
3403 .dump_survey = ieee80211_dump_survey,
3404 #ifdef CONFIG_MAC80211_MESH
3405 .add_mpath = ieee80211_add_mpath,
3406 .del_mpath = ieee80211_del_mpath,
3407 .change_mpath = ieee80211_change_mpath,
3408 .get_mpath = ieee80211_get_mpath,
3409 .dump_mpath = ieee80211_dump_mpath,
3410 .get_mpp = ieee80211_get_mpp,
3411 .dump_mpp = ieee80211_dump_mpp,
3412 .update_mesh_config = ieee80211_update_mesh_config,
3413 .get_mesh_config = ieee80211_get_mesh_config,
3414 .join_mesh = ieee80211_join_mesh,
3415 .leave_mesh = ieee80211_leave_mesh,
3417 .join_ocb = ieee80211_join_ocb,
3418 .leave_ocb = ieee80211_leave_ocb,
3419 .change_bss = ieee80211_change_bss,
3420 .set_txq_params = ieee80211_set_txq_params,
3421 .set_monitor_channel = ieee80211_set_monitor_channel,
3422 .suspend = ieee80211_suspend,
3423 .resume = ieee80211_resume,
3424 .scan = ieee80211_scan,
3425 .abort_scan = ieee80211_abort_scan,
3426 .sched_scan_start = ieee80211_sched_scan_start,
3427 .sched_scan_stop = ieee80211_sched_scan_stop,
3428 .auth = ieee80211_auth,
3429 .assoc = ieee80211_assoc,
3430 .deauth = ieee80211_deauth,
3431 .disassoc = ieee80211_disassoc,
3432 .join_ibss = ieee80211_join_ibss,
3433 .leave_ibss = ieee80211_leave_ibss,
3434 .set_mcast_rate = ieee80211_set_mcast_rate,
3435 .set_wiphy_params = ieee80211_set_wiphy_params,
3436 .set_tx_power = ieee80211_set_tx_power,
3437 .get_tx_power = ieee80211_get_tx_power,
3438 .set_wds_peer = ieee80211_set_wds_peer,
3439 .rfkill_poll = ieee80211_rfkill_poll,
3440 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
3441 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
3442 .set_power_mgmt = ieee80211_set_power_mgmt,
3443 .set_bitrate_mask = ieee80211_set_bitrate_mask,
3444 .remain_on_channel = ieee80211_remain_on_channel,
3445 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
3446 .mgmt_tx = ieee80211_mgmt_tx,
3447 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
3448 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
3449 .mgmt_frame_register = ieee80211_mgmt_frame_register,
3450 .set_antenna = ieee80211_set_antenna,
3451 .get_antenna = ieee80211_get_antenna,
3452 .set_rekey_data = ieee80211_set_rekey_data,
3453 .tdls_oper = ieee80211_tdls_oper,
3454 .tdls_mgmt = ieee80211_tdls_mgmt,
3455 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3456 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
3457 .probe_client = ieee80211_probe_client,
3458 .set_noack_map = ieee80211_set_noack_map,
3460 .set_wakeup = ieee80211_set_wakeup,
3462 .get_channel = ieee80211_cfg_get_channel,
3463 .start_radar_detection = ieee80211_start_radar_detection,
3464 .channel_switch = ieee80211_channel_switch,
3465 .set_qos_map = ieee80211_set_qos_map,
3466 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
3467 .add_tx_ts = ieee80211_add_tx_ts,
3468 .del_tx_ts = ieee80211_del_tx_ts,