2 * BSS client mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
4 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 * Copyright 2013-2014 Intel Mobile Communications GmbH
9 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
10 * Copyright (C) 2018 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/delay.h>
18 #include <linux/if_ether.h>
19 #include <linux/skbuff.h>
20 #include <linux/if_arp.h>
21 #include <linux/etherdevice.h>
22 #include <linux/moduleparam.h>
23 #include <linux/rtnetlink.h>
24 #include <linux/crc32.h>
25 #include <linux/slab.h>
26 #include <linux/export.h>
27 #include <net/mac80211.h>
28 #include <asm/unaligned.h>
30 #include "ieee80211_i.h"
31 #include "driver-ops.h"
34 #include "fils_aead.h"
36 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
37 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
38 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
39 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
40 #define IEEE80211_AUTH_MAX_TRIES 3
41 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
42 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
43 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
44 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
45 #define IEEE80211_ASSOC_MAX_TRIES 3
47 static int max_nullfunc_tries
= 2;
48 module_param(max_nullfunc_tries
, int, 0644);
49 MODULE_PARM_DESC(max_nullfunc_tries
,
50 "Maximum nullfunc tx tries before disconnecting (reason 4).");
52 static int max_probe_tries
= 5;
53 module_param(max_probe_tries
, int, 0644);
54 MODULE_PARM_DESC(max_probe_tries
,
55 "Maximum probe tries before disconnecting (reason 4).");
58 * Beacon loss timeout is calculated as N frames times the
59 * advertised beacon interval. This may need to be somewhat
60 * higher than what hardware might detect to account for
61 * delays in the host processing frames. But since we also
62 * probe on beacon miss before declaring the connection lost
63 * default to what we want.
65 static int beacon_loss_count
= 7;
66 module_param(beacon_loss_count
, int, 0644);
67 MODULE_PARM_DESC(beacon_loss_count
,
68 "Number of beacon intervals before we decide beacon was lost.");
71 * Time the connection can be idle before we probe
72 * it to see if we can still talk to the AP.
74 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
76 * Time we wait for a probe response after sending
77 * a probe request because of beacon loss or for
78 * checking the connection still works.
80 static int probe_wait_ms
= 500;
81 module_param(probe_wait_ms
, int, 0644);
82 MODULE_PARM_DESC(probe_wait_ms
,
83 "Maximum time(ms) to wait for probe response"
84 " before disconnecting (reason 4).");
87 * How many Beacon frames need to have been used in average signal strength
88 * before starting to indicate signal change events.
90 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
93 * We can have multiple work items (and connection probing)
94 * scheduling this timer, but we need to take care to only
95 * reschedule it when it should fire _earlier_ than it was
96 * asked for before, or if it's not pending right now. This
97 * function ensures that. Note that it then is required to
98 * run this function for all timeouts after the first one
99 * has happened -- the work that runs from this timer will
102 static void run_again(struct ieee80211_sub_if_data
*sdata
,
103 unsigned long timeout
)
105 sdata_assert_lock(sdata
);
107 if (!timer_pending(&sdata
->u
.mgd
.timer
) ||
108 time_before(timeout
, sdata
->u
.mgd
.timer
.expires
))
109 mod_timer(&sdata
->u
.mgd
.timer
, timeout
);
112 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
114 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
117 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
120 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
121 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
124 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
126 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
128 if (unlikely(!ifmgd
->associated
))
131 if (ifmgd
->probe_send_count
)
132 ifmgd
->probe_send_count
= 0;
134 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
137 mod_timer(&ifmgd
->conn_mon_timer
,
138 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
141 static int ecw2cw(int ecw
)
143 return (1 << ecw
) - 1;
147 ieee80211_determine_chantype(struct ieee80211_sub_if_data
*sdata
,
148 struct ieee80211_supported_band
*sband
,
149 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 struct cfg80211_chan_def
*chandef
, bool tracking
)
155 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
156 struct cfg80211_chan_def vht_chandef
;
157 struct ieee80211_sta_ht_cap sta_ht_cap
;
160 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
161 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
163 chandef
->chan
= channel
;
164 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
165 chandef
->center_freq1
= channel
->center_freq
;
166 chandef
->center_freq2
= 0;
168 if (!ht_oper
|| !sta_ht_cap
.ht_supported
) {
169 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
173 chandef
->width
= NL80211_CHAN_WIDTH_20
;
175 ht_cfreq
= ieee80211_channel_to_frequency(ht_oper
->primary_chan
,
177 /* check that channel matches the right operating channel */
178 if (!tracking
&& channel
->center_freq
!= ht_cfreq
) {
180 * It's possible that some APs are confused here;
181 * Netgear WNDR3700 sometimes reports 4 higher than
182 * the actual channel in association responses, but
183 * since we look at probe response/beacon data here
187 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
188 channel
->center_freq
, ht_cfreq
,
189 ht_oper
->primary_chan
, channel
->band
);
190 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
194 /* check 40 MHz support, if we have it */
195 if (sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) {
196 ieee80211_chandef_ht_oper(ht_oper
, chandef
);
198 /* 40 MHz (and 80 MHz) must be supported for VHT */
199 ret
= IEEE80211_STA_DISABLE_VHT
;
200 /* also mark 40 MHz disabled */
201 ret
|= IEEE80211_STA_DISABLE_40MHZ
;
205 if (!vht_oper
|| !sband
->vht_cap
.vht_supported
) {
206 ret
= IEEE80211_STA_DISABLE_VHT
;
210 vht_chandef
= *chandef
;
211 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) && he_oper
&&
212 (le32_to_cpu(he_oper
->he_oper_params
) &
213 IEEE80211_HE_OPERATION_VHT_OPER_INFO
)) {
214 struct ieee80211_vht_operation he_oper_vht_cap
;
217 * Set only first 3 bytes (other 2 aren't used in
218 * ieee80211_chandef_vht_oper() anyway)
220 memcpy(&he_oper_vht_cap
, he_oper
->optional
, 3);
221 he_oper_vht_cap
.basic_mcs_set
= cpu_to_le16(0);
223 if (!ieee80211_chandef_vht_oper(&he_oper_vht_cap
,
225 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
))
227 "HE AP VHT information is invalid, disable HE\n");
228 ret
= IEEE80211_STA_DISABLE_HE
;
231 } else if (!ieee80211_chandef_vht_oper(vht_oper
, &vht_chandef
)) {
232 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
234 "AP VHT information is invalid, disable VHT\n");
235 ret
= IEEE80211_STA_DISABLE_VHT
;
239 if (!cfg80211_chandef_valid(&vht_chandef
)) {
240 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
242 "AP VHT information is invalid, disable VHT\n");
243 ret
= IEEE80211_STA_DISABLE_VHT
;
247 if (cfg80211_chandef_identical(chandef
, &vht_chandef
)) {
252 if (!cfg80211_chandef_compatible(chandef
, &vht_chandef
)) {
253 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
255 "AP VHT information doesn't match HT, disable VHT\n");
256 ret
= IEEE80211_STA_DISABLE_VHT
;
260 *chandef
= vht_chandef
;
266 * When tracking the current AP, don't do any further checks if the
267 * new chandef is identical to the one we're currently using for the
268 * connection. This keeps us from playing ping-pong with regulatory,
269 * without it the following can happen (for example):
270 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
271 * - AP advertises regdom US
272 * - CRDA loads regdom US with 80 MHz prohibited (old database)
273 * - the code below detects an unsupported channel, downgrades, and
274 * we disconnect from the AP in the caller
275 * - disconnect causes CRDA to reload world regdomain and the game
277 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
279 * It seems possible that there are still scenarios with CSA or real
280 * bandwidth changes where a this could happen, but those cases are
281 * less common and wouldn't completely prevent using the AP.
284 cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
))
287 /* don't print the message below for VHT mismatch if VHT is disabled */
288 if (ret
& IEEE80211_STA_DISABLE_VHT
)
289 vht_chandef
= *chandef
;
292 * Ignore the DISABLED flag when we're already connected and only
293 * tracking the APs beacon for bandwidth changes - otherwise we
294 * might get disconnected here if we connect to an AP, update our
295 * regulatory information based on the AP's country IE and the
296 * information we have is wrong/outdated and disables the channel
297 * that we're actually using for the connection to the AP.
299 while (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
301 IEEE80211_CHAN_DISABLED
)) {
302 if (WARN_ON(chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
)) {
303 ret
= IEEE80211_STA_DISABLE_HT
|
304 IEEE80211_STA_DISABLE_VHT
;
308 ret
|= ieee80211_chandef_downgrade(chandef
);
311 if (chandef
->width
!= vht_chandef
.width
&& !tracking
)
313 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
315 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef
));
319 static int ieee80211_config_bw(struct ieee80211_sub_if_data
*sdata
,
320 struct sta_info
*sta
,
321 const struct ieee80211_ht_cap
*ht_cap
,
322 const struct ieee80211_ht_operation
*ht_oper
,
323 const struct ieee80211_vht_operation
*vht_oper
,
324 const struct ieee80211_he_operation
*he_oper
,
325 const u8
*bssid
, u32
*changed
)
327 struct ieee80211_local
*local
= sdata
->local
;
328 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
329 struct ieee80211_channel
*chan
= sdata
->vif
.bss_conf
.chandef
.chan
;
330 struct ieee80211_supported_band
*sband
=
331 local
->hw
.wiphy
->bands
[chan
->band
];
332 struct cfg80211_chan_def chandef
;
335 enum ieee80211_sta_rx_bandwidth new_sta_bw
;
338 /* if HT was/is disabled, don't track any bandwidth changes */
339 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
|| !ht_oper
)
342 /* don't check VHT if we associated as non-VHT station */
343 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
346 /* don't check HE if we associated as non-HE station */
347 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
||
348 !ieee80211_get_he_sta_cap(sband
))
351 if (WARN_ON_ONCE(!sta
))
355 * if bss configuration changed store the new one -
356 * this may be applicable even if channel is identical
358 ht_opmode
= le16_to_cpu(ht_oper
->operation_mode
);
359 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
360 *changed
|= BSS_CHANGED_HT
;
361 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
364 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
365 flags
= ieee80211_determine_chantype(sdata
, sband
, chan
,
366 ht_oper
, vht_oper
, he_oper
,
370 * Downgrade the new channel if we associated with restricted
371 * capabilities. For example, if we associated as a 20 MHz STA
372 * to a 40 MHz AP (due to regulatory, capabilities or config
373 * reasons) then switching to a 40 MHz channel now won't do us
374 * any good -- we couldn't use it with the AP.
376 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_80P80MHZ
&&
377 chandef
.width
== NL80211_CHAN_WIDTH_80P80
)
378 flags
|= ieee80211_chandef_downgrade(&chandef
);
379 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_160MHZ
&&
380 chandef
.width
== NL80211_CHAN_WIDTH_160
)
381 flags
|= ieee80211_chandef_downgrade(&chandef
);
382 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
&&
383 chandef
.width
> NL80211_CHAN_WIDTH_20
)
384 flags
|= ieee80211_chandef_downgrade(&chandef
);
386 if (cfg80211_chandef_identical(&chandef
, &sdata
->vif
.bss_conf
.chandef
))
390 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
391 ifmgd
->bssid
, chandef
.chan
->center_freq
, chandef
.width
,
392 chandef
.center_freq1
, chandef
.center_freq2
);
394 if (flags
!= (ifmgd
->flags
& (IEEE80211_STA_DISABLE_HT
|
395 IEEE80211_STA_DISABLE_VHT
|
396 IEEE80211_STA_DISABLE_40MHZ
|
397 IEEE80211_STA_DISABLE_80P80MHZ
|
398 IEEE80211_STA_DISABLE_160MHZ
)) ||
399 !cfg80211_chandef_valid(&chandef
)) {
401 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
406 switch (chandef
.width
) {
407 case NL80211_CHAN_WIDTH_20_NOHT
:
408 case NL80211_CHAN_WIDTH_20
:
409 new_sta_bw
= IEEE80211_STA_RX_BW_20
;
411 case NL80211_CHAN_WIDTH_40
:
412 new_sta_bw
= IEEE80211_STA_RX_BW_40
;
414 case NL80211_CHAN_WIDTH_80
:
415 new_sta_bw
= IEEE80211_STA_RX_BW_80
;
417 case NL80211_CHAN_WIDTH_80P80
:
418 case NL80211_CHAN_WIDTH_160
:
419 new_sta_bw
= IEEE80211_STA_RX_BW_160
;
425 if (new_sta_bw
> sta
->cur_max_bandwidth
)
426 new_sta_bw
= sta
->cur_max_bandwidth
;
428 if (new_sta_bw
< sta
->sta
.bandwidth
) {
429 sta
->sta
.bandwidth
= new_sta_bw
;
430 rate_control_rate_update(local
, sband
, sta
,
431 IEEE80211_RC_BW_CHANGED
);
434 ret
= ieee80211_vif_change_bandwidth(sdata
, &chandef
, changed
);
437 "AP %pM changed bandwidth to incompatible one - disconnect\n",
442 if (new_sta_bw
> sta
->sta
.bandwidth
) {
443 sta
->sta
.bandwidth
= new_sta_bw
;
444 rate_control_rate_update(local
, sband
, sta
,
445 IEEE80211_RC_BW_CHANGED
);
451 /* frame sending functions */
453 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data
*sdata
,
454 struct sk_buff
*skb
, u8 ap_ht_param
,
455 struct ieee80211_supported_band
*sband
,
456 struct ieee80211_channel
*channel
,
457 enum ieee80211_smps_mode smps
)
460 u32 flags
= channel
->flags
;
462 struct ieee80211_sta_ht_cap ht_cap
;
464 BUILD_BUG_ON(sizeof(ht_cap
) != sizeof(sband
->ht_cap
));
466 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
467 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
469 /* determine capability flags */
472 switch (ap_ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
473 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
474 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
475 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
476 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
479 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
480 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
481 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
482 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
488 * If 40 MHz was disabled associate as though we weren't
489 * capable of 40 MHz -- some broken APs will never fall
490 * back to trying to transmit in 20 MHz.
492 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_40MHZ
) {
493 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
494 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
497 /* set SM PS mode properly */
498 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
500 case IEEE80211_SMPS_AUTOMATIC
:
501 case IEEE80211_SMPS_NUM_MODES
:
504 case IEEE80211_SMPS_OFF
:
505 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
506 IEEE80211_HT_CAP_SM_PS_SHIFT
;
508 case IEEE80211_SMPS_STATIC
:
509 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
510 IEEE80211_HT_CAP_SM_PS_SHIFT
;
512 case IEEE80211_SMPS_DYNAMIC
:
513 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
514 IEEE80211_HT_CAP_SM_PS_SHIFT
;
518 /* reserve and fill IE */
519 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
520 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, cap
);
523 /* This function determines vht capability flags for the association
525 * Note - the function may set the owner of the MU-MIMO capability
527 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data
*sdata
,
529 struct ieee80211_supported_band
*sband
,
530 struct ieee80211_vht_cap
*ap_vht_cap
)
532 struct ieee80211_local
*local
= sdata
->local
;
535 struct ieee80211_sta_vht_cap vht_cap
;
536 u32 mask
, ap_bf_sts
, our_bf_sts
;
538 BUILD_BUG_ON(sizeof(vht_cap
) != sizeof(sband
->vht_cap
));
540 memcpy(&vht_cap
, &sband
->vht_cap
, sizeof(vht_cap
));
541 ieee80211_apply_vhtcap_overrides(sdata
, &vht_cap
);
543 /* determine capability flags */
546 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_80P80MHZ
) {
547 u32 bw
= cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
549 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
550 if (bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
||
551 bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
552 cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
555 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_160MHZ
) {
556 cap
&= ~IEEE80211_VHT_CAP_SHORT_GI_160
;
557 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
561 * Some APs apparently get confused if our capabilities are better
562 * than theirs, so restrict what we advertise in the assoc request.
564 if (!(ap_vht_cap
->vht_cap_info
&
565 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)))
566 cap
&= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
567 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
);
568 else if (!(ap_vht_cap
->vht_cap_info
&
569 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
570 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
573 * If some other vif is using the MU-MIMO capablity we cannot associate
574 * using MU-MIMO - this will lead to contradictions in the group-id
576 * Ownership is defined since association request, in order to avoid
577 * simultaneous associations with MU-MIMO.
579 if (cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
) {
580 bool disable_mu_mimo
= false;
581 struct ieee80211_sub_if_data
*other
;
583 list_for_each_entry_rcu(other
, &local
->interfaces
, list
) {
584 if (other
->vif
.mu_mimo_owner
) {
585 disable_mu_mimo
= true;
590 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
592 sdata
->vif
.mu_mimo_owner
= true;
595 mask
= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
597 ap_bf_sts
= le32_to_cpu(ap_vht_cap
->vht_cap_info
) & mask
;
598 our_bf_sts
= cap
& mask
;
600 if (ap_bf_sts
< our_bf_sts
) {
605 /* reserve and fill IE */
606 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
607 ieee80211_ie_build_vht_cap(pos
, &vht_cap
, cap
);
610 /* This function determines HE capability flags for the association
613 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data
*sdata
,
615 struct ieee80211_supported_band
*sband
)
618 const struct ieee80211_sta_he_cap
*he_cap
= NULL
;
621 he_cap
= ieee80211_get_he_sta_cap(sband
);
626 * TODO: the 1 added is because this temporarily is under the EXTENSION
627 * IE. Get rid of it when it moves.
630 2 + 1 + sizeof(he_cap
->he_cap_elem
) +
631 ieee80211_he_mcs_nss_size(&he_cap
->he_cap_elem
) +
632 ieee80211_he_ppe_size(he_cap
->ppe_thres
[0],
633 he_cap
->he_cap_elem
.phy_cap_info
);
634 pos
= skb_put(skb
, he_cap_size
);
635 ieee80211_ie_build_he_cap(pos
, he_cap
, pos
+ he_cap_size
);
638 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
)
640 struct ieee80211_local
*local
= sdata
->local
;
641 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
642 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
644 struct ieee80211_mgmt
*mgmt
;
646 size_t offset
= 0, noffset
;
647 int i
, count
, rates_len
, supp_rates_len
, shift
;
649 struct ieee80211_supported_band
*sband
;
650 struct ieee80211_chanctx_conf
*chanctx_conf
;
651 struct ieee80211_channel
*chan
;
654 sdata_assert_lock(sdata
);
657 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
658 if (WARN_ON(!chanctx_conf
)) {
662 chan
= chanctx_conf
->def
.chan
;
664 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
665 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
667 if (assoc_data
->supp_rates_len
) {
669 * Get all rates supported by the device and the AP as
670 * some APs don't like getting a superset of their rates
671 * in the association request (e.g. D-Link DAP 1353 in
674 rates_len
= ieee80211_parse_bitrates(&chanctx_conf
->def
, sband
,
675 assoc_data
->supp_rates
,
676 assoc_data
->supp_rates_len
,
680 * In case AP not provide any supported rates information
681 * before association, we send information element(s) with
682 * all rates that we support.
685 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
691 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
692 sizeof(*mgmt
) + /* bit too much but doesn't matter */
693 2 + assoc_data
->ssid_len
+ /* SSID */
694 4 + rates_len
+ /* (extended) rates */
695 4 + /* power capability */
696 2 + 2 * sband
->n_channels
+ /* supported channels */
697 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
698 2 + sizeof(struct ieee80211_vht_cap
) + /* VHT */
699 2 + 1 + sizeof(struct ieee80211_he_cap_elem
) + /* HE */
700 sizeof(struct ieee80211_he_mcs_nss_supp
) +
701 IEEE80211_HE_PPE_THRES_MAX_LEN
+
702 assoc_data
->ie_len
+ /* extra IEs */
703 (assoc_data
->fils_kek_len
? 16 /* AES-SIV */ : 0) +
709 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
711 capab
= WLAN_CAPABILITY_ESS
;
713 if (sband
->band
== NL80211_BAND_2GHZ
) {
714 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
715 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
718 if (assoc_data
->capability
& WLAN_CAPABILITY_PRIVACY
)
719 capab
|= WLAN_CAPABILITY_PRIVACY
;
721 if ((assoc_data
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
722 ieee80211_hw_check(&local
->hw
, SPECTRUM_MGMT
))
723 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
725 if (ifmgd
->flags
& IEEE80211_STA_ENABLE_RRM
)
726 capab
|= WLAN_CAPABILITY_RADIO_MEASURE
;
728 mgmt
= skb_put_zero(skb
, 24);
729 memcpy(mgmt
->da
, assoc_data
->bss
->bssid
, ETH_ALEN
);
730 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
731 memcpy(mgmt
->bssid
, assoc_data
->bss
->bssid
, ETH_ALEN
);
733 if (!is_zero_ether_addr(assoc_data
->prev_bssid
)) {
735 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
736 IEEE80211_STYPE_REASSOC_REQ
);
737 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
738 mgmt
->u
.reassoc_req
.listen_interval
=
739 cpu_to_le16(local
->hw
.conf
.listen_interval
);
740 memcpy(mgmt
->u
.reassoc_req
.current_ap
, assoc_data
->prev_bssid
,
744 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
745 IEEE80211_STYPE_ASSOC_REQ
);
746 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
747 mgmt
->u
.assoc_req
.listen_interval
=
748 cpu_to_le16(local
->hw
.conf
.listen_interval
);
752 pos
= skb_put(skb
, 2 + assoc_data
->ssid_len
);
753 *pos
++ = WLAN_EID_SSID
;
754 *pos
++ = assoc_data
->ssid_len
;
755 memcpy(pos
, assoc_data
->ssid
, assoc_data
->ssid_len
);
757 /* add all rates which were marked to be used above */
758 supp_rates_len
= rates_len
;
759 if (supp_rates_len
> 8)
762 pos
= skb_put(skb
, supp_rates_len
+ 2);
763 *pos
++ = WLAN_EID_SUPP_RATES
;
764 *pos
++ = supp_rates_len
;
767 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
768 if (BIT(i
) & rates
) {
769 int rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
777 if (rates_len
> count
) {
778 pos
= skb_put(skb
, rates_len
- count
+ 2);
779 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
780 *pos
++ = rates_len
- count
;
782 for (i
++; i
< sband
->n_bitrates
; i
++) {
783 if (BIT(i
) & rates
) {
785 rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
792 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
||
793 capab
& WLAN_CAPABILITY_RADIO_MEASURE
) {
794 pos
= skb_put(skb
, 4);
795 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
797 *pos
++ = 0; /* min tx power */
799 *pos
++ = ieee80211_chandef_max_power(&chanctx_conf
->def
);
802 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
803 /* TODO: get this in reg domain format */
804 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
805 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
806 *pos
++ = 2 * sband
->n_channels
;
807 for (i
= 0; i
< sband
->n_channels
; i
++) {
808 *pos
++ = ieee80211_frequency_to_channel(
809 sband
->channels
[i
].center_freq
);
810 *pos
++ = 1; /* one channel in the subband*/
814 /* if present, add any custom IEs that go before HT */
815 if (assoc_data
->ie_len
) {
816 static const u8 before_ht
[] = {
819 WLAN_EID_EXT_SUPP_RATES
,
820 WLAN_EID_PWR_CAPABILITY
,
821 WLAN_EID_SUPPORTED_CHANNELS
,
824 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
825 WLAN_EID_MOBILITY_DOMAIN
,
826 WLAN_EID_FAST_BSS_TRANSITION
, /* reassoc only */
827 WLAN_EID_RIC_DATA
, /* reassoc only */
828 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
830 static const u8 after_ric
[] = {
831 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
832 WLAN_EID_HT_CAPABILITY
,
833 WLAN_EID_BSS_COEX_2040
,
834 /* luckily this is almost always there */
835 WLAN_EID_EXT_CAPABILITY
,
836 WLAN_EID_QOS_TRAFFIC_CAPA
,
837 WLAN_EID_TIM_BCAST_REQ
,
838 WLAN_EID_INTERWORKING
,
839 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
840 WLAN_EID_VHT_CAPABILITY
,
841 WLAN_EID_OPMODE_NOTIF
,
844 noffset
= ieee80211_ie_split_ric(assoc_data
->ie
,
847 ARRAY_SIZE(before_ht
),
849 ARRAY_SIZE(after_ric
),
851 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
855 if (WARN_ON_ONCE((ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
856 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)))
857 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
859 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
860 ieee80211_add_ht_ie(sdata
, skb
, assoc_data
->ap_ht_param
,
861 sband
, chan
, sdata
->smps_mode
);
863 /* if present, add any custom IEs that go before VHT */
864 if (assoc_data
->ie_len
) {
865 static const u8 before_vht
[] = {
867 * no need to list the ones split off before HT
870 WLAN_EID_BSS_COEX_2040
,
871 WLAN_EID_EXT_CAPABILITY
,
872 WLAN_EID_QOS_TRAFFIC_CAPA
,
873 WLAN_EID_TIM_BCAST_REQ
,
874 WLAN_EID_INTERWORKING
,
875 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
878 /* RIC already taken above, so no need to handle here anymore */
879 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
880 before_vht
, ARRAY_SIZE(before_vht
),
882 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
886 /* if present, add any custom IEs that go before HE */
887 if (assoc_data
->ie_len
) {
888 static const u8 before_he
[] = {
890 * no need to list the ones split off before VHT
893 WLAN_EID_OPMODE_NOTIF
,
894 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE
,
896 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_SESSION
,
897 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_PUBLIC_KEY
,
898 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_KEY_CONFIRM
,
899 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_HLP_CONTAINER
,
900 WLAN_EID_EXTENSION
, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN
,
901 /* TODO: add 11ah/11aj/11ak elements */
904 /* RIC already taken above, so no need to handle here anymore */
905 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
906 before_he
, ARRAY_SIZE(before_he
),
908 pos
= skb_put(skb
, noffset
- offset
);
909 memcpy(pos
, assoc_data
->ie
+ offset
, noffset
- offset
);
913 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
914 ieee80211_add_vht_ie(sdata
, skb
, sband
,
915 &assoc_data
->ap_vht_cap
);
917 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
))
918 ieee80211_add_he_ie(sdata
, skb
, sband
);
920 /* if present, add any custom non-vendor IEs that go after HE */
921 if (assoc_data
->ie_len
) {
922 noffset
= ieee80211_ie_split_vendor(assoc_data
->ie
,
925 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
929 if (assoc_data
->wmm
) {
930 if (assoc_data
->uapsd
) {
931 qos_info
= ifmgd
->uapsd_queues
;
932 qos_info
|= (ifmgd
->uapsd_max_sp_len
<<
933 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
938 pos
= ieee80211_add_wmm_info_ie(skb_put(skb
, 9), qos_info
);
941 /* add any remaining custom (i.e. vendor specific here) IEs */
942 if (assoc_data
->ie_len
) {
943 noffset
= assoc_data
->ie_len
;
944 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
947 if (assoc_data
->fils_kek_len
&&
948 fils_encrypt_assoc_req(skb
, assoc_data
) < 0) {
953 drv_mgd_prepare_tx(local
, sdata
, 0);
955 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
956 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
957 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
958 IEEE80211_TX_INTFL_MLME_CONN_TX
;
959 ieee80211_tx_skb(sdata
, skb
);
962 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
963 struct ieee80211_sub_if_data
*sdata
)
965 struct ieee80211_pspoll
*pspoll
;
968 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
972 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
973 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
975 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
976 ieee80211_tx_skb(sdata
, skb
);
979 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
980 struct ieee80211_sub_if_data
*sdata
,
984 struct ieee80211_hdr_3addr
*nullfunc
;
985 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
987 /* Don't send NDPs when STA is connected HE */
988 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
&&
989 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
))
992 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
,
993 !ieee80211_hw_check(&local
->hw
, DOESNT_SUPPORT_QOS_NDP
));
997 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
999 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1001 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
1002 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
1004 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1005 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
1007 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1008 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
1010 ieee80211_tx_skb(sdata
, skb
);
1013 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
1014 struct ieee80211_sub_if_data
*sdata
)
1016 struct sk_buff
*skb
;
1017 struct ieee80211_hdr
*nullfunc
;
1020 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
1023 /* Don't send NDPs when connected HE */
1024 if (!(sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_HE
))
1027 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
1031 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
1033 nullfunc
= skb_put_zero(skb
, 30);
1034 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
1035 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
1036 nullfunc
->frame_control
= fc
;
1037 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
1038 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
1039 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
1040 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
1042 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
1043 ieee80211_tx_skb(sdata
, skb
);
1046 /* spectrum management related things */
1047 static void ieee80211_chswitch_work(struct work_struct
*work
)
1049 struct ieee80211_sub_if_data
*sdata
=
1050 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
1051 struct ieee80211_local
*local
= sdata
->local
;
1052 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1055 if (!ieee80211_sdata_running(sdata
))
1059 mutex_lock(&local
->mtx
);
1060 mutex_lock(&local
->chanctx_mtx
);
1062 if (!ifmgd
->associated
)
1065 if (!sdata
->vif
.csa_active
)
1069 * using reservation isn't immediate as it may be deferred until later
1070 * with multi-vif. once reservation is complete it will re-schedule the
1071 * work with no reserved_chanctx so verify chandef to check if it
1072 * completed successfully
1075 if (sdata
->reserved_chanctx
) {
1076 struct ieee80211_supported_band
*sband
= NULL
;
1077 struct sta_info
*mgd_sta
= NULL
;
1078 enum ieee80211_sta_rx_bandwidth bw
= IEEE80211_STA_RX_BW_20
;
1081 * with multi-vif csa driver may call ieee80211_csa_finish()
1082 * many times while waiting for other interfaces to use their
1085 if (sdata
->reserved_ready
)
1088 if (sdata
->vif
.bss_conf
.chandef
.width
!=
1089 sdata
->csa_chandef
.width
) {
1091 * For managed interface, we need to also update the AP
1092 * station bandwidth and align the rate scale algorithm
1093 * on the bandwidth change. Here we only consider the
1094 * bandwidth of the new channel definition (as channel
1095 * switch flow does not have the full HT/VHT/HE
1096 * information), assuming that if additional changes are
1097 * required they would be done as part of the processing
1098 * of the next beacon from the AP.
1100 switch (sdata
->csa_chandef
.width
) {
1101 case NL80211_CHAN_WIDTH_20_NOHT
:
1102 case NL80211_CHAN_WIDTH_20
:
1104 bw
= IEEE80211_STA_RX_BW_20
;
1106 case NL80211_CHAN_WIDTH_40
:
1107 bw
= IEEE80211_STA_RX_BW_40
;
1109 case NL80211_CHAN_WIDTH_80
:
1110 bw
= IEEE80211_STA_RX_BW_80
;
1112 case NL80211_CHAN_WIDTH_80P80
:
1113 case NL80211_CHAN_WIDTH_160
:
1114 bw
= IEEE80211_STA_RX_BW_160
;
1118 mgd_sta
= sta_info_get(sdata
, ifmgd
->bssid
);
1120 local
->hw
.wiphy
->bands
[sdata
->csa_chandef
.chan
->band
];
1123 if (sdata
->vif
.bss_conf
.chandef
.width
>
1124 sdata
->csa_chandef
.width
) {
1125 mgd_sta
->sta
.bandwidth
= bw
;
1126 rate_control_rate_update(local
, sband
, mgd_sta
,
1127 IEEE80211_RC_BW_CHANGED
);
1130 ret
= ieee80211_vif_use_reserved_context(sdata
);
1133 "failed to use reserved channel context, disconnecting (err=%d)\n",
1135 ieee80211_queue_work(&sdata
->local
->hw
,
1136 &ifmgd
->csa_connection_drop_work
);
1140 if (sdata
->vif
.bss_conf
.chandef
.width
<
1141 sdata
->csa_chandef
.width
) {
1142 mgd_sta
->sta
.bandwidth
= bw
;
1143 rate_control_rate_update(local
, sband
, mgd_sta
,
1144 IEEE80211_RC_BW_CHANGED
);
1150 if (!cfg80211_chandef_identical(&sdata
->vif
.bss_conf
.chandef
,
1151 &sdata
->csa_chandef
)) {
1153 "failed to finalize channel switch, disconnecting\n");
1154 ieee80211_queue_work(&sdata
->local
->hw
,
1155 &ifmgd
->csa_connection_drop_work
);
1159 /* XXX: shouldn't really modify cfg80211-owned data! */
1160 ifmgd
->associated
->channel
= sdata
->csa_chandef
.chan
;
1162 ifmgd
->csa_waiting_bcn
= true;
1164 ieee80211_sta_reset_beacon_monitor(sdata
);
1165 ieee80211_sta_reset_conn_monitor(sdata
);
1168 mutex_unlock(&local
->chanctx_mtx
);
1169 mutex_unlock(&local
->mtx
);
1170 sdata_unlock(sdata
);
1173 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data
*sdata
)
1175 struct ieee80211_local
*local
= sdata
->local
;
1176 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1179 sdata_assert_lock(sdata
);
1181 WARN_ON(!sdata
->vif
.csa_active
);
1183 if (sdata
->csa_block_tx
) {
1184 ieee80211_wake_vif_queues(local
, sdata
,
1185 IEEE80211_QUEUE_STOP_REASON_CSA
);
1186 sdata
->csa_block_tx
= false;
1189 sdata
->vif
.csa_active
= false;
1190 ifmgd
->csa_waiting_bcn
= false;
1192 ret
= drv_post_channel_switch(sdata
);
1195 "driver post channel switch failed, disconnecting\n");
1196 ieee80211_queue_work(&local
->hw
,
1197 &ifmgd
->csa_connection_drop_work
);
1201 cfg80211_ch_switch_notify(sdata
->dev
, &sdata
->reserved_chandef
);
1204 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
1206 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1207 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1209 trace_api_chswitch_done(sdata
, success
);
1212 "driver channel switch failed, disconnecting\n");
1213 ieee80211_queue_work(&sdata
->local
->hw
,
1214 &ifmgd
->csa_connection_drop_work
);
1216 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
1219 EXPORT_SYMBOL(ieee80211_chswitch_done
);
1221 static void ieee80211_chswitch_timer(struct timer_list
*t
)
1223 struct ieee80211_sub_if_data
*sdata
=
1224 from_timer(sdata
, t
, u
.mgd
.chswitch_timer
);
1226 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->u
.mgd
.chswitch_work
);
1230 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
1231 u64 timestamp
, u32 device_timestamp
,
1232 struct ieee802_11_elems
*elems
,
1235 struct ieee80211_local
*local
= sdata
->local
;
1236 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1237 struct cfg80211_bss
*cbss
= ifmgd
->associated
;
1238 struct ieee80211_chanctx_conf
*conf
;
1239 struct ieee80211_chanctx
*chanctx
;
1240 enum nl80211_band current_band
;
1241 struct ieee80211_csa_ie csa_ie
;
1242 struct ieee80211_channel_switch ch_switch
;
1245 sdata_assert_lock(sdata
);
1250 if (local
->scanning
)
1253 /* disregard subsequent announcements if we are already processing */
1254 if (sdata
->vif
.csa_active
)
1257 current_band
= cbss
->channel
->band
;
1258 res
= ieee80211_parse_ch_switch_ie(sdata
, elems
, current_band
,
1260 ifmgd
->associated
->bssid
, &csa_ie
);
1262 ieee80211_queue_work(&local
->hw
,
1263 &ifmgd
->csa_connection_drop_work
);
1267 if (!cfg80211_chandef_usable(local
->hw
.wiphy
, &csa_ie
.chandef
,
1268 IEEE80211_CHAN_DISABLED
)) {
1270 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1271 ifmgd
->associated
->bssid
,
1272 csa_ie
.chandef
.chan
->center_freq
,
1273 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1274 csa_ie
.chandef
.center_freq2
);
1275 ieee80211_queue_work(&local
->hw
,
1276 &ifmgd
->csa_connection_drop_work
);
1280 if (cfg80211_chandef_identical(&csa_ie
.chandef
,
1281 &sdata
->vif
.bss_conf
.chandef
)) {
1282 if (ifmgd
->csa_ignored_same_chan
)
1285 "AP %pM tries to chanswitch to same channel, ignore\n",
1286 ifmgd
->associated
->bssid
);
1287 ifmgd
->csa_ignored_same_chan
= true;
1292 * Drop all TDLS peers - either we disconnect or move to a different
1293 * channel from this point on. There's no telling what our peer will do.
1294 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1295 * have an incompatible wider chandef.
1297 ieee80211_teardown_tdls_peers(sdata
);
1299 mutex_lock(&local
->mtx
);
1300 mutex_lock(&local
->chanctx_mtx
);
1301 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1302 lockdep_is_held(&local
->chanctx_mtx
));
1305 "no channel context assigned to vif?, disconnecting\n");
1306 goto drop_connection
;
1309 chanctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1311 if (local
->use_chanctx
&&
1312 !ieee80211_hw_check(&local
->hw
, CHANCTX_STA_CSA
)) {
1314 "driver doesn't support chan-switch with channel contexts\n");
1315 goto drop_connection
;
1318 ch_switch
.timestamp
= timestamp
;
1319 ch_switch
.device_timestamp
= device_timestamp
;
1320 ch_switch
.block_tx
= csa_ie
.mode
;
1321 ch_switch
.chandef
= csa_ie
.chandef
;
1322 ch_switch
.count
= csa_ie
.count
;
1324 if (drv_pre_channel_switch(sdata
, &ch_switch
)) {
1326 "preparing for channel switch failed, disconnecting\n");
1327 goto drop_connection
;
1330 res
= ieee80211_vif_reserve_chanctx(sdata
, &csa_ie
.chandef
,
1331 chanctx
->mode
, false);
1334 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1336 goto drop_connection
;
1338 mutex_unlock(&local
->chanctx_mtx
);
1340 sdata
->vif
.csa_active
= true;
1341 sdata
->csa_chandef
= csa_ie
.chandef
;
1342 sdata
->csa_block_tx
= csa_ie
.mode
;
1343 ifmgd
->csa_ignored_same_chan
= false;
1345 if (sdata
->csa_block_tx
)
1346 ieee80211_stop_vif_queues(local
, sdata
,
1347 IEEE80211_QUEUE_STOP_REASON_CSA
);
1348 mutex_unlock(&local
->mtx
);
1350 cfg80211_ch_switch_started_notify(sdata
->dev
, &csa_ie
.chandef
,
1353 if (local
->ops
->channel_switch
) {
1354 /* use driver's channel switch callback */
1355 drv_channel_switch(local
, sdata
, &ch_switch
);
1359 /* channel switch handled in software */
1360 if (csa_ie
.count
<= 1)
1361 ieee80211_queue_work(&local
->hw
, &ifmgd
->chswitch_work
);
1363 mod_timer(&ifmgd
->chswitch_timer
,
1364 TU_TO_EXP_TIME((csa_ie
.count
- 1) *
1365 cbss
->beacon_interval
));
1369 * This is just so that the disconnect flow will know that
1370 * we were trying to switch channel and failed. In case the
1371 * mode is 1 (we are not allowed to Tx), we will know not to
1372 * send a deauthentication frame. Those two fields will be
1373 * reset when the disconnection worker runs.
1375 sdata
->vif
.csa_active
= true;
1376 sdata
->csa_block_tx
= csa_ie
.mode
;
1378 ieee80211_queue_work(&local
->hw
, &ifmgd
->csa_connection_drop_work
);
1379 mutex_unlock(&local
->chanctx_mtx
);
1380 mutex_unlock(&local
->mtx
);
1384 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1385 struct ieee80211_channel
*channel
,
1386 const u8
*country_ie
, u8 country_ie_len
,
1387 const u8
*pwr_constr_elem
,
1388 int *chan_pwr
, int *pwr_reduction
)
1390 struct ieee80211_country_ie_triplet
*triplet
;
1391 int chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1392 int i
, chan_increment
;
1393 bool have_chan_pwr
= false;
1396 if (country_ie_len
% 2 || country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1399 triplet
= (void *)(country_ie
+ 3);
1400 country_ie_len
-= 3;
1402 switch (channel
->band
) {
1406 case NL80211_BAND_2GHZ
:
1407 case NL80211_BAND_60GHZ
:
1410 case NL80211_BAND_5GHZ
:
1416 while (country_ie_len
>= 3) {
1417 u8 first_channel
= triplet
->chans
.first_channel
;
1419 if (first_channel
>= IEEE80211_COUNTRY_EXTENSION_ID
)
1422 for (i
= 0; i
< triplet
->chans
.num_channels
; i
++) {
1423 if (first_channel
+ i
* chan_increment
== chan
) {
1424 have_chan_pwr
= true;
1425 *chan_pwr
= triplet
->chans
.max_power
;
1434 country_ie_len
-= 3;
1437 if (have_chan_pwr
&& pwr_constr_elem
)
1438 *pwr_reduction
= *pwr_constr_elem
;
1442 return have_chan_pwr
;
1445 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data
*sdata
,
1446 struct ieee80211_channel
*channel
,
1447 const u8
*cisco_dtpc_ie
,
1450 /* From practical testing, the first data byte of the DTPC element
1451 * seems to contain the requested dBm level, and the CLI on Cisco
1452 * APs clearly state the range is -127 to 127 dBm, which indicates
1453 * a signed byte, although it seemingly never actually goes negative.
1454 * The other byte seems to always be zero.
1456 *pwr_level
= (__s8
)cisco_dtpc_ie
[4];
1459 static u32
ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1460 struct ieee80211_channel
*channel
,
1461 struct ieee80211_mgmt
*mgmt
,
1462 const u8
*country_ie
, u8 country_ie_len
,
1463 const u8
*pwr_constr_ie
,
1464 const u8
*cisco_dtpc_ie
)
1466 bool has_80211h_pwr
= false, has_cisco_pwr
= false;
1467 int chan_pwr
= 0, pwr_reduction_80211h
= 0;
1468 int pwr_level_cisco
, pwr_level_80211h
;
1470 __le16 capab
= mgmt
->u
.probe_resp
.capab_info
;
1473 (capab
& cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT
) ||
1474 capab
& cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE
))) {
1475 has_80211h_pwr
= ieee80211_find_80211h_pwr_constr(
1476 sdata
, channel
, country_ie
, country_ie_len
,
1477 pwr_constr_ie
, &chan_pwr
, &pwr_reduction_80211h
);
1479 max_t(int, 0, chan_pwr
- pwr_reduction_80211h
);
1482 if (cisco_dtpc_ie
) {
1483 ieee80211_find_cisco_dtpc(
1484 sdata
, channel
, cisco_dtpc_ie
, &pwr_level_cisco
);
1485 has_cisco_pwr
= true;
1488 if (!has_80211h_pwr
&& !has_cisco_pwr
)
1491 /* If we have both 802.11h and Cisco DTPC, apply both limits
1492 * by picking the smallest of the two power levels advertised.
1494 if (has_80211h_pwr
&&
1495 (!has_cisco_pwr
|| pwr_level_80211h
<= pwr_level_cisco
)) {
1496 new_ap_level
= pwr_level_80211h
;
1498 if (sdata
->ap_power_level
== new_ap_level
)
1502 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1503 pwr_level_80211h
, chan_pwr
, pwr_reduction_80211h
,
1504 sdata
->u
.mgd
.bssid
);
1505 } else { /* has_cisco_pwr is always true here. */
1506 new_ap_level
= pwr_level_cisco
;
1508 if (sdata
->ap_power_level
== new_ap_level
)
1512 "Limiting TX power to %d dBm as advertised by %pM\n",
1513 pwr_level_cisco
, sdata
->u
.mgd
.bssid
);
1516 sdata
->ap_power_level
= new_ap_level
;
1517 if (__ieee80211_recalc_txpower(sdata
))
1518 return BSS_CHANGED_TXPOWER
;
1523 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
1524 struct ieee80211_sub_if_data
*sdata
)
1526 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1529 * If we are scanning right now then the parameters will
1530 * take effect when scan finishes.
1532 if (local
->scanning
)
1535 if (conf
->dynamic_ps_timeout
> 0 &&
1536 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
)) {
1537 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1538 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
1540 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
1541 ieee80211_send_nullfunc(local
, sdata
, true);
1543 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1544 ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1547 conf
->flags
|= IEEE80211_CONF_PS
;
1548 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1552 static void ieee80211_change_ps(struct ieee80211_local
*local
)
1554 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1556 if (local
->ps_sdata
) {
1557 ieee80211_enable_ps(local
, local
->ps_sdata
);
1558 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
1559 conf
->flags
&= ~IEEE80211_CONF_PS
;
1560 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1561 del_timer_sync(&local
->dynamic_ps_timer
);
1562 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1566 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
1568 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
1569 struct sta_info
*sta
= NULL
;
1570 bool authorized
= false;
1572 if (!mgd
->powersave
)
1578 if (!mgd
->associated
)
1581 if (mgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1584 if (!mgd
->have_beacon
)
1588 sta
= sta_info_get(sdata
, mgd
->bssid
);
1590 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
1596 /* need to hold RTNL or interface lock */
1597 void ieee80211_recalc_ps(struct ieee80211_local
*local
)
1599 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
1603 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
)) {
1604 local
->ps_sdata
= NULL
;
1608 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1609 if (!ieee80211_sdata_running(sdata
))
1611 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1612 /* If an AP vif is found, then disable PS
1613 * by setting the count to zero thereby setting
1619 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1625 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
1626 u8 dtimper
= found
->u
.mgd
.dtim_period
;
1628 timeout
= local
->dynamic_ps_forced_timeout
;
1631 local
->hw
.conf
.dynamic_ps_timeout
= timeout
;
1633 /* If the TIM IE is invalid, pretend the value is 1 */
1637 local
->hw
.conf
.ps_dtim_period
= dtimper
;
1638 local
->ps_sdata
= found
;
1640 local
->ps_sdata
= NULL
;
1643 ieee80211_change_ps(local
);
1646 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data
*sdata
)
1648 bool ps_allowed
= ieee80211_powersave_allowed(sdata
);
1650 if (sdata
->vif
.bss_conf
.ps
!= ps_allowed
) {
1651 sdata
->vif
.bss_conf
.ps
= ps_allowed
;
1652 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_PS
);
1656 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
1658 struct ieee80211_local
*local
=
1659 container_of(work
, struct ieee80211_local
,
1660 dynamic_ps_disable_work
);
1662 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1663 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1664 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1667 ieee80211_wake_queues_by_reason(&local
->hw
,
1668 IEEE80211_MAX_QUEUE_MAP
,
1669 IEEE80211_QUEUE_STOP_REASON_PS
,
1673 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
1675 struct ieee80211_local
*local
=
1676 container_of(work
, struct ieee80211_local
,
1677 dynamic_ps_enable_work
);
1678 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
1679 struct ieee80211_if_managed
*ifmgd
;
1680 unsigned long flags
;
1683 /* can only happen when PS was just disabled anyway */
1687 ifmgd
= &sdata
->u
.mgd
;
1689 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
1692 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1693 /* don't enter PS if TX frames are pending */
1694 if (drv_tx_frames_pending(local
)) {
1695 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1697 local
->hw
.conf
.dynamic_ps_timeout
));
1702 * transmission can be stopped by others which leads to
1703 * dynamic_ps_timer expiry. Postpone the ps timer if it
1704 * is not the actual idle state.
1706 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1707 for (q
= 0; q
< local
->hw
.queues
; q
++) {
1708 if (local
->queue_stop_reasons
[q
]) {
1709 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1711 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1713 local
->hw
.conf
.dynamic_ps_timeout
));
1717 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1720 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1721 !(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1722 if (drv_tx_frames_pending(local
)) {
1723 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1725 local
->hw
.conf
.dynamic_ps_timeout
));
1727 ieee80211_send_nullfunc(local
, sdata
, true);
1728 /* Flush to get the tx status of nullfunc frame */
1729 ieee80211_flush_queues(local
, sdata
, false);
1733 if (!(ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
) &&
1734 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
)) ||
1735 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1736 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
1737 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
1738 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1742 void ieee80211_dynamic_ps_timer(struct timer_list
*t
)
1744 struct ieee80211_local
*local
= from_timer(local
, t
, dynamic_ps_timer
);
1746 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
1749 void ieee80211_dfs_cac_timer_work(struct work_struct
*work
)
1751 struct delayed_work
*delayed_work
= to_delayed_work(work
);
1752 struct ieee80211_sub_if_data
*sdata
=
1753 container_of(delayed_work
, struct ieee80211_sub_if_data
,
1754 dfs_cac_timer_work
);
1755 struct cfg80211_chan_def chandef
= sdata
->vif
.bss_conf
.chandef
;
1757 mutex_lock(&sdata
->local
->mtx
);
1758 if (sdata
->wdev
.cac_started
) {
1759 ieee80211_vif_release_channel(sdata
);
1760 cfg80211_cac_event(sdata
->dev
, &chandef
,
1761 NL80211_RADAR_CAC_FINISHED
,
1764 mutex_unlock(&sdata
->local
->mtx
);
1768 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1770 struct ieee80211_local
*local
= sdata
->local
;
1771 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1775 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1778 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1779 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
1781 unsigned long now
= jiffies
;
1783 if (tx_tspec
->action
== TX_TSPEC_ACTION_NONE
&&
1784 tx_tspec
->admitted_time
&&
1785 time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1786 tx_tspec
->consumed_tx_time
= 0;
1787 tx_tspec
->time_slice_start
= now
;
1789 if (tx_tspec
->downgraded
)
1791 TX_TSPEC_ACTION_STOP_DOWNGRADE
;
1794 switch (tx_tspec
->action
) {
1795 case TX_TSPEC_ACTION_STOP_DOWNGRADE
:
1796 /* take the original parameters */
1797 if (drv_conf_tx(local
, sdata
, ac
, &sdata
->tx_conf
[ac
]))
1799 "failed to set TX queue parameters for queue %d\n",
1801 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1802 tx_tspec
->downgraded
= false;
1805 case TX_TSPEC_ACTION_DOWNGRADE
:
1806 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1807 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1811 /* downgrade next lower non-ACM AC */
1812 for (non_acm_ac
= ac
+ 1;
1813 non_acm_ac
< IEEE80211_NUM_ACS
;
1815 if (!(sdata
->wmm_acm
& BIT(7 - 2 * non_acm_ac
)))
1817 /* Usually the loop will result in using BK even if it
1818 * requires admission control, but such a configuration
1819 * makes no sense and we have to transmit somehow - the
1820 * AC selection does the same thing.
1821 * If we started out trying to downgrade from BK, then
1822 * the extra condition here might be needed.
1824 if (non_acm_ac
>= IEEE80211_NUM_ACS
)
1825 non_acm_ac
= IEEE80211_AC_BK
;
1826 if (drv_conf_tx(local
, sdata
, ac
,
1827 &sdata
->tx_conf
[non_acm_ac
]))
1829 "failed to set TX queue parameters for queue %d\n",
1831 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1833 schedule_delayed_work(&ifmgd
->tx_tspec_wk
,
1834 tx_tspec
->time_slice_start
+ HZ
- now
+ 1);
1836 case TX_TSPEC_ACTION_NONE
:
1845 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1847 if (__ieee80211_sta_handle_tspec_ac_params(sdata
))
1848 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
1851 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct
*work
)
1853 struct ieee80211_sub_if_data
*sdata
;
1855 sdata
= container_of(work
, struct ieee80211_sub_if_data
,
1856 u
.mgd
.tx_tspec_wk
.work
);
1857 ieee80211_sta_handle_tspec_ac_params(sdata
);
1862 ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
1863 struct ieee80211_sub_if_data
*sdata
,
1864 const u8
*wmm_param
, size_t wmm_param_len
,
1865 const struct ieee80211_mu_edca_param_set
*mu_edca
)
1867 struct ieee80211_tx_queue_params params
[IEEE80211_NUM_ACS
];
1868 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1872 u8 uapsd_queues
= 0;
1874 if (!local
->ops
->conf_tx
)
1877 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1883 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
1886 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
1887 uapsd_queues
= ifmgd
->uapsd_queues
;
1889 count
= wmm_param
[6] & 0x0f;
1890 if (count
== ifmgd
->wmm_last_param_set
)
1892 ifmgd
->wmm_last_param_set
= count
;
1894 pos
= wmm_param
+ 8;
1895 left
= wmm_param_len
- 8;
1897 memset(¶ms
, 0, sizeof(params
));
1900 for (; left
>= 4; left
-= 4, pos
+= 4) {
1901 int aci
= (pos
[0] >> 5) & 0x03;
1902 int acm
= (pos
[0] >> 4) & 0x01;
1907 ac
= IEEE80211_AC_BK
;
1909 sdata
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
1910 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1912 params
[ac
].mu_edca
= !!mu_edca
;
1914 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_bk
;
1917 ac
= IEEE80211_AC_VI
;
1919 sdata
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
1920 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1922 params
[ac
].mu_edca
= !!mu_edca
;
1924 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_vi
;
1927 ac
= IEEE80211_AC_VO
;
1929 sdata
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
1930 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1932 params
[ac
].mu_edca
= !!mu_edca
;
1934 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_vo
;
1938 ac
= IEEE80211_AC_BE
;
1940 sdata
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
1941 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1943 params
[ac
].mu_edca
= !!mu_edca
;
1945 params
[ac
].mu_edca_param_rec
= mu_edca
->ac_be
;
1949 params
[ac
].aifs
= pos
[0] & 0x0f;
1951 if (params
[ac
].aifs
< 2) {
1953 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
1954 params
[ac
].aifs
, aci
);
1955 params
[ac
].aifs
= 2;
1957 params
[ac
].cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
1958 params
[ac
].cw_min
= ecw2cw(pos
[1] & 0x0f);
1959 params
[ac
].txop
= get_unaligned_le16(pos
+ 2);
1960 params
[ac
].acm
= acm
;
1961 params
[ac
].uapsd
= uapsd
;
1963 if (params
[ac
].cw_min
== 0 ||
1964 params
[ac
].cw_min
> params
[ac
].cw_max
) {
1966 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1967 params
[ac
].cw_min
, params
[ac
].cw_max
, aci
);
1970 ieee80211_regulatory_limit_wmm_params(sdata
, ¶ms
[ac
], ac
);
1973 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1975 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1977 params
[ac
].aifs
, params
[ac
].cw_min
, params
[ac
].cw_max
,
1978 params
[ac
].txop
, params
[ac
].uapsd
,
1979 ifmgd
->tx_tspec
[ac
].downgraded
);
1980 sdata
->tx_conf
[ac
] = params
[ac
];
1981 if (!ifmgd
->tx_tspec
[ac
].downgraded
&&
1982 drv_conf_tx(local
, sdata
, ac
, ¶ms
[ac
]))
1984 "failed to set TX queue parameters for AC %d\n",
1988 /* enable WMM or activate new settings */
1989 sdata
->vif
.bss_conf
.qos
= true;
1993 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1995 lockdep_assert_held(&sdata
->local
->mtx
);
1997 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_CONNECTION_POLL
;
1998 ieee80211_run_deferred_scan(sdata
->local
);
2001 static void ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
2003 mutex_lock(&sdata
->local
->mtx
);
2004 __ieee80211_stop_poll(sdata
);
2005 mutex_unlock(&sdata
->local
->mtx
);
2008 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
2009 u16 capab
, bool erp_valid
, u8 erp
)
2011 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2012 struct ieee80211_supported_band
*sband
;
2014 bool use_protection
;
2015 bool use_short_preamble
;
2016 bool use_short_slot
;
2018 sband
= ieee80211_get_sband(sdata
);
2023 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
2024 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
2026 use_protection
= false;
2027 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
2030 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
2031 if (sband
->band
== NL80211_BAND_5GHZ
)
2032 use_short_slot
= true;
2034 if (use_protection
!= bss_conf
->use_cts_prot
) {
2035 bss_conf
->use_cts_prot
= use_protection
;
2036 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
2039 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
2040 bss_conf
->use_short_preamble
= use_short_preamble
;
2041 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
2044 if (use_short_slot
!= bss_conf
->use_short_slot
) {
2045 bss_conf
->use_short_slot
= use_short_slot
;
2046 changed
|= BSS_CHANGED_ERP_SLOT
;
2052 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
2053 struct cfg80211_bss
*cbss
,
2054 u32 bss_info_changed
)
2056 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
2057 struct ieee80211_local
*local
= sdata
->local
;
2058 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2060 bss_info_changed
|= BSS_CHANGED_ASSOC
;
2061 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
2062 bss_conf
->assoc_capability
, bss
->has_erp_value
, bss
->erp_value
);
2064 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
2065 beacon_loss_count
* bss_conf
->beacon_int
));
2067 sdata
->u
.mgd
.associated
= cbss
;
2068 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
2070 ieee80211_check_rate_mask(sdata
);
2072 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
2074 if (sdata
->vif
.p2p
||
2075 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
2076 const struct cfg80211_bss_ies
*ies
;
2079 ies
= rcu_dereference(cbss
->ies
);
2083 ret
= cfg80211_get_p2p_attr(
2084 ies
->data
, ies
->len
,
2085 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
2086 (u8
*) &bss_conf
->p2p_noa_attr
,
2087 sizeof(bss_conf
->p2p_noa_attr
));
2089 sdata
->u
.mgd
.p2p_noa_index
=
2090 bss_conf
->p2p_noa_attr
.index
;
2091 bss_info_changed
|= BSS_CHANGED_P2P_PS
;
2097 /* just to be sure */
2098 ieee80211_stop_poll(sdata
);
2100 ieee80211_led_assoc(local
, 1);
2102 if (sdata
->u
.mgd
.have_beacon
) {
2104 * If the AP is buggy we may get here with no DTIM period
2105 * known, so assume it's 1 which is the only safe assumption
2106 * in that case, although if the TIM IE is broken powersave
2107 * probably just won't work at all.
2109 bss_conf
->dtim_period
= sdata
->u
.mgd
.dtim_period
?: 1;
2110 bss_conf
->beacon_rate
= bss
->beacon_rate
;
2111 bss_info_changed
|= BSS_CHANGED_BEACON_INFO
;
2113 bss_conf
->beacon_rate
= NULL
;
2114 bss_conf
->dtim_period
= 0;
2117 bss_conf
->assoc
= 1;
2119 /* Tell the driver to monitor connection quality (if supported) */
2120 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
&&
2121 bss_conf
->cqm_rssi_thold
)
2122 bss_info_changed
|= BSS_CHANGED_CQM
;
2124 /* Enable ARP filtering */
2125 if (bss_conf
->arp_addr_cnt
)
2126 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
2128 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
2130 mutex_lock(&local
->iflist_mtx
);
2131 ieee80211_recalc_ps(local
);
2132 mutex_unlock(&local
->iflist_mtx
);
2134 ieee80211_recalc_smps(sdata
);
2135 ieee80211_recalc_ps_vif(sdata
);
2137 netif_carrier_on(sdata
->dev
);
2140 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
2141 u16 stype
, u16 reason
, bool tx
,
2144 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2145 struct ieee80211_local
*local
= sdata
->local
;
2148 sdata_assert_lock(sdata
);
2150 if (WARN_ON_ONCE(tx
&& !frame_buf
))
2153 if (WARN_ON(!ifmgd
->associated
))
2156 ieee80211_stop_poll(sdata
);
2158 ifmgd
->associated
= NULL
;
2159 netif_carrier_off(sdata
->dev
);
2162 * if we want to get out of ps before disassoc (why?) we have
2163 * to do it before sending disassoc, as otherwise the null-packet
2166 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
2167 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
2168 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2170 local
->ps_sdata
= NULL
;
2172 /* disable per-vif ps */
2173 ieee80211_recalc_ps_vif(sdata
);
2175 /* make sure ongoing transmission finishes */
2179 * drop any frame before deauth/disassoc, this can be data or
2180 * management frame. Since we are disconnecting, we should not
2181 * insist sending these frames which can take time and delay
2182 * the disconnection and possible the roaming.
2185 ieee80211_flush_queues(local
, sdata
, true);
2187 /* deauthenticate/disassociate now */
2188 if (tx
|| frame_buf
) {
2190 * In multi channel scenarios guarantee that the virtual
2191 * interface is granted immediate airtime to transmit the
2192 * deauthentication frame by calling mgd_prepare_tx, if the
2193 * driver requested so.
2195 if (ieee80211_hw_check(&local
->hw
, DEAUTH_NEED_MGD_TX_PREP
) &&
2196 !ifmgd
->have_beacon
)
2197 drv_mgd_prepare_tx(sdata
->local
, sdata
, 0);
2199 ieee80211_send_deauth_disassoc(sdata
, ifmgd
->bssid
, stype
,
2200 reason
, tx
, frame_buf
);
2203 /* flush out frame - make sure the deauth was actually sent */
2205 ieee80211_flush_queues(local
, sdata
, false);
2207 /* clear bssid only after building the needed mgmt frames */
2208 eth_zero_addr(ifmgd
->bssid
);
2210 /* remove AP and TDLS peers */
2211 sta_info_flush(sdata
);
2213 /* finally reset all BSS / config parameters */
2214 changed
|= ieee80211_reset_erp_info(sdata
);
2216 ieee80211_led_assoc(local
, 0);
2217 changed
|= BSS_CHANGED_ASSOC
;
2218 sdata
->vif
.bss_conf
.assoc
= false;
2220 ifmgd
->p2p_noa_index
= -1;
2221 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
2222 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
2224 /* on the next assoc, re-program HT/VHT parameters */
2225 memset(&ifmgd
->ht_capa
, 0, sizeof(ifmgd
->ht_capa
));
2226 memset(&ifmgd
->ht_capa_mask
, 0, sizeof(ifmgd
->ht_capa_mask
));
2227 memset(&ifmgd
->vht_capa
, 0, sizeof(ifmgd
->vht_capa
));
2228 memset(&ifmgd
->vht_capa_mask
, 0, sizeof(ifmgd
->vht_capa_mask
));
2230 /* reset MU-MIMO ownership and group data */
2231 memset(sdata
->vif
.bss_conf
.mu_group
.membership
, 0,
2232 sizeof(sdata
->vif
.bss_conf
.mu_group
.membership
));
2233 memset(sdata
->vif
.bss_conf
.mu_group
.position
, 0,
2234 sizeof(sdata
->vif
.bss_conf
.mu_group
.position
));
2235 changed
|= BSS_CHANGED_MU_GROUPS
;
2236 sdata
->vif
.mu_mimo_owner
= false;
2238 sdata
->ap_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2240 del_timer_sync(&local
->dynamic_ps_timer
);
2241 cancel_work_sync(&local
->dynamic_ps_enable_work
);
2243 /* Disable ARP filtering */
2244 if (sdata
->vif
.bss_conf
.arp_addr_cnt
)
2245 changed
|= BSS_CHANGED_ARP_FILTER
;
2247 sdata
->vif
.bss_conf
.qos
= false;
2248 changed
|= BSS_CHANGED_QOS
;
2250 /* The BSSID (not really interesting) and HT changed */
2251 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
2252 ieee80211_bss_info_change_notify(sdata
, changed
);
2254 /* disassociated - set to defaults now */
2255 ieee80211_set_wmm_default(sdata
, false, false);
2257 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
2258 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
2259 del_timer_sync(&sdata
->u
.mgd
.timer
);
2260 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
2262 sdata
->vif
.bss_conf
.dtim_period
= 0;
2263 sdata
->vif
.bss_conf
.beacon_rate
= NULL
;
2265 ifmgd
->have_beacon
= false;
2268 mutex_lock(&local
->mtx
);
2269 ieee80211_vif_release_channel(sdata
);
2271 sdata
->vif
.csa_active
= false;
2272 ifmgd
->csa_waiting_bcn
= false;
2273 ifmgd
->csa_ignored_same_chan
= false;
2274 if (sdata
->csa_block_tx
) {
2275 ieee80211_wake_vif_queues(local
, sdata
,
2276 IEEE80211_QUEUE_STOP_REASON_CSA
);
2277 sdata
->csa_block_tx
= false;
2279 mutex_unlock(&local
->mtx
);
2281 /* existing TX TSPEC sessions no longer exist */
2282 memset(ifmgd
->tx_tspec
, 0, sizeof(ifmgd
->tx_tspec
));
2283 cancel_delayed_work_sync(&ifmgd
->tx_tspec_wk
);
2285 sdata
->encrypt_headroom
= IEEE80211_ENCRYPT_HEADROOM
;
2288 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data
*sdata
,
2289 struct ieee80211_hdr
*hdr
)
2292 * We can postpone the mgd.timer whenever receiving unicast frames
2293 * from AP because we know that the connection is working both ways
2294 * at that time. But multicast frames (and hence also beacons) must
2295 * be ignored here, because we need to trigger the timer during
2296 * data idle periods for sending the periodic probe request to the
2297 * AP we're connected to.
2299 if (is_multicast_ether_addr(hdr
->addr1
))
2302 ieee80211_sta_reset_conn_monitor(sdata
);
2305 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
2307 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2308 struct ieee80211_local
*local
= sdata
->local
;
2310 mutex_lock(&local
->mtx
);
2311 if (!(ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
))
2314 __ieee80211_stop_poll(sdata
);
2316 mutex_lock(&local
->iflist_mtx
);
2317 ieee80211_recalc_ps(local
);
2318 mutex_unlock(&local
->iflist_mtx
);
2320 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
2324 * We've received a probe response, but are not sure whether
2325 * we have or will be receiving any beacons or data, so let's
2326 * schedule the timers again, just in case.
2328 ieee80211_sta_reset_beacon_monitor(sdata
);
2330 mod_timer(&ifmgd
->conn_mon_timer
,
2331 round_jiffies_up(jiffies
+
2332 IEEE80211_CONNECTION_IDLE_TIME
));
2334 mutex_unlock(&local
->mtx
);
2337 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data
*sdata
,
2338 struct ieee80211_hdr
*hdr
,
2341 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2342 u16 tid
= ieee80211_get_tid(hdr
);
2343 int ac
= ieee80211_ac_from_tid(tid
);
2344 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
2345 unsigned long now
= jiffies
;
2347 if (likely(!tx_tspec
->admitted_time
))
2350 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
2351 tx_tspec
->consumed_tx_time
= 0;
2352 tx_tspec
->time_slice_start
= now
;
2354 if (tx_tspec
->downgraded
) {
2355 tx_tspec
->action
= TX_TSPEC_ACTION_STOP_DOWNGRADE
;
2356 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2360 if (tx_tspec
->downgraded
)
2363 tx_tspec
->consumed_tx_time
+= tx_time
;
2365 if (tx_tspec
->consumed_tx_time
>= tx_tspec
->admitted_time
) {
2366 tx_tspec
->downgraded
= true;
2367 tx_tspec
->action
= TX_TSPEC_ACTION_DOWNGRADE
;
2368 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2372 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
2373 struct ieee80211_hdr
*hdr
, bool ack
, u16 tx_time
)
2375 ieee80211_sta_tx_wmm_ac_notify(sdata
, hdr
, tx_time
);
2377 if (!ieee80211_is_data(hdr
->frame_control
))
2380 if (ieee80211_is_nullfunc(hdr
->frame_control
) &&
2381 sdata
->u
.mgd
.probe_send_count
> 0) {
2383 ieee80211_sta_reset_conn_monitor(sdata
);
2385 sdata
->u
.mgd
.nullfunc_failed
= true;
2386 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
2391 ieee80211_sta_reset_conn_monitor(sdata
);
2394 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data
*sdata
,
2395 const u8
*src
, const u8
*dst
,
2396 const u8
*ssid
, size_t ssid_len
,
2397 struct ieee80211_channel
*channel
)
2399 struct sk_buff
*skb
;
2401 skb
= ieee80211_build_probe_req(sdata
, src
, dst
, (u32
)-1, channel
,
2402 ssid
, ssid_len
, NULL
, 0,
2403 IEEE80211_PROBE_FLAG_DIRECTED
);
2405 ieee80211_tx_skb(sdata
, skb
);
2408 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
2410 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2412 u8
*dst
= ifmgd
->associated
->bssid
;
2413 u8 unicast_limit
= max(1, max_probe_tries
- 3);
2414 struct sta_info
*sta
;
2417 * Try sending broadcast probe requests for the last three
2418 * probe requests after the first ones failed since some
2419 * buggy APs only support broadcast probe requests.
2421 if (ifmgd
->probe_send_count
>= unicast_limit
)
2425 * When the hardware reports an accurate Tx ACK status, it's
2426 * better to send a nullfunc frame instead of a probe request,
2427 * as it will kick us off the AP quickly if we aren't associated
2428 * anymore. The timeout will be reset if the frame is ACKed by
2431 ifmgd
->probe_send_count
++;
2434 mutex_lock(&sdata
->local
->sta_mtx
);
2435 sta
= sta_info_get(sdata
, dst
);
2437 ieee80211_check_fast_rx(sta
);
2438 mutex_unlock(&sdata
->local
->sta_mtx
);
2441 if (ieee80211_hw_check(&sdata
->local
->hw
, REPORTS_TX_ACK_STATUS
)) {
2442 ifmgd
->nullfunc_failed
= false;
2443 ieee80211_send_nullfunc(sdata
->local
, sdata
, false);
2448 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
2449 if (WARN_ON_ONCE(ssid
== NULL
))
2454 ieee80211_mlme_send_probe_req(sdata
, sdata
->vif
.addr
, dst
,
2456 ifmgd
->associated
->channel
);
2460 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
2461 run_again(sdata
, ifmgd
->probe_timeout
);
2464 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
2467 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2468 bool already
= false;
2470 if (!ieee80211_sdata_running(sdata
))
2475 if (!ifmgd
->associated
)
2478 mutex_lock(&sdata
->local
->mtx
);
2480 if (sdata
->local
->tmp_channel
|| sdata
->local
->scanning
) {
2481 mutex_unlock(&sdata
->local
->mtx
);
2486 mlme_dbg_ratelimited(sdata
,
2487 "detected beacon loss from AP (missed %d beacons) - probing\n",
2490 ieee80211_cqm_beacon_loss_notify(&sdata
->vif
, GFP_KERNEL
);
2494 * The driver/our work has already reported this event or the
2495 * connection monitoring has kicked in and we have already sent
2496 * a probe request. Or maybe the AP died and the driver keeps
2497 * reporting until we disassociate...
2499 * In either case we have to ignore the current call to this
2500 * function (except for setting the correct probe reason bit)
2501 * because otherwise we would reset the timer every time and
2502 * never check whether we received a probe response!
2504 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
2507 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
2509 mutex_unlock(&sdata
->local
->mtx
);
2514 mutex_lock(&sdata
->local
->iflist_mtx
);
2515 ieee80211_recalc_ps(sdata
->local
);
2516 mutex_unlock(&sdata
->local
->iflist_mtx
);
2518 ifmgd
->probe_send_count
= 0;
2519 ieee80211_mgd_probe_ap_send(sdata
);
2521 sdata_unlock(sdata
);
2524 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
2525 struct ieee80211_vif
*vif
)
2527 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2528 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2529 struct cfg80211_bss
*cbss
;
2530 struct sk_buff
*skb
;
2534 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2537 sdata_assert_lock(sdata
);
2539 if (ifmgd
->associated
)
2540 cbss
= ifmgd
->associated
;
2541 else if (ifmgd
->auth_data
)
2542 cbss
= ifmgd
->auth_data
->bss
;
2543 else if (ifmgd
->assoc_data
)
2544 cbss
= ifmgd
->assoc_data
->bss
;
2549 ssid
= ieee80211_bss_get_ie(cbss
, WLAN_EID_SSID
);
2550 if (WARN_ON_ONCE(ssid
== NULL
))
2555 skb
= ieee80211_build_probe_req(sdata
, sdata
->vif
.addr
, cbss
->bssid
,
2556 (u32
) -1, cbss
->channel
,
2558 NULL
, 0, IEEE80211_PROBE_FLAG_DIRECTED
);
2563 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
2565 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data
*sdata
,
2566 const u8
*buf
, size_t len
, bool tx
,
2569 struct ieee80211_event event
= {
2571 .u
.mlme
.data
= tx
? DEAUTH_TX_EVENT
: DEAUTH_RX_EVENT
,
2572 .u
.mlme
.reason
= reason
,
2576 cfg80211_tx_mlme_mgmt(sdata
->dev
, buf
, len
);
2578 cfg80211_rx_mlme_mgmt(sdata
->dev
, buf
, len
);
2580 drv_event_callback(sdata
->local
, sdata
, &event
);
2583 static void __ieee80211_disconnect(struct ieee80211_sub_if_data
*sdata
)
2585 struct ieee80211_local
*local
= sdata
->local
;
2586 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2587 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2591 if (!ifmgd
->associated
) {
2592 sdata_unlock(sdata
);
2596 tx
= !sdata
->csa_block_tx
;
2598 /* AP is probably out of range (or not reachable for another reason) so
2599 * remove the bss struct for that AP.
2601 cfg80211_unlink_bss(local
->hw
.wiphy
, ifmgd
->associated
);
2603 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
2604 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2606 mutex_lock(&local
->mtx
);
2607 sdata
->vif
.csa_active
= false;
2608 ifmgd
->csa_waiting_bcn
= false;
2609 if (sdata
->csa_block_tx
) {
2610 ieee80211_wake_vif_queues(local
, sdata
,
2611 IEEE80211_QUEUE_STOP_REASON_CSA
);
2612 sdata
->csa_block_tx
= false;
2614 mutex_unlock(&local
->mtx
);
2616 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), tx
,
2617 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
2619 sdata_unlock(sdata
);
2622 static void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
2624 struct ieee80211_sub_if_data
*sdata
=
2625 container_of(work
, struct ieee80211_sub_if_data
,
2626 u
.mgd
.beacon_connection_loss_work
);
2627 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2629 if (ifmgd
->associated
)
2630 ifmgd
->beacon_loss_count
++;
2632 if (ifmgd
->connection_loss
) {
2633 sdata_info(sdata
, "Connection to AP %pM lost\n",
2635 __ieee80211_disconnect(sdata
);
2637 ieee80211_mgd_probe_ap(sdata
, true);
2641 static void ieee80211_csa_connection_drop_work(struct work_struct
*work
)
2643 struct ieee80211_sub_if_data
*sdata
=
2644 container_of(work
, struct ieee80211_sub_if_data
,
2645 u
.mgd
.csa_connection_drop_work
);
2647 __ieee80211_disconnect(sdata
);
2650 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
2652 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2653 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2655 trace_api_beacon_loss(sdata
);
2657 sdata
->u
.mgd
.connection_loss
= false;
2658 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2660 EXPORT_SYMBOL(ieee80211_beacon_loss
);
2662 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
2664 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2665 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2667 trace_api_connection_loss(sdata
);
2669 sdata
->u
.mgd
.connection_loss
= true;
2670 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2672 EXPORT_SYMBOL(ieee80211_connection_loss
);
2675 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data
*sdata
,
2678 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2680 sdata_assert_lock(sdata
);
2684 * we are not authenticated yet, the only timer that could be
2685 * running is the timeout for the authentication response which
2686 * which is not relevant anymore.
2688 del_timer_sync(&sdata
->u
.mgd
.timer
);
2689 sta_info_destroy_addr(sdata
, auth_data
->bss
->bssid
);
2691 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2692 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2693 sdata
->u
.mgd
.flags
= 0;
2694 mutex_lock(&sdata
->local
->mtx
);
2695 ieee80211_vif_release_channel(sdata
);
2696 mutex_unlock(&sdata
->local
->mtx
);
2699 cfg80211_put_bss(sdata
->local
->hw
.wiphy
, auth_data
->bss
);
2701 sdata
->u
.mgd
.auth_data
= NULL
;
2704 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data
*sdata
,
2705 bool assoc
, bool abandon
)
2707 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
2709 sdata_assert_lock(sdata
);
2713 * we are not associated yet, the only timer that could be
2714 * running is the timeout for the association response which
2715 * which is not relevant anymore.
2717 del_timer_sync(&sdata
->u
.mgd
.timer
);
2718 sta_info_destroy_addr(sdata
, assoc_data
->bss
->bssid
);
2720 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2721 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2722 sdata
->u
.mgd
.flags
= 0;
2723 sdata
->vif
.mu_mimo_owner
= false;
2725 mutex_lock(&sdata
->local
->mtx
);
2726 ieee80211_vif_release_channel(sdata
);
2727 mutex_unlock(&sdata
->local
->mtx
);
2730 cfg80211_abandon_assoc(sdata
->dev
, assoc_data
->bss
);
2734 sdata
->u
.mgd
.assoc_data
= NULL
;
2737 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
2738 struct ieee80211_mgmt
*mgmt
, size_t len
)
2740 struct ieee80211_local
*local
= sdata
->local
;
2741 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2743 struct ieee802_11_elems elems
;
2746 pos
= mgmt
->u
.auth
.variable
;
2747 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2748 if (!elems
.challenge
)
2750 auth_data
->expected_transaction
= 4;
2751 drv_mgd_prepare_tx(sdata
->local
, sdata
, 0);
2752 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
2753 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2754 IEEE80211_TX_INTFL_MLME_CONN_TX
;
2755 ieee80211_send_auth(sdata
, 3, auth_data
->algorithm
, 0,
2756 elems
.challenge
- 2, elems
.challenge_len
+ 2,
2757 auth_data
->bss
->bssid
, auth_data
->bss
->bssid
,
2758 auth_data
->key
, auth_data
->key_len
,
2759 auth_data
->key_idx
, tx_flags
);
2762 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
2763 struct ieee80211_mgmt
*mgmt
, size_t len
)
2765 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2767 u16 auth_alg
, auth_transaction
, status_code
;
2768 struct sta_info
*sta
;
2769 struct ieee80211_event event
= {
2771 .u
.mlme
.data
= AUTH_EVENT
,
2774 sdata_assert_lock(sdata
);
2779 if (!ifmgd
->auth_data
|| ifmgd
->auth_data
->done
)
2782 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
2784 if (!ether_addr_equal(bssid
, mgmt
->bssid
))
2787 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
2788 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
2789 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
2791 if (auth_alg
!= ifmgd
->auth_data
->algorithm
||
2792 auth_transaction
!= ifmgd
->auth_data
->expected_transaction
) {
2793 sdata_info(sdata
, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2794 mgmt
->sa
, auth_alg
, ifmgd
->auth_data
->algorithm
,
2796 ifmgd
->auth_data
->expected_transaction
);
2800 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2801 sdata_info(sdata
, "%pM denied authentication (status %d)\n",
2802 mgmt
->sa
, status_code
);
2803 ieee80211_destroy_auth_data(sdata
, false);
2804 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2805 event
.u
.mlme
.status
= MLME_DENIED
;
2806 event
.u
.mlme
.reason
= status_code
;
2807 drv_event_callback(sdata
->local
, sdata
, &event
);
2811 switch (ifmgd
->auth_data
->algorithm
) {
2812 case WLAN_AUTH_OPEN
:
2813 case WLAN_AUTH_LEAP
:
2816 case WLAN_AUTH_FILS_SK
:
2817 case WLAN_AUTH_FILS_SK_PFS
:
2818 case WLAN_AUTH_FILS_PK
:
2820 case WLAN_AUTH_SHARED_KEY
:
2821 if (ifmgd
->auth_data
->expected_transaction
!= 4) {
2822 ieee80211_auth_challenge(sdata
, mgmt
, len
);
2823 /* need another frame */
2828 WARN_ONCE(1, "invalid auth alg %d",
2829 ifmgd
->auth_data
->algorithm
);
2833 event
.u
.mlme
.status
= MLME_SUCCESS
;
2834 drv_event_callback(sdata
->local
, sdata
, &event
);
2835 sdata_info(sdata
, "authenticated\n");
2836 ifmgd
->auth_data
->done
= true;
2837 ifmgd
->auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_WAIT_ASSOC
;
2838 ifmgd
->auth_data
->timeout_started
= true;
2839 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2841 if (ifmgd
->auth_data
->algorithm
== WLAN_AUTH_SAE
&&
2842 ifmgd
->auth_data
->expected_transaction
!= 2) {
2844 * Report auth frame to user space for processing since another
2845 * round of Authentication frames is still needed.
2847 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2851 /* move station state to auth */
2852 mutex_lock(&sdata
->local
->sta_mtx
);
2853 sta
= sta_info_get(sdata
, bssid
);
2855 WARN_ONCE(1, "%s: STA %pM not found", sdata
->name
, bssid
);
2858 if (sta_info_move_state(sta
, IEEE80211_STA_AUTH
)) {
2859 sdata_info(sdata
, "failed moving %pM to auth\n", bssid
);
2862 mutex_unlock(&sdata
->local
->sta_mtx
);
2864 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2867 mutex_unlock(&sdata
->local
->sta_mtx
);
2868 /* ignore frame -- wait for timeout */
2871 #define case_WLAN(type) \
2872 case WLAN_REASON_##type: return #type
2874 static const char *ieee80211_get_reason_code_string(u16 reason_code
)
2876 switch (reason_code
) {
2877 case_WLAN(UNSPECIFIED
);
2878 case_WLAN(PREV_AUTH_NOT_VALID
);
2879 case_WLAN(DEAUTH_LEAVING
);
2880 case_WLAN(DISASSOC_DUE_TO_INACTIVITY
);
2881 case_WLAN(DISASSOC_AP_BUSY
);
2882 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA
);
2883 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA
);
2884 case_WLAN(DISASSOC_STA_HAS_LEFT
);
2885 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH
);
2886 case_WLAN(DISASSOC_BAD_POWER
);
2887 case_WLAN(DISASSOC_BAD_SUPP_CHAN
);
2888 case_WLAN(INVALID_IE
);
2889 case_WLAN(MIC_FAILURE
);
2890 case_WLAN(4WAY_HANDSHAKE_TIMEOUT
);
2891 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT
);
2892 case_WLAN(IE_DIFFERENT
);
2893 case_WLAN(INVALID_GROUP_CIPHER
);
2894 case_WLAN(INVALID_PAIRWISE_CIPHER
);
2895 case_WLAN(INVALID_AKMP
);
2896 case_WLAN(UNSUPP_RSN_VERSION
);
2897 case_WLAN(INVALID_RSN_IE_CAP
);
2898 case_WLAN(IEEE8021X_FAILED
);
2899 case_WLAN(CIPHER_SUITE_REJECTED
);
2900 case_WLAN(DISASSOC_UNSPECIFIED_QOS
);
2901 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH
);
2902 case_WLAN(DISASSOC_LOW_ACK
);
2903 case_WLAN(DISASSOC_QAP_EXCEED_TXOP
);
2904 case_WLAN(QSTA_LEAVE_QBSS
);
2905 case_WLAN(QSTA_NOT_USE
);
2906 case_WLAN(QSTA_REQUIRE_SETUP
);
2907 case_WLAN(QSTA_TIMEOUT
);
2908 case_WLAN(QSTA_CIPHER_NOT_SUPP
);
2909 case_WLAN(MESH_PEER_CANCELED
);
2910 case_WLAN(MESH_MAX_PEERS
);
2911 case_WLAN(MESH_CONFIG
);
2912 case_WLAN(MESH_CLOSE
);
2913 case_WLAN(MESH_MAX_RETRIES
);
2914 case_WLAN(MESH_CONFIRM_TIMEOUT
);
2915 case_WLAN(MESH_INVALID_GTK
);
2916 case_WLAN(MESH_INCONSISTENT_PARAM
);
2917 case_WLAN(MESH_INVALID_SECURITY
);
2918 case_WLAN(MESH_PATH_ERROR
);
2919 case_WLAN(MESH_PATH_NOFORWARD
);
2920 case_WLAN(MESH_PATH_DEST_UNREACHABLE
);
2921 case_WLAN(MAC_EXISTS_IN_MBSS
);
2922 case_WLAN(MESH_CHAN_REGULATORY
);
2923 case_WLAN(MESH_CHAN
);
2924 default: return "<unknown>";
2928 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
2929 struct ieee80211_mgmt
*mgmt
, size_t len
)
2931 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2932 u16 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
2934 sdata_assert_lock(sdata
);
2939 if (ifmgd
->associated
&&
2940 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
)) {
2941 const u8
*bssid
= ifmgd
->associated
->bssid
;
2943 sdata_info(sdata
, "deauthenticated from %pM (Reason: %u=%s)\n",
2945 ieee80211_get_reason_code_string(reason_code
));
2947 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2949 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false,
2954 if (ifmgd
->assoc_data
&&
2955 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
2956 const u8
*bssid
= ifmgd
->assoc_data
->bss
->bssid
;
2959 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2961 ieee80211_get_reason_code_string(reason_code
));
2963 ieee80211_destroy_assoc_data(sdata
, false, true);
2965 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2971 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
2972 struct ieee80211_mgmt
*mgmt
, size_t len
)
2974 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2977 sdata_assert_lock(sdata
);
2982 if (!ifmgd
->associated
||
2983 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2986 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
2988 sdata_info(sdata
, "disassociated from %pM (Reason: %u=%s)\n",
2989 mgmt
->sa
, reason_code
,
2990 ieee80211_get_reason_code_string(reason_code
));
2992 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2994 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false, reason_code
);
2997 static void ieee80211_get_rates(struct ieee80211_supported_band
*sband
,
2998 u8
*supp_rates
, unsigned int supp_rates_len
,
2999 u32
*rates
, u32
*basic_rates
,
3000 bool *have_higher_than_11mbit
,
3001 int *min_rate
, int *min_rate_index
,
3006 for (i
= 0; i
< supp_rates_len
; i
++) {
3007 int rate
= supp_rates
[i
] & 0x7f;
3008 bool is_basic
= !!(supp_rates
[i
] & 0x80);
3010 if ((rate
* 5 * (1 << shift
)) > 110)
3011 *have_higher_than_11mbit
= true;
3014 * Skip HT and VHT BSS membership selectors since they're not
3017 * Note: Even though the membership selector and the basic
3018 * rate flag share the same bit, they are not exactly
3021 if (supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
) ||
3022 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
))
3025 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
3026 struct ieee80211_rate
*br
;
3029 br
= &sband
->bitrates
[j
];
3031 brate
= DIV_ROUND_UP(br
->bitrate
, (1 << shift
) * 5);
3032 if (brate
== rate
) {
3035 *basic_rates
|= BIT(j
);
3036 if ((rate
* 5) < *min_rate
) {
3037 *min_rate
= rate
* 5;
3038 *min_rate_index
= j
;
3046 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data
*sdata
,
3047 struct cfg80211_bss
*cbss
,
3048 struct ieee80211_mgmt
*mgmt
, size_t len
)
3050 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3051 struct ieee80211_local
*local
= sdata
->local
;
3052 struct ieee80211_supported_band
*sband
;
3053 struct sta_info
*sta
;
3055 u16 capab_info
, aid
;
3056 struct ieee802_11_elems elems
;
3057 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3058 const struct cfg80211_bss_ies
*bss_ies
= NULL
;
3059 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3064 /* AssocResp and ReassocResp have identical structure */
3066 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3067 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3070 * The 5 MSB of the AID field are reserved
3071 * (802.11-2016 9.4.1.8 AID field)
3075 ifmgd
->broken_ap
= false;
3077 if (aid
== 0 || aid
> IEEE80211_MAX_AID
) {
3078 sdata_info(sdata
, "invalid AID value %d (out of range), turn off PS\n",
3081 ifmgd
->broken_ap
= true;
3084 pos
= mgmt
->u
.assoc_resp
.variable
;
3085 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
3087 if (!elems
.supp_rates
) {
3088 sdata_info(sdata
, "no SuppRates element in AssocResp\n");
3093 ifmgd
->tdls_chan_switch_prohibited
=
3094 elems
.ext_capab
&& elems
.ext_capab_len
>= 5 &&
3095 (elems
.ext_capab
[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED
);
3098 * Some APs are erroneously not including some information in their
3099 * (re)association response frames. Try to recover by using the data
3100 * from the beacon or probe response. This seems to afflict mobile
3101 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3102 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3104 if ((assoc_data
->wmm
&& !elems
.wmm_param
) ||
3105 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3106 (!elems
.ht_cap_elem
|| !elems
.ht_operation
)) ||
3107 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3108 (!elems
.vht_cap_elem
|| !elems
.vht_operation
))) {
3109 const struct cfg80211_bss_ies
*ies
;
3110 struct ieee802_11_elems bss_elems
;
3113 ies
= rcu_dereference(cbss
->ies
);
3115 bss_ies
= kmemdup(ies
, sizeof(*ies
) + ies
->len
,
3121 ieee802_11_parse_elems(bss_ies
->data
, bss_ies
->len
,
3123 if (assoc_data
->wmm
&&
3124 !elems
.wmm_param
&& bss_elems
.wmm_param
) {
3125 elems
.wmm_param
= bss_elems
.wmm_param
;
3127 "AP bug: WMM param missing from AssocResp\n");
3131 * Also check if we requested HT/VHT, otherwise the AP doesn't
3132 * have to include the IEs in the (re)association response.
3134 if (!elems
.ht_cap_elem
&& bss_elems
.ht_cap_elem
&&
3135 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
3136 elems
.ht_cap_elem
= bss_elems
.ht_cap_elem
;
3138 "AP bug: HT capability missing from AssocResp\n");
3140 if (!elems
.ht_operation
&& bss_elems
.ht_operation
&&
3141 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
3142 elems
.ht_operation
= bss_elems
.ht_operation
;
3144 "AP bug: HT operation missing from AssocResp\n");
3146 if (!elems
.vht_cap_elem
&& bss_elems
.vht_cap_elem
&&
3147 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3148 elems
.vht_cap_elem
= bss_elems
.vht_cap_elem
;
3150 "AP bug: VHT capa missing from AssocResp\n");
3152 if (!elems
.vht_operation
&& bss_elems
.vht_operation
&&
3153 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3154 elems
.vht_operation
= bss_elems
.vht_operation
;
3156 "AP bug: VHT operation missing from AssocResp\n");
3161 * We previously checked these in the beacon/probe response, so
3162 * they should be present here. This is just a safety net.
3164 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3165 (!elems
.wmm_param
|| !elems
.ht_cap_elem
|| !elems
.ht_operation
)) {
3167 "HT AP is missing WMM params or HT capability/operation\n");
3172 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3173 (!elems
.vht_cap_elem
|| !elems
.vht_operation
)) {
3175 "VHT AP is missing VHT capability/operation\n");
3180 mutex_lock(&sdata
->local
->sta_mtx
);
3182 * station info was already allocated and inserted before
3183 * the association and should be available to us
3185 sta
= sta_info_get(sdata
, cbss
->bssid
);
3186 if (WARN_ON(!sta
)) {
3187 mutex_unlock(&sdata
->local
->sta_mtx
);
3192 sband
= ieee80211_get_sband(sdata
);
3194 mutex_unlock(&sdata
->local
->sta_mtx
);
3200 * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
3201 * HE as disabled. If on the 5GHz band, make sure it supports VHT.
3203 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
||
3204 (sband
->band
== NL80211_BAND_5GHZ
&&
3205 ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) ||
3206 (!elems
.he_cap
&& !elems
.he_operation
))
3207 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
3209 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
3210 (!elems
.he_cap
|| !elems
.he_operation
)) {
3211 mutex_unlock(&sdata
->local
->sta_mtx
);
3213 "HE AP is missing HE capability/operation\n");
3218 /* Set up internal HT/VHT capabilities */
3219 if (elems
.ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
3220 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
3221 elems
.ht_cap_elem
, sta
);
3223 if (elems
.vht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
3224 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
3225 elems
.vht_cap_elem
, sta
);
3227 if (elems
.he_operation
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
3229 ieee80211_he_cap_ie_to_sta_he_cap(sdata
, sband
,
3234 bss_conf
->he_support
= sta
->sta
.he_cap
.has_he
;
3236 bss_conf
->he_support
= false;
3239 if (bss_conf
->he_support
) {
3240 u32 he_oper_params
=
3241 le32_to_cpu(elems
.he_operation
->he_oper_params
);
3243 bss_conf
->bss_color
= he_oper_params
&
3244 IEEE80211_HE_OPERATION_BSS_COLOR_MASK
;
3245 bss_conf
->htc_trig_based_pkt_ext
=
3247 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK
) <<
3248 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_OFFSET
;
3249 bss_conf
->frame_time_rts_th
=
3251 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK
) <<
3252 IEEE80211_HE_OPERATION_RTS_THRESHOLD_OFFSET
;
3254 bss_conf
->multi_sta_back_32bit
=
3255 sta
->sta
.he_cap
.he_cap_elem
.mac_cap_info
[2] &
3256 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP
;
3258 bss_conf
->ack_enabled
=
3259 sta
->sta
.he_cap
.he_cap_elem
.mac_cap_info
[2] &
3260 IEEE80211_HE_MAC_CAP2_ACK_EN
;
3262 bss_conf
->uora_exists
= !!elems
.uora_element
;
3263 if (elems
.uora_element
)
3264 bss_conf
->uora_ocw_range
= elems
.uora_element
[0];
3266 /* TODO: OPEN: what happens if BSS color disable is set? */
3270 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3271 * in their association response, so ignore that data for our own
3272 * configuration. If it changed since the last beacon, we'll get the
3273 * next beacon and update then.
3277 * If an operating mode notification IE is present, override the
3278 * NSS calculation (that would be done in rate_control_rate_init())
3279 * and use the # of streams from that element.
3281 if (elems
.opmode_notif
&&
3282 !(*elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)) {
3285 nss
= *elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
3286 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
3288 sta
->sta
.rx_nss
= nss
;
3291 rate_control_rate_init(sta
);
3293 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
) {
3294 set_sta_flag(sta
, WLAN_STA_MFP
);
3295 sta
->sta
.mfp
= true;
3297 sta
->sta
.mfp
= false;
3300 sta
->sta
.wme
= elems
.wmm_param
&& local
->hw
.queues
>= IEEE80211_NUM_ACS
;
3302 err
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
3303 if (!err
&& !(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
3304 err
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
3307 "failed to move station %pM to desired state\n",
3309 WARN_ON(__sta_info_destroy(sta
));
3310 mutex_unlock(&sdata
->local
->sta_mtx
);
3315 mutex_unlock(&sdata
->local
->sta_mtx
);
3318 * Always handle WMM once after association regardless
3319 * of the first value the AP uses. Setting -1 here has
3320 * that effect because the AP values is an unsigned
3323 ifmgd
->wmm_last_param_set
= -1;
3325 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
3326 ieee80211_set_wmm_default(sdata
, false, false);
3327 } else if (!ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3328 elems
.wmm_param_len
,
3329 elems
.mu_edca_param_set
)) {
3330 /* still enable QoS since we might have HT/VHT */
3331 ieee80211_set_wmm_default(sdata
, false, true);
3332 /* set the disable-WMM flag in this case to disable
3333 * tracking WMM parameter changes in the beacon if
3334 * the parameters weren't actually valid. Doing so
3335 * avoids changing parameters very strangely when
3336 * the AP is going back and forth between valid and
3337 * invalid parameters.
3339 ifmgd
->flags
|= IEEE80211_STA_DISABLE_WMM
;
3341 changed
|= BSS_CHANGED_QOS
;
3343 if (elems
.max_idle_period_ie
) {
3344 bss_conf
->max_idle_period
=
3345 le16_to_cpu(elems
.max_idle_period_ie
->max_idle_period
);
3346 bss_conf
->protected_keep_alive
=
3347 !!(elems
.max_idle_period_ie
->idle_options
&
3348 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE
);
3349 changed
|= BSS_CHANGED_KEEP_ALIVE
;
3351 bss_conf
->max_idle_period
= 0;
3352 bss_conf
->protected_keep_alive
= false;
3355 /* set AID and assoc capability,
3356 * ieee80211_set_associated() will tell the driver */
3357 bss_conf
->aid
= aid
;
3358 bss_conf
->assoc_capability
= capab_info
;
3359 ieee80211_set_associated(sdata
, cbss
, changed
);
3362 * If we're using 4-addr mode, let the AP know that we're
3363 * doing so, so that it can create the STA VLAN on its side
3365 if (ifmgd
->use_4addr
)
3366 ieee80211_send_4addr_nullfunc(local
, sdata
);
3369 * Start timer to probe the connection to the AP now.
3370 * Also start the timer that will detect beacon loss.
3372 ieee80211_sta_rx_notify(sdata
, (struct ieee80211_hdr
*)mgmt
);
3373 ieee80211_sta_reset_beacon_monitor(sdata
);
3381 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
3382 struct ieee80211_mgmt
*mgmt
,
3385 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3386 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3387 u16 capab_info
, status_code
, aid
;
3388 struct ieee802_11_elems elems
;
3389 int ac
, uapsd_queues
= -1;
3392 struct cfg80211_bss
*bss
;
3393 struct ieee80211_event event
= {
3395 .u
.mlme
.data
= ASSOC_EVENT
,
3398 sdata_assert_lock(sdata
);
3402 if (!ether_addr_equal(assoc_data
->bss
->bssid
, mgmt
->bssid
))
3406 * AssocResp and ReassocResp have identical structure, so process both
3407 * of them in this function.
3413 reassoc
= ieee80211_is_reassoc_resp(mgmt
->frame_control
);
3414 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3415 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
3416 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3419 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3420 reassoc
? "Rea" : "A", mgmt
->sa
,
3421 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
3423 if (assoc_data
->fils_kek_len
&&
3424 fils_decrypt_assoc_resp(sdata
, (u8
*)mgmt
, &len
, assoc_data
) < 0)
3427 pos
= mgmt
->u
.assoc_resp
.variable
;
3428 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
3430 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
3431 elems
.timeout_int
&&
3432 elems
.timeout_int
->type
== WLAN_TIMEOUT_ASSOC_COMEBACK
) {
3434 tu
= le32_to_cpu(elems
.timeout_int
->value
);
3435 ms
= tu
* 1024 / 1000;
3437 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3439 assoc_data
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
3440 assoc_data
->timeout_started
= true;
3441 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
3442 run_again(sdata
, assoc_data
->timeout
);
3446 bss
= assoc_data
->bss
;
3448 if (status_code
!= WLAN_STATUS_SUCCESS
) {
3449 sdata_info(sdata
, "%pM denied association (code=%d)\n",
3450 mgmt
->sa
, status_code
);
3451 ieee80211_destroy_assoc_data(sdata
, false, false);
3452 event
.u
.mlme
.status
= MLME_DENIED
;
3453 event
.u
.mlme
.reason
= status_code
;
3454 drv_event_callback(sdata
->local
, sdata
, &event
);
3456 if (!ieee80211_assoc_success(sdata
, bss
, mgmt
, len
)) {
3457 /* oops -- internal error -- send timeout for now */
3458 ieee80211_destroy_assoc_data(sdata
, false, false);
3459 cfg80211_assoc_timeout(sdata
->dev
, bss
);
3462 event
.u
.mlme
.status
= MLME_SUCCESS
;
3463 drv_event_callback(sdata
->local
, sdata
, &event
);
3464 sdata_info(sdata
, "associated\n");
3467 * destroy assoc_data afterwards, as otherwise an idle
3468 * recalc after assoc_data is NULL but before associated
3469 * is set can cause the interface to go idle
3471 ieee80211_destroy_assoc_data(sdata
, true, false);
3473 /* get uapsd queues configuration */
3475 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
3476 if (sdata
->tx_conf
[ac
].uapsd
)
3477 uapsd_queues
|= ieee80211_ac_to_qos_mask
[ac
];
3480 cfg80211_rx_assoc_resp(sdata
->dev
, bss
, (u8
*)mgmt
, len
, uapsd_queues
);
3483 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
3484 struct ieee80211_mgmt
*mgmt
, size_t len
,
3485 struct ieee80211_rx_status
*rx_status
,
3486 struct ieee802_11_elems
*elems
)
3488 struct ieee80211_local
*local
= sdata
->local
;
3489 struct ieee80211_bss
*bss
;
3490 struct ieee80211_channel
*channel
;
3492 sdata_assert_lock(sdata
);
3494 channel
= ieee80211_get_channel(local
->hw
.wiphy
, rx_status
->freq
);
3498 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
3501 sdata
->vif
.bss_conf
.beacon_rate
= bss
->beacon_rate
;
3502 ieee80211_rx_bss_put(local
, bss
);
3507 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
3508 struct sk_buff
*skb
)
3510 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
3511 struct ieee80211_if_managed
*ifmgd
;
3512 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
3513 size_t baselen
, len
= skb
->len
;
3514 struct ieee802_11_elems elems
;
3516 ifmgd
= &sdata
->u
.mgd
;
3518 sdata_assert_lock(sdata
);
3520 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
3521 return; /* ignore ProbeResp to foreign address */
3523 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
3527 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
3530 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3532 if (ifmgd
->associated
&&
3533 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3534 ieee80211_reset_ap_probe(sdata
);
3538 * This is the canonical list of information elements we care about,
3539 * the filter code also gives us all changes to the Microsoft OUI
3540 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3541 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3542 * changes to requested client power.
3544 * We implement beacon filtering in software since that means we can
3545 * avoid processing the frame here and in cfg80211, and userspace
3546 * will not be able to tell whether the hardware supports it or not.
3548 * XXX: This list needs to be dynamic -- userspace needs to be able to
3549 * add items it requires. It also needs to be able to tell us to
3550 * look out for other vendor IEs.
3552 static const u64 care_about_ies
=
3553 (1ULL << WLAN_EID_COUNTRY
) |
3554 (1ULL << WLAN_EID_ERP_INFO
) |
3555 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
3556 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
3557 (1ULL << WLAN_EID_HT_CAPABILITY
) |
3558 (1ULL << WLAN_EID_HT_OPERATION
) |
3559 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN
);
3561 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data
*sdata
,
3562 struct ieee80211_if_managed
*ifmgd
,
3563 struct ieee80211_bss_conf
*bss_conf
,
3564 struct ieee80211_local
*local
,
3565 struct ieee80211_rx_status
*rx_status
)
3567 /* Track average RSSI from the Beacon frames of the current AP */
3569 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
3570 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
3571 ewma_beacon_signal_init(&ifmgd
->ave_beacon_signal
);
3572 ifmgd
->last_cqm_event_signal
= 0;
3573 ifmgd
->count_beacon_signal
= 1;
3574 ifmgd
->last_ave_beacon_signal
= 0;
3576 ifmgd
->count_beacon_signal
++;
3579 ewma_beacon_signal_add(&ifmgd
->ave_beacon_signal
, -rx_status
->signal
);
3581 if (ifmgd
->rssi_min_thold
!= ifmgd
->rssi_max_thold
&&
3582 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3583 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3584 int last_sig
= ifmgd
->last_ave_beacon_signal
;
3585 struct ieee80211_event event
= {
3590 * if signal crosses either of the boundaries, invoke callback
3591 * with appropriate parameters
3593 if (sig
> ifmgd
->rssi_max_thold
&&
3594 (last_sig
<= ifmgd
->rssi_min_thold
|| last_sig
== 0)) {
3595 ifmgd
->last_ave_beacon_signal
= sig
;
3596 event
.u
.rssi
.data
= RSSI_EVENT_HIGH
;
3597 drv_event_callback(local
, sdata
, &event
);
3598 } else if (sig
< ifmgd
->rssi_min_thold
&&
3599 (last_sig
>= ifmgd
->rssi_max_thold
||
3601 ifmgd
->last_ave_beacon_signal
= sig
;
3602 event
.u
.rssi
.data
= RSSI_EVENT_LOW
;
3603 drv_event_callback(local
, sdata
, &event
);
3607 if (bss_conf
->cqm_rssi_thold
&&
3608 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
3609 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)) {
3610 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3611 int last_event
= ifmgd
->last_cqm_event_signal
;
3612 int thold
= bss_conf
->cqm_rssi_thold
;
3613 int hyst
= bss_conf
->cqm_rssi_hyst
;
3616 (last_event
== 0 || sig
< last_event
- hyst
)) {
3617 ifmgd
->last_cqm_event_signal
= sig
;
3618 ieee80211_cqm_rssi_notify(
3620 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3622 } else if (sig
> thold
&&
3623 (last_event
== 0 || sig
> last_event
+ hyst
)) {
3624 ifmgd
->last_cqm_event_signal
= sig
;
3625 ieee80211_cqm_rssi_notify(
3627 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3632 if (bss_conf
->cqm_rssi_low
&&
3633 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3634 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3635 int last_event
= ifmgd
->last_cqm_event_signal
;
3636 int low
= bss_conf
->cqm_rssi_low
;
3637 int high
= bss_conf
->cqm_rssi_high
;
3640 (last_event
== 0 || last_event
>= low
)) {
3641 ifmgd
->last_cqm_event_signal
= sig
;
3642 ieee80211_cqm_rssi_notify(
3644 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3646 } else if (sig
> high
&&
3647 (last_event
== 0 || last_event
<= high
)) {
3648 ifmgd
->last_cqm_event_signal
= sig
;
3649 ieee80211_cqm_rssi_notify(
3651 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3657 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
3658 struct ieee80211_mgmt
*mgmt
, size_t len
,
3659 struct ieee80211_rx_status
*rx_status
)
3661 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3662 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3664 struct ieee802_11_elems elems
;
3665 struct ieee80211_local
*local
= sdata
->local
;
3666 struct ieee80211_chanctx_conf
*chanctx_conf
;
3667 struct ieee80211_channel
*chan
;
3668 struct sta_info
*sta
;
3674 u8 deauth_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3676 sdata_assert_lock(sdata
);
3678 /* Process beacon from the current BSS */
3679 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
3684 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3685 if (!chanctx_conf
) {
3690 if (rx_status
->freq
!= chanctx_conf
->def
.chan
->center_freq
) {
3694 chan
= chanctx_conf
->def
.chan
;
3697 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->need_beacon
&&
3698 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
3699 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
3700 len
- baselen
, false, &elems
);
3702 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3703 if (elems
.tim
&& !elems
.parse_error
) {
3704 const struct ieee80211_tim_ie
*tim_ie
= elems
.tim
;
3705 ifmgd
->dtim_period
= tim_ie
->dtim_period
;
3707 ifmgd
->have_beacon
= true;
3708 ifmgd
->assoc_data
->need_beacon
= false;
3709 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3710 sdata
->vif
.bss_conf
.sync_tsf
=
3711 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3712 sdata
->vif
.bss_conf
.sync_device_ts
=
3713 rx_status
->device_timestamp
;
3715 sdata
->vif
.bss_conf
.sync_dtim_count
=
3716 elems
.tim
->dtim_count
;
3718 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3720 /* continue assoc process */
3721 ifmgd
->assoc_data
->timeout
= jiffies
;
3722 ifmgd
->assoc_data
->timeout_started
= true;
3723 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3727 if (!ifmgd
->associated
||
3728 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3730 bssid
= ifmgd
->associated
->bssid
;
3732 if (!(rx_status
->flag
& RX_FLAG_NO_SIGNAL_VAL
))
3733 ieee80211_handle_beacon_sig(sdata
, ifmgd
, bss_conf
,
3736 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
) {
3737 mlme_dbg_ratelimited(sdata
,
3738 "cancelling AP probe due to a received beacon\n");
3739 ieee80211_reset_ap_probe(sdata
);
3743 * Push the beacon loss detection into the future since
3744 * we are processing a beacon from the AP just now.
3746 ieee80211_sta_reset_beacon_monitor(sdata
);
3748 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
3749 ncrc
= ieee802_11_parse_elems_crc(mgmt
->u
.beacon
.variable
,
3750 len
- baselen
, false, &elems
,
3751 care_about_ies
, ncrc
);
3753 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
3754 ieee80211_check_tim(elems
.tim
, elems
.tim_len
, ifmgd
->aid
)) {
3755 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
3756 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
3757 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
3758 ieee80211_hw_config(local
,
3759 IEEE80211_CONF_CHANGE_PS
);
3761 ieee80211_send_nullfunc(local
, sdata
, false);
3762 } else if (!local
->pspolling
&& sdata
->u
.mgd
.powersave
) {
3763 local
->pspolling
= true;
3766 * Here is assumed that the driver will be
3767 * able to send ps-poll frame and receive a
3768 * response even though power save mode is
3769 * enabled, but some drivers might require
3770 * to disable power save here. This needs
3771 * to be investigated.
3773 ieee80211_send_pspoll(local
, sdata
);
3777 if (sdata
->vif
.p2p
||
3778 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
3779 struct ieee80211_p2p_noa_attr noa
= {};
3782 ret
= cfg80211_get_p2p_attr(mgmt
->u
.beacon
.variable
,
3784 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
3785 (u8
*) &noa
, sizeof(noa
));
3787 if (sdata
->u
.mgd
.p2p_noa_index
!= noa
.index
) {
3788 /* valid noa_attr and index changed */
3789 sdata
->u
.mgd
.p2p_noa_index
= noa
.index
;
3790 memcpy(&bss_conf
->p2p_noa_attr
, &noa
, sizeof(noa
));
3791 changed
|= BSS_CHANGED_P2P_PS
;
3793 * make sure we update all information, the CRC
3794 * mechanism doesn't look at P2P attributes.
3796 ifmgd
->beacon_crc_valid
= false;
3798 } else if (sdata
->u
.mgd
.p2p_noa_index
!= -1) {
3799 /* noa_attr not found and we had valid noa_attr before */
3800 sdata
->u
.mgd
.p2p_noa_index
= -1;
3801 memset(&bss_conf
->p2p_noa_attr
, 0, sizeof(bss_conf
->p2p_noa_attr
));
3802 changed
|= BSS_CHANGED_P2P_PS
;
3803 ifmgd
->beacon_crc_valid
= false;
3807 if (ifmgd
->csa_waiting_bcn
)
3808 ieee80211_chswitch_post_beacon(sdata
);
3811 * Update beacon timing and dtim count on every beacon appearance. This
3812 * will allow the driver to use the most updated values. Do it before
3813 * comparing this one with last received beacon.
3814 * IMPORTANT: These parameters would possibly be out of sync by the time
3815 * the driver will use them. The synchronized view is currently
3816 * guaranteed only in certain callbacks.
3818 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3819 sdata
->vif
.bss_conf
.sync_tsf
=
3820 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3821 sdata
->vif
.bss_conf
.sync_device_ts
=
3822 rx_status
->device_timestamp
;
3824 sdata
->vif
.bss_conf
.sync_dtim_count
=
3825 elems
.tim
->dtim_count
;
3827 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3830 if (ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
)
3832 ifmgd
->beacon_crc
= ncrc
;
3833 ifmgd
->beacon_crc_valid
= true;
3835 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3837 ieee80211_sta_process_chanswitch(sdata
, rx_status
->mactime
,
3838 rx_status
->device_timestamp
,
3841 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) &&
3842 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3843 elems
.wmm_param_len
,
3844 elems
.mu_edca_param_set
))
3845 changed
|= BSS_CHANGED_QOS
;
3848 * If we haven't had a beacon before, tell the driver about the
3849 * DTIM period (and beacon timing if desired) now.
3851 if (!ifmgd
->have_beacon
) {
3852 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3854 bss_conf
->dtim_period
= elems
.tim
->dtim_period
?: 1;
3856 bss_conf
->dtim_period
= 1;
3858 changed
|= BSS_CHANGED_BEACON_INFO
;
3859 ifmgd
->have_beacon
= true;
3861 mutex_lock(&local
->iflist_mtx
);
3862 ieee80211_recalc_ps(local
);
3863 mutex_unlock(&local
->iflist_mtx
);
3865 ieee80211_recalc_ps_vif(sdata
);
3868 if (elems
.erp_info
) {
3870 erp_value
= elems
.erp_info
[0];
3874 changed
|= ieee80211_handle_bss_capability(sdata
,
3875 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
3876 erp_valid
, erp_value
);
3878 mutex_lock(&local
->sta_mtx
);
3879 sta
= sta_info_get(sdata
, bssid
);
3881 if (ieee80211_config_bw(sdata
, sta
,
3882 elems
.ht_cap_elem
, elems
.ht_operation
,
3883 elems
.vht_operation
, elems
.he_operation
,
3885 mutex_unlock(&local
->sta_mtx
);
3887 "failed to follow AP %pM bandwidth change, disconnect\n",
3889 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
3890 WLAN_REASON_DEAUTH_LEAVING
,
3892 ieee80211_report_disconnect(sdata
, deauth_buf
,
3893 sizeof(deauth_buf
), true,
3894 WLAN_REASON_DEAUTH_LEAVING
);
3898 if (sta
&& elems
.opmode_notif
)
3899 ieee80211_vht_handle_opmode(sdata
, sta
, *elems
.opmode_notif
,
3901 mutex_unlock(&local
->sta_mtx
);
3903 changed
|= ieee80211_handle_pwr_constr(sdata
, chan
, mgmt
,
3905 elems
.country_elem_len
,
3906 elems
.pwr_constr_elem
,
3907 elems
.cisco_dtpc_elem
);
3909 ieee80211_bss_info_change_notify(sdata
, changed
);
3912 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
3913 struct sk_buff
*skb
)
3915 struct ieee80211_rx_status
*rx_status
;
3916 struct ieee80211_mgmt
*mgmt
;
3918 struct ieee802_11_elems elems
;
3921 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3922 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3923 fc
= le16_to_cpu(mgmt
->frame_control
);
3927 switch (fc
& IEEE80211_FCTL_STYPE
) {
3928 case IEEE80211_STYPE_BEACON
:
3929 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3931 case IEEE80211_STYPE_PROBE_RESP
:
3932 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
3934 case IEEE80211_STYPE_AUTH
:
3935 ieee80211_rx_mgmt_auth(sdata
, mgmt
, skb
->len
);
3937 case IEEE80211_STYPE_DEAUTH
:
3938 ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
3940 case IEEE80211_STYPE_DISASSOC
:
3941 ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
3943 case IEEE80211_STYPE_ASSOC_RESP
:
3944 case IEEE80211_STYPE_REASSOC_RESP
:
3945 ieee80211_rx_mgmt_assoc_resp(sdata
, mgmt
, skb
->len
);
3947 case IEEE80211_STYPE_ACTION
:
3948 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
) {
3949 ies_len
= skb
->len
-
3950 offsetof(struct ieee80211_mgmt
,
3951 u
.action
.u
.chan_switch
.variable
);
3956 ieee802_11_parse_elems(
3957 mgmt
->u
.action
.u
.chan_switch
.variable
,
3958 ies_len
, true, &elems
);
3960 if (elems
.parse_error
)
3963 ieee80211_sta_process_chanswitch(sdata
,
3965 rx_status
->device_timestamp
,
3967 } else if (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
) {
3968 ies_len
= skb
->len
-
3969 offsetof(struct ieee80211_mgmt
,
3970 u
.action
.u
.ext_chan_switch
.variable
);
3975 ieee802_11_parse_elems(
3976 mgmt
->u
.action
.u
.ext_chan_switch
.variable
,
3977 ies_len
, true, &elems
);
3979 if (elems
.parse_error
)
3982 /* for the handling code pretend this was also an IE */
3983 elems
.ext_chansw_ie
=
3984 &mgmt
->u
.action
.u
.ext_chan_switch
.data
;
3986 ieee80211_sta_process_chanswitch(sdata
,
3988 rx_status
->device_timestamp
,
3993 sdata_unlock(sdata
);
3996 static void ieee80211_sta_timer(struct timer_list
*t
)
3998 struct ieee80211_sub_if_data
*sdata
=
3999 from_timer(sdata
, t
, u
.mgd
.timer
);
4001 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
4004 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
4005 u8
*bssid
, u8 reason
, bool tx
)
4007 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4009 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
, reason
,
4012 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
4016 static int ieee80211_auth(struct ieee80211_sub_if_data
*sdata
)
4018 struct ieee80211_local
*local
= sdata
->local
;
4019 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4020 struct ieee80211_mgd_auth_data
*auth_data
= ifmgd
->auth_data
;
4024 u16 prepare_tx_duration
= 0;
4026 sdata_assert_lock(sdata
);
4028 if (WARN_ON_ONCE(!auth_data
))
4033 if (auth_data
->tries
> IEEE80211_AUTH_MAX_TRIES
) {
4034 sdata_info(sdata
, "authentication with %pM timed out\n",
4035 auth_data
->bss
->bssid
);
4038 * Most likely AP is not in the range so remove the
4039 * bss struct for that AP.
4041 cfg80211_unlink_bss(local
->hw
.wiphy
, auth_data
->bss
);
4046 if (auth_data
->algorithm
== WLAN_AUTH_SAE
)
4047 prepare_tx_duration
=
4048 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE
);
4050 drv_mgd_prepare_tx(local
, sdata
, prepare_tx_duration
);
4052 sdata_info(sdata
, "send auth to %pM (try %d/%d)\n",
4053 auth_data
->bss
->bssid
, auth_data
->tries
,
4054 IEEE80211_AUTH_MAX_TRIES
);
4056 auth_data
->expected_transaction
= 2;
4058 if (auth_data
->algorithm
== WLAN_AUTH_SAE
) {
4059 trans
= auth_data
->sae_trans
;
4060 status
= auth_data
->sae_status
;
4061 auth_data
->expected_transaction
= trans
;
4064 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
4065 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
4066 IEEE80211_TX_INTFL_MLME_CONN_TX
;
4068 ieee80211_send_auth(sdata
, trans
, auth_data
->algorithm
, status
,
4069 auth_data
->data
, auth_data
->data_len
,
4070 auth_data
->bss
->bssid
,
4071 auth_data
->bss
->bssid
, NULL
, 0, 0,
4074 if (tx_flags
== 0) {
4075 if (auth_data
->algorithm
== WLAN_AUTH_SAE
)
4076 auth_data
->timeout
= jiffies
+
4077 IEEE80211_AUTH_TIMEOUT_SAE
;
4079 auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
4081 auth_data
->timeout
=
4082 round_jiffies_up(jiffies
+ IEEE80211_AUTH_TIMEOUT_LONG
);
4085 auth_data
->timeout_started
= true;
4086 run_again(sdata
, auth_data
->timeout
);
4091 static int ieee80211_do_assoc(struct ieee80211_sub_if_data
*sdata
)
4093 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
4094 struct ieee80211_local
*local
= sdata
->local
;
4096 sdata_assert_lock(sdata
);
4098 assoc_data
->tries
++;
4099 if (assoc_data
->tries
> IEEE80211_ASSOC_MAX_TRIES
) {
4100 sdata_info(sdata
, "association with %pM timed out\n",
4101 assoc_data
->bss
->bssid
);
4104 * Most likely AP is not in the range so remove the
4105 * bss struct for that AP.
4107 cfg80211_unlink_bss(local
->hw
.wiphy
, assoc_data
->bss
);
4112 sdata_info(sdata
, "associate with %pM (try %d/%d)\n",
4113 assoc_data
->bss
->bssid
, assoc_data
->tries
,
4114 IEEE80211_ASSOC_MAX_TRIES
);
4115 ieee80211_send_assoc(sdata
);
4117 if (!ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
4118 assoc_data
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
4119 assoc_data
->timeout_started
= true;
4120 run_again(sdata
, assoc_data
->timeout
);
4122 assoc_data
->timeout
=
4123 round_jiffies_up(jiffies
+
4124 IEEE80211_ASSOC_TIMEOUT_LONG
);
4125 assoc_data
->timeout_started
= true;
4126 run_again(sdata
, assoc_data
->timeout
);
4132 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data
*sdata
,
4133 __le16 fc
, bool acked
)
4135 struct ieee80211_local
*local
= sdata
->local
;
4137 sdata
->u
.mgd
.status_fc
= fc
;
4138 sdata
->u
.mgd
.status_acked
= acked
;
4139 sdata
->u
.mgd
.status_received
= true;
4141 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
4144 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
4146 struct ieee80211_local
*local
= sdata
->local
;
4147 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4151 if (ifmgd
->status_received
) {
4152 __le16 fc
= ifmgd
->status_fc
;
4153 bool status_acked
= ifmgd
->status_acked
;
4155 ifmgd
->status_received
= false;
4156 if (ifmgd
->auth_data
&& ieee80211_is_auth(fc
)) {
4158 if (ifmgd
->auth_data
->algorithm
==
4160 ifmgd
->auth_data
->timeout
=
4162 IEEE80211_AUTH_TIMEOUT_SAE
;
4164 ifmgd
->auth_data
->timeout
=
4166 IEEE80211_AUTH_TIMEOUT_SHORT
;
4167 run_again(sdata
, ifmgd
->auth_data
->timeout
);
4169 ifmgd
->auth_data
->timeout
= jiffies
- 1;
4171 ifmgd
->auth_data
->timeout_started
= true;
4172 } else if (ifmgd
->assoc_data
&&
4173 (ieee80211_is_assoc_req(fc
) ||
4174 ieee80211_is_reassoc_req(fc
))) {
4176 ifmgd
->assoc_data
->timeout
=
4177 jiffies
+ IEEE80211_ASSOC_TIMEOUT_SHORT
;
4178 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4180 ifmgd
->assoc_data
->timeout
= jiffies
- 1;
4182 ifmgd
->assoc_data
->timeout_started
= true;
4186 if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
&&
4187 time_after(jiffies
, ifmgd
->auth_data
->timeout
)) {
4188 if (ifmgd
->auth_data
->done
) {
4190 * ok ... we waited for assoc but userspace didn't,
4191 * so let's just kill the auth data
4193 ieee80211_destroy_auth_data(sdata
, false);
4194 } else if (ieee80211_auth(sdata
)) {
4196 struct ieee80211_event event
= {
4198 .u
.mlme
.data
= AUTH_EVENT
,
4199 .u
.mlme
.status
= MLME_TIMEOUT
,
4202 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
4204 ieee80211_destroy_auth_data(sdata
, false);
4206 cfg80211_auth_timeout(sdata
->dev
, bssid
);
4207 drv_event_callback(sdata
->local
, sdata
, &event
);
4209 } else if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
)
4210 run_again(sdata
, ifmgd
->auth_data
->timeout
);
4212 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
&&
4213 time_after(jiffies
, ifmgd
->assoc_data
->timeout
)) {
4214 if ((ifmgd
->assoc_data
->need_beacon
&& !ifmgd
->have_beacon
) ||
4215 ieee80211_do_assoc(sdata
)) {
4216 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
4217 struct ieee80211_event event
= {
4219 .u
.mlme
.data
= ASSOC_EVENT
,
4220 .u
.mlme
.status
= MLME_TIMEOUT
,
4223 ieee80211_destroy_assoc_data(sdata
, false, false);
4224 cfg80211_assoc_timeout(sdata
->dev
, bss
);
4225 drv_event_callback(sdata
->local
, sdata
, &event
);
4227 } else if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
)
4228 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4230 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
&&
4231 ifmgd
->associated
) {
4235 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4237 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
4238 max_tries
= max_nullfunc_tries
;
4240 max_tries
= max_probe_tries
;
4242 /* ACK received for nullfunc probing frame */
4243 if (!ifmgd
->probe_send_count
)
4244 ieee80211_reset_ap_probe(sdata
);
4245 else if (ifmgd
->nullfunc_failed
) {
4246 if (ifmgd
->probe_send_count
< max_tries
) {
4248 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4249 bssid
, ifmgd
->probe_send_count
,
4251 ieee80211_mgd_probe_ap_send(sdata
);
4254 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4256 ieee80211_sta_connection_lost(sdata
, bssid
,
4257 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
4260 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
4261 run_again(sdata
, ifmgd
->probe_timeout
);
4262 else if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
4264 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4265 bssid
, probe_wait_ms
);
4266 ieee80211_sta_connection_lost(sdata
, bssid
,
4267 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4268 } else if (ifmgd
->probe_send_count
< max_tries
) {
4270 "No probe response from AP %pM after %dms, try %d/%i\n",
4271 bssid
, probe_wait_ms
,
4272 ifmgd
->probe_send_count
, max_tries
);
4273 ieee80211_mgd_probe_ap_send(sdata
);
4276 * We actually lost the connection ... or did we?
4280 "No probe response from AP %pM after %dms, disconnecting.\n",
4281 bssid
, probe_wait_ms
);
4283 ieee80211_sta_connection_lost(sdata
, bssid
,
4284 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4288 sdata_unlock(sdata
);
4291 static void ieee80211_sta_bcn_mon_timer(struct timer_list
*t
)
4293 struct ieee80211_sub_if_data
*sdata
=
4294 from_timer(sdata
, t
, u
.mgd
.bcn_mon_timer
);
4295 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4297 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4300 sdata
->u
.mgd
.connection_loss
= false;
4301 ieee80211_queue_work(&sdata
->local
->hw
,
4302 &sdata
->u
.mgd
.beacon_connection_loss_work
);
4305 static void ieee80211_sta_conn_mon_timer(struct timer_list
*t
)
4307 struct ieee80211_sub_if_data
*sdata
=
4308 from_timer(sdata
, t
, u
.mgd
.conn_mon_timer
);
4309 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4310 struct ieee80211_local
*local
= sdata
->local
;
4312 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4315 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
4318 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
4320 struct ieee80211_sub_if_data
*sdata
=
4321 container_of(work
, struct ieee80211_sub_if_data
,
4322 u
.mgd
.monitor_work
);
4324 ieee80211_mgd_probe_ap(sdata
, false);
4327 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
4329 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
4330 __ieee80211_stop_poll(sdata
);
4332 /* let's probe the connection once */
4333 if (!ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
4334 ieee80211_queue_work(&sdata
->local
->hw
,
4335 &sdata
->u
.mgd
.monitor_work
);
4340 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data
*sdata
)
4342 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4343 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4347 if (ifmgd
->auth_data
|| ifmgd
->assoc_data
) {
4348 const u8
*bssid
= ifmgd
->auth_data
?
4349 ifmgd
->auth_data
->bss
->bssid
:
4350 ifmgd
->assoc_data
->bss
->bssid
;
4353 * If we are trying to authenticate / associate while suspending,
4354 * cfg80211 won't know and won't actually abort those attempts,
4355 * thus we need to do that ourselves.
4357 ieee80211_send_deauth_disassoc(sdata
, bssid
,
4358 IEEE80211_STYPE_DEAUTH
,
4359 WLAN_REASON_DEAUTH_LEAVING
,
4361 if (ifmgd
->assoc_data
)
4362 ieee80211_destroy_assoc_data(sdata
, false, true);
4363 if (ifmgd
->auth_data
)
4364 ieee80211_destroy_auth_data(sdata
, false);
4365 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4366 IEEE80211_DEAUTH_FRAME_LEN
);
4369 /* This is a bit of a hack - we should find a better and more generic
4370 * solution to this. Normally when suspending, cfg80211 will in fact
4371 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4372 * auth (not so important) or assoc (this is the problem) process.
4374 * As a consequence, it can happen that we are in the process of both
4375 * associating and suspending, and receive an association response
4376 * after cfg80211 has checked if it needs to disconnect, but before
4377 * we actually set the flag to drop incoming frames. This will then
4378 * cause the workqueue flush to process the association response in
4379 * the suspend, resulting in a successful association just before it
4380 * tries to remove the interface from the driver, which now though
4381 * has a channel context assigned ... this results in issues.
4383 * To work around this (for now) simply deauth here again if we're
4386 if (ifmgd
->associated
&& !sdata
->local
->wowlan
) {
4388 struct cfg80211_deauth_request req
= {
4389 .reason_code
= WLAN_REASON_DEAUTH_LEAVING
,
4393 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4394 ieee80211_mgd_deauth(sdata
, &req
);
4397 sdata_unlock(sdata
);
4400 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
4402 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4405 if (!ifmgd
->associated
) {
4406 sdata_unlock(sdata
);
4410 if (sdata
->flags
& IEEE80211_SDATA_DISCONNECT_RESUME
) {
4411 sdata
->flags
&= ~IEEE80211_SDATA_DISCONNECT_RESUME
;
4412 mlme_dbg(sdata
, "driver requested disconnect after resume\n");
4413 ieee80211_sta_connection_lost(sdata
,
4414 ifmgd
->associated
->bssid
,
4415 WLAN_REASON_UNSPECIFIED
,
4417 sdata_unlock(sdata
);
4420 sdata_unlock(sdata
);
4424 /* interface setup */
4425 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
4427 struct ieee80211_if_managed
*ifmgd
;
4429 ifmgd
= &sdata
->u
.mgd
;
4430 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
4431 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
4432 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
4433 ieee80211_beacon_connection_loss_work
);
4434 INIT_WORK(&ifmgd
->csa_connection_drop_work
,
4435 ieee80211_csa_connection_drop_work
);
4436 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_mgd_work
);
4437 INIT_DELAYED_WORK(&ifmgd
->tdls_peer_del_work
,
4438 ieee80211_tdls_peer_del_work
);
4439 timer_setup(&ifmgd
->timer
, ieee80211_sta_timer
, 0);
4440 timer_setup(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
, 0);
4441 timer_setup(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
, 0);
4442 timer_setup(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
, 0);
4443 INIT_DELAYED_WORK(&ifmgd
->tx_tspec_wk
,
4444 ieee80211_sta_handle_tspec_ac_params_wk
);
4447 ifmgd
->powersave
= sdata
->wdev
.ps
;
4448 ifmgd
->uapsd_queues
= sdata
->local
->hw
.uapsd_queues
;
4449 ifmgd
->uapsd_max_sp_len
= sdata
->local
->hw
.uapsd_max_sp_len
;
4450 ifmgd
->p2p_noa_index
= -1;
4452 if (sdata
->local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
)
4453 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
4455 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
4457 /* Setup TDLS data */
4458 spin_lock_init(&ifmgd
->teardown_lock
);
4459 ifmgd
->teardown_skb
= NULL
;
4460 ifmgd
->orig_teardown_skb
= NULL
;
4463 /* scan finished notification */
4464 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
4466 struct ieee80211_sub_if_data
*sdata
;
4468 /* Restart STA timers */
4470 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4471 if (ieee80211_sdata_running(sdata
))
4472 ieee80211_restart_sta_timer(sdata
);
4477 static u8
ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data
*sdata
,
4478 struct cfg80211_bss
*cbss
)
4480 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4481 const u8
*ht_cap_ie
, *vht_cap_ie
;
4482 const struct ieee80211_ht_cap
*ht_cap
;
4483 const struct ieee80211_vht_cap
*vht_cap
;
4486 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)
4489 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4490 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
)) {
4491 ht_cap
= (void *)(ht_cap_ie
+ 2);
4492 chains
= ieee80211_mcs_to_chains(&ht_cap
->mcs
);
4494 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4495 * "Tx Unequal Modulation Supported" fields.
4499 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
4502 vht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4503 if (vht_cap_ie
&& vht_cap_ie
[1] >= sizeof(*vht_cap
)) {
4507 vht_cap
= (void *)(vht_cap_ie
+ 2);
4508 tx_mcs_map
= le16_to_cpu(vht_cap
->supp_mcs
.tx_mcs_map
);
4509 for (nss
= 8; nss
> 0; nss
--) {
4510 if (((tx_mcs_map
>> (2 * (nss
- 1))) & 3) !=
4511 IEEE80211_VHT_MCS_NOT_SUPPORTED
)
4514 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4515 chains
= max(chains
, nss
);
4522 ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band
*sband
,
4523 const struct ieee80211_he_operation
*he_op
)
4525 const struct ieee80211_sta_he_cap
*sta_he_cap
=
4526 ieee80211_get_he_sta_cap(sband
);
4530 if (!sta_he_cap
|| !he_op
)
4533 ap_min_req_set
= le16_to_cpu(he_op
->he_mcs_nss_set
);
4535 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4536 for (i
= 0; i
< 3; i
++) {
4537 const struct ieee80211_he_mcs_nss_supp
*sta_mcs_nss_supp
=
4538 &sta_he_cap
->he_mcs_nss_supp
;
4539 u16 sta_mcs_map_rx
=
4540 le16_to_cpu(((__le16
*)sta_mcs_nss_supp
)[2 * i
]);
4541 u16 sta_mcs_map_tx
=
4542 le16_to_cpu(((__le16
*)sta_mcs_nss_supp
)[2 * i
+ 1]);
4544 bool verified
= true;
4547 * For each band there is a maximum of 8 spatial streams
4548 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4549 * of 2 bits per NSS (1-8), with the values defined in enum
4550 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4551 * capabilities aren't less than the AP's minimum requirements
4552 * for this HE BSS per SS.
4553 * It is enough to find one such band that meets the reqs.
4555 for (nss
= 8; nss
> 0; nss
--) {
4556 u8 sta_rx_val
= (sta_mcs_map_rx
>> (2 * (nss
- 1))) & 3;
4557 u8 sta_tx_val
= (sta_mcs_map_tx
>> (2 * (nss
- 1))) & 3;
4558 u8 ap_val
= (ap_min_req_set
>> (2 * (nss
- 1))) & 3;
4560 if (ap_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
)
4564 * Make sure the HE AP doesn't require MCSs that aren't
4565 * supported by the client
4567 if (sta_rx_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
||
4568 sta_tx_val
== IEEE80211_HE_MCS_NOT_SUPPORTED
||
4569 (ap_val
> sta_rx_val
) || (ap_val
> sta_tx_val
)) {
4579 /* If here, STA doesn't meet AP's HE min requirements */
4583 static int ieee80211_prep_channel(struct ieee80211_sub_if_data
*sdata
,
4584 struct cfg80211_bss
*cbss
)
4586 struct ieee80211_local
*local
= sdata
->local
;
4587 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4588 const struct ieee80211_ht_cap
*ht_cap
= NULL
;
4589 const struct ieee80211_ht_operation
*ht_oper
= NULL
;
4590 const struct ieee80211_vht_operation
*vht_oper
= NULL
;
4591 const struct ieee80211_he_operation
*he_oper
= NULL
;
4592 struct ieee80211_supported_band
*sband
;
4593 struct cfg80211_chan_def chandef
;
4598 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4600 ifmgd
->flags
&= ~(IEEE80211_STA_DISABLE_40MHZ
|
4601 IEEE80211_STA_DISABLE_80P80MHZ
|
4602 IEEE80211_STA_DISABLE_160MHZ
);
4606 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
4607 sband
->ht_cap
.ht_supported
) {
4608 const u8
*ht_oper_ie
, *ht_cap_ie
;
4610 ht_oper_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_OPERATION
);
4611 if (ht_oper_ie
&& ht_oper_ie
[1] >= sizeof(*ht_oper
))
4612 ht_oper
= (void *)(ht_oper_ie
+ 2);
4614 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4615 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
))
4616 ht_cap
= (void *)(ht_cap_ie
+ 2);
4619 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4624 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
4625 sband
->vht_cap
.vht_supported
) {
4626 const u8
*vht_oper_ie
, *vht_cap
;
4628 vht_oper_ie
= ieee80211_bss_get_ie(cbss
,
4629 WLAN_EID_VHT_OPERATION
);
4630 if (vht_oper_ie
&& vht_oper_ie
[1] >= sizeof(*vht_oper
))
4631 vht_oper
= (void *)(vht_oper_ie
+ 2);
4632 if (vht_oper
&& !ht_oper
) {
4635 "AP advertised VHT without HT, disabling both\n");
4636 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4637 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4640 vht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4641 if (!vht_cap
|| vht_cap
[1] < sizeof(struct ieee80211_vht_cap
)) {
4642 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4647 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HE
) &&
4648 ieee80211_get_he_sta_cap(sband
)) {
4649 const struct cfg80211_bss_ies
*ies
;
4650 const u8
*he_oper_ie
;
4652 ies
= rcu_dereference(cbss
->ies
);
4653 he_oper_ie
= cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION
,
4654 ies
->data
, ies
->len
);
4656 he_oper_ie
[1] == ieee80211_he_oper_size(&he_oper_ie
[3]))
4657 he_oper
= (void *)(he_oper_ie
+ 3);
4661 if (!ieee80211_verify_sta_he_mcs_support(sband
, he_oper
))
4662 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
4665 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4667 for (i
= 0; i
< sband
->n_channels
; i
++) {
4668 if (sband
->channels
[i
].flags
& (IEEE80211_CHAN_DISABLED
|
4669 IEEE80211_CHAN_NO_80MHZ
))
4677 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4679 ifmgd
->flags
|= ieee80211_determine_chantype(sdata
, sband
,
4681 ht_oper
, vht_oper
, he_oper
,
4684 sdata
->needed_rx_chains
= min(ieee80211_ht_vht_rx_chains(sdata
, cbss
),
4689 /* will change later if needed */
4690 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4692 mutex_lock(&local
->mtx
);
4694 * If this fails (possibly due to channel context sharing
4695 * on incompatible channels, e.g. 80+80 and 160 sharing the
4696 * same control channel) try to use a smaller bandwidth.
4698 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4699 IEEE80211_CHANCTX_SHARED
);
4701 /* don't downgrade for 5 and 10 MHz channels, though. */
4702 if (chandef
.width
== NL80211_CHAN_WIDTH_5
||
4703 chandef
.width
== NL80211_CHAN_WIDTH_10
)
4706 while (ret
&& chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) {
4707 ifmgd
->flags
|= ieee80211_chandef_downgrade(&chandef
);
4708 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4709 IEEE80211_CHANCTX_SHARED
);
4712 mutex_unlock(&local
->mtx
);
4716 static int ieee80211_prep_connection(struct ieee80211_sub_if_data
*sdata
,
4717 struct cfg80211_bss
*cbss
, bool assoc
,
4720 struct ieee80211_local
*local
= sdata
->local
;
4721 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4722 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
4723 struct sta_info
*new_sta
= NULL
;
4724 struct ieee80211_supported_band
*sband
;
4725 bool have_sta
= false;
4728 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4730 if (WARN_ON(!ifmgd
->auth_data
&& !ifmgd
->assoc_data
))
4733 /* If a reconfig is happening, bail out */
4734 if (local
->in_reconfig
)
4739 have_sta
= sta_info_get(sdata
, cbss
->bssid
);
4744 new_sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
4750 * Set up the information for the new channel before setting the
4751 * new channel. We can't - completely race-free - change the basic
4752 * rates bitmap and the channel (sband) that it refers to, but if
4753 * we set it up before we at least avoid calling into the driver's
4754 * bss_info_changed() method with invalid information (since we do
4755 * call that from changing the channel - only for IDLE and perhaps
4756 * some others, but ...).
4758 * So to avoid that, just set up all the new information before the
4759 * channel, but tell the driver to apply it only afterwards, since
4760 * it might need the new channel for that.
4763 u32 rates
= 0, basic_rates
= 0;
4764 bool have_higher_than_11mbit
;
4765 int min_rate
= INT_MAX
, min_rate_index
= -1;
4766 const struct cfg80211_bss_ies
*ies
;
4767 int shift
= ieee80211_vif_get_shift(&sdata
->vif
);
4769 ieee80211_get_rates(sband
, bss
->supp_rates
,
4770 bss
->supp_rates_len
,
4771 &rates
, &basic_rates
,
4772 &have_higher_than_11mbit
,
4773 &min_rate
, &min_rate_index
,
4777 * This used to be a workaround for basic rates missing
4778 * in the association response frame. Now that we no
4779 * longer use the basic rates from there, it probably
4780 * doesn't happen any more, but keep the workaround so
4781 * in case some *other* APs are buggy in different ways
4782 * we can connect -- with a warning.
4784 if (!basic_rates
&& min_rate_index
>= 0) {
4786 "No basic rates, using min rate instead\n");
4787 basic_rates
= BIT(min_rate_index
);
4790 new_sta
->sta
.supp_rates
[cbss
->channel
->band
] = rates
;
4791 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
4793 /* cf. IEEE 802.11 9.2.12 */
4794 if (cbss
->channel
->band
== NL80211_BAND_2GHZ
&&
4795 have_higher_than_11mbit
)
4796 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
4798 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
4800 memcpy(ifmgd
->bssid
, cbss
->bssid
, ETH_ALEN
);
4802 /* set timing information */
4803 sdata
->vif
.bss_conf
.beacon_int
= cbss
->beacon_interval
;
4805 ies
= rcu_dereference(cbss
->beacon_ies
);
4809 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4810 sdata
->vif
.bss_conf
.sync_device_ts
=
4811 bss
->device_ts_beacon
;
4812 tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4813 ies
->data
, ies
->len
);
4814 if (tim_ie
&& tim_ie
[1] >= 2)
4815 sdata
->vif
.bss_conf
.sync_dtim_count
= tim_ie
[2];
4817 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4818 } else if (!ieee80211_hw_check(&sdata
->local
->hw
,
4819 TIMING_BEACON_ONLY
)) {
4820 ies
= rcu_dereference(cbss
->proberesp_ies
);
4821 /* must be non-NULL since beacon IEs were NULL */
4822 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4823 sdata
->vif
.bss_conf
.sync_device_ts
=
4824 bss
->device_ts_presp
;
4825 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4827 sdata
->vif
.bss_conf
.sync_tsf
= 0;
4828 sdata
->vif
.bss_conf
.sync_device_ts
= 0;
4829 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4834 if (new_sta
|| override
) {
4835 err
= ieee80211_prep_channel(sdata
, cbss
);
4838 sta_info_free(local
, new_sta
);
4845 * tell driver about BSSID, basic rates and timing
4846 * this was set up above, before setting the channel
4848 ieee80211_bss_info_change_notify(sdata
,
4849 BSS_CHANGED_BSSID
| BSS_CHANGED_BASIC_RATES
|
4850 BSS_CHANGED_BEACON_INT
);
4853 sta_info_pre_move_state(new_sta
, IEEE80211_STA_AUTH
);
4855 err
= sta_info_insert(new_sta
);
4859 "failed to insert STA entry for the AP (error %d)\n",
4864 WARN_ON_ONCE(!ether_addr_equal(ifmgd
->bssid
, cbss
->bssid
));
4866 /* Cancel scan to ensure that nothing interferes with connection */
4867 if (local
->scanning
)
4868 ieee80211_scan_cancel(local
);
4874 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
4875 struct cfg80211_auth_request
*req
)
4877 struct ieee80211_local
*local
= sdata
->local
;
4878 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4879 struct ieee80211_mgd_auth_data
*auth_data
;
4883 /* prepare auth data structure */
4885 switch (req
->auth_type
) {
4886 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
4887 auth_alg
= WLAN_AUTH_OPEN
;
4889 case NL80211_AUTHTYPE_SHARED_KEY
:
4890 if (IS_ERR(local
->wep_tx_tfm
))
4892 auth_alg
= WLAN_AUTH_SHARED_KEY
;
4894 case NL80211_AUTHTYPE_FT
:
4895 auth_alg
= WLAN_AUTH_FT
;
4897 case NL80211_AUTHTYPE_NETWORK_EAP
:
4898 auth_alg
= WLAN_AUTH_LEAP
;
4900 case NL80211_AUTHTYPE_SAE
:
4901 auth_alg
= WLAN_AUTH_SAE
;
4903 case NL80211_AUTHTYPE_FILS_SK
:
4904 auth_alg
= WLAN_AUTH_FILS_SK
;
4906 case NL80211_AUTHTYPE_FILS_SK_PFS
:
4907 auth_alg
= WLAN_AUTH_FILS_SK_PFS
;
4909 case NL80211_AUTHTYPE_FILS_PK
:
4910 auth_alg
= WLAN_AUTH_FILS_PK
;
4916 auth_data
= kzalloc(sizeof(*auth_data
) + req
->auth_data_len
+
4917 req
->ie_len
, GFP_KERNEL
);
4921 auth_data
->bss
= req
->bss
;
4923 if (req
->auth_data_len
>= 4) {
4924 if (req
->auth_type
== NL80211_AUTHTYPE_SAE
) {
4925 __le16
*pos
= (__le16
*) req
->auth_data
;
4927 auth_data
->sae_trans
= le16_to_cpu(pos
[0]);
4928 auth_data
->sae_status
= le16_to_cpu(pos
[1]);
4930 memcpy(auth_data
->data
, req
->auth_data
+ 4,
4931 req
->auth_data_len
- 4);
4932 auth_data
->data_len
+= req
->auth_data_len
- 4;
4935 if (req
->ie
&& req
->ie_len
) {
4936 memcpy(&auth_data
->data
[auth_data
->data_len
],
4937 req
->ie
, req
->ie_len
);
4938 auth_data
->data_len
+= req
->ie_len
;
4941 if (req
->key
&& req
->key_len
) {
4942 auth_data
->key_len
= req
->key_len
;
4943 auth_data
->key_idx
= req
->key_idx
;
4944 memcpy(auth_data
->key
, req
->key
, req
->key_len
);
4947 auth_data
->algorithm
= auth_alg
;
4949 /* try to authenticate/probe */
4951 if ((ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) ||
4952 ifmgd
->assoc_data
) {
4957 if (ifmgd
->auth_data
)
4958 ieee80211_destroy_auth_data(sdata
, false);
4960 /* prep auth_data so we don't go into idle on disassoc */
4961 ifmgd
->auth_data
= auth_data
;
4963 if (ifmgd
->associated
) {
4964 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4967 "disconnect from AP %pM for new auth to %pM\n",
4968 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
4969 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4970 WLAN_REASON_UNSPECIFIED
,
4973 ieee80211_report_disconnect(sdata
, frame_buf
,
4974 sizeof(frame_buf
), true,
4975 WLAN_REASON_UNSPECIFIED
);
4978 sdata_info(sdata
, "authenticate with %pM\n", req
->bss
->bssid
);
4980 err
= ieee80211_prep_connection(sdata
, req
->bss
, false, false);
4984 err
= ieee80211_auth(sdata
);
4986 sta_info_destroy_addr(sdata
, req
->bss
->bssid
);
4990 /* hold our own reference */
4991 cfg80211_ref_bss(local
->hw
.wiphy
, auth_data
->bss
);
4995 eth_zero_addr(ifmgd
->bssid
);
4996 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
4997 ifmgd
->auth_data
= NULL
;
4998 mutex_lock(&sdata
->local
->mtx
);
4999 ieee80211_vif_release_channel(sdata
);
5000 mutex_unlock(&sdata
->local
->mtx
);
5006 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
5007 struct cfg80211_assoc_request
*req
)
5009 struct ieee80211_local
*local
= sdata
->local
;
5010 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5011 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
5012 struct ieee80211_mgd_assoc_data
*assoc_data
;
5013 const struct cfg80211_bss_ies
*beacon_ies
;
5014 struct ieee80211_supported_band
*sband
;
5015 const u8
*ssidie
, *ht_ie
, *vht_ie
;
5017 bool override
= false;
5019 assoc_data
= kzalloc(sizeof(*assoc_data
) + req
->ie_len
, GFP_KERNEL
);
5024 ssidie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
5030 memcpy(assoc_data
->ssid
, ssidie
+ 2, ssidie
[1]);
5031 assoc_data
->ssid_len
= ssidie
[1];
5034 if (ifmgd
->associated
) {
5035 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5038 "disconnect from AP %pM for new assoc to %pM\n",
5039 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
5040 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5041 WLAN_REASON_UNSPECIFIED
,
5044 ieee80211_report_disconnect(sdata
, frame_buf
,
5045 sizeof(frame_buf
), true,
5046 WLAN_REASON_UNSPECIFIED
);
5049 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) {
5054 if (ifmgd
->assoc_data
) {
5059 if (ifmgd
->auth_data
) {
5062 /* keep sta info, bssid if matching */
5063 match
= ether_addr_equal(ifmgd
->bssid
, req
->bss
->bssid
);
5064 ieee80211_destroy_auth_data(sdata
, match
);
5067 /* prepare assoc data */
5069 ifmgd
->beacon_crc_valid
= false;
5071 assoc_data
->wmm
= bss
->wmm_used
&&
5072 (local
->hw
.queues
>= IEEE80211_NUM_ACS
);
5075 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5076 * We still associate in non-HT mode (11a/b/g) if any one of these
5077 * ciphers is configured as pairwise.
5078 * We can set this to true for non-11n hardware, that'll be checked
5079 * separately along with the peer capabilities.
5081 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++) {
5082 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
5083 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
5084 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
) {
5085 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5086 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5087 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HE
;
5088 netdev_info(sdata
->dev
,
5089 "disabling HE/HT/VHT due to WEP/TKIP use\n");
5093 /* Also disable HT if we don't support it or the AP doesn't use WMM */
5094 sband
= local
->hw
.wiphy
->bands
[req
->bss
->channel
->band
];
5095 if (!sband
->ht_cap
.ht_supported
||
5096 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
5097 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
5098 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5099 if (!bss
->wmm_used
&&
5100 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
5101 netdev_info(sdata
->dev
,
5102 "disabling HT as WMM/QoS is not supported by the AP\n");
5105 /* disable VHT if we don't support it or the AP doesn't use WMM */
5106 if (!sband
->vht_cap
.vht_supported
||
5107 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
5108 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
5109 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5110 if (!bss
->wmm_used
&&
5111 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
5112 netdev_info(sdata
->dev
,
5113 "disabling VHT as WMM/QoS is not supported by the AP\n");
5116 memcpy(&ifmgd
->ht_capa
, &req
->ht_capa
, sizeof(ifmgd
->ht_capa
));
5117 memcpy(&ifmgd
->ht_capa_mask
, &req
->ht_capa_mask
,
5118 sizeof(ifmgd
->ht_capa_mask
));
5120 memcpy(&ifmgd
->vht_capa
, &req
->vht_capa
, sizeof(ifmgd
->vht_capa
));
5121 memcpy(&ifmgd
->vht_capa_mask
, &req
->vht_capa_mask
,
5122 sizeof(ifmgd
->vht_capa_mask
));
5124 if (req
->ie
&& req
->ie_len
) {
5125 memcpy(assoc_data
->ie
, req
->ie
, req
->ie_len
);
5126 assoc_data
->ie_len
= req
->ie_len
;
5129 if (req
->fils_kek
) {
5130 /* should already be checked in cfg80211 - so warn */
5131 if (WARN_ON(req
->fils_kek_len
> FILS_MAX_KEK_LEN
)) {
5135 memcpy(assoc_data
->fils_kek
, req
->fils_kek
,
5137 assoc_data
->fils_kek_len
= req
->fils_kek_len
;
5140 if (req
->fils_nonces
)
5141 memcpy(assoc_data
->fils_nonces
, req
->fils_nonces
,
5142 2 * FILS_NONCE_LEN
);
5144 assoc_data
->bss
= req
->bss
;
5146 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
5147 if (ifmgd
->powersave
)
5148 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
5150 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
5152 sdata
->smps_mode
= ifmgd
->req_smps
;
5154 assoc_data
->capability
= req
->bss
->capability
;
5155 assoc_data
->supp_rates
= bss
->supp_rates
;
5156 assoc_data
->supp_rates_len
= bss
->supp_rates_len
;
5159 ht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_OPERATION
);
5160 if (ht_ie
&& ht_ie
[1] >= sizeof(struct ieee80211_ht_operation
))
5161 assoc_data
->ap_ht_param
=
5162 ((struct ieee80211_ht_operation
*)(ht_ie
+ 2))->ht_param
;
5164 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5165 vht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_VHT_CAPABILITY
);
5166 if (vht_ie
&& vht_ie
[1] >= sizeof(struct ieee80211_vht_cap
))
5167 memcpy(&assoc_data
->ap_vht_cap
, vht_ie
+ 2,
5168 sizeof(struct ieee80211_vht_cap
));
5170 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5173 if (WARN((sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
) &&
5174 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
),
5175 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5176 sdata
->vif
.driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
5178 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
5179 (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
)) {
5180 assoc_data
->uapsd
= true;
5181 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
5183 assoc_data
->uapsd
= false;
5184 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
5187 if (req
->prev_bssid
)
5188 memcpy(assoc_data
->prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
5191 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
5192 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
5194 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
5195 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
5198 if (req
->flags
& ASSOC_REQ_USE_RRM
)
5199 ifmgd
->flags
|= IEEE80211_STA_ENABLE_RRM
;
5201 ifmgd
->flags
&= ~IEEE80211_STA_ENABLE_RRM
;
5203 if (req
->crypto
.control_port
)
5204 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
5206 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
5208 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
5209 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
5210 sdata
->control_port_over_nl80211
=
5211 req
->crypto
.control_port_over_nl80211
;
5212 sdata
->encrypt_headroom
= ieee80211_cs_headroom(local
, &req
->crypto
,
5215 /* kick off associate process */
5217 ifmgd
->assoc_data
= assoc_data
;
5218 ifmgd
->dtim_period
= 0;
5219 ifmgd
->have_beacon
= false;
5221 /* override HT/VHT configuration only if the AP and we support it */
5222 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
5223 struct ieee80211_sta_ht_cap sta_ht_cap
;
5225 if (req
->flags
& ASSOC_REQ_DISABLE_HT
)
5228 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
5229 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
5231 /* check for 40 MHz disable override */
5232 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
) &&
5233 sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
&&
5234 !(sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
5237 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
5238 req
->flags
& ASSOC_REQ_DISABLE_VHT
)
5242 if (req
->flags
& ASSOC_REQ_DISABLE_HT
) {
5243 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
5244 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5247 if (req
->flags
& ASSOC_REQ_DISABLE_VHT
)
5248 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
5250 err
= ieee80211_prep_connection(sdata
, req
->bss
, true, override
);
5255 beacon_ies
= rcu_dereference(req
->bss
->beacon_ies
);
5257 if (ieee80211_hw_check(&sdata
->local
->hw
, NEED_DTIM_BEFORE_ASSOC
) &&
5260 * Wait up to one beacon interval ...
5261 * should this be more if we miss one?
5263 sdata_info(sdata
, "waiting for beacon from %pM\n",
5265 assoc_data
->timeout
= TU_TO_EXP_TIME(req
->bss
->beacon_interval
);
5266 assoc_data
->timeout_started
= true;
5267 assoc_data
->need_beacon
= true;
5268 } else if (beacon_ies
) {
5269 const u8
*tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
5274 if (tim_ie
&& tim_ie
[1] >= sizeof(struct ieee80211_tim_ie
)) {
5275 const struct ieee80211_tim_ie
*tim
;
5276 tim
= (void *)(tim_ie
+ 2);
5277 ifmgd
->dtim_period
= tim
->dtim_period
;
5278 dtim_count
= tim
->dtim_count
;
5280 ifmgd
->have_beacon
= true;
5281 assoc_data
->timeout
= jiffies
;
5282 assoc_data
->timeout_started
= true;
5284 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
5285 sdata
->vif
.bss_conf
.sync_tsf
= beacon_ies
->tsf
;
5286 sdata
->vif
.bss_conf
.sync_device_ts
=
5287 bss
->device_ts_beacon
;
5288 sdata
->vif
.bss_conf
.sync_dtim_count
= dtim_count
;
5291 assoc_data
->timeout
= jiffies
;
5292 assoc_data
->timeout_started
= true;
5296 run_again(sdata
, assoc_data
->timeout
);
5298 if (bss
->corrupt_data
) {
5299 char *corrupt_type
= "data";
5300 if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_BEACON
) {
5301 if (bss
->corrupt_data
&
5302 IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5303 corrupt_type
= "beacon and probe response";
5305 corrupt_type
= "beacon";
5306 } else if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5307 corrupt_type
= "probe response";
5308 sdata_info(sdata
, "associating with AP with corrupt %s\n",
5314 eth_zero_addr(ifmgd
->bssid
);
5315 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
5316 ifmgd
->assoc_data
= NULL
;
5322 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
5323 struct cfg80211_deauth_request
*req
)
5325 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5326 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5327 bool tx
= !req
->local_state_change
;
5329 if (ifmgd
->auth_data
&&
5330 ether_addr_equal(ifmgd
->auth_data
->bss
->bssid
, req
->bssid
)) {
5332 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5333 req
->bssid
, req
->reason_code
,
5334 ieee80211_get_reason_code_string(req
->reason_code
));
5336 drv_mgd_prepare_tx(sdata
->local
, sdata
, 0);
5337 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
5338 IEEE80211_STYPE_DEAUTH
,
5339 req
->reason_code
, tx
,
5341 ieee80211_destroy_auth_data(sdata
, false);
5342 ieee80211_report_disconnect(sdata
, frame_buf
,
5343 sizeof(frame_buf
), true,
5349 if (ifmgd
->assoc_data
&&
5350 ether_addr_equal(ifmgd
->assoc_data
->bss
->bssid
, req
->bssid
)) {
5352 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5353 req
->bssid
, req
->reason_code
,
5354 ieee80211_get_reason_code_string(req
->reason_code
));
5356 drv_mgd_prepare_tx(sdata
->local
, sdata
, 0);
5357 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
5358 IEEE80211_STYPE_DEAUTH
,
5359 req
->reason_code
, tx
,
5361 ieee80211_destroy_assoc_data(sdata
, false, true);
5362 ieee80211_report_disconnect(sdata
, frame_buf
,
5363 sizeof(frame_buf
), true,
5368 if (ifmgd
->associated
&&
5369 ether_addr_equal(ifmgd
->associated
->bssid
, req
->bssid
)) {
5371 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5372 req
->bssid
, req
->reason_code
,
5373 ieee80211_get_reason_code_string(req
->reason_code
));
5375 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5376 req
->reason_code
, tx
, frame_buf
);
5377 ieee80211_report_disconnect(sdata
, frame_buf
,
5378 sizeof(frame_buf
), true,
5386 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
5387 struct cfg80211_disassoc_request
*req
)
5389 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5391 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5394 * cfg80211 should catch this ... but it's racy since
5395 * we can receive a disassoc frame, process it, hand it
5396 * to cfg80211 while that's in a locked section already
5397 * trying to tell us that the user wants to disconnect.
5399 if (ifmgd
->associated
!= req
->bss
)
5403 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5404 req
->bss
->bssid
, req
->reason_code
, ieee80211_get_reason_code_string(req
->reason_code
));
5406 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
5407 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DISASSOC
,
5408 req
->reason_code
, !req
->local_state_change
,
5411 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
5417 void ieee80211_mgd_stop(struct ieee80211_sub_if_data
*sdata
)
5419 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5422 * Make sure some work items will not run after this,
5423 * they will not do anything but might not have been
5424 * cancelled when disconnecting.
5426 cancel_work_sync(&ifmgd
->monitor_work
);
5427 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
5428 cancel_work_sync(&ifmgd
->request_smps_work
);
5429 cancel_work_sync(&ifmgd
->csa_connection_drop_work
);
5430 cancel_work_sync(&ifmgd
->chswitch_work
);
5431 cancel_delayed_work_sync(&ifmgd
->tdls_peer_del_work
);
5434 if (ifmgd
->assoc_data
) {
5435 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
5436 ieee80211_destroy_assoc_data(sdata
, false, false);
5437 cfg80211_assoc_timeout(sdata
->dev
, bss
);
5439 if (ifmgd
->auth_data
)
5440 ieee80211_destroy_auth_data(sdata
, false);
5441 spin_lock_bh(&ifmgd
->teardown_lock
);
5442 if (ifmgd
->teardown_skb
) {
5443 kfree_skb(ifmgd
->teardown_skb
);
5444 ifmgd
->teardown_skb
= NULL
;
5445 ifmgd
->orig_teardown_skb
= NULL
;
5447 spin_unlock_bh(&ifmgd
->teardown_lock
);
5448 del_timer_sync(&ifmgd
->timer
);
5449 sdata_unlock(sdata
);
5452 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
5453 enum nl80211_cqm_rssi_threshold_event rssi_event
,
5457 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5459 trace_api_cqm_rssi_notify(sdata
, rssi_event
, rssi_level
);
5461 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, rssi_level
, gfp
);
5463 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);
5465 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif
*vif
, gfp_t gfp
)
5467 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5469 trace_api_cqm_beacon_loss_notify(sdata
->local
, sdata
);
5471 cfg80211_cqm_beacon_loss_notify(sdata
->dev
, gfp
);
5473 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify
);