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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/delay.h>
17 #include <linux/if_ether.h>
18 #include <linux/skbuff.h>
19 #include <linux/if_arp.h>
20 #include <linux/etherdevice.h>
21 #include <linux/moduleparam.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/crc32.h>
24 #include <linux/slab.h>
25 #include <linux/export.h>
26 #include <net/mac80211.h>
27 #include <asm/unaligned.h>
29 #include "ieee80211_i.h"
30 #include "driver-ops.h"
33 #include "fils_aead.h"
35 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
37 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
38 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
39 #define IEEE80211_AUTH_MAX_TRIES 3
40 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries
= 2;
47 module_param(max_nullfunc_tries
, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries
,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries
= 5;
52 module_param(max_probe_tries
, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries
,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count
= 7;
65 module_param(beacon_loss_count
, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count
,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms
= 500;
80 module_param(probe_wait_ms
, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms
,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
101 static void run_again(struct ieee80211_sub_if_data
*sdata
,
102 unsigned long timeout
)
104 sdata_assert_lock(sdata
);
106 if (!timer_pending(&sdata
->u
.mgd
.timer
) ||
107 time_before(timeout
, sdata
->u
.mgd
.timer
.expires
))
108 mod_timer(&sdata
->u
.mgd
.timer
, timeout
);
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
113 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
116 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
119 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
120 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
125 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
127 if (unlikely(!ifmgd
->associated
))
130 if (ifmgd
->probe_send_count
)
131 ifmgd
->probe_send_count
= 0;
133 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
136 mod_timer(&ifmgd
->conn_mon_timer
,
137 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
140 static int ecw2cw(int ecw
)
142 return (1 << ecw
) - 1;
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data
*sdata
,
147 struct ieee80211_supported_band
*sband
,
148 struct ieee80211_channel
*channel
,
149 const struct ieee80211_ht_operation
*ht_oper
,
150 const struct ieee80211_vht_operation
*vht_oper
,
151 struct cfg80211_chan_def
*chandef
, bool tracking
)
153 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
154 struct cfg80211_chan_def vht_chandef
;
155 struct ieee80211_sta_ht_cap sta_ht_cap
;
158 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
159 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
161 chandef
->chan
= channel
;
162 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
163 chandef
->center_freq1
= channel
->center_freq
;
164 chandef
->center_freq2
= 0;
166 if (!ht_oper
|| !sta_ht_cap
.ht_supported
) {
167 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
171 chandef
->width
= NL80211_CHAN_WIDTH_20
;
173 ht_cfreq
= ieee80211_channel_to_frequency(ht_oper
->primary_chan
,
175 /* check that channel matches the right operating channel */
176 if (!tracking
&& channel
->center_freq
!= ht_cfreq
) {
178 * It's possible that some APs are confused here;
179 * Netgear WNDR3700 sometimes reports 4 higher than
180 * the actual channel in association responses, but
181 * since we look at probe response/beacon data here
185 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
186 channel
->center_freq
, ht_cfreq
,
187 ht_oper
->primary_chan
, channel
->band
);
188 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
192 /* check 40 MHz support, if we have it */
193 if (sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) {
194 ieee80211_chandef_ht_oper(ht_oper
, chandef
);
196 /* 40 MHz (and 80 MHz) must be supported for VHT */
197 ret
= IEEE80211_STA_DISABLE_VHT
;
198 /* also mark 40 MHz disabled */
199 ret
|= IEEE80211_STA_DISABLE_40MHZ
;
203 if (!vht_oper
|| !sband
->vht_cap
.vht_supported
) {
204 ret
= IEEE80211_STA_DISABLE_VHT
;
208 vht_chandef
= *chandef
;
209 if (!ieee80211_chandef_vht_oper(vht_oper
, &vht_chandef
)) {
210 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
212 "AP VHT information is invalid, disable VHT\n");
213 ret
= IEEE80211_STA_DISABLE_VHT
;
217 if (!cfg80211_chandef_valid(&vht_chandef
)) {
218 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
220 "AP VHT information is invalid, disable VHT\n");
221 ret
= IEEE80211_STA_DISABLE_VHT
;
225 if (cfg80211_chandef_identical(chandef
, &vht_chandef
)) {
230 if (!cfg80211_chandef_compatible(chandef
, &vht_chandef
)) {
231 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
233 "AP VHT information doesn't match HT, disable VHT\n");
234 ret
= IEEE80211_STA_DISABLE_VHT
;
238 *chandef
= vht_chandef
;
244 * When tracking the current AP, don't do any further checks if the
245 * new chandef is identical to the one we're currently using for the
246 * connection. This keeps us from playing ping-pong with regulatory,
247 * without it the following can happen (for example):
248 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
249 * - AP advertises regdom US
250 * - CRDA loads regdom US with 80 MHz prohibited (old database)
251 * - the code below detects an unsupported channel, downgrades, and
252 * we disconnect from the AP in the caller
253 * - disconnect causes CRDA to reload world regdomain and the game
255 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
257 * It seems possible that there are still scenarios with CSA or real
258 * bandwidth changes where a this could happen, but those cases are
259 * less common and wouldn't completely prevent using the AP.
262 cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
))
265 /* don't print the message below for VHT mismatch if VHT is disabled */
266 if (ret
& IEEE80211_STA_DISABLE_VHT
)
267 vht_chandef
= *chandef
;
270 * Ignore the DISABLED flag when we're already connected and only
271 * tracking the APs beacon for bandwidth changes - otherwise we
272 * might get disconnected here if we connect to an AP, update our
273 * regulatory information based on the AP's country IE and the
274 * information we have is wrong/outdated and disables the channel
275 * that we're actually using for the connection to the AP.
277 while (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
279 IEEE80211_CHAN_DISABLED
)) {
280 if (WARN_ON(chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
)) {
281 ret
= IEEE80211_STA_DISABLE_HT
|
282 IEEE80211_STA_DISABLE_VHT
;
286 ret
|= ieee80211_chandef_downgrade(chandef
);
289 if (chandef
->width
!= vht_chandef
.width
&& !tracking
)
291 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
293 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef
));
297 static int ieee80211_config_bw(struct ieee80211_sub_if_data
*sdata
,
298 struct sta_info
*sta
,
299 const struct ieee80211_ht_cap
*ht_cap
,
300 const struct ieee80211_ht_operation
*ht_oper
,
301 const struct ieee80211_vht_operation
*vht_oper
,
302 const u8
*bssid
, u32
*changed
)
304 struct ieee80211_local
*local
= sdata
->local
;
305 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
306 struct ieee80211_supported_band
*sband
;
307 struct ieee80211_channel
*chan
;
308 struct cfg80211_chan_def chandef
;
311 enum ieee80211_sta_rx_bandwidth new_sta_bw
;
314 /* if HT was/is disabled, don't track any bandwidth changes */
315 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
|| !ht_oper
)
318 /* don't check VHT if we associated as non-VHT station */
319 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
322 if (WARN_ON_ONCE(!sta
))
326 * if bss configuration changed store the new one -
327 * this may be applicable even if channel is identical
329 ht_opmode
= le16_to_cpu(ht_oper
->operation_mode
);
330 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
331 *changed
|= BSS_CHANGED_HT
;
332 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
335 chan
= sdata
->vif
.bss_conf
.chandef
.chan
;
336 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
338 /* calculate new channel (type) based on HT/VHT operation IEs */
339 flags
= ieee80211_determine_chantype(sdata
, sband
, chan
,
344 * Downgrade the new channel if we associated with restricted
345 * capabilities. For example, if we associated as a 20 MHz STA
346 * to a 40 MHz AP (due to regulatory, capabilities or config
347 * reasons) then switching to a 40 MHz channel now won't do us
348 * any good -- we couldn't use it with the AP.
350 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_80P80MHZ
&&
351 chandef
.width
== NL80211_CHAN_WIDTH_80P80
)
352 flags
|= ieee80211_chandef_downgrade(&chandef
);
353 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_160MHZ
&&
354 chandef
.width
== NL80211_CHAN_WIDTH_160
)
355 flags
|= ieee80211_chandef_downgrade(&chandef
);
356 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
&&
357 chandef
.width
> NL80211_CHAN_WIDTH_20
)
358 flags
|= ieee80211_chandef_downgrade(&chandef
);
360 if (cfg80211_chandef_identical(&chandef
, &sdata
->vif
.bss_conf
.chandef
))
364 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
365 ifmgd
->bssid
, chandef
.chan
->center_freq
, chandef
.width
,
366 chandef
.center_freq1
, chandef
.center_freq2
);
368 if (flags
!= (ifmgd
->flags
& (IEEE80211_STA_DISABLE_HT
|
369 IEEE80211_STA_DISABLE_VHT
|
370 IEEE80211_STA_DISABLE_40MHZ
|
371 IEEE80211_STA_DISABLE_80P80MHZ
|
372 IEEE80211_STA_DISABLE_160MHZ
)) ||
373 !cfg80211_chandef_valid(&chandef
)) {
375 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
380 switch (chandef
.width
) {
381 case NL80211_CHAN_WIDTH_20_NOHT
:
382 case NL80211_CHAN_WIDTH_20
:
383 new_sta_bw
= IEEE80211_STA_RX_BW_20
;
385 case NL80211_CHAN_WIDTH_40
:
386 new_sta_bw
= IEEE80211_STA_RX_BW_40
;
388 case NL80211_CHAN_WIDTH_80
:
389 new_sta_bw
= IEEE80211_STA_RX_BW_80
;
391 case NL80211_CHAN_WIDTH_80P80
:
392 case NL80211_CHAN_WIDTH_160
:
393 new_sta_bw
= IEEE80211_STA_RX_BW_160
;
399 if (new_sta_bw
> sta
->cur_max_bandwidth
)
400 new_sta_bw
= sta
->cur_max_bandwidth
;
402 if (new_sta_bw
< sta
->sta
.bandwidth
) {
403 sta
->sta
.bandwidth
= new_sta_bw
;
404 rate_control_rate_update(local
, sband
, sta
,
405 IEEE80211_RC_BW_CHANGED
);
408 ret
= ieee80211_vif_change_bandwidth(sdata
, &chandef
, changed
);
411 "AP %pM changed bandwidth to incompatible one - disconnect\n",
416 if (new_sta_bw
> sta
->sta
.bandwidth
) {
417 sta
->sta
.bandwidth
= new_sta_bw
;
418 rate_control_rate_update(local
, sband
, sta
,
419 IEEE80211_RC_BW_CHANGED
);
425 /* frame sending functions */
427 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data
*sdata
,
428 struct sk_buff
*skb
, u8 ap_ht_param
,
429 struct ieee80211_supported_band
*sband
,
430 struct ieee80211_channel
*channel
,
431 enum ieee80211_smps_mode smps
)
434 u32 flags
= channel
->flags
;
436 struct ieee80211_sta_ht_cap ht_cap
;
438 BUILD_BUG_ON(sizeof(ht_cap
) != sizeof(sband
->ht_cap
));
440 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
441 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
443 /* determine capability flags */
446 switch (ap_ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
447 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
448 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
449 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
450 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
453 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
454 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
455 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
456 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
462 * If 40 MHz was disabled associate as though we weren't
463 * capable of 40 MHz -- some broken APs will never fall
464 * back to trying to transmit in 20 MHz.
466 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_40MHZ
) {
467 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
468 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
471 /* set SM PS mode properly */
472 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
474 case IEEE80211_SMPS_AUTOMATIC
:
475 case IEEE80211_SMPS_NUM_MODES
:
477 case IEEE80211_SMPS_OFF
:
478 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
479 IEEE80211_HT_CAP_SM_PS_SHIFT
;
481 case IEEE80211_SMPS_STATIC
:
482 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
483 IEEE80211_HT_CAP_SM_PS_SHIFT
;
485 case IEEE80211_SMPS_DYNAMIC
:
486 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
487 IEEE80211_HT_CAP_SM_PS_SHIFT
;
491 /* reserve and fill IE */
492 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
493 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, cap
);
496 /* This function determines vht capability flags for the association
498 * Note - the function may set the owner of the MU-MIMO capability
500 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data
*sdata
,
502 struct ieee80211_supported_band
*sband
,
503 struct ieee80211_vht_cap
*ap_vht_cap
)
505 struct ieee80211_local
*local
= sdata
->local
;
508 struct ieee80211_sta_vht_cap vht_cap
;
509 u32 mask
, ap_bf_sts
, our_bf_sts
;
511 BUILD_BUG_ON(sizeof(vht_cap
) != sizeof(sband
->vht_cap
));
513 memcpy(&vht_cap
, &sband
->vht_cap
, sizeof(vht_cap
));
514 ieee80211_apply_vhtcap_overrides(sdata
, &vht_cap
);
516 /* determine capability flags */
519 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_80P80MHZ
) {
520 u32 bw
= cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
522 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
523 if (bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
||
524 bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
525 cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
528 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_160MHZ
) {
529 cap
&= ~IEEE80211_VHT_CAP_SHORT_GI_160
;
530 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
534 * Some APs apparently get confused if our capabilities are better
535 * than theirs, so restrict what we advertise in the assoc request.
537 if (!(ap_vht_cap
->vht_cap_info
&
538 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)))
539 cap
&= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
540 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
);
541 else if (!(ap_vht_cap
->vht_cap_info
&
542 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
543 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
546 * If some other vif is using the MU-MIMO capablity we cannot associate
547 * using MU-MIMO - this will lead to contradictions in the group-id
549 * Ownership is defined since association request, in order to avoid
550 * simultaneous associations with MU-MIMO.
552 if (cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
) {
553 bool disable_mu_mimo
= false;
554 struct ieee80211_sub_if_data
*other
;
556 list_for_each_entry_rcu(other
, &local
->interfaces
, list
) {
557 if (other
->vif
.mu_mimo_owner
) {
558 disable_mu_mimo
= true;
563 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
565 sdata
->vif
.mu_mimo_owner
= true;
568 mask
= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
570 ap_bf_sts
= le32_to_cpu(ap_vht_cap
->vht_cap_info
) & mask
;
571 our_bf_sts
= cap
& mask
;
573 if (ap_bf_sts
< our_bf_sts
) {
578 /* reserve and fill IE */
579 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
580 ieee80211_ie_build_vht_cap(pos
, &vht_cap
, cap
);
583 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
)
585 struct ieee80211_local
*local
= sdata
->local
;
586 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
587 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
589 struct ieee80211_mgmt
*mgmt
;
591 size_t offset
= 0, noffset
;
592 int i
, count
, rates_len
, supp_rates_len
, shift
;
594 struct ieee80211_supported_band
*sband
;
595 struct ieee80211_chanctx_conf
*chanctx_conf
;
596 struct ieee80211_channel
*chan
;
599 sdata_assert_lock(sdata
);
602 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
603 if (WARN_ON(!chanctx_conf
)) {
607 chan
= chanctx_conf
->def
.chan
;
609 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
610 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
612 if (assoc_data
->supp_rates_len
) {
614 * Get all rates supported by the device and the AP as
615 * some APs don't like getting a superset of their rates
616 * in the association request (e.g. D-Link DAP 1353 in
619 rates_len
= ieee80211_parse_bitrates(&chanctx_conf
->def
, sband
,
620 assoc_data
->supp_rates
,
621 assoc_data
->supp_rates_len
,
625 * In case AP not provide any supported rates information
626 * before association, we send information element(s) with
627 * all rates that we support.
630 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
636 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
637 sizeof(*mgmt
) + /* bit too much but doesn't matter */
638 2 + assoc_data
->ssid_len
+ /* SSID */
639 4 + rates_len
+ /* (extended) rates */
640 4 + /* power capability */
641 2 + 2 * sband
->n_channels
+ /* supported channels */
642 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
643 2 + sizeof(struct ieee80211_vht_cap
) + /* VHT */
644 assoc_data
->ie_len
+ /* extra IEs */
645 (assoc_data
->fils_kek_len
? 16 /* AES-SIV */ : 0) +
651 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
653 capab
= WLAN_CAPABILITY_ESS
;
655 if (sband
->band
== NL80211_BAND_2GHZ
) {
656 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
657 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
660 if (assoc_data
->capability
& WLAN_CAPABILITY_PRIVACY
)
661 capab
|= WLAN_CAPABILITY_PRIVACY
;
663 if ((assoc_data
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
664 ieee80211_hw_check(&local
->hw
, SPECTRUM_MGMT
))
665 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
667 if (ifmgd
->flags
& IEEE80211_STA_ENABLE_RRM
)
668 capab
|= WLAN_CAPABILITY_RADIO_MEASURE
;
670 mgmt
= skb_put_zero(skb
, 24);
671 memcpy(mgmt
->da
, assoc_data
->bss
->bssid
, ETH_ALEN
);
672 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
673 memcpy(mgmt
->bssid
, assoc_data
->bss
->bssid
, ETH_ALEN
);
675 if (!is_zero_ether_addr(assoc_data
->prev_bssid
)) {
677 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
678 IEEE80211_STYPE_REASSOC_REQ
);
679 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
680 mgmt
->u
.reassoc_req
.listen_interval
=
681 cpu_to_le16(local
->hw
.conf
.listen_interval
);
682 memcpy(mgmt
->u
.reassoc_req
.current_ap
, assoc_data
->prev_bssid
,
686 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
687 IEEE80211_STYPE_ASSOC_REQ
);
688 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
689 mgmt
->u
.assoc_req
.listen_interval
=
690 cpu_to_le16(local
->hw
.conf
.listen_interval
);
694 pos
= skb_put(skb
, 2 + assoc_data
->ssid_len
);
695 *pos
++ = WLAN_EID_SSID
;
696 *pos
++ = assoc_data
->ssid_len
;
697 memcpy(pos
, assoc_data
->ssid
, assoc_data
->ssid_len
);
699 /* add all rates which were marked to be used above */
700 supp_rates_len
= rates_len
;
701 if (supp_rates_len
> 8)
704 pos
= skb_put(skb
, supp_rates_len
+ 2);
705 *pos
++ = WLAN_EID_SUPP_RATES
;
706 *pos
++ = supp_rates_len
;
709 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
710 if (BIT(i
) & rates
) {
711 int rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
719 if (rates_len
> count
) {
720 pos
= skb_put(skb
, rates_len
- count
+ 2);
721 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
722 *pos
++ = rates_len
- count
;
724 for (i
++; i
< sband
->n_bitrates
; i
++) {
725 if (BIT(i
) & rates
) {
727 rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
734 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
||
735 capab
& WLAN_CAPABILITY_RADIO_MEASURE
) {
736 pos
= skb_put(skb
, 4);
737 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
739 *pos
++ = 0; /* min tx power */
741 *pos
++ = ieee80211_chandef_max_power(&chanctx_conf
->def
);
744 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
745 /* TODO: get this in reg domain format */
746 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
747 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
748 *pos
++ = 2 * sband
->n_channels
;
749 for (i
= 0; i
< sband
->n_channels
; i
++) {
750 *pos
++ = ieee80211_frequency_to_channel(
751 sband
->channels
[i
].center_freq
);
752 *pos
++ = 1; /* one channel in the subband*/
756 /* if present, add any custom IEs that go before HT */
757 if (assoc_data
->ie_len
) {
758 static const u8 before_ht
[] = {
761 WLAN_EID_EXT_SUPP_RATES
,
762 WLAN_EID_PWR_CAPABILITY
,
763 WLAN_EID_SUPPORTED_CHANNELS
,
766 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
767 WLAN_EID_MOBILITY_DOMAIN
,
768 WLAN_EID_FAST_BSS_TRANSITION
, /* reassoc only */
769 WLAN_EID_RIC_DATA
, /* reassoc only */
770 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
772 static const u8 after_ric
[] = {
773 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
774 WLAN_EID_HT_CAPABILITY
,
775 WLAN_EID_BSS_COEX_2040
,
776 /* luckily this is almost always there */
777 WLAN_EID_EXT_CAPABILITY
,
778 WLAN_EID_QOS_TRAFFIC_CAPA
,
779 WLAN_EID_TIM_BCAST_REQ
,
780 WLAN_EID_INTERWORKING
,
781 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
782 WLAN_EID_VHT_CAPABILITY
,
783 WLAN_EID_OPMODE_NOTIF
,
786 noffset
= ieee80211_ie_split_ric(assoc_data
->ie
,
789 ARRAY_SIZE(before_ht
),
791 ARRAY_SIZE(after_ric
),
793 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
797 if (WARN_ON_ONCE((ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
798 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)))
799 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
801 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
802 ieee80211_add_ht_ie(sdata
, skb
, assoc_data
->ap_ht_param
,
803 sband
, chan
, sdata
->smps_mode
);
805 /* if present, add any custom IEs that go before VHT */
806 if (assoc_data
->ie_len
) {
807 static const u8 before_vht
[] = {
809 * no need to list the ones split off before HT
812 WLAN_EID_BSS_COEX_2040
,
813 WLAN_EID_EXT_CAPABILITY
,
814 WLAN_EID_QOS_TRAFFIC_CAPA
,
815 WLAN_EID_TIM_BCAST_REQ
,
816 WLAN_EID_INTERWORKING
,
817 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
820 /* RIC already taken above, so no need to handle here anymore */
821 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
822 before_vht
, ARRAY_SIZE(before_vht
),
824 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
828 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
829 ieee80211_add_vht_ie(sdata
, skb
, sband
,
830 &assoc_data
->ap_vht_cap
);
832 /* if present, add any custom non-vendor IEs that go after HT */
833 if (assoc_data
->ie_len
) {
834 noffset
= ieee80211_ie_split_vendor(assoc_data
->ie
,
837 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
841 if (assoc_data
->wmm
) {
842 if (assoc_data
->uapsd
) {
843 qos_info
= ifmgd
->uapsd_queues
;
844 qos_info
|= (ifmgd
->uapsd_max_sp_len
<<
845 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
850 pos
= ieee80211_add_wmm_info_ie(skb_put(skb
, 9), qos_info
);
853 /* add any remaining custom (i.e. vendor specific here) IEs */
854 if (assoc_data
->ie_len
) {
855 noffset
= assoc_data
->ie_len
;
856 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
859 if (assoc_data
->fils_kek_len
&&
860 fils_encrypt_assoc_req(skb
, assoc_data
) < 0) {
865 drv_mgd_prepare_tx(local
, sdata
);
867 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
868 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
869 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
870 IEEE80211_TX_INTFL_MLME_CONN_TX
;
871 ieee80211_tx_skb(sdata
, skb
);
874 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
875 struct ieee80211_sub_if_data
*sdata
)
877 struct ieee80211_pspoll
*pspoll
;
880 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
884 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
885 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
887 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
888 ieee80211_tx_skb(sdata
, skb
);
891 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
892 struct ieee80211_sub_if_data
*sdata
,
896 struct ieee80211_hdr_3addr
*nullfunc
;
897 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
899 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
, true);
903 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
905 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
907 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
908 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
910 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
911 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
913 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
914 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
916 ieee80211_tx_skb(sdata
, skb
);
919 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
920 struct ieee80211_sub_if_data
*sdata
)
923 struct ieee80211_hdr
*nullfunc
;
926 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
929 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
933 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
935 nullfunc
= skb_put_zero(skb
, 30);
936 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
937 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
938 nullfunc
->frame_control
= fc
;
939 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
940 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
941 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
942 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
944 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
945 ieee80211_tx_skb(sdata
, skb
);
948 /* spectrum management related things */
949 static void ieee80211_chswitch_work(struct work_struct
*work
)
951 struct ieee80211_sub_if_data
*sdata
=
952 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
953 struct ieee80211_local
*local
= sdata
->local
;
954 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
957 if (!ieee80211_sdata_running(sdata
))
961 mutex_lock(&local
->mtx
);
962 mutex_lock(&local
->chanctx_mtx
);
964 if (!ifmgd
->associated
)
967 if (!sdata
->vif
.csa_active
)
971 * using reservation isn't immediate as it may be deferred until later
972 * with multi-vif. once reservation is complete it will re-schedule the
973 * work with no reserved_chanctx so verify chandef to check if it
974 * completed successfully
977 if (sdata
->reserved_chanctx
) {
978 struct ieee80211_supported_band
*sband
= NULL
;
979 struct sta_info
*mgd_sta
= NULL
;
980 enum ieee80211_sta_rx_bandwidth bw
= IEEE80211_STA_RX_BW_20
;
983 * with multi-vif csa driver may call ieee80211_csa_finish()
984 * many times while waiting for other interfaces to use their
987 if (sdata
->reserved_ready
)
990 if (sdata
->vif
.bss_conf
.chandef
.width
!=
991 sdata
->csa_chandef
.width
) {
993 * For managed interface, we need to also update the AP
994 * station bandwidth and align the rate scale algorithm
995 * on the bandwidth change. Here we only consider the
996 * bandwidth of the new channel definition (as channel
997 * switch flow does not have the full HT/VHT/HE
998 * information), assuming that if additional changes are
999 * required they would be done as part of the processing
1000 * of the next beacon from the AP.
1002 switch (sdata
->csa_chandef
.width
) {
1003 case NL80211_CHAN_WIDTH_20_NOHT
:
1004 case NL80211_CHAN_WIDTH_20
:
1006 bw
= IEEE80211_STA_RX_BW_20
;
1008 case NL80211_CHAN_WIDTH_40
:
1009 bw
= IEEE80211_STA_RX_BW_40
;
1011 case NL80211_CHAN_WIDTH_80
:
1012 bw
= IEEE80211_STA_RX_BW_80
;
1014 case NL80211_CHAN_WIDTH_80P80
:
1015 case NL80211_CHAN_WIDTH_160
:
1016 bw
= IEEE80211_STA_RX_BW_160
;
1020 mgd_sta
= sta_info_get(sdata
, ifmgd
->bssid
);
1022 local
->hw
.wiphy
->bands
[sdata
->csa_chandef
.chan
->band
];
1025 if (sdata
->vif
.bss_conf
.chandef
.width
>
1026 sdata
->csa_chandef
.width
) {
1027 mgd_sta
->sta
.bandwidth
= bw
;
1028 rate_control_rate_update(local
, sband
, mgd_sta
,
1029 IEEE80211_RC_BW_CHANGED
);
1032 ret
= ieee80211_vif_use_reserved_context(sdata
);
1035 "failed to use reserved channel context, disconnecting (err=%d)\n",
1037 ieee80211_queue_work(&sdata
->local
->hw
,
1038 &ifmgd
->csa_connection_drop_work
);
1042 if (sdata
->vif
.bss_conf
.chandef
.width
<
1043 sdata
->csa_chandef
.width
) {
1044 mgd_sta
->sta
.bandwidth
= bw
;
1045 rate_control_rate_update(local
, sband
, mgd_sta
,
1046 IEEE80211_RC_BW_CHANGED
);
1052 if (!cfg80211_chandef_identical(&sdata
->vif
.bss_conf
.chandef
,
1053 &sdata
->csa_chandef
)) {
1055 "failed to finalize channel switch, disconnecting\n");
1056 ieee80211_queue_work(&sdata
->local
->hw
,
1057 &ifmgd
->csa_connection_drop_work
);
1061 /* XXX: shouldn't really modify cfg80211-owned data! */
1062 ifmgd
->associated
->channel
= sdata
->csa_chandef
.chan
;
1064 ifmgd
->csa_waiting_bcn
= true;
1066 ieee80211_sta_reset_beacon_monitor(sdata
);
1067 ieee80211_sta_reset_conn_monitor(sdata
);
1070 mutex_unlock(&local
->chanctx_mtx
);
1071 mutex_unlock(&local
->mtx
);
1072 sdata_unlock(sdata
);
1075 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data
*sdata
)
1077 struct ieee80211_local
*local
= sdata
->local
;
1078 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1081 sdata_assert_lock(sdata
);
1083 WARN_ON(!sdata
->vif
.csa_active
);
1085 if (sdata
->csa_block_tx
) {
1086 ieee80211_wake_vif_queues(local
, sdata
,
1087 IEEE80211_QUEUE_STOP_REASON_CSA
);
1088 sdata
->csa_block_tx
= false;
1091 sdata
->vif
.csa_active
= false;
1092 ifmgd
->csa_waiting_bcn
= false;
1094 ret
= drv_post_channel_switch(sdata
);
1097 "driver post channel switch failed, disconnecting\n");
1098 ieee80211_queue_work(&local
->hw
,
1099 &ifmgd
->csa_connection_drop_work
);
1103 cfg80211_ch_switch_notify(sdata
->dev
, &sdata
->reserved_chandef
);
1106 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
1108 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1109 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1111 trace_api_chswitch_done(sdata
, success
);
1114 "driver channel switch failed, disconnecting\n");
1115 ieee80211_queue_work(&sdata
->local
->hw
,
1116 &ifmgd
->csa_connection_drop_work
);
1118 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
1121 EXPORT_SYMBOL(ieee80211_chswitch_done
);
1123 static void ieee80211_chswitch_timer(struct timer_list
*t
)
1125 struct ieee80211_sub_if_data
*sdata
=
1126 from_timer(sdata
, t
, u
.mgd
.chswitch_timer
);
1128 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->u
.mgd
.chswitch_work
);
1132 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
1133 u64 timestamp
, u32 device_timestamp
,
1134 struct ieee802_11_elems
*elems
,
1137 struct ieee80211_local
*local
= sdata
->local
;
1138 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1139 struct cfg80211_bss
*cbss
= ifmgd
->associated
;
1140 struct ieee80211_chanctx_conf
*conf
;
1141 struct ieee80211_chanctx
*chanctx
;
1142 enum nl80211_band current_band
;
1143 struct ieee80211_csa_ie csa_ie
;
1144 struct ieee80211_channel_switch ch_switch
;
1147 sdata_assert_lock(sdata
);
1152 if (local
->scanning
)
1155 /* disregard subsequent announcements if we are already processing */
1156 if (sdata
->vif
.csa_active
)
1159 current_band
= cbss
->channel
->band
;
1160 res
= ieee80211_parse_ch_switch_ie(sdata
, elems
, current_band
,
1162 ifmgd
->associated
->bssid
, &csa_ie
);
1164 ieee80211_queue_work(&local
->hw
,
1165 &ifmgd
->csa_connection_drop_work
);
1169 if (!cfg80211_chandef_usable(local
->hw
.wiphy
, &csa_ie
.chandef
,
1170 IEEE80211_CHAN_DISABLED
)) {
1172 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1173 ifmgd
->associated
->bssid
,
1174 csa_ie
.chandef
.chan
->center_freq
,
1175 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1176 csa_ie
.chandef
.center_freq2
);
1177 ieee80211_queue_work(&local
->hw
,
1178 &ifmgd
->csa_connection_drop_work
);
1182 if (cfg80211_chandef_identical(&csa_ie
.chandef
,
1183 &sdata
->vif
.bss_conf
.chandef
)) {
1184 if (ifmgd
->csa_ignored_same_chan
)
1187 "AP %pM tries to chanswitch to same channel, ignore\n",
1188 ifmgd
->associated
->bssid
);
1189 ifmgd
->csa_ignored_same_chan
= true;
1194 * Drop all TDLS peers - either we disconnect or move to a different
1195 * channel from this point on. There's no telling what our peer will do.
1196 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1197 * have an incompatible wider chandef.
1199 ieee80211_teardown_tdls_peers(sdata
);
1201 mutex_lock(&local
->mtx
);
1202 mutex_lock(&local
->chanctx_mtx
);
1203 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1204 lockdep_is_held(&local
->chanctx_mtx
));
1207 "no channel context assigned to vif?, disconnecting\n");
1208 goto drop_connection
;
1211 chanctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1213 if (local
->use_chanctx
&&
1214 !ieee80211_hw_check(&local
->hw
, CHANCTX_STA_CSA
)) {
1216 "driver doesn't support chan-switch with channel contexts\n");
1217 goto drop_connection
;
1220 ch_switch
.timestamp
= timestamp
;
1221 ch_switch
.device_timestamp
= device_timestamp
;
1222 ch_switch
.block_tx
= csa_ie
.mode
;
1223 ch_switch
.chandef
= csa_ie
.chandef
;
1224 ch_switch
.count
= csa_ie
.count
;
1226 if (drv_pre_channel_switch(sdata
, &ch_switch
)) {
1228 "preparing for channel switch failed, disconnecting\n");
1229 goto drop_connection
;
1232 res
= ieee80211_vif_reserve_chanctx(sdata
, &csa_ie
.chandef
,
1233 chanctx
->mode
, false);
1236 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1238 goto drop_connection
;
1240 mutex_unlock(&local
->chanctx_mtx
);
1242 sdata
->vif
.csa_active
= true;
1243 sdata
->csa_chandef
= csa_ie
.chandef
;
1244 sdata
->csa_block_tx
= csa_ie
.mode
;
1245 ifmgd
->csa_ignored_same_chan
= false;
1247 if (sdata
->csa_block_tx
)
1248 ieee80211_stop_vif_queues(local
, sdata
,
1249 IEEE80211_QUEUE_STOP_REASON_CSA
);
1250 mutex_unlock(&local
->mtx
);
1252 cfg80211_ch_switch_started_notify(sdata
->dev
, &csa_ie
.chandef
,
1255 if (local
->ops
->channel_switch
) {
1256 /* use driver's channel switch callback */
1257 drv_channel_switch(local
, sdata
, &ch_switch
);
1261 /* channel switch handled in software */
1262 if (csa_ie
.count
<= 1)
1263 ieee80211_queue_work(&local
->hw
, &ifmgd
->chswitch_work
);
1265 mod_timer(&ifmgd
->chswitch_timer
,
1266 TU_TO_EXP_TIME((csa_ie
.count
- 1) *
1267 cbss
->beacon_interval
));
1271 * This is just so that the disconnect flow will know that
1272 * we were trying to switch channel and failed. In case the
1273 * mode is 1 (we are not allowed to Tx), we will know not to
1274 * send a deauthentication frame. Those two fields will be
1275 * reset when the disconnection worker runs.
1277 sdata
->vif
.csa_active
= true;
1278 sdata
->csa_block_tx
= csa_ie
.mode
;
1280 ieee80211_queue_work(&local
->hw
, &ifmgd
->csa_connection_drop_work
);
1281 mutex_unlock(&local
->chanctx_mtx
);
1282 mutex_unlock(&local
->mtx
);
1286 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1287 struct ieee80211_channel
*channel
,
1288 const u8
*country_ie
, u8 country_ie_len
,
1289 const u8
*pwr_constr_elem
,
1290 int *chan_pwr
, int *pwr_reduction
)
1292 struct ieee80211_country_ie_triplet
*triplet
;
1293 int chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1294 int i
, chan_increment
;
1295 bool have_chan_pwr
= false;
1298 if (country_ie_len
% 2 || country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1301 triplet
= (void *)(country_ie
+ 3);
1302 country_ie_len
-= 3;
1304 switch (channel
->band
) {
1308 case NL80211_BAND_2GHZ
:
1309 case NL80211_BAND_60GHZ
:
1312 case NL80211_BAND_5GHZ
:
1318 while (country_ie_len
>= 3) {
1319 u8 first_channel
= triplet
->chans
.first_channel
;
1321 if (first_channel
>= IEEE80211_COUNTRY_EXTENSION_ID
)
1324 for (i
= 0; i
< triplet
->chans
.num_channels
; i
++) {
1325 if (first_channel
+ i
* chan_increment
== chan
) {
1326 have_chan_pwr
= true;
1327 *chan_pwr
= triplet
->chans
.max_power
;
1336 country_ie_len
-= 3;
1339 if (have_chan_pwr
&& pwr_constr_elem
)
1340 *pwr_reduction
= *pwr_constr_elem
;
1344 return have_chan_pwr
;
1347 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data
*sdata
,
1348 struct ieee80211_channel
*channel
,
1349 const u8
*cisco_dtpc_ie
,
1352 /* From practical testing, the first data byte of the DTPC element
1353 * seems to contain the requested dBm level, and the CLI on Cisco
1354 * APs clearly state the range is -127 to 127 dBm, which indicates
1355 * a signed byte, although it seemingly never actually goes negative.
1356 * The other byte seems to always be zero.
1358 *pwr_level
= (__s8
)cisco_dtpc_ie
[4];
1361 static u32
ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1362 struct ieee80211_channel
*channel
,
1363 struct ieee80211_mgmt
*mgmt
,
1364 const u8
*country_ie
, u8 country_ie_len
,
1365 const u8
*pwr_constr_ie
,
1366 const u8
*cisco_dtpc_ie
)
1368 bool has_80211h_pwr
= false, has_cisco_pwr
= false;
1369 int chan_pwr
= 0, pwr_reduction_80211h
= 0;
1370 int pwr_level_cisco
, pwr_level_80211h
;
1372 __le16 capab
= mgmt
->u
.probe_resp
.capab_info
;
1375 (capab
& cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT
) ||
1376 capab
& cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE
))) {
1377 has_80211h_pwr
= ieee80211_find_80211h_pwr_constr(
1378 sdata
, channel
, country_ie
, country_ie_len
,
1379 pwr_constr_ie
, &chan_pwr
, &pwr_reduction_80211h
);
1381 max_t(int, 0, chan_pwr
- pwr_reduction_80211h
);
1384 if (cisco_dtpc_ie
) {
1385 ieee80211_find_cisco_dtpc(
1386 sdata
, channel
, cisco_dtpc_ie
, &pwr_level_cisco
);
1387 has_cisco_pwr
= true;
1390 if (!has_80211h_pwr
&& !has_cisco_pwr
)
1393 /* If we have both 802.11h and Cisco DTPC, apply both limits
1394 * by picking the smallest of the two power levels advertised.
1396 if (has_80211h_pwr
&&
1397 (!has_cisco_pwr
|| pwr_level_80211h
<= pwr_level_cisco
)) {
1398 new_ap_level
= pwr_level_80211h
;
1400 if (sdata
->ap_power_level
== new_ap_level
)
1404 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1405 pwr_level_80211h
, chan_pwr
, pwr_reduction_80211h
,
1406 sdata
->u
.mgd
.bssid
);
1407 } else { /* has_cisco_pwr is always true here. */
1408 new_ap_level
= pwr_level_cisco
;
1410 if (sdata
->ap_power_level
== new_ap_level
)
1414 "Limiting TX power to %d dBm as advertised by %pM\n",
1415 pwr_level_cisco
, sdata
->u
.mgd
.bssid
);
1418 sdata
->ap_power_level
= new_ap_level
;
1419 if (__ieee80211_recalc_txpower(sdata
))
1420 return BSS_CHANGED_TXPOWER
;
1425 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
1426 struct ieee80211_sub_if_data
*sdata
)
1428 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1431 * If we are scanning right now then the parameters will
1432 * take effect when scan finishes.
1434 if (local
->scanning
)
1437 if (conf
->dynamic_ps_timeout
> 0 &&
1438 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
)) {
1439 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1440 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
1442 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
1443 ieee80211_send_nullfunc(local
, sdata
, true);
1445 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1446 ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1449 conf
->flags
|= IEEE80211_CONF_PS
;
1450 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1454 static void ieee80211_change_ps(struct ieee80211_local
*local
)
1456 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1458 if (local
->ps_sdata
) {
1459 ieee80211_enable_ps(local
, local
->ps_sdata
);
1460 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
1461 conf
->flags
&= ~IEEE80211_CONF_PS
;
1462 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1463 del_timer_sync(&local
->dynamic_ps_timer
);
1464 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1468 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
1470 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
1471 struct sta_info
*sta
= NULL
;
1472 bool authorized
= false;
1474 if (!mgd
->powersave
)
1480 if (!mgd
->associated
)
1483 if (mgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1486 if (!mgd
->have_beacon
)
1490 sta
= sta_info_get(sdata
, mgd
->bssid
);
1492 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
1498 /* need to hold RTNL or interface lock */
1499 void ieee80211_recalc_ps(struct ieee80211_local
*local
)
1501 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
1505 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
)) {
1506 local
->ps_sdata
= NULL
;
1510 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1511 if (!ieee80211_sdata_running(sdata
))
1513 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1514 /* If an AP vif is found, then disable PS
1515 * by setting the count to zero thereby setting
1521 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1527 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
1528 u8 dtimper
= found
->u
.mgd
.dtim_period
;
1530 timeout
= local
->dynamic_ps_forced_timeout
;
1533 local
->hw
.conf
.dynamic_ps_timeout
= timeout
;
1535 /* If the TIM IE is invalid, pretend the value is 1 */
1539 local
->hw
.conf
.ps_dtim_period
= dtimper
;
1540 local
->ps_sdata
= found
;
1542 local
->ps_sdata
= NULL
;
1545 ieee80211_change_ps(local
);
1548 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data
*sdata
)
1550 bool ps_allowed
= ieee80211_powersave_allowed(sdata
);
1552 if (sdata
->vif
.bss_conf
.ps
!= ps_allowed
) {
1553 sdata
->vif
.bss_conf
.ps
= ps_allowed
;
1554 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_PS
);
1558 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
1560 struct ieee80211_local
*local
=
1561 container_of(work
, struct ieee80211_local
,
1562 dynamic_ps_disable_work
);
1564 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1565 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1566 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1569 ieee80211_wake_queues_by_reason(&local
->hw
,
1570 IEEE80211_MAX_QUEUE_MAP
,
1571 IEEE80211_QUEUE_STOP_REASON_PS
,
1575 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
1577 struct ieee80211_local
*local
=
1578 container_of(work
, struct ieee80211_local
,
1579 dynamic_ps_enable_work
);
1580 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
1581 struct ieee80211_if_managed
*ifmgd
;
1582 unsigned long flags
;
1585 /* can only happen when PS was just disabled anyway */
1589 ifmgd
= &sdata
->u
.mgd
;
1591 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
1594 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1595 /* don't enter PS if TX frames are pending */
1596 if (drv_tx_frames_pending(local
)) {
1597 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1599 local
->hw
.conf
.dynamic_ps_timeout
));
1604 * transmission can be stopped by others which leads to
1605 * dynamic_ps_timer expiry. Postpone the ps timer if it
1606 * is not the actual idle state.
1608 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1609 for (q
= 0; q
< local
->hw
.queues
; q
++) {
1610 if (local
->queue_stop_reasons
[q
]) {
1611 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1613 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1615 local
->hw
.conf
.dynamic_ps_timeout
));
1619 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1622 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1623 !(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1624 if (drv_tx_frames_pending(local
)) {
1625 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1627 local
->hw
.conf
.dynamic_ps_timeout
));
1629 ieee80211_send_nullfunc(local
, sdata
, true);
1630 /* Flush to get the tx status of nullfunc frame */
1631 ieee80211_flush_queues(local
, sdata
, false);
1635 if (!(ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
) &&
1636 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
)) ||
1637 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1638 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
1639 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
1640 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1644 void ieee80211_dynamic_ps_timer(struct timer_list
*t
)
1646 struct ieee80211_local
*local
= from_timer(local
, t
, dynamic_ps_timer
);
1648 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
1651 void ieee80211_dfs_cac_timer_work(struct work_struct
*work
)
1653 struct delayed_work
*delayed_work
= to_delayed_work(work
);
1654 struct ieee80211_sub_if_data
*sdata
=
1655 container_of(delayed_work
, struct ieee80211_sub_if_data
,
1656 dfs_cac_timer_work
);
1657 struct cfg80211_chan_def chandef
= sdata
->vif
.bss_conf
.chandef
;
1659 mutex_lock(&sdata
->local
->mtx
);
1660 if (sdata
->wdev
.cac_started
) {
1661 ieee80211_vif_release_channel(sdata
);
1662 cfg80211_cac_event(sdata
->dev
, &chandef
,
1663 NL80211_RADAR_CAC_FINISHED
,
1666 mutex_unlock(&sdata
->local
->mtx
);
1670 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1672 struct ieee80211_local
*local
= sdata
->local
;
1673 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1677 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1680 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1681 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
1683 unsigned long now
= jiffies
;
1685 if (tx_tspec
->action
== TX_TSPEC_ACTION_NONE
&&
1686 tx_tspec
->admitted_time
&&
1687 time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1688 tx_tspec
->consumed_tx_time
= 0;
1689 tx_tspec
->time_slice_start
= now
;
1691 if (tx_tspec
->downgraded
)
1693 TX_TSPEC_ACTION_STOP_DOWNGRADE
;
1696 switch (tx_tspec
->action
) {
1697 case TX_TSPEC_ACTION_STOP_DOWNGRADE
:
1698 /* take the original parameters */
1699 if (drv_conf_tx(local
, sdata
, ac
, &sdata
->tx_conf
[ac
]))
1701 "failed to set TX queue parameters for queue %d\n",
1703 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1704 tx_tspec
->downgraded
= false;
1707 case TX_TSPEC_ACTION_DOWNGRADE
:
1708 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1709 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1713 /* downgrade next lower non-ACM AC */
1714 for (non_acm_ac
= ac
+ 1;
1715 non_acm_ac
< IEEE80211_NUM_ACS
;
1717 if (!(sdata
->wmm_acm
& BIT(7 - 2 * non_acm_ac
)))
1719 /* Usually the loop will result in using BK even if it
1720 * requires admission control, but such a configuration
1721 * makes no sense and we have to transmit somehow - the
1722 * AC selection does the same thing.
1723 * If we started out trying to downgrade from BK, then
1724 * the extra condition here might be needed.
1726 if (non_acm_ac
>= IEEE80211_NUM_ACS
)
1727 non_acm_ac
= IEEE80211_AC_BK
;
1728 if (drv_conf_tx(local
, sdata
, ac
,
1729 &sdata
->tx_conf
[non_acm_ac
]))
1731 "failed to set TX queue parameters for queue %d\n",
1733 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1735 schedule_delayed_work(&ifmgd
->tx_tspec_wk
,
1736 tx_tspec
->time_slice_start
+ HZ
- now
+ 1);
1738 case TX_TSPEC_ACTION_NONE
:
1747 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1749 if (__ieee80211_sta_handle_tspec_ac_params(sdata
))
1750 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
1753 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct
*work
)
1755 struct ieee80211_sub_if_data
*sdata
;
1757 sdata
= container_of(work
, struct ieee80211_sub_if_data
,
1758 u
.mgd
.tx_tspec_wk
.work
);
1759 ieee80211_sta_handle_tspec_ac_params(sdata
);
1763 static bool ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
1764 struct ieee80211_sub_if_data
*sdata
,
1765 const u8
*wmm_param
, size_t wmm_param_len
)
1767 struct ieee80211_tx_queue_params params
[IEEE80211_NUM_ACS
];
1768 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1772 u8 uapsd_queues
= 0;
1774 if (!local
->ops
->conf_tx
)
1777 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1783 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
1786 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
1787 uapsd_queues
= ifmgd
->uapsd_queues
;
1789 count
= wmm_param
[6] & 0x0f;
1790 if (count
== ifmgd
->wmm_last_param_set
)
1792 ifmgd
->wmm_last_param_set
= count
;
1794 pos
= wmm_param
+ 8;
1795 left
= wmm_param_len
- 8;
1797 memset(¶ms
, 0, sizeof(params
));
1800 for (; left
>= 4; left
-= 4, pos
+= 4) {
1801 int aci
= (pos
[0] >> 5) & 0x03;
1802 int acm
= (pos
[0] >> 4) & 0x01;
1807 ac
= IEEE80211_AC_BK
;
1809 sdata
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
1810 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1814 ac
= IEEE80211_AC_VI
;
1816 sdata
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
1817 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1821 ac
= IEEE80211_AC_VO
;
1823 sdata
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
1824 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1829 ac
= IEEE80211_AC_BE
;
1831 sdata
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
1832 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1837 params
[ac
].aifs
= pos
[0] & 0x0f;
1839 if (params
[ac
].aifs
< 2) {
1841 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
1842 params
[ac
].aifs
, aci
);
1843 params
[ac
].aifs
= 2;
1845 params
[ac
].cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
1846 params
[ac
].cw_min
= ecw2cw(pos
[1] & 0x0f);
1847 params
[ac
].txop
= get_unaligned_le16(pos
+ 2);
1848 params
[ac
].acm
= acm
;
1849 params
[ac
].uapsd
= uapsd
;
1851 if (params
->cw_min
== 0 ||
1852 params
[ac
].cw_min
> params
[ac
].cw_max
) {
1854 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1855 params
[ac
].cw_min
, params
[ac
].cw_max
, aci
);
1860 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1862 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1864 params
[ac
].aifs
, params
[ac
].cw_min
, params
[ac
].cw_max
,
1865 params
[ac
].txop
, params
[ac
].uapsd
,
1866 ifmgd
->tx_tspec
[ac
].downgraded
);
1867 sdata
->tx_conf
[ac
] = params
[ac
];
1868 if (!ifmgd
->tx_tspec
[ac
].downgraded
&&
1869 drv_conf_tx(local
, sdata
, ac
, ¶ms
[ac
]))
1871 "failed to set TX queue parameters for AC %d\n",
1875 /* enable WMM or activate new settings */
1876 sdata
->vif
.bss_conf
.qos
= true;
1880 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1882 lockdep_assert_held(&sdata
->local
->mtx
);
1884 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_CONNECTION_POLL
;
1885 ieee80211_run_deferred_scan(sdata
->local
);
1888 static void ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1890 mutex_lock(&sdata
->local
->mtx
);
1891 __ieee80211_stop_poll(sdata
);
1892 mutex_unlock(&sdata
->local
->mtx
);
1895 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
1896 u16 capab
, bool erp_valid
, u8 erp
)
1898 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1899 struct ieee80211_supported_band
*sband
;
1901 bool use_protection
;
1902 bool use_short_preamble
;
1903 bool use_short_slot
;
1905 sband
= ieee80211_get_sband(sdata
);
1910 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
1911 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
1913 use_protection
= false;
1914 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
1917 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1918 if (sband
->band
== NL80211_BAND_5GHZ
)
1919 use_short_slot
= true;
1921 if (use_protection
!= bss_conf
->use_cts_prot
) {
1922 bss_conf
->use_cts_prot
= use_protection
;
1923 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1926 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
1927 bss_conf
->use_short_preamble
= use_short_preamble
;
1928 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1931 if (use_short_slot
!= bss_conf
->use_short_slot
) {
1932 bss_conf
->use_short_slot
= use_short_slot
;
1933 changed
|= BSS_CHANGED_ERP_SLOT
;
1939 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
1940 struct cfg80211_bss
*cbss
,
1941 u32 bss_info_changed
)
1943 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
1944 struct ieee80211_local
*local
= sdata
->local
;
1945 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1947 bss_info_changed
|= BSS_CHANGED_ASSOC
;
1948 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
1949 bss_conf
->assoc_capability
, bss
->has_erp_value
, bss
->erp_value
);
1951 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
1952 beacon_loss_count
* bss_conf
->beacon_int
));
1954 sdata
->u
.mgd
.associated
= cbss
;
1955 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
1957 ieee80211_check_rate_mask(sdata
);
1959 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
1961 if (sdata
->vif
.p2p
||
1962 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
1963 const struct cfg80211_bss_ies
*ies
;
1966 ies
= rcu_dereference(cbss
->ies
);
1970 ret
= cfg80211_get_p2p_attr(
1971 ies
->data
, ies
->len
,
1972 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
1973 (u8
*) &bss_conf
->p2p_noa_attr
,
1974 sizeof(bss_conf
->p2p_noa_attr
));
1976 sdata
->u
.mgd
.p2p_noa_index
=
1977 bss_conf
->p2p_noa_attr
.index
;
1978 bss_info_changed
|= BSS_CHANGED_P2P_PS
;
1984 /* just to be sure */
1985 ieee80211_stop_poll(sdata
);
1987 ieee80211_led_assoc(local
, 1);
1989 if (sdata
->u
.mgd
.have_beacon
) {
1991 * If the AP is buggy we may get here with no DTIM period
1992 * known, so assume it's 1 which is the only safe assumption
1993 * in that case, although if the TIM IE is broken powersave
1994 * probably just won't work at all.
1996 bss_conf
->dtim_period
= sdata
->u
.mgd
.dtim_period
?: 1;
1997 bss_conf
->beacon_rate
= bss
->beacon_rate
;
1998 bss_info_changed
|= BSS_CHANGED_BEACON_INFO
;
2000 bss_conf
->beacon_rate
= NULL
;
2001 bss_conf
->dtim_period
= 0;
2004 bss_conf
->assoc
= 1;
2006 /* Tell the driver to monitor connection quality (if supported) */
2007 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
&&
2008 bss_conf
->cqm_rssi_thold
)
2009 bss_info_changed
|= BSS_CHANGED_CQM
;
2011 /* Enable ARP filtering */
2012 if (bss_conf
->arp_addr_cnt
)
2013 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
2015 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
2017 mutex_lock(&local
->iflist_mtx
);
2018 ieee80211_recalc_ps(local
);
2019 mutex_unlock(&local
->iflist_mtx
);
2021 ieee80211_recalc_smps(sdata
);
2022 ieee80211_recalc_ps_vif(sdata
);
2024 netif_carrier_on(sdata
->dev
);
2027 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
2028 u16 stype
, u16 reason
, bool tx
,
2031 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2032 struct ieee80211_local
*local
= sdata
->local
;
2035 sdata_assert_lock(sdata
);
2037 if (WARN_ON_ONCE(tx
&& !frame_buf
))
2040 if (WARN_ON(!ifmgd
->associated
))
2043 ieee80211_stop_poll(sdata
);
2045 ifmgd
->associated
= NULL
;
2046 netif_carrier_off(sdata
->dev
);
2049 * if we want to get out of ps before disassoc (why?) we have
2050 * to do it before sending disassoc, as otherwise the null-packet
2053 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
2054 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
2055 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
2057 local
->ps_sdata
= NULL
;
2059 /* disable per-vif ps */
2060 ieee80211_recalc_ps_vif(sdata
);
2062 /* make sure ongoing transmission finishes */
2066 * drop any frame before deauth/disassoc, this can be data or
2067 * management frame. Since we are disconnecting, we should not
2068 * insist sending these frames which can take time and delay
2069 * the disconnection and possible the roaming.
2072 ieee80211_flush_queues(local
, sdata
, true);
2074 /* deauthenticate/disassociate now */
2075 if (tx
|| frame_buf
)
2076 ieee80211_send_deauth_disassoc(sdata
, ifmgd
->bssid
, stype
,
2077 reason
, tx
, frame_buf
);
2079 /* flush out frame - make sure the deauth was actually sent */
2081 ieee80211_flush_queues(local
, sdata
, false);
2083 /* clear bssid only after building the needed mgmt frames */
2084 eth_zero_addr(ifmgd
->bssid
);
2086 /* remove AP and TDLS peers */
2087 sta_info_flush(sdata
);
2089 /* finally reset all BSS / config parameters */
2090 changed
|= ieee80211_reset_erp_info(sdata
);
2092 ieee80211_led_assoc(local
, 0);
2093 changed
|= BSS_CHANGED_ASSOC
;
2094 sdata
->vif
.bss_conf
.assoc
= false;
2096 ifmgd
->p2p_noa_index
= -1;
2097 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
2098 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
2100 /* on the next assoc, re-program HT/VHT parameters */
2101 memset(&ifmgd
->ht_capa
, 0, sizeof(ifmgd
->ht_capa
));
2102 memset(&ifmgd
->ht_capa_mask
, 0, sizeof(ifmgd
->ht_capa_mask
));
2103 memset(&ifmgd
->vht_capa
, 0, sizeof(ifmgd
->vht_capa
));
2104 memset(&ifmgd
->vht_capa_mask
, 0, sizeof(ifmgd
->vht_capa_mask
));
2106 /* reset MU-MIMO ownership and group data */
2107 memset(sdata
->vif
.bss_conf
.mu_group
.membership
, 0,
2108 sizeof(sdata
->vif
.bss_conf
.mu_group
.membership
));
2109 memset(sdata
->vif
.bss_conf
.mu_group
.position
, 0,
2110 sizeof(sdata
->vif
.bss_conf
.mu_group
.position
));
2111 changed
|= BSS_CHANGED_MU_GROUPS
;
2112 sdata
->vif
.mu_mimo_owner
= false;
2114 sdata
->ap_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2116 del_timer_sync(&local
->dynamic_ps_timer
);
2117 cancel_work_sync(&local
->dynamic_ps_enable_work
);
2119 /* Disable ARP filtering */
2120 if (sdata
->vif
.bss_conf
.arp_addr_cnt
)
2121 changed
|= BSS_CHANGED_ARP_FILTER
;
2123 sdata
->vif
.bss_conf
.qos
= false;
2124 changed
|= BSS_CHANGED_QOS
;
2126 /* The BSSID (not really interesting) and HT changed */
2127 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
2128 ieee80211_bss_info_change_notify(sdata
, changed
);
2130 /* disassociated - set to defaults now */
2131 ieee80211_set_wmm_default(sdata
, false, false);
2133 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
2134 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
2135 del_timer_sync(&sdata
->u
.mgd
.timer
);
2136 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
2138 sdata
->vif
.bss_conf
.dtim_period
= 0;
2139 sdata
->vif
.bss_conf
.beacon_rate
= NULL
;
2141 ifmgd
->have_beacon
= false;
2144 mutex_lock(&local
->mtx
);
2145 ieee80211_vif_release_channel(sdata
);
2147 sdata
->vif
.csa_active
= false;
2148 ifmgd
->csa_waiting_bcn
= false;
2149 ifmgd
->csa_ignored_same_chan
= false;
2150 if (sdata
->csa_block_tx
) {
2151 ieee80211_wake_vif_queues(local
, sdata
,
2152 IEEE80211_QUEUE_STOP_REASON_CSA
);
2153 sdata
->csa_block_tx
= false;
2155 mutex_unlock(&local
->mtx
);
2157 /* existing TX TSPEC sessions no longer exist */
2158 memset(ifmgd
->tx_tspec
, 0, sizeof(ifmgd
->tx_tspec
));
2159 cancel_delayed_work_sync(&ifmgd
->tx_tspec_wk
);
2161 sdata
->encrypt_headroom
= IEEE80211_ENCRYPT_HEADROOM
;
2164 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data
*sdata
,
2165 struct ieee80211_hdr
*hdr
)
2168 * We can postpone the mgd.timer whenever receiving unicast frames
2169 * from AP because we know that the connection is working both ways
2170 * at that time. But multicast frames (and hence also beacons) must
2171 * be ignored here, because we need to trigger the timer during
2172 * data idle periods for sending the periodic probe request to the
2173 * AP we're connected to.
2175 if (is_multicast_ether_addr(hdr
->addr1
))
2178 ieee80211_sta_reset_conn_monitor(sdata
);
2181 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
2183 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2184 struct ieee80211_local
*local
= sdata
->local
;
2186 mutex_lock(&local
->mtx
);
2187 if (!(ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
))
2190 __ieee80211_stop_poll(sdata
);
2192 mutex_lock(&local
->iflist_mtx
);
2193 ieee80211_recalc_ps(local
);
2194 mutex_unlock(&local
->iflist_mtx
);
2196 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
2200 * We've received a probe response, but are not sure whether
2201 * we have or will be receiving any beacons or data, so let's
2202 * schedule the timers again, just in case.
2204 ieee80211_sta_reset_beacon_monitor(sdata
);
2206 mod_timer(&ifmgd
->conn_mon_timer
,
2207 round_jiffies_up(jiffies
+
2208 IEEE80211_CONNECTION_IDLE_TIME
));
2210 mutex_unlock(&local
->mtx
);
2213 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data
*sdata
,
2214 struct ieee80211_hdr
*hdr
,
2217 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2218 u16 tid
= *ieee80211_get_qos_ctl(hdr
) & IEEE80211_QOS_CTL_TID_MASK
;
2219 int ac
= ieee80211_ac_from_tid(tid
);
2220 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
2221 unsigned long now
= jiffies
;
2223 if (likely(!tx_tspec
->admitted_time
))
2226 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
2227 tx_tspec
->consumed_tx_time
= 0;
2228 tx_tspec
->time_slice_start
= now
;
2230 if (tx_tspec
->downgraded
) {
2231 tx_tspec
->action
= TX_TSPEC_ACTION_STOP_DOWNGRADE
;
2232 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2236 if (tx_tspec
->downgraded
)
2239 tx_tspec
->consumed_tx_time
+= tx_time
;
2241 if (tx_tspec
->consumed_tx_time
>= tx_tspec
->admitted_time
) {
2242 tx_tspec
->downgraded
= true;
2243 tx_tspec
->action
= TX_TSPEC_ACTION_DOWNGRADE
;
2244 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2248 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
2249 struct ieee80211_hdr
*hdr
, bool ack
, u16 tx_time
)
2251 ieee80211_sta_tx_wmm_ac_notify(sdata
, hdr
, tx_time
);
2253 if (!ieee80211_is_data(hdr
->frame_control
))
2256 if (ieee80211_is_nullfunc(hdr
->frame_control
) &&
2257 sdata
->u
.mgd
.probe_send_count
> 0) {
2259 ieee80211_sta_reset_conn_monitor(sdata
);
2261 sdata
->u
.mgd
.nullfunc_failed
= true;
2262 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
2267 ieee80211_sta_reset_conn_monitor(sdata
);
2270 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
2272 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2274 u8
*dst
= ifmgd
->associated
->bssid
;
2275 u8 unicast_limit
= max(1, max_probe_tries
- 3);
2276 struct sta_info
*sta
;
2279 * Try sending broadcast probe requests for the last three
2280 * probe requests after the first ones failed since some
2281 * buggy APs only support broadcast probe requests.
2283 if (ifmgd
->probe_send_count
>= unicast_limit
)
2287 * When the hardware reports an accurate Tx ACK status, it's
2288 * better to send a nullfunc frame instead of a probe request,
2289 * as it will kick us off the AP quickly if we aren't associated
2290 * anymore. The timeout will be reset if the frame is ACKed by
2293 ifmgd
->probe_send_count
++;
2296 mutex_lock(&sdata
->local
->sta_mtx
);
2297 sta
= sta_info_get(sdata
, dst
);
2299 ieee80211_check_fast_rx(sta
);
2300 mutex_unlock(&sdata
->local
->sta_mtx
);
2303 if (ieee80211_hw_check(&sdata
->local
->hw
, REPORTS_TX_ACK_STATUS
)) {
2304 ifmgd
->nullfunc_failed
= false;
2305 ieee80211_send_nullfunc(sdata
->local
, sdata
, false);
2310 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
2311 if (WARN_ON_ONCE(ssid
== NULL
))
2316 ieee80211_send_probe_req(sdata
, sdata
->vif
.addr
, dst
,
2317 ssid
+ 2, ssid_len
, NULL
,
2318 0, (u32
) -1, true, 0,
2319 ifmgd
->associated
->channel
, false);
2323 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
2324 run_again(sdata
, ifmgd
->probe_timeout
);
2327 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
2330 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2331 bool already
= false;
2333 if (!ieee80211_sdata_running(sdata
))
2338 if (!ifmgd
->associated
)
2341 mutex_lock(&sdata
->local
->mtx
);
2343 if (sdata
->local
->tmp_channel
|| sdata
->local
->scanning
) {
2344 mutex_unlock(&sdata
->local
->mtx
);
2349 mlme_dbg_ratelimited(sdata
,
2350 "detected beacon loss from AP (missed %d beacons) - probing\n",
2353 ieee80211_cqm_beacon_loss_notify(&sdata
->vif
, GFP_KERNEL
);
2357 * The driver/our work has already reported this event or the
2358 * connection monitoring has kicked in and we have already sent
2359 * a probe request. Or maybe the AP died and the driver keeps
2360 * reporting until we disassociate...
2362 * In either case we have to ignore the current call to this
2363 * function (except for setting the correct probe reason bit)
2364 * because otherwise we would reset the timer every time and
2365 * never check whether we received a probe response!
2367 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
2370 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
2372 mutex_unlock(&sdata
->local
->mtx
);
2377 mutex_lock(&sdata
->local
->iflist_mtx
);
2378 ieee80211_recalc_ps(sdata
->local
);
2379 mutex_unlock(&sdata
->local
->iflist_mtx
);
2381 ifmgd
->probe_send_count
= 0;
2382 ieee80211_mgd_probe_ap_send(sdata
);
2384 sdata_unlock(sdata
);
2387 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
2388 struct ieee80211_vif
*vif
)
2390 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2391 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2392 struct cfg80211_bss
*cbss
;
2393 struct sk_buff
*skb
;
2397 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2400 sdata_assert_lock(sdata
);
2402 if (ifmgd
->associated
)
2403 cbss
= ifmgd
->associated
;
2404 else if (ifmgd
->auth_data
)
2405 cbss
= ifmgd
->auth_data
->bss
;
2406 else if (ifmgd
->assoc_data
)
2407 cbss
= ifmgd
->assoc_data
->bss
;
2412 ssid
= ieee80211_bss_get_ie(cbss
, WLAN_EID_SSID
);
2413 if (WARN_ON_ONCE(ssid
== NULL
))
2418 skb
= ieee80211_build_probe_req(sdata
, sdata
->vif
.addr
, cbss
->bssid
,
2419 (u32
) -1, cbss
->channel
,
2426 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
2428 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data
*sdata
,
2429 const u8
*buf
, size_t len
, bool tx
,
2432 struct ieee80211_event event
= {
2434 .u
.mlme
.data
= tx
? DEAUTH_TX_EVENT
: DEAUTH_RX_EVENT
,
2435 .u
.mlme
.reason
= reason
,
2439 cfg80211_tx_mlme_mgmt(sdata
->dev
, buf
, len
);
2441 cfg80211_rx_mlme_mgmt(sdata
->dev
, buf
, len
);
2443 drv_event_callback(sdata
->local
, sdata
, &event
);
2446 static void __ieee80211_disconnect(struct ieee80211_sub_if_data
*sdata
)
2448 struct ieee80211_local
*local
= sdata
->local
;
2449 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2450 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2454 if (!ifmgd
->associated
) {
2455 sdata_unlock(sdata
);
2459 tx
= !sdata
->csa_block_tx
;
2461 /* AP is probably out of range (or not reachable for another reason) so
2462 * remove the bss struct for that AP.
2464 cfg80211_unlink_bss(local
->hw
.wiphy
, ifmgd
->associated
);
2466 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
2467 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2469 mutex_lock(&local
->mtx
);
2470 sdata
->vif
.csa_active
= false;
2471 ifmgd
->csa_waiting_bcn
= false;
2472 if (sdata
->csa_block_tx
) {
2473 ieee80211_wake_vif_queues(local
, sdata
,
2474 IEEE80211_QUEUE_STOP_REASON_CSA
);
2475 sdata
->csa_block_tx
= false;
2477 mutex_unlock(&local
->mtx
);
2479 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), tx
,
2480 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
2482 sdata_unlock(sdata
);
2485 static void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
2487 struct ieee80211_sub_if_data
*sdata
=
2488 container_of(work
, struct ieee80211_sub_if_data
,
2489 u
.mgd
.beacon_connection_loss_work
);
2490 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2492 if (ifmgd
->associated
)
2493 ifmgd
->beacon_loss_count
++;
2495 if (ifmgd
->connection_loss
) {
2496 sdata_info(sdata
, "Connection to AP %pM lost\n",
2498 __ieee80211_disconnect(sdata
);
2500 ieee80211_mgd_probe_ap(sdata
, true);
2504 static void ieee80211_csa_connection_drop_work(struct work_struct
*work
)
2506 struct ieee80211_sub_if_data
*sdata
=
2507 container_of(work
, struct ieee80211_sub_if_data
,
2508 u
.mgd
.csa_connection_drop_work
);
2510 __ieee80211_disconnect(sdata
);
2513 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
2515 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2516 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2518 trace_api_beacon_loss(sdata
);
2520 sdata
->u
.mgd
.connection_loss
= false;
2521 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2523 EXPORT_SYMBOL(ieee80211_beacon_loss
);
2525 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
2527 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2528 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2530 trace_api_connection_loss(sdata
);
2532 sdata
->u
.mgd
.connection_loss
= true;
2533 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2535 EXPORT_SYMBOL(ieee80211_connection_loss
);
2538 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data
*sdata
,
2541 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2543 sdata_assert_lock(sdata
);
2547 * we are not authenticated yet, the only timer that could be
2548 * running is the timeout for the authentication response which
2549 * which is not relevant anymore.
2551 del_timer_sync(&sdata
->u
.mgd
.timer
);
2552 sta_info_destroy_addr(sdata
, auth_data
->bss
->bssid
);
2554 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2555 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2556 sdata
->u
.mgd
.flags
= 0;
2557 mutex_lock(&sdata
->local
->mtx
);
2558 ieee80211_vif_release_channel(sdata
);
2559 mutex_unlock(&sdata
->local
->mtx
);
2562 cfg80211_put_bss(sdata
->local
->hw
.wiphy
, auth_data
->bss
);
2564 sdata
->u
.mgd
.auth_data
= NULL
;
2567 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data
*sdata
,
2568 bool assoc
, bool abandon
)
2570 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
2572 sdata_assert_lock(sdata
);
2576 * we are not associated yet, the only timer that could be
2577 * running is the timeout for the association response which
2578 * which is not relevant anymore.
2580 del_timer_sync(&sdata
->u
.mgd
.timer
);
2581 sta_info_destroy_addr(sdata
, assoc_data
->bss
->bssid
);
2583 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2584 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2585 sdata
->u
.mgd
.flags
= 0;
2586 sdata
->vif
.mu_mimo_owner
= false;
2588 mutex_lock(&sdata
->local
->mtx
);
2589 ieee80211_vif_release_channel(sdata
);
2590 mutex_unlock(&sdata
->local
->mtx
);
2593 cfg80211_abandon_assoc(sdata
->dev
, assoc_data
->bss
);
2597 sdata
->u
.mgd
.assoc_data
= NULL
;
2600 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
2601 struct ieee80211_mgmt
*mgmt
, size_t len
)
2603 struct ieee80211_local
*local
= sdata
->local
;
2604 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2606 struct ieee802_11_elems elems
;
2609 pos
= mgmt
->u
.auth
.variable
;
2610 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2611 if (!elems
.challenge
)
2613 auth_data
->expected_transaction
= 4;
2614 drv_mgd_prepare_tx(sdata
->local
, sdata
);
2615 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
2616 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2617 IEEE80211_TX_INTFL_MLME_CONN_TX
;
2618 ieee80211_send_auth(sdata
, 3, auth_data
->algorithm
, 0,
2619 elems
.challenge
- 2, elems
.challenge_len
+ 2,
2620 auth_data
->bss
->bssid
, auth_data
->bss
->bssid
,
2621 auth_data
->key
, auth_data
->key_len
,
2622 auth_data
->key_idx
, tx_flags
);
2625 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
2626 struct ieee80211_mgmt
*mgmt
, size_t len
)
2628 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2630 u16 auth_alg
, auth_transaction
, status_code
;
2631 struct sta_info
*sta
;
2632 struct ieee80211_event event
= {
2634 .u
.mlme
.data
= AUTH_EVENT
,
2637 sdata_assert_lock(sdata
);
2642 if (!ifmgd
->auth_data
|| ifmgd
->auth_data
->done
)
2645 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
2647 if (!ether_addr_equal(bssid
, mgmt
->bssid
))
2650 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
2651 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
2652 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
2654 if (auth_alg
!= ifmgd
->auth_data
->algorithm
||
2655 auth_transaction
!= ifmgd
->auth_data
->expected_transaction
) {
2656 sdata_info(sdata
, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2657 mgmt
->sa
, auth_alg
, ifmgd
->auth_data
->algorithm
,
2659 ifmgd
->auth_data
->expected_transaction
);
2663 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2664 sdata_info(sdata
, "%pM denied authentication (status %d)\n",
2665 mgmt
->sa
, status_code
);
2666 ieee80211_destroy_auth_data(sdata
, false);
2667 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2668 event
.u
.mlme
.status
= MLME_DENIED
;
2669 event
.u
.mlme
.reason
= status_code
;
2670 drv_event_callback(sdata
->local
, sdata
, &event
);
2674 switch (ifmgd
->auth_data
->algorithm
) {
2675 case WLAN_AUTH_OPEN
:
2676 case WLAN_AUTH_LEAP
:
2679 case WLAN_AUTH_FILS_SK
:
2680 case WLAN_AUTH_FILS_SK_PFS
:
2681 case WLAN_AUTH_FILS_PK
:
2683 case WLAN_AUTH_SHARED_KEY
:
2684 if (ifmgd
->auth_data
->expected_transaction
!= 4) {
2685 ieee80211_auth_challenge(sdata
, mgmt
, len
);
2686 /* need another frame */
2691 WARN_ONCE(1, "invalid auth alg %d",
2692 ifmgd
->auth_data
->algorithm
);
2696 event
.u
.mlme
.status
= MLME_SUCCESS
;
2697 drv_event_callback(sdata
->local
, sdata
, &event
);
2698 sdata_info(sdata
, "authenticated\n");
2699 ifmgd
->auth_data
->done
= true;
2700 ifmgd
->auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_WAIT_ASSOC
;
2701 ifmgd
->auth_data
->timeout_started
= true;
2702 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2704 if (ifmgd
->auth_data
->algorithm
== WLAN_AUTH_SAE
&&
2705 ifmgd
->auth_data
->expected_transaction
!= 2) {
2707 * Report auth frame to user space for processing since another
2708 * round of Authentication frames is still needed.
2710 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2714 /* move station state to auth */
2715 mutex_lock(&sdata
->local
->sta_mtx
);
2716 sta
= sta_info_get(sdata
, bssid
);
2718 WARN_ONCE(1, "%s: STA %pM not found", sdata
->name
, bssid
);
2721 if (sta_info_move_state(sta
, IEEE80211_STA_AUTH
)) {
2722 sdata_info(sdata
, "failed moving %pM to auth\n", bssid
);
2725 mutex_unlock(&sdata
->local
->sta_mtx
);
2727 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2730 mutex_unlock(&sdata
->local
->sta_mtx
);
2731 /* ignore frame -- wait for timeout */
2734 #define case_WLAN(type) \
2735 case WLAN_REASON_##type: return #type
2737 static const char *ieee80211_get_reason_code_string(u16 reason_code
)
2739 switch (reason_code
) {
2740 case_WLAN(UNSPECIFIED
);
2741 case_WLAN(PREV_AUTH_NOT_VALID
);
2742 case_WLAN(DEAUTH_LEAVING
);
2743 case_WLAN(DISASSOC_DUE_TO_INACTIVITY
);
2744 case_WLAN(DISASSOC_AP_BUSY
);
2745 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA
);
2746 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA
);
2747 case_WLAN(DISASSOC_STA_HAS_LEFT
);
2748 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH
);
2749 case_WLAN(DISASSOC_BAD_POWER
);
2750 case_WLAN(DISASSOC_BAD_SUPP_CHAN
);
2751 case_WLAN(INVALID_IE
);
2752 case_WLAN(MIC_FAILURE
);
2753 case_WLAN(4WAY_HANDSHAKE_TIMEOUT
);
2754 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT
);
2755 case_WLAN(IE_DIFFERENT
);
2756 case_WLAN(INVALID_GROUP_CIPHER
);
2757 case_WLAN(INVALID_PAIRWISE_CIPHER
);
2758 case_WLAN(INVALID_AKMP
);
2759 case_WLAN(UNSUPP_RSN_VERSION
);
2760 case_WLAN(INVALID_RSN_IE_CAP
);
2761 case_WLAN(IEEE8021X_FAILED
);
2762 case_WLAN(CIPHER_SUITE_REJECTED
);
2763 case_WLAN(DISASSOC_UNSPECIFIED_QOS
);
2764 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH
);
2765 case_WLAN(DISASSOC_LOW_ACK
);
2766 case_WLAN(DISASSOC_QAP_EXCEED_TXOP
);
2767 case_WLAN(QSTA_LEAVE_QBSS
);
2768 case_WLAN(QSTA_NOT_USE
);
2769 case_WLAN(QSTA_REQUIRE_SETUP
);
2770 case_WLAN(QSTA_TIMEOUT
);
2771 case_WLAN(QSTA_CIPHER_NOT_SUPP
);
2772 case_WLAN(MESH_PEER_CANCELED
);
2773 case_WLAN(MESH_MAX_PEERS
);
2774 case_WLAN(MESH_CONFIG
);
2775 case_WLAN(MESH_CLOSE
);
2776 case_WLAN(MESH_MAX_RETRIES
);
2777 case_WLAN(MESH_CONFIRM_TIMEOUT
);
2778 case_WLAN(MESH_INVALID_GTK
);
2779 case_WLAN(MESH_INCONSISTENT_PARAM
);
2780 case_WLAN(MESH_INVALID_SECURITY
);
2781 case_WLAN(MESH_PATH_ERROR
);
2782 case_WLAN(MESH_PATH_NOFORWARD
);
2783 case_WLAN(MESH_PATH_DEST_UNREACHABLE
);
2784 case_WLAN(MAC_EXISTS_IN_MBSS
);
2785 case_WLAN(MESH_CHAN_REGULATORY
);
2786 case_WLAN(MESH_CHAN
);
2787 default: return "<unknown>";
2791 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
2792 struct ieee80211_mgmt
*mgmt
, size_t len
)
2794 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2795 u16 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
2797 sdata_assert_lock(sdata
);
2802 if (ifmgd
->associated
&&
2803 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
)) {
2804 const u8
*bssid
= ifmgd
->associated
->bssid
;
2806 sdata_info(sdata
, "deauthenticated from %pM (Reason: %u=%s)\n",
2808 ieee80211_get_reason_code_string(reason_code
));
2810 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2812 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false,
2817 if (ifmgd
->assoc_data
&&
2818 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
2819 const u8
*bssid
= ifmgd
->assoc_data
->bss
->bssid
;
2822 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2824 ieee80211_get_reason_code_string(reason_code
));
2826 ieee80211_destroy_assoc_data(sdata
, false, true);
2828 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2834 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
2835 struct ieee80211_mgmt
*mgmt
, size_t len
)
2837 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2840 sdata_assert_lock(sdata
);
2845 if (!ifmgd
->associated
||
2846 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2849 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
2851 sdata_info(sdata
, "disassociated from %pM (Reason: %u=%s)\n",
2852 mgmt
->sa
, reason_code
,
2853 ieee80211_get_reason_code_string(reason_code
));
2855 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2857 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false, reason_code
);
2860 static void ieee80211_get_rates(struct ieee80211_supported_band
*sband
,
2861 u8
*supp_rates
, unsigned int supp_rates_len
,
2862 u32
*rates
, u32
*basic_rates
,
2863 bool *have_higher_than_11mbit
,
2864 int *min_rate
, int *min_rate_index
,
2869 for (i
= 0; i
< supp_rates_len
; i
++) {
2870 int rate
= supp_rates
[i
] & 0x7f;
2871 bool is_basic
= !!(supp_rates
[i
] & 0x80);
2873 if ((rate
* 5 * (1 << shift
)) > 110)
2874 *have_higher_than_11mbit
= true;
2877 * Skip HT and VHT BSS membership selectors since they're not
2880 * Note: Even though the membership selector and the basic
2881 * rate flag share the same bit, they are not exactly
2884 if (supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
) ||
2885 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
))
2888 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2889 struct ieee80211_rate
*br
;
2892 br
= &sband
->bitrates
[j
];
2894 brate
= DIV_ROUND_UP(br
->bitrate
, (1 << shift
) * 5);
2895 if (brate
== rate
) {
2898 *basic_rates
|= BIT(j
);
2899 if ((rate
* 5) < *min_rate
) {
2900 *min_rate
= rate
* 5;
2901 *min_rate_index
= j
;
2909 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data
*sdata
,
2910 struct cfg80211_bss
*cbss
,
2911 struct ieee80211_mgmt
*mgmt
, size_t len
)
2913 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2914 struct ieee80211_local
*local
= sdata
->local
;
2915 struct ieee80211_supported_band
*sband
;
2916 struct sta_info
*sta
;
2918 u16 capab_info
, aid
;
2919 struct ieee802_11_elems elems
;
2920 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2921 const struct cfg80211_bss_ies
*bss_ies
= NULL
;
2922 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
2927 /* AssocResp and ReassocResp have identical structure */
2929 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
2930 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
2932 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2933 sdata_info(sdata
, "invalid AID value 0x%x; bits 15:14 not set\n",
2935 aid
&= ~(BIT(15) | BIT(14));
2937 ifmgd
->broken_ap
= false;
2939 if (aid
== 0 || aid
> IEEE80211_MAX_AID
) {
2940 sdata_info(sdata
, "invalid AID value %d (out of range), turn off PS\n",
2943 ifmgd
->broken_ap
= true;
2946 pos
= mgmt
->u
.assoc_resp
.variable
;
2947 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2949 if (!elems
.supp_rates
) {
2950 sdata_info(sdata
, "no SuppRates element in AssocResp\n");
2955 ifmgd
->tdls_chan_switch_prohibited
=
2956 elems
.ext_capab
&& elems
.ext_capab_len
>= 5 &&
2957 (elems
.ext_capab
[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED
);
2960 * Some APs are erroneously not including some information in their
2961 * (re)association response frames. Try to recover by using the data
2962 * from the beacon or probe response. This seems to afflict mobile
2963 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2964 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2966 if ((assoc_data
->wmm
&& !elems
.wmm_param
) ||
2967 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
2968 (!elems
.ht_cap_elem
|| !elems
.ht_operation
)) ||
2969 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
2970 (!elems
.vht_cap_elem
|| !elems
.vht_operation
))) {
2971 const struct cfg80211_bss_ies
*ies
;
2972 struct ieee802_11_elems bss_elems
;
2975 ies
= rcu_dereference(cbss
->ies
);
2977 bss_ies
= kmemdup(ies
, sizeof(*ies
) + ies
->len
,
2983 ieee802_11_parse_elems(bss_ies
->data
, bss_ies
->len
,
2985 if (assoc_data
->wmm
&&
2986 !elems
.wmm_param
&& bss_elems
.wmm_param
) {
2987 elems
.wmm_param
= bss_elems
.wmm_param
;
2989 "AP bug: WMM param missing from AssocResp\n");
2993 * Also check if we requested HT/VHT, otherwise the AP doesn't
2994 * have to include the IEs in the (re)association response.
2996 if (!elems
.ht_cap_elem
&& bss_elems
.ht_cap_elem
&&
2997 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
2998 elems
.ht_cap_elem
= bss_elems
.ht_cap_elem
;
3000 "AP bug: HT capability missing from AssocResp\n");
3002 if (!elems
.ht_operation
&& bss_elems
.ht_operation
&&
3003 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
3004 elems
.ht_operation
= bss_elems
.ht_operation
;
3006 "AP bug: HT operation missing from AssocResp\n");
3008 if (!elems
.vht_cap_elem
&& bss_elems
.vht_cap_elem
&&
3009 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3010 elems
.vht_cap_elem
= bss_elems
.vht_cap_elem
;
3012 "AP bug: VHT capa missing from AssocResp\n");
3014 if (!elems
.vht_operation
&& bss_elems
.vht_operation
&&
3015 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
3016 elems
.vht_operation
= bss_elems
.vht_operation
;
3018 "AP bug: VHT operation missing from AssocResp\n");
3023 * We previously checked these in the beacon/probe response, so
3024 * they should be present here. This is just a safety net.
3026 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3027 (!elems
.wmm_param
|| !elems
.ht_cap_elem
|| !elems
.ht_operation
)) {
3029 "HT AP is missing WMM params or HT capability/operation\n");
3034 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3035 (!elems
.vht_cap_elem
|| !elems
.vht_operation
)) {
3037 "VHT AP is missing VHT capability/operation\n");
3042 mutex_lock(&sdata
->local
->sta_mtx
);
3044 * station info was already allocated and inserted before
3045 * the association and should be available to us
3047 sta
= sta_info_get(sdata
, cbss
->bssid
);
3048 if (WARN_ON(!sta
)) {
3049 mutex_unlock(&sdata
->local
->sta_mtx
);
3054 sband
= ieee80211_get_sband(sdata
);
3056 mutex_unlock(&sdata
->local
->sta_mtx
);
3061 /* Set up internal HT/VHT capabilities */
3062 if (elems
.ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
3063 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
3064 elems
.ht_cap_elem
, sta
);
3066 if (elems
.vht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
3067 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
3068 elems
.vht_cap_elem
, sta
);
3071 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3072 * in their association response, so ignore that data for our own
3073 * configuration. If it changed since the last beacon, we'll get the
3074 * next beacon and update then.
3078 * If an operating mode notification IE is present, override the
3079 * NSS calculation (that would be done in rate_control_rate_init())
3080 * and use the # of streams from that element.
3082 if (elems
.opmode_notif
&&
3083 !(*elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)) {
3086 nss
= *elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
3087 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
3089 sta
->sta
.rx_nss
= nss
;
3092 rate_control_rate_init(sta
);
3094 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
) {
3095 set_sta_flag(sta
, WLAN_STA_MFP
);
3096 sta
->sta
.mfp
= true;
3098 sta
->sta
.mfp
= false;
3101 sta
->sta
.wme
= elems
.wmm_param
&& local
->hw
.queues
>= IEEE80211_NUM_ACS
;
3103 err
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
3104 if (!err
&& !(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
3105 err
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
3108 "failed to move station %pM to desired state\n",
3110 WARN_ON(__sta_info_destroy(sta
));
3111 mutex_unlock(&sdata
->local
->sta_mtx
);
3116 mutex_unlock(&sdata
->local
->sta_mtx
);
3119 * Always handle WMM once after association regardless
3120 * of the first value the AP uses. Setting -1 here has
3121 * that effect because the AP values is an unsigned
3124 ifmgd
->wmm_last_param_set
= -1;
3126 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
3127 ieee80211_set_wmm_default(sdata
, false, false);
3128 } else if (!ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3129 elems
.wmm_param_len
)) {
3130 /* still enable QoS since we might have HT/VHT */
3131 ieee80211_set_wmm_default(sdata
, false, true);
3132 /* set the disable-WMM flag in this case to disable
3133 * tracking WMM parameter changes in the beacon if
3134 * the parameters weren't actually valid. Doing so
3135 * avoids changing parameters very strangely when
3136 * the AP is going back and forth between valid and
3137 * invalid parameters.
3139 ifmgd
->flags
|= IEEE80211_STA_DISABLE_WMM
;
3141 changed
|= BSS_CHANGED_QOS
;
3143 if (elems
.max_idle_period_ie
) {
3144 bss_conf
->max_idle_period
=
3145 le16_to_cpu(elems
.max_idle_period_ie
->max_idle_period
);
3146 bss_conf
->protected_keep_alive
=
3147 !!(elems
.max_idle_period_ie
->idle_options
&
3148 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE
);
3149 changed
|= BSS_CHANGED_KEEP_ALIVE
;
3151 bss_conf
->max_idle_period
= 0;
3152 bss_conf
->protected_keep_alive
= false;
3155 /* set AID and assoc capability,
3156 * ieee80211_set_associated() will tell the driver */
3157 bss_conf
->aid
= aid
;
3158 bss_conf
->assoc_capability
= capab_info
;
3159 ieee80211_set_associated(sdata
, cbss
, changed
);
3162 * If we're using 4-addr mode, let the AP know that we're
3163 * doing so, so that it can create the STA VLAN on its side
3165 if (ifmgd
->use_4addr
)
3166 ieee80211_send_4addr_nullfunc(local
, sdata
);
3169 * Start timer to probe the connection to the AP now.
3170 * Also start the timer that will detect beacon loss.
3172 ieee80211_sta_rx_notify(sdata
, (struct ieee80211_hdr
*)mgmt
);
3173 ieee80211_sta_reset_beacon_monitor(sdata
);
3181 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
3182 struct ieee80211_mgmt
*mgmt
,
3185 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3186 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3187 u16 capab_info
, status_code
, aid
;
3188 struct ieee802_11_elems elems
;
3189 int ac
, uapsd_queues
= -1;
3192 struct cfg80211_bss
*bss
;
3193 struct ieee80211_event event
= {
3195 .u
.mlme
.data
= ASSOC_EVENT
,
3198 sdata_assert_lock(sdata
);
3202 if (!ether_addr_equal(assoc_data
->bss
->bssid
, mgmt
->bssid
))
3206 * AssocResp and ReassocResp have identical structure, so process both
3207 * of them in this function.
3213 reassoc
= ieee80211_is_reassoc_resp(mgmt
->frame_control
);
3214 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3215 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
3216 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3219 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3220 reassoc
? "Rea" : "A", mgmt
->sa
,
3221 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
3223 if (assoc_data
->fils_kek_len
&&
3224 fils_decrypt_assoc_resp(sdata
, (u8
*)mgmt
, &len
, assoc_data
) < 0)
3227 pos
= mgmt
->u
.assoc_resp
.variable
;
3228 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
3230 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
3231 elems
.timeout_int
&&
3232 elems
.timeout_int
->type
== WLAN_TIMEOUT_ASSOC_COMEBACK
) {
3234 tu
= le32_to_cpu(elems
.timeout_int
->value
);
3235 ms
= tu
* 1024 / 1000;
3237 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3239 assoc_data
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
3240 assoc_data
->timeout_started
= true;
3241 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
3242 run_again(sdata
, assoc_data
->timeout
);
3246 bss
= assoc_data
->bss
;
3248 if (status_code
!= WLAN_STATUS_SUCCESS
) {
3249 sdata_info(sdata
, "%pM denied association (code=%d)\n",
3250 mgmt
->sa
, status_code
);
3251 ieee80211_destroy_assoc_data(sdata
, false, false);
3252 event
.u
.mlme
.status
= MLME_DENIED
;
3253 event
.u
.mlme
.reason
= status_code
;
3254 drv_event_callback(sdata
->local
, sdata
, &event
);
3256 if (!ieee80211_assoc_success(sdata
, bss
, mgmt
, len
)) {
3257 /* oops -- internal error -- send timeout for now */
3258 ieee80211_destroy_assoc_data(sdata
, false, false);
3259 cfg80211_assoc_timeout(sdata
->dev
, bss
);
3262 event
.u
.mlme
.status
= MLME_SUCCESS
;
3263 drv_event_callback(sdata
->local
, sdata
, &event
);
3264 sdata_info(sdata
, "associated\n");
3267 * destroy assoc_data afterwards, as otherwise an idle
3268 * recalc after assoc_data is NULL but before associated
3269 * is set can cause the interface to go idle
3271 ieee80211_destroy_assoc_data(sdata
, true, false);
3273 /* get uapsd queues configuration */
3275 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
3276 if (sdata
->tx_conf
[ac
].uapsd
)
3277 uapsd_queues
|= ieee80211_ac_to_qos_mask
[ac
];
3280 cfg80211_rx_assoc_resp(sdata
->dev
, bss
, (u8
*)mgmt
, len
, uapsd_queues
);
3283 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
3284 struct ieee80211_mgmt
*mgmt
, size_t len
,
3285 struct ieee80211_rx_status
*rx_status
,
3286 struct ieee802_11_elems
*elems
)
3288 struct ieee80211_local
*local
= sdata
->local
;
3289 struct ieee80211_bss
*bss
;
3290 struct ieee80211_channel
*channel
;
3292 sdata_assert_lock(sdata
);
3294 channel
= ieee80211_get_channel(local
->hw
.wiphy
, rx_status
->freq
);
3298 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
3301 sdata
->vif
.bss_conf
.beacon_rate
= bss
->beacon_rate
;
3302 ieee80211_rx_bss_put(local
, bss
);
3307 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
3308 struct sk_buff
*skb
)
3310 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
3311 struct ieee80211_if_managed
*ifmgd
;
3312 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
3313 size_t baselen
, len
= skb
->len
;
3314 struct ieee802_11_elems elems
;
3316 ifmgd
= &sdata
->u
.mgd
;
3318 sdata_assert_lock(sdata
);
3320 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
3321 return; /* ignore ProbeResp to foreign address */
3323 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
3327 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
3330 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3332 if (ifmgd
->associated
&&
3333 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3334 ieee80211_reset_ap_probe(sdata
);
3338 * This is the canonical list of information elements we care about,
3339 * the filter code also gives us all changes to the Microsoft OUI
3340 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3341 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3342 * changes to requested client power.
3344 * We implement beacon filtering in software since that means we can
3345 * avoid processing the frame here and in cfg80211, and userspace
3346 * will not be able to tell whether the hardware supports it or not.
3348 * XXX: This list needs to be dynamic -- userspace needs to be able to
3349 * add items it requires. It also needs to be able to tell us to
3350 * look out for other vendor IEs.
3352 static const u64 care_about_ies
=
3353 (1ULL << WLAN_EID_COUNTRY
) |
3354 (1ULL << WLAN_EID_ERP_INFO
) |
3355 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
3356 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
3357 (1ULL << WLAN_EID_HT_CAPABILITY
) |
3358 (1ULL << WLAN_EID_HT_OPERATION
) |
3359 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN
);
3361 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
3362 struct ieee80211_mgmt
*mgmt
, size_t len
,
3363 struct ieee80211_rx_status
*rx_status
)
3365 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3366 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3368 struct ieee802_11_elems elems
;
3369 struct ieee80211_local
*local
= sdata
->local
;
3370 struct ieee80211_chanctx_conf
*chanctx_conf
;
3371 struct ieee80211_channel
*chan
;
3372 struct sta_info
*sta
;
3378 u8 deauth_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3380 sdata_assert_lock(sdata
);
3382 /* Process beacon from the current BSS */
3383 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
3388 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3389 if (!chanctx_conf
) {
3394 if (rx_status
->freq
!= chanctx_conf
->def
.chan
->center_freq
) {
3398 chan
= chanctx_conf
->def
.chan
;
3401 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->need_beacon
&&
3402 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
3403 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
3404 len
- baselen
, false, &elems
);
3406 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3407 if (elems
.tim
&& !elems
.parse_error
) {
3408 const struct ieee80211_tim_ie
*tim_ie
= elems
.tim
;
3409 ifmgd
->dtim_period
= tim_ie
->dtim_period
;
3411 ifmgd
->have_beacon
= true;
3412 ifmgd
->assoc_data
->need_beacon
= false;
3413 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3414 sdata
->vif
.bss_conf
.sync_tsf
=
3415 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3416 sdata
->vif
.bss_conf
.sync_device_ts
=
3417 rx_status
->device_timestamp
;
3419 sdata
->vif
.bss_conf
.sync_dtim_count
=
3420 elems
.tim
->dtim_count
;
3422 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3424 /* continue assoc process */
3425 ifmgd
->assoc_data
->timeout
= jiffies
;
3426 ifmgd
->assoc_data
->timeout_started
= true;
3427 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3431 if (!ifmgd
->associated
||
3432 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3434 bssid
= ifmgd
->associated
->bssid
;
3436 /* Track average RSSI from the Beacon frames of the current AP */
3437 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
3438 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
3439 ewma_beacon_signal_init(&ifmgd
->ave_beacon_signal
);
3440 ifmgd
->last_cqm_event_signal
= 0;
3441 ifmgd
->count_beacon_signal
= 1;
3442 ifmgd
->last_ave_beacon_signal
= 0;
3444 ifmgd
->count_beacon_signal
++;
3447 ewma_beacon_signal_add(&ifmgd
->ave_beacon_signal
, -rx_status
->signal
);
3449 if (ifmgd
->rssi_min_thold
!= ifmgd
->rssi_max_thold
&&
3450 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3451 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3452 int last_sig
= ifmgd
->last_ave_beacon_signal
;
3453 struct ieee80211_event event
= {
3458 * if signal crosses either of the boundaries, invoke callback
3459 * with appropriate parameters
3461 if (sig
> ifmgd
->rssi_max_thold
&&
3462 (last_sig
<= ifmgd
->rssi_min_thold
|| last_sig
== 0)) {
3463 ifmgd
->last_ave_beacon_signal
= sig
;
3464 event
.u
.rssi
.data
= RSSI_EVENT_HIGH
;
3465 drv_event_callback(local
, sdata
, &event
);
3466 } else if (sig
< ifmgd
->rssi_min_thold
&&
3467 (last_sig
>= ifmgd
->rssi_max_thold
||
3469 ifmgd
->last_ave_beacon_signal
= sig
;
3470 event
.u
.rssi
.data
= RSSI_EVENT_LOW
;
3471 drv_event_callback(local
, sdata
, &event
);
3475 if (bss_conf
->cqm_rssi_thold
&&
3476 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
3477 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)) {
3478 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3479 int last_event
= ifmgd
->last_cqm_event_signal
;
3480 int thold
= bss_conf
->cqm_rssi_thold
;
3481 int hyst
= bss_conf
->cqm_rssi_hyst
;
3484 (last_event
== 0 || sig
< last_event
- hyst
)) {
3485 ifmgd
->last_cqm_event_signal
= sig
;
3486 ieee80211_cqm_rssi_notify(
3488 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3490 } else if (sig
> thold
&&
3491 (last_event
== 0 || sig
> last_event
+ hyst
)) {
3492 ifmgd
->last_cqm_event_signal
= sig
;
3493 ieee80211_cqm_rssi_notify(
3495 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3500 if (bss_conf
->cqm_rssi_low
&&
3501 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3502 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3503 int last_event
= ifmgd
->last_cqm_event_signal
;
3504 int low
= bss_conf
->cqm_rssi_low
;
3505 int high
= bss_conf
->cqm_rssi_high
;
3508 (last_event
== 0 || last_event
>= low
)) {
3509 ifmgd
->last_cqm_event_signal
= sig
;
3510 ieee80211_cqm_rssi_notify(
3512 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3514 } else if (sig
> high
&&
3515 (last_event
== 0 || last_event
<= high
)) {
3516 ifmgd
->last_cqm_event_signal
= sig
;
3517 ieee80211_cqm_rssi_notify(
3519 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3524 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
) {
3525 mlme_dbg_ratelimited(sdata
,
3526 "cancelling AP probe due to a received beacon\n");
3527 ieee80211_reset_ap_probe(sdata
);
3531 * Push the beacon loss detection into the future since
3532 * we are processing a beacon from the AP just now.
3534 ieee80211_sta_reset_beacon_monitor(sdata
);
3536 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
3537 ncrc
= ieee802_11_parse_elems_crc(mgmt
->u
.beacon
.variable
,
3538 len
- baselen
, false, &elems
,
3539 care_about_ies
, ncrc
);
3541 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
3542 ieee80211_check_tim(elems
.tim
, elems
.tim_len
, ifmgd
->aid
)) {
3543 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
3544 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
3545 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
3546 ieee80211_hw_config(local
,
3547 IEEE80211_CONF_CHANGE_PS
);
3549 ieee80211_send_nullfunc(local
, sdata
, false);
3550 } else if (!local
->pspolling
&& sdata
->u
.mgd
.powersave
) {
3551 local
->pspolling
= true;
3554 * Here is assumed that the driver will be
3555 * able to send ps-poll frame and receive a
3556 * response even though power save mode is
3557 * enabled, but some drivers might require
3558 * to disable power save here. This needs
3559 * to be investigated.
3561 ieee80211_send_pspoll(local
, sdata
);
3565 if (sdata
->vif
.p2p
||
3566 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
3567 struct ieee80211_p2p_noa_attr noa
= {};
3570 ret
= cfg80211_get_p2p_attr(mgmt
->u
.beacon
.variable
,
3572 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
3573 (u8
*) &noa
, sizeof(noa
));
3575 if (sdata
->u
.mgd
.p2p_noa_index
!= noa
.index
) {
3576 /* valid noa_attr and index changed */
3577 sdata
->u
.mgd
.p2p_noa_index
= noa
.index
;
3578 memcpy(&bss_conf
->p2p_noa_attr
, &noa
, sizeof(noa
));
3579 changed
|= BSS_CHANGED_P2P_PS
;
3581 * make sure we update all information, the CRC
3582 * mechanism doesn't look at P2P attributes.
3584 ifmgd
->beacon_crc_valid
= false;
3586 } else if (sdata
->u
.mgd
.p2p_noa_index
!= -1) {
3587 /* noa_attr not found and we had valid noa_attr before */
3588 sdata
->u
.mgd
.p2p_noa_index
= -1;
3589 memset(&bss_conf
->p2p_noa_attr
, 0, sizeof(bss_conf
->p2p_noa_attr
));
3590 changed
|= BSS_CHANGED_P2P_PS
;
3591 ifmgd
->beacon_crc_valid
= false;
3595 if (ifmgd
->csa_waiting_bcn
)
3596 ieee80211_chswitch_post_beacon(sdata
);
3599 * Update beacon timing and dtim count on every beacon appearance. This
3600 * will allow the driver to use the most updated values. Do it before
3601 * comparing this one with last received beacon.
3602 * IMPORTANT: These parameters would possibly be out of sync by the time
3603 * the driver will use them. The synchronized view is currently
3604 * guaranteed only in certain callbacks.
3606 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3607 sdata
->vif
.bss_conf
.sync_tsf
=
3608 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3609 sdata
->vif
.bss_conf
.sync_device_ts
=
3610 rx_status
->device_timestamp
;
3612 sdata
->vif
.bss_conf
.sync_dtim_count
=
3613 elems
.tim
->dtim_count
;
3615 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3618 if (ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
)
3620 ifmgd
->beacon_crc
= ncrc
;
3621 ifmgd
->beacon_crc_valid
= true;
3623 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3625 ieee80211_sta_process_chanswitch(sdata
, rx_status
->mactime
,
3626 rx_status
->device_timestamp
,
3629 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) &&
3630 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3631 elems
.wmm_param_len
))
3632 changed
|= BSS_CHANGED_QOS
;
3635 * If we haven't had a beacon before, tell the driver about the
3636 * DTIM period (and beacon timing if desired) now.
3638 if (!ifmgd
->have_beacon
) {
3639 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3641 bss_conf
->dtim_period
= elems
.tim
->dtim_period
?: 1;
3643 bss_conf
->dtim_period
= 1;
3645 changed
|= BSS_CHANGED_BEACON_INFO
;
3646 ifmgd
->have_beacon
= true;
3648 mutex_lock(&local
->iflist_mtx
);
3649 ieee80211_recalc_ps(local
);
3650 mutex_unlock(&local
->iflist_mtx
);
3652 ieee80211_recalc_ps_vif(sdata
);
3655 if (elems
.erp_info
) {
3657 erp_value
= elems
.erp_info
[0];
3661 changed
|= ieee80211_handle_bss_capability(sdata
,
3662 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
3663 erp_valid
, erp_value
);
3665 mutex_lock(&local
->sta_mtx
);
3666 sta
= sta_info_get(sdata
, bssid
);
3668 if (ieee80211_config_bw(sdata
, sta
,
3669 elems
.ht_cap_elem
, elems
.ht_operation
,
3670 elems
.vht_operation
, bssid
, &changed
)) {
3671 mutex_unlock(&local
->sta_mtx
);
3673 "failed to follow AP %pM bandwidth change, disconnect\n",
3675 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
3676 WLAN_REASON_DEAUTH_LEAVING
,
3678 ieee80211_report_disconnect(sdata
, deauth_buf
,
3679 sizeof(deauth_buf
), true,
3680 WLAN_REASON_DEAUTH_LEAVING
);
3684 if (sta
&& elems
.opmode_notif
)
3685 ieee80211_vht_handle_opmode(sdata
, sta
, *elems
.opmode_notif
,
3687 mutex_unlock(&local
->sta_mtx
);
3689 changed
|= ieee80211_handle_pwr_constr(sdata
, chan
, mgmt
,
3691 elems
.country_elem_len
,
3692 elems
.pwr_constr_elem
,
3693 elems
.cisco_dtpc_elem
);
3695 ieee80211_bss_info_change_notify(sdata
, changed
);
3698 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
3699 struct sk_buff
*skb
)
3701 struct ieee80211_rx_status
*rx_status
;
3702 struct ieee80211_mgmt
*mgmt
;
3704 struct ieee802_11_elems elems
;
3707 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3708 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3709 fc
= le16_to_cpu(mgmt
->frame_control
);
3713 switch (fc
& IEEE80211_FCTL_STYPE
) {
3714 case IEEE80211_STYPE_BEACON
:
3715 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3717 case IEEE80211_STYPE_PROBE_RESP
:
3718 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
3720 case IEEE80211_STYPE_AUTH
:
3721 ieee80211_rx_mgmt_auth(sdata
, mgmt
, skb
->len
);
3723 case IEEE80211_STYPE_DEAUTH
:
3724 ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
3726 case IEEE80211_STYPE_DISASSOC
:
3727 ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
3729 case IEEE80211_STYPE_ASSOC_RESP
:
3730 case IEEE80211_STYPE_REASSOC_RESP
:
3731 ieee80211_rx_mgmt_assoc_resp(sdata
, mgmt
, skb
->len
);
3733 case IEEE80211_STYPE_ACTION
:
3734 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
) {
3735 ies_len
= skb
->len
-
3736 offsetof(struct ieee80211_mgmt
,
3737 u
.action
.u
.chan_switch
.variable
);
3742 ieee802_11_parse_elems(
3743 mgmt
->u
.action
.u
.chan_switch
.variable
,
3744 ies_len
, true, &elems
);
3746 if (elems
.parse_error
)
3749 ieee80211_sta_process_chanswitch(sdata
,
3751 rx_status
->device_timestamp
,
3753 } else if (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
) {
3754 ies_len
= skb
->len
-
3755 offsetof(struct ieee80211_mgmt
,
3756 u
.action
.u
.ext_chan_switch
.variable
);
3761 ieee802_11_parse_elems(
3762 mgmt
->u
.action
.u
.ext_chan_switch
.variable
,
3763 ies_len
, true, &elems
);
3765 if (elems
.parse_error
)
3768 /* for the handling code pretend this was also an IE */
3769 elems
.ext_chansw_ie
=
3770 &mgmt
->u
.action
.u
.ext_chan_switch
.data
;
3772 ieee80211_sta_process_chanswitch(sdata
,
3774 rx_status
->device_timestamp
,
3779 sdata_unlock(sdata
);
3782 static void ieee80211_sta_timer(struct timer_list
*t
)
3784 struct ieee80211_sub_if_data
*sdata
=
3785 from_timer(sdata
, t
, u
.mgd
.timer
);
3787 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
3790 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
3791 u8
*bssid
, u8 reason
, bool tx
)
3793 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3795 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
, reason
,
3798 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
3802 static int ieee80211_auth(struct ieee80211_sub_if_data
*sdata
)
3804 struct ieee80211_local
*local
= sdata
->local
;
3805 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3806 struct ieee80211_mgd_auth_data
*auth_data
= ifmgd
->auth_data
;
3811 sdata_assert_lock(sdata
);
3813 if (WARN_ON_ONCE(!auth_data
))
3818 if (auth_data
->tries
> IEEE80211_AUTH_MAX_TRIES
) {
3819 sdata_info(sdata
, "authentication with %pM timed out\n",
3820 auth_data
->bss
->bssid
);
3823 * Most likely AP is not in the range so remove the
3824 * bss struct for that AP.
3826 cfg80211_unlink_bss(local
->hw
.wiphy
, auth_data
->bss
);
3831 drv_mgd_prepare_tx(local
, sdata
);
3833 sdata_info(sdata
, "send auth to %pM (try %d/%d)\n",
3834 auth_data
->bss
->bssid
, auth_data
->tries
,
3835 IEEE80211_AUTH_MAX_TRIES
);
3837 auth_data
->expected_transaction
= 2;
3839 if (auth_data
->algorithm
== WLAN_AUTH_SAE
) {
3840 trans
= auth_data
->sae_trans
;
3841 status
= auth_data
->sae_status
;
3842 auth_data
->expected_transaction
= trans
;
3845 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
3846 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3847 IEEE80211_TX_INTFL_MLME_CONN_TX
;
3849 ieee80211_send_auth(sdata
, trans
, auth_data
->algorithm
, status
,
3850 auth_data
->data
, auth_data
->data_len
,
3851 auth_data
->bss
->bssid
,
3852 auth_data
->bss
->bssid
, NULL
, 0, 0,
3855 if (tx_flags
== 0) {
3856 if (auth_data
->algorithm
== WLAN_AUTH_SAE
)
3857 auth_data
->timeout
= jiffies
+
3858 IEEE80211_AUTH_TIMEOUT_SAE
;
3860 auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
3862 auth_data
->timeout
=
3863 round_jiffies_up(jiffies
+ IEEE80211_AUTH_TIMEOUT_LONG
);
3866 auth_data
->timeout_started
= true;
3867 run_again(sdata
, auth_data
->timeout
);
3872 static int ieee80211_do_assoc(struct ieee80211_sub_if_data
*sdata
)
3874 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
3875 struct ieee80211_local
*local
= sdata
->local
;
3877 sdata_assert_lock(sdata
);
3879 assoc_data
->tries
++;
3880 if (assoc_data
->tries
> IEEE80211_ASSOC_MAX_TRIES
) {
3881 sdata_info(sdata
, "association with %pM timed out\n",
3882 assoc_data
->bss
->bssid
);
3885 * Most likely AP is not in the range so remove the
3886 * bss struct for that AP.
3888 cfg80211_unlink_bss(local
->hw
.wiphy
, assoc_data
->bss
);
3893 sdata_info(sdata
, "associate with %pM (try %d/%d)\n",
3894 assoc_data
->bss
->bssid
, assoc_data
->tries
,
3895 IEEE80211_ASSOC_MAX_TRIES
);
3896 ieee80211_send_assoc(sdata
);
3898 if (!ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
3899 assoc_data
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
3900 assoc_data
->timeout_started
= true;
3901 run_again(sdata
, assoc_data
->timeout
);
3903 assoc_data
->timeout
=
3904 round_jiffies_up(jiffies
+
3905 IEEE80211_ASSOC_TIMEOUT_LONG
);
3906 assoc_data
->timeout_started
= true;
3907 run_again(sdata
, assoc_data
->timeout
);
3913 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data
*sdata
,
3914 __le16 fc
, bool acked
)
3916 struct ieee80211_local
*local
= sdata
->local
;
3918 sdata
->u
.mgd
.status_fc
= fc
;
3919 sdata
->u
.mgd
.status_acked
= acked
;
3920 sdata
->u
.mgd
.status_received
= true;
3922 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
3925 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
3927 struct ieee80211_local
*local
= sdata
->local
;
3928 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3932 if (ifmgd
->status_received
) {
3933 __le16 fc
= ifmgd
->status_fc
;
3934 bool status_acked
= ifmgd
->status_acked
;
3936 ifmgd
->status_received
= false;
3937 if (ifmgd
->auth_data
&& ieee80211_is_auth(fc
)) {
3939 if (ifmgd
->auth_data
->algorithm
==
3941 ifmgd
->auth_data
->timeout
=
3943 IEEE80211_AUTH_TIMEOUT_SAE
;
3945 ifmgd
->auth_data
->timeout
=
3947 IEEE80211_AUTH_TIMEOUT_SHORT
;
3948 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3950 ifmgd
->auth_data
->timeout
= jiffies
- 1;
3952 ifmgd
->auth_data
->timeout_started
= true;
3953 } else if (ifmgd
->assoc_data
&&
3954 (ieee80211_is_assoc_req(fc
) ||
3955 ieee80211_is_reassoc_req(fc
))) {
3957 ifmgd
->assoc_data
->timeout
=
3958 jiffies
+ IEEE80211_ASSOC_TIMEOUT_SHORT
;
3959 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3961 ifmgd
->assoc_data
->timeout
= jiffies
- 1;
3963 ifmgd
->assoc_data
->timeout_started
= true;
3967 if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
&&
3968 time_after(jiffies
, ifmgd
->auth_data
->timeout
)) {
3969 if (ifmgd
->auth_data
->done
) {
3971 * ok ... we waited for assoc but userspace didn't,
3972 * so let's just kill the auth data
3974 ieee80211_destroy_auth_data(sdata
, false);
3975 } else if (ieee80211_auth(sdata
)) {
3977 struct ieee80211_event event
= {
3979 .u
.mlme
.data
= AUTH_EVENT
,
3980 .u
.mlme
.status
= MLME_TIMEOUT
,
3983 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
3985 ieee80211_destroy_auth_data(sdata
, false);
3987 cfg80211_auth_timeout(sdata
->dev
, bssid
);
3988 drv_event_callback(sdata
->local
, sdata
, &event
);
3990 } else if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
)
3991 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3993 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
&&
3994 time_after(jiffies
, ifmgd
->assoc_data
->timeout
)) {
3995 if ((ifmgd
->assoc_data
->need_beacon
&& !ifmgd
->have_beacon
) ||
3996 ieee80211_do_assoc(sdata
)) {
3997 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
3998 struct ieee80211_event event
= {
4000 .u
.mlme
.data
= ASSOC_EVENT
,
4001 .u
.mlme
.status
= MLME_TIMEOUT
,
4004 ieee80211_destroy_assoc_data(sdata
, false, false);
4005 cfg80211_assoc_timeout(sdata
->dev
, bss
);
4006 drv_event_callback(sdata
->local
, sdata
, &event
);
4008 } else if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
)
4009 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
4011 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
&&
4012 ifmgd
->associated
) {
4016 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4018 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
4019 max_tries
= max_nullfunc_tries
;
4021 max_tries
= max_probe_tries
;
4023 /* ACK received for nullfunc probing frame */
4024 if (!ifmgd
->probe_send_count
)
4025 ieee80211_reset_ap_probe(sdata
);
4026 else if (ifmgd
->nullfunc_failed
) {
4027 if (ifmgd
->probe_send_count
< max_tries
) {
4029 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4030 bssid
, ifmgd
->probe_send_count
,
4032 ieee80211_mgd_probe_ap_send(sdata
);
4035 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4037 ieee80211_sta_connection_lost(sdata
, bssid
,
4038 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
4041 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
4042 run_again(sdata
, ifmgd
->probe_timeout
);
4043 else if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
4045 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4046 bssid
, probe_wait_ms
);
4047 ieee80211_sta_connection_lost(sdata
, bssid
,
4048 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4049 } else if (ifmgd
->probe_send_count
< max_tries
) {
4051 "No probe response from AP %pM after %dms, try %d/%i\n",
4052 bssid
, probe_wait_ms
,
4053 ifmgd
->probe_send_count
, max_tries
);
4054 ieee80211_mgd_probe_ap_send(sdata
);
4057 * We actually lost the connection ... or did we?
4061 "No probe response from AP %pM after %dms, disconnecting.\n",
4062 bssid
, probe_wait_ms
);
4064 ieee80211_sta_connection_lost(sdata
, bssid
,
4065 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
4069 sdata_unlock(sdata
);
4072 static void ieee80211_sta_bcn_mon_timer(struct timer_list
*t
)
4074 struct ieee80211_sub_if_data
*sdata
=
4075 from_timer(sdata
, t
, u
.mgd
.bcn_mon_timer
);
4076 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4078 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4081 sdata
->u
.mgd
.connection_loss
= false;
4082 ieee80211_queue_work(&sdata
->local
->hw
,
4083 &sdata
->u
.mgd
.beacon_connection_loss_work
);
4086 static void ieee80211_sta_conn_mon_timer(struct timer_list
*t
)
4088 struct ieee80211_sub_if_data
*sdata
=
4089 from_timer(sdata
, t
, u
.mgd
.conn_mon_timer
);
4090 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4091 struct ieee80211_local
*local
= sdata
->local
;
4093 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4096 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
4099 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
4101 struct ieee80211_sub_if_data
*sdata
=
4102 container_of(work
, struct ieee80211_sub_if_data
,
4103 u
.mgd
.monitor_work
);
4105 ieee80211_mgd_probe_ap(sdata
, false);
4108 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
4110 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
4111 __ieee80211_stop_poll(sdata
);
4113 /* let's probe the connection once */
4114 if (!ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
4115 ieee80211_queue_work(&sdata
->local
->hw
,
4116 &sdata
->u
.mgd
.monitor_work
);
4121 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data
*sdata
)
4123 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4124 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4128 if (ifmgd
->auth_data
|| ifmgd
->assoc_data
) {
4129 const u8
*bssid
= ifmgd
->auth_data
?
4130 ifmgd
->auth_data
->bss
->bssid
:
4131 ifmgd
->assoc_data
->bss
->bssid
;
4134 * If we are trying to authenticate / associate while suspending,
4135 * cfg80211 won't know and won't actually abort those attempts,
4136 * thus we need to do that ourselves.
4138 ieee80211_send_deauth_disassoc(sdata
, bssid
,
4139 IEEE80211_STYPE_DEAUTH
,
4140 WLAN_REASON_DEAUTH_LEAVING
,
4142 if (ifmgd
->assoc_data
)
4143 ieee80211_destroy_assoc_data(sdata
, false, true);
4144 if (ifmgd
->auth_data
)
4145 ieee80211_destroy_auth_data(sdata
, false);
4146 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4147 IEEE80211_DEAUTH_FRAME_LEN
);
4150 /* This is a bit of a hack - we should find a better and more generic
4151 * solution to this. Normally when suspending, cfg80211 will in fact
4152 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4153 * auth (not so important) or assoc (this is the problem) process.
4155 * As a consequence, it can happen that we are in the process of both
4156 * associating and suspending, and receive an association response
4157 * after cfg80211 has checked if it needs to disconnect, but before
4158 * we actually set the flag to drop incoming frames. This will then
4159 * cause the workqueue flush to process the association response in
4160 * the suspend, resulting in a successful association just before it
4161 * tries to remove the interface from the driver, which now though
4162 * has a channel context assigned ... this results in issues.
4164 * To work around this (for now) simply deauth here again if we're
4167 if (ifmgd
->associated
&& !sdata
->local
->wowlan
) {
4169 struct cfg80211_deauth_request req
= {
4170 .reason_code
= WLAN_REASON_DEAUTH_LEAVING
,
4174 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4175 ieee80211_mgd_deauth(sdata
, &req
);
4178 sdata_unlock(sdata
);
4181 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
4183 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4186 if (!ifmgd
->associated
) {
4187 sdata_unlock(sdata
);
4191 if (sdata
->flags
& IEEE80211_SDATA_DISCONNECT_RESUME
) {
4192 sdata
->flags
&= ~IEEE80211_SDATA_DISCONNECT_RESUME
;
4193 mlme_dbg(sdata
, "driver requested disconnect after resume\n");
4194 ieee80211_sta_connection_lost(sdata
,
4195 ifmgd
->associated
->bssid
,
4196 WLAN_REASON_UNSPECIFIED
,
4198 sdata_unlock(sdata
);
4201 sdata_unlock(sdata
);
4205 /* interface setup */
4206 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
4208 struct ieee80211_if_managed
*ifmgd
;
4210 ifmgd
= &sdata
->u
.mgd
;
4211 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
4212 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
4213 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
4214 ieee80211_beacon_connection_loss_work
);
4215 INIT_WORK(&ifmgd
->csa_connection_drop_work
,
4216 ieee80211_csa_connection_drop_work
);
4217 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_mgd_work
);
4218 INIT_DELAYED_WORK(&ifmgd
->tdls_peer_del_work
,
4219 ieee80211_tdls_peer_del_work
);
4220 timer_setup(&ifmgd
->timer
, ieee80211_sta_timer
, 0);
4221 timer_setup(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
, 0);
4222 timer_setup(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
, 0);
4223 timer_setup(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
, 0);
4224 INIT_DELAYED_WORK(&ifmgd
->tx_tspec_wk
,
4225 ieee80211_sta_handle_tspec_ac_params_wk
);
4228 ifmgd
->powersave
= sdata
->wdev
.ps
;
4229 ifmgd
->uapsd_queues
= sdata
->local
->hw
.uapsd_queues
;
4230 ifmgd
->uapsd_max_sp_len
= sdata
->local
->hw
.uapsd_max_sp_len
;
4231 ifmgd
->p2p_noa_index
= -1;
4233 if (sdata
->local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
)
4234 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
4236 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
4238 /* Setup TDLS data */
4239 spin_lock_init(&ifmgd
->teardown_lock
);
4240 ifmgd
->teardown_skb
= NULL
;
4241 ifmgd
->orig_teardown_skb
= NULL
;
4244 /* scan finished notification */
4245 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
4247 struct ieee80211_sub_if_data
*sdata
;
4249 /* Restart STA timers */
4251 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4252 if (ieee80211_sdata_running(sdata
))
4253 ieee80211_restart_sta_timer(sdata
);
4258 static u8
ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data
*sdata
,
4259 struct cfg80211_bss
*cbss
)
4261 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4262 const u8
*ht_cap_ie
, *vht_cap_ie
;
4263 const struct ieee80211_ht_cap
*ht_cap
;
4264 const struct ieee80211_vht_cap
*vht_cap
;
4267 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)
4270 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4271 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
)) {
4272 ht_cap
= (void *)(ht_cap_ie
+ 2);
4273 chains
= ieee80211_mcs_to_chains(&ht_cap
->mcs
);
4275 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4276 * "Tx Unequal Modulation Supported" fields.
4280 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
4283 vht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4284 if (vht_cap_ie
&& vht_cap_ie
[1] >= sizeof(*vht_cap
)) {
4288 vht_cap
= (void *)(vht_cap_ie
+ 2);
4289 tx_mcs_map
= le16_to_cpu(vht_cap
->supp_mcs
.tx_mcs_map
);
4290 for (nss
= 8; nss
> 0; nss
--) {
4291 if (((tx_mcs_map
>> (2 * (nss
- 1))) & 3) !=
4292 IEEE80211_VHT_MCS_NOT_SUPPORTED
)
4295 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4296 chains
= max(chains
, nss
);
4302 static int ieee80211_prep_channel(struct ieee80211_sub_if_data
*sdata
,
4303 struct cfg80211_bss
*cbss
)
4305 struct ieee80211_local
*local
= sdata
->local
;
4306 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4307 const struct ieee80211_ht_cap
*ht_cap
= NULL
;
4308 const struct ieee80211_ht_operation
*ht_oper
= NULL
;
4309 const struct ieee80211_vht_operation
*vht_oper
= NULL
;
4310 struct ieee80211_supported_band
*sband
;
4311 struct cfg80211_chan_def chandef
;
4316 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4318 ifmgd
->flags
&= ~(IEEE80211_STA_DISABLE_40MHZ
|
4319 IEEE80211_STA_DISABLE_80P80MHZ
|
4320 IEEE80211_STA_DISABLE_160MHZ
);
4324 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
4325 sband
->ht_cap
.ht_supported
) {
4326 const u8
*ht_oper_ie
, *ht_cap_ie
;
4328 ht_oper_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_OPERATION
);
4329 if (ht_oper_ie
&& ht_oper_ie
[1] >= sizeof(*ht_oper
))
4330 ht_oper
= (void *)(ht_oper_ie
+ 2);
4332 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4333 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
))
4334 ht_cap
= (void *)(ht_cap_ie
+ 2);
4337 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4342 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
4343 sband
->vht_cap
.vht_supported
) {
4344 const u8
*vht_oper_ie
, *vht_cap
;
4346 vht_oper_ie
= ieee80211_bss_get_ie(cbss
,
4347 WLAN_EID_VHT_OPERATION
);
4348 if (vht_oper_ie
&& vht_oper_ie
[1] >= sizeof(*vht_oper
))
4349 vht_oper
= (void *)(vht_oper_ie
+ 2);
4350 if (vht_oper
&& !ht_oper
) {
4353 "AP advertised VHT without HT, disabling both\n");
4354 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4355 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4358 vht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4359 if (!vht_cap
|| vht_cap
[1] < sizeof(struct ieee80211_vht_cap
)) {
4360 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4365 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4367 for (i
= 0; i
< sband
->n_channels
; i
++) {
4368 if (sband
->channels
[i
].flags
& (IEEE80211_CHAN_DISABLED
|
4369 IEEE80211_CHAN_NO_80MHZ
))
4377 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4379 ifmgd
->flags
|= ieee80211_determine_chantype(sdata
, sband
,
4384 sdata
->needed_rx_chains
= min(ieee80211_ht_vht_rx_chains(sdata
, cbss
),
4389 /* will change later if needed */
4390 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4392 mutex_lock(&local
->mtx
);
4394 * If this fails (possibly due to channel context sharing
4395 * on incompatible channels, e.g. 80+80 and 160 sharing the
4396 * same control channel) try to use a smaller bandwidth.
4398 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4399 IEEE80211_CHANCTX_SHARED
);
4401 /* don't downgrade for 5 and 10 MHz channels, though. */
4402 if (chandef
.width
== NL80211_CHAN_WIDTH_5
||
4403 chandef
.width
== NL80211_CHAN_WIDTH_10
)
4406 while (ret
&& chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) {
4407 ifmgd
->flags
|= ieee80211_chandef_downgrade(&chandef
);
4408 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4409 IEEE80211_CHANCTX_SHARED
);
4412 mutex_unlock(&local
->mtx
);
4416 static int ieee80211_prep_connection(struct ieee80211_sub_if_data
*sdata
,
4417 struct cfg80211_bss
*cbss
, bool assoc
,
4420 struct ieee80211_local
*local
= sdata
->local
;
4421 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4422 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
4423 struct sta_info
*new_sta
= NULL
;
4424 struct ieee80211_supported_band
*sband
;
4425 bool have_sta
= false;
4428 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4430 if (WARN_ON(!ifmgd
->auth_data
&& !ifmgd
->assoc_data
))
4433 /* If a reconfig is happening, bail out */
4434 if (local
->in_reconfig
)
4439 have_sta
= sta_info_get(sdata
, cbss
->bssid
);
4444 new_sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
4450 * Set up the information for the new channel before setting the
4451 * new channel. We can't - completely race-free - change the basic
4452 * rates bitmap and the channel (sband) that it refers to, but if
4453 * we set it up before we at least avoid calling into the driver's
4454 * bss_info_changed() method with invalid information (since we do
4455 * call that from changing the channel - only for IDLE and perhaps
4456 * some others, but ...).
4458 * So to avoid that, just set up all the new information before the
4459 * channel, but tell the driver to apply it only afterwards, since
4460 * it might need the new channel for that.
4463 u32 rates
= 0, basic_rates
= 0;
4464 bool have_higher_than_11mbit
;
4465 int min_rate
= INT_MAX
, min_rate_index
= -1;
4466 const struct cfg80211_bss_ies
*ies
;
4467 int shift
= ieee80211_vif_get_shift(&sdata
->vif
);
4469 ieee80211_get_rates(sband
, bss
->supp_rates
,
4470 bss
->supp_rates_len
,
4471 &rates
, &basic_rates
,
4472 &have_higher_than_11mbit
,
4473 &min_rate
, &min_rate_index
,
4477 * This used to be a workaround for basic rates missing
4478 * in the association response frame. Now that we no
4479 * longer use the basic rates from there, it probably
4480 * doesn't happen any more, but keep the workaround so
4481 * in case some *other* APs are buggy in different ways
4482 * we can connect -- with a warning.
4484 if (!basic_rates
&& min_rate_index
>= 0) {
4486 "No basic rates, using min rate instead\n");
4487 basic_rates
= BIT(min_rate_index
);
4490 new_sta
->sta
.supp_rates
[cbss
->channel
->band
] = rates
;
4491 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
4493 /* cf. IEEE 802.11 9.2.12 */
4494 if (cbss
->channel
->band
== NL80211_BAND_2GHZ
&&
4495 have_higher_than_11mbit
)
4496 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
4498 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
4500 memcpy(ifmgd
->bssid
, cbss
->bssid
, ETH_ALEN
);
4502 /* set timing information */
4503 sdata
->vif
.bss_conf
.beacon_int
= cbss
->beacon_interval
;
4505 ies
= rcu_dereference(cbss
->beacon_ies
);
4509 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4510 sdata
->vif
.bss_conf
.sync_device_ts
=
4511 bss
->device_ts_beacon
;
4512 tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4513 ies
->data
, ies
->len
);
4514 if (tim_ie
&& tim_ie
[1] >= 2)
4515 sdata
->vif
.bss_conf
.sync_dtim_count
= tim_ie
[2];
4517 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4518 } else if (!ieee80211_hw_check(&sdata
->local
->hw
,
4519 TIMING_BEACON_ONLY
)) {
4520 ies
= rcu_dereference(cbss
->proberesp_ies
);
4521 /* must be non-NULL since beacon IEs were NULL */
4522 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4523 sdata
->vif
.bss_conf
.sync_device_ts
=
4524 bss
->device_ts_presp
;
4525 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4527 sdata
->vif
.bss_conf
.sync_tsf
= 0;
4528 sdata
->vif
.bss_conf
.sync_device_ts
= 0;
4529 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4534 if (new_sta
|| override
) {
4535 err
= ieee80211_prep_channel(sdata
, cbss
);
4538 sta_info_free(local
, new_sta
);
4545 * tell driver about BSSID, basic rates and timing
4546 * this was set up above, before setting the channel
4548 ieee80211_bss_info_change_notify(sdata
,
4549 BSS_CHANGED_BSSID
| BSS_CHANGED_BASIC_RATES
|
4550 BSS_CHANGED_BEACON_INT
);
4553 sta_info_pre_move_state(new_sta
, IEEE80211_STA_AUTH
);
4555 err
= sta_info_insert(new_sta
);
4559 "failed to insert STA entry for the AP (error %d)\n",
4564 WARN_ON_ONCE(!ether_addr_equal(ifmgd
->bssid
, cbss
->bssid
));
4566 /* Cancel scan to ensure that nothing interferes with connection */
4567 if (local
->scanning
)
4568 ieee80211_scan_cancel(local
);
4574 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
4575 struct cfg80211_auth_request
*req
)
4577 struct ieee80211_local
*local
= sdata
->local
;
4578 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4579 struct ieee80211_mgd_auth_data
*auth_data
;
4583 /* prepare auth data structure */
4585 switch (req
->auth_type
) {
4586 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
4587 auth_alg
= WLAN_AUTH_OPEN
;
4589 case NL80211_AUTHTYPE_SHARED_KEY
:
4590 if (IS_ERR(local
->wep_tx_tfm
))
4592 auth_alg
= WLAN_AUTH_SHARED_KEY
;
4594 case NL80211_AUTHTYPE_FT
:
4595 auth_alg
= WLAN_AUTH_FT
;
4597 case NL80211_AUTHTYPE_NETWORK_EAP
:
4598 auth_alg
= WLAN_AUTH_LEAP
;
4600 case NL80211_AUTHTYPE_SAE
:
4601 auth_alg
= WLAN_AUTH_SAE
;
4603 case NL80211_AUTHTYPE_FILS_SK
:
4604 auth_alg
= WLAN_AUTH_FILS_SK
;
4606 case NL80211_AUTHTYPE_FILS_SK_PFS
:
4607 auth_alg
= WLAN_AUTH_FILS_SK_PFS
;
4609 case NL80211_AUTHTYPE_FILS_PK
:
4610 auth_alg
= WLAN_AUTH_FILS_PK
;
4616 auth_data
= kzalloc(sizeof(*auth_data
) + req
->auth_data_len
+
4617 req
->ie_len
, GFP_KERNEL
);
4621 auth_data
->bss
= req
->bss
;
4623 if (req
->auth_data_len
>= 4) {
4624 if (req
->auth_type
== NL80211_AUTHTYPE_SAE
) {
4625 __le16
*pos
= (__le16
*) req
->auth_data
;
4627 auth_data
->sae_trans
= le16_to_cpu(pos
[0]);
4628 auth_data
->sae_status
= le16_to_cpu(pos
[1]);
4630 memcpy(auth_data
->data
, req
->auth_data
+ 4,
4631 req
->auth_data_len
- 4);
4632 auth_data
->data_len
+= req
->auth_data_len
- 4;
4635 if (req
->ie
&& req
->ie_len
) {
4636 memcpy(&auth_data
->data
[auth_data
->data_len
],
4637 req
->ie
, req
->ie_len
);
4638 auth_data
->data_len
+= req
->ie_len
;
4641 if (req
->key
&& req
->key_len
) {
4642 auth_data
->key_len
= req
->key_len
;
4643 auth_data
->key_idx
= req
->key_idx
;
4644 memcpy(auth_data
->key
, req
->key
, req
->key_len
);
4647 auth_data
->algorithm
= auth_alg
;
4649 /* try to authenticate/probe */
4651 if ((ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) ||
4652 ifmgd
->assoc_data
) {
4657 if (ifmgd
->auth_data
)
4658 ieee80211_destroy_auth_data(sdata
, false);
4660 /* prep auth_data so we don't go into idle on disassoc */
4661 ifmgd
->auth_data
= auth_data
;
4663 if (ifmgd
->associated
) {
4664 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4667 "disconnect from AP %pM for new auth to %pM\n",
4668 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
4669 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4670 WLAN_REASON_UNSPECIFIED
,
4673 ieee80211_report_disconnect(sdata
, frame_buf
,
4674 sizeof(frame_buf
), true,
4675 WLAN_REASON_UNSPECIFIED
);
4678 sdata_info(sdata
, "authenticate with %pM\n", req
->bss
->bssid
);
4680 err
= ieee80211_prep_connection(sdata
, req
->bss
, false, false);
4684 err
= ieee80211_auth(sdata
);
4686 sta_info_destroy_addr(sdata
, req
->bss
->bssid
);
4690 /* hold our own reference */
4691 cfg80211_ref_bss(local
->hw
.wiphy
, auth_data
->bss
);
4695 eth_zero_addr(ifmgd
->bssid
);
4696 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
4697 ifmgd
->auth_data
= NULL
;
4698 mutex_lock(&sdata
->local
->mtx
);
4699 ieee80211_vif_release_channel(sdata
);
4700 mutex_unlock(&sdata
->local
->mtx
);
4706 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
4707 struct cfg80211_assoc_request
*req
)
4709 struct ieee80211_local
*local
= sdata
->local
;
4710 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4711 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
4712 struct ieee80211_mgd_assoc_data
*assoc_data
;
4713 const struct cfg80211_bss_ies
*beacon_ies
;
4714 struct ieee80211_supported_band
*sband
;
4715 const u8
*ssidie
, *ht_ie
, *vht_ie
;
4717 bool override
= false;
4719 assoc_data
= kzalloc(sizeof(*assoc_data
) + req
->ie_len
, GFP_KERNEL
);
4724 ssidie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
4730 memcpy(assoc_data
->ssid
, ssidie
+ 2, ssidie
[1]);
4731 assoc_data
->ssid_len
= ssidie
[1];
4734 if (ifmgd
->associated
) {
4735 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4738 "disconnect from AP %pM for new assoc to %pM\n",
4739 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
4740 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4741 WLAN_REASON_UNSPECIFIED
,
4744 ieee80211_report_disconnect(sdata
, frame_buf
,
4745 sizeof(frame_buf
), true,
4746 WLAN_REASON_UNSPECIFIED
);
4749 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) {
4754 if (ifmgd
->assoc_data
) {
4759 if (ifmgd
->auth_data
) {
4762 /* keep sta info, bssid if matching */
4763 match
= ether_addr_equal(ifmgd
->bssid
, req
->bss
->bssid
);
4764 ieee80211_destroy_auth_data(sdata
, match
);
4767 /* prepare assoc data */
4769 ifmgd
->beacon_crc_valid
= false;
4771 assoc_data
->wmm
= bss
->wmm_used
&&
4772 (local
->hw
.queues
>= IEEE80211_NUM_ACS
);
4775 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4776 * We still associate in non-HT mode (11a/b/g) if any one of these
4777 * ciphers is configured as pairwise.
4778 * We can set this to true for non-11n hardware, that'll be checked
4779 * separately along with the peer capabilities.
4781 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++) {
4782 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
4783 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
4784 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
) {
4785 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4786 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4787 netdev_info(sdata
->dev
,
4788 "disabling HT/VHT due to WEP/TKIP use\n");
4792 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4793 sband
= local
->hw
.wiphy
->bands
[req
->bss
->channel
->band
];
4794 if (!sband
->ht_cap
.ht_supported
||
4795 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4796 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4797 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4798 if (!bss
->wmm_used
&&
4799 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4800 netdev_info(sdata
->dev
,
4801 "disabling HT as WMM/QoS is not supported by the AP\n");
4804 /* disable VHT if we don't support it or the AP doesn't use WMM */
4805 if (!sband
->vht_cap
.vht_supported
||
4806 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4807 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4808 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4809 if (!bss
->wmm_used
&&
4810 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4811 netdev_info(sdata
->dev
,
4812 "disabling VHT as WMM/QoS is not supported by the AP\n");
4815 memcpy(&ifmgd
->ht_capa
, &req
->ht_capa
, sizeof(ifmgd
->ht_capa
));
4816 memcpy(&ifmgd
->ht_capa_mask
, &req
->ht_capa_mask
,
4817 sizeof(ifmgd
->ht_capa_mask
));
4819 memcpy(&ifmgd
->vht_capa
, &req
->vht_capa
, sizeof(ifmgd
->vht_capa
));
4820 memcpy(&ifmgd
->vht_capa_mask
, &req
->vht_capa_mask
,
4821 sizeof(ifmgd
->vht_capa_mask
));
4823 if (req
->ie
&& req
->ie_len
) {
4824 memcpy(assoc_data
->ie
, req
->ie
, req
->ie_len
);
4825 assoc_data
->ie_len
= req
->ie_len
;
4828 if (req
->fils_kek
) {
4829 /* should already be checked in cfg80211 - so warn */
4830 if (WARN_ON(req
->fils_kek_len
> FILS_MAX_KEK_LEN
)) {
4834 memcpy(assoc_data
->fils_kek
, req
->fils_kek
,
4836 assoc_data
->fils_kek_len
= req
->fils_kek_len
;
4839 if (req
->fils_nonces
)
4840 memcpy(assoc_data
->fils_nonces
, req
->fils_nonces
,
4841 2 * FILS_NONCE_LEN
);
4843 assoc_data
->bss
= req
->bss
;
4845 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
4846 if (ifmgd
->powersave
)
4847 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
4849 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4851 sdata
->smps_mode
= ifmgd
->req_smps
;
4853 assoc_data
->capability
= req
->bss
->capability
;
4854 assoc_data
->supp_rates
= bss
->supp_rates
;
4855 assoc_data
->supp_rates_len
= bss
->supp_rates_len
;
4858 ht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_OPERATION
);
4859 if (ht_ie
&& ht_ie
[1] >= sizeof(struct ieee80211_ht_operation
))
4860 assoc_data
->ap_ht_param
=
4861 ((struct ieee80211_ht_operation
*)(ht_ie
+ 2))->ht_param
;
4863 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4864 vht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_VHT_CAPABILITY
);
4865 if (vht_ie
&& vht_ie
[1] >= sizeof(struct ieee80211_vht_cap
))
4866 memcpy(&assoc_data
->ap_vht_cap
, vht_ie
+ 2,
4867 sizeof(struct ieee80211_vht_cap
));
4869 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4872 if (WARN((sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
) &&
4873 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
),
4874 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
4875 sdata
->vif
.driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
4877 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
4878 (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
)) {
4879 assoc_data
->uapsd
= true;
4880 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
4882 assoc_data
->uapsd
= false;
4883 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
4886 if (req
->prev_bssid
)
4887 memcpy(assoc_data
->prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
4890 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
4891 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
4893 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
4894 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
4897 if (req
->flags
& ASSOC_REQ_USE_RRM
)
4898 ifmgd
->flags
|= IEEE80211_STA_ENABLE_RRM
;
4900 ifmgd
->flags
&= ~IEEE80211_STA_ENABLE_RRM
;
4902 if (req
->crypto
.control_port
)
4903 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
4905 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
4907 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
4908 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
4909 sdata
->encrypt_headroom
= ieee80211_cs_headroom(local
, &req
->crypto
,
4912 /* kick off associate process */
4914 ifmgd
->assoc_data
= assoc_data
;
4915 ifmgd
->dtim_period
= 0;
4916 ifmgd
->have_beacon
= false;
4918 /* override HT/VHT configuration only if the AP and we support it */
4919 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
4920 struct ieee80211_sta_ht_cap sta_ht_cap
;
4922 if (req
->flags
& ASSOC_REQ_DISABLE_HT
)
4925 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
4926 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
4928 /* check for 40 MHz disable override */
4929 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
) &&
4930 sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
&&
4931 !(sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
4934 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
4935 req
->flags
& ASSOC_REQ_DISABLE_VHT
)
4939 if (req
->flags
& ASSOC_REQ_DISABLE_HT
) {
4940 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4941 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4944 if (req
->flags
& ASSOC_REQ_DISABLE_VHT
)
4945 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4947 err
= ieee80211_prep_connection(sdata
, req
->bss
, true, override
);
4952 beacon_ies
= rcu_dereference(req
->bss
->beacon_ies
);
4954 if (ieee80211_hw_check(&sdata
->local
->hw
, NEED_DTIM_BEFORE_ASSOC
) &&
4957 * Wait up to one beacon interval ...
4958 * should this be more if we miss one?
4960 sdata_info(sdata
, "waiting for beacon from %pM\n",
4962 assoc_data
->timeout
= TU_TO_EXP_TIME(req
->bss
->beacon_interval
);
4963 assoc_data
->timeout_started
= true;
4964 assoc_data
->need_beacon
= true;
4965 } else if (beacon_ies
) {
4966 const u8
*tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4971 if (tim_ie
&& tim_ie
[1] >= sizeof(struct ieee80211_tim_ie
)) {
4972 const struct ieee80211_tim_ie
*tim
;
4973 tim
= (void *)(tim_ie
+ 2);
4974 ifmgd
->dtim_period
= tim
->dtim_period
;
4975 dtim_count
= tim
->dtim_count
;
4977 ifmgd
->have_beacon
= true;
4978 assoc_data
->timeout
= jiffies
;
4979 assoc_data
->timeout_started
= true;
4981 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
4982 sdata
->vif
.bss_conf
.sync_tsf
= beacon_ies
->tsf
;
4983 sdata
->vif
.bss_conf
.sync_device_ts
=
4984 bss
->device_ts_beacon
;
4985 sdata
->vif
.bss_conf
.sync_dtim_count
= dtim_count
;
4988 assoc_data
->timeout
= jiffies
;
4989 assoc_data
->timeout_started
= true;
4993 run_again(sdata
, assoc_data
->timeout
);
4995 if (bss
->corrupt_data
) {
4996 char *corrupt_type
= "data";
4997 if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_BEACON
) {
4998 if (bss
->corrupt_data
&
4999 IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5000 corrupt_type
= "beacon and probe response";
5002 corrupt_type
= "beacon";
5003 } else if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_PROBE_RESP
)
5004 corrupt_type
= "probe response";
5005 sdata_info(sdata
, "associating with AP with corrupt %s\n",
5011 eth_zero_addr(ifmgd
->bssid
);
5012 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
5013 ifmgd
->assoc_data
= NULL
;
5019 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
5020 struct cfg80211_deauth_request
*req
)
5022 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5023 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5024 bool tx
= !req
->local_state_change
;
5026 if (ifmgd
->auth_data
&&
5027 ether_addr_equal(ifmgd
->auth_data
->bss
->bssid
, req
->bssid
)) {
5029 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5030 req
->bssid
, req
->reason_code
,
5031 ieee80211_get_reason_code_string(req
->reason_code
));
5033 drv_mgd_prepare_tx(sdata
->local
, sdata
);
5034 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
5035 IEEE80211_STYPE_DEAUTH
,
5036 req
->reason_code
, tx
,
5038 ieee80211_destroy_auth_data(sdata
, false);
5039 ieee80211_report_disconnect(sdata
, frame_buf
,
5040 sizeof(frame_buf
), true,
5046 if (ifmgd
->assoc_data
&&
5047 ether_addr_equal(ifmgd
->assoc_data
->bss
->bssid
, req
->bssid
)) {
5049 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5050 req
->bssid
, req
->reason_code
,
5051 ieee80211_get_reason_code_string(req
->reason_code
));
5053 drv_mgd_prepare_tx(sdata
->local
, sdata
);
5054 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
5055 IEEE80211_STYPE_DEAUTH
,
5056 req
->reason_code
, tx
,
5058 ieee80211_destroy_assoc_data(sdata
, false, true);
5059 ieee80211_report_disconnect(sdata
, frame_buf
,
5060 sizeof(frame_buf
), true,
5065 if (ifmgd
->associated
&&
5066 ether_addr_equal(ifmgd
->associated
->bssid
, req
->bssid
)) {
5068 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5069 req
->bssid
, req
->reason_code
,
5070 ieee80211_get_reason_code_string(req
->reason_code
));
5072 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
5073 req
->reason_code
, tx
, frame_buf
);
5074 ieee80211_report_disconnect(sdata
, frame_buf
,
5075 sizeof(frame_buf
), true,
5083 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
5084 struct cfg80211_disassoc_request
*req
)
5086 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5088 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5091 * cfg80211 should catch this ... but it's racy since
5092 * we can receive a disassoc frame, process it, hand it
5093 * to cfg80211 while that's in a locked section already
5094 * trying to tell us that the user wants to disconnect.
5096 if (ifmgd
->associated
!= req
->bss
)
5100 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5101 req
->bss
->bssid
, req
->reason_code
, ieee80211_get_reason_code_string(req
->reason_code
));
5103 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
5104 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DISASSOC
,
5105 req
->reason_code
, !req
->local_state_change
,
5108 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
5114 void ieee80211_mgd_stop(struct ieee80211_sub_if_data
*sdata
)
5116 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5119 * Make sure some work items will not run after this,
5120 * they will not do anything but might not have been
5121 * cancelled when disconnecting.
5123 cancel_work_sync(&ifmgd
->monitor_work
);
5124 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
5125 cancel_work_sync(&ifmgd
->request_smps_work
);
5126 cancel_work_sync(&ifmgd
->csa_connection_drop_work
);
5127 cancel_work_sync(&ifmgd
->chswitch_work
);
5128 cancel_delayed_work_sync(&ifmgd
->tdls_peer_del_work
);
5131 if (ifmgd
->assoc_data
) {
5132 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
5133 ieee80211_destroy_assoc_data(sdata
, false, false);
5134 cfg80211_assoc_timeout(sdata
->dev
, bss
);
5136 if (ifmgd
->auth_data
)
5137 ieee80211_destroy_auth_data(sdata
, false);
5138 spin_lock_bh(&ifmgd
->teardown_lock
);
5139 if (ifmgd
->teardown_skb
) {
5140 kfree_skb(ifmgd
->teardown_skb
);
5141 ifmgd
->teardown_skb
= NULL
;
5142 ifmgd
->orig_teardown_skb
= NULL
;
5144 spin_unlock_bh(&ifmgd
->teardown_lock
);
5145 del_timer_sync(&ifmgd
->timer
);
5146 sdata_unlock(sdata
);
5149 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
5150 enum nl80211_cqm_rssi_threshold_event rssi_event
,
5154 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5156 trace_api_cqm_rssi_notify(sdata
, rssi_event
, rssi_level
);
5158 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, rssi_level
, gfp
);
5160 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);
5162 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif
*vif
, gfp_t gfp
)
5164 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5166 trace_api_cqm_beacon_loss_notify(sdata
->local
, sdata
);
5168 cfg80211_cqm_beacon_loss_notify(sdata
->dev
, gfp
);
5170 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify
);