1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2021 Intel Corporation
14 #include <linux/delay.h>
15 #include <linux/fips.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/moduleparam.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
32 #include "fils_aead.h"
34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
35 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
36 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
37 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40 #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries
= 2;
47 module_param(max_nullfunc_tries
, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries
,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries
= 5;
52 module_param(max_probe_tries
, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries
,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count
= 7;
65 module_param(beacon_loss_count
, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count
,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms
= 500;
80 module_param(probe_wait_ms
, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms
,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
101 static void run_again(struct ieee80211_sub_if_data
*sdata
,
102 unsigned long timeout
)
104 sdata_assert_lock(sdata
);
106 if (!timer_pending(&sdata
->u
.mgd
.timer
) ||
107 time_before(timeout
, sdata
->u
.mgd
.timer
.expires
))
108 mod_timer(&sdata
->u
.mgd
.timer
, timeout
);
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
113 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
116 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
119 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
120 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
125 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
127 if (unlikely(!ifmgd
->associated
))
130 if (ifmgd
->probe_send_count
)
131 ifmgd
->probe_send_count
= 0;
133 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
136 mod_timer(&ifmgd
->conn_mon_timer
,
137 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
140 static int ecw2cw(int ecw
)
142 return (1 << ecw
) - 1;
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data
*sdata
,
147 struct ieee80211_supported_band
*sband
,
148 struct ieee80211_channel
*channel
,
150 const struct ieee80211_ht_operation
*ht_oper
,
151 const struct ieee80211_vht_operation
*vht_oper
,
152 const struct ieee80211_he_operation
*he_oper
,
153 const struct ieee80211_s1g_oper_ie
*s1g_oper
,
154 struct cfg80211_chan_def
*chandef
, bool tracking
)
156 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
157 struct cfg80211_chan_def vht_chandef
;
158 struct ieee80211_sta_ht_cap sta_ht_cap
;
161 memset(chandef
, 0, sizeof(struct cfg80211_chan_def
));
162 chandef
->chan
= channel
;
163 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
164 chandef
->center_freq1
= channel
->center_freq
;
165 chandef
->freq1_offset
= channel
->freq_offset
;
167 if (channel
->band
== NL80211_BAND_6GHZ
) {
168 if (!ieee80211_chandef_he_6ghz_oper(sdata
, he_oper
, chandef
))
169 ret
= IEEE80211_STA_DISABLE_HT
|
170 IEEE80211_STA_DISABLE_VHT
|
171 IEEE80211_STA_DISABLE_HE
;
174 vht_chandef
= *chandef
;
176 } else if (sband
->band
== NL80211_BAND_S1GHZ
) {
177 if (!ieee80211_chandef_s1g_oper(s1g_oper
, chandef
)) {
179 "Missing S1G Operation Element? Trying operating == primary\n");
180 chandef
->width
= ieee80211_s1g_channel_width(channel
);
183 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_40MHZ
|
184 IEEE80211_STA_DISABLE_VHT
|
185 IEEE80211_STA_DISABLE_80P80MHZ
|
186 IEEE80211_STA_DISABLE_160MHZ
;
190 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
191 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
193 if (!ht_oper
|| !sta_ht_cap
.ht_supported
) {
194 ret
= IEEE80211_STA_DISABLE_HT
|
195 IEEE80211_STA_DISABLE_VHT
|
196 IEEE80211_STA_DISABLE_HE
;
200 chandef
->width
= NL80211_CHAN_WIDTH_20
;
202 ht_cfreq
= ieee80211_channel_to_frequency(ht_oper
->primary_chan
,
204 /* check that channel matches the right operating channel */
205 if (!tracking
&& channel
->center_freq
!= ht_cfreq
) {
207 * It's possible that some APs are confused here;
208 * Netgear WNDR3700 sometimes reports 4 higher than
209 * the actual channel in association responses, but
210 * since we look at probe response/beacon data here
214 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
215 channel
->center_freq
, ht_cfreq
,
216 ht_oper
->primary_chan
, channel
->band
);
217 ret
= IEEE80211_STA_DISABLE_HT
|
218 IEEE80211_STA_DISABLE_VHT
|
219 IEEE80211_STA_DISABLE_HE
;
223 /* check 40 MHz support, if we have it */
224 if (sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) {
225 ieee80211_chandef_ht_oper(ht_oper
, chandef
);
227 /* 40 MHz (and 80 MHz) must be supported for VHT */
228 ret
= IEEE80211_STA_DISABLE_VHT
;
229 /* also mark 40 MHz disabled */
230 ret
|= IEEE80211_STA_DISABLE_40MHZ
;
234 if (!vht_oper
|| !sband
->vht_cap
.vht_supported
) {
235 ret
= IEEE80211_STA_DISABLE_VHT
;
239 vht_chandef
= *chandef
;
240 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) && he_oper
&&
241 (le32_to_cpu(he_oper
->he_oper_params
) &
242 IEEE80211_HE_OPERATION_VHT_OPER_INFO
)) {
243 struct ieee80211_vht_operation he_oper_vht_cap
;
246 * Set only first 3 bytes (other 2 aren't used in
247 * ieee80211_chandef_vht_oper() anyway)
249 memcpy(&he_oper_vht_cap
, he_oper
->optional
, 3);
250 he_oper_vht_cap
.basic_mcs_set
= cpu_to_le16(0);
252 if (!ieee80211_chandef_vht_oper(&sdata
->local
->hw
, vht_cap_info
,
253 &he_oper_vht_cap
, ht_oper
,
255 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
))
257 "HE AP VHT information is invalid, disable HE\n");
258 ret
= IEEE80211_STA_DISABLE_HE
;
261 } else if (!ieee80211_chandef_vht_oper(&sdata
->local
->hw
,
265 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
267 "AP VHT information is invalid, disable VHT\n");
268 ret
= IEEE80211_STA_DISABLE_VHT
;
272 if (!cfg80211_chandef_valid(&vht_chandef
)) {
273 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
275 "AP VHT information is invalid, disable VHT\n");
276 ret
= IEEE80211_STA_DISABLE_VHT
;
280 if (cfg80211_chandef_identical(chandef
, &vht_chandef
)) {
285 if (!cfg80211_chandef_compatible(chandef
, &vht_chandef
)) {
286 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
288 "AP VHT information doesn't match HT, disable VHT\n");
289 ret
= IEEE80211_STA_DISABLE_VHT
;
293 *chandef
= vht_chandef
;
299 * When tracking the current AP, don't do any further checks if the
300 * new chandef is identical to the one we're currently using for the
301 * connection. This keeps us from playing ping-pong with regulatory,
302 * without it the following can happen (for example):
303 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
304 * - AP advertises regdom US
305 * - CRDA loads regdom US with 80 MHz prohibited (old database)
306 * - the code below detects an unsupported channel, downgrades, and
307 * we disconnect from the AP in the caller
308 * - disconnect causes CRDA to reload world regdomain and the game
310 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
312 * It seems possible that there are still scenarios with CSA or real
313 * bandwidth changes where a this could happen, but those cases are
314 * less common and wouldn't completely prevent using the AP.
317 cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
))
320 /* don't print the message below for VHT mismatch if VHT is disabled */
321 if (ret
& IEEE80211_STA_DISABLE_VHT
)
322 vht_chandef
= *chandef
;
325 * Ignore the DISABLED flag when we're already connected and only
326 * tracking the APs beacon for bandwidth changes - otherwise we
327 * might get disconnected here if we connect to an AP, update our
328 * regulatory information based on the AP's country IE and the
329 * information we have is wrong/outdated and disables the channel
330 * that we're actually using for the connection to the AP.
332 while (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
334 IEEE80211_CHAN_DISABLED
)) {
335 if (WARN_ON(chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
)) {
336 ret
= IEEE80211_STA_DISABLE_HT
|
337 IEEE80211_STA_DISABLE_VHT
|
338 IEEE80211_STA_DISABLE_HE
;
342 ret
|= ieee80211_chandef_downgrade(chandef
);
345 if (!he_oper
|| !cfg80211_chandef_usable(sdata
->wdev
.wiphy
, chandef
,
346 IEEE80211_CHAN_NO_HE
))
347 ret
|= IEEE80211_STA_DISABLE_HE
;
349 if (chandef
->width
!= vht_chandef
.width
&& !tracking
)
351 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
353 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef
));
357 static int ieee80211_config_bw(struct ieee80211_sub_if_data
*sdata
,
358 struct sta_info
*sta
,
359 const struct ieee80211_ht_cap
*ht_cap
,
360 const struct ieee80211_vht_cap
*vht_cap
,
361 const struct ieee80211_ht_operation
*ht_oper
,
362 const struct ieee80211_vht_operation
*vht_oper
,
363 const struct ieee80211_he_operation
*he_oper
,
364 const struct ieee80211_s1g_oper_ie
*s1g_oper
,
365 const u8
*bssid
, u32
*changed
)
367 struct ieee80211_local
*local
= sdata
->local
;
368 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
369 struct ieee80211_channel
*chan
= sdata
->vif
.bss_conf
.chandef
.chan
;
370 struct ieee80211_supported_band
*sband
=
371 local
->hw
.wiphy
->bands
[chan
->band
];
372 struct cfg80211_chan_def chandef
;
375 u32 vht_cap_info
= 0;
378 /* if HT was/is disabled, don't track any bandwidth changes */
379 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
|| !ht_oper
)
382 /* don't check VHT if we associated as non-VHT station */
383 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
386 /* don't check HE if we associated as non-HE station */
387 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
||
388 !ieee80211_get_he_iftype_cap(sband
,
389 ieee80211_vif_type_p2p(&sdata
->vif
)))
393 if (WARN_ON_ONCE(!sta
))
397 * if bss configuration changed store the new one -
398 * this may be applicable even if channel is identical
400 ht_opmode
= le16_to_cpu(ht_oper
->operation_mode
);
401 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
402 *changed
|= BSS_CHANGED_HT
;
403 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
407 vht_cap_info
= le32_to_cpu(vht_cap
->vht_cap_info
);
409 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
410 flags
= ieee80211_determine_chantype(sdata
, sband
, chan
, vht_cap_info
,
411 ht_oper
, vht_oper
, he_oper
,
412 s1g_oper
, &chandef
, true);
415 * Downgrade the new channel if we associated with restricted
416 * capabilities. For example, if we associated as a 20 MHz STA
417 * to a 40 MHz AP (due to regulatory, capabilities or config
418 * reasons) then switching to a 40 MHz channel now won't do us
419 * any good -- we couldn't use it with the AP.
421 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_80P80MHZ
&&
422 chandef
.width
== NL80211_CHAN_WIDTH_80P80
)
423 flags
|= ieee80211_chandef_downgrade(&chandef
);
424 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_160MHZ
&&
425 chandef
.width
== NL80211_CHAN_WIDTH_160
)
426 flags
|= ieee80211_chandef_downgrade(&chandef
);
427 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
&&
428 chandef
.width
> NL80211_CHAN_WIDTH_20
)
429 flags
|= ieee80211_chandef_downgrade(&chandef
);
431 if (cfg80211_chandef_identical(&chandef
, &sdata
->vif
.bss_conf
.chandef
))
435 "AP %pM changed bandwidth, new config is %d.%03d MHz, "
436 "width %d (%d.%03d/%d MHz)\n",
437 ifmgd
->bssid
, chandef
.chan
->center_freq
,
438 chandef
.chan
->freq_offset
, chandef
.width
,
439 chandef
.center_freq1
, chandef
.freq1_offset
,
440 chandef
.center_freq2
);
442 if (flags
!= (ifmgd
->flags
& (IEEE80211_STA_DISABLE_HT
|
443 IEEE80211_STA_DISABLE_VHT
|
444 IEEE80211_STA_DISABLE_HE
|
445 IEEE80211_STA_DISABLE_40MHZ
|
446 IEEE80211_STA_DISABLE_80P80MHZ
|
447 IEEE80211_STA_DISABLE_160MHZ
)) ||
448 !cfg80211_chandef_valid(&chandef
)) {
450 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
451 ifmgd
->bssid
, flags
, ifmgd
->flags
);
455 ret
= ieee80211_vif_change_bandwidth(sdata
, &chandef
, changed
);
459 "AP %pM changed bandwidth to incompatible one - disconnect\n",
467 /* frame sending functions */
469 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data
*sdata
,
470 struct sk_buff
*skb
, u8 ap_ht_param
,
471 struct ieee80211_supported_band
*sband
,
472 struct ieee80211_channel
*channel
,
473 enum ieee80211_smps_mode smps
)
476 u32 flags
= channel
->flags
;
478 struct ieee80211_sta_ht_cap ht_cap
;
480 BUILD_BUG_ON(sizeof(ht_cap
) != sizeof(sband
->ht_cap
));
482 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
483 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
485 /* determine capability flags */
488 switch (ap_ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
489 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
490 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
491 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
492 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
495 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
496 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
497 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
498 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
504 * If 40 MHz was disabled associate as though we weren't
505 * capable of 40 MHz -- some broken APs will never fall
506 * back to trying to transmit in 20 MHz.
508 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_40MHZ
) {
509 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
510 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
513 /* set SM PS mode properly */
514 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
516 case IEEE80211_SMPS_AUTOMATIC
:
517 case IEEE80211_SMPS_NUM_MODES
:
520 case IEEE80211_SMPS_OFF
:
521 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
522 IEEE80211_HT_CAP_SM_PS_SHIFT
;
524 case IEEE80211_SMPS_STATIC
:
525 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
526 IEEE80211_HT_CAP_SM_PS_SHIFT
;
528 case IEEE80211_SMPS_DYNAMIC
:
529 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
530 IEEE80211_HT_CAP_SM_PS_SHIFT
;
534 /* reserve and fill IE */
535 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
536 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, cap
);
539 /* This function determines vht capability flags for the association
541 * Note - the function may set the owner of the MU-MIMO capability
543 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data
*sdata
,
545 struct ieee80211_supported_band
*sband
,
546 struct ieee80211_vht_cap
*ap_vht_cap
)
548 struct ieee80211_local
*local
= sdata
->local
;
551 struct ieee80211_sta_vht_cap vht_cap
;
552 u32 mask
, ap_bf_sts
, our_bf_sts
;
554 BUILD_BUG_ON(sizeof(vht_cap
) != sizeof(sband
->vht_cap
));
556 memcpy(&vht_cap
, &sband
->vht_cap
, sizeof(vht_cap
));
557 ieee80211_apply_vhtcap_overrides(sdata
, &vht_cap
);
559 /* determine capability flags */
562 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_80P80MHZ
) {
563 u32 bw
= cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
565 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
566 if (bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
||
567 bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
568 cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
571 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_160MHZ
) {
572 cap
&= ~IEEE80211_VHT_CAP_SHORT_GI_160
;
573 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
577 * Some APs apparently get confused if our capabilities are better
578 * than theirs, so restrict what we advertise in the assoc request.
580 if (!(ap_vht_cap
->vht_cap_info
&
581 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)))
582 cap
&= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
583 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
);
584 else if (!(ap_vht_cap
->vht_cap_info
&
585 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
586 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
589 * If some other vif is using the MU-MIMO capability we cannot associate
590 * using MU-MIMO - this will lead to contradictions in the group-id
592 * Ownership is defined since association request, in order to avoid
593 * simultaneous associations with MU-MIMO.
595 if (cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
) {
596 bool disable_mu_mimo
= false;
597 struct ieee80211_sub_if_data
*other
;
599 list_for_each_entry_rcu(other
, &local
->interfaces
, list
) {
600 if (other
->vif
.mu_mimo_owner
) {
601 disable_mu_mimo
= true;
606 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
608 sdata
->vif
.mu_mimo_owner
= true;
611 mask
= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
613 ap_bf_sts
= le32_to_cpu(ap_vht_cap
->vht_cap_info
) & mask
;
614 our_bf_sts
= cap
& mask
;
616 if (ap_bf_sts
< our_bf_sts
) {
621 /* reserve and fill IE */
622 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
623 ieee80211_ie_build_vht_cap(pos
, &vht_cap
, cap
);
626 /* This function determines HE capability flags for the association
629 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data
*sdata
,
631 struct ieee80211_supported_band
*sband
)
634 const struct ieee80211_sta_he_cap
*he_cap
= NULL
;
635 struct ieee80211_chanctx_conf
*chanctx_conf
;
637 bool reg_cap
= false;
640 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
641 if (!WARN_ON_ONCE(!chanctx_conf
))
642 reg_cap
= cfg80211_chandef_usable(sdata
->wdev
.wiphy
,
644 IEEE80211_CHAN_NO_HE
);
648 he_cap
= ieee80211_get_he_iftype_cap(sband
,
649 ieee80211_vif_type_p2p(&sdata
->vif
));
650 if (!he_cap
|| !reg_cap
)
654 2 + 1 + sizeof(he_cap
->he_cap_elem
) +
655 ieee80211_he_mcs_nss_size(&he_cap
->he_cap_elem
) +
656 ieee80211_he_ppe_size(he_cap
->ppe_thres
[0],
657 he_cap
->he_cap_elem
.phy_cap_info
);
658 pos
= skb_put(skb
, he_cap_size
);
659 ieee80211_ie_build_he_cap(pos
, he_cap
, pos
+ he_cap_size
);
661 ieee80211_ie_build_he_6ghz_cap(sdata
, skb
);
664 static int ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
)
666 struct ieee80211_local
*local
= sdata
->local
;
667 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
668 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
670 struct ieee80211_mgmt
*mgmt
;
671 u8
*pos
, qos_info
, *ie_start
;
672 size_t offset
= 0, noffset
;
673 int i
, count
, rates_len
, supp_rates_len
, shift
;
675 struct ieee80211_supported_band
*sband
;
676 struct ieee80211_chanctx_conf
*chanctx_conf
;
677 struct ieee80211_channel
*chan
;
680 struct element
*ext_capa
= NULL
;
681 enum nl80211_iftype iftype
= ieee80211_vif_type_p2p(&sdata
->vif
);
682 const struct ieee80211_sband_iftype_data
*iftd
;
683 struct ieee80211_prep_tx_info info
= {};
686 /* we know it's writable, cast away the const */
687 if (assoc_data
->ie_len
)
688 ext_capa
= (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY
,
692 sdata_assert_lock(sdata
);
695 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
696 if (WARN_ON(!chanctx_conf
)) {
700 chan
= chanctx_conf
->def
.chan
;
702 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
703 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
705 if (assoc_data
->supp_rates_len
) {
707 * Get all rates supported by the device and the AP as
708 * some APs don't like getting a superset of their rates
709 * in the association request (e.g. D-Link DAP 1353 in
712 rates_len
= ieee80211_parse_bitrates(&chanctx_conf
->def
, sband
,
713 assoc_data
->supp_rates
,
714 assoc_data
->supp_rates_len
,
718 * In case AP not provide any supported rates information
719 * before association, we send information element(s) with
720 * all rates that we support.
723 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
729 iftd
= ieee80211_get_sband_iftype_data(sband
, iftype
);
731 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
732 sizeof(*mgmt
) + /* bit too much but doesn't matter */
733 2 + assoc_data
->ssid_len
+ /* SSID */
734 4 + rates_len
+ /* (extended) rates */
735 4 + /* power capability */
736 2 + 2 * sband
->n_channels
+ /* supported channels */
737 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
738 2 + sizeof(struct ieee80211_vht_cap
) + /* VHT */
739 2 + 1 + sizeof(struct ieee80211_he_cap_elem
) + /* HE */
740 sizeof(struct ieee80211_he_mcs_nss_supp
) +
741 IEEE80211_HE_PPE_THRES_MAX_LEN
+
742 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa
) +
743 assoc_data
->ie_len
+ /* extra IEs */
744 (assoc_data
->fils_kek_len
? 16 /* AES-SIV */ : 0) +
746 (iftd
? iftd
->vendor_elems
.len
: 0),
751 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
753 capab
= WLAN_CAPABILITY_ESS
;
755 if (sband
->band
== NL80211_BAND_2GHZ
) {
756 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
757 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
760 if (assoc_data
->capability
& WLAN_CAPABILITY_PRIVACY
)
761 capab
|= WLAN_CAPABILITY_PRIVACY
;
763 if ((assoc_data
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
764 ieee80211_hw_check(&local
->hw
, SPECTRUM_MGMT
))
765 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
767 if (ifmgd
->flags
& IEEE80211_STA_ENABLE_RRM
)
768 capab
|= WLAN_CAPABILITY_RADIO_MEASURE
;
770 mgmt
= skb_put_zero(skb
, 24);
771 memcpy(mgmt
->da
, assoc_data
->bss
->bssid
, ETH_ALEN
);
772 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
773 memcpy(mgmt
->bssid
, assoc_data
->bss
->bssid
, ETH_ALEN
);
775 listen_int
= cpu_to_le16(sband
->band
== NL80211_BAND_S1GHZ
?
776 ieee80211_encode_usf(local
->hw
.conf
.listen_interval
) :
777 local
->hw
.conf
.listen_interval
);
778 if (!is_zero_ether_addr(assoc_data
->prev_bssid
)) {
780 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
781 IEEE80211_STYPE_REASSOC_REQ
);
782 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
783 mgmt
->u
.reassoc_req
.listen_interval
= listen_int
;
784 memcpy(mgmt
->u
.reassoc_req
.current_ap
, assoc_data
->prev_bssid
,
786 info
.subtype
= IEEE80211_STYPE_REASSOC_REQ
;
789 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
790 IEEE80211_STYPE_ASSOC_REQ
);
791 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
792 mgmt
->u
.assoc_req
.listen_interval
= listen_int
;
793 info
.subtype
= IEEE80211_STYPE_ASSOC_REQ
;
797 pos
= skb_put(skb
, 2 + assoc_data
->ssid_len
);
799 *pos
++ = WLAN_EID_SSID
;
800 *pos
++ = assoc_data
->ssid_len
;
801 memcpy(pos
, assoc_data
->ssid
, assoc_data
->ssid_len
);
803 if (sband
->band
== NL80211_BAND_S1GHZ
)
806 /* add all rates which were marked to be used above */
807 supp_rates_len
= rates_len
;
808 if (supp_rates_len
> 8)
811 pos
= skb_put(skb
, supp_rates_len
+ 2);
812 *pos
++ = WLAN_EID_SUPP_RATES
;
813 *pos
++ = supp_rates_len
;
816 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
817 if (BIT(i
) & rates
) {
818 int rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
826 if (rates_len
> count
) {
827 pos
= skb_put(skb
, rates_len
- count
+ 2);
828 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
829 *pos
++ = rates_len
- count
;
831 for (i
++; i
< sband
->n_bitrates
; i
++) {
832 if (BIT(i
) & rates
) {
834 rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
842 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
||
843 capab
& WLAN_CAPABILITY_RADIO_MEASURE
) {
844 pos
= skb_put(skb
, 4);
845 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
847 *pos
++ = 0; /* min tx power */
849 *pos
++ = ieee80211_chandef_max_power(&chanctx_conf
->def
);
853 * Per spec, we shouldn't include the list of channels if we advertise
854 * support for extended channel switching, but we've always done that;
855 * (for now?) apply this restriction only on the (new) 6 GHz band.
857 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
&&
858 (sband
->band
!= NL80211_BAND_6GHZ
||
859 !ext_capa
|| ext_capa
->datalen
< 1 ||
860 !(ext_capa
->data
[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING
))) {
861 /* TODO: get this in reg domain format */
862 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
863 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
864 *pos
++ = 2 * sband
->n_channels
;
865 for (i
= 0; i
< sband
->n_channels
; i
++) {
866 *pos
++ = ieee80211_frequency_to_channel(
867 sband
->channels
[i
].center_freq
);
868 *pos
++ = 1; /* one channel in the subband*/
872 /* Set MBSSID support for HE AP if needed */
873 if (ieee80211_hw_check(&local
->hw
, SUPPORTS_ONLY_HE_MULTI_BSSID
) &&
874 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) && assoc_data
->ie_len
&&
875 ext_capa
&& ext_capa
->datalen
>= 3)
876 ext_capa
->data
[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT
;
878 /* if present, add any custom IEs that go before HT */
879 if (assoc_data
->ie_len
) {
880 static const u8 before_ht
[] = {
883 WLAN_EID_EXT_SUPP_RATES
,
884 WLAN_EID_PWR_CAPABILITY
,
885 WLAN_EID_SUPPORTED_CHANNELS
,
888 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
889 WLAN_EID_MOBILITY_DOMAIN
,
890 WLAN_EID_FAST_BSS_TRANSITION
, /* reassoc only */
891 WLAN_EID_RIC_DATA
, /* reassoc only */
892 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
894 static const u8 after_ric
[] = {
895 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
896 WLAN_EID_HT_CAPABILITY
,
897 WLAN_EID_BSS_COEX_2040
,
898 /* luckily this is almost always there */
899 WLAN_EID_EXT_CAPABILITY
,
900 WLAN_EID_QOS_TRAFFIC_CAPA
,
901 WLAN_EID_TIM_BCAST_REQ
,
902 WLAN_EID_INTERWORKING
,
903 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
904 WLAN_EID_VHT_CAPABILITY
,
905 WLAN_EID_OPMODE_NOTIF
,
908 noffset
= ieee80211_ie_split_ric(assoc_data
->ie
,
911 ARRAY_SIZE(before_ht
),
913 ARRAY_SIZE(after_ric
),
915 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
919 if (WARN_ON_ONCE((ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
920 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)))
921 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
923 if (sband
->band
!= NL80211_BAND_6GHZ
&&
924 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
925 ieee80211_add_ht_ie(sdata
, skb
, assoc_data
->ap_ht_param
,
926 sband
, chan
, sdata
->smps_mode
);
928 /* if present, add any custom IEs that go before VHT */
929 if (assoc_data
->ie_len
) {
930 static const u8 before_vht
[] = {
932 * no need to list the ones split off before HT
935 WLAN_EID_BSS_COEX_2040
,
936 WLAN_EID_EXT_CAPABILITY
,
937 WLAN_EID_QOS_TRAFFIC_CAPA
,
938 WLAN_EID_TIM_BCAST_REQ
,
939 WLAN_EID_INTERWORKING
,
940 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
943 /* RIC already taken above, so no need to handle here anymore */
944 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
945 before_vht
, ARRAY_SIZE(before_vht
),
947 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
951 /* if present, add any custom IEs that go before HE */
952 if (assoc_data
->ie_len
) {
953 static const u8 before_he
[] = {
955 * no need to list the ones split off before VHT
958 WLAN_EID_OPMODE_NOTIF
,
959 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE
,
961 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_SESSION
,
962 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_PUBLIC_KEY
,
963 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_KEY_CONFIRM
,
964 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_HLP_CONTAINER
,
965 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN
,
966 /* TODO: add 11ah/11aj/11ak elements */
969 /* RIC already taken above, so no need to handle here anymore */
970 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
971 before_he
, ARRAY_SIZE(before_he
),
973 pos
= skb_put(skb
, noffset
- offset
);
974 memcpy(pos
, assoc_data
->ie
+ offset
, noffset
- offset
);
978 if (sband
->band
!= NL80211_BAND_6GHZ
&&
979 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
980 ieee80211_add_vht_ie(sdata
, skb
, sband
,
981 &assoc_data
->ap_vht_cap
);
984 * If AP doesn't support HT, mark HE as disabled.
985 * If on the 5GHz band, make sure it supports VHT.
987 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
||
988 (sband
->band
== NL80211_BAND_5GHZ
&&
989 ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
990 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
992 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
))
993 ieee80211_add_he_ie(sdata
, skb
, sband
);
995 /* if present, add any custom non-vendor IEs that go after HE */
996 if (assoc_data
->ie_len
) {
997 noffset
= ieee80211_ie_split_vendor(assoc_data
->ie
,
1000 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
1004 if (assoc_data
->wmm
) {
1005 if (assoc_data
->uapsd
) {
1006 qos_info
= ifmgd
->uapsd_queues
;
1007 qos_info
|= (ifmgd
->uapsd_max_sp_len
<<
1008 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
1013 pos
= ieee80211_add_wmm_info_ie(skb_put(skb
, 9), qos_info
);
1016 if (sband
->band
== NL80211_BAND_S1GHZ
) {
1017 ieee80211_add_aid_request_ie(sdata
, skb
);
1018 ieee80211_add_s1g_capab_ie(sdata
, &sband
->s1g_cap
, skb
);
1021 if (iftd
&& iftd
->vendor_elems
.data
&& iftd
->vendor_elems
.len
)
1022 skb_put_data(skb
, iftd
->vendor_elems
.data
, iftd
->vendor_elems
.len
);
1024 /* add any remaining custom (i.e. vendor specific here) IEs */
1025 if (assoc_data
->ie_len
) {
1026 noffset
= assoc_data
->ie_len
;
1027 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
1030 if (assoc_data
->fils_kek_len
) {
1031 ret
= fils_encrypt_assoc_req(skb
, assoc_data
);
1038 pos
= skb_tail_pointer(skb
);
1039 kfree(ifmgd
->assoc_req_ies
);
1040 ifmgd
->assoc_req_ies
= kmemdup(ie_start
, pos
- ie_start
, GFP_ATOMIC
);
1041 if (!ifmgd
->assoc_req_ies
) {
1046 ifmgd
->assoc_req_ies_len
= pos
- ie_start
;
1048 drv_mgd_prepare_tx(local
, sdata
, &info
);
1050 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
1051 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1052 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
1053 IEEE80211_TX_INTFL_MLME_CONN_TX
;
1054 ieee80211_tx_skb(sdata
, skb
);
1059 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
1060 struct ieee80211_sub_if_data
*sdata
)
1062 struct ieee80211_pspoll
*pspoll
;
1063 struct sk_buff
*skb
;
1065 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
1069 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
1070 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1072 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
1073 ieee80211_tx_skb(sdata
, skb
);
1076 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
1077 struct ieee80211_sub_if_data
*sdata
,
1080 struct sk_buff
*skb
;
1081 struct ieee80211_hdr_3addr
*nullfunc
;
1082 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1084 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
,
1085 !ieee80211_hw_check(&local
->hw
, DOESNT_SUPPORT_QOS_NDP
));
1089 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
1091 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1093 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
1094 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
1096 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1097 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
1099 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1100 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
1102 ieee80211_tx_skb(sdata
, skb
);
1105 void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
1106 struct ieee80211_sub_if_data
*sdata
)
1108 struct sk_buff
*skb
;
1109 struct ieee80211_hdr
*nullfunc
;
1112 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
1115 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
1119 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1121 nullfunc
= skb_put_zero(skb
, 30);
1122 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
1123 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
1124 nullfunc
->frame_control
= fc
;
1125 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
1126 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
1127 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
1128 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
1130 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
1131 ieee80211_tx_skb(sdata
, skb
);
1134 /* spectrum management related things */
1135 static void ieee80211_chswitch_work(struct work_struct
*work
)
1137 struct ieee80211_sub_if_data
*sdata
=
1138 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
1139 struct ieee80211_local
*local
= sdata
->local
;
1140 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1143 if (!ieee80211_sdata_running(sdata
))
1147 mutex_lock(&local
->mtx
);
1148 mutex_lock(&local
->chanctx_mtx
);
1150 if (!ifmgd
->associated
)
1153 if (!sdata
->vif
.csa_active
)
1157 * using reservation isn't immediate as it may be deferred until later
1158 * with multi-vif. once reservation is complete it will re-schedule the
1159 * work with no reserved_chanctx so verify chandef to check if it
1160 * completed successfully
1163 if (sdata
->reserved_chanctx
) {
1165 * with multi-vif csa driver may call ieee80211_csa_finish()
1166 * many times while waiting for other interfaces to use their
1169 if (sdata
->reserved_ready
)
1172 ret
= ieee80211_vif_use_reserved_context(sdata
);
1175 "failed to use reserved channel context, disconnecting (err=%d)\n",
1177 ieee80211_queue_work(&sdata
->local
->hw
,
1178 &ifmgd
->csa_connection_drop_work
);
1185 if (!cfg80211_chandef_identical(&sdata
->vif
.bss_conf
.chandef
,
1186 &sdata
->csa_chandef
)) {
1188 "failed to finalize channel switch, disconnecting\n");
1189 ieee80211_queue_work(&sdata
->local
->hw
,
1190 &ifmgd
->csa_connection_drop_work
);
1194 ifmgd
->csa_waiting_bcn
= true;
1196 ieee80211_sta_reset_beacon_monitor(sdata
);
1197 ieee80211_sta_reset_conn_monitor(sdata
);
1200 mutex_unlock(&local
->chanctx_mtx
);
1201 mutex_unlock(&local
->mtx
);
1202 sdata_unlock(sdata
);
1205 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data
*sdata
)
1207 struct ieee80211_local
*local
= sdata
->local
;
1208 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1211 sdata_assert_lock(sdata
);
1213 WARN_ON(!sdata
->vif
.csa_active
);
1215 if (sdata
->csa_block_tx
) {
1216 ieee80211_wake_vif_queues(local
, sdata
,
1217 IEEE80211_QUEUE_STOP_REASON_CSA
);
1218 sdata
->csa_block_tx
= false;
1221 sdata
->vif
.csa_active
= false;
1222 ifmgd
->csa_waiting_bcn
= false;
1224 * If the CSA IE is still present on the beacon after the switch,
1225 * we need to consider it as a new CSA (possibly to self).
1227 ifmgd
->beacon_crc_valid
= false;
1229 ret
= drv_post_channel_switch(sdata
);
1232 "driver post channel switch failed, disconnecting\n");
1233 ieee80211_queue_work(&local
->hw
,
1234 &ifmgd
->csa_connection_drop_work
);
1238 cfg80211_ch_switch_notify(sdata
->dev
, &sdata
->reserved_chandef
);
1241 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
1243 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1244 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1246 trace_api_chswitch_done(sdata
, success
);
1249 "driver channel switch failed, disconnecting\n");
1250 ieee80211_queue_work(&sdata
->local
->hw
,
1251 &ifmgd
->csa_connection_drop_work
);
1253 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
1256 EXPORT_SYMBOL(ieee80211_chswitch_done
);
1258 static void ieee80211_chswitch_timer(struct timer_list
*t
)
1260 struct ieee80211_sub_if_data
*sdata
=
1261 from_timer(sdata
, t
, u
.mgd
.chswitch_timer
);
1263 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->u
.mgd
.chswitch_work
);
1267 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data
*sdata
)
1269 struct ieee80211_local
*local
= sdata
->local
;
1271 if (!local
->ops
->abort_channel_switch
)
1274 mutex_lock(&local
->mtx
);
1276 mutex_lock(&local
->chanctx_mtx
);
1277 ieee80211_vif_unreserve_chanctx(sdata
);
1278 mutex_unlock(&local
->chanctx_mtx
);
1280 if (sdata
->csa_block_tx
)
1281 ieee80211_wake_vif_queues(local
, sdata
,
1282 IEEE80211_QUEUE_STOP_REASON_CSA
);
1284 sdata
->csa_block_tx
= false;
1285 sdata
->vif
.csa_active
= false;
1287 mutex_unlock(&local
->mtx
);
1289 drv_abort_channel_switch(sdata
);
1293 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
1294 u64 timestamp
, u32 device_timestamp
,
1295 struct ieee802_11_elems
*elems
,
1298 struct ieee80211_local
*local
= sdata
->local
;
1299 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1300 struct cfg80211_bss
*cbss
= ifmgd
->associated
;
1301 struct ieee80211_chanctx_conf
*conf
;
1302 struct ieee80211_chanctx
*chanctx
;
1303 enum nl80211_band current_band
;
1304 struct ieee80211_csa_ie csa_ie
;
1305 struct ieee80211_channel_switch ch_switch
;
1306 struct ieee80211_bss
*bss
;
1309 sdata_assert_lock(sdata
);
1314 if (local
->scanning
)
1317 current_band
= cbss
->channel
->band
;
1318 bss
= (void *)cbss
->priv
;
1319 res
= ieee80211_parse_ch_switch_ie(sdata
, elems
, current_band
,
1322 ifmgd
->associated
->bssid
, &csa_ie
);
1325 ch_switch
.timestamp
= timestamp
;
1326 ch_switch
.device_timestamp
= device_timestamp
;
1327 ch_switch
.block_tx
= csa_ie
.mode
;
1328 ch_switch
.chandef
= csa_ie
.chandef
;
1329 ch_switch
.count
= csa_ie
.count
;
1330 ch_switch
.delay
= csa_ie
.max_switch_time
;
1334 goto lock_and_drop_connection
;
1336 if (beacon
&& sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
) {
1338 ieee80211_sta_abort_chanswitch(sdata
);
1340 drv_channel_switch_rx_beacon(sdata
, &ch_switch
);
1342 } else if (sdata
->vif
.csa_active
|| res
) {
1343 /* disregard subsequent announcements if already processing */
1347 if (sdata
->vif
.bss_conf
.chandef
.chan
->band
!=
1348 csa_ie
.chandef
.chan
->band
) {
1350 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1351 ifmgd
->associated
->bssid
,
1352 csa_ie
.chandef
.chan
->center_freq
,
1353 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1354 csa_ie
.chandef
.center_freq2
);
1355 goto lock_and_drop_connection
;
1358 if (!cfg80211_chandef_usable(local
->hw
.wiphy
, &csa_ie
.chandef
,
1359 IEEE80211_CHAN_DISABLED
)) {
1361 "AP %pM switches to unsupported channel "
1362 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1364 ifmgd
->associated
->bssid
,
1365 csa_ie
.chandef
.chan
->center_freq
,
1366 csa_ie
.chandef
.chan
->freq_offset
,
1367 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1368 csa_ie
.chandef
.freq1_offset
,
1369 csa_ie
.chandef
.center_freq2
);
1370 goto lock_and_drop_connection
;
1373 if (cfg80211_chandef_identical(&csa_ie
.chandef
,
1374 &sdata
->vif
.bss_conf
.chandef
) &&
1375 (!csa_ie
.mode
|| !beacon
)) {
1376 if (ifmgd
->csa_ignored_same_chan
)
1379 "AP %pM tries to chanswitch to same channel, ignore\n",
1380 ifmgd
->associated
->bssid
);
1381 ifmgd
->csa_ignored_same_chan
= true;
1386 * Drop all TDLS peers - either we disconnect or move to a different
1387 * channel from this point on. There's no telling what our peer will do.
1388 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1389 * have an incompatible wider chandef.
1391 ieee80211_teardown_tdls_peers(sdata
);
1393 mutex_lock(&local
->mtx
);
1394 mutex_lock(&local
->chanctx_mtx
);
1395 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1396 lockdep_is_held(&local
->chanctx_mtx
));
1399 "no channel context assigned to vif?, disconnecting\n");
1400 goto drop_connection
;
1403 chanctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1405 if (local
->use_chanctx
&&
1406 !ieee80211_hw_check(&local
->hw
, CHANCTX_STA_CSA
)) {
1408 "driver doesn't support chan-switch with channel contexts\n");
1409 goto drop_connection
;
1412 if (drv_pre_channel_switch(sdata
, &ch_switch
)) {
1414 "preparing for channel switch failed, disconnecting\n");
1415 goto drop_connection
;
1418 res
= ieee80211_vif_reserve_chanctx(sdata
, &csa_ie
.chandef
,
1419 chanctx
->mode
, false);
1422 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1424 goto drop_connection
;
1426 mutex_unlock(&local
->chanctx_mtx
);
1428 sdata
->vif
.csa_active
= true;
1429 sdata
->csa_chandef
= csa_ie
.chandef
;
1430 sdata
->csa_block_tx
= csa_ie
.mode
;
1431 ifmgd
->csa_ignored_same_chan
= false;
1432 ifmgd
->beacon_crc_valid
= false;
1434 if (sdata
->csa_block_tx
)
1435 ieee80211_stop_vif_queues(local
, sdata
,
1436 IEEE80211_QUEUE_STOP_REASON_CSA
);
1437 mutex_unlock(&local
->mtx
);
1439 cfg80211_ch_switch_started_notify(sdata
->dev
, &csa_ie
.chandef
,
1440 csa_ie
.count
, csa_ie
.mode
);
1442 if (local
->ops
->channel_switch
) {
1443 /* use driver's channel switch callback */
1444 drv_channel_switch(local
, sdata
, &ch_switch
);
1448 /* channel switch handled in software */
1449 if (csa_ie
.count
<= 1)
1450 ieee80211_queue_work(&local
->hw
, &ifmgd
->chswitch_work
);
1452 mod_timer(&ifmgd
->chswitch_timer
,
1453 TU_TO_EXP_TIME((csa_ie
.count
- 1) *
1454 cbss
->beacon_interval
));
1456 lock_and_drop_connection
:
1457 mutex_lock(&local
->mtx
);
1458 mutex_lock(&local
->chanctx_mtx
);
1461 * This is just so that the disconnect flow will know that
1462 * we were trying to switch channel and failed. In case the
1463 * mode is 1 (we are not allowed to Tx), we will know not to
1464 * send a deauthentication frame. Those two fields will be
1465 * reset when the disconnection worker runs.
1467 sdata
->vif
.csa_active
= true;
1468 sdata
->csa_block_tx
= csa_ie
.mode
;
1470 ieee80211_queue_work(&local
->hw
, &ifmgd
->csa_connection_drop_work
);
1471 mutex_unlock(&local
->chanctx_mtx
);
1472 mutex_unlock(&local
->mtx
);
1476 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1477 struct ieee80211_channel
*channel
,
1478 const u8
*country_ie
, u8 country_ie_len
,
1479 const u8
*pwr_constr_elem
,
1480 int *chan_pwr
, int *pwr_reduction
)
1482 struct ieee80211_country_ie_triplet
*triplet
;
1483 int chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1484 int i
, chan_increment
;
1485 bool have_chan_pwr
= false;
1488 if (country_ie_len
% 2 || country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1491 triplet
= (void *)(country_ie
+ 3);
1492 country_ie_len
-= 3;
1494 switch (channel
->band
) {
1498 case NL80211_BAND_2GHZ
:
1499 case NL80211_BAND_60GHZ
:
1502 case NL80211_BAND_5GHZ
:
1505 case NL80211_BAND_6GHZ
:
1507 * In the 6 GHz band, the "maximum transmit power level"
1508 * field in the triplets is reserved, and thus will be
1509 * zero and we shouldn't use it to control TX power.
1510 * The actual TX power will be given in the transmit
1511 * power envelope element instead.
1517 while (country_ie_len
>= 3) {
1518 u8 first_channel
= triplet
->chans
.first_channel
;
1520 if (first_channel
>= IEEE80211_COUNTRY_EXTENSION_ID
)
1523 for (i
= 0; i
< triplet
->chans
.num_channels
; i
++) {
1524 if (first_channel
+ i
* chan_increment
== chan
) {
1525 have_chan_pwr
= true;
1526 *chan_pwr
= triplet
->chans
.max_power
;
1535 country_ie_len
-= 3;
1538 if (have_chan_pwr
&& pwr_constr_elem
)
1539 *pwr_reduction
= *pwr_constr_elem
;
1543 return have_chan_pwr
;
1546 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data
*sdata
,
1547 struct ieee80211_channel
*channel
,
1548 const u8
*cisco_dtpc_ie
,
1551 /* From practical testing, the first data byte of the DTPC element
1552 * seems to contain the requested dBm level, and the CLI on Cisco
1553 * APs clearly state the range is -127 to 127 dBm, which indicates
1554 * a signed byte, although it seemingly never actually goes negative.
1555 * The other byte seems to always be zero.
1557 *pwr_level
= (__s8
)cisco_dtpc_ie
[4];
1560 static u32
ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1561 struct ieee80211_channel
*channel
,
1562 struct ieee80211_mgmt
*mgmt
,
1563 const u8
*country_ie
, u8 country_ie_len
,
1564 const u8
*pwr_constr_ie
,
1565 const u8
*cisco_dtpc_ie
)
1567 bool has_80211h_pwr
= false, has_cisco_pwr
= false;
1568 int chan_pwr
= 0, pwr_reduction_80211h
= 0;
1569 int pwr_level_cisco
, pwr_level_80211h
;
1571 __le16 capab
= mgmt
->u
.probe_resp
.capab_info
;
1573 if (ieee80211_is_s1g_beacon(mgmt
->frame_control
))
1574 return 0; /* TODO */
1577 (capab
& cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT
) ||
1578 capab
& cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE
))) {
1579 has_80211h_pwr
= ieee80211_find_80211h_pwr_constr(
1580 sdata
, channel
, country_ie
, country_ie_len
,
1581 pwr_constr_ie
, &chan_pwr
, &pwr_reduction_80211h
);
1583 max_t(int, 0, chan_pwr
- pwr_reduction_80211h
);
1586 if (cisco_dtpc_ie
) {
1587 ieee80211_find_cisco_dtpc(
1588 sdata
, channel
, cisco_dtpc_ie
, &pwr_level_cisco
);
1589 has_cisco_pwr
= true;
1592 if (!has_80211h_pwr
&& !has_cisco_pwr
)
1595 /* If we have both 802.11h and Cisco DTPC, apply both limits
1596 * by picking the smallest of the two power levels advertised.
1598 if (has_80211h_pwr
&&
1599 (!has_cisco_pwr
|| pwr_level_80211h
<= pwr_level_cisco
)) {
1600 new_ap_level
= pwr_level_80211h
;
1602 if (sdata
->ap_power_level
== new_ap_level
)
1606 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1607 pwr_level_80211h
, chan_pwr
, pwr_reduction_80211h
,
1608 sdata
->u
.mgd
.bssid
);
1609 } else { /* has_cisco_pwr is always true here. */
1610 new_ap_level
= pwr_level_cisco
;
1612 if (sdata
->ap_power_level
== new_ap_level
)
1616 "Limiting TX power to %d dBm as advertised by %pM\n",
1617 pwr_level_cisco
, sdata
->u
.mgd
.bssid
);
1620 sdata
->ap_power_level
= new_ap_level
;
1621 if (__ieee80211_recalc_txpower(sdata
))
1622 return BSS_CHANGED_TXPOWER
;
1627 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
1628 struct ieee80211_sub_if_data
*sdata
)
1630 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1633 * If we are scanning right now then the parameters will
1634 * take effect when scan finishes.
1636 if (local
->scanning
)
1639 if (conf
->dynamic_ps_timeout
> 0 &&
1640 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
)) {
1641 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1642 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
1644 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
1645 ieee80211_send_nullfunc(local
, sdata
, true);
1647 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1648 ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1651 conf
->flags
|= IEEE80211_CONF_PS
;
1652 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1656 static void ieee80211_change_ps(struct ieee80211_local
*local
)
1658 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1660 if (local
->ps_sdata
) {
1661 ieee80211_enable_ps(local
, local
->ps_sdata
);
1662 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
1663 conf
->flags
&= ~IEEE80211_CONF_PS
;
1664 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1665 del_timer_sync(&local
->dynamic_ps_timer
);
1666 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1670 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
1672 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
1673 struct sta_info
*sta
= NULL
;
1674 bool authorized
= false;
1676 if (!mgd
->powersave
)
1682 if (!mgd
->associated
)
1685 if (mgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1688 if (!mgd
->have_beacon
)
1692 sta
= sta_info_get(sdata
, mgd
->bssid
);
1694 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
1700 /* need to hold RTNL or interface lock */
1701 void ieee80211_recalc_ps(struct ieee80211_local
*local
)
1703 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
1707 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
)) {
1708 local
->ps_sdata
= NULL
;
1712 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1713 if (!ieee80211_sdata_running(sdata
))
1715 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1716 /* If an AP vif is found, then disable PS
1717 * by setting the count to zero thereby setting
1723 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1729 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
1730 u8 dtimper
= found
->u
.mgd
.dtim_period
;
1732 timeout
= local
->dynamic_ps_forced_timeout
;
1735 local
->hw
.conf
.dynamic_ps_timeout
= timeout
;
1737 /* If the TIM IE is invalid, pretend the value is 1 */
1741 local
->hw
.conf
.ps_dtim_period
= dtimper
;
1742 local
->ps_sdata
= found
;
1744 local
->ps_sdata
= NULL
;
1747 ieee80211_change_ps(local
);
1750 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data
*sdata
)
1752 bool ps_allowed
= ieee80211_powersave_allowed(sdata
);
1754 if (sdata
->vif
.bss_conf
.ps
!= ps_allowed
) {
1755 sdata
->vif
.bss_conf
.ps
= ps_allowed
;
1756 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_PS
);
1760 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
1762 struct ieee80211_local
*local
=
1763 container_of(work
, struct ieee80211_local
,
1764 dynamic_ps_disable_work
);
1766 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1767 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1768 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1771 ieee80211_wake_queues_by_reason(&local
->hw
,
1772 IEEE80211_MAX_QUEUE_MAP
,
1773 IEEE80211_QUEUE_STOP_REASON_PS
,
1777 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
1779 struct ieee80211_local
*local
=
1780 container_of(work
, struct ieee80211_local
,
1781 dynamic_ps_enable_work
);
1782 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
1783 struct ieee80211_if_managed
*ifmgd
;
1784 unsigned long flags
;
1787 /* can only happen when PS was just disabled anyway */
1791 ifmgd
= &sdata
->u
.mgd
;
1793 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
1796 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1797 /* don't enter PS if TX frames are pending */
1798 if (drv_tx_frames_pending(local
)) {
1799 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1801 local
->hw
.conf
.dynamic_ps_timeout
));
1806 * transmission can be stopped by others which leads to
1807 * dynamic_ps_timer expiry. Postpone the ps timer if it
1808 * is not the actual idle state.
1810 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1811 for (q
= 0; q
< local
->hw
.queues
; q
++) {
1812 if (local
->queue_stop_reasons
[q
]) {
1813 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1815 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1817 local
->hw
.conf
.dynamic_ps_timeout
));
1821 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1824 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1825 !(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1826 if (drv_tx_frames_pending(local
)) {
1827 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1829 local
->hw
.conf
.dynamic_ps_timeout
));
1831 ieee80211_send_nullfunc(local
, sdata
, true);
1832 /* Flush to get the tx status of nullfunc frame */
1833 ieee80211_flush_queues(local
, sdata
, false);
1837 if (!(ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
) &&
1838 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
)) ||
1839 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1840 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
1841 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
1842 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1846 void ieee80211_dynamic_ps_timer(struct timer_list
*t
)
1848 struct ieee80211_local
*local
= from_timer(local
, t
, dynamic_ps_timer
);
1850 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
1853 void ieee80211_dfs_cac_timer_work(struct work_struct
*work
)
1855 struct delayed_work
*delayed_work
= to_delayed_work(work
);
1856 struct ieee80211_sub_if_data
*sdata
=
1857 container_of(delayed_work
, struct ieee80211_sub_if_data
,
1858 dfs_cac_timer_work
);
1859 struct cfg80211_chan_def chandef
= sdata
->vif
.bss_conf
.chandef
;
1861 mutex_lock(&sdata
->local
->mtx
);
1862 if (sdata
->wdev
.cac_started
) {
1863 ieee80211_vif_release_channel(sdata
);
1864 cfg80211_cac_event(sdata
->dev
, &chandef
,
1865 NL80211_RADAR_CAC_FINISHED
,
1868 mutex_unlock(&sdata
->local
->mtx
);
1872 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1874 struct ieee80211_local
*local
= sdata
->local
;
1875 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1879 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1882 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1883 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
1885 unsigned long now
= jiffies
;
1887 if (tx_tspec
->action
== TX_TSPEC_ACTION_NONE
&&
1888 tx_tspec
->admitted_time
&&
1889 time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1890 tx_tspec
->consumed_tx_time
= 0;
1891 tx_tspec
->time_slice_start
= now
;
1893 if (tx_tspec
->downgraded
)
1895 TX_TSPEC_ACTION_STOP_DOWNGRADE
;
1898 switch (tx_tspec
->action
) {
1899 case TX_TSPEC_ACTION_STOP_DOWNGRADE
:
1900 /* take the original parameters */
1901 if (drv_conf_tx(local
, sdata
, ac
, &sdata
->tx_conf
[ac
]))
1903 "failed to set TX queue parameters for queue %d\n",
1905 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1906 tx_tspec
->downgraded
= false;
1909 case TX_TSPEC_ACTION_DOWNGRADE
:
1910 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1911 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1915 /* downgrade next lower non-ACM AC */
1916 for (non_acm_ac
= ac
+ 1;
1917 non_acm_ac
< IEEE80211_NUM_ACS
;
1919 if (!(sdata
->wmm_acm
& BIT(7 - 2 * non_acm_ac
)))
1921 /* Usually the loop will result in using BK even if it
1922 * requires admission control, but such a configuration
1923 * makes no sense and we have to transmit somehow - the
1924 * AC selection does the same thing.
1925 * If we started out trying to downgrade from BK, then
1926 * the extra condition here might be needed.
1928 if (non_acm_ac
>= IEEE80211_NUM_ACS
)
1929 non_acm_ac
= IEEE80211_AC_BK
;
1930 if (drv_conf_tx(local
, sdata
, ac
,
1931 &sdata
->tx_conf
[non_acm_ac
]))
1933 "failed to set TX queue parameters for queue %d\n",
1935 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1937 schedule_delayed_work(&ifmgd
->tx_tspec_wk
,
1938 tx_tspec
->time_slice_start
+ HZ
- now
+ 1);
1940 case TX_TSPEC_ACTION_NONE
:
1949 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1951 if (__ieee80211_sta_handle_tspec_ac_params(sdata
))
1952 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
1955 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct
*work
)
1957 struct ieee80211_sub_if_data
*sdata
;
1959 sdata
= container_of(work
, struct ieee80211_sub_if_data
,
1960 u
.mgd
.tx_tspec_wk
.work
);
1961 ieee80211_sta_handle_tspec_ac_params(sdata
);
1966 ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
1967 struct ieee80211_sub_if_data
*sdata
,
1968 const u8
*wmm_param
, size_t wmm_param_len
,
1969 const struct ieee80211_mu_edca_param_set
*mu_edca
)
1971 struct ieee80211_tx_queue_params params
[IEEE80211_NUM_ACS
];
1972 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1974 int count
, mu_edca_count
, ac
;
1976 u8 uapsd_queues
= 0;
1978 if (!local
->ops
->conf_tx
)
1981 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1987 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
1990 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
1991 uapsd_queues
= ifmgd
->uapsd_queues
;
1993 count
= wmm_param
[6] & 0x0f;
1994 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1995 * if mu_edca was preset before and now it disappeared tell
1996 * the driver about it.
1998 mu_edca_count
= mu_edca
? mu_edca
->mu_qos_info
& 0x0f : -1;
1999 if (count
== ifmgd
->wmm_last_param_set
&&
2000 mu_edca_count
== ifmgd
->mu_edca_last_param_set
)
2002 ifmgd
->wmm_last_param_set
= count
;
2003 ifmgd
->mu_edca_last_param_set
= mu_edca_count
;
2005 pos
= wmm_param
+ 8;
2006 left
= wmm_param_len
- 8;
2008 memset(¶ms
, 0, sizeof(params
));
2011 for (; left
>= 4; left
-= 4, pos
+= 4) {
2012 int aci
= (pos
[0] >> 5) & 0x03;
2013 int acm
= (pos
[0] >> 4) & 0x01;
2018 ac
= IEEE80211_AC_BK
;
2020 sdata
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
2021 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
2023 params
[ac
].mu_edca
= !!mu_edca
;
2025 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_bk
;
2028 ac
= IEEE80211_AC_VI
;
2030 sdata
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
2031 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
2033 params
[ac
].mu_edca
= !!mu_edca
;
2035 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_vi
;
2038 ac
= IEEE80211_AC_VO
;
2040 sdata
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
2041 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
2043 params
[ac
].mu_edca
= !!mu_edca
;
2045 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_vo
;
2049 ac
= IEEE80211_AC_BE
;
2051 sdata
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
2052 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
2054 params
[ac
].mu_edca
= !!mu_edca
;
2056 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_be
;
2060 params
[ac
].aifs
= pos
[0] & 0x0f;
2062 if (params
[ac
].aifs
< 2) {
2064 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2065 params
[ac
].aifs
, aci
);
2066 params
[ac
].aifs
= 2;
2068 params
[ac
].cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
2069 params
[ac
].cw_min
= ecw2cw(pos
[1] & 0x0f);
2070 params
[ac
].txop
= get_unaligned_le16(pos
+ 2);
2071 params
[ac
].acm
= acm
;
2072 params
[ac
].uapsd
= uapsd
;
2074 if (params
[ac
].cw_min
== 0 ||
2075 params
[ac
].cw_min
> params
[ac
].cw_max
) {
2077 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2078 params
[ac
].cw_min
, params
[ac
].cw_max
, aci
);
2081 ieee80211_regulatory_limit_wmm_params(sdata
, ¶ms
[ac
], ac
);
2084 /* WMM specification requires all 4 ACIs. */
2085 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
2086 if (params
[ac
].cw_min
== 0) {
2088 "AP has invalid WMM params (missing AC %d), using defaults\n",
2094 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
2096 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2098 params
[ac
].aifs
, params
[ac
].cw_min
, params
[ac
].cw_max
,
2099 params
[ac
].txop
, params
[ac
].uapsd
,
2100 ifmgd
->tx_tspec
[ac
].downgraded
);
2101 sdata
->tx_conf
[ac
] = params
[ac
];
2102 if (!ifmgd
->tx_tspec
[ac
].downgraded
&&
2103 drv_conf_tx(local
, sdata
, ac
, ¶ms
[ac
]))
2105 "failed to set TX queue parameters for AC %d\n",
2109 /* enable WMM or activate new settings */
2110 sdata
->vif
.bss_conf
.qos
= true;
2114 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
2116 lockdep_assert_held(&sdata
->local
->mtx
);
2118 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_CONNECTION_POLL
;
2119 ieee80211_run_deferred_scan(sdata
->local
);
2122 static void ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
2124 mutex_lock(&sdata
->local
->mtx
);
2125 __ieee80211_stop_poll(sdata
);
2126 mutex_unlock(&sdata
->local
->mtx
);
2129 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
2130 u16 capab
, bool erp_valid
, u8 erp
)
2132 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2133 struct ieee80211_supported_band
*sband
;
2135 bool use_protection
;
2136 bool use_short_preamble
;
2137 bool use_short_slot
;
2139 sband
= ieee80211_get_sband(sdata
);
2144 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
2145 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
2147 use_protection
= false;
2148 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
2151 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
2152 if (sband
->band
== NL80211_BAND_5GHZ
||
2153 sband
->band
== NL80211_BAND_6GHZ
)
2154 use_short_slot
= true;
2156 if (use_protection
!= bss_conf
->use_cts_prot
) {
2157 bss_conf
->use_cts_prot
= use_protection
;
2158 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
2161 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
2162 bss_conf
->use_short_preamble
= use_short_preamble
;
2163 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
2166 if (use_short_slot
!= bss_conf
->use_short_slot
) {
2167 bss_conf
->use_short_slot
= use_short_slot
;
2168 changed
|= BSS_CHANGED_ERP_SLOT
;
2174 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
2175 struct cfg80211_bss
*cbss
,
2176 u32 bss_info_changed
)
2178 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
2179 struct ieee80211_local
*local
= sdata
->local
;
2180 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2182 bss_info_changed
|= BSS_CHANGED_ASSOC
;
2183 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
2184 bss_conf
->assoc_capability
, bss
->has_erp_value
, bss
->erp_value
);
2186 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
2187 beacon_loss_count
* bss_conf
->beacon_int
));
2189 sdata
->u
.mgd
.associated
= cbss
;
2190 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
2192 ieee80211_check_rate_mask(sdata
);
2194 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
2196 if (sdata
->vif
.p2p
||
2197 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
2198 const struct cfg80211_bss_ies
*ies
;
2201 ies
= rcu_dereference(cbss
->ies
);
2205 ret
= cfg80211_get_p2p_attr(
2206 ies
->data
, ies
->len
,
2207 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
2208 (u8
*) &bss_conf
->p2p_noa_attr
,
2209 sizeof(bss_conf
->p2p_noa_attr
));
2211 sdata
->u
.mgd
.p2p_noa_index
=
2212 bss_conf
->p2p_noa_attr
.index
;
2213 bss_info_changed
|= BSS_CHANGED_P2P_PS
;
2219 /* just to be sure */
2220 ieee80211_stop_poll(sdata
);
2222 ieee80211_led_assoc(local
, 1);
2224 if (sdata
->u
.mgd
.have_beacon
) {
2226 * If the AP is buggy we may get here with no DTIM period
2227 * known, so assume it's 1 which is the only safe assumption
2228 * in that case, although if the TIM IE is broken powersave
2229 * probably just won't work at all.
2231 bss_conf
->dtim_period
= sdata
->u
.mgd
.dtim_period
?: 1;
2232 bss_conf
->beacon_rate
= bss
->beacon_rate
;
2233 bss_info_changed
|= BSS_CHANGED_BEACON_INFO
;
2235 bss_conf
->beacon_rate
= NULL
;
2236 bss_conf
->dtim_period
= 0;
2239 bss_conf
->assoc
= 1;
2241 /* Tell the driver to monitor connection quality (if supported) */
2242 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
&&
2243 bss_conf
->cqm_rssi_thold
)
2244 bss_info_changed
|= BSS_CHANGED_CQM
;
2246 /* Enable ARP filtering */
2247 if (bss_conf
->arp_addr_cnt
)
2248 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
2250 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
2252 mutex_lock(&local
->iflist_mtx
);
2253 ieee80211_recalc_ps(local
);
2254 mutex_unlock(&local
->iflist_mtx
);
2256 ieee80211_recalc_smps(sdata
);
2257 ieee80211_recalc_ps_vif(sdata
);
2259 netif_carrier_on(sdata
->dev
);
2262 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
2263 u16 stype
, u16 reason
, bool tx
,
2266 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2267 struct ieee80211_local
*local
= sdata
->local
;
2269 struct ieee80211_prep_tx_info info
= {
2273 sdata_assert_lock(sdata
);
2275 if (WARN_ON_ONCE(tx
&& !frame_buf
))
2278 if (WARN_ON(!ifmgd
->associated
))
2281 ieee80211_stop_poll(sdata
);
2283 ifmgd
->associated
= NULL
;
2284 netif_carrier_off(sdata
->dev
);
2287 * if we want to get out of ps before disassoc (why?) we have
2288 * to do it before sending disassoc, as otherwise the null-packet
2291 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
2292 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
2293 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2295 local
->ps_sdata
= NULL
;
2297 /* disable per-vif ps */
2298 ieee80211_recalc_ps_vif(sdata
);
2300 /* make sure ongoing transmission finishes */
2304 * drop any frame before deauth/disassoc, this can be data or
2305 * management frame. Since we are disconnecting, we should not
2306 * insist sending these frames which can take time and delay
2307 * the disconnection and possible the roaming.
2310 ieee80211_flush_queues(local
, sdata
, true);
2312 /* deauthenticate/disassociate now */
2313 if (tx
|| frame_buf
) {
2315 * In multi channel scenarios guarantee that the virtual
2316 * interface is granted immediate airtime to transmit the
2317 * deauthentication frame by calling mgd_prepare_tx, if the
2318 * driver requested so.
2320 if (ieee80211_hw_check(&local
->hw
, DEAUTH_NEED_MGD_TX_PREP
) &&
2321 !ifmgd
->have_beacon
) {
2322 drv_mgd_prepare_tx(sdata
->local
, sdata
, &info
);
2325 ieee80211_send_deauth_disassoc(sdata
, ifmgd
->bssid
,
2326 ifmgd
->bssid
, stype
, reason
,
2330 /* flush out frame - make sure the deauth was actually sent */
2332 ieee80211_flush_queues(local
, sdata
, false);
2334 drv_mgd_complete_tx(sdata
->local
, sdata
, &info
);
2336 /* clear bssid only after building the needed mgmt frames */
2337 eth_zero_addr(ifmgd
->bssid
);
2339 sdata
->vif
.bss_conf
.ssid_len
= 0;
2341 /* remove AP and TDLS peers */
2342 sta_info_flush(sdata
);
2344 /* finally reset all BSS / config parameters */
2345 changed
|= ieee80211_reset_erp_info(sdata
);
2347 ieee80211_led_assoc(local
, 0);
2348 changed
|= BSS_CHANGED_ASSOC
;
2349 sdata
->vif
.bss_conf
.assoc
= false;
2351 ifmgd
->p2p_noa_index
= -1;
2352 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
2353 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
2355 /* on the next assoc, re-program HT/VHT parameters */
2356 memset(&ifmgd
->ht_capa
, 0, sizeof(ifmgd
->ht_capa
));
2357 memset(&ifmgd
->ht_capa_mask
, 0, sizeof(ifmgd
->ht_capa_mask
));
2358 memset(&ifmgd
->vht_capa
, 0, sizeof(ifmgd
->vht_capa
));
2359 memset(&ifmgd
->vht_capa_mask
, 0, sizeof(ifmgd
->vht_capa_mask
));
2361 /* reset MU-MIMO ownership and group data */
2362 memset(sdata
->vif
.bss_conf
.mu_group
.membership
, 0,
2363 sizeof(sdata
->vif
.bss_conf
.mu_group
.membership
));
2364 memset(sdata
->vif
.bss_conf
.mu_group
.position
, 0,
2365 sizeof(sdata
->vif
.bss_conf
.mu_group
.position
));
2366 changed
|= BSS_CHANGED_MU_GROUPS
;
2367 sdata
->vif
.mu_mimo_owner
= false;
2369 sdata
->ap_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2371 del_timer_sync(&local
->dynamic_ps_timer
);
2372 cancel_work_sync(&local
->dynamic_ps_enable_work
);
2374 /* Disable ARP filtering */
2375 if (sdata
->vif
.bss_conf
.arp_addr_cnt
)
2376 changed
|= BSS_CHANGED_ARP_FILTER
;
2378 sdata
->vif
.bss_conf
.qos
= false;
2379 changed
|= BSS_CHANGED_QOS
;
2381 /* The BSSID (not really interesting) and HT changed */
2382 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
2383 ieee80211_bss_info_change_notify(sdata
, changed
);
2385 /* disassociated - set to defaults now */
2386 ieee80211_set_wmm_default(sdata
, false, false);
2388 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
2389 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
2390 del_timer_sync(&sdata
->u
.mgd
.timer
);
2391 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
2393 sdata
->vif
.bss_conf
.dtim_period
= 0;
2394 sdata
->vif
.bss_conf
.beacon_rate
= NULL
;
2396 ifmgd
->have_beacon
= false;
2399 mutex_lock(&local
->mtx
);
2400 ieee80211_vif_release_channel(sdata
);
2402 sdata
->vif
.csa_active
= false;
2403 ifmgd
->csa_waiting_bcn
= false;
2404 ifmgd
->csa_ignored_same_chan
= false;
2405 if (sdata
->csa_block_tx
) {
2406 ieee80211_wake_vif_queues(local
, sdata
,
2407 IEEE80211_QUEUE_STOP_REASON_CSA
);
2408 sdata
->csa_block_tx
= false;
2410 mutex_unlock(&local
->mtx
);
2412 /* existing TX TSPEC sessions no longer exist */
2413 memset(ifmgd
->tx_tspec
, 0, sizeof(ifmgd
->tx_tspec
));
2414 cancel_delayed_work_sync(&ifmgd
->tx_tspec_wk
);
2416 sdata
->encrypt_headroom
= IEEE80211_ENCRYPT_HEADROOM
;
2419 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
2421 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2422 struct ieee80211_local
*local
= sdata
->local
;
2424 mutex_lock(&local
->mtx
);
2425 if (!(ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
))
2428 __ieee80211_stop_poll(sdata
);
2430 mutex_lock(&local
->iflist_mtx
);
2431 ieee80211_recalc_ps(local
);
2432 mutex_unlock(&local
->iflist_mtx
);
2434 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
2438 * We've received a probe response, but are not sure whether
2439 * we have or will be receiving any beacons or data, so let's
2440 * schedule the timers again, just in case.
2442 ieee80211_sta_reset_beacon_monitor(sdata
);
2444 mod_timer(&ifmgd
->conn_mon_timer
,
2445 round_jiffies_up(jiffies
+
2446 IEEE80211_CONNECTION_IDLE_TIME
));
2448 mutex_unlock(&local
->mtx
);
2451 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data
*sdata
,
2452 struct ieee80211_hdr
*hdr
,
2455 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2458 struct ieee80211_sta_tx_tspec
*tx_tspec
;
2459 unsigned long now
= jiffies
;
2461 if (!ieee80211_is_data_qos(hdr
->frame_control
))
2464 tid
= ieee80211_get_tid(hdr
);
2465 ac
= ieee80211_ac_from_tid(tid
);
2466 tx_tspec
= &ifmgd
->tx_tspec
[ac
];
2468 if (likely(!tx_tspec
->admitted_time
))
2471 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
2472 tx_tspec
->consumed_tx_time
= 0;
2473 tx_tspec
->time_slice_start
= now
;
2475 if (tx_tspec
->downgraded
) {
2476 tx_tspec
->action
= TX_TSPEC_ACTION_STOP_DOWNGRADE
;
2477 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2481 if (tx_tspec
->downgraded
)
2484 tx_tspec
->consumed_tx_time
+= tx_time
;
2486 if (tx_tspec
->consumed_tx_time
>= tx_tspec
->admitted_time
) {
2487 tx_tspec
->downgraded
= true;
2488 tx_tspec
->action
= TX_TSPEC_ACTION_DOWNGRADE
;
2489 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2493 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
2494 struct ieee80211_hdr
*hdr
, bool ack
, u16 tx_time
)
2496 ieee80211_sta_tx_wmm_ac_notify(sdata
, hdr
, tx_time
);
2498 if (!ieee80211_is_any_nullfunc(hdr
->frame_control
) ||
2499 !sdata
->u
.mgd
.probe_send_count
)
2503 sdata
->u
.mgd
.probe_send_count
= 0;
2505 sdata
->u
.mgd
.nullfunc_failed
= true;
2506 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
2509 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data
*sdata
,
2510 const u8
*src
, const u8
*dst
,
2511 const u8
*ssid
, size_t ssid_len
,
2512 struct ieee80211_channel
*channel
)
2514 struct sk_buff
*skb
;
2516 skb
= ieee80211_build_probe_req(sdata
, src
, dst
, (u32
)-1, channel
,
2517 ssid
, ssid_len
, NULL
, 0,
2518 IEEE80211_PROBE_FLAG_DIRECTED
);
2520 ieee80211_tx_skb(sdata
, skb
);
2523 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
2525 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2527 u8
*dst
= ifmgd
->associated
->bssid
;
2528 u8 unicast_limit
= max(1, max_probe_tries
- 3);
2529 struct sta_info
*sta
;
2532 * Try sending broadcast probe requests for the last three
2533 * probe requests after the first ones failed since some
2534 * buggy APs only support broadcast probe requests.
2536 if (ifmgd
->probe_send_count
>= unicast_limit
)
2540 * When the hardware reports an accurate Tx ACK status, it's
2541 * better to send a nullfunc frame instead of a probe request,
2542 * as it will kick us off the AP quickly if we aren't associated
2543 * anymore. The timeout will be reset if the frame is ACKed by
2546 ifmgd
->probe_send_count
++;
2549 mutex_lock(&sdata
->local
->sta_mtx
);
2550 sta
= sta_info_get(sdata
, dst
);
2552 ieee80211_check_fast_rx(sta
);
2553 mutex_unlock(&sdata
->local
->sta_mtx
);
2556 if (ieee80211_hw_check(&sdata
->local
->hw
, REPORTS_TX_ACK_STATUS
)) {
2557 ifmgd
->nullfunc_failed
= false;
2558 ieee80211_send_nullfunc(sdata
->local
, sdata
, false);
2563 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
2564 if (WARN_ON_ONCE(ssid
== NULL
))
2569 ieee80211_mlme_send_probe_req(sdata
, sdata
->vif
.addr
, dst
,
2571 ifmgd
->associated
->channel
);
2575 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
2576 run_again(sdata
, ifmgd
->probe_timeout
);
2579 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
2582 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2583 bool already
= false;
2585 if (!ieee80211_sdata_running(sdata
))
2590 if (!ifmgd
->associated
)
2593 mutex_lock(&sdata
->local
->mtx
);
2595 if (sdata
->local
->tmp_channel
|| sdata
->local
->scanning
) {
2596 mutex_unlock(&sdata
->local
->mtx
);
2601 mlme_dbg_ratelimited(sdata
,
2602 "detected beacon loss from AP (missed %d beacons) - probing\n",
2605 ieee80211_cqm_beacon_loss_notify(&sdata
->vif
, GFP_KERNEL
);
2609 * The driver/our work has already reported this event or the
2610 * connection monitoring has kicked in and we have already sent
2611 * a probe request. Or maybe the AP died and the driver keeps
2612 * reporting until we disassociate...
2614 * In either case we have to ignore the current call to this
2615 * function (except for setting the correct probe reason bit)
2616 * because otherwise we would reset the timer every time and
2617 * never check whether we received a probe response!
2619 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
2622 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
2624 mutex_unlock(&sdata
->local
->mtx
);
2629 mutex_lock(&sdata
->local
->iflist_mtx
);
2630 ieee80211_recalc_ps(sdata
->local
);
2631 mutex_unlock(&sdata
->local
->iflist_mtx
);
2633 ifmgd
->probe_send_count
= 0;
2634 ieee80211_mgd_probe_ap_send(sdata
);
2636 sdata_unlock(sdata
);
2639 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
2640 struct ieee80211_vif
*vif
)
2642 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2643 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2644 struct cfg80211_bss
*cbss
;
2645 struct sk_buff
*skb
;
2649 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2652 sdata_assert_lock(sdata
);
2654 if (ifmgd
->associated
)
2655 cbss
= ifmgd
->associated
;
2656 else if (ifmgd
->auth_data
)
2657 cbss
= ifmgd
->auth_data
->bss
;
2658 else if (ifmgd
->assoc_data
)
2659 cbss
= ifmgd
->assoc_data
->bss
;
2664 ssid
= ieee80211_bss_get_ie(cbss
, WLAN_EID_SSID
);
2665 if (WARN_ONCE(!ssid
|| ssid
[1] > IEEE80211_MAX_SSID_LEN
,
2666 "invalid SSID element (len=%d)", ssid
? ssid
[1] : -1))
2671 skb
= ieee80211_build_probe_req(sdata
, sdata
->vif
.addr
, cbss
->bssid
,
2672 (u32
) -1, cbss
->channel
,
2674 NULL
, 0, IEEE80211_PROBE_FLAG_DIRECTED
);
2679 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
2681 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data
*sdata
,
2682 const u8
*buf
, size_t len
, bool tx
,
2683 u16 reason
, bool reconnect
)
2685 struct ieee80211_event event
= {
2687 .u
.mlme
.data
= tx
? DEAUTH_TX_EVENT
: DEAUTH_RX_EVENT
,
2688 .u
.mlme
.reason
= reason
,
2692 cfg80211_tx_mlme_mgmt(sdata
->dev
, buf
, len
, reconnect
);
2694 cfg80211_rx_mlme_mgmt(sdata
->dev
, buf
, len
);
2696 drv_event_callback(sdata
->local
, sdata
, &event
);
2699 static void __ieee80211_disconnect(struct ieee80211_sub_if_data
*sdata
)
2701 struct ieee80211_local
*local
= sdata
->local
;
2702 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2703 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2707 if (!ifmgd
->associated
) {
2708 sdata_unlock(sdata
);
2712 tx
= !sdata
->csa_block_tx
;
2714 if (!ifmgd
->driver_disconnect
) {
2716 * AP is probably out of range (or not reachable for another
2717 * reason) so remove the bss struct for that AP.
2719 cfg80211_unlink_bss(local
->hw
.wiphy
, ifmgd
->associated
);
2722 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
2723 ifmgd
->driver_disconnect
?
2724 WLAN_REASON_DEAUTH_LEAVING
:
2725 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2727 mutex_lock(&local
->mtx
);
2728 sdata
->vif
.csa_active
= false;
2729 ifmgd
->csa_waiting_bcn
= false;
2730 if (sdata
->csa_block_tx
) {
2731 ieee80211_wake_vif_queues(local
, sdata
,
2732 IEEE80211_QUEUE_STOP_REASON_CSA
);
2733 sdata
->csa_block_tx
= false;
2735 mutex_unlock(&local
->mtx
);
2737 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), tx
,
2738 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2740 ifmgd
->reconnect
= false;
2742 sdata_unlock(sdata
);
2745 static void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
2747 struct ieee80211_sub_if_data
*sdata
=
2748 container_of(work
, struct ieee80211_sub_if_data
,
2749 u
.mgd
.beacon_connection_loss_work
);
2750 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2752 if (ifmgd
->associated
)
2753 ifmgd
->beacon_loss_count
++;
2755 if (ifmgd
->connection_loss
) {
2756 sdata_info(sdata
, "Connection to AP %pM lost\n",
2758 __ieee80211_disconnect(sdata
);
2759 ifmgd
->connection_loss
= false;
2760 } else if (ifmgd
->driver_disconnect
) {
2762 "Driver requested disconnection from AP %pM\n",
2764 __ieee80211_disconnect(sdata
);
2765 ifmgd
->driver_disconnect
= false;
2767 ieee80211_mgd_probe_ap(sdata
, true);
2771 static void ieee80211_csa_connection_drop_work(struct work_struct
*work
)
2773 struct ieee80211_sub_if_data
*sdata
=
2774 container_of(work
, struct ieee80211_sub_if_data
,
2775 u
.mgd
.csa_connection_drop_work
);
2777 __ieee80211_disconnect(sdata
);
2780 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
2782 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2783 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2785 trace_api_beacon_loss(sdata
);
2787 sdata
->u
.mgd
.connection_loss
= false;
2788 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2790 EXPORT_SYMBOL(ieee80211_beacon_loss
);
2792 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
2794 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2795 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2797 trace_api_connection_loss(sdata
);
2799 sdata
->u
.mgd
.connection_loss
= true;
2800 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2802 EXPORT_SYMBOL(ieee80211_connection_loss
);
2804 void ieee80211_disconnect(struct ieee80211_vif
*vif
, bool reconnect
)
2806 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2807 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2809 trace_api_disconnect(sdata
, reconnect
);
2811 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2814 sdata
->u
.mgd
.driver_disconnect
= true;
2815 sdata
->u
.mgd
.reconnect
= reconnect
;
2816 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2818 EXPORT_SYMBOL(ieee80211_disconnect
);
2820 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data
*sdata
,
2823 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2825 sdata_assert_lock(sdata
);
2829 * we are not authenticated yet, the only timer that could be
2830 * running is the timeout for the authentication response which
2831 * which is not relevant anymore.
2833 del_timer_sync(&sdata
->u
.mgd
.timer
);
2834 sta_info_destroy_addr(sdata
, auth_data
->bss
->bssid
);
2836 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2837 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2838 sdata
->u
.mgd
.flags
= 0;
2839 mutex_lock(&sdata
->local
->mtx
);
2840 ieee80211_vif_release_channel(sdata
);
2841 mutex_unlock(&sdata
->local
->mtx
);
2844 cfg80211_put_bss(sdata
->local
->hw
.wiphy
, auth_data
->bss
);
2846 sdata
->u
.mgd
.auth_data
= NULL
;
2849 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data
*sdata
,
2850 bool assoc
, bool abandon
)
2852 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
2854 sdata_assert_lock(sdata
);
2858 * we are not associated yet, the only timer that could be
2859 * running is the timeout for the association response which
2860 * which is not relevant anymore.
2862 del_timer_sync(&sdata
->u
.mgd
.timer
);
2863 sta_info_destroy_addr(sdata
, assoc_data
->bss
->bssid
);
2865 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2866 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2867 sdata
->u
.mgd
.flags
= 0;
2868 sdata
->vif
.mu_mimo_owner
= false;
2870 mutex_lock(&sdata
->local
->mtx
);
2871 ieee80211_vif_release_channel(sdata
);
2872 mutex_unlock(&sdata
->local
->mtx
);
2875 cfg80211_abandon_assoc(sdata
->dev
, assoc_data
->bss
);
2879 sdata
->u
.mgd
.assoc_data
= NULL
;
2882 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
2883 struct ieee80211_mgmt
*mgmt
, size_t len
)
2885 struct ieee80211_local
*local
= sdata
->local
;
2886 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2888 struct ieee802_11_elems elems
;
2890 struct ieee80211_prep_tx_info info
= {
2891 .subtype
= IEEE80211_STYPE_AUTH
,
2894 pos
= mgmt
->u
.auth
.variable
;
2895 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*)mgmt
), false, &elems
,
2896 mgmt
->bssid
, auth_data
->bss
->bssid
);
2897 if (!elems
.challenge
)
2899 auth_data
->expected_transaction
= 4;
2900 drv_mgd_prepare_tx(sdata
->local
, sdata
, &info
);
2901 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
2902 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2903 IEEE80211_TX_INTFL_MLME_CONN_TX
;
2904 ieee80211_send_auth(sdata
, 3, auth_data
->algorithm
, 0,
2905 elems
.challenge
- 2, elems
.challenge_len
+ 2,
2906 auth_data
->bss
->bssid
, auth_data
->bss
->bssid
,
2907 auth_data
->key
, auth_data
->key_len
,
2908 auth_data
->key_idx
, tx_flags
);
2911 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data
*sdata
,
2914 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2915 struct sta_info
*sta
;
2918 sdata_info(sdata
, "authenticated\n");
2919 ifmgd
->auth_data
->done
= true;
2920 ifmgd
->auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_WAIT_ASSOC
;
2921 ifmgd
->auth_data
->timeout_started
= true;
2922 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2924 /* move station state to auth */
2925 mutex_lock(&sdata
->local
->sta_mtx
);
2926 sta
= sta_info_get(sdata
, bssid
);
2928 WARN_ONCE(1, "%s: STA %pM not found", sdata
->name
, bssid
);
2932 if (sta_info_move_state(sta
, IEEE80211_STA_AUTH
)) {
2933 sdata_info(sdata
, "failed moving %pM to auth\n", bssid
);
2939 mutex_unlock(&sdata
->local
->sta_mtx
);
2943 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
2944 struct ieee80211_mgmt
*mgmt
, size_t len
)
2946 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2948 u16 auth_alg
, auth_transaction
, status_code
;
2949 struct ieee80211_event event
= {
2951 .u
.mlme
.data
= AUTH_EVENT
,
2953 struct ieee80211_prep_tx_info info
= {
2954 .subtype
= IEEE80211_STYPE_AUTH
,
2957 sdata_assert_lock(sdata
);
2962 if (!ifmgd
->auth_data
|| ifmgd
->auth_data
->done
)
2965 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
2967 if (!ether_addr_equal(bssid
, mgmt
->bssid
))
2970 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
2971 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
2972 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
2974 if (auth_alg
!= ifmgd
->auth_data
->algorithm
||
2975 (auth_alg
!= WLAN_AUTH_SAE
&&
2976 auth_transaction
!= ifmgd
->auth_data
->expected_transaction
) ||
2977 (auth_alg
== WLAN_AUTH_SAE
&&
2978 (auth_transaction
< ifmgd
->auth_data
->expected_transaction
||
2979 auth_transaction
> 2))) {
2980 sdata_info(sdata
, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2981 mgmt
->sa
, auth_alg
, ifmgd
->auth_data
->algorithm
,
2983 ifmgd
->auth_data
->expected_transaction
);
2987 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2988 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2990 if (auth_alg
== WLAN_AUTH_SAE
&&
2991 (status_code
== WLAN_STATUS_ANTI_CLOG_REQUIRED
||
2992 (auth_transaction
== 1 &&
2993 (status_code
== WLAN_STATUS_SAE_HASH_TO_ELEMENT
||
2994 status_code
== WLAN_STATUS_SAE_PK
)))) {
2995 /* waiting for userspace now */
2996 ifmgd
->auth_data
->waiting
= true;
2997 ifmgd
->auth_data
->timeout
=
2998 jiffies
+ IEEE80211_AUTH_WAIT_SAE_RETRY
;
2999 ifmgd
->auth_data
->timeout_started
= true;
3000 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3004 sdata_info(sdata
, "%pM denied authentication (status %d)\n",
3005 mgmt
->sa
, status_code
);
3006 ieee80211_destroy_auth_data(sdata
, false);
3007 event
.u
.mlme
.status
= MLME_DENIED
;
3008 event
.u
.mlme
.reason
= status_code
;
3009 drv_event_callback(sdata
->local
, sdata
, &event
);
3013 switch (ifmgd
->auth_data
->algorithm
) {
3014 case WLAN_AUTH_OPEN
:
3015 case WLAN_AUTH_LEAP
:
3018 case WLAN_AUTH_FILS_SK
:
3019 case WLAN_AUTH_FILS_SK_PFS
:
3020 case WLAN_AUTH_FILS_PK
:
3022 case WLAN_AUTH_SHARED_KEY
:
3023 if (ifmgd
->auth_data
->expected_transaction
!= 4) {
3024 ieee80211_auth_challenge(sdata
, mgmt
, len
);
3025 /* need another frame */
3030 WARN_ONCE(1, "invalid auth alg %d",
3031 ifmgd
->auth_data
->algorithm
);
3035 event
.u
.mlme
.status
= MLME_SUCCESS
;
3037 drv_event_callback(sdata
->local
, sdata
, &event
);
3038 if (ifmgd
->auth_data
->algorithm
!= WLAN_AUTH_SAE
||
3039 (auth_transaction
== 2 &&
3040 ifmgd
->auth_data
->expected_transaction
== 2)) {
3041 if (!ieee80211_mark_sta_auth(sdata
, bssid
))
3042 return; /* ignore frame -- wait for timeout */
3043 } else if (ifmgd
->auth_data
->algorithm
== WLAN_AUTH_SAE
&&
3044 auth_transaction
== 2) {
3045 sdata_info(sdata
, "SAE peer confirmed\n");
3046 ifmgd
->auth_data
->peer_confirmed
= true;
3049 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
3051 drv_mgd_complete_tx(sdata
->local
, sdata
, &info
);
3054 #define case_WLAN(type) \
3055 case WLAN_REASON_##type: return #type
3057 const char *ieee80211_get_reason_code_string(u16 reason_code
)
3059 switch (reason_code
) {
3060 case_WLAN(UNSPECIFIED
);
3061 case_WLAN(PREV_AUTH_NOT_VALID
);
3062 case_WLAN(DEAUTH_LEAVING
);
3063 case_WLAN(DISASSOC_DUE_TO_INACTIVITY
);
3064 case_WLAN(DISASSOC_AP_BUSY
);
3065 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA
);
3066 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA
);
3067 case_WLAN(DISASSOC_STA_HAS_LEFT
);
3068 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH
);
3069 case_WLAN(DISASSOC_BAD_POWER
);
3070 case_WLAN(DISASSOC_BAD_SUPP_CHAN
);
3071 case_WLAN(INVALID_IE
);
3072 case_WLAN(MIC_FAILURE
);
3073 case_WLAN(4WAY_HANDSHAKE_TIMEOUT
);
3074 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT
);
3075 case_WLAN(IE_DIFFERENT
);
3076 case_WLAN(INVALID_GROUP_CIPHER
);
3077 case_WLAN(INVALID_PAIRWISE_CIPHER
);
3078 case_WLAN(INVALID_AKMP
);
3079 case_WLAN(UNSUPP_RSN_VERSION
);
3080 case_WLAN(INVALID_RSN_IE_CAP
);
3081 case_WLAN(IEEE8021X_FAILED
);
3082 case_WLAN(CIPHER_SUITE_REJECTED
);
3083 case_WLAN(DISASSOC_UNSPECIFIED_QOS
);
3084 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH
);
3085 case_WLAN(DISASSOC_LOW_ACK
);
3086 case_WLAN(DISASSOC_QAP_EXCEED_TXOP
);
3087 case_WLAN(QSTA_LEAVE_QBSS
);
3088 case_WLAN(QSTA_NOT_USE
);
3089 case_WLAN(QSTA_REQUIRE_SETUP
);
3090 case_WLAN(QSTA_TIMEOUT
);
3091 case_WLAN(QSTA_CIPHER_NOT_SUPP
);
3092 case_WLAN(MESH_PEER_CANCELED
);
3093 case_WLAN(MESH_MAX_PEERS
);
3094 case_WLAN(MESH_CONFIG
);
3095 case_WLAN(MESH_CLOSE
);
3096 case_WLAN(MESH_MAX_RETRIES
);
3097 case_WLAN(MESH_CONFIRM_TIMEOUT
);
3098 case_WLAN(MESH_INVALID_GTK
);
3099 case_WLAN(MESH_INCONSISTENT_PARAM
);
3100 case_WLAN(MESH_INVALID_SECURITY
);
3101 case_WLAN(MESH_PATH_ERROR
);
3102 case_WLAN(MESH_PATH_NOFORWARD
);
3103 case_WLAN(MESH_PATH_DEST_UNREACHABLE
);
3104 case_WLAN(MAC_EXISTS_IN_MBSS
);
3105 case_WLAN(MESH_CHAN_REGULATORY
);
3106 case_WLAN(MESH_CHAN
);
3107 default: return "<unknown>";
3111 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
3112 struct ieee80211_mgmt
*mgmt
, size_t len
)
3114 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3115 u16 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
3117 sdata_assert_lock(sdata
);
3122 if (!ether_addr_equal(mgmt
->bssid
, mgmt
->sa
)) {
3123 ieee80211_tdls_handle_disconnect(sdata
, mgmt
->sa
, reason_code
);
3127 if (ifmgd
->associated
&&
3128 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
)) {
3129 const u8
*bssid
= ifmgd
->associated
->bssid
;
3131 sdata_info(sdata
, "deauthenticated from %pM (Reason: %u=%s)\n",
3133 ieee80211_get_reason_code_string(reason_code
));
3135 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
3137 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false,
3138 reason_code
, false);
3142 if (ifmgd
->assoc_data
&&
3143 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
3144 const u8
*bssid
= ifmgd
->assoc_data
->bss
->bssid
;
3147 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3149 ieee80211_get_reason_code_string(reason_code
));
3151 ieee80211_destroy_assoc_data(sdata
, false, true);
3153 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
3159 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
3160 struct ieee80211_mgmt
*mgmt
, size_t len
)
3162 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3165 sdata_assert_lock(sdata
);
3170 if (!ifmgd
->associated
||
3171 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3174 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
3176 if (!ether_addr_equal(mgmt
->bssid
, mgmt
->sa
)) {
3177 ieee80211_tdls_handle_disconnect(sdata
, mgmt
->sa
, reason_code
);
3181 sdata_info(sdata
, "disassociated from %pM (Reason: %u=%s)\n",
3182 mgmt
->sa
, reason_code
,
3183 ieee80211_get_reason_code_string(reason_code
));
3185 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
3187 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false, reason_code
,
3191 static void ieee80211_get_rates(struct ieee80211_supported_band
*sband
,
3192 u8
*supp_rates
, unsigned int supp_rates_len
,
3193 u32
*rates
, u32
*basic_rates
,
3194 bool *have_higher_than_11mbit
,
3195 int *min_rate
, int *min_rate_index
,
3200 for (i
= 0; i
< supp_rates_len
; i
++) {
3201 int rate
= supp_rates
[i
] & 0x7f;
3202 bool is_basic
= !!(supp_rates
[i
] & 0x80);
3204 if ((rate
* 5 * (1 << shift
)) > 110)
3205 *have_higher_than_11mbit
= true;
3208 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3209 * since they're not rates.
3211 * Note: Even though the membership selector and the basic
3212 * rate flag share the same bit, they are not exactly
3215 if (supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
) ||
3216 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
) ||
3217 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY
) ||
3218 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E
))
3221 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
3222 struct ieee80211_rate
*br
;
3225 br
= &sband
->bitrates
[j
];
3227 brate
= DIV_ROUND_UP(br
->bitrate
, (1 << shift
) * 5);
3228 if (brate
== rate
) {
3231 *basic_rates
|= BIT(j
);
3232 if ((rate
* 5) < *min_rate
) {
3233 *min_rate
= rate
* 5;
3234 *min_rate_index
= j
;
3242 static bool ieee80211_twt_req_supported(const struct sta_info
*sta
,
3243 const struct ieee802_11_elems
*elems
)
3245 if (elems
->ext_capab_len
< 10)
3248 if (!(elems
->ext_capab
[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT
))
3251 return sta
->sta
.he_cap
.he_cap_elem
.mac_cap_info
[0] &
3252 IEEE80211_HE_MAC_CAP0_TWT_RES
;
3255 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data
*sdata
,
3256 struct sta_info
*sta
,
3257 struct ieee802_11_elems
*elems
)
3259 bool twt
= ieee80211_twt_req_supported(sta
, elems
);
3261 if (sdata
->vif
.bss_conf
.twt_requester
!= twt
) {
3262 sdata
->vif
.bss_conf
.twt_requester
= twt
;
3263 return BSS_CHANGED_TWT
;
3268 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data
*sdata
,
3269 struct ieee80211_bss_conf
*bss_conf
,
3270 struct ieee80211_supported_band
*sband
,
3271 struct sta_info
*sta
)
3273 const struct ieee80211_sta_he_cap
*own_he_cap
=
3274 ieee80211_get_he_iftype_cap(sband
,
3275 ieee80211_vif_type_p2p(&sdata
->vif
));
3277 return bss_conf
->he_support
&&
3278 (sta
->sta
.he_cap
.he_cap_elem
.mac_cap_info
[2] &
3279 IEEE80211_HE_MAC_CAP2_BCAST_TWT
) &&
3281 (own_he_cap
->he_cap_elem
.mac_cap_info
[2] &
3282 IEEE80211_HE_MAC_CAP2_BCAST_TWT
);
3285 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data
*sdata
,
3286 struct cfg80211_bss
*cbss
,
3287 struct ieee80211_mgmt
*mgmt
, size_t len
,
3288 struct ieee802_11_elems
*elems
)
3290 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3291 struct ieee80211_local
*local
= sdata
->local
;
3292 struct ieee80211_supported_band
*sband
;
3293 struct sta_info
*sta
;
3294 u16 capab_info
, aid
;
3295 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3296 const struct cfg80211_bss_ies
*bss_ies
= NULL
;
3297 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3298 bool is_6ghz
= cbss
->channel
->band
== NL80211_BAND_6GHZ
;
3299 bool is_s1g
= cbss
->channel
->band
== NL80211_BAND_S1GHZ
;
3305 /* AssocResp and ReassocResp have identical structure */
3307 pos
= mgmt
->u
.assoc_resp
.variable
;
3308 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3310 pos
= (u8
*) mgmt
->u
.s1g_assoc_resp
.variable
;
3313 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3314 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*)mgmt
), false, elems
,
3315 mgmt
->bssid
, assoc_data
->bss
->bssid
);
3317 if (elems
->aid_resp
)
3318 aid
= le16_to_cpu(elems
->aid_resp
->aid
);
3321 * The 5 MSB of the AID field are reserved
3322 * (802.11-2016 9.4.1.8 AID field)
3326 ifmgd
->broken_ap
= false;
3328 if (aid
== 0 || aid
> IEEE80211_MAX_AID
) {
3329 sdata_info(sdata
, "invalid AID value %d (out of range), turn off PS\n",
3332 ifmgd
->broken_ap
= true;
3335 if (!is_s1g
&& !elems
->supp_rates
) {
3336 sdata_info(sdata
, "no SuppRates element in AssocResp\n");
3340 sdata
->vif
.bss_conf
.aid
= aid
;
3341 ifmgd
->tdls_chan_switch_prohibited
=
3342 elems
->ext_capab
&& elems
->ext_capab_len
>= 5 &&
3343 (elems
->ext_capab
[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED
);
3346 * Some APs are erroneously not including some information in their
3347 * (re)association response frames. Try to recover by using the data
3348 * from the beacon or probe response. This seems to afflict mobile
3349 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3350 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3353 ((assoc_data
->wmm
&& !elems
->wmm_param
) ||
3354 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3355 (!elems
->ht_cap_elem
|| !elems
->ht_operation
)) ||
3356 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3357 (!elems
->vht_cap_elem
|| !elems
->vht_operation
)))) {
3358 const struct cfg80211_bss_ies
*ies
;
3359 struct ieee802_11_elems bss_elems
;
3362 ies
= rcu_dereference(cbss
->ies
);
3364 bss_ies
= kmemdup(ies
, sizeof(*ies
) + ies
->len
,
3370 ieee802_11_parse_elems(bss_ies
->data
, bss_ies
->len
,
3373 assoc_data
->bss
->bssid
);
3374 if (assoc_data
->wmm
&&
3375 !elems
->wmm_param
&& bss_elems
.wmm_param
) {
3376 elems
->wmm_param
= bss_elems
.wmm_param
;
3378 "AP bug: WMM param missing from AssocResp\n");
3382 * Also check if we requested HT/VHT, otherwise the AP doesn't
3383 * have to include the IEs in the (re)association response.
3385 if (!elems
->ht_cap_elem
&& bss_elems
.ht_cap_elem
&&
3386 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
3387 elems
->ht_cap_elem
= bss_elems
.ht_cap_elem
;
3389 "AP bug: HT capability missing from AssocResp\n");
3391 if (!elems
->ht_operation
&& bss_elems
.ht_operation
&&
3392 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
3393 elems
->ht_operation
= bss_elems
.ht_operation
;
3395 "AP bug: HT operation missing from AssocResp\n");
3397 if (!elems
->vht_cap_elem
&& bss_elems
.vht_cap_elem
&&
3398 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3399 elems
->vht_cap_elem
= bss_elems
.vht_cap_elem
;
3401 "AP bug: VHT capa missing from AssocResp\n");
3403 if (!elems
->vht_operation
&& bss_elems
.vht_operation
&&
3404 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3405 elems
->vht_operation
= bss_elems
.vht_operation
;
3407 "AP bug: VHT operation missing from AssocResp\n");
3412 * We previously checked these in the beacon/probe response, so
3413 * they should be present here. This is just a safety net.
3415 if (!is_6ghz
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3416 (!elems
->wmm_param
|| !elems
->ht_cap_elem
|| !elems
->ht_operation
)) {
3418 "HT AP is missing WMM params or HT capability/operation\n");
3423 if (!is_6ghz
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3424 (!elems
->vht_cap_elem
|| !elems
->vht_operation
)) {
3426 "VHT AP is missing VHT capability/operation\n");
3431 if (is_6ghz
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
3432 !elems
->he_6ghz_capa
) {
3434 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3439 mutex_lock(&sdata
->local
->sta_mtx
);
3441 * station info was already allocated and inserted before
3442 * the association and should be available to us
3444 sta
= sta_info_get(sdata
, cbss
->bssid
);
3445 if (WARN_ON(!sta
)) {
3446 mutex_unlock(&sdata
->local
->sta_mtx
);
3451 sband
= ieee80211_get_sband(sdata
);
3453 mutex_unlock(&sdata
->local
->sta_mtx
);
3458 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
3459 (!elems
->he_cap
|| !elems
->he_operation
)) {
3460 mutex_unlock(&sdata
->local
->sta_mtx
);
3462 "HE AP is missing HE capability/operation\n");
3467 /* Set up internal HT/VHT capabilities */
3468 if (elems
->ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
3469 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
3470 elems
->ht_cap_elem
, sta
);
3472 if (elems
->vht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
3473 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
3474 elems
->vht_cap_elem
, sta
);
3476 if (elems
->he_operation
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
3478 ieee80211_he_cap_ie_to_sta_he_cap(sdata
, sband
,
3481 elems
->he_6ghz_capa
,
3484 bss_conf
->he_support
= sta
->sta
.he_cap
.has_he
;
3485 if (elems
->rsnx
&& elems
->rsnx_len
&&
3486 (elems
->rsnx
[0] & WLAN_RSNX_CAPA_PROTECTED_TWT
) &&
3487 wiphy_ext_feature_isset(local
->hw
.wiphy
,
3488 NL80211_EXT_FEATURE_PROTECTED_TWT
))
3489 bss_conf
->twt_protected
= true;
3491 bss_conf
->twt_protected
= false;
3493 changed
|= ieee80211_recalc_twt_req(sdata
, sta
, elems
);
3495 bss_conf
->he_support
= false;
3496 bss_conf
->twt_requester
= false;
3497 bss_conf
->twt_protected
= false;
3500 bss_conf
->twt_broadcast
=
3501 ieee80211_twt_bcast_support(sdata
, bss_conf
, sband
, sta
);
3503 if (bss_conf
->he_support
) {
3504 bss_conf
->he_bss_color
.color
=
3505 le32_get_bits(elems
->he_operation
->he_oper_params
,
3506 IEEE80211_HE_OPERATION_BSS_COLOR_MASK
);
3507 bss_conf
->he_bss_color
.partial
=
3508 le32_get_bits(elems
->he_operation
->he_oper_params
,
3509 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR
);
3510 bss_conf
->he_bss_color
.enabled
=
3511 !le32_get_bits(elems
->he_operation
->he_oper_params
,
3512 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED
);
3514 if (bss_conf
->he_bss_color
.enabled
)
3515 changed
|= BSS_CHANGED_HE_BSS_COLOR
;
3517 bss_conf
->htc_trig_based_pkt_ext
=
3518 le32_get_bits(elems
->he_operation
->he_oper_params
,
3519 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK
);
3520 bss_conf
->frame_time_rts_th
=
3521 le32_get_bits(elems
->he_operation
->he_oper_params
,
3522 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK
);
3524 bss_conf
->uora_exists
= !!elems
->uora_element
;
3525 if (elems
->uora_element
)
3526 bss_conf
->uora_ocw_range
= elems
->uora_element
[0];
3528 ieee80211_he_op_ie_to_bss_conf(&sdata
->vif
, elems
->he_operation
);
3529 ieee80211_he_spr_ie_to_bss_conf(&sdata
->vif
, elems
->he_spr
);
3530 /* TODO: OPEN: what happens if BSS color disable is set? */
3533 if (cbss
->transmitted_bss
) {
3534 bss_conf
->nontransmitted
= true;
3535 ether_addr_copy(bss_conf
->transmitter_bssid
,
3536 cbss
->transmitted_bss
->bssid
);
3537 bss_conf
->bssid_indicator
= cbss
->max_bssid_indicator
;
3538 bss_conf
->bssid_index
= cbss
->bssid_index
;
3542 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3543 * in their association response, so ignore that data for our own
3544 * configuration. If it changed since the last beacon, we'll get the
3545 * next beacon and update then.
3549 * If an operating mode notification IE is present, override the
3550 * NSS calculation (that would be done in rate_control_rate_init())
3551 * and use the # of streams from that element.
3553 if (elems
->opmode_notif
&&
3554 !(*elems
->opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)) {
3557 nss
= *elems
->opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
3558 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
3560 sta
->sta
.rx_nss
= nss
;
3563 rate_control_rate_init(sta
);
3565 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
) {
3566 set_sta_flag(sta
, WLAN_STA_MFP
);
3567 sta
->sta
.mfp
= true;
3569 sta
->sta
.mfp
= false;
3572 sta
->sta
.wme
= (elems
->wmm_param
|| elems
->s1g_capab
) &&
3573 local
->hw
.queues
>= IEEE80211_NUM_ACS
;
3575 err
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
3576 if (!err
&& !(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
3577 err
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
3580 "failed to move station %pM to desired state\n",
3582 WARN_ON(__sta_info_destroy(sta
));
3583 mutex_unlock(&sdata
->local
->sta_mtx
);
3588 if (sdata
->wdev
.use_4addr
)
3589 drv_sta_set_4addr(local
, sdata
, &sta
->sta
, true);
3591 mutex_unlock(&sdata
->local
->sta_mtx
);
3594 * Always handle WMM once after association regardless
3595 * of the first value the AP uses. Setting -1 here has
3596 * that effect because the AP values is an unsigned
3599 ifmgd
->wmm_last_param_set
= -1;
3600 ifmgd
->mu_edca_last_param_set
= -1;
3602 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
3603 ieee80211_set_wmm_default(sdata
, false, false);
3604 } else if (!ieee80211_sta_wmm_params(local
, sdata
, elems
->wmm_param
,
3605 elems
->wmm_param_len
,
3606 elems
->mu_edca_param_set
)) {
3607 /* still enable QoS since we might have HT/VHT */
3608 ieee80211_set_wmm_default(sdata
, false, true);
3609 /* set the disable-WMM flag in this case to disable
3610 * tracking WMM parameter changes in the beacon if
3611 * the parameters weren't actually valid. Doing so
3612 * avoids changing parameters very strangely when
3613 * the AP is going back and forth between valid and
3614 * invalid parameters.
3616 ifmgd
->flags
|= IEEE80211_STA_DISABLE_WMM
;
3618 changed
|= BSS_CHANGED_QOS
;
3620 if (elems
->max_idle_period_ie
) {
3621 bss_conf
->max_idle_period
=
3622 le16_to_cpu(elems
->max_idle_period_ie
->max_idle_period
);
3623 bss_conf
->protected_keep_alive
=
3624 !!(elems
->max_idle_period_ie
->idle_options
&
3625 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE
);
3626 changed
|= BSS_CHANGED_KEEP_ALIVE
;
3628 bss_conf
->max_idle_period
= 0;
3629 bss_conf
->protected_keep_alive
= false;
3632 /* set assoc capability (AID was already set earlier),
3633 * ieee80211_set_associated() will tell the driver */
3634 bss_conf
->assoc_capability
= capab_info
;
3635 ieee80211_set_associated(sdata
, cbss
, changed
);
3638 * If we're using 4-addr mode, let the AP know that we're
3639 * doing so, so that it can create the STA VLAN on its side
3641 if (ifmgd
->use_4addr
)
3642 ieee80211_send_4addr_nullfunc(local
, sdata
);
3645 * Start timer to probe the connection to the AP now.
3646 * Also start the timer that will detect beacon loss.
3648 ieee80211_sta_reset_beacon_monitor(sdata
);
3649 ieee80211_sta_reset_conn_monitor(sdata
);
3657 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
3658 struct ieee80211_mgmt
*mgmt
,
3661 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3662 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3663 u16 capab_info
, status_code
, aid
;
3664 struct ieee802_11_elems elems
;
3665 int ac
, uapsd_queues
= -1;
3668 struct cfg80211_bss
*cbss
;
3669 struct ieee80211_event event
= {
3671 .u
.mlme
.data
= ASSOC_EVENT
,
3673 struct ieee80211_prep_tx_info info
= {};
3675 sdata_assert_lock(sdata
);
3680 if (!ether_addr_equal(assoc_data
->bss
->bssid
, mgmt
->bssid
))
3683 cbss
= assoc_data
->bss
;
3686 * AssocResp and ReassocResp have identical structure, so process both
3687 * of them in this function.
3693 reassoc
= ieee80211_is_reassoc_resp(mgmt
->frame_control
);
3694 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3695 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
3696 pos
= mgmt
->u
.assoc_resp
.variable
;
3697 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3698 if (cbss
->channel
->band
== NL80211_BAND_S1GHZ
) {
3699 pos
= (u8
*) mgmt
->u
.s1g_assoc_resp
.variable
;
3704 * Note: this may not be perfect, AP might misbehave - if
3705 * anyone needs to rely on perfect complete notification
3706 * with the exact right subtype, then we need to track what
3707 * we actually transmitted.
3709 info
.subtype
= reassoc
? IEEE80211_STYPE_REASSOC_REQ
:
3710 IEEE80211_STYPE_ASSOC_REQ
;
3713 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3714 reassoc
? "Rea" : "A", mgmt
->sa
,
3715 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
3717 if (assoc_data
->fils_kek_len
&&
3718 fils_decrypt_assoc_resp(sdata
, (u8
*)mgmt
, &len
, assoc_data
) < 0)
3721 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*)mgmt
), false, &elems
,
3722 mgmt
->bssid
, assoc_data
->bss
->bssid
);
3724 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
3725 elems
.timeout_int
&&
3726 elems
.timeout_int
->type
== WLAN_TIMEOUT_ASSOC_COMEBACK
) {
3728 tu
= le32_to_cpu(elems
.timeout_int
->value
);
3729 ms
= tu
* 1024 / 1000;
3731 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3733 assoc_data
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
3734 assoc_data
->timeout_started
= true;
3735 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
3736 run_again(sdata
, assoc_data
->timeout
);
3740 if (status_code
!= WLAN_STATUS_SUCCESS
) {
3741 sdata_info(sdata
, "%pM denied association (code=%d)\n",
3742 mgmt
->sa
, status_code
);
3743 ieee80211_destroy_assoc_data(sdata
, false, false);
3744 event
.u
.mlme
.status
= MLME_DENIED
;
3745 event
.u
.mlme
.reason
= status_code
;
3746 drv_event_callback(sdata
->local
, sdata
, &event
);
3748 if (!ieee80211_assoc_success(sdata
, cbss
, mgmt
, len
, &elems
)) {
3749 /* oops -- internal error -- send timeout for now */
3750 ieee80211_destroy_assoc_data(sdata
, false, false);
3751 cfg80211_assoc_timeout(sdata
->dev
, cbss
);
3754 event
.u
.mlme
.status
= MLME_SUCCESS
;
3755 drv_event_callback(sdata
->local
, sdata
, &event
);
3756 sdata_info(sdata
, "associated\n");
3759 * destroy assoc_data afterwards, as otherwise an idle
3760 * recalc after assoc_data is NULL but before associated
3761 * is set can cause the interface to go idle
3763 ieee80211_destroy_assoc_data(sdata
, true, false);
3765 /* get uapsd queues configuration */
3767 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
3768 if (sdata
->tx_conf
[ac
].uapsd
)
3769 uapsd_queues
|= ieee80211_ac_to_qos_mask
[ac
];
3774 cfg80211_rx_assoc_resp(sdata
->dev
, cbss
, (u8
*)mgmt
, len
, uapsd_queues
,
3775 ifmgd
->assoc_req_ies
, ifmgd
->assoc_req_ies_len
);
3777 drv_mgd_complete_tx(sdata
->local
, sdata
, &info
);
3780 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
3781 struct ieee80211_mgmt
*mgmt
, size_t len
,
3782 struct ieee80211_rx_status
*rx_status
)
3784 struct ieee80211_local
*local
= sdata
->local
;
3785 struct ieee80211_bss
*bss
;
3786 struct ieee80211_channel
*channel
;
3788 sdata_assert_lock(sdata
);
3790 channel
= ieee80211_get_channel_khz(local
->hw
.wiphy
,
3791 ieee80211_rx_status_to_khz(rx_status
));
3795 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, channel
);
3797 sdata
->vif
.bss_conf
.beacon_rate
= bss
->beacon_rate
;
3798 ieee80211_rx_bss_put(local
, bss
);
3803 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
3804 struct sk_buff
*skb
)
3806 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
3807 struct ieee80211_if_managed
*ifmgd
;
3808 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
3809 struct ieee80211_channel
*channel
;
3810 size_t baselen
, len
= skb
->len
;
3812 ifmgd
= &sdata
->u
.mgd
;
3814 sdata_assert_lock(sdata
);
3817 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3818 * "If a 6 GHz AP receives a Probe Request frame and responds with
3819 * a Probe Response frame [..], the Address 1 field of the Probe
3820 * Response frame shall be set to the broadcast address [..]"
3821 * So, on 6GHz band we should also accept broadcast responses.
3823 channel
= ieee80211_get_channel(sdata
->local
->hw
.wiphy
,
3828 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
) &&
3829 (channel
->band
!= NL80211_BAND_6GHZ
||
3830 !is_broadcast_ether_addr(mgmt
->da
)))
3831 return; /* ignore ProbeResp to foreign address */
3833 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
3837 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
);
3839 if (ifmgd
->associated
&&
3840 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3841 ieee80211_reset_ap_probe(sdata
);
3845 * This is the canonical list of information elements we care about,
3846 * the filter code also gives us all changes to the Microsoft OUI
3847 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3848 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3849 * changes to requested client power.
3851 * We implement beacon filtering in software since that means we can
3852 * avoid processing the frame here and in cfg80211, and userspace
3853 * will not be able to tell whether the hardware supports it or not.
3855 * XXX: This list needs to be dynamic -- userspace needs to be able to
3856 * add items it requires. It also needs to be able to tell us to
3857 * look out for other vendor IEs.
3859 static const u64 care_about_ies
=
3860 (1ULL << WLAN_EID_COUNTRY
) |
3861 (1ULL << WLAN_EID_ERP_INFO
) |
3862 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
3863 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
3864 (1ULL << WLAN_EID_HT_CAPABILITY
) |
3865 (1ULL << WLAN_EID_HT_OPERATION
) |
3866 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN
);
3868 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data
*sdata
,
3869 struct ieee80211_if_managed
*ifmgd
,
3870 struct ieee80211_bss_conf
*bss_conf
,
3871 struct ieee80211_local
*local
,
3872 struct ieee80211_rx_status
*rx_status
)
3874 /* Track average RSSI from the Beacon frames of the current AP */
3876 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
3877 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
3878 ewma_beacon_signal_init(&ifmgd
->ave_beacon_signal
);
3879 ifmgd
->last_cqm_event_signal
= 0;
3880 ifmgd
->count_beacon_signal
= 1;
3881 ifmgd
->last_ave_beacon_signal
= 0;
3883 ifmgd
->count_beacon_signal
++;
3886 ewma_beacon_signal_add(&ifmgd
->ave_beacon_signal
, -rx_status
->signal
);
3888 if (ifmgd
->rssi_min_thold
!= ifmgd
->rssi_max_thold
&&
3889 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3890 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3891 int last_sig
= ifmgd
->last_ave_beacon_signal
;
3892 struct ieee80211_event event
= {
3897 * if signal crosses either of the boundaries, invoke callback
3898 * with appropriate parameters
3900 if (sig
> ifmgd
->rssi_max_thold
&&
3901 (last_sig
<= ifmgd
->rssi_min_thold
|| last_sig
== 0)) {
3902 ifmgd
->last_ave_beacon_signal
= sig
;
3903 event
.u
.rssi
.data
= RSSI_EVENT_HIGH
;
3904 drv_event_callback(local
, sdata
, &event
);
3905 } else if (sig
< ifmgd
->rssi_min_thold
&&
3906 (last_sig
>= ifmgd
->rssi_max_thold
||
3908 ifmgd
->last_ave_beacon_signal
= sig
;
3909 event
.u
.rssi
.data
= RSSI_EVENT_LOW
;
3910 drv_event_callback(local
, sdata
, &event
);
3914 if (bss_conf
->cqm_rssi_thold
&&
3915 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
3916 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)) {
3917 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3918 int last_event
= ifmgd
->last_cqm_event_signal
;
3919 int thold
= bss_conf
->cqm_rssi_thold
;
3920 int hyst
= bss_conf
->cqm_rssi_hyst
;
3923 (last_event
== 0 || sig
< last_event
- hyst
)) {
3924 ifmgd
->last_cqm_event_signal
= sig
;
3925 ieee80211_cqm_rssi_notify(
3927 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3929 } else if (sig
> thold
&&
3930 (last_event
== 0 || sig
> last_event
+ hyst
)) {
3931 ifmgd
->last_cqm_event_signal
= sig
;
3932 ieee80211_cqm_rssi_notify(
3934 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3939 if (bss_conf
->cqm_rssi_low
&&
3940 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3941 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3942 int last_event
= ifmgd
->last_cqm_event_signal
;
3943 int low
= bss_conf
->cqm_rssi_low
;
3944 int high
= bss_conf
->cqm_rssi_high
;
3947 (last_event
== 0 || last_event
>= low
)) {
3948 ifmgd
->last_cqm_event_signal
= sig
;
3949 ieee80211_cqm_rssi_notify(
3951 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3953 } else if (sig
> high
&&
3954 (last_event
== 0 || last_event
<= high
)) {
3955 ifmgd
->last_cqm_event_signal
= sig
;
3956 ieee80211_cqm_rssi_notify(
3958 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3964 static bool ieee80211_rx_our_beacon(const u8
*tx_bssid
,
3965 struct cfg80211_bss
*bss
)
3967 if (ether_addr_equal(tx_bssid
, bss
->bssid
))
3969 if (!bss
->transmitted_bss
)
3971 return ether_addr_equal(tx_bssid
, bss
->transmitted_bss
->bssid
);
3974 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
3975 struct ieee80211_hdr
*hdr
, size_t len
,
3976 struct ieee80211_rx_status
*rx_status
)
3978 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3979 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3980 struct ieee80211_mgmt
*mgmt
= (void *) hdr
;
3982 struct ieee802_11_elems elems
;
3983 struct ieee80211_local
*local
= sdata
->local
;
3984 struct ieee80211_chanctx_conf
*chanctx_conf
;
3985 struct ieee80211_channel
*chan
;
3986 struct sta_info
*sta
;
3991 u8
*bssid
, *variable
= mgmt
->u
.beacon
.variable
;
3992 u8 deauth_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3994 sdata_assert_lock(sdata
);
3996 /* Process beacon from the current BSS */
3997 bssid
= ieee80211_get_bssid(hdr
, len
, sdata
->vif
.type
);
3998 if (ieee80211_is_s1g_beacon(mgmt
->frame_control
)) {
3999 struct ieee80211_ext
*ext
= (void *) mgmt
;
4001 if (ieee80211_is_s1g_short_beacon(ext
->frame_control
))
4002 variable
= ext
->u
.s1g_short_beacon
.variable
;
4004 variable
= ext
->u
.s1g_beacon
.variable
;
4007 baselen
= (u8
*) variable
- (u8
*) mgmt
;
4012 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
4013 if (!chanctx_conf
) {
4018 if (ieee80211_rx_status_to_khz(rx_status
) !=
4019 ieee80211_channel_to_khz(chanctx_conf
->def
.chan
)) {
4023 chan
= chanctx_conf
->def
.chan
;
4026 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->need_beacon
&&
4027 ieee80211_rx_our_beacon(bssid
, ifmgd
->assoc_data
->bss
)) {
4028 ieee802_11_parse_elems(variable
,
4029 len
- baselen
, false, &elems
,
4031 ifmgd
->assoc_data
->bss
->bssid
);
4033 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
);
4035 if (elems
.dtim_period
)
4036 ifmgd
->dtim_period
= elems
.dtim_period
;
4037 ifmgd
->have_beacon
= true;
4038 ifmgd
->assoc_data
->need_beacon
= false;
4039 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
4040 sdata
->vif
.bss_conf
.sync_tsf
=
4041 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
4042 sdata
->vif
.bss_conf
.sync_device_ts
=
4043 rx_status
->device_timestamp
;
4044 sdata
->vif
.bss_conf
.sync_dtim_count
= elems
.dtim_count
;
4047 if (elems
.mbssid_config_ie
)
4048 bss_conf
->profile_periodicity
=
4049 elems
.mbssid_config_ie
->profile_periodicity
;
4051 bss_conf
->profile_periodicity
= 0;
4053 if (elems
.ext_capab_len
>= 11 &&
4054 (elems
.ext_capab
[10] & WLAN_EXT_CAPA11_EMA_SUPPORT
))
4055 bss_conf
->ema_ap
= true;
4057 bss_conf
->ema_ap
= false;
4059 /* continue assoc process */
4060 ifmgd
->assoc_data
->timeout
= jiffies
;
4061 ifmgd
->assoc_data
->timeout_started
= true;
4062 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4066 if (!ifmgd
->associated
||
4067 !ieee80211_rx_our_beacon(bssid
, ifmgd
->associated
))
4069 bssid
= ifmgd
->associated
->bssid
;
4071 if (!(rx_status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
4072 ieee80211_handle_beacon_sig(sdata
, ifmgd
, bss_conf
,
4075 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
) {
4076 mlme_dbg_ratelimited(sdata
,
4077 "cancelling AP probe due to a received beacon\n");
4078 ieee80211_reset_ap_probe(sdata
);
4082 * Push the beacon loss detection into the future since
4083 * we are processing a beacon from the AP just now.
4085 ieee80211_sta_reset_beacon_monitor(sdata
);
4087 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4088 * element (which carries the beacon interval). Don't forget to add a
4089 * bit to care_about_ies[] above if mac80211 is interested in a
4090 * changing S1G element.
4092 if (!ieee80211_is_s1g_beacon(hdr
->frame_control
))
4093 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
4094 ncrc
= ieee802_11_parse_elems_crc(variable
,
4095 len
- baselen
, false, &elems
,
4096 care_about_ies
, ncrc
,
4097 mgmt
->bssid
, bssid
);
4099 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
4100 ieee80211_check_tim(elems
.tim
, elems
.tim_len
, bss_conf
->aid
)) {
4101 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
4102 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
4103 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
4104 ieee80211_hw_config(local
,
4105 IEEE80211_CONF_CHANGE_PS
);
4107 ieee80211_send_nullfunc(local
, sdata
, false);
4108 } else if (!local
->pspolling
&& sdata
->u
.mgd
.powersave
) {
4109 local
->pspolling
= true;
4112 * Here is assumed that the driver will be
4113 * able to send ps-poll frame and receive a
4114 * response even though power save mode is
4115 * enabled, but some drivers might require
4116 * to disable power save here. This needs
4117 * to be investigated.
4119 ieee80211_send_pspoll(local
, sdata
);
4123 if (sdata
->vif
.p2p
||
4124 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
4125 struct ieee80211_p2p_noa_attr noa
= {};
4128 ret
= cfg80211_get_p2p_attr(variable
,
4130 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
4131 (u8
*) &noa
, sizeof(noa
));
4133 if (sdata
->u
.mgd
.p2p_noa_index
!= noa
.index
) {
4134 /* valid noa_attr and index changed */
4135 sdata
->u
.mgd
.p2p_noa_index
= noa
.index
;
4136 memcpy(&bss_conf
->p2p_noa_attr
, &noa
, sizeof(noa
));
4137 changed
|= BSS_CHANGED_P2P_PS
;
4139 * make sure we update all information, the CRC
4140 * mechanism doesn't look at P2P attributes.
4142 ifmgd
->beacon_crc_valid
= false;
4144 } else if (sdata
->u
.mgd
.p2p_noa_index
!= -1) {
4145 /* noa_attr not found and we had valid noa_attr before */
4146 sdata
->u
.mgd
.p2p_noa_index
= -1;
4147 memset(&bss_conf
->p2p_noa_attr
, 0, sizeof(bss_conf
->p2p_noa_attr
));
4148 changed
|= BSS_CHANGED_P2P_PS
;
4149 ifmgd
->beacon_crc_valid
= false;
4153 if (ifmgd
->csa_waiting_bcn
)
4154 ieee80211_chswitch_post_beacon(sdata
);
4157 * Update beacon timing and dtim count on every beacon appearance. This
4158 * will allow the driver to use the most updated values. Do it before
4159 * comparing this one with last received beacon.
4160 * IMPORTANT: These parameters would possibly be out of sync by the time
4161 * the driver will use them. The synchronized view is currently
4162 * guaranteed only in certain callbacks.
4164 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
) &&
4165 !ieee80211_is_s1g_beacon(hdr
->frame_control
)) {
4166 sdata
->vif
.bss_conf
.sync_tsf
=
4167 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
4168 sdata
->vif
.bss_conf
.sync_device_ts
=
4169 rx_status
->device_timestamp
;
4170 sdata
->vif
.bss_conf
.sync_dtim_count
= elems
.dtim_count
;
4173 if ((ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
) ||
4174 ieee80211_is_s1g_short_beacon(mgmt
->frame_control
))
4176 ifmgd
->beacon_crc
= ncrc
;
4177 ifmgd
->beacon_crc_valid
= true;
4179 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
);
4181 ieee80211_sta_process_chanswitch(sdata
, rx_status
->mactime
,
4182 rx_status
->device_timestamp
,
4185 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) &&
4186 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
4187 elems
.wmm_param_len
,
4188 elems
.mu_edca_param_set
))
4189 changed
|= BSS_CHANGED_QOS
;
4192 * If we haven't had a beacon before, tell the driver about the
4193 * DTIM period (and beacon timing if desired) now.
4195 if (!ifmgd
->have_beacon
) {
4196 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4197 bss_conf
->dtim_period
= elems
.dtim_period
?: 1;
4199 changed
|= BSS_CHANGED_BEACON_INFO
;
4200 ifmgd
->have_beacon
= true;
4202 mutex_lock(&local
->iflist_mtx
);
4203 ieee80211_recalc_ps(local
);
4204 mutex_unlock(&local
->iflist_mtx
);
4206 ieee80211_recalc_ps_vif(sdata
);
4209 if (elems
.erp_info
) {
4211 erp_value
= elems
.erp_info
[0];
4216 if (!ieee80211_is_s1g_beacon(hdr
->frame_control
))
4217 changed
|= ieee80211_handle_bss_capability(sdata
,
4218 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
4219 erp_valid
, erp_value
);
4221 mutex_lock(&local
->sta_mtx
);
4222 sta
= sta_info_get(sdata
, bssid
);
4224 changed
|= ieee80211_recalc_twt_req(sdata
, sta
, &elems
);
4226 if (ieee80211_config_bw(sdata
, sta
, elems
.ht_cap_elem
,
4227 elems
.vht_cap_elem
, elems
.ht_operation
,
4228 elems
.vht_operation
, elems
.he_operation
,
4229 elems
.s1g_oper
, bssid
, &changed
)) {
4230 mutex_unlock(&local
->sta_mtx
);
4232 "failed to follow AP %pM bandwidth change, disconnect\n",
4234 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4235 WLAN_REASON_DEAUTH_LEAVING
,
4237 ieee80211_report_disconnect(sdata
, deauth_buf
,
4238 sizeof(deauth_buf
), true,
4239 WLAN_REASON_DEAUTH_LEAVING
,
4244 if (sta
&& elems
.opmode_notif
)
4245 ieee80211_vht_handle_opmode(sdata
, sta
, *elems
.opmode_notif
,
4247 mutex_unlock(&local
->sta_mtx
);
4249 changed
|= ieee80211_handle_pwr_constr(sdata
, chan
, mgmt
,
4251 elems
.country_elem_len
,
4252 elems
.pwr_constr_elem
,
4253 elems
.cisco_dtpc_elem
);
4255 ieee80211_bss_info_change_notify(sdata
, changed
);
4258 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data
*sdata
,
4259 struct sk_buff
*skb
)
4261 struct ieee80211_rx_status
*rx_status
;
4262 struct ieee80211_hdr
*hdr
;
4265 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
4266 hdr
= (struct ieee80211_hdr
*) skb
->data
;
4267 fc
= le16_to_cpu(hdr
->frame_control
);
4270 switch (fc
& IEEE80211_FCTL_STYPE
) {
4271 case IEEE80211_STYPE_S1G_BEACON
:
4272 ieee80211_rx_mgmt_beacon(sdata
, hdr
, skb
->len
, rx_status
);
4275 sdata_unlock(sdata
);
4278 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
4279 struct sk_buff
*skb
)
4281 struct ieee80211_rx_status
*rx_status
;
4282 struct ieee80211_mgmt
*mgmt
;
4284 struct ieee802_11_elems elems
;
4287 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
4288 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
4289 fc
= le16_to_cpu(mgmt
->frame_control
);
4293 switch (fc
& IEEE80211_FCTL_STYPE
) {
4294 case IEEE80211_STYPE_BEACON
:
4295 ieee80211_rx_mgmt_beacon(sdata
, (void *)mgmt
,
4296 skb
->len
, rx_status
);
4298 case IEEE80211_STYPE_PROBE_RESP
:
4299 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
4301 case IEEE80211_STYPE_AUTH
:
4302 ieee80211_rx_mgmt_auth(sdata
, mgmt
, skb
->len
);
4304 case IEEE80211_STYPE_DEAUTH
:
4305 ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
4307 case IEEE80211_STYPE_DISASSOC
:
4308 ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
4310 case IEEE80211_STYPE_ASSOC_RESP
:
4311 case IEEE80211_STYPE_REASSOC_RESP
:
4312 ieee80211_rx_mgmt_assoc_resp(sdata
, mgmt
, skb
->len
);
4314 case IEEE80211_STYPE_ACTION
:
4315 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
) {
4316 ies_len
= skb
->len
-
4317 offsetof(struct ieee80211_mgmt
,
4318 u
.action
.u
.chan_switch
.variable
);
4323 /* CSA IE cannot be overridden, no need for BSSID */
4324 ieee802_11_parse_elems(
4325 mgmt
->u
.action
.u
.chan_switch
.variable
,
4326 ies_len
, true, &elems
, mgmt
->bssid
, NULL
);
4328 if (elems
.parse_error
)
4331 ieee80211_sta_process_chanswitch(sdata
,
4333 rx_status
->device_timestamp
,
4335 } else if (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
) {
4336 ies_len
= skb
->len
-
4337 offsetof(struct ieee80211_mgmt
,
4338 u
.action
.u
.ext_chan_switch
.variable
);
4344 * extended CSA IE can't be overridden, no need for
4347 ieee802_11_parse_elems(
4348 mgmt
->u
.action
.u
.ext_chan_switch
.variable
,
4349 ies_len
, true, &elems
, mgmt
->bssid
, NULL
);
4351 if (elems
.parse_error
)
4354 /* for the handling code pretend this was also an IE */
4355 elems
.ext_chansw_ie
=
4356 &mgmt
->u
.action
.u
.ext_chan_switch
.data
;
4358 ieee80211_sta_process_chanswitch(sdata
,
4360 rx_status
->device_timestamp
,
4365 sdata_unlock(sdata
);
4368 static void ieee80211_sta_timer(struct timer_list
*t
)
4370 struct ieee80211_sub_if_data
*sdata
=
4371 from_timer(sdata
, t
, u
.mgd
.timer
);
4373 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
4376 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
4377 u8
*bssid
, u8 reason
, bool tx
)
4379 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4381 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
, reason
,
4384 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
4388 static int ieee80211_auth(struct ieee80211_sub_if_data
*sdata
)
4390 struct ieee80211_local
*local
= sdata
->local
;
4391 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4392 struct ieee80211_mgd_auth_data
*auth_data
= ifmgd
->auth_data
;
4396 struct ieee80211_prep_tx_info info
= {
4397 .subtype
= IEEE80211_STYPE_AUTH
,
4400 sdata_assert_lock(sdata
);
4402 if (WARN_ON_ONCE(!auth_data
))
4407 if (auth_data
->tries
> IEEE80211_AUTH_MAX_TRIES
) {
4408 sdata_info(sdata
, "authentication with %pM timed out\n",
4409 auth_data
->bss
->bssid
);
4412 * Most likely AP is not in the range so remove the
4413 * bss struct for that AP.
4415 cfg80211_unlink_bss(local
->hw
.wiphy
, auth_data
->bss
);
4420 if (auth_data
->algorithm
== WLAN_AUTH_SAE
)
4421 info
.duration
= jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE
);
4423 drv_mgd_prepare_tx(local
, sdata
, &info
);
4425 sdata_info(sdata
, "send auth to %pM (try %d/%d)\n",
4426 auth_data
->bss
->bssid
, auth_data
->tries
,
4427 IEEE80211_AUTH_MAX_TRIES
);
4429 auth_data
->expected_transaction
= 2;
4431 if (auth_data
->algorithm
== WLAN_AUTH_SAE
) {
4432 trans
= auth_data
->sae_trans
;
4433 status
= auth_data
->sae_status
;
4434 auth_data
->expected_transaction
= trans
;
4437 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
4438 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
4439 IEEE80211_TX_INTFL_MLME_CONN_TX
;
4441 ieee80211_send_auth(sdata
, trans
, auth_data
->algorithm
, status
,
4442 auth_data
->data
, auth_data
->data_len
,
4443 auth_data
->bss
->bssid
,
4444 auth_data
->bss
->bssid
, NULL
, 0, 0,
4447 if (tx_flags
== 0) {
4448 if (auth_data
->algorithm
== WLAN_AUTH_SAE
)
4449 auth_data
->timeout
= jiffies
+
4450 IEEE80211_AUTH_TIMEOUT_SAE
;
4452 auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
4454 auth_data
->timeout
=
4455 round_jiffies_up(jiffies
+ IEEE80211_AUTH_TIMEOUT_LONG
);
4458 auth_data
->timeout_started
= true;
4459 run_again(sdata
, auth_data
->timeout
);
4464 static int ieee80211_do_assoc(struct ieee80211_sub_if_data
*sdata
)
4466 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
4467 struct ieee80211_local
*local
= sdata
->local
;
4470 sdata_assert_lock(sdata
);
4472 assoc_data
->tries
++;
4473 if (assoc_data
->tries
> IEEE80211_ASSOC_MAX_TRIES
) {
4474 sdata_info(sdata
, "association with %pM timed out\n",
4475 assoc_data
->bss
->bssid
);
4478 * Most likely AP is not in the range so remove the
4479 * bss struct for that AP.
4481 cfg80211_unlink_bss(local
->hw
.wiphy
, assoc_data
->bss
);
4486 sdata_info(sdata
, "associate with %pM (try %d/%d)\n",
4487 assoc_data
->bss
->bssid
, assoc_data
->tries
,
4488 IEEE80211_ASSOC_MAX_TRIES
);
4489 ret
= ieee80211_send_assoc(sdata
);
4493 if (!ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
4494 assoc_data
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
4495 assoc_data
->timeout_started
= true;
4496 run_again(sdata
, assoc_data
->timeout
);
4498 assoc_data
->timeout
=
4499 round_jiffies_up(jiffies
+
4500 IEEE80211_ASSOC_TIMEOUT_LONG
);
4501 assoc_data
->timeout_started
= true;
4502 run_again(sdata
, assoc_data
->timeout
);
4508 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data
*sdata
,
4509 __le16 fc
, bool acked
)
4511 struct ieee80211_local
*local
= sdata
->local
;
4513 sdata
->u
.mgd
.status_fc
= fc
;
4514 sdata
->u
.mgd
.status_acked
= acked
;
4515 sdata
->u
.mgd
.status_received
= true;
4517 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
4520 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
4522 struct ieee80211_local
*local
= sdata
->local
;
4523 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4527 if (ifmgd
->status_received
) {
4528 __le16 fc
= ifmgd
->status_fc
;
4529 bool status_acked
= ifmgd
->status_acked
;
4531 ifmgd
->status_received
= false;
4532 if (ifmgd
->auth_data
&& ieee80211_is_auth(fc
)) {
4534 if (ifmgd
->auth_data
->algorithm
==
4536 ifmgd
->auth_data
->timeout
=
4538 IEEE80211_AUTH_TIMEOUT_SAE
;
4540 ifmgd
->auth_data
->timeout
=
4542 IEEE80211_AUTH_TIMEOUT_SHORT
;
4543 run_again(sdata
, ifmgd
->auth_data
->timeout
);
4545 ifmgd
->auth_data
->timeout
= jiffies
- 1;
4547 ifmgd
->auth_data
->timeout_started
= true;
4548 } else if (ifmgd
->assoc_data
&&
4549 (ieee80211_is_assoc_req(fc
) ||
4550 ieee80211_is_reassoc_req(fc
))) {
4552 ifmgd
->assoc_data
->timeout
=
4553 jiffies
+ IEEE80211_ASSOC_TIMEOUT_SHORT
;
4554 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4556 ifmgd
->assoc_data
->timeout
= jiffies
- 1;
4558 ifmgd
->assoc_data
->timeout_started
= true;
4562 if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
&&
4563 time_after(jiffies
, ifmgd
->auth_data
->timeout
)) {
4564 if (ifmgd
->auth_data
->done
|| ifmgd
->auth_data
->waiting
) {
4566 * ok ... we waited for assoc or continuation but
4567 * userspace didn't do it, so kill the auth data
4569 ieee80211_destroy_auth_data(sdata
, false);
4570 } else if (ieee80211_auth(sdata
)) {
4572 struct ieee80211_event event
= {
4574 .u
.mlme
.data
= AUTH_EVENT
,
4575 .u
.mlme
.status
= MLME_TIMEOUT
,
4578 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
4580 ieee80211_destroy_auth_data(sdata
, false);
4582 cfg80211_auth_timeout(sdata
->dev
, bssid
);
4583 drv_event_callback(sdata
->local
, sdata
, &event
);
4585 } else if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
)
4586 run_again(sdata
, ifmgd
->auth_data
->timeout
);
4588 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
&&
4589 time_after(jiffies
, ifmgd
->assoc_data
->timeout
)) {
4590 if ((ifmgd
->assoc_data
->need_beacon
&& !ifmgd
->have_beacon
) ||
4591 ieee80211_do_assoc(sdata
)) {
4592 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
4593 struct ieee80211_event event
= {
4595 .u
.mlme
.data
= ASSOC_EVENT
,
4596 .u
.mlme
.status
= MLME_TIMEOUT
,
4599 ieee80211_destroy_assoc_data(sdata
, false, false);
4600 cfg80211_assoc_timeout(sdata
->dev
, bss
);
4601 drv_event_callback(sdata
->local
, sdata
, &event
);
4603 } else if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
)
4604 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4606 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
&&
4607 ifmgd
->associated
) {
4611 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4613 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
4614 max_tries
= max_nullfunc_tries
;
4616 max_tries
= max_probe_tries
;
4618 /* ACK received for nullfunc probing frame */
4619 if (!ifmgd
->probe_send_count
)
4620 ieee80211_reset_ap_probe(sdata
);
4621 else if (ifmgd
->nullfunc_failed
) {
4622 if (ifmgd
->probe_send_count
< max_tries
) {
4624 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4625 bssid
, ifmgd
->probe_send_count
,
4627 ieee80211_mgd_probe_ap_send(sdata
);
4630 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4632 ieee80211_sta_connection_lost(sdata
, bssid
,
4633 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
4636 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
4637 run_again(sdata
, ifmgd
->probe_timeout
);
4638 else if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
4640 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4641 bssid
, probe_wait_ms
);
4642 ieee80211_sta_connection_lost(sdata
, bssid
,
4643 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4644 } else if (ifmgd
->probe_send_count
< max_tries
) {
4646 "No probe response from AP %pM after %dms, try %d/%i\n",
4647 bssid
, probe_wait_ms
,
4648 ifmgd
->probe_send_count
, max_tries
);
4649 ieee80211_mgd_probe_ap_send(sdata
);
4652 * We actually lost the connection ... or did we?
4656 "No probe response from AP %pM after %dms, disconnecting.\n",
4657 bssid
, probe_wait_ms
);
4659 ieee80211_sta_connection_lost(sdata
, bssid
,
4660 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4664 sdata_unlock(sdata
);
4667 static void ieee80211_sta_bcn_mon_timer(struct timer_list
*t
)
4669 struct ieee80211_sub_if_data
*sdata
=
4670 from_timer(sdata
, t
, u
.mgd
.bcn_mon_timer
);
4671 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4673 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4676 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
4679 sdata
->u
.mgd
.connection_loss
= false;
4680 ieee80211_queue_work(&sdata
->local
->hw
,
4681 &sdata
->u
.mgd
.beacon_connection_loss_work
);
4684 static void ieee80211_sta_conn_mon_timer(struct timer_list
*t
)
4686 struct ieee80211_sub_if_data
*sdata
=
4687 from_timer(sdata
, t
, u
.mgd
.conn_mon_timer
);
4688 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4689 struct ieee80211_local
*local
= sdata
->local
;
4690 struct sta_info
*sta
;
4691 unsigned long timeout
;
4693 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4696 sta
= sta_info_get(sdata
, ifmgd
->bssid
);
4700 timeout
= sta
->status_stats
.last_ack
;
4701 if (time_before(sta
->status_stats
.last_ack
, sta
->rx_stats
.last_rx
))
4702 timeout
= sta
->rx_stats
.last_rx
;
4703 timeout
+= IEEE80211_CONNECTION_IDLE_TIME
;
4705 /* If timeout is after now, then update timer to fire at
4706 * the later date, but do not actually probe at this time.
4708 if (time_is_after_jiffies(timeout
)) {
4709 mod_timer(&ifmgd
->conn_mon_timer
, round_jiffies_up(timeout
));
4713 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
4716 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
4718 struct ieee80211_sub_if_data
*sdata
=
4719 container_of(work
, struct ieee80211_sub_if_data
,
4720 u
.mgd
.monitor_work
);
4722 ieee80211_mgd_probe_ap(sdata
, false);
4725 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
4727 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
4728 __ieee80211_stop_poll(sdata
);
4730 /* let's probe the connection once */
4731 if (!ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
4732 ieee80211_queue_work(&sdata
->local
->hw
,
4733 &sdata
->u
.mgd
.monitor_work
);
4738 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data
*sdata
)
4740 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4741 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4745 if (ifmgd
->auth_data
|| ifmgd
->assoc_data
) {
4746 const u8
*bssid
= ifmgd
->auth_data
?
4747 ifmgd
->auth_data
->bss
->bssid
:
4748 ifmgd
->assoc_data
->bss
->bssid
;
4751 * If we are trying to authenticate / associate while suspending,
4752 * cfg80211 won't know and won't actually abort those attempts,
4753 * thus we need to do that ourselves.
4755 ieee80211_send_deauth_disassoc(sdata
, bssid
, bssid
,
4756 IEEE80211_STYPE_DEAUTH
,
4757 WLAN_REASON_DEAUTH_LEAVING
,
4759 if (ifmgd
->assoc_data
)
4760 ieee80211_destroy_assoc_data(sdata
, false, true);
4761 if (ifmgd
->auth_data
)
4762 ieee80211_destroy_auth_data(sdata
, false);
4763 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4764 IEEE80211_DEAUTH_FRAME_LEN
,
4768 /* This is a bit of a hack - we should find a better and more generic
4769 * solution to this. Normally when suspending, cfg80211 will in fact
4770 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4771 * auth (not so important) or assoc (this is the problem) process.
4773 * As a consequence, it can happen that we are in the process of both
4774 * associating and suspending, and receive an association response
4775 * after cfg80211 has checked if it needs to disconnect, but before
4776 * we actually set the flag to drop incoming frames. This will then
4777 * cause the workqueue flush to process the association response in
4778 * the suspend, resulting in a successful association just before it
4779 * tries to remove the interface from the driver, which now though
4780 * has a channel context assigned ... this results in issues.
4782 * To work around this (for now) simply deauth here again if we're
4785 if (ifmgd
->associated
&& !sdata
->local
->wowlan
) {
4787 struct cfg80211_deauth_request req
= {
4788 .reason_code
= WLAN_REASON_DEAUTH_LEAVING
,
4792 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4793 ieee80211_mgd_deauth(sdata
, &req
);
4796 sdata_unlock(sdata
);
4799 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
4801 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4804 if (!ifmgd
->associated
) {
4805 sdata_unlock(sdata
);
4809 if (sdata
->flags
& IEEE80211_SDATA_DISCONNECT_RESUME
) {
4810 sdata
->flags
&= ~IEEE80211_SDATA_DISCONNECT_RESUME
;
4811 mlme_dbg(sdata
, "driver requested disconnect after resume\n");
4812 ieee80211_sta_connection_lost(sdata
,
4813 ifmgd
->associated
->bssid
,
4814 WLAN_REASON_UNSPECIFIED
,
4816 sdata_unlock(sdata
);
4819 sdata_unlock(sdata
);
4823 /* interface setup */
4824 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
4826 struct ieee80211_if_managed
*ifmgd
;
4828 ifmgd
= &sdata
->u
.mgd
;
4829 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
4830 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
4831 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
4832 ieee80211_beacon_connection_loss_work
);
4833 INIT_WORK(&ifmgd
->csa_connection_drop_work
,
4834 ieee80211_csa_connection_drop_work
);
4835 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_mgd_work
);
4836 INIT_DELAYED_WORK(&ifmgd
->tdls_peer_del_work
,
4837 ieee80211_tdls_peer_del_work
);
4838 timer_setup(&ifmgd
->timer
, ieee80211_sta_timer
, 0);
4839 timer_setup(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
, 0);
4840 timer_setup(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
, 0);
4841 timer_setup(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
, 0);
4842 INIT_DELAYED_WORK(&ifmgd
->tx_tspec_wk
,
4843 ieee80211_sta_handle_tspec_ac_params_wk
);
4846 ifmgd
->powersave
= sdata
->wdev
.ps
;
4847 ifmgd
->uapsd_queues
= sdata
->local
->hw
.uapsd_queues
;
4848 ifmgd
->uapsd_max_sp_len
= sdata
->local
->hw
.uapsd_max_sp_len
;
4849 ifmgd
->p2p_noa_index
= -1;
4851 if (sdata
->local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
)
4852 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
4854 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
4856 /* Setup TDLS data */
4857 spin_lock_init(&ifmgd
->teardown_lock
);
4858 ifmgd
->teardown_skb
= NULL
;
4859 ifmgd
->orig_teardown_skb
= NULL
;
4862 /* scan finished notification */
4863 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
4865 struct ieee80211_sub_if_data
*sdata
;
4867 /* Restart STA timers */
4869 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4870 if (ieee80211_sdata_running(sdata
))
4871 ieee80211_restart_sta_timer(sdata
);
4876 static u8
ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data
*sdata
,
4877 struct cfg80211_bss
*cbss
)
4879 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4880 const u8
*ht_cap_ie
, *vht_cap_ie
;
4881 const struct ieee80211_ht_cap
*ht_cap
;
4882 const struct ieee80211_vht_cap
*vht_cap
;
4885 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)
4888 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4889 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
)) {
4890 ht_cap
= (void *)(ht_cap_ie
+ 2);
4891 chains
= ieee80211_mcs_to_chains(&ht_cap
->mcs
);
4893 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4894 * "Tx Unequal Modulation Supported" fields.
4898 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
4901 vht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4902 if (vht_cap_ie
&& vht_cap_ie
[1] >= sizeof(*vht_cap
)) {
4906 vht_cap
= (void *)(vht_cap_ie
+ 2);
4907 tx_mcs_map
= le16_to_cpu(vht_cap
->supp_mcs
.tx_mcs_map
);
4908 for (nss
= 8; nss
> 0; nss
--) {
4909 if (((tx_mcs_map
>> (2 * (nss
- 1))) & 3) !=
4910 IEEE80211_VHT_MCS_NOT_SUPPORTED
)
4913 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4914 chains
= max(chains
, nss
);
4921 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data
*sdata
,
4922 struct ieee80211_supported_band
*sband
,
4923 const struct ieee80211_he_operation
*he_op
)
4925 const struct ieee80211_sta_he_cap
*sta_he_cap
=
4926 ieee80211_get_he_iftype_cap(sband
,
4927 ieee80211_vif_type_p2p(&sdata
->vif
));
4931 if (!sta_he_cap
|| !he_op
)
4934 ap_min_req_set
= le16_to_cpu(he_op
->he_mcs_nss_set
);
4936 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4937 for (i
= 0; i
< 3; i
++) {
4938 const struct ieee80211_he_mcs_nss_supp
*sta_mcs_nss_supp
=
4939 &sta_he_cap
->he_mcs_nss_supp
;
4940 u16 sta_mcs_map_rx
=
4941 le16_to_cpu(((__le16
*)sta_mcs_nss_supp
)[2 * i
]);
4942 u16 sta_mcs_map_tx
=
4943 le16_to_cpu(((__le16
*)sta_mcs_nss_supp
)[2 * i
+ 1]);
4945 bool verified
= true;
4948 * For each band there is a maximum of 8 spatial streams
4949 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4950 * of 2 bits per NSS (1-8), with the values defined in enum
4951 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4952 * capabilities aren't less than the AP's minimum requirements
4953 * for this HE BSS per SS.
4954 * It is enough to find one such band that meets the reqs.
4956 for (nss
= 8; nss
> 0; nss
--) {
4957 u8 sta_rx_val
= (sta_mcs_map_rx
>> (2 * (nss
- 1))) & 3;
4958 u8 sta_tx_val
= (sta_mcs_map_tx
>> (2 * (nss
- 1))) & 3;
4959 u8 ap_val
= (ap_min_req_set
>> (2 * (nss
- 1))) & 3;
4961 if (ap_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
)
4965 * Make sure the HE AP doesn't require MCSs that aren't
4966 * supported by the client
4968 if (sta_rx_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
||
4969 sta_tx_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
||
4970 (ap_val
> sta_rx_val
) || (ap_val
> sta_tx_val
)) {
4980 /* If here, STA doesn't meet AP's HE min requirements */
4984 static int ieee80211_prep_channel(struct ieee80211_sub_if_data
*sdata
,
4985 struct cfg80211_bss
*cbss
)
4987 struct ieee80211_local
*local
= sdata
->local
;
4988 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4989 const struct ieee80211_ht_cap
*ht_cap
= NULL
;
4990 const struct ieee80211_ht_operation
*ht_oper
= NULL
;
4991 const struct ieee80211_vht_operation
*vht_oper
= NULL
;
4992 const struct ieee80211_he_operation
*he_oper
= NULL
;
4993 const struct ieee80211_s1g_oper_ie
*s1g_oper
= NULL
;
4994 struct ieee80211_supported_band
*sband
;
4995 struct cfg80211_chan_def chandef
;
4996 bool is_6ghz
= cbss
->channel
->band
== NL80211_BAND_6GHZ
;
4997 bool is_5ghz
= cbss
->channel
->band
== NL80211_BAND_5GHZ
;
4998 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
5003 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
5005 ifmgd
->flags
&= ~(IEEE80211_STA_DISABLE_40MHZ
|
5006 IEEE80211_STA_DISABLE_80P80MHZ
|
5007 IEEE80211_STA_DISABLE_160MHZ
);
5009 /* disable HT/VHT/HE if we don't support them */
5010 if (!sband
->ht_cap
.ht_supported
&& !is_6ghz
) {
5011 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5012 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5013 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5016 if (!sband
->vht_cap
.vht_supported
&& is_5ghz
) {
5017 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5018 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5021 if (!ieee80211_get_he_iftype_cap(sband
,
5022 ieee80211_vif_type_p2p(&sdata
->vif
)))
5023 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5027 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) && !is_6ghz
) {
5028 const u8
*ht_oper_ie
, *ht_cap_ie
;
5030 ht_oper_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_OPERATION
);
5031 if (ht_oper_ie
&& ht_oper_ie
[1] >= sizeof(*ht_oper
))
5032 ht_oper
= (void *)(ht_oper_ie
+ 2);
5034 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
5035 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
))
5036 ht_cap
= (void *)(ht_cap_ie
+ 2);
5039 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5044 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) && !is_6ghz
) {
5045 const u8
*vht_oper_ie
, *vht_cap
;
5047 vht_oper_ie
= ieee80211_bss_get_ie(cbss
,
5048 WLAN_EID_VHT_OPERATION
);
5049 if (vht_oper_ie
&& vht_oper_ie
[1] >= sizeof(*vht_oper
))
5050 vht_oper
= (void *)(vht_oper_ie
+ 2);
5051 if (vht_oper
&& !ht_oper
) {
5054 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5055 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5056 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5057 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5060 vht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
5061 if (!vht_cap
|| vht_cap
[1] < sizeof(struct ieee80211_vht_cap
)) {
5062 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5067 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
)) {
5068 const struct cfg80211_bss_ies
*ies
;
5069 const u8
*he_oper_ie
;
5071 ies
= rcu_dereference(cbss
->ies
);
5072 he_oper_ie
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION
,
5073 ies
->data
, ies
->len
);
5075 he_oper_ie
[1] >= ieee80211_he_oper_size(&he_oper_ie
[3]))
5076 he_oper
= (void *)(he_oper_ie
+ 3);
5080 if (!ieee80211_verify_sta_he_mcs_support(sdata
, sband
, he_oper
))
5081 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5084 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5086 for (i
= 0; i
< sband
->n_channels
; i
++) {
5087 if (sband
->channels
[i
].flags
& (IEEE80211_CHAN_DISABLED
|
5088 IEEE80211_CHAN_NO_80MHZ
))
5096 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5098 if (sband
->band
== NL80211_BAND_S1GHZ
) {
5099 const u8
*s1g_oper_ie
;
5101 s1g_oper_ie
= ieee80211_bss_get_ie(cbss
,
5102 WLAN_EID_S1G_OPERATION
);
5103 if (s1g_oper_ie
&& s1g_oper_ie
[1] >= sizeof(*s1g_oper
))
5104 s1g_oper
= (void *)(s1g_oper_ie
+ 2);
5107 "AP missing S1G operation element?\n");
5110 ifmgd
->flags
|= ieee80211_determine_chantype(sdata
, sband
,
5113 ht_oper
, vht_oper
, he_oper
,
5117 sdata
->needed_rx_chains
= min(ieee80211_ht_vht_rx_chains(sdata
, cbss
),
5122 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
&& is_6ghz
) {
5123 sdata_info(sdata
, "Rejecting non-HE 6/7 GHz connection");
5127 /* will change later if needed */
5128 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
5130 mutex_lock(&local
->mtx
);
5132 * If this fails (possibly due to channel context sharing
5133 * on incompatible channels, e.g. 80+80 and 160 sharing the
5134 * same control channel) try to use a smaller bandwidth.
5136 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
5137 IEEE80211_CHANCTX_SHARED
);
5139 /* don't downgrade for 5 and 10 MHz channels, though. */
5140 if (chandef
.width
== NL80211_CHAN_WIDTH_5
||
5141 chandef
.width
== NL80211_CHAN_WIDTH_10
)
5144 while (ret
&& chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) {
5145 ifmgd
->flags
|= ieee80211_chandef_downgrade(&chandef
);
5146 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
5147 IEEE80211_CHANCTX_SHARED
);
5150 mutex_unlock(&local
->mtx
);
5154 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies
*ies
,
5155 u8
*dtim_count
, u8
*dtim_period
)
5157 const u8
*tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
, ies
->data
, ies
->len
);
5158 const u8
*idx_ie
= cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX
, ies
->data
,
5160 const struct ieee80211_tim_ie
*tim
= NULL
;
5161 const struct ieee80211_bssid_index
*idx
;
5162 bool valid
= tim_ie
&& tim_ie
[1] >= 2;
5165 tim
= (void *)(tim_ie
+ 2);
5168 *dtim_count
= valid
? tim
->dtim_count
: 0;
5171 *dtim_period
= valid
? tim
->dtim_period
: 0;
5173 /* Check if value is overridden by non-transmitted profile */
5174 if (!idx_ie
|| idx_ie
[1] < 3)
5177 idx
= (void *)(idx_ie
+ 2);
5180 *dtim_count
= idx
->dtim_count
;
5183 *dtim_period
= idx
->dtim_period
;
5188 static int ieee80211_prep_connection(struct ieee80211_sub_if_data
*sdata
,
5189 struct cfg80211_bss
*cbss
, bool assoc
,
5192 struct ieee80211_local
*local
= sdata
->local
;
5193 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5194 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
5195 struct sta_info
*new_sta
= NULL
;
5196 struct ieee80211_supported_band
*sband
;
5197 bool have_sta
= false;
5200 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
5202 if (WARN_ON(!ifmgd
->auth_data
&& !ifmgd
->assoc_data
))
5205 /* If a reconfig is happening, bail out */
5206 if (local
->in_reconfig
)
5211 have_sta
= sta_info_get(sdata
, cbss
->bssid
);
5216 new_sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
5222 * Set up the information for the new channel before setting the
5223 * new channel. We can't - completely race-free - change the basic
5224 * rates bitmap and the channel (sband) that it refers to, but if
5225 * we set it up before we at least avoid calling into the driver's
5226 * bss_info_changed() method with invalid information (since we do
5227 * call that from changing the channel - only for IDLE and perhaps
5228 * some others, but ...).
5230 * So to avoid that, just set up all the new information before the
5231 * channel, but tell the driver to apply it only afterwards, since
5232 * it might need the new channel for that.
5235 u32 rates
= 0, basic_rates
= 0;
5236 bool have_higher_than_11mbit
= false;
5237 int min_rate
= INT_MAX
, min_rate_index
= -1;
5238 const struct cfg80211_bss_ies
*ies
;
5239 int shift
= ieee80211_vif_get_shift(&sdata
->vif
);
5241 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5242 if (cbss
->channel
->band
== NL80211_BAND_S1GHZ
) {
5243 ieee80211_s1g_sta_rate_init(new_sta
);
5247 ieee80211_get_rates(sband
, bss
->supp_rates
,
5248 bss
->supp_rates_len
,
5249 &rates
, &basic_rates
,
5250 &have_higher_than_11mbit
,
5251 &min_rate
, &min_rate_index
,
5255 * This used to be a workaround for basic rates missing
5256 * in the association response frame. Now that we no
5257 * longer use the basic rates from there, it probably
5258 * doesn't happen any more, but keep the workaround so
5259 * in case some *other* APs are buggy in different ways
5260 * we can connect -- with a warning.
5261 * Allow this workaround only in case the AP provided at least
5264 if (min_rate_index
< 0) {
5266 "No legacy rates in association response\n");
5268 sta_info_free(local
, new_sta
);
5270 } else if (!basic_rates
) {
5272 "No basic rates, using min rate instead\n");
5273 basic_rates
= BIT(min_rate_index
);
5277 new_sta
->sta
.supp_rates
[cbss
->channel
->band
] = rates
;
5280 "No rates found, keeping mandatory only\n");
5282 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
5284 /* cf. IEEE 802.11 9.2.12 */
5285 if (cbss
->channel
->band
== NL80211_BAND_2GHZ
&&
5286 have_higher_than_11mbit
)
5287 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
5289 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
5292 memcpy(ifmgd
->bssid
, cbss
->bssid
, ETH_ALEN
);
5294 /* set timing information */
5295 sdata
->vif
.bss_conf
.beacon_int
= cbss
->beacon_interval
;
5297 ies
= rcu_dereference(cbss
->beacon_ies
);
5299 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
5300 sdata
->vif
.bss_conf
.sync_device_ts
=
5301 bss
->device_ts_beacon
;
5303 ieee80211_get_dtim(ies
,
5304 &sdata
->vif
.bss_conf
.sync_dtim_count
,
5306 } else if (!ieee80211_hw_check(&sdata
->local
->hw
,
5307 TIMING_BEACON_ONLY
)) {
5308 ies
= rcu_dereference(cbss
->proberesp_ies
);
5309 /* must be non-NULL since beacon IEs were NULL */
5310 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
5311 sdata
->vif
.bss_conf
.sync_device_ts
=
5312 bss
->device_ts_presp
;
5313 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
5315 sdata
->vif
.bss_conf
.sync_tsf
= 0;
5316 sdata
->vif
.bss_conf
.sync_device_ts
= 0;
5317 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
5322 if (new_sta
|| override
) {
5323 err
= ieee80211_prep_channel(sdata
, cbss
);
5326 sta_info_free(local
, new_sta
);
5333 * tell driver about BSSID, basic rates and timing
5334 * this was set up above, before setting the channel
5336 ieee80211_bss_info_change_notify(sdata
,
5337 BSS_CHANGED_BSSID
| BSS_CHANGED_BASIC_RATES
|
5338 BSS_CHANGED_BEACON_INT
);
5341 sta_info_pre_move_state(new_sta
, IEEE80211_STA_AUTH
);
5343 err
= sta_info_insert(new_sta
);
5347 "failed to insert STA entry for the AP (error %d)\n",
5352 WARN_ON_ONCE(!ether_addr_equal(ifmgd
->bssid
, cbss
->bssid
));
5354 /* Cancel scan to ensure that nothing interferes with connection */
5355 if (local
->scanning
)
5356 ieee80211_scan_cancel(local
);
5362 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
5363 struct cfg80211_auth_request
*req
)
5365 struct ieee80211_local
*local
= sdata
->local
;
5366 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5367 struct ieee80211_mgd_auth_data
*auth_data
;
5372 /* prepare auth data structure */
5374 switch (req
->auth_type
) {
5375 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
5376 auth_alg
= WLAN_AUTH_OPEN
;
5378 case NL80211_AUTHTYPE_SHARED_KEY
:
5381 auth_alg
= WLAN_AUTH_SHARED_KEY
;
5383 case NL80211_AUTHTYPE_FT
:
5384 auth_alg
= WLAN_AUTH_FT
;
5386 case NL80211_AUTHTYPE_NETWORK_EAP
:
5387 auth_alg
= WLAN_AUTH_LEAP
;
5389 case NL80211_AUTHTYPE_SAE
:
5390 auth_alg
= WLAN_AUTH_SAE
;
5392 case NL80211_AUTHTYPE_FILS_SK
:
5393 auth_alg
= WLAN_AUTH_FILS_SK
;
5395 case NL80211_AUTHTYPE_FILS_SK_PFS
:
5396 auth_alg
= WLAN_AUTH_FILS_SK_PFS
;
5398 case NL80211_AUTHTYPE_FILS_PK
:
5399 auth_alg
= WLAN_AUTH_FILS_PK
;
5405 if (ifmgd
->assoc_data
)
5408 auth_data
= kzalloc(sizeof(*auth_data
) + req
->auth_data_len
+
5409 req
->ie_len
, GFP_KERNEL
);
5413 auth_data
->bss
= req
->bss
;
5415 if (req
->auth_data_len
>= 4) {
5416 if (req
->auth_type
== NL80211_AUTHTYPE_SAE
) {
5417 __le16
*pos
= (__le16
*) req
->auth_data
;
5419 auth_data
->sae_trans
= le16_to_cpu(pos
[0]);
5420 auth_data
->sae_status
= le16_to_cpu(pos
[1]);
5422 memcpy(auth_data
->data
, req
->auth_data
+ 4,
5423 req
->auth_data_len
- 4);
5424 auth_data
->data_len
+= req
->auth_data_len
- 4;
5427 /* Check if continuing authentication or trying to authenticate with the
5428 * same BSS that we were in the process of authenticating with and avoid
5429 * removal and re-addition of the STA entry in
5430 * ieee80211_prep_connection().
5432 cont_auth
= ifmgd
->auth_data
&& req
->bss
== ifmgd
->auth_data
->bss
;
5434 if (req
->ie
&& req
->ie_len
) {
5435 memcpy(&auth_data
->data
[auth_data
->data_len
],
5436 req
->ie
, req
->ie_len
);
5437 auth_data
->data_len
+= req
->ie_len
;
5440 if (req
->key
&& req
->key_len
) {
5441 auth_data
->key_len
= req
->key_len
;
5442 auth_data
->key_idx
= req
->key_idx
;
5443 memcpy(auth_data
->key
, req
->key
, req
->key_len
);
5446 auth_data
->algorithm
= auth_alg
;
5448 /* try to authenticate/probe */
5450 if (ifmgd
->auth_data
) {
5451 if (cont_auth
&& req
->auth_type
== NL80211_AUTHTYPE_SAE
) {
5452 auth_data
->peer_confirmed
=
5453 ifmgd
->auth_data
->peer_confirmed
;
5455 ieee80211_destroy_auth_data(sdata
, cont_auth
);
5458 /* prep auth_data so we don't go into idle on disassoc */
5459 ifmgd
->auth_data
= auth_data
;
5461 /* If this is continuation of an ongoing SAE authentication exchange
5462 * (i.e., request to send SAE Confirm) and the peer has already
5463 * confirmed, mark authentication completed since we are about to send
5466 if (cont_auth
&& req
->auth_type
== NL80211_AUTHTYPE_SAE
&&
5467 auth_data
->peer_confirmed
&& auth_data
->sae_trans
== 2)
5468 ieee80211_mark_sta_auth(sdata
, req
->bss
->bssid
);
5470 if (ifmgd
->associated
) {
5471 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5474 "disconnect from AP %pM for new auth to %pM\n",
5475 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
5476 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5477 WLAN_REASON_UNSPECIFIED
,
5480 ieee80211_report_disconnect(sdata
, frame_buf
,
5481 sizeof(frame_buf
), true,
5482 WLAN_REASON_UNSPECIFIED
,
5486 sdata_info(sdata
, "authenticate with %pM\n", req
->bss
->bssid
);
5488 err
= ieee80211_prep_connection(sdata
, req
->bss
, cont_auth
, false);
5492 err
= ieee80211_auth(sdata
);
5494 sta_info_destroy_addr(sdata
, req
->bss
->bssid
);
5498 /* hold our own reference */
5499 cfg80211_ref_bss(local
->hw
.wiphy
, auth_data
->bss
);
5503 eth_zero_addr(ifmgd
->bssid
);
5504 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
5505 ifmgd
->auth_data
= NULL
;
5506 mutex_lock(&sdata
->local
->mtx
);
5507 ieee80211_vif_release_channel(sdata
);
5508 mutex_unlock(&sdata
->local
->mtx
);
5513 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
5514 struct cfg80211_assoc_request
*req
)
5516 bool is_6ghz
= req
->bss
->channel
->band
== NL80211_BAND_6GHZ
;
5517 bool is_5ghz
= req
->bss
->channel
->band
== NL80211_BAND_5GHZ
;
5518 struct ieee80211_local
*local
= sdata
->local
;
5519 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5520 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
5521 struct ieee80211_mgd_assoc_data
*assoc_data
;
5522 const struct cfg80211_bss_ies
*beacon_ies
;
5523 struct ieee80211_supported_band
*sband
;
5524 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
5525 const u8
*ssidie
, *ht_ie
, *vht_ie
;
5527 bool override
= false;
5529 assoc_data
= kzalloc(sizeof(*assoc_data
) + req
->ie_len
, GFP_KERNEL
);
5534 ssidie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
5535 if (!ssidie
|| ssidie
[1] > sizeof(assoc_data
->ssid
)) {
5540 memcpy(assoc_data
->ssid
, ssidie
+ 2, ssidie
[1]);
5541 assoc_data
->ssid_len
= ssidie
[1];
5542 memcpy(bss_conf
->ssid
, assoc_data
->ssid
, assoc_data
->ssid_len
);
5543 bss_conf
->ssid_len
= assoc_data
->ssid_len
;
5546 if (ifmgd
->associated
) {
5547 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5550 "disconnect from AP %pM for new assoc to %pM\n",
5551 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
5552 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5553 WLAN_REASON_UNSPECIFIED
,
5556 ieee80211_report_disconnect(sdata
, frame_buf
,
5557 sizeof(frame_buf
), true,
5558 WLAN_REASON_UNSPECIFIED
,
5562 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) {
5567 if (ifmgd
->assoc_data
) {
5572 if (ifmgd
->auth_data
) {
5575 /* keep sta info, bssid if matching */
5576 match
= ether_addr_equal(ifmgd
->bssid
, req
->bss
->bssid
);
5577 ieee80211_destroy_auth_data(sdata
, match
);
5580 /* prepare assoc data */
5582 ifmgd
->beacon_crc_valid
= false;
5584 assoc_data
->wmm
= bss
->wmm_used
&&
5585 (local
->hw
.queues
>= IEEE80211_NUM_ACS
);
5588 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5589 * We still associate in non-HT mode (11a/b/g) if any one of these
5590 * ciphers is configured as pairwise.
5591 * We can set this to true for non-11n hardware, that'll be checked
5592 * separately along with the peer capabilities.
5594 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++) {
5595 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
5596 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
5597 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
) {
5598 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5599 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5600 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5601 netdev_info(sdata
->dev
,
5602 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5606 sband
= local
->hw
.wiphy
->bands
[req
->bss
->channel
->band
];
5608 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5609 if (!bss
->wmm_used
) {
5610 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5611 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5612 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5613 netdev_info(sdata
->dev
,
5614 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5617 memcpy(&ifmgd
->ht_capa
, &req
->ht_capa
, sizeof(ifmgd
->ht_capa
));
5618 memcpy(&ifmgd
->ht_capa_mask
, &req
->ht_capa_mask
,
5619 sizeof(ifmgd
->ht_capa_mask
));
5621 memcpy(&ifmgd
->vht_capa
, &req
->vht_capa
, sizeof(ifmgd
->vht_capa
));
5622 memcpy(&ifmgd
->vht_capa_mask
, &req
->vht_capa_mask
,
5623 sizeof(ifmgd
->vht_capa_mask
));
5625 memcpy(&ifmgd
->s1g_capa
, &req
->s1g_capa
, sizeof(ifmgd
->s1g_capa
));
5626 memcpy(&ifmgd
->s1g_capa_mask
, &req
->s1g_capa_mask
,
5627 sizeof(ifmgd
->s1g_capa_mask
));
5629 if (req
->ie
&& req
->ie_len
) {
5630 memcpy(assoc_data
->ie
, req
->ie
, req
->ie_len
);
5631 assoc_data
->ie_len
= req
->ie_len
;
5634 if (req
->fils_kek
) {
5635 /* should already be checked in cfg80211 - so warn */
5636 if (WARN_ON(req
->fils_kek_len
> FILS_MAX_KEK_LEN
)) {
5640 memcpy(assoc_data
->fils_kek
, req
->fils_kek
,
5642 assoc_data
->fils_kek_len
= req
->fils_kek_len
;
5645 if (req
->fils_nonces
)
5646 memcpy(assoc_data
->fils_nonces
, req
->fils_nonces
,
5647 2 * FILS_NONCE_LEN
);
5649 assoc_data
->bss
= req
->bss
;
5650 assoc_data
->capability
= req
->bss
->capability
;
5651 assoc_data
->supp_rates
= bss
->supp_rates
;
5652 assoc_data
->supp_rates_len
= bss
->supp_rates_len
;
5655 ht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_OPERATION
);
5656 if (ht_ie
&& ht_ie
[1] >= sizeof(struct ieee80211_ht_operation
))
5657 assoc_data
->ap_ht_param
=
5658 ((struct ieee80211_ht_operation
*)(ht_ie
+ 2))->ht_param
;
5660 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5661 vht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_VHT_CAPABILITY
);
5662 if (vht_ie
&& vht_ie
[1] >= sizeof(struct ieee80211_vht_cap
))
5663 memcpy(&assoc_data
->ap_vht_cap
, vht_ie
+ 2,
5664 sizeof(struct ieee80211_vht_cap
));
5666 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
|
5667 IEEE80211_STA_DISABLE_HE
;
5670 if (WARN((sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
) &&
5671 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
),
5672 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5673 sdata
->vif
.driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
5675 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
5676 (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
)) {
5677 assoc_data
->uapsd
= true;
5678 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
5680 assoc_data
->uapsd
= false;
5681 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
5684 if (req
->prev_bssid
)
5685 memcpy(assoc_data
->prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
5688 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
5689 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
5691 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
5692 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
5695 if (req
->flags
& ASSOC_REQ_USE_RRM
)
5696 ifmgd
->flags
|= IEEE80211_STA_ENABLE_RRM
;
5698 ifmgd
->flags
&= ~IEEE80211_STA_ENABLE_RRM
;
5700 if (req
->crypto
.control_port
)
5701 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
5703 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
5705 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
5706 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
5707 sdata
->control_port_over_nl80211
=
5708 req
->crypto
.control_port_over_nl80211
;
5709 sdata
->control_port_no_preauth
= req
->crypto
.control_port_no_preauth
;
5710 sdata
->encrypt_headroom
= ieee80211_cs_headroom(local
, &req
->crypto
,
5713 /* kick off associate process */
5715 ifmgd
->assoc_data
= assoc_data
;
5716 ifmgd
->dtim_period
= 0;
5717 ifmgd
->have_beacon
= false;
5719 /* override HT/VHT configuration only if the AP and we support it */
5720 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
5721 struct ieee80211_sta_ht_cap sta_ht_cap
;
5723 if (req
->flags
& ASSOC_REQ_DISABLE_HT
)
5726 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
5727 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
5729 /* check for 40 MHz disable override */
5730 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
) &&
5731 sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
&&
5732 !(sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
5735 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
5736 req
->flags
& ASSOC_REQ_DISABLE_VHT
)
5740 if (req
->flags
& ASSOC_REQ_DISABLE_HT
) {
5741 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5742 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5743 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5746 if (req
->flags
& ASSOC_REQ_DISABLE_VHT
)
5747 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5749 if (req
->flags
& ASSOC_REQ_DISABLE_HE
)
5750 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5752 err
= ieee80211_prep_connection(sdata
, req
->bss
, true, override
);
5756 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
5757 if (ifmgd
->powersave
)
5758 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
5760 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
5762 sdata
->smps_mode
= ifmgd
->req_smps
;
5766 beacon_ies
= rcu_dereference(req
->bss
->beacon_ies
);
5768 if (ieee80211_hw_check(&sdata
->local
->hw
, NEED_DTIM_BEFORE_ASSOC
) &&
5771 * Wait up to one beacon interval ...
5772 * should this be more if we miss one?
5774 sdata_info(sdata
, "waiting for beacon from %pM\n",
5776 assoc_data
->timeout
= TU_TO_EXP_TIME(req
->bss
->beacon_interval
);
5777 assoc_data
->timeout_started
= true;
5778 assoc_data
->need_beacon
= true;
5779 } else if (beacon_ies
) {
5780 const struct element
*elem
;
5783 ieee80211_get_dtim(beacon_ies
, &dtim_count
,
5784 &ifmgd
->dtim_period
);
5786 ifmgd
->have_beacon
= true;
5787 assoc_data
->timeout
= jiffies
;
5788 assoc_data
->timeout_started
= true;
5790 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
5791 sdata
->vif
.bss_conf
.sync_tsf
= beacon_ies
->tsf
;
5792 sdata
->vif
.bss_conf
.sync_device_ts
=
5793 bss
->device_ts_beacon
;
5794 sdata
->vif
.bss_conf
.sync_dtim_count
= dtim_count
;
5797 elem
= cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION
,
5798 beacon_ies
->data
, beacon_ies
->len
);
5799 if (elem
&& elem
->datalen
>= 3)
5800 sdata
->vif
.bss_conf
.profile_periodicity
= elem
->data
[2];
5802 sdata
->vif
.bss_conf
.profile_periodicity
= 0;
5804 elem
= cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY
,
5805 beacon_ies
->data
, beacon_ies
->len
);
5806 if (elem
&& elem
->datalen
>= 11 &&
5807 (elem
->data
[10] & WLAN_EXT_CAPA11_EMA_SUPPORT
))
5808 sdata
->vif
.bss_conf
.ema_ap
= true;
5810 sdata
->vif
.bss_conf
.ema_ap
= false;
5812 assoc_data
->timeout
= jiffies
;
5813 assoc_data
->timeout_started
= true;
5817 run_again(sdata
, assoc_data
->timeout
);
5819 if (bss
->corrupt_data
) {
5820 char *corrupt_type
= "data";
5821 if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_BEACON
) {
5822 if (bss
->corrupt_data
&
5823 IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5824 corrupt_type
= "beacon and probe response";
5826 corrupt_type
= "beacon";
5827 } else if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5828 corrupt_type
= "probe response";
5829 sdata_info(sdata
, "associating with AP with corrupt %s\n",
5835 eth_zero_addr(ifmgd
->bssid
);
5836 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
5837 ifmgd
->assoc_data
= NULL
;
5843 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
5844 struct cfg80211_deauth_request
*req
)
5846 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5847 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5848 bool tx
= !req
->local_state_change
;
5849 struct ieee80211_prep_tx_info info
= {
5850 .subtype
= IEEE80211_STYPE_DEAUTH
,
5853 if (ifmgd
->auth_data
&&
5854 ether_addr_equal(ifmgd
->auth_data
->bss
->bssid
, req
->bssid
)) {
5856 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5857 req
->bssid
, req
->reason_code
,
5858 ieee80211_get_reason_code_string(req
->reason_code
));
5860 drv_mgd_prepare_tx(sdata
->local
, sdata
, &info
);
5861 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
, req
->bssid
,
5862 IEEE80211_STYPE_DEAUTH
,
5863 req
->reason_code
, tx
,
5865 ieee80211_destroy_auth_data(sdata
, false);
5866 ieee80211_report_disconnect(sdata
, frame_buf
,
5867 sizeof(frame_buf
), true,
5868 req
->reason_code
, false);
5869 drv_mgd_complete_tx(sdata
->local
, sdata
, &info
);
5873 if (ifmgd
->assoc_data
&&
5874 ether_addr_equal(ifmgd
->assoc_data
->bss
->bssid
, req
->bssid
)) {
5876 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5877 req
->bssid
, req
->reason_code
,
5878 ieee80211_get_reason_code_string(req
->reason_code
));
5880 drv_mgd_prepare_tx(sdata
->local
, sdata
, &info
);
5881 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
, req
->bssid
,
5882 IEEE80211_STYPE_DEAUTH
,
5883 req
->reason_code
, tx
,
5885 ieee80211_destroy_assoc_data(sdata
, false, true);
5886 ieee80211_report_disconnect(sdata
, frame_buf
,
5887 sizeof(frame_buf
), true,
5888 req
->reason_code
, false);
5892 if (ifmgd
->associated
&&
5893 ether_addr_equal(ifmgd
->associated
->bssid
, req
->bssid
)) {
5895 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5896 req
->bssid
, req
->reason_code
,
5897 ieee80211_get_reason_code_string(req
->reason_code
));
5899 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5900 req
->reason_code
, tx
, frame_buf
);
5901 ieee80211_report_disconnect(sdata
, frame_buf
,
5902 sizeof(frame_buf
), true,
5903 req
->reason_code
, false);
5904 drv_mgd_complete_tx(sdata
->local
, sdata
, &info
);
5911 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
5912 struct cfg80211_disassoc_request
*req
)
5914 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5916 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5919 * cfg80211 should catch this ... but it's racy since
5920 * we can receive a disassoc frame, process it, hand it
5921 * to cfg80211 while that's in a locked section already
5922 * trying to tell us that the user wants to disconnect.
5924 if (ifmgd
->associated
!= req
->bss
)
5928 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5929 req
->bss
->bssid
, req
->reason_code
, ieee80211_get_reason_code_string(req
->reason_code
));
5931 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
5932 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DISASSOC
,
5933 req
->reason_code
, !req
->local_state_change
,
5936 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
5937 req
->reason_code
, false);
5942 void ieee80211_mgd_stop(struct ieee80211_sub_if_data
*sdata
)
5944 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5947 * Make sure some work items will not run after this,
5948 * they will not do anything but might not have been
5949 * cancelled when disconnecting.
5951 cancel_work_sync(&ifmgd
->monitor_work
);
5952 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
5953 cancel_work_sync(&ifmgd
->request_smps_work
);
5954 cancel_work_sync(&ifmgd
->csa_connection_drop_work
);
5955 cancel_work_sync(&ifmgd
->chswitch_work
);
5956 cancel_delayed_work_sync(&ifmgd
->tdls_peer_del_work
);
5959 if (ifmgd
->assoc_data
) {
5960 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
5961 ieee80211_destroy_assoc_data(sdata
, false, false);
5962 cfg80211_assoc_timeout(sdata
->dev
, bss
);
5964 if (ifmgd
->auth_data
)
5965 ieee80211_destroy_auth_data(sdata
, false);
5966 spin_lock_bh(&ifmgd
->teardown_lock
);
5967 if (ifmgd
->teardown_skb
) {
5968 kfree_skb(ifmgd
->teardown_skb
);
5969 ifmgd
->teardown_skb
= NULL
;
5970 ifmgd
->orig_teardown_skb
= NULL
;
5972 kfree(ifmgd
->assoc_req_ies
);
5973 ifmgd
->assoc_req_ies
= NULL
;
5974 ifmgd
->assoc_req_ies_len
= 0;
5975 spin_unlock_bh(&ifmgd
->teardown_lock
);
5976 del_timer_sync(&ifmgd
->timer
);
5977 sdata_unlock(sdata
);
5980 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
5981 enum nl80211_cqm_rssi_threshold_event rssi_event
,
5985 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5987 trace_api_cqm_rssi_notify(sdata
, rssi_event
, rssi_level
);
5989 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, rssi_level
, gfp
);
5991 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);
5993 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif
*vif
, gfp_t gfp
)
5995 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5997 trace_api_cqm_beacon_loss_notify(sdata
->local
, sdata
);
5999 cfg80211_cqm_beacon_loss_notify(sdata
->dev
, gfp
);
6001 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify
);