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
&&
162 params
&& params
->use_4addr
== 0) {
163 RCU_INIT_POINTER(sdata
->u
.vlan
.sta
, NULL
);
164 ieee80211_check_fast_rx_iface(sdata
);
165 } else if (type
== NL80211_IFTYPE_STATION
&&
166 params
&& params
->use_4addr
>= 0) {
167 sdata
->u
.mgd
.use_4addr
= params
->use_4addr
;
170 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
) {
171 ret
= ieee80211_set_mon_options(sdata
, params
);
179 static int ieee80211_start_p2p_device(struct wiphy
*wiphy
,
180 struct wireless_dev
*wdev
)
182 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
185 mutex_lock(&sdata
->local
->chanctx_mtx
);
186 ret
= ieee80211_check_combinations(sdata
, NULL
, 0, 0);
187 mutex_unlock(&sdata
->local
->chanctx_mtx
);
191 return ieee80211_do_open(wdev
, true);
194 static void ieee80211_stop_p2p_device(struct wiphy
*wiphy
,
195 struct wireless_dev
*wdev
)
197 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev
));
200 static int ieee80211_start_nan(struct wiphy
*wiphy
,
201 struct wireless_dev
*wdev
,
202 struct cfg80211_nan_conf
*conf
)
204 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
207 mutex_lock(&sdata
->local
->chanctx_mtx
);
208 ret
= ieee80211_check_combinations(sdata
, NULL
, 0, 0);
209 mutex_unlock(&sdata
->local
->chanctx_mtx
);
213 ret
= ieee80211_do_open(wdev
, true);
217 ret
= drv_start_nan(sdata
->local
, sdata
, conf
);
219 ieee80211_sdata_stop(sdata
);
221 sdata
->u
.nan
.conf
= *conf
;
226 static void ieee80211_stop_nan(struct wiphy
*wiphy
,
227 struct wireless_dev
*wdev
)
229 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
231 drv_stop_nan(sdata
->local
, sdata
);
232 ieee80211_sdata_stop(sdata
);
235 static int ieee80211_nan_change_conf(struct wiphy
*wiphy
,
236 struct wireless_dev
*wdev
,
237 struct cfg80211_nan_conf
*conf
,
240 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
241 struct cfg80211_nan_conf new_conf
;
244 if (sdata
->vif
.type
!= NL80211_IFTYPE_NAN
)
247 if (!ieee80211_sdata_running(sdata
))
250 new_conf
= sdata
->u
.nan
.conf
;
252 if (changes
& CFG80211_NAN_CONF_CHANGED_PREF
)
253 new_conf
.master_pref
= conf
->master_pref
;
255 if (changes
& CFG80211_NAN_CONF_CHANGED_BANDS
)
256 new_conf
.bands
= conf
->bands
;
258 ret
= drv_nan_change_conf(sdata
->local
, sdata
, &new_conf
, changes
);
260 sdata
->u
.nan
.conf
= new_conf
;
265 static int ieee80211_add_nan_func(struct wiphy
*wiphy
,
266 struct wireless_dev
*wdev
,
267 struct cfg80211_nan_func
*nan_func
)
269 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
272 if (sdata
->vif
.type
!= NL80211_IFTYPE_NAN
)
275 if (!ieee80211_sdata_running(sdata
))
278 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
280 ret
= idr_alloc(&sdata
->u
.nan
.function_inst_ids
,
281 nan_func
, 1, sdata
->local
->hw
.max_nan_de_entries
+ 1,
283 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
288 nan_func
->instance_id
= ret
;
290 WARN_ON(nan_func
->instance_id
== 0);
292 ret
= drv_add_nan_func(sdata
->local
, sdata
, nan_func
);
294 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
295 idr_remove(&sdata
->u
.nan
.function_inst_ids
,
296 nan_func
->instance_id
);
297 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
303 static struct cfg80211_nan_func
*
304 ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data
*sdata
,
307 struct cfg80211_nan_func
*func
;
310 lockdep_assert_held(&sdata
->u
.nan
.func_lock
);
312 idr_for_each_entry(&sdata
->u
.nan
.function_inst_ids
, func
, id
) {
313 if (func
->cookie
== cookie
)
320 static void ieee80211_del_nan_func(struct wiphy
*wiphy
,
321 struct wireless_dev
*wdev
, u64 cookie
)
323 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
324 struct cfg80211_nan_func
*func
;
327 if (sdata
->vif
.type
!= NL80211_IFTYPE_NAN
||
328 !ieee80211_sdata_running(sdata
))
331 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
333 func
= ieee80211_find_nan_func_by_cookie(sdata
, cookie
);
335 instance_id
= func
->instance_id
;
337 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
340 drv_del_nan_func(sdata
->local
, sdata
, instance_id
);
343 static int ieee80211_set_noack_map(struct wiphy
*wiphy
,
344 struct net_device
*dev
,
347 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
349 sdata
->noack_map
= noack_map
;
351 ieee80211_check_fast_xmit_iface(sdata
);
356 static int ieee80211_add_key(struct wiphy
*wiphy
, struct net_device
*dev
,
357 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
358 struct key_params
*params
)
360 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
361 struct ieee80211_local
*local
= sdata
->local
;
362 struct sta_info
*sta
= NULL
;
363 const struct ieee80211_cipher_scheme
*cs
= NULL
;
364 struct ieee80211_key
*key
;
367 if (!ieee80211_sdata_running(sdata
))
370 /* reject WEP and TKIP keys if WEP failed to initialize */
371 switch (params
->cipher
) {
372 case WLAN_CIPHER_SUITE_WEP40
:
373 case WLAN_CIPHER_SUITE_TKIP
:
374 case WLAN_CIPHER_SUITE_WEP104
:
375 if (IS_ERR(local
->wep_tx_tfm
))
378 case WLAN_CIPHER_SUITE_CCMP
:
379 case WLAN_CIPHER_SUITE_CCMP_256
:
380 case WLAN_CIPHER_SUITE_AES_CMAC
:
381 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
382 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
383 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
384 case WLAN_CIPHER_SUITE_GCMP
:
385 case WLAN_CIPHER_SUITE_GCMP_256
:
388 cs
= ieee80211_cs_get(local
, params
->cipher
, sdata
->vif
.type
);
392 key
= ieee80211_key_alloc(params
->cipher
, key_idx
, params
->key_len
,
393 params
->key
, params
->seq_len
, params
->seq
,
399 key
->conf
.flags
|= IEEE80211_KEY_FLAG_PAIRWISE
;
401 mutex_lock(&local
->sta_mtx
);
404 sta
= sta_info_get_bss(sdata
, mac_addr
);
406 * The ASSOC test makes sure the driver is ready to
407 * receive the key. When wpa_supplicant has roamed
408 * using FT, it attempts to set the key before
409 * association has completed, this rejects that attempt
410 * so it will set the key again after association.
412 * TODO: accept the key if we have a station entry and
413 * add it to the device after the station.
415 if (!sta
|| !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
416 ieee80211_key_free_unused(key
);
422 switch (sdata
->vif
.type
) {
423 case NL80211_IFTYPE_STATION
:
424 if (sdata
->u
.mgd
.mfp
!= IEEE80211_MFP_DISABLED
)
425 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
427 case NL80211_IFTYPE_AP
:
428 case NL80211_IFTYPE_AP_VLAN
:
429 /* Keys without a station are used for TX only */
430 if (key
->sta
&& test_sta_flag(key
->sta
, WLAN_STA_MFP
))
431 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
433 case NL80211_IFTYPE_ADHOC
:
436 case NL80211_IFTYPE_MESH_POINT
:
437 #ifdef CONFIG_MAC80211_MESH
438 if (sdata
->u
.mesh
.security
!= IEEE80211_MESH_SEC_NONE
)
439 key
->conf
.flags
|= IEEE80211_KEY_FLAG_RX_MGMT
;
442 case NL80211_IFTYPE_WDS
:
443 case NL80211_IFTYPE_MONITOR
:
444 case NL80211_IFTYPE_P2P_DEVICE
:
445 case NL80211_IFTYPE_NAN
:
446 case NL80211_IFTYPE_UNSPECIFIED
:
447 case NUM_NL80211_IFTYPES
:
448 case NL80211_IFTYPE_P2P_CLIENT
:
449 case NL80211_IFTYPE_P2P_GO
:
450 case NL80211_IFTYPE_OCB
:
451 /* shouldn't happen */
457 sta
->cipher_scheme
= cs
;
459 err
= ieee80211_key_link(key
, sdata
, sta
);
462 mutex_unlock(&local
->sta_mtx
);
467 static int ieee80211_del_key(struct wiphy
*wiphy
, struct net_device
*dev
,
468 u8 key_idx
, bool pairwise
, const u8
*mac_addr
)
470 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
471 struct ieee80211_local
*local
= sdata
->local
;
472 struct sta_info
*sta
;
473 struct ieee80211_key
*key
= NULL
;
476 mutex_lock(&local
->sta_mtx
);
477 mutex_lock(&local
->key_mtx
);
482 sta
= sta_info_get_bss(sdata
, mac_addr
);
487 key
= key_mtx_dereference(local
, sta
->ptk
[key_idx
]);
489 key
= key_mtx_dereference(local
, sta
->gtk
[key_idx
]);
491 key
= key_mtx_dereference(local
, sdata
->keys
[key_idx
]);
498 ieee80211_key_free(key
, sdata
->vif
.type
== NL80211_IFTYPE_STATION
);
502 mutex_unlock(&local
->key_mtx
);
503 mutex_unlock(&local
->sta_mtx
);
508 static int ieee80211_get_key(struct wiphy
*wiphy
, struct net_device
*dev
,
509 u8 key_idx
, bool pairwise
, const u8
*mac_addr
,
511 void (*callback
)(void *cookie
,
512 struct key_params
*params
))
514 struct ieee80211_sub_if_data
*sdata
;
515 struct sta_info
*sta
= NULL
;
517 struct key_params params
;
518 struct ieee80211_key
*key
= NULL
;
523 struct ieee80211_key_seq kseq
= {};
525 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
530 sta
= sta_info_get_bss(sdata
, mac_addr
);
534 if (pairwise
&& key_idx
< NUM_DEFAULT_KEYS
)
535 key
= rcu_dereference(sta
->ptk
[key_idx
]);
536 else if (!pairwise
&&
537 key_idx
< NUM_DEFAULT_KEYS
+ NUM_DEFAULT_MGMT_KEYS
)
538 key
= rcu_dereference(sta
->gtk
[key_idx
]);
540 key
= rcu_dereference(sdata
->keys
[key_idx
]);
545 memset(¶ms
, 0, sizeof(params
));
547 params
.cipher
= key
->conf
.cipher
;
549 switch (key
->conf
.cipher
) {
550 case WLAN_CIPHER_SUITE_TKIP
:
551 pn64
= atomic64_read(&key
->conf
.tx_pn
);
552 iv32
= TKIP_PN_TO_IV32(pn64
);
553 iv16
= TKIP_PN_TO_IV16(pn64
);
555 if (key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
&&
556 !(key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
)) {
557 drv_get_key_seq(sdata
->local
, key
, &kseq
);
558 iv32
= kseq
.tkip
.iv32
;
559 iv16
= kseq
.tkip
.iv16
;
562 seq
[0] = iv16
& 0xff;
563 seq
[1] = (iv16
>> 8) & 0xff;
564 seq
[2] = iv32
& 0xff;
565 seq
[3] = (iv32
>> 8) & 0xff;
566 seq
[4] = (iv32
>> 16) & 0xff;
567 seq
[5] = (iv32
>> 24) & 0xff;
571 case WLAN_CIPHER_SUITE_CCMP
:
572 case WLAN_CIPHER_SUITE_CCMP_256
:
573 case WLAN_CIPHER_SUITE_AES_CMAC
:
574 case WLAN_CIPHER_SUITE_BIP_CMAC_256
:
575 BUILD_BUG_ON(offsetof(typeof(kseq
), ccmp
) !=
576 offsetof(typeof(kseq
), aes_cmac
));
578 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
579 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
580 BUILD_BUG_ON(offsetof(typeof(kseq
), ccmp
) !=
581 offsetof(typeof(kseq
), aes_gmac
));
583 case WLAN_CIPHER_SUITE_GCMP
:
584 case WLAN_CIPHER_SUITE_GCMP_256
:
585 BUILD_BUG_ON(offsetof(typeof(kseq
), ccmp
) !=
586 offsetof(typeof(kseq
), gcmp
));
588 if (key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
&&
589 !(key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
)) {
590 drv_get_key_seq(sdata
->local
, key
, &kseq
);
591 memcpy(seq
, kseq
.ccmp
.pn
, 6);
593 pn64
= atomic64_read(&key
->conf
.tx_pn
);
605 if (!(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
607 if (WARN_ON(key
->conf
.flags
& IEEE80211_KEY_FLAG_GENERATE_IV
))
609 drv_get_key_seq(sdata
->local
, key
, &kseq
);
610 params
.seq
= kseq
.hw
.seq
;
611 params
.seq_len
= kseq
.hw
.seq_len
;
615 params
.key
= key
->conf
.key
;
616 params
.key_len
= key
->conf
.keylen
;
618 callback(cookie
, ¶ms
);
626 static int ieee80211_config_default_key(struct wiphy
*wiphy
,
627 struct net_device
*dev
,
628 u8 key_idx
, bool uni
,
631 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
633 ieee80211_set_default_key(sdata
, key_idx
, uni
, multi
);
638 static int ieee80211_config_default_mgmt_key(struct wiphy
*wiphy
,
639 struct net_device
*dev
,
642 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
644 ieee80211_set_default_mgmt_key(sdata
, key_idx
);
649 void sta_set_rate_info_tx(struct sta_info
*sta
,
650 const struct ieee80211_tx_rate
*rate
,
651 struct rate_info
*rinfo
)
654 if (rate
->flags
& IEEE80211_TX_RC_MCS
) {
655 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
656 rinfo
->mcs
= rate
->idx
;
657 } else if (rate
->flags
& IEEE80211_TX_RC_VHT_MCS
) {
658 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
659 rinfo
->mcs
= ieee80211_rate_get_vht_mcs(rate
);
660 rinfo
->nss
= ieee80211_rate_get_vht_nss(rate
);
662 struct ieee80211_supported_band
*sband
;
663 int shift
= ieee80211_vif_get_shift(&sta
->sdata
->vif
);
666 sband
= ieee80211_get_sband(sta
->sdata
);
668 brate
= sband
->bitrates
[rate
->idx
].bitrate
;
669 rinfo
->legacy
= DIV_ROUND_UP(brate
, 1 << shift
);
672 if (rate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
673 rinfo
->bw
= RATE_INFO_BW_40
;
674 else if (rate
->flags
& IEEE80211_TX_RC_80_MHZ_WIDTH
)
675 rinfo
->bw
= RATE_INFO_BW_80
;
676 else if (rate
->flags
& IEEE80211_TX_RC_160_MHZ_WIDTH
)
677 rinfo
->bw
= RATE_INFO_BW_160
;
679 rinfo
->bw
= RATE_INFO_BW_20
;
680 if (rate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
681 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
684 static int ieee80211_dump_station(struct wiphy
*wiphy
, struct net_device
*dev
,
685 int idx
, u8
*mac
, struct station_info
*sinfo
)
687 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
688 struct ieee80211_local
*local
= sdata
->local
;
689 struct sta_info
*sta
;
692 mutex_lock(&local
->sta_mtx
);
694 sta
= sta_info_get_by_idx(sdata
, idx
);
697 memcpy(mac
, sta
->sta
.addr
, ETH_ALEN
);
698 sta_set_sinfo(sta
, sinfo
, true);
701 mutex_unlock(&local
->sta_mtx
);
706 static int ieee80211_dump_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
707 int idx
, struct survey_info
*survey
)
709 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
711 return drv_get_survey(local
, idx
, survey
);
714 static int ieee80211_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
715 const u8
*mac
, struct station_info
*sinfo
)
717 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
718 struct ieee80211_local
*local
= sdata
->local
;
719 struct sta_info
*sta
;
722 mutex_lock(&local
->sta_mtx
);
724 sta
= sta_info_get_bss(sdata
, mac
);
727 sta_set_sinfo(sta
, sinfo
, true);
730 mutex_unlock(&local
->sta_mtx
);
735 static int ieee80211_set_monitor_channel(struct wiphy
*wiphy
,
736 struct cfg80211_chan_def
*chandef
)
738 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
739 struct ieee80211_sub_if_data
*sdata
;
742 if (cfg80211_chandef_identical(&local
->monitor_chandef
, chandef
))
745 mutex_lock(&local
->mtx
);
746 if (local
->use_chanctx
) {
747 sdata
= rtnl_dereference(local
->monitor_sdata
);
749 ieee80211_vif_release_channel(sdata
);
750 ret
= ieee80211_vif_use_channel(sdata
, chandef
,
751 IEEE80211_CHANCTX_EXCLUSIVE
);
753 } else if (local
->open_count
== local
->monitors
) {
754 local
->_oper_chandef
= *chandef
;
755 ieee80211_hw_config(local
, 0);
759 local
->monitor_chandef
= *chandef
;
760 mutex_unlock(&local
->mtx
);
765 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data
*sdata
,
766 const u8
*resp
, size_t resp_len
,
767 const struct ieee80211_csa_settings
*csa
)
769 struct probe_resp
*new, *old
;
771 if (!resp
|| !resp_len
)
774 old
= sdata_dereference(sdata
->u
.ap
.probe_resp
, sdata
);
776 new = kzalloc(sizeof(struct probe_resp
) + resp_len
, GFP_KERNEL
);
781 memcpy(new->data
, resp
, resp_len
);
784 memcpy(new->csa_counter_offsets
, csa
->counter_offsets_presp
,
785 csa
->n_counter_offsets_presp
*
786 sizeof(new->csa_counter_offsets
[0]));
788 rcu_assign_pointer(sdata
->u
.ap
.probe_resp
, new);
790 kfree_rcu(old
, rcu_head
);
795 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data
*sdata
,
796 struct cfg80211_beacon_data
*params
,
797 const struct ieee80211_csa_settings
*csa
)
799 struct beacon_data
*new, *old
;
800 int new_head_len
, new_tail_len
;
802 u32 changed
= BSS_CHANGED_BEACON
;
804 old
= sdata_dereference(sdata
->u
.ap
.beacon
, sdata
);
807 /* Need to have a beacon head if we don't have one yet */
808 if (!params
->head
&& !old
)
811 /* new or old head? */
813 new_head_len
= params
->head_len
;
815 new_head_len
= old
->head_len
;
817 /* new or old tail? */
818 if (params
->tail
|| !old
)
819 /* params->tail_len will be zero for !params->tail */
820 new_tail_len
= params
->tail_len
;
822 new_tail_len
= old
->tail_len
;
824 size
= sizeof(*new) + new_head_len
+ new_tail_len
;
826 new = kzalloc(size
, GFP_KERNEL
);
830 /* start filling the new info now */
833 * pointers go into the block we allocated,
834 * memory is | beacon_data | head | tail |
836 new->head
= ((u8
*) new) + sizeof(*new);
837 new->tail
= new->head
+ new_head_len
;
838 new->head_len
= new_head_len
;
839 new->tail_len
= new_tail_len
;
842 new->csa_current_counter
= csa
->count
;
843 memcpy(new->csa_counter_offsets
, csa
->counter_offsets_beacon
,
844 csa
->n_counter_offsets_beacon
*
845 sizeof(new->csa_counter_offsets
[0]));
850 memcpy(new->head
, params
->head
, new_head_len
);
852 memcpy(new->head
, old
->head
, new_head_len
);
854 /* copy in optional tail */
856 memcpy(new->tail
, params
->tail
, new_tail_len
);
859 memcpy(new->tail
, old
->tail
, new_tail_len
);
861 err
= ieee80211_set_probe_resp(sdata
, params
->probe_resp
,
862 params
->probe_resp_len
, csa
);
866 changed
|= BSS_CHANGED_AP_PROBE_RESP
;
868 rcu_assign_pointer(sdata
->u
.ap
.beacon
, new);
871 kfree_rcu(old
, rcu_head
);
876 static int ieee80211_start_ap(struct wiphy
*wiphy
, struct net_device
*dev
,
877 struct cfg80211_ap_settings
*params
)
879 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
880 struct ieee80211_local
*local
= sdata
->local
;
881 struct beacon_data
*old
;
882 struct ieee80211_sub_if_data
*vlan
;
883 u32 changed
= BSS_CHANGED_BEACON_INT
|
884 BSS_CHANGED_BEACON_ENABLED
|
891 old
= sdata_dereference(sdata
->u
.ap
.beacon
, sdata
);
895 switch (params
->smps_mode
) {
896 case NL80211_SMPS_OFF
:
897 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
899 case NL80211_SMPS_STATIC
:
900 sdata
->smps_mode
= IEEE80211_SMPS_STATIC
;
902 case NL80211_SMPS_DYNAMIC
:
903 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
908 sdata
->u
.ap
.req_smps
= sdata
->smps_mode
;
910 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
912 sdata
->vif
.bss_conf
.beacon_int
= params
->beacon_interval
;
914 mutex_lock(&local
->mtx
);
915 err
= ieee80211_vif_use_channel(sdata
, ¶ms
->chandef
,
916 IEEE80211_CHANCTX_SHARED
);
918 ieee80211_vif_copy_chanctx_to_vlans(sdata
, false);
919 mutex_unlock(&local
->mtx
);
924 * Apply control port protocol, this allows us to
925 * not encrypt dynamic WEP control frames.
927 sdata
->control_port_protocol
= params
->crypto
.control_port_ethertype
;
928 sdata
->control_port_no_encrypt
= params
->crypto
.control_port_no_encrypt
;
929 sdata
->control_port_over_nl80211
=
930 params
->crypto
.control_port_over_nl80211
;
931 sdata
->encrypt_headroom
= ieee80211_cs_headroom(sdata
->local
,
935 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
) {
936 vlan
->control_port_protocol
=
937 params
->crypto
.control_port_ethertype
;
938 vlan
->control_port_no_encrypt
=
939 params
->crypto
.control_port_no_encrypt
;
940 vlan
->control_port_over_nl80211
=
941 params
->crypto
.control_port_over_nl80211
;
942 vlan
->encrypt_headroom
=
943 ieee80211_cs_headroom(sdata
->local
,
948 sdata
->vif
.bss_conf
.dtim_period
= params
->dtim_period
;
949 sdata
->vif
.bss_conf
.enable_beacon
= true;
950 sdata
->vif
.bss_conf
.allow_p2p_go_ps
= sdata
->vif
.p2p
;
952 sdata
->vif
.bss_conf
.ssid_len
= params
->ssid_len
;
953 if (params
->ssid_len
)
954 memcpy(sdata
->vif
.bss_conf
.ssid
, params
->ssid
,
956 sdata
->vif
.bss_conf
.hidden_ssid
=
957 (params
->hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
);
959 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
960 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
961 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
=
962 params
->p2p_ctwindow
& IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
963 if (params
->p2p_opp_ps
)
964 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
965 IEEE80211_P2P_OPPPS_ENABLE_BIT
;
967 err
= ieee80211_assign_beacon(sdata
, ¶ms
->beacon
, NULL
);
969 ieee80211_vif_release_channel(sdata
);
974 err
= drv_start_ap(sdata
->local
, sdata
);
976 old
= sdata_dereference(sdata
->u
.ap
.beacon
, sdata
);
979 kfree_rcu(old
, rcu_head
);
980 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
981 ieee80211_vif_release_channel(sdata
);
985 ieee80211_recalc_dtim(local
, sdata
);
986 ieee80211_bss_info_change_notify(sdata
, changed
);
988 netif_carrier_on(dev
);
989 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
990 netif_carrier_on(vlan
->dev
);
995 static int ieee80211_change_beacon(struct wiphy
*wiphy
, struct net_device
*dev
,
996 struct cfg80211_beacon_data
*params
)
998 struct ieee80211_sub_if_data
*sdata
;
999 struct beacon_data
*old
;
1002 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1003 sdata_assert_lock(sdata
);
1005 /* don't allow changing the beacon while CSA is in place - offset
1006 * of channel switch counter may change
1008 if (sdata
->vif
.csa_active
)
1011 old
= sdata_dereference(sdata
->u
.ap
.beacon
, sdata
);
1015 err
= ieee80211_assign_beacon(sdata
, params
, NULL
);
1018 ieee80211_bss_info_change_notify(sdata
, err
);
1022 static int ieee80211_stop_ap(struct wiphy
*wiphy
, struct net_device
*dev
)
1024 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1025 struct ieee80211_sub_if_data
*vlan
;
1026 struct ieee80211_local
*local
= sdata
->local
;
1027 struct beacon_data
*old_beacon
;
1028 struct probe_resp
*old_probe_resp
;
1029 struct cfg80211_chan_def chandef
;
1031 sdata_assert_lock(sdata
);
1033 old_beacon
= sdata_dereference(sdata
->u
.ap
.beacon
, sdata
);
1036 old_probe_resp
= sdata_dereference(sdata
->u
.ap
.probe_resp
, sdata
);
1038 /* abort any running channel switch */
1039 mutex_lock(&local
->mtx
);
1040 sdata
->vif
.csa_active
= false;
1041 if (sdata
->csa_block_tx
) {
1042 ieee80211_wake_vif_queues(local
, sdata
,
1043 IEEE80211_QUEUE_STOP_REASON_CSA
);
1044 sdata
->csa_block_tx
= false;
1047 mutex_unlock(&local
->mtx
);
1049 kfree(sdata
->u
.ap
.next_beacon
);
1050 sdata
->u
.ap
.next_beacon
= NULL
;
1052 /* turn off carrier for this interface and dependent VLANs */
1053 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
1054 netif_carrier_off(vlan
->dev
);
1055 netif_carrier_off(dev
);
1057 /* remove beacon and probe response */
1058 RCU_INIT_POINTER(sdata
->u
.ap
.beacon
, NULL
);
1059 RCU_INIT_POINTER(sdata
->u
.ap
.probe_resp
, NULL
);
1060 kfree_rcu(old_beacon
, rcu_head
);
1062 kfree_rcu(old_probe_resp
, rcu_head
);
1063 sdata
->u
.ap
.driver_smps_mode
= IEEE80211_SMPS_OFF
;
1065 __sta_info_flush(sdata
, true);
1066 ieee80211_free_keys(sdata
, true);
1068 sdata
->vif
.bss_conf
.enable_beacon
= false;
1069 sdata
->vif
.bss_conf
.ssid_len
= 0;
1070 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED
, &sdata
->state
);
1071 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BEACON_ENABLED
);
1073 if (sdata
->wdev
.cac_started
) {
1074 chandef
= sdata
->vif
.bss_conf
.chandef
;
1075 cancel_delayed_work_sync(&sdata
->dfs_cac_timer_work
);
1076 cfg80211_cac_event(sdata
->dev
, &chandef
,
1077 NL80211_RADAR_CAC_ABORTED
,
1081 drv_stop_ap(sdata
->local
, sdata
);
1083 /* free all potentially still buffered bcast frames */
1084 local
->total_ps_buffered
-= skb_queue_len(&sdata
->u
.ap
.ps
.bc_buf
);
1085 ieee80211_purge_tx_queue(&local
->hw
, &sdata
->u
.ap
.ps
.bc_buf
);
1087 mutex_lock(&local
->mtx
);
1088 ieee80211_vif_copy_chanctx_to_vlans(sdata
, true);
1089 ieee80211_vif_release_channel(sdata
);
1090 mutex_unlock(&local
->mtx
);
1095 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1096 struct iapp_layer2_update
{
1097 u8 da
[ETH_ALEN
]; /* broadcast */
1098 u8 sa
[ETH_ALEN
]; /* STA addr */
1106 static void ieee80211_send_layer2_update(struct sta_info
*sta
)
1108 struct iapp_layer2_update
*msg
;
1109 struct sk_buff
*skb
;
1111 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1114 skb
= dev_alloc_skb(sizeof(*msg
));
1117 msg
= skb_put(skb
, sizeof(*msg
));
1119 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1120 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1122 eth_broadcast_addr(msg
->da
);
1123 memcpy(msg
->sa
, sta
->sta
.addr
, ETH_ALEN
);
1124 msg
->len
= htons(6);
1126 msg
->ssap
= 0x01; /* NULL LSAP, CR Bit: Response */
1127 msg
->control
= 0xaf; /* XID response lsb.1111F101.
1128 * F=0 (no poll command; unsolicited frame) */
1129 msg
->xid_info
[0] = 0x81; /* XID format identifier */
1130 msg
->xid_info
[1] = 1; /* LLC types/classes: Type 1 LLC */
1131 msg
->xid_info
[2] = 0; /* XID sender's receive window size (RW) */
1133 skb
->dev
= sta
->sdata
->dev
;
1134 skb
->protocol
= eth_type_trans(skb
, sta
->sdata
->dev
);
1135 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1139 static int sta_apply_auth_flags(struct ieee80211_local
*local
,
1140 struct sta_info
*sta
,
1145 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1146 set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1147 !test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1148 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1153 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1154 set
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1155 !test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1157 * When peer becomes associated, init rate control as
1158 * well. Some drivers require rate control initialized
1159 * before drv_sta_state() is called.
1161 if (!test_sta_flag(sta
, WLAN_STA_RATE_CONTROL
))
1162 rate_control_rate_init(sta
);
1164 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1169 if (mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1170 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
1171 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
1172 else if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1173 ret
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
1180 if (mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
) &&
1181 !(set
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) &&
1182 test_sta_flag(sta
, WLAN_STA_ASSOC
)) {
1183 ret
= sta_info_move_state(sta
, IEEE80211_STA_AUTH
);
1188 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
) &&
1189 !(set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) &&
1190 test_sta_flag(sta
, WLAN_STA_AUTH
)) {
1191 ret
= sta_info_move_state(sta
, IEEE80211_STA_NONE
);
1199 static void sta_apply_mesh_params(struct ieee80211_local
*local
,
1200 struct sta_info
*sta
,
1201 struct station_parameters
*params
)
1203 #ifdef CONFIG_MAC80211_MESH
1204 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1207 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
) {
1208 switch (params
->plink_state
) {
1209 case NL80211_PLINK_ESTAB
:
1210 if (sta
->mesh
->plink_state
!= NL80211_PLINK_ESTAB
)
1211 changed
= mesh_plink_inc_estab_count(sdata
);
1212 sta
->mesh
->plink_state
= params
->plink_state
;
1213 sta
->mesh
->aid
= params
->peer_aid
;
1215 ieee80211_mps_sta_status_update(sta
);
1216 changed
|= ieee80211_mps_set_sta_local_pm(sta
,
1217 sdata
->u
.mesh
.mshcfg
.power_mode
);
1219 case NL80211_PLINK_LISTEN
:
1220 case NL80211_PLINK_BLOCKED
:
1221 case NL80211_PLINK_OPN_SNT
:
1222 case NL80211_PLINK_OPN_RCVD
:
1223 case NL80211_PLINK_CNF_RCVD
:
1224 case NL80211_PLINK_HOLDING
:
1225 if (sta
->mesh
->plink_state
== NL80211_PLINK_ESTAB
)
1226 changed
= mesh_plink_dec_estab_count(sdata
);
1227 sta
->mesh
->plink_state
= params
->plink_state
;
1229 ieee80211_mps_sta_status_update(sta
);
1230 changed
|= ieee80211_mps_set_sta_local_pm(sta
,
1231 NL80211_MESH_POWER_UNKNOWN
);
1239 switch (params
->plink_action
) {
1240 case NL80211_PLINK_ACTION_NO_ACTION
:
1243 case NL80211_PLINK_ACTION_OPEN
:
1244 changed
|= mesh_plink_open(sta
);
1246 case NL80211_PLINK_ACTION_BLOCK
:
1247 changed
|= mesh_plink_block(sta
);
1251 if (params
->local_pm
)
1252 changed
|= ieee80211_mps_set_sta_local_pm(sta
,
1255 ieee80211_mbss_info_change_notify(sdata
, changed
);
1259 static int sta_apply_parameters(struct ieee80211_local
*local
,
1260 struct sta_info
*sta
,
1261 struct station_parameters
*params
)
1264 struct ieee80211_supported_band
*sband
;
1265 struct ieee80211_sub_if_data
*sdata
= sta
->sdata
;
1268 sband
= ieee80211_get_sband(sdata
);
1272 mask
= params
->sta_flags_mask
;
1273 set
= params
->sta_flags_set
;
1275 if (ieee80211_vif_is_mesh(&sdata
->vif
)) {
1277 * In mesh mode, ASSOCIATED isn't part of the nl80211
1278 * API but must follow AUTHENTICATED for driver state.
1280 if (mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1281 mask
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1282 if (set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
1283 set
|= BIT(NL80211_STA_FLAG_ASSOCIATED
);
1284 } else if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
1286 * TDLS -- everything follows authorized, but
1287 * only becoming authorized is possible, not
1290 if (set
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1291 set
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
1292 BIT(NL80211_STA_FLAG_ASSOCIATED
);
1293 mask
|= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
1294 BIT(NL80211_STA_FLAG_ASSOCIATED
);
1298 if (mask
& BIT(NL80211_STA_FLAG_WME
) &&
1299 local
->hw
.queues
>= IEEE80211_NUM_ACS
)
1300 sta
->sta
.wme
= set
& BIT(NL80211_STA_FLAG_WME
);
1302 /* auth flags will be set later for TDLS,
1303 * and for unassociated stations that move to assocaited */
1304 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) &&
1305 !((mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) &&
1306 (set
& BIT(NL80211_STA_FLAG_ASSOCIATED
)))) {
1307 ret
= sta_apply_auth_flags(local
, sta
, mask
, set
);
1312 if (mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
1313 if (set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
1314 set_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1316 clear_sta_flag(sta
, WLAN_STA_SHORT_PREAMBLE
);
1319 if (mask
& BIT(NL80211_STA_FLAG_MFP
)) {
1320 sta
->sta
.mfp
= !!(set
& BIT(NL80211_STA_FLAG_MFP
));
1321 if (set
& BIT(NL80211_STA_FLAG_MFP
))
1322 set_sta_flag(sta
, WLAN_STA_MFP
);
1324 clear_sta_flag(sta
, WLAN_STA_MFP
);
1327 if (mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
1328 if (set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
1329 set_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1331 clear_sta_flag(sta
, WLAN_STA_TDLS_PEER
);
1334 /* mark TDLS channel switch support, if the AP allows it */
1335 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) &&
1336 !sdata
->u
.mgd
.tdls_chan_switch_prohibited
&&
1337 params
->ext_capab_len
>= 4 &&
1338 params
->ext_capab
[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH
)
1339 set_sta_flag(sta
, WLAN_STA_TDLS_CHAN_SWITCH
);
1341 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) &&
1342 !sdata
->u
.mgd
.tdls_wider_bw_prohibited
&&
1343 ieee80211_hw_check(&local
->hw
, TDLS_WIDER_BW
) &&
1344 params
->ext_capab_len
>= 8 &&
1345 params
->ext_capab
[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED
)
1346 set_sta_flag(sta
, WLAN_STA_TDLS_WIDER_BW
);
1348 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
) {
1349 sta
->sta
.uapsd_queues
= params
->uapsd_queues
;
1350 sta
->sta
.max_sp
= params
->max_sp
;
1353 /* The sender might not have sent the last bit, consider it to be 0 */
1354 if (params
->ext_capab_len
>= 8) {
1355 u8 val
= (params
->ext_capab
[7] &
1356 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB
) >> 7;
1358 /* we did get all the bits, take the MSB as well */
1359 if (params
->ext_capab_len
>= 9) {
1360 u8 val_msb
= params
->ext_capab
[8] &
1361 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB
;
1368 sta
->sta
.max_amsdu_subframes
= 32;
1371 sta
->sta
.max_amsdu_subframes
= 16;
1374 sta
->sta
.max_amsdu_subframes
= 8;
1377 sta
->sta
.max_amsdu_subframes
= 0;
1382 * cfg80211 validates this (1-2007) and allows setting the AID
1383 * only when creating a new station entry
1386 sta
->sta
.aid
= params
->aid
;
1389 * Some of the following updates would be racy if called on an
1390 * existing station, via ieee80211_change_station(). However,
1391 * all such changes are rejected by cfg80211 except for updates
1392 * changing the supported rates on an existing but not yet used
1396 if (params
->listen_interval
>= 0)
1397 sta
->listen_interval
= params
->listen_interval
;
1399 if (params
->supported_rates
) {
1400 ieee80211_parse_bitrates(&sdata
->vif
.bss_conf
.chandef
,
1401 sband
, params
->supported_rates
,
1402 params
->supported_rates_len
,
1403 &sta
->sta
.supp_rates
[sband
->band
]);
1406 if (params
->ht_capa
)
1407 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
1408 params
->ht_capa
, sta
);
1410 /* VHT can override some HT caps such as the A-MSDU max length */
1411 if (params
->vht_capa
)
1412 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
1413 params
->vht_capa
, sta
);
1415 if (params
->he_capa
)
1416 ieee80211_he_cap_ie_to_sta_he_cap(sdata
, sband
,
1417 (void *)params
->he_capa
,
1418 params
->he_capa_len
, sta
);
1420 if (params
->opmode_notif_used
) {
1421 /* returned value is only needed for rc update, but the
1422 * rc isn't initialized here yet, so ignore it
1424 __ieee80211_vht_handle_opmode(sdata
, sta
, params
->opmode_notif
,
1428 if (params
->support_p2p_ps
>= 0)
1429 sta
->sta
.support_p2p_ps
= params
->support_p2p_ps
;
1431 if (ieee80211_vif_is_mesh(&sdata
->vif
))
1432 sta_apply_mesh_params(local
, sta
, params
);
1434 /* set the STA state after all sta info from usermode has been set */
1435 if (test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) ||
1436 set
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
1437 ret
= sta_apply_auth_flags(local
, sta
, mask
, set
);
1445 static int ieee80211_add_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1447 struct station_parameters
*params
)
1449 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1450 struct sta_info
*sta
;
1451 struct ieee80211_sub_if_data
*sdata
;
1456 sdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1458 if (sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
&&
1459 sdata
->vif
.type
!= NL80211_IFTYPE_AP
)
1462 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1464 if (ether_addr_equal(mac
, sdata
->vif
.addr
))
1467 if (is_multicast_ether_addr(mac
))
1470 sta
= sta_info_alloc(sdata
, mac
, GFP_KERNEL
);
1474 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
1475 sta
->sta
.tdls
= true;
1477 err
= sta_apply_parameters(local
, sta
, params
);
1479 sta_info_free(local
, sta
);
1484 * for TDLS and for unassociated station, rate control should be
1485 * initialized only when rates are known and station is marked
1486 * authorized/associated
1488 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
) &&
1489 test_sta_flag(sta
, WLAN_STA_ASSOC
))
1490 rate_control_rate_init(sta
);
1492 layer2_update
= sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
||
1493 sdata
->vif
.type
== NL80211_IFTYPE_AP
;
1495 err
= sta_info_insert_rcu(sta
);
1502 ieee80211_send_layer2_update(sta
);
1509 static int ieee80211_del_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1510 struct station_del_parameters
*params
)
1512 struct ieee80211_sub_if_data
*sdata
;
1514 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1517 return sta_info_destroy_addr_bss(sdata
, params
->mac
);
1519 sta_info_flush(sdata
);
1523 static int ieee80211_change_station(struct wiphy
*wiphy
,
1524 struct net_device
*dev
, const u8
*mac
,
1525 struct station_parameters
*params
)
1527 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1528 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
1529 struct sta_info
*sta
;
1530 struct ieee80211_sub_if_data
*vlansdata
;
1531 enum cfg80211_station_type statype
;
1534 mutex_lock(&local
->sta_mtx
);
1536 sta
= sta_info_get_bss(sdata
, mac
);
1542 switch (sdata
->vif
.type
) {
1543 case NL80211_IFTYPE_MESH_POINT
:
1544 if (sdata
->u
.mesh
.user_mpm
)
1545 statype
= CFG80211_STA_MESH_PEER_USER
;
1547 statype
= CFG80211_STA_MESH_PEER_KERNEL
;
1549 case NL80211_IFTYPE_ADHOC
:
1550 statype
= CFG80211_STA_IBSS
;
1552 case NL80211_IFTYPE_STATION
:
1553 if (!test_sta_flag(sta
, WLAN_STA_TDLS_PEER
)) {
1554 statype
= CFG80211_STA_AP_STA
;
1557 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1558 statype
= CFG80211_STA_TDLS_PEER_ACTIVE
;
1560 statype
= CFG80211_STA_TDLS_PEER_SETUP
;
1562 case NL80211_IFTYPE_AP
:
1563 case NL80211_IFTYPE_AP_VLAN
:
1564 if (test_sta_flag(sta
, WLAN_STA_ASSOC
))
1565 statype
= CFG80211_STA_AP_CLIENT
;
1567 statype
= CFG80211_STA_AP_CLIENT_UNASSOC
;
1574 err
= cfg80211_check_station_change(wiphy
, params
, statype
);
1578 if (params
->vlan
&& params
->vlan
!= sta
->sdata
->dev
) {
1579 vlansdata
= IEEE80211_DEV_TO_SUB_IF(params
->vlan
);
1581 if (params
->vlan
->ieee80211_ptr
->use_4addr
) {
1582 if (vlansdata
->u
.vlan
.sta
) {
1587 rcu_assign_pointer(vlansdata
->u
.vlan
.sta
, sta
);
1588 __ieee80211_check_fast_rx_iface(vlansdata
);
1591 if (sta
->sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
&&
1592 sta
->sdata
->u
.vlan
.sta
)
1593 RCU_INIT_POINTER(sta
->sdata
->u
.vlan
.sta
, NULL
);
1595 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1596 ieee80211_vif_dec_num_mcast(sta
->sdata
);
1598 sta
->sdata
= vlansdata
;
1599 ieee80211_check_fast_xmit(sta
);
1601 if (test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
1602 ieee80211_vif_inc_num_mcast(sta
->sdata
);
1604 ieee80211_send_layer2_update(sta
);
1607 err
= sta_apply_parameters(local
, sta
, params
);
1611 mutex_unlock(&local
->sta_mtx
);
1613 if ((sdata
->vif
.type
== NL80211_IFTYPE_AP
||
1614 sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
) &&
1615 sta
->known_smps_mode
!= sta
->sdata
->bss
->req_smps
&&
1616 test_sta_flag(sta
, WLAN_STA_AUTHORIZED
) &&
1617 sta_info_tx_streams(sta
) != 1) {
1619 "%pM just authorized and MIMO capable - update SMPS\n",
1621 ieee80211_send_smps_action(sta
->sdata
,
1622 sta
->sdata
->bss
->req_smps
,
1624 sta
->sdata
->vif
.bss_conf
.bssid
);
1627 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
1628 params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
1629 ieee80211_recalc_ps(local
);
1630 ieee80211_recalc_ps_vif(sdata
);
1635 mutex_unlock(&local
->sta_mtx
);
1639 #ifdef CONFIG_MAC80211_MESH
1640 static int ieee80211_add_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1641 const u8
*dst
, const u8
*next_hop
)
1643 struct ieee80211_sub_if_data
*sdata
;
1644 struct mesh_path
*mpath
;
1645 struct sta_info
*sta
;
1647 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1650 sta
= sta_info_get(sdata
, next_hop
);
1656 mpath
= mesh_path_add(sdata
, dst
);
1657 if (IS_ERR(mpath
)) {
1659 return PTR_ERR(mpath
);
1662 mesh_path_fix_nexthop(mpath
, sta
);
1668 static int ieee80211_del_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1671 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1674 return mesh_path_del(sdata
, dst
);
1676 mesh_path_flush_by_iface(sdata
);
1680 static int ieee80211_change_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1681 const u8
*dst
, const u8
*next_hop
)
1683 struct ieee80211_sub_if_data
*sdata
;
1684 struct mesh_path
*mpath
;
1685 struct sta_info
*sta
;
1687 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1691 sta
= sta_info_get(sdata
, next_hop
);
1697 mpath
= mesh_path_lookup(sdata
, dst
);
1703 mesh_path_fix_nexthop(mpath
, sta
);
1709 static void mpath_set_pinfo(struct mesh_path
*mpath
, u8
*next_hop
,
1710 struct mpath_info
*pinfo
)
1712 struct sta_info
*next_hop_sta
= rcu_dereference(mpath
->next_hop
);
1715 memcpy(next_hop
, next_hop_sta
->sta
.addr
, ETH_ALEN
);
1717 eth_zero_addr(next_hop
);
1719 memset(pinfo
, 0, sizeof(*pinfo
));
1721 pinfo
->generation
= mpath
->sdata
->u
.mesh
.mesh_paths_generation
;
1723 pinfo
->filled
= MPATH_INFO_FRAME_QLEN
|
1726 MPATH_INFO_EXPTIME
|
1727 MPATH_INFO_DISCOVERY_TIMEOUT
|
1728 MPATH_INFO_DISCOVERY_RETRIES
|
1731 pinfo
->frame_qlen
= mpath
->frame_queue
.qlen
;
1732 pinfo
->sn
= mpath
->sn
;
1733 pinfo
->metric
= mpath
->metric
;
1734 if (time_before(jiffies
, mpath
->exp_time
))
1735 pinfo
->exptime
= jiffies_to_msecs(mpath
->exp_time
- jiffies
);
1736 pinfo
->discovery_timeout
=
1737 jiffies_to_msecs(mpath
->discovery_timeout
);
1738 pinfo
->discovery_retries
= mpath
->discovery_retries
;
1739 if (mpath
->flags
& MESH_PATH_ACTIVE
)
1740 pinfo
->flags
|= NL80211_MPATH_FLAG_ACTIVE
;
1741 if (mpath
->flags
& MESH_PATH_RESOLVING
)
1742 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVING
;
1743 if (mpath
->flags
& MESH_PATH_SN_VALID
)
1744 pinfo
->flags
|= NL80211_MPATH_FLAG_SN_VALID
;
1745 if (mpath
->flags
& MESH_PATH_FIXED
)
1746 pinfo
->flags
|= NL80211_MPATH_FLAG_FIXED
;
1747 if (mpath
->flags
& MESH_PATH_RESOLVED
)
1748 pinfo
->flags
|= NL80211_MPATH_FLAG_RESOLVED
;
1751 static int ieee80211_get_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1752 u8
*dst
, u8
*next_hop
, struct mpath_info
*pinfo
)
1755 struct ieee80211_sub_if_data
*sdata
;
1756 struct mesh_path
*mpath
;
1758 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1761 mpath
= mesh_path_lookup(sdata
, dst
);
1766 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1767 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1772 static int ieee80211_dump_mpath(struct wiphy
*wiphy
, struct net_device
*dev
,
1773 int idx
, u8
*dst
, u8
*next_hop
,
1774 struct mpath_info
*pinfo
)
1776 struct ieee80211_sub_if_data
*sdata
;
1777 struct mesh_path
*mpath
;
1779 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1782 mpath
= mesh_path_lookup_by_idx(sdata
, idx
);
1787 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1788 mpath_set_pinfo(mpath
, next_hop
, pinfo
);
1793 static void mpp_set_pinfo(struct mesh_path
*mpath
, u8
*mpp
,
1794 struct mpath_info
*pinfo
)
1796 memset(pinfo
, 0, sizeof(*pinfo
));
1797 memcpy(mpp
, mpath
->mpp
, ETH_ALEN
);
1799 pinfo
->generation
= mpath
->sdata
->u
.mesh
.mpp_paths_generation
;
1802 static int ieee80211_get_mpp(struct wiphy
*wiphy
, struct net_device
*dev
,
1803 u8
*dst
, u8
*mpp
, struct mpath_info
*pinfo
)
1806 struct ieee80211_sub_if_data
*sdata
;
1807 struct mesh_path
*mpath
;
1809 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1812 mpath
= mpp_path_lookup(sdata
, dst
);
1817 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1818 mpp_set_pinfo(mpath
, mpp
, pinfo
);
1823 static int ieee80211_dump_mpp(struct wiphy
*wiphy
, struct net_device
*dev
,
1824 int idx
, u8
*dst
, u8
*mpp
,
1825 struct mpath_info
*pinfo
)
1827 struct ieee80211_sub_if_data
*sdata
;
1828 struct mesh_path
*mpath
;
1830 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1833 mpath
= mpp_path_lookup_by_idx(sdata
, idx
);
1838 memcpy(dst
, mpath
->dst
, ETH_ALEN
);
1839 mpp_set_pinfo(mpath
, mpp
, pinfo
);
1844 static int ieee80211_get_mesh_config(struct wiphy
*wiphy
,
1845 struct net_device
*dev
,
1846 struct mesh_config
*conf
)
1848 struct ieee80211_sub_if_data
*sdata
;
1849 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1851 memcpy(conf
, &(sdata
->u
.mesh
.mshcfg
), sizeof(struct mesh_config
));
1855 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm
, u32 mask
)
1857 return (mask
>> (parm
-1)) & 0x1;
1860 static int copy_mesh_setup(struct ieee80211_if_mesh
*ifmsh
,
1861 const struct mesh_setup
*setup
)
1865 struct ieee80211_sub_if_data
*sdata
= container_of(ifmsh
,
1866 struct ieee80211_sub_if_data
, u
.mesh
);
1868 /* allocate information elements */
1872 if (setup
->ie_len
) {
1873 new_ie
= kmemdup(setup
->ie
, setup
->ie_len
,
1878 ifmsh
->ie_len
= setup
->ie_len
;
1882 /* now copy the rest of the setup parameters */
1883 ifmsh
->mesh_id_len
= setup
->mesh_id_len
;
1884 memcpy(ifmsh
->mesh_id
, setup
->mesh_id
, ifmsh
->mesh_id_len
);
1885 ifmsh
->mesh_sp_id
= setup
->sync_method
;
1886 ifmsh
->mesh_pp_id
= setup
->path_sel_proto
;
1887 ifmsh
->mesh_pm_id
= setup
->path_metric
;
1888 ifmsh
->user_mpm
= setup
->user_mpm
;
1889 ifmsh
->mesh_auth_id
= setup
->auth_id
;
1890 ifmsh
->security
= IEEE80211_MESH_SEC_NONE
;
1891 ifmsh
->userspace_handles_dfs
= setup
->userspace_handles_dfs
;
1892 if (setup
->is_authenticated
)
1893 ifmsh
->security
|= IEEE80211_MESH_SEC_AUTHED
;
1894 if (setup
->is_secure
)
1895 ifmsh
->security
|= IEEE80211_MESH_SEC_SECURED
;
1897 /* mcast rate setting in Mesh Node */
1898 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, setup
->mcast_rate
,
1899 sizeof(setup
->mcast_rate
));
1900 sdata
->vif
.bss_conf
.basic_rates
= setup
->basic_rates
;
1902 sdata
->vif
.bss_conf
.beacon_int
= setup
->beacon_interval
;
1903 sdata
->vif
.bss_conf
.dtim_period
= setup
->dtim_period
;
1908 static int ieee80211_update_mesh_config(struct wiphy
*wiphy
,
1909 struct net_device
*dev
, u32 mask
,
1910 const struct mesh_config
*nconf
)
1912 struct mesh_config
*conf
;
1913 struct ieee80211_sub_if_data
*sdata
;
1914 struct ieee80211_if_mesh
*ifmsh
;
1916 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1917 ifmsh
= &sdata
->u
.mesh
;
1919 /* Set the config options which we are interested in setting */
1920 conf
= &(sdata
->u
.mesh
.mshcfg
);
1921 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT
, mask
))
1922 conf
->dot11MeshRetryTimeout
= nconf
->dot11MeshRetryTimeout
;
1923 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT
, mask
))
1924 conf
->dot11MeshConfirmTimeout
= nconf
->dot11MeshConfirmTimeout
;
1925 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT
, mask
))
1926 conf
->dot11MeshHoldingTimeout
= nconf
->dot11MeshHoldingTimeout
;
1927 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS
, mask
))
1928 conf
->dot11MeshMaxPeerLinks
= nconf
->dot11MeshMaxPeerLinks
;
1929 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES
, mask
))
1930 conf
->dot11MeshMaxRetries
= nconf
->dot11MeshMaxRetries
;
1931 if (_chg_mesh_attr(NL80211_MESHCONF_TTL
, mask
))
1932 conf
->dot11MeshTTL
= nconf
->dot11MeshTTL
;
1933 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL
, mask
))
1934 conf
->element_ttl
= nconf
->element_ttl
;
1935 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS
, mask
)) {
1936 if (ifmsh
->user_mpm
)
1938 conf
->auto_open_plinks
= nconf
->auto_open_plinks
;
1940 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
, mask
))
1941 conf
->dot11MeshNbrOffsetMaxNeighbor
=
1942 nconf
->dot11MeshNbrOffsetMaxNeighbor
;
1943 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
, mask
))
1944 conf
->dot11MeshHWMPmaxPREQretries
=
1945 nconf
->dot11MeshHWMPmaxPREQretries
;
1946 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME
, mask
))
1947 conf
->path_refresh_time
= nconf
->path_refresh_time
;
1948 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
, mask
))
1949 conf
->min_discovery_timeout
= nconf
->min_discovery_timeout
;
1950 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
, mask
))
1951 conf
->dot11MeshHWMPactivePathTimeout
=
1952 nconf
->dot11MeshHWMPactivePathTimeout
;
1953 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
, mask
))
1954 conf
->dot11MeshHWMPpreqMinInterval
=
1955 nconf
->dot11MeshHWMPpreqMinInterval
;
1956 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
, mask
))
1957 conf
->dot11MeshHWMPperrMinInterval
=
1958 nconf
->dot11MeshHWMPperrMinInterval
;
1959 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
1961 conf
->dot11MeshHWMPnetDiameterTraversalTime
=
1962 nconf
->dot11MeshHWMPnetDiameterTraversalTime
;
1963 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE
, mask
)) {
1964 conf
->dot11MeshHWMPRootMode
= nconf
->dot11MeshHWMPRootMode
;
1965 ieee80211_mesh_root_setup(ifmsh
);
1967 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS
, mask
)) {
1968 /* our current gate announcement implementation rides on root
1969 * announcements, so require this ifmsh to also be a root node
1971 if (nconf
->dot11MeshGateAnnouncementProtocol
&&
1972 !(conf
->dot11MeshHWMPRootMode
> IEEE80211_ROOTMODE_ROOT
)) {
1973 conf
->dot11MeshHWMPRootMode
= IEEE80211_PROACTIVE_RANN
;
1974 ieee80211_mesh_root_setup(ifmsh
);
1976 conf
->dot11MeshGateAnnouncementProtocol
=
1977 nconf
->dot11MeshGateAnnouncementProtocol
;
1979 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL
, mask
))
1980 conf
->dot11MeshHWMPRannInterval
=
1981 nconf
->dot11MeshHWMPRannInterval
;
1982 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING
, mask
))
1983 conf
->dot11MeshForwarding
= nconf
->dot11MeshForwarding
;
1984 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD
, mask
)) {
1985 /* our RSSI threshold implementation is supported only for
1986 * devices that report signal in dBm.
1988 if (!ieee80211_hw_check(&sdata
->local
->hw
, SIGNAL_DBM
))
1990 conf
->rssi_threshold
= nconf
->rssi_threshold
;
1992 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE
, mask
)) {
1993 conf
->ht_opmode
= nconf
->ht_opmode
;
1994 sdata
->vif
.bss_conf
.ht_operation_mode
= nconf
->ht_opmode
;
1995 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_HT
);
1997 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
, mask
))
1998 conf
->dot11MeshHWMPactivePathToRootTimeout
=
1999 nconf
->dot11MeshHWMPactivePathToRootTimeout
;
2000 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL
, mask
))
2001 conf
->dot11MeshHWMProotInterval
=
2002 nconf
->dot11MeshHWMProotInterval
;
2003 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
, mask
))
2004 conf
->dot11MeshHWMPconfirmationInterval
=
2005 nconf
->dot11MeshHWMPconfirmationInterval
;
2006 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE
, mask
)) {
2007 conf
->power_mode
= nconf
->power_mode
;
2008 ieee80211_mps_local_status_update(sdata
);
2010 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW
, mask
))
2011 conf
->dot11MeshAwakeWindowDuration
=
2012 nconf
->dot11MeshAwakeWindowDuration
;
2013 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT
, mask
))
2014 conf
->plink_timeout
= nconf
->plink_timeout
;
2015 ieee80211_mbss_info_change_notify(sdata
, BSS_CHANGED_BEACON
);
2019 static int ieee80211_join_mesh(struct wiphy
*wiphy
, struct net_device
*dev
,
2020 const struct mesh_config
*conf
,
2021 const struct mesh_setup
*setup
)
2023 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2024 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
2027 memcpy(&ifmsh
->mshcfg
, conf
, sizeof(struct mesh_config
));
2028 err
= copy_mesh_setup(ifmsh
, setup
);
2032 sdata
->control_port_over_nl80211
= setup
->control_port_over_nl80211
;
2034 /* can mesh use other SMPS modes? */
2035 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
2036 sdata
->needed_rx_chains
= sdata
->local
->rx_chains
;
2038 mutex_lock(&sdata
->local
->mtx
);
2039 err
= ieee80211_vif_use_channel(sdata
, &setup
->chandef
,
2040 IEEE80211_CHANCTX_SHARED
);
2041 mutex_unlock(&sdata
->local
->mtx
);
2045 return ieee80211_start_mesh(sdata
);
2048 static int ieee80211_leave_mesh(struct wiphy
*wiphy
, struct net_device
*dev
)
2050 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2052 ieee80211_stop_mesh(sdata
);
2053 mutex_lock(&sdata
->local
->mtx
);
2054 ieee80211_vif_release_channel(sdata
);
2055 mutex_unlock(&sdata
->local
->mtx
);
2061 static int ieee80211_change_bss(struct wiphy
*wiphy
,
2062 struct net_device
*dev
,
2063 struct bss_parameters
*params
)
2065 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2066 struct ieee80211_supported_band
*sband
;
2069 if (!sdata_dereference(sdata
->u
.ap
.beacon
, sdata
))
2072 sband
= ieee80211_get_sband(sdata
);
2076 if (params
->use_cts_prot
>= 0) {
2077 sdata
->vif
.bss_conf
.use_cts_prot
= params
->use_cts_prot
;
2078 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
2080 if (params
->use_short_preamble
>= 0) {
2081 sdata
->vif
.bss_conf
.use_short_preamble
=
2082 params
->use_short_preamble
;
2083 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
2086 if (!sdata
->vif
.bss_conf
.use_short_slot
&&
2087 sband
->band
== NL80211_BAND_5GHZ
) {
2088 sdata
->vif
.bss_conf
.use_short_slot
= true;
2089 changed
|= BSS_CHANGED_ERP_SLOT
;
2092 if (params
->use_short_slot_time
>= 0) {
2093 sdata
->vif
.bss_conf
.use_short_slot
=
2094 params
->use_short_slot_time
;
2095 changed
|= BSS_CHANGED_ERP_SLOT
;
2098 if (params
->basic_rates
) {
2099 ieee80211_parse_bitrates(&sdata
->vif
.bss_conf
.chandef
,
2100 wiphy
->bands
[sband
->band
],
2101 params
->basic_rates
,
2102 params
->basic_rates_len
,
2103 &sdata
->vif
.bss_conf
.basic_rates
);
2104 changed
|= BSS_CHANGED_BASIC_RATES
;
2105 ieee80211_check_rate_mask(sdata
);
2108 if (params
->ap_isolate
>= 0) {
2109 if (params
->ap_isolate
)
2110 sdata
->flags
|= IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
2112 sdata
->flags
&= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS
;
2113 ieee80211_check_fast_rx_iface(sdata
);
2116 if (params
->ht_opmode
>= 0) {
2117 sdata
->vif
.bss_conf
.ht_operation_mode
=
2118 (u16
) params
->ht_opmode
;
2119 changed
|= BSS_CHANGED_HT
;
2122 if (params
->p2p_ctwindow
>= 0) {
2123 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
&=
2124 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
2125 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
2126 params
->p2p_ctwindow
& IEEE80211_P2P_OPPPS_CTWINDOW_MASK
;
2127 changed
|= BSS_CHANGED_P2P_PS
;
2130 if (params
->p2p_opp_ps
> 0) {
2131 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
|=
2132 IEEE80211_P2P_OPPPS_ENABLE_BIT
;
2133 changed
|= BSS_CHANGED_P2P_PS
;
2134 } else if (params
->p2p_opp_ps
== 0) {
2135 sdata
->vif
.bss_conf
.p2p_noa_attr
.oppps_ctwindow
&=
2136 ~IEEE80211_P2P_OPPPS_ENABLE_BIT
;
2137 changed
|= BSS_CHANGED_P2P_PS
;
2140 ieee80211_bss_info_change_notify(sdata
, changed
);
2145 static int ieee80211_set_txq_params(struct wiphy
*wiphy
,
2146 struct net_device
*dev
,
2147 struct ieee80211_txq_params
*params
)
2149 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2150 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2151 struct ieee80211_tx_queue_params p
;
2153 if (!local
->ops
->conf_tx
)
2156 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
2159 memset(&p
, 0, sizeof(p
));
2160 p
.aifs
= params
->aifs
;
2161 p
.cw_max
= params
->cwmax
;
2162 p
.cw_min
= params
->cwmin
;
2163 p
.txop
= params
->txop
;
2166 * Setting tx queue params disables u-apsd because it's only
2167 * called in master mode.
2171 ieee80211_regulatory_limit_wmm_params(sdata
, &p
, params
->ac
);
2173 sdata
->tx_conf
[params
->ac
] = p
;
2174 if (drv_conf_tx(local
, sdata
, params
->ac
, &p
)) {
2175 wiphy_debug(local
->hw
.wiphy
,
2176 "failed to set TX queue parameters for AC %d\n",
2181 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
2187 static int ieee80211_suspend(struct wiphy
*wiphy
,
2188 struct cfg80211_wowlan
*wowlan
)
2190 return __ieee80211_suspend(wiphy_priv(wiphy
), wowlan
);
2193 static int ieee80211_resume(struct wiphy
*wiphy
)
2195 return __ieee80211_resume(wiphy_priv(wiphy
));
2198 #define ieee80211_suspend NULL
2199 #define ieee80211_resume NULL
2202 static int ieee80211_scan(struct wiphy
*wiphy
,
2203 struct cfg80211_scan_request
*req
)
2205 struct ieee80211_sub_if_data
*sdata
;
2207 sdata
= IEEE80211_WDEV_TO_SUB_IF(req
->wdev
);
2209 switch (ieee80211_vif_type_p2p(&sdata
->vif
)) {
2210 case NL80211_IFTYPE_STATION
:
2211 case NL80211_IFTYPE_ADHOC
:
2212 case NL80211_IFTYPE_MESH_POINT
:
2213 case NL80211_IFTYPE_P2P_CLIENT
:
2214 case NL80211_IFTYPE_P2P_DEVICE
:
2216 case NL80211_IFTYPE_P2P_GO
:
2217 if (sdata
->local
->ops
->hw_scan
)
2220 * FIXME: implement NoA while scanning in software,
2221 * for now fall through to allow scanning only when
2222 * beaconing hasn't been configured yet
2225 case NL80211_IFTYPE_AP
:
2227 * If the scan has been forced (and the driver supports
2228 * forcing), don't care about being beaconing already.
2229 * This will create problems to the attached stations (e.g. all
2230 * the frames sent while scanning on other channel will be
2233 if (sdata
->u
.ap
.beacon
&&
2234 (!(wiphy
->features
& NL80211_FEATURE_AP_SCAN
) ||
2235 !(req
->flags
& NL80211_SCAN_FLAG_AP
)))
2238 case NL80211_IFTYPE_NAN
:
2243 return ieee80211_request_scan(sdata
, req
);
2246 static void ieee80211_abort_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
2248 ieee80211_scan_cancel(wiphy_priv(wiphy
));
2252 ieee80211_sched_scan_start(struct wiphy
*wiphy
,
2253 struct net_device
*dev
,
2254 struct cfg80211_sched_scan_request
*req
)
2256 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2258 if (!sdata
->local
->ops
->sched_scan_start
)
2261 return ieee80211_request_sched_scan_start(sdata
, req
);
2265 ieee80211_sched_scan_stop(struct wiphy
*wiphy
, struct net_device
*dev
,
2268 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2270 if (!local
->ops
->sched_scan_stop
)
2273 return ieee80211_request_sched_scan_stop(local
);
2276 static int ieee80211_auth(struct wiphy
*wiphy
, struct net_device
*dev
,
2277 struct cfg80211_auth_request
*req
)
2279 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2282 static int ieee80211_assoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2283 struct cfg80211_assoc_request
*req
)
2285 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2288 static int ieee80211_deauth(struct wiphy
*wiphy
, struct net_device
*dev
,
2289 struct cfg80211_deauth_request
*req
)
2291 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2294 static int ieee80211_disassoc(struct wiphy
*wiphy
, struct net_device
*dev
,
2295 struct cfg80211_disassoc_request
*req
)
2297 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev
), req
);
2300 static int ieee80211_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
2301 struct cfg80211_ibss_params
*params
)
2303 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev
), params
);
2306 static int ieee80211_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2308 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev
));
2311 static int ieee80211_join_ocb(struct wiphy
*wiphy
, struct net_device
*dev
,
2312 struct ocb_setup
*setup
)
2314 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev
), setup
);
2317 static int ieee80211_leave_ocb(struct wiphy
*wiphy
, struct net_device
*dev
)
2319 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev
));
2322 static int ieee80211_set_mcast_rate(struct wiphy
*wiphy
, struct net_device
*dev
,
2323 int rate
[NUM_NL80211_BANDS
])
2325 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2327 memcpy(sdata
->vif
.bss_conf
.mcast_rate
, rate
,
2328 sizeof(int) * NUM_NL80211_BANDS
);
2330 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_MCAST_RATE
);
2335 static int ieee80211_set_wiphy_params(struct wiphy
*wiphy
, u32 changed
)
2337 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2340 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
) {
2341 ieee80211_check_fast_xmit_all(local
);
2343 err
= drv_set_frag_threshold(local
, wiphy
->frag_threshold
);
2346 ieee80211_check_fast_xmit_all(local
);
2351 if ((changed
& WIPHY_PARAM_COVERAGE_CLASS
) ||
2352 (changed
& WIPHY_PARAM_DYN_ACK
)) {
2355 coverage_class
= changed
& WIPHY_PARAM_COVERAGE_CLASS
?
2356 wiphy
->coverage_class
: -1;
2357 err
= drv_set_coverage_class(local
, coverage_class
);
2363 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
) {
2364 err
= drv_set_rts_threshold(local
, wiphy
->rts_threshold
);
2370 if (changed
& WIPHY_PARAM_RETRY_SHORT
) {
2371 if (wiphy
->retry_short
> IEEE80211_MAX_TX_RETRY
)
2373 local
->hw
.conf
.short_frame_max_tx_count
= wiphy
->retry_short
;
2375 if (changed
& WIPHY_PARAM_RETRY_LONG
) {
2376 if (wiphy
->retry_long
> IEEE80211_MAX_TX_RETRY
)
2378 local
->hw
.conf
.long_frame_max_tx_count
= wiphy
->retry_long
;
2381 (WIPHY_PARAM_RETRY_SHORT
| WIPHY_PARAM_RETRY_LONG
))
2382 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_RETRY_LIMITS
);
2384 if (changed
& (WIPHY_PARAM_TXQ_LIMIT
|
2385 WIPHY_PARAM_TXQ_MEMORY_LIMIT
|
2386 WIPHY_PARAM_TXQ_QUANTUM
))
2387 ieee80211_txq_set_params(local
);
2392 static int ieee80211_set_tx_power(struct wiphy
*wiphy
,
2393 struct wireless_dev
*wdev
,
2394 enum nl80211_tx_power_setting type
, int mbm
)
2396 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2397 struct ieee80211_sub_if_data
*sdata
;
2398 enum nl80211_tx_power_setting txp_type
= type
;
2399 bool update_txp_type
= false;
2400 bool has_monitor
= false;
2403 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2405 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
) {
2406 sdata
= rtnl_dereference(local
->monitor_sdata
);
2412 case NL80211_TX_POWER_AUTOMATIC
:
2413 sdata
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2414 txp_type
= NL80211_TX_POWER_LIMITED
;
2416 case NL80211_TX_POWER_LIMITED
:
2417 case NL80211_TX_POWER_FIXED
:
2418 if (mbm
< 0 || (mbm
% 100))
2420 sdata
->user_power_level
= MBM_TO_DBM(mbm
);
2424 if (txp_type
!= sdata
->vif
.bss_conf
.txpower_type
) {
2425 update_txp_type
= true;
2426 sdata
->vif
.bss_conf
.txpower_type
= txp_type
;
2429 ieee80211_recalc_txpower(sdata
, update_txp_type
);
2435 case NL80211_TX_POWER_AUTOMATIC
:
2436 local
->user_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2437 txp_type
= NL80211_TX_POWER_LIMITED
;
2439 case NL80211_TX_POWER_LIMITED
:
2440 case NL80211_TX_POWER_FIXED
:
2441 if (mbm
< 0 || (mbm
% 100))
2443 local
->user_power_level
= MBM_TO_DBM(mbm
);
2447 mutex_lock(&local
->iflist_mtx
);
2448 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
2449 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
) {
2453 sdata
->user_power_level
= local
->user_power_level
;
2454 if (txp_type
!= sdata
->vif
.bss_conf
.txpower_type
)
2455 update_txp_type
= true;
2456 sdata
->vif
.bss_conf
.txpower_type
= txp_type
;
2458 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
2459 if (sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
)
2461 ieee80211_recalc_txpower(sdata
, update_txp_type
);
2463 mutex_unlock(&local
->iflist_mtx
);
2466 sdata
= rtnl_dereference(local
->monitor_sdata
);
2468 sdata
->user_power_level
= local
->user_power_level
;
2469 if (txp_type
!= sdata
->vif
.bss_conf
.txpower_type
)
2470 update_txp_type
= true;
2471 sdata
->vif
.bss_conf
.txpower_type
= txp_type
;
2473 ieee80211_recalc_txpower(sdata
, update_txp_type
);
2480 static int ieee80211_get_tx_power(struct wiphy
*wiphy
,
2481 struct wireless_dev
*wdev
,
2484 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2485 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2487 if (local
->ops
->get_txpower
)
2488 return drv_get_txpower(local
, sdata
, dbm
);
2490 if (!local
->use_chanctx
)
2491 *dbm
= local
->hw
.conf
.power_level
;
2493 *dbm
= sdata
->vif
.bss_conf
.txpower
;
2498 static int ieee80211_set_wds_peer(struct wiphy
*wiphy
, struct net_device
*dev
,
2501 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2503 memcpy(&sdata
->u
.wds
.remote_addr
, addr
, ETH_ALEN
);
2508 static void ieee80211_rfkill_poll(struct wiphy
*wiphy
)
2510 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2512 drv_rfkill_poll(local
);
2515 #ifdef CONFIG_NL80211_TESTMODE
2516 static int ieee80211_testmode_cmd(struct wiphy
*wiphy
,
2517 struct wireless_dev
*wdev
,
2518 void *data
, int len
)
2520 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2521 struct ieee80211_vif
*vif
= NULL
;
2523 if (!local
->ops
->testmode_cmd
)
2527 struct ieee80211_sub_if_data
*sdata
;
2529 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
2530 if (sdata
->flags
& IEEE80211_SDATA_IN_DRIVER
)
2534 return local
->ops
->testmode_cmd(&local
->hw
, vif
, data
, len
);
2537 static int ieee80211_testmode_dump(struct wiphy
*wiphy
,
2538 struct sk_buff
*skb
,
2539 struct netlink_callback
*cb
,
2540 void *data
, int len
)
2542 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
2544 if (!local
->ops
->testmode_dump
)
2547 return local
->ops
->testmode_dump(&local
->hw
, skb
, cb
, data
, len
);
2551 int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data
*sdata
,
2552 enum ieee80211_smps_mode smps_mode
)
2554 struct sta_info
*sta
;
2555 enum ieee80211_smps_mode old_req
;
2557 if (WARN_ON_ONCE(sdata
->vif
.type
!= NL80211_IFTYPE_AP
))
2560 if (sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
2563 old_req
= sdata
->u
.ap
.req_smps
;
2564 sdata
->u
.ap
.req_smps
= smps_mode
;
2566 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2567 if (old_req
== smps_mode
||
2568 smps_mode
== IEEE80211_SMPS_AUTOMATIC
)
2572 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
2573 smps_mode
, atomic_read(&sdata
->u
.ap
.num_mcast_sta
));
2575 mutex_lock(&sdata
->local
->sta_mtx
);
2576 list_for_each_entry(sta
, &sdata
->local
->sta_list
, list
) {
2578 * Only stations associated to our AP and
2581 if (sta
->sdata
->bss
!= &sdata
->u
.ap
)
2584 /* This station doesn't support MIMO - skip it */
2585 if (sta_info_tx_streams(sta
) == 1)
2589 * Don't wake up a STA just to send the action frame
2590 * unless we are getting more restrictive.
2592 if (test_sta_flag(sta
, WLAN_STA_PS_STA
) &&
2593 !ieee80211_smps_is_restrictive(sta
->known_smps_mode
,
2595 ht_dbg(sdata
, "Won't send SMPS to sleeping STA %pM\n",
2601 * If the STA is not authorized, wait until it gets
2602 * authorized and the action frame will be sent then.
2604 if (!test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
2607 ht_dbg(sdata
, "Sending SMPS to %pM\n", sta
->sta
.addr
);
2608 ieee80211_send_smps_action(sdata
, smps_mode
, sta
->sta
.addr
,
2609 sdata
->vif
.bss_conf
.bssid
);
2611 mutex_unlock(&sdata
->local
->sta_mtx
);
2613 sdata
->smps_mode
= smps_mode
;
2614 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->recalc_smps
);
2619 int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data
*sdata
,
2620 enum ieee80211_smps_mode smps_mode
)
2623 enum ieee80211_smps_mode old_req
;
2625 struct sta_info
*sta
;
2626 bool tdls_peer_found
= false;
2628 lockdep_assert_held(&sdata
->wdev
.mtx
);
2630 if (WARN_ON_ONCE(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2633 old_req
= sdata
->u
.mgd
.req_smps
;
2634 sdata
->u
.mgd
.req_smps
= smps_mode
;
2636 if (old_req
== smps_mode
&&
2637 smps_mode
!= IEEE80211_SMPS_AUTOMATIC
)
2641 * If not associated, or current association is not an HT
2642 * association, there's no need to do anything, just store
2643 * the new value until we associate.
2645 if (!sdata
->u
.mgd
.associated
||
2646 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
)
2649 ap
= sdata
->u
.mgd
.associated
->bssid
;
2652 list_for_each_entry_rcu(sta
, &sdata
->local
->sta_list
, list
) {
2653 if (!sta
->sta
.tdls
|| sta
->sdata
!= sdata
|| !sta
->uploaded
||
2654 !test_sta_flag(sta
, WLAN_STA_AUTHORIZED
))
2657 tdls_peer_found
= true;
2662 if (smps_mode
== IEEE80211_SMPS_AUTOMATIC
) {
2663 if (tdls_peer_found
|| !sdata
->u
.mgd
.powersave
)
2664 smps_mode
= IEEE80211_SMPS_OFF
;
2666 smps_mode
= IEEE80211_SMPS_DYNAMIC
;
2669 /* send SM PS frame to AP */
2670 err
= ieee80211_send_smps_action(sdata
, smps_mode
,
2673 sdata
->u
.mgd
.req_smps
= old_req
;
2674 else if (smps_mode
!= IEEE80211_SMPS_OFF
&& tdls_peer_found
)
2675 ieee80211_teardown_tdls_peers(sdata
);
2680 static int ieee80211_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2681 bool enabled
, int timeout
)
2683 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2684 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2686 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
2689 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
))
2692 if (enabled
== sdata
->u
.mgd
.powersave
&&
2693 timeout
== local
->dynamic_ps_forced_timeout
)
2696 sdata
->u
.mgd
.powersave
= enabled
;
2697 local
->dynamic_ps_forced_timeout
= timeout
;
2699 /* no change, but if automatic follow powersave */
2701 __ieee80211_request_smps_mgd(sdata
, sdata
->u
.mgd
.req_smps
);
2702 sdata_unlock(sdata
);
2704 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
))
2705 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2707 ieee80211_recalc_ps(local
);
2708 ieee80211_recalc_ps_vif(sdata
);
2709 ieee80211_check_fast_rx_iface(sdata
);
2714 static int ieee80211_set_cqm_rssi_config(struct wiphy
*wiphy
,
2715 struct net_device
*dev
,
2716 s32 rssi_thold
, u32 rssi_hyst
)
2718 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2719 struct ieee80211_vif
*vif
= &sdata
->vif
;
2720 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
2722 if (rssi_thold
== bss_conf
->cqm_rssi_thold
&&
2723 rssi_hyst
== bss_conf
->cqm_rssi_hyst
)
2726 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
&&
2727 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
))
2730 bss_conf
->cqm_rssi_thold
= rssi_thold
;
2731 bss_conf
->cqm_rssi_hyst
= rssi_hyst
;
2732 bss_conf
->cqm_rssi_low
= 0;
2733 bss_conf
->cqm_rssi_high
= 0;
2734 sdata
->u
.mgd
.last_cqm_event_signal
= 0;
2736 /* tell the driver upon association, unless already associated */
2737 if (sdata
->u
.mgd
.associated
&&
2738 sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)
2739 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_CQM
);
2744 static int ieee80211_set_cqm_rssi_range_config(struct wiphy
*wiphy
,
2745 struct net_device
*dev
,
2746 s32 rssi_low
, s32 rssi_high
)
2748 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2749 struct ieee80211_vif
*vif
= &sdata
->vif
;
2750 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
2752 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
2755 bss_conf
->cqm_rssi_low
= rssi_low
;
2756 bss_conf
->cqm_rssi_high
= rssi_high
;
2757 bss_conf
->cqm_rssi_thold
= 0;
2758 bss_conf
->cqm_rssi_hyst
= 0;
2759 sdata
->u
.mgd
.last_cqm_event_signal
= 0;
2761 /* tell the driver upon association, unless already associated */
2762 if (sdata
->u
.mgd
.associated
&&
2763 sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)
2764 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_CQM
);
2769 static int ieee80211_set_bitrate_mask(struct wiphy
*wiphy
,
2770 struct net_device
*dev
,
2772 const struct cfg80211_bitrate_mask
*mask
)
2774 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2775 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
2778 if (!ieee80211_sdata_running(sdata
))
2782 * If active validate the setting and reject it if it doesn't leave
2783 * at least one basic rate usable, since we really have to be able
2784 * to send something, and if we're an AP we have to be able to do
2785 * so at a basic rate so that all clients can receive it.
2787 if (rcu_access_pointer(sdata
->vif
.chanctx_conf
) &&
2788 sdata
->vif
.bss_conf
.chandef
.chan
) {
2789 u32 basic_rates
= sdata
->vif
.bss_conf
.basic_rates
;
2790 enum nl80211_band band
= sdata
->vif
.bss_conf
.chandef
.chan
->band
;
2792 if (!(mask
->control
[band
].legacy
& basic_rates
))
2796 if (ieee80211_hw_check(&local
->hw
, HAS_RATE_CONTROL
)) {
2797 ret
= drv_set_bitrate_mask(local
, sdata
, mask
);
2802 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
2803 struct ieee80211_supported_band
*sband
= wiphy
->bands
[i
];
2806 sdata
->rc_rateidx_mask
[i
] = mask
->control
[i
].legacy
;
2807 memcpy(sdata
->rc_rateidx_mcs_mask
[i
], mask
->control
[i
].ht_mcs
,
2808 sizeof(mask
->control
[i
].ht_mcs
));
2809 memcpy(sdata
->rc_rateidx_vht_mcs_mask
[i
],
2810 mask
->control
[i
].vht_mcs
,
2811 sizeof(mask
->control
[i
].vht_mcs
));
2813 sdata
->rc_has_mcs_mask
[i
] = false;
2814 sdata
->rc_has_vht_mcs_mask
[i
] = false;
2818 for (j
= 0; j
< IEEE80211_HT_MCS_MASK_LEN
; j
++) {
2819 if (~sdata
->rc_rateidx_mcs_mask
[i
][j
]) {
2820 sdata
->rc_has_mcs_mask
[i
] = true;
2825 for (j
= 0; j
< NL80211_VHT_NSS_MAX
; j
++) {
2826 if (~sdata
->rc_rateidx_vht_mcs_mask
[i
][j
]) {
2827 sdata
->rc_has_vht_mcs_mask
[i
] = true;
2836 static int ieee80211_start_radar_detection(struct wiphy
*wiphy
,
2837 struct net_device
*dev
,
2838 struct cfg80211_chan_def
*chandef
,
2841 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
2842 struct ieee80211_local
*local
= sdata
->local
;
2845 mutex_lock(&local
->mtx
);
2846 if (!list_empty(&local
->roc_list
) || local
->scanning
) {
2851 /* whatever, but channel contexts should not complain about that one */
2852 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
2853 sdata
->needed_rx_chains
= local
->rx_chains
;
2855 err
= ieee80211_vif_use_channel(sdata
, chandef
,
2856 IEEE80211_CHANCTX_SHARED
);
2860 ieee80211_queue_delayed_work(&sdata
->local
->hw
,
2861 &sdata
->dfs_cac_timer_work
,
2862 msecs_to_jiffies(cac_time_ms
));
2865 mutex_unlock(&local
->mtx
);
2869 static struct cfg80211_beacon_data
*
2870 cfg80211_beacon_dup(struct cfg80211_beacon_data
*beacon
)
2872 struct cfg80211_beacon_data
*new_beacon
;
2876 len
= beacon
->head_len
+ beacon
->tail_len
+ beacon
->beacon_ies_len
+
2877 beacon
->proberesp_ies_len
+ beacon
->assocresp_ies_len
+
2878 beacon
->probe_resp_len
;
2880 new_beacon
= kzalloc(sizeof(*new_beacon
) + len
, GFP_KERNEL
);
2884 pos
= (u8
*)(new_beacon
+ 1);
2885 if (beacon
->head_len
) {
2886 new_beacon
->head_len
= beacon
->head_len
;
2887 new_beacon
->head
= pos
;
2888 memcpy(pos
, beacon
->head
, beacon
->head_len
);
2889 pos
+= beacon
->head_len
;
2891 if (beacon
->tail_len
) {
2892 new_beacon
->tail_len
= beacon
->tail_len
;
2893 new_beacon
->tail
= pos
;
2894 memcpy(pos
, beacon
->tail
, beacon
->tail_len
);
2895 pos
+= beacon
->tail_len
;
2897 if (beacon
->beacon_ies_len
) {
2898 new_beacon
->beacon_ies_len
= beacon
->beacon_ies_len
;
2899 new_beacon
->beacon_ies
= pos
;
2900 memcpy(pos
, beacon
->beacon_ies
, beacon
->beacon_ies_len
);
2901 pos
+= beacon
->beacon_ies_len
;
2903 if (beacon
->proberesp_ies_len
) {
2904 new_beacon
->proberesp_ies_len
= beacon
->proberesp_ies_len
;
2905 new_beacon
->proberesp_ies
= pos
;
2906 memcpy(pos
, beacon
->proberesp_ies
, beacon
->proberesp_ies_len
);
2907 pos
+= beacon
->proberesp_ies_len
;
2909 if (beacon
->assocresp_ies_len
) {
2910 new_beacon
->assocresp_ies_len
= beacon
->assocresp_ies_len
;
2911 new_beacon
->assocresp_ies
= pos
;
2912 memcpy(pos
, beacon
->assocresp_ies
, beacon
->assocresp_ies_len
);
2913 pos
+= beacon
->assocresp_ies_len
;
2915 if (beacon
->probe_resp_len
) {
2916 new_beacon
->probe_resp_len
= beacon
->probe_resp_len
;
2917 new_beacon
->probe_resp
= pos
;
2918 memcpy(pos
, beacon
->probe_resp
, beacon
->probe_resp_len
);
2919 pos
+= beacon
->probe_resp_len
;
2925 void ieee80211_csa_finish(struct ieee80211_vif
*vif
)
2927 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2929 ieee80211_queue_work(&sdata
->local
->hw
,
2930 &sdata
->csa_finalize_work
);
2932 EXPORT_SYMBOL(ieee80211_csa_finish
);
2934 static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data
*sdata
,
2939 switch (sdata
->vif
.type
) {
2940 case NL80211_IFTYPE_AP
:
2941 err
= ieee80211_assign_beacon(sdata
, sdata
->u
.ap
.next_beacon
,
2943 kfree(sdata
->u
.ap
.next_beacon
);
2944 sdata
->u
.ap
.next_beacon
= NULL
;
2950 case NL80211_IFTYPE_ADHOC
:
2951 err
= ieee80211_ibss_finish_csa(sdata
);
2956 #ifdef CONFIG_MAC80211_MESH
2957 case NL80211_IFTYPE_MESH_POINT
:
2958 err
= ieee80211_mesh_finish_csa(sdata
);
2972 static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data
*sdata
)
2974 struct ieee80211_local
*local
= sdata
->local
;
2978 sdata_assert_lock(sdata
);
2979 lockdep_assert_held(&local
->mtx
);
2980 lockdep_assert_held(&local
->chanctx_mtx
);
2983 * using reservation isn't immediate as it may be deferred until later
2984 * with multi-vif. once reservation is complete it will re-schedule the
2985 * work with no reserved_chanctx so verify chandef to check if it
2986 * completed successfully
2989 if (sdata
->reserved_chanctx
) {
2991 * with multi-vif csa driver may call ieee80211_csa_finish()
2992 * many times while waiting for other interfaces to use their
2995 if (sdata
->reserved_ready
)
2998 return ieee80211_vif_use_reserved_context(sdata
);
3001 if (!cfg80211_chandef_identical(&sdata
->vif
.bss_conf
.chandef
,
3002 &sdata
->csa_chandef
))
3005 sdata
->vif
.csa_active
= false;
3007 err
= ieee80211_set_after_csa_beacon(sdata
, &changed
);
3011 ieee80211_bss_info_change_notify(sdata
, changed
);
3013 if (sdata
->csa_block_tx
) {
3014 ieee80211_wake_vif_queues(local
, sdata
,
3015 IEEE80211_QUEUE_STOP_REASON_CSA
);
3016 sdata
->csa_block_tx
= false;
3019 err
= drv_post_channel_switch(sdata
);
3023 cfg80211_ch_switch_notify(sdata
->dev
, &sdata
->csa_chandef
);
3028 static void ieee80211_csa_finalize(struct ieee80211_sub_if_data
*sdata
)
3030 if (__ieee80211_csa_finalize(sdata
)) {
3031 sdata_info(sdata
, "failed to finalize CSA, disconnecting\n");
3032 cfg80211_stop_iface(sdata
->local
->hw
.wiphy
, &sdata
->wdev
,
3037 void ieee80211_csa_finalize_work(struct work_struct
*work
)
3039 struct ieee80211_sub_if_data
*sdata
=
3040 container_of(work
, struct ieee80211_sub_if_data
,
3042 struct ieee80211_local
*local
= sdata
->local
;
3045 mutex_lock(&local
->mtx
);
3046 mutex_lock(&local
->chanctx_mtx
);
3048 /* AP might have been stopped while waiting for the lock. */
3049 if (!sdata
->vif
.csa_active
)
3052 if (!ieee80211_sdata_running(sdata
))
3055 ieee80211_csa_finalize(sdata
);
3058 mutex_unlock(&local
->chanctx_mtx
);
3059 mutex_unlock(&local
->mtx
);
3060 sdata_unlock(sdata
);
3063 static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data
*sdata
,
3064 struct cfg80211_csa_settings
*params
,
3067 struct ieee80211_csa_settings csa
= {};
3070 switch (sdata
->vif
.type
) {
3071 case NL80211_IFTYPE_AP
:
3072 sdata
->u
.ap
.next_beacon
=
3073 cfg80211_beacon_dup(¶ms
->beacon_after
);
3074 if (!sdata
->u
.ap
.next_beacon
)
3078 * With a count of 0, we don't have to wait for any
3079 * TBTT before switching, so complete the CSA
3080 * immediately. In theory, with a count == 1 we
3081 * should delay the switch until just before the next
3082 * TBTT, but that would complicate things so we switch
3083 * immediately too. If we would delay the switch
3084 * until the next TBTT, we would have to set the probe
3087 * TODO: A channel switch with count <= 1 without
3088 * sending a CSA action frame is kind of useless,
3089 * because the clients won't know we're changing
3090 * channels. The action frame must be implemented
3091 * either here or in the userspace.
3093 if (params
->count
<= 1)
3096 if ((params
->n_counter_offsets_beacon
>
3097 IEEE80211_MAX_CSA_COUNTERS_NUM
) ||
3098 (params
->n_counter_offsets_presp
>
3099 IEEE80211_MAX_CSA_COUNTERS_NUM
))
3102 csa
.counter_offsets_beacon
= params
->counter_offsets_beacon
;
3103 csa
.counter_offsets_presp
= params
->counter_offsets_presp
;
3104 csa
.n_counter_offsets_beacon
= params
->n_counter_offsets_beacon
;
3105 csa
.n_counter_offsets_presp
= params
->n_counter_offsets_presp
;
3106 csa
.count
= params
->count
;
3108 err
= ieee80211_assign_beacon(sdata
, ¶ms
->beacon_csa
, &csa
);
3110 kfree(sdata
->u
.ap
.next_beacon
);
3116 case NL80211_IFTYPE_ADHOC
:
3117 if (!sdata
->vif
.bss_conf
.ibss_joined
)
3120 if (params
->chandef
.width
!= sdata
->u
.ibss
.chandef
.width
)
3123 switch (params
->chandef
.width
) {
3124 case NL80211_CHAN_WIDTH_40
:
3125 if (cfg80211_get_chandef_type(¶ms
->chandef
) !=
3126 cfg80211_get_chandef_type(&sdata
->u
.ibss
.chandef
))
3128 case NL80211_CHAN_WIDTH_5
:
3129 case NL80211_CHAN_WIDTH_10
:
3130 case NL80211_CHAN_WIDTH_20_NOHT
:
3131 case NL80211_CHAN_WIDTH_20
:
3137 /* changes into another band are not supported */
3138 if (sdata
->u
.ibss
.chandef
.chan
->band
!=
3139 params
->chandef
.chan
->band
)
3142 /* see comments in the NL80211_IFTYPE_AP block */
3143 if (params
->count
> 1) {
3144 err
= ieee80211_ibss_csa_beacon(sdata
, params
);
3150 ieee80211_send_action_csa(sdata
, params
);
3153 #ifdef CONFIG_MAC80211_MESH
3154 case NL80211_IFTYPE_MESH_POINT
: {
3155 struct ieee80211_if_mesh
*ifmsh
= &sdata
->u
.mesh
;
3157 if (params
->chandef
.width
!= sdata
->vif
.bss_conf
.chandef
.width
)
3160 /* changes into another band are not supported */
3161 if (sdata
->vif
.bss_conf
.chandef
.chan
->band
!=
3162 params
->chandef
.chan
->band
)
3165 if (ifmsh
->csa_role
== IEEE80211_MESH_CSA_ROLE_NONE
) {
3166 ifmsh
->csa_role
= IEEE80211_MESH_CSA_ROLE_INIT
;
3167 if (!ifmsh
->pre_value
)
3168 ifmsh
->pre_value
= 1;
3173 /* see comments in the NL80211_IFTYPE_AP block */
3174 if (params
->count
> 1) {
3175 err
= ieee80211_mesh_csa_beacon(sdata
, params
);
3177 ifmsh
->csa_role
= IEEE80211_MESH_CSA_ROLE_NONE
;
3183 if (ifmsh
->csa_role
== IEEE80211_MESH_CSA_ROLE_INIT
)
3184 ieee80211_send_action_csa(sdata
, params
);
3197 __ieee80211_channel_switch(struct wiphy
*wiphy
, struct net_device
*dev
,
3198 struct cfg80211_csa_settings
*params
)
3200 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3201 struct ieee80211_local
*local
= sdata
->local
;
3202 struct ieee80211_channel_switch ch_switch
;
3203 struct ieee80211_chanctx_conf
*conf
;
3204 struct ieee80211_chanctx
*chanctx
;
3208 sdata_assert_lock(sdata
);
3209 lockdep_assert_held(&local
->mtx
);
3211 if (!list_empty(&local
->roc_list
) || local
->scanning
)
3214 if (sdata
->wdev
.cac_started
)
3217 if (cfg80211_chandef_identical(¶ms
->chandef
,
3218 &sdata
->vif
.bss_conf
.chandef
))
3221 /* don't allow another channel switch if one is already active. */
3222 if (sdata
->vif
.csa_active
)
3225 mutex_lock(&local
->chanctx_mtx
);
3226 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
3227 lockdep_is_held(&local
->chanctx_mtx
));
3233 chanctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
3235 ch_switch
.timestamp
= 0;
3236 ch_switch
.device_timestamp
= 0;
3237 ch_switch
.block_tx
= params
->block_tx
;
3238 ch_switch
.chandef
= params
->chandef
;
3239 ch_switch
.count
= params
->count
;
3241 err
= drv_pre_channel_switch(sdata
, &ch_switch
);
3245 err
= ieee80211_vif_reserve_chanctx(sdata
, ¶ms
->chandef
,
3247 params
->radar_required
);
3251 /* if reservation is invalid then this will fail */
3252 err
= ieee80211_check_combinations(sdata
, NULL
, chanctx
->mode
, 0);
3254 ieee80211_vif_unreserve_chanctx(sdata
);
3258 err
= ieee80211_set_csa_beacon(sdata
, params
, &changed
);
3260 ieee80211_vif_unreserve_chanctx(sdata
);
3264 sdata
->csa_chandef
= params
->chandef
;
3265 sdata
->csa_block_tx
= params
->block_tx
;
3266 sdata
->vif
.csa_active
= true;
3268 if (sdata
->csa_block_tx
)
3269 ieee80211_stop_vif_queues(local
, sdata
,
3270 IEEE80211_QUEUE_STOP_REASON_CSA
);
3272 cfg80211_ch_switch_started_notify(sdata
->dev
, &sdata
->csa_chandef
,
3276 ieee80211_bss_info_change_notify(sdata
, changed
);
3277 drv_channel_switch_beacon(sdata
, ¶ms
->chandef
);
3279 /* if the beacon didn't change, we can finalize immediately */
3280 ieee80211_csa_finalize(sdata
);
3284 mutex_unlock(&local
->chanctx_mtx
);
3288 int ieee80211_channel_switch(struct wiphy
*wiphy
, struct net_device
*dev
,
3289 struct cfg80211_csa_settings
*params
)
3291 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3292 struct ieee80211_local
*local
= sdata
->local
;
3295 mutex_lock(&local
->mtx
);
3296 err
= __ieee80211_channel_switch(wiphy
, dev
, params
);
3297 mutex_unlock(&local
->mtx
);
3302 u64
ieee80211_mgmt_tx_cookie(struct ieee80211_local
*local
)
3304 lockdep_assert_held(&local
->mtx
);
3306 local
->roc_cookie_counter
++;
3308 /* wow, you wrapped 64 bits ... more likely a bug */
3309 if (WARN_ON(local
->roc_cookie_counter
== 0))
3310 local
->roc_cookie_counter
++;
3312 return local
->roc_cookie_counter
;
3315 int ieee80211_attach_ack_skb(struct ieee80211_local
*local
, struct sk_buff
*skb
,
3316 u64
*cookie
, gfp_t gfp
)
3318 unsigned long spin_flags
;
3319 struct sk_buff
*ack_skb
;
3322 ack_skb
= skb_copy(skb
, gfp
);
3326 spin_lock_irqsave(&local
->ack_status_lock
, spin_flags
);
3327 id
= idr_alloc(&local
->ack_status_frames
, ack_skb
,
3328 1, 0x10000, GFP_ATOMIC
);
3329 spin_unlock_irqrestore(&local
->ack_status_lock
, spin_flags
);
3336 IEEE80211_SKB_CB(skb
)->ack_frame_id
= id
;
3338 *cookie
= ieee80211_mgmt_tx_cookie(local
);
3339 IEEE80211_SKB_CB(ack_skb
)->ack
.cookie
= *cookie
;
3344 static void ieee80211_mgmt_frame_register(struct wiphy
*wiphy
,
3345 struct wireless_dev
*wdev
,
3346 u16 frame_type
, bool reg
)
3348 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3349 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3351 switch (frame_type
) {
3352 case IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_PROBE_REQ
:
3354 local
->probe_req_reg
++;
3355 sdata
->vif
.probe_req_reg
++;
3357 if (local
->probe_req_reg
)
3358 local
->probe_req_reg
--;
3360 if (sdata
->vif
.probe_req_reg
)
3361 sdata
->vif
.probe_req_reg
--;
3364 if (!local
->open_count
)
3367 if (sdata
->vif
.probe_req_reg
== 1)
3368 drv_config_iface_filter(local
, sdata
, FIF_PROBE_REQ
,
3370 else if (sdata
->vif
.probe_req_reg
== 0)
3371 drv_config_iface_filter(local
, sdata
, 0,
3374 ieee80211_configure_filter(local
);
3381 static int ieee80211_set_antenna(struct wiphy
*wiphy
, u32 tx_ant
, u32 rx_ant
)
3383 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3388 return drv_set_antenna(local
, tx_ant
, rx_ant
);
3391 static int ieee80211_get_antenna(struct wiphy
*wiphy
, u32
*tx_ant
, u32
*rx_ant
)
3393 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3395 return drv_get_antenna(local
, tx_ant
, rx_ant
);
3398 static int ieee80211_set_rekey_data(struct wiphy
*wiphy
,
3399 struct net_device
*dev
,
3400 struct cfg80211_gtk_rekey_data
*data
)
3402 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3403 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3405 if (!local
->ops
->set_rekey_data
)
3408 drv_set_rekey_data(local
, sdata
, data
);
3413 static int ieee80211_probe_client(struct wiphy
*wiphy
, struct net_device
*dev
,
3414 const u8
*peer
, u64
*cookie
)
3416 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3417 struct ieee80211_local
*local
= sdata
->local
;
3418 struct ieee80211_qos_hdr
*nullfunc
;
3419 struct sk_buff
*skb
;
3420 int size
= sizeof(*nullfunc
);
3423 struct ieee80211_tx_info
*info
;
3424 struct sta_info
*sta
;
3425 struct ieee80211_chanctx_conf
*chanctx_conf
;
3426 enum nl80211_band band
;
3429 /* the lock is needed to assign the cookie later */
3430 mutex_lock(&local
->mtx
);
3433 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3434 if (WARN_ON(!chanctx_conf
)) {
3438 band
= chanctx_conf
->def
.chan
->band
;
3439 sta
= sta_info_get_bss(sdata
, peer
);
3448 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3449 IEEE80211_STYPE_QOS_NULLFUNC
|
3450 IEEE80211_FCTL_FROMDS
);
3453 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
3454 IEEE80211_STYPE_NULLFUNC
|
3455 IEEE80211_FCTL_FROMDS
);
3458 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ size
);
3466 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
3468 nullfunc
= skb_put(skb
, size
);
3469 nullfunc
->frame_control
= fc
;
3470 nullfunc
->duration_id
= 0;
3471 memcpy(nullfunc
->addr1
, sta
->sta
.addr
, ETH_ALEN
);
3472 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
3473 memcpy(nullfunc
->addr3
, sdata
->vif
.addr
, ETH_ALEN
);
3474 nullfunc
->seq_ctrl
= 0;
3476 info
= IEEE80211_SKB_CB(skb
);
3478 info
->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3479 IEEE80211_TX_INTFL_NL80211_FRAME_TX
;
3482 skb_set_queue_mapping(skb
, IEEE80211_AC_VO
);
3485 nullfunc
->qos_ctrl
= cpu_to_le16(7);
3487 ret
= ieee80211_attach_ack_skb(local
, skb
, cookie
, GFP_ATOMIC
);
3494 ieee80211_xmit(sdata
, sta
, skb
, 0);
3500 mutex_unlock(&local
->mtx
);
3505 static int ieee80211_cfg_get_channel(struct wiphy
*wiphy
,
3506 struct wireless_dev
*wdev
,
3507 struct cfg80211_chan_def
*chandef
)
3509 struct ieee80211_sub_if_data
*sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3510 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3511 struct ieee80211_chanctx_conf
*chanctx_conf
;
3515 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3517 *chandef
= sdata
->vif
.bss_conf
.chandef
;
3519 } else if (local
->open_count
> 0 &&
3520 local
->open_count
== local
->monitors
&&
3521 sdata
->vif
.type
== NL80211_IFTYPE_MONITOR
) {
3522 if (local
->use_chanctx
)
3523 *chandef
= local
->monitor_chandef
;
3525 *chandef
= local
->_oper_chandef
;
3534 static void ieee80211_set_wakeup(struct wiphy
*wiphy
, bool enabled
)
3536 drv_set_wakeup(wiphy_priv(wiphy
), enabled
);
3540 static int ieee80211_set_qos_map(struct wiphy
*wiphy
,
3541 struct net_device
*dev
,
3542 struct cfg80211_qos_map
*qos_map
)
3544 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3545 struct mac80211_qos_map
*new_qos_map
, *old_qos_map
;
3548 new_qos_map
= kzalloc(sizeof(*new_qos_map
), GFP_KERNEL
);
3551 memcpy(&new_qos_map
->qos_map
, qos_map
, sizeof(*qos_map
));
3553 /* A NULL qos_map was passed to disable QoS mapping */
3557 old_qos_map
= sdata_dereference(sdata
->qos_map
, sdata
);
3558 rcu_assign_pointer(sdata
->qos_map
, new_qos_map
);
3560 kfree_rcu(old_qos_map
, rcu_head
);
3565 static int ieee80211_set_ap_chanwidth(struct wiphy
*wiphy
,
3566 struct net_device
*dev
,
3567 struct cfg80211_chan_def
*chandef
)
3569 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3573 ret
= ieee80211_vif_change_bandwidth(sdata
, chandef
, &changed
);
3575 ieee80211_bss_info_change_notify(sdata
, changed
);
3580 static int ieee80211_add_tx_ts(struct wiphy
*wiphy
, struct net_device
*dev
,
3581 u8 tsid
, const u8
*peer
, u8 up
,
3584 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3585 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3586 int ac
= ieee802_1d_to_ac
[up
];
3588 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
3591 if (!(sdata
->wmm_acm
& BIT(up
)))
3594 if (ifmgd
->tx_tspec
[ac
].admitted_time
)
3597 if (admitted_time
) {
3598 ifmgd
->tx_tspec
[ac
].admitted_time
= 32 * admitted_time
;
3599 ifmgd
->tx_tspec
[ac
].tsid
= tsid
;
3600 ifmgd
->tx_tspec
[ac
].up
= up
;
3606 static int ieee80211_del_tx_ts(struct wiphy
*wiphy
, struct net_device
*dev
,
3607 u8 tsid
, const u8
*peer
)
3609 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3610 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3611 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3614 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
3615 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
3617 /* skip unused entries */
3618 if (!tx_tspec
->admitted_time
)
3621 if (tx_tspec
->tsid
!= tsid
)
3624 /* due to this new packets will be reassigned to non-ACM ACs */
3627 /* Make sure that all packets have been sent to avoid to
3628 * restore the QoS params on packets that are still on the
3632 ieee80211_flush_queues(local
, sdata
, false);
3634 /* restore the normal QoS parameters
3635 * (unconditionally to avoid races)
3637 tx_tspec
->action
= TX_TSPEC_ACTION_STOP_DOWNGRADE
;
3638 tx_tspec
->downgraded
= false;
3639 ieee80211_sta_handle_tspec_ac_params(sdata
);
3641 /* finally clear all the data */
3642 memset(tx_tspec
, 0, sizeof(*tx_tspec
));
3650 void ieee80211_nan_func_terminated(struct ieee80211_vif
*vif
,
3652 enum nl80211_nan_func_term_reason reason
,
3655 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
3656 struct cfg80211_nan_func
*func
;
3659 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_NAN
))
3662 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
3664 func
= idr_find(&sdata
->u
.nan
.function_inst_ids
, inst_id
);
3665 if (WARN_ON(!func
)) {
3666 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
3670 cookie
= func
->cookie
;
3671 idr_remove(&sdata
->u
.nan
.function_inst_ids
, inst_id
);
3673 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
3675 cfg80211_free_nan_func(func
);
3677 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif
), inst_id
,
3678 reason
, cookie
, gfp
);
3680 EXPORT_SYMBOL(ieee80211_nan_func_terminated
);
3682 void ieee80211_nan_func_match(struct ieee80211_vif
*vif
,
3683 struct cfg80211_nan_match_params
*match
,
3686 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
3687 struct cfg80211_nan_func
*func
;
3689 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_NAN
))
3692 spin_lock_bh(&sdata
->u
.nan
.func_lock
);
3694 func
= idr_find(&sdata
->u
.nan
.function_inst_ids
, match
->inst_id
);
3695 if (WARN_ON(!func
)) {
3696 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
3699 match
->cookie
= func
->cookie
;
3701 spin_unlock_bh(&sdata
->u
.nan
.func_lock
);
3703 cfg80211_nan_match(ieee80211_vif_to_wdev(vif
), match
, gfp
);
3705 EXPORT_SYMBOL(ieee80211_nan_func_match
);
3707 static int ieee80211_set_multicast_to_unicast(struct wiphy
*wiphy
,
3708 struct net_device
*dev
,
3711 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
3713 sdata
->u
.ap
.multicast_to_unicast
= enabled
;
3718 void ieee80211_fill_txq_stats(struct cfg80211_txq_stats
*txqstats
,
3719 struct txq_info
*txqi
)
3721 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_BACKLOG_BYTES
))) {
3722 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES
);
3723 txqstats
->backlog_bytes
= txqi
->tin
.backlog_bytes
;
3726 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS
))) {
3727 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS
);
3728 txqstats
->backlog_packets
= txqi
->tin
.backlog_packets
;
3731 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_FLOWS
))) {
3732 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_FLOWS
);
3733 txqstats
->flows
= txqi
->tin
.flows
;
3736 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_DROPS
))) {
3737 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_DROPS
);
3738 txqstats
->drops
= txqi
->cstats
.drop_count
;
3741 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_ECN_MARKS
))) {
3742 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_ECN_MARKS
);
3743 txqstats
->ecn_marks
= txqi
->cstats
.ecn_mark
;
3746 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_OVERLIMIT
))) {
3747 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_OVERLIMIT
);
3748 txqstats
->overlimit
= txqi
->tin
.overlimit
;
3751 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_COLLISIONS
))) {
3752 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_COLLISIONS
);
3753 txqstats
->collisions
= txqi
->tin
.collisions
;
3756 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_TX_BYTES
))) {
3757 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_TX_BYTES
);
3758 txqstats
->tx_bytes
= txqi
->tin
.tx_bytes
;
3761 if (!(txqstats
->filled
& BIT(NL80211_TXQ_STATS_TX_PACKETS
))) {
3762 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_TX_PACKETS
);
3763 txqstats
->tx_packets
= txqi
->tin
.tx_packets
;
3767 static int ieee80211_get_txq_stats(struct wiphy
*wiphy
,
3768 struct wireless_dev
*wdev
,
3769 struct cfg80211_txq_stats
*txqstats
)
3771 struct ieee80211_local
*local
= wiphy_priv(wiphy
);
3772 struct ieee80211_sub_if_data
*sdata
;
3775 if (!local
->ops
->wake_tx_queue
)
3778 spin_lock_bh(&local
->fq
.lock
);
3782 sdata
= IEEE80211_WDEV_TO_SUB_IF(wdev
);
3783 if (!sdata
->vif
.txq
) {
3787 ieee80211_fill_txq_stats(txqstats
, to_txq_info(sdata
->vif
.txq
));
3790 txqstats
->filled
|= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS
) |
3791 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES
) |
3792 BIT(NL80211_TXQ_STATS_OVERLIMIT
) |
3793 BIT(NL80211_TXQ_STATS_OVERMEMORY
) |
3794 BIT(NL80211_TXQ_STATS_COLLISIONS
) |
3795 BIT(NL80211_TXQ_STATS_MAX_FLOWS
);
3796 txqstats
->backlog_packets
= local
->fq
.backlog
;
3797 txqstats
->backlog_bytes
= local
->fq
.memory_usage
;
3798 txqstats
->overlimit
= local
->fq
.overlimit
;
3799 txqstats
->overmemory
= local
->fq
.overmemory
;
3800 txqstats
->collisions
= local
->fq
.collisions
;
3801 txqstats
->max_flows
= local
->fq
.flows_cnt
;
3806 spin_unlock_bh(&local
->fq
.lock
);
3811 const struct cfg80211_ops mac80211_config_ops
= {
3812 .add_virtual_intf
= ieee80211_add_iface
,
3813 .del_virtual_intf
= ieee80211_del_iface
,
3814 .change_virtual_intf
= ieee80211_change_iface
,
3815 .start_p2p_device
= ieee80211_start_p2p_device
,
3816 .stop_p2p_device
= ieee80211_stop_p2p_device
,
3817 .add_key
= ieee80211_add_key
,
3818 .del_key
= ieee80211_del_key
,
3819 .get_key
= ieee80211_get_key
,
3820 .set_default_key
= ieee80211_config_default_key
,
3821 .set_default_mgmt_key
= ieee80211_config_default_mgmt_key
,
3822 .start_ap
= ieee80211_start_ap
,
3823 .change_beacon
= ieee80211_change_beacon
,
3824 .stop_ap
= ieee80211_stop_ap
,
3825 .add_station
= ieee80211_add_station
,
3826 .del_station
= ieee80211_del_station
,
3827 .change_station
= ieee80211_change_station
,
3828 .get_station
= ieee80211_get_station
,
3829 .dump_station
= ieee80211_dump_station
,
3830 .dump_survey
= ieee80211_dump_survey
,
3831 #ifdef CONFIG_MAC80211_MESH
3832 .add_mpath
= ieee80211_add_mpath
,
3833 .del_mpath
= ieee80211_del_mpath
,
3834 .change_mpath
= ieee80211_change_mpath
,
3835 .get_mpath
= ieee80211_get_mpath
,
3836 .dump_mpath
= ieee80211_dump_mpath
,
3837 .get_mpp
= ieee80211_get_mpp
,
3838 .dump_mpp
= ieee80211_dump_mpp
,
3839 .update_mesh_config
= ieee80211_update_mesh_config
,
3840 .get_mesh_config
= ieee80211_get_mesh_config
,
3841 .join_mesh
= ieee80211_join_mesh
,
3842 .leave_mesh
= ieee80211_leave_mesh
,
3844 .join_ocb
= ieee80211_join_ocb
,
3845 .leave_ocb
= ieee80211_leave_ocb
,
3846 .change_bss
= ieee80211_change_bss
,
3847 .set_txq_params
= ieee80211_set_txq_params
,
3848 .set_monitor_channel
= ieee80211_set_monitor_channel
,
3849 .suspend
= ieee80211_suspend
,
3850 .resume
= ieee80211_resume
,
3851 .scan
= ieee80211_scan
,
3852 .abort_scan
= ieee80211_abort_scan
,
3853 .sched_scan_start
= ieee80211_sched_scan_start
,
3854 .sched_scan_stop
= ieee80211_sched_scan_stop
,
3855 .auth
= ieee80211_auth
,
3856 .assoc
= ieee80211_assoc
,
3857 .deauth
= ieee80211_deauth
,
3858 .disassoc
= ieee80211_disassoc
,
3859 .join_ibss
= ieee80211_join_ibss
,
3860 .leave_ibss
= ieee80211_leave_ibss
,
3861 .set_mcast_rate
= ieee80211_set_mcast_rate
,
3862 .set_wiphy_params
= ieee80211_set_wiphy_params
,
3863 .set_tx_power
= ieee80211_set_tx_power
,
3864 .get_tx_power
= ieee80211_get_tx_power
,
3865 .set_wds_peer
= ieee80211_set_wds_peer
,
3866 .rfkill_poll
= ieee80211_rfkill_poll
,
3867 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd
)
3868 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump
)
3869 .set_power_mgmt
= ieee80211_set_power_mgmt
,
3870 .set_bitrate_mask
= ieee80211_set_bitrate_mask
,
3871 .remain_on_channel
= ieee80211_remain_on_channel
,
3872 .cancel_remain_on_channel
= ieee80211_cancel_remain_on_channel
,
3873 .mgmt_tx
= ieee80211_mgmt_tx
,
3874 .mgmt_tx_cancel_wait
= ieee80211_mgmt_tx_cancel_wait
,
3875 .set_cqm_rssi_config
= ieee80211_set_cqm_rssi_config
,
3876 .set_cqm_rssi_range_config
= ieee80211_set_cqm_rssi_range_config
,
3877 .mgmt_frame_register
= ieee80211_mgmt_frame_register
,
3878 .set_antenna
= ieee80211_set_antenna
,
3879 .get_antenna
= ieee80211_get_antenna
,
3880 .set_rekey_data
= ieee80211_set_rekey_data
,
3881 .tdls_oper
= ieee80211_tdls_oper
,
3882 .tdls_mgmt
= ieee80211_tdls_mgmt
,
3883 .tdls_channel_switch
= ieee80211_tdls_channel_switch
,
3884 .tdls_cancel_channel_switch
= ieee80211_tdls_cancel_channel_switch
,
3885 .probe_client
= ieee80211_probe_client
,
3886 .set_noack_map
= ieee80211_set_noack_map
,
3888 .set_wakeup
= ieee80211_set_wakeup
,
3890 .get_channel
= ieee80211_cfg_get_channel
,
3891 .start_radar_detection
= ieee80211_start_radar_detection
,
3892 .channel_switch
= ieee80211_channel_switch
,
3893 .set_qos_map
= ieee80211_set_qos_map
,
3894 .set_ap_chanwidth
= ieee80211_set_ap_chanwidth
,
3895 .add_tx_ts
= ieee80211_add_tx_ts
,
3896 .del_tx_ts
= ieee80211_del_tx_ts
,
3897 .start_nan
= ieee80211_start_nan
,
3898 .stop_nan
= ieee80211_stop_nan
,
3899 .nan_change_conf
= ieee80211_nan_change_conf
,
3900 .add_nan_func
= ieee80211_add_nan_func
,
3901 .del_nan_func
= ieee80211_del_nan_func
,
3902 .set_multicast_to_unicast
= ieee80211_set_multicast_to_unicast
,
3903 .tx_control_port
= ieee80211_tx_control_port
,
3904 .get_txq_stats
= ieee80211_get_txq_stats
,