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_MAX_TRIES 3
39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
41 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
42 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
43 #define IEEE80211_ASSOC_MAX_TRIES 3
45 static int max_nullfunc_tries
= 2;
46 module_param(max_nullfunc_tries
, int, 0644);
47 MODULE_PARM_DESC(max_nullfunc_tries
,
48 "Maximum nullfunc tx tries before disconnecting (reason 4).");
50 static int max_probe_tries
= 5;
51 module_param(max_probe_tries
, int, 0644);
52 MODULE_PARM_DESC(max_probe_tries
,
53 "Maximum probe tries before disconnecting (reason 4).");
56 * Beacon loss timeout is calculated as N frames times the
57 * advertised beacon interval. This may need to be somewhat
58 * higher than what hardware might detect to account for
59 * delays in the host processing frames. But since we also
60 * probe on beacon miss before declaring the connection lost
61 * default to what we want.
63 static int beacon_loss_count
= 7;
64 module_param(beacon_loss_count
, int, 0644);
65 MODULE_PARM_DESC(beacon_loss_count
,
66 "Number of beacon intervals before we decide beacon was lost.");
69 * Time the connection can be idle before we probe
70 * it to see if we can still talk to the AP.
72 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
74 * Time we wait for a probe response after sending
75 * a probe request because of beacon loss or for
76 * checking the connection still works.
78 static int probe_wait_ms
= 500;
79 module_param(probe_wait_ms
, int, 0644);
80 MODULE_PARM_DESC(probe_wait_ms
,
81 "Maximum time(ms) to wait for probe response"
82 " before disconnecting (reason 4).");
85 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
88 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91 * We can have multiple work items (and connection probing)
92 * scheduling this timer, but we need to take care to only
93 * reschedule it when it should fire _earlier_ than it was
94 * asked for before, or if it's not pending right now. This
95 * function ensures that. Note that it then is required to
96 * run this function for all timeouts after the first one
97 * has happened -- the work that runs from this timer will
100 static void run_again(struct ieee80211_sub_if_data
*sdata
,
101 unsigned long timeout
)
103 sdata_assert_lock(sdata
);
105 if (!timer_pending(&sdata
->u
.mgd
.timer
) ||
106 time_before(timeout
, sdata
->u
.mgd
.timer
.expires
))
107 mod_timer(&sdata
->u
.mgd
.timer
, timeout
);
110 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
112 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
115 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
118 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
119 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
122 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
124 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
126 if (unlikely(!ifmgd
->associated
))
129 if (ifmgd
->probe_send_count
)
130 ifmgd
->probe_send_count
= 0;
132 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
135 mod_timer(&ifmgd
->conn_mon_timer
,
136 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
139 static int ecw2cw(int ecw
)
141 return (1 << ecw
) - 1;
145 ieee80211_determine_chantype(struct ieee80211_sub_if_data
*sdata
,
146 struct ieee80211_supported_band
*sband
,
147 struct ieee80211_channel
*channel
,
148 const struct ieee80211_ht_operation
*ht_oper
,
149 const struct ieee80211_vht_operation
*vht_oper
,
150 struct cfg80211_chan_def
*chandef
, bool tracking
)
152 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
153 struct cfg80211_chan_def vht_chandef
;
154 struct ieee80211_sta_ht_cap sta_ht_cap
;
157 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
158 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
160 chandef
->chan
= channel
;
161 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
162 chandef
->center_freq1
= channel
->center_freq
;
163 chandef
->center_freq2
= 0;
165 if (!ht_oper
|| !sta_ht_cap
.ht_supported
) {
166 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
170 chandef
->width
= NL80211_CHAN_WIDTH_20
;
172 ht_cfreq
= ieee80211_channel_to_frequency(ht_oper
->primary_chan
,
174 /* check that channel matches the right operating channel */
175 if (!tracking
&& channel
->center_freq
!= ht_cfreq
) {
177 * It's possible that some APs are confused here;
178 * Netgear WNDR3700 sometimes reports 4 higher than
179 * the actual channel in association responses, but
180 * since we look at probe response/beacon data here
184 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
185 channel
->center_freq
, ht_cfreq
,
186 ht_oper
->primary_chan
, channel
->band
);
187 ret
= IEEE80211_STA_DISABLE_HT
| IEEE80211_STA_DISABLE_VHT
;
191 /* check 40 MHz support, if we have it */
192 if (sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) {
193 ieee80211_chandef_ht_oper(ht_oper
, chandef
);
195 /* 40 MHz (and 80 MHz) must be supported for VHT */
196 ret
= IEEE80211_STA_DISABLE_VHT
;
197 /* also mark 40 MHz disabled */
198 ret
|= IEEE80211_STA_DISABLE_40MHZ
;
202 if (!vht_oper
|| !sband
->vht_cap
.vht_supported
) {
203 ret
= IEEE80211_STA_DISABLE_VHT
;
207 vht_chandef
= *chandef
;
208 if (!ieee80211_chandef_vht_oper(vht_oper
, &vht_chandef
)) {
209 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
211 "AP VHT information is invalid, disable VHT\n");
212 ret
= IEEE80211_STA_DISABLE_VHT
;
216 if (!cfg80211_chandef_valid(&vht_chandef
)) {
217 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
219 "AP VHT information is invalid, disable VHT\n");
220 ret
= IEEE80211_STA_DISABLE_VHT
;
224 if (cfg80211_chandef_identical(chandef
, &vht_chandef
)) {
229 if (!cfg80211_chandef_compatible(chandef
, &vht_chandef
)) {
230 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
232 "AP VHT information doesn't match HT, disable VHT\n");
233 ret
= IEEE80211_STA_DISABLE_VHT
;
237 *chandef
= vht_chandef
;
243 * When tracking the current AP, don't do any further checks if the
244 * new chandef is identical to the one we're currently using for the
245 * connection. This keeps us from playing ping-pong with regulatory,
246 * without it the following can happen (for example):
247 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
248 * - AP advertises regdom US
249 * - CRDA loads regdom US with 80 MHz prohibited (old database)
250 * - the code below detects an unsupported channel, downgrades, and
251 * we disconnect from the AP in the caller
252 * - disconnect causes CRDA to reload world regdomain and the game
254 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
256 * It seems possible that there are still scenarios with CSA or real
257 * bandwidth changes where a this could happen, but those cases are
258 * less common and wouldn't completely prevent using the AP.
261 cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
))
264 /* don't print the message below for VHT mismatch if VHT is disabled */
265 if (ret
& IEEE80211_STA_DISABLE_VHT
)
266 vht_chandef
= *chandef
;
269 * Ignore the DISABLED flag when we're already connected and only
270 * tracking the APs beacon for bandwidth changes - otherwise we
271 * might get disconnected here if we connect to an AP, update our
272 * regulatory information based on the AP's country IE and the
273 * information we have is wrong/outdated and disables the channel
274 * that we're actually using for the connection to the AP.
276 while (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
278 IEEE80211_CHAN_DISABLED
)) {
279 if (WARN_ON(chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
)) {
280 ret
= IEEE80211_STA_DISABLE_HT
|
281 IEEE80211_STA_DISABLE_VHT
;
285 ret
|= ieee80211_chandef_downgrade(chandef
);
288 if (chandef
->width
!= vht_chandef
.width
&& !tracking
)
290 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
292 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef
));
296 static int ieee80211_config_bw(struct ieee80211_sub_if_data
*sdata
,
297 struct sta_info
*sta
,
298 const struct ieee80211_ht_cap
*ht_cap
,
299 const struct ieee80211_ht_operation
*ht_oper
,
300 const struct ieee80211_vht_operation
*vht_oper
,
301 const u8
*bssid
, u32
*changed
)
303 struct ieee80211_local
*local
= sdata
->local
;
304 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
305 struct ieee80211_supported_band
*sband
;
306 struct ieee80211_channel
*chan
;
307 struct cfg80211_chan_def chandef
;
310 enum ieee80211_sta_rx_bandwidth new_sta_bw
;
313 /* if HT was/is disabled, don't track any bandwidth changes */
314 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
|| !ht_oper
)
317 /* don't check VHT if we associated as non-VHT station */
318 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
321 if (WARN_ON_ONCE(!sta
))
325 * if bss configuration changed store the new one -
326 * this may be applicable even if channel is identical
328 ht_opmode
= le16_to_cpu(ht_oper
->operation_mode
);
329 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
330 *changed
|= BSS_CHANGED_HT
;
331 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
334 chan
= sdata
->vif
.bss_conf
.chandef
.chan
;
335 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
337 /* calculate new channel (type) based on HT/VHT operation IEs */
338 flags
= ieee80211_determine_chantype(sdata
, sband
, chan
,
343 * Downgrade the new channel if we associated with restricted
344 * capabilities. For example, if we associated as a 20 MHz STA
345 * to a 40 MHz AP (due to regulatory, capabilities or config
346 * reasons) then switching to a 40 MHz channel now won't do us
347 * any good -- we couldn't use it with the AP.
349 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_80P80MHZ
&&
350 chandef
.width
== NL80211_CHAN_WIDTH_80P80
)
351 flags
|= ieee80211_chandef_downgrade(&chandef
);
352 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_160MHZ
&&
353 chandef
.width
== NL80211_CHAN_WIDTH_160
)
354 flags
|= ieee80211_chandef_downgrade(&chandef
);
355 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
&&
356 chandef
.width
> NL80211_CHAN_WIDTH_20
)
357 flags
|= ieee80211_chandef_downgrade(&chandef
);
359 if (cfg80211_chandef_identical(&chandef
, &sdata
->vif
.bss_conf
.chandef
))
363 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
364 ifmgd
->bssid
, chandef
.chan
->center_freq
, chandef
.width
,
365 chandef
.center_freq1
, chandef
.center_freq2
);
367 if (flags
!= (ifmgd
->flags
& (IEEE80211_STA_DISABLE_HT
|
368 IEEE80211_STA_DISABLE_VHT
|
369 IEEE80211_STA_DISABLE_40MHZ
|
370 IEEE80211_STA_DISABLE_80P80MHZ
|
371 IEEE80211_STA_DISABLE_160MHZ
)) ||
372 !cfg80211_chandef_valid(&chandef
)) {
374 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
379 switch (chandef
.width
) {
380 case NL80211_CHAN_WIDTH_20_NOHT
:
381 case NL80211_CHAN_WIDTH_20
:
382 new_sta_bw
= IEEE80211_STA_RX_BW_20
;
384 case NL80211_CHAN_WIDTH_40
:
385 new_sta_bw
= IEEE80211_STA_RX_BW_40
;
387 case NL80211_CHAN_WIDTH_80
:
388 new_sta_bw
= IEEE80211_STA_RX_BW_80
;
390 case NL80211_CHAN_WIDTH_80P80
:
391 case NL80211_CHAN_WIDTH_160
:
392 new_sta_bw
= IEEE80211_STA_RX_BW_160
;
398 if (new_sta_bw
> sta
->cur_max_bandwidth
)
399 new_sta_bw
= sta
->cur_max_bandwidth
;
401 if (new_sta_bw
< sta
->sta
.bandwidth
) {
402 sta
->sta
.bandwidth
= new_sta_bw
;
403 rate_control_rate_update(local
, sband
, sta
,
404 IEEE80211_RC_BW_CHANGED
);
407 ret
= ieee80211_vif_change_bandwidth(sdata
, &chandef
, changed
);
410 "AP %pM changed bandwidth to incompatible one - disconnect\n",
415 if (new_sta_bw
> sta
->sta
.bandwidth
) {
416 sta
->sta
.bandwidth
= new_sta_bw
;
417 rate_control_rate_update(local
, sband
, sta
,
418 IEEE80211_RC_BW_CHANGED
);
424 /* frame sending functions */
426 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data
*sdata
,
427 struct sk_buff
*skb
, u8 ap_ht_param
,
428 struct ieee80211_supported_band
*sband
,
429 struct ieee80211_channel
*channel
,
430 enum ieee80211_smps_mode smps
)
433 u32 flags
= channel
->flags
;
435 struct ieee80211_sta_ht_cap ht_cap
;
437 BUILD_BUG_ON(sizeof(ht_cap
) != sizeof(sband
->ht_cap
));
439 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
440 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
442 /* determine capability flags */
445 switch (ap_ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
446 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
447 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
448 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
449 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
452 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
453 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
454 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
455 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
461 * If 40 MHz was disabled associate as though we weren't
462 * capable of 40 MHz -- some broken APs will never fall
463 * back to trying to transmit in 20 MHz.
465 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_40MHZ
) {
466 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
467 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
470 /* set SM PS mode properly */
471 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
473 case IEEE80211_SMPS_AUTOMATIC
:
474 case IEEE80211_SMPS_NUM_MODES
:
476 case IEEE80211_SMPS_OFF
:
477 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
478 IEEE80211_HT_CAP_SM_PS_SHIFT
;
480 case IEEE80211_SMPS_STATIC
:
481 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
482 IEEE80211_HT_CAP_SM_PS_SHIFT
;
484 case IEEE80211_SMPS_DYNAMIC
:
485 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
486 IEEE80211_HT_CAP_SM_PS_SHIFT
;
490 /* reserve and fill IE */
491 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
492 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, cap
);
495 /* This function determines vht capability flags for the association
497 * Note - the function may set the owner of the MU-MIMO capability
499 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data
*sdata
,
501 struct ieee80211_supported_band
*sband
,
502 struct ieee80211_vht_cap
*ap_vht_cap
)
504 struct ieee80211_local
*local
= sdata
->local
;
507 struct ieee80211_sta_vht_cap vht_cap
;
508 u32 mask
, ap_bf_sts
, our_bf_sts
;
510 BUILD_BUG_ON(sizeof(vht_cap
) != sizeof(sband
->vht_cap
));
512 memcpy(&vht_cap
, &sband
->vht_cap
, sizeof(vht_cap
));
513 ieee80211_apply_vhtcap_overrides(sdata
, &vht_cap
);
515 /* determine capability flags */
518 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_80P80MHZ
) {
519 u32 bw
= cap
& IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
521 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
522 if (bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
||
523 bw
== IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
)
524 cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
527 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_160MHZ
) {
528 cap
&= ~IEEE80211_VHT_CAP_SHORT_GI_160
;
529 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK
;
533 * Some APs apparently get confused if our capabilities are better
534 * than theirs, so restrict what we advertise in the assoc request.
536 if (!(ap_vht_cap
->vht_cap_info
&
537 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)))
538 cap
&= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
|
539 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
);
540 else if (!(ap_vht_cap
->vht_cap_info
&
541 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE
)))
542 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
545 * If some other vif is using the MU-MIMO capablity we cannot associate
546 * using MU-MIMO - this will lead to contradictions in the group-id
548 * Ownership is defined since association request, in order to avoid
549 * simultaneous associations with MU-MIMO.
551 if (cap
& IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
) {
552 bool disable_mu_mimo
= false;
553 struct ieee80211_sub_if_data
*other
;
555 list_for_each_entry_rcu(other
, &local
->interfaces
, list
) {
556 if (other
->vif
.mu_mimo_owner
) {
557 disable_mu_mimo
= true;
562 cap
&= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE
;
564 sdata
->vif
.mu_mimo_owner
= true;
567 mask
= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
569 ap_bf_sts
= le32_to_cpu(ap_vht_cap
->vht_cap_info
) & mask
;
570 our_bf_sts
= cap
& mask
;
572 if (ap_bf_sts
< our_bf_sts
) {
577 /* reserve and fill IE */
578 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
579 ieee80211_ie_build_vht_cap(pos
, &vht_cap
, cap
);
582 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
)
584 struct ieee80211_local
*local
= sdata
->local
;
585 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
586 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
588 struct ieee80211_mgmt
*mgmt
;
590 size_t offset
= 0, noffset
;
591 int i
, count
, rates_len
, supp_rates_len
, shift
;
593 struct ieee80211_supported_band
*sband
;
594 struct ieee80211_chanctx_conf
*chanctx_conf
;
595 struct ieee80211_channel
*chan
;
598 sdata_assert_lock(sdata
);
601 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
602 if (WARN_ON(!chanctx_conf
)) {
606 chan
= chanctx_conf
->def
.chan
;
608 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
609 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
611 if (assoc_data
->supp_rates_len
) {
613 * Get all rates supported by the device and the AP as
614 * some APs don't like getting a superset of their rates
615 * in the association request (e.g. D-Link DAP 1353 in
618 rates_len
= ieee80211_parse_bitrates(&chanctx_conf
->def
, sband
,
619 assoc_data
->supp_rates
,
620 assoc_data
->supp_rates_len
,
624 * In case AP not provide any supported rates information
625 * before association, we send information element(s) with
626 * all rates that we support.
629 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
635 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
636 sizeof(*mgmt
) + /* bit too much but doesn't matter */
637 2 + assoc_data
->ssid_len
+ /* SSID */
638 4 + rates_len
+ /* (extended) rates */
639 4 + /* power capability */
640 2 + 2 * sband
->n_channels
+ /* supported channels */
641 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
642 2 + sizeof(struct ieee80211_vht_cap
) + /* VHT */
643 assoc_data
->ie_len
+ /* extra IEs */
644 (assoc_data
->fils_kek_len
? 16 /* AES-SIV */ : 0) +
650 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
652 capab
= WLAN_CAPABILITY_ESS
;
654 if (sband
->band
== NL80211_BAND_2GHZ
) {
655 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
656 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
659 if (assoc_data
->capability
& WLAN_CAPABILITY_PRIVACY
)
660 capab
|= WLAN_CAPABILITY_PRIVACY
;
662 if ((assoc_data
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
663 ieee80211_hw_check(&local
->hw
, SPECTRUM_MGMT
))
664 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
666 if (ifmgd
->flags
& IEEE80211_STA_ENABLE_RRM
)
667 capab
|= WLAN_CAPABILITY_RADIO_MEASURE
;
669 mgmt
= skb_put_zero(skb
, 24);
670 memcpy(mgmt
->da
, assoc_data
->bss
->bssid
, ETH_ALEN
);
671 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
672 memcpy(mgmt
->bssid
, assoc_data
->bss
->bssid
, ETH_ALEN
);
674 if (!is_zero_ether_addr(assoc_data
->prev_bssid
)) {
676 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
677 IEEE80211_STYPE_REASSOC_REQ
);
678 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
679 mgmt
->u
.reassoc_req
.listen_interval
=
680 cpu_to_le16(local
->hw
.conf
.listen_interval
);
681 memcpy(mgmt
->u
.reassoc_req
.current_ap
, assoc_data
->prev_bssid
,
685 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
686 IEEE80211_STYPE_ASSOC_REQ
);
687 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
688 mgmt
->u
.assoc_req
.listen_interval
=
689 cpu_to_le16(local
->hw
.conf
.listen_interval
);
693 pos
= skb_put(skb
, 2 + assoc_data
->ssid_len
);
694 *pos
++ = WLAN_EID_SSID
;
695 *pos
++ = assoc_data
->ssid_len
;
696 memcpy(pos
, assoc_data
->ssid
, assoc_data
->ssid_len
);
698 /* add all rates which were marked to be used above */
699 supp_rates_len
= rates_len
;
700 if (supp_rates_len
> 8)
703 pos
= skb_put(skb
, supp_rates_len
+ 2);
704 *pos
++ = WLAN_EID_SUPP_RATES
;
705 *pos
++ = supp_rates_len
;
708 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
709 if (BIT(i
) & rates
) {
710 int rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
718 if (rates_len
> count
) {
719 pos
= skb_put(skb
, rates_len
- count
+ 2);
720 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
721 *pos
++ = rates_len
- count
;
723 for (i
++; i
< sband
->n_bitrates
; i
++) {
724 if (BIT(i
) & rates
) {
726 rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
733 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
||
734 capab
& WLAN_CAPABILITY_RADIO_MEASURE
) {
735 pos
= skb_put(skb
, 4);
736 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
738 *pos
++ = 0; /* min tx power */
740 *pos
++ = ieee80211_chandef_max_power(&chanctx_conf
->def
);
743 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
744 /* TODO: get this in reg domain format */
745 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
746 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
747 *pos
++ = 2 * sband
->n_channels
;
748 for (i
= 0; i
< sband
->n_channels
; i
++) {
749 *pos
++ = ieee80211_frequency_to_channel(
750 sband
->channels
[i
].center_freq
);
751 *pos
++ = 1; /* one channel in the subband*/
755 /* if present, add any custom IEs that go before HT */
756 if (assoc_data
->ie_len
) {
757 static const u8 before_ht
[] = {
760 WLAN_EID_EXT_SUPP_RATES
,
761 WLAN_EID_PWR_CAPABILITY
,
762 WLAN_EID_SUPPORTED_CHANNELS
,
765 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
766 WLAN_EID_MOBILITY_DOMAIN
,
767 WLAN_EID_FAST_BSS_TRANSITION
, /* reassoc only */
768 WLAN_EID_RIC_DATA
, /* reassoc only */
769 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
771 static const u8 after_ric
[] = {
772 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
773 WLAN_EID_HT_CAPABILITY
,
774 WLAN_EID_BSS_COEX_2040
,
775 /* luckily this is almost always there */
776 WLAN_EID_EXT_CAPABILITY
,
777 WLAN_EID_QOS_TRAFFIC_CAPA
,
778 WLAN_EID_TIM_BCAST_REQ
,
779 WLAN_EID_INTERWORKING
,
780 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
781 WLAN_EID_VHT_CAPABILITY
,
782 WLAN_EID_OPMODE_NOTIF
,
785 noffset
= ieee80211_ie_split_ric(assoc_data
->ie
,
788 ARRAY_SIZE(before_ht
),
790 ARRAY_SIZE(after_ric
),
792 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
796 if (WARN_ON_ONCE((ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
797 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)))
798 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
800 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
801 ieee80211_add_ht_ie(sdata
, skb
, assoc_data
->ap_ht_param
,
802 sband
, chan
, sdata
->smps_mode
);
804 /* if present, add any custom IEs that go before VHT */
805 if (assoc_data
->ie_len
) {
806 static const u8 before_vht
[] = {
808 * no need to list the ones split off before HT
811 WLAN_EID_BSS_COEX_2040
,
812 WLAN_EID_EXT_CAPABILITY
,
813 WLAN_EID_QOS_TRAFFIC_CAPA
,
814 WLAN_EID_TIM_BCAST_REQ
,
815 WLAN_EID_INTERWORKING
,
816 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
819 /* RIC already taken above, so no need to handle here anymore */
820 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
821 before_vht
, ARRAY_SIZE(before_vht
),
823 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
827 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
828 ieee80211_add_vht_ie(sdata
, skb
, sband
,
829 &assoc_data
->ap_vht_cap
);
831 /* if present, add any custom non-vendor IEs that go after HT */
832 if (assoc_data
->ie_len
) {
833 noffset
= ieee80211_ie_split_vendor(assoc_data
->ie
,
836 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
840 if (assoc_data
->wmm
) {
841 if (assoc_data
->uapsd
) {
842 qos_info
= ifmgd
->uapsd_queues
;
843 qos_info
|= (ifmgd
->uapsd_max_sp_len
<<
844 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
849 pos
= ieee80211_add_wmm_info_ie(skb_put(skb
, 9), qos_info
);
852 /* add any remaining custom (i.e. vendor specific here) IEs */
853 if (assoc_data
->ie_len
) {
854 noffset
= assoc_data
->ie_len
;
855 skb_put_data(skb
, assoc_data
->ie
+ offset
, noffset
- offset
);
858 if (assoc_data
->fils_kek_len
&&
859 fils_encrypt_assoc_req(skb
, assoc_data
) < 0) {
864 drv_mgd_prepare_tx(local
, sdata
);
866 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
867 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
868 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
869 IEEE80211_TX_INTFL_MLME_CONN_TX
;
870 ieee80211_tx_skb(sdata
, skb
);
873 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
874 struct ieee80211_sub_if_data
*sdata
)
876 struct ieee80211_pspoll
*pspoll
;
879 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
883 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
884 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
886 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
887 ieee80211_tx_skb(sdata
, skb
);
890 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
891 struct ieee80211_sub_if_data
*sdata
,
895 struct ieee80211_hdr_3addr
*nullfunc
;
896 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
898 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
);
902 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
904 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
906 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
907 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
909 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
910 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
912 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
913 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
915 ieee80211_tx_skb(sdata
, skb
);
918 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
919 struct ieee80211_sub_if_data
*sdata
)
922 struct ieee80211_hdr
*nullfunc
;
925 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
928 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
932 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
934 nullfunc
= skb_put_zero(skb
, 30);
935 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
936 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
937 nullfunc
->frame_control
= fc
;
938 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
939 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
940 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
941 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
943 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
944 ieee80211_tx_skb(sdata
, skb
);
947 /* spectrum management related things */
948 static void ieee80211_chswitch_work(struct work_struct
*work
)
950 struct ieee80211_sub_if_data
*sdata
=
951 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
952 struct ieee80211_local
*local
= sdata
->local
;
953 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
956 if (!ieee80211_sdata_running(sdata
))
960 mutex_lock(&local
->mtx
);
961 mutex_lock(&local
->chanctx_mtx
);
963 if (!ifmgd
->associated
)
966 if (!sdata
->vif
.csa_active
)
970 * using reservation isn't immediate as it may be deferred until later
971 * with multi-vif. once reservation is complete it will re-schedule the
972 * work with no reserved_chanctx so verify chandef to check if it
973 * completed successfully
976 if (sdata
->reserved_chanctx
) {
978 * with multi-vif csa driver may call ieee80211_csa_finish()
979 * many times while waiting for other interfaces to use their
982 if (sdata
->reserved_ready
)
985 ret
= ieee80211_vif_use_reserved_context(sdata
);
988 "failed to use reserved channel context, disconnecting (err=%d)\n",
990 ieee80211_queue_work(&sdata
->local
->hw
,
991 &ifmgd
->csa_connection_drop_work
);
998 if (!cfg80211_chandef_identical(&sdata
->vif
.bss_conf
.chandef
,
999 &sdata
->csa_chandef
)) {
1001 "failed to finalize channel switch, disconnecting\n");
1002 ieee80211_queue_work(&sdata
->local
->hw
,
1003 &ifmgd
->csa_connection_drop_work
);
1007 /* XXX: shouldn't really modify cfg80211-owned data! */
1008 ifmgd
->associated
->channel
= sdata
->csa_chandef
.chan
;
1010 ifmgd
->csa_waiting_bcn
= true;
1012 ieee80211_sta_reset_beacon_monitor(sdata
);
1013 ieee80211_sta_reset_conn_monitor(sdata
);
1016 mutex_unlock(&local
->chanctx_mtx
);
1017 mutex_unlock(&local
->mtx
);
1018 sdata_unlock(sdata
);
1021 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data
*sdata
)
1023 struct ieee80211_local
*local
= sdata
->local
;
1024 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1027 sdata_assert_lock(sdata
);
1029 WARN_ON(!sdata
->vif
.csa_active
);
1031 if (sdata
->csa_block_tx
) {
1032 ieee80211_wake_vif_queues(local
, sdata
,
1033 IEEE80211_QUEUE_STOP_REASON_CSA
);
1034 sdata
->csa_block_tx
= false;
1037 sdata
->vif
.csa_active
= false;
1038 ifmgd
->csa_waiting_bcn
= false;
1040 ret
= drv_post_channel_switch(sdata
);
1043 "driver post channel switch failed, disconnecting\n");
1044 ieee80211_queue_work(&local
->hw
,
1045 &ifmgd
->csa_connection_drop_work
);
1049 cfg80211_ch_switch_notify(sdata
->dev
, &sdata
->reserved_chandef
);
1052 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
1054 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1055 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1057 trace_api_chswitch_done(sdata
, success
);
1060 "driver channel switch failed, disconnecting\n");
1061 ieee80211_queue_work(&sdata
->local
->hw
,
1062 &ifmgd
->csa_connection_drop_work
);
1064 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
1067 EXPORT_SYMBOL(ieee80211_chswitch_done
);
1069 static void ieee80211_chswitch_timer(struct timer_list
*t
)
1071 struct ieee80211_sub_if_data
*sdata
=
1072 from_timer(sdata
, t
, u
.mgd
.chswitch_timer
);
1074 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->u
.mgd
.chswitch_work
);
1078 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
1079 u64 timestamp
, u32 device_timestamp
,
1080 struct ieee802_11_elems
*elems
,
1083 struct ieee80211_local
*local
= sdata
->local
;
1084 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1085 struct cfg80211_bss
*cbss
= ifmgd
->associated
;
1086 struct ieee80211_chanctx_conf
*conf
;
1087 struct ieee80211_chanctx
*chanctx
;
1088 enum nl80211_band current_band
;
1089 struct ieee80211_csa_ie csa_ie
;
1090 struct ieee80211_channel_switch ch_switch
;
1093 sdata_assert_lock(sdata
);
1098 if (local
->scanning
)
1101 /* disregard subsequent announcements if we are already processing */
1102 if (sdata
->vif
.csa_active
)
1105 current_band
= cbss
->channel
->band
;
1106 res
= ieee80211_parse_ch_switch_ie(sdata
, elems
, current_band
,
1108 ifmgd
->associated
->bssid
, &csa_ie
);
1110 ieee80211_queue_work(&local
->hw
,
1111 &ifmgd
->csa_connection_drop_work
);
1115 if (!cfg80211_chandef_usable(local
->hw
.wiphy
, &csa_ie
.chandef
,
1116 IEEE80211_CHAN_DISABLED
)) {
1118 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1119 ifmgd
->associated
->bssid
,
1120 csa_ie
.chandef
.chan
->center_freq
,
1121 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1122 csa_ie
.chandef
.center_freq2
);
1123 ieee80211_queue_work(&local
->hw
,
1124 &ifmgd
->csa_connection_drop_work
);
1128 if (cfg80211_chandef_identical(&csa_ie
.chandef
,
1129 &sdata
->vif
.bss_conf
.chandef
)) {
1130 if (ifmgd
->csa_ignored_same_chan
)
1133 "AP %pM tries to chanswitch to same channel, ignore\n",
1134 ifmgd
->associated
->bssid
);
1135 ifmgd
->csa_ignored_same_chan
= true;
1140 * Drop all TDLS peers - either we disconnect or move to a different
1141 * channel from this point on. There's no telling what our peer will do.
1142 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1143 * have an incompatible wider chandef.
1145 ieee80211_teardown_tdls_peers(sdata
);
1147 mutex_lock(&local
->mtx
);
1148 mutex_lock(&local
->chanctx_mtx
);
1149 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1150 lockdep_is_held(&local
->chanctx_mtx
));
1153 "no channel context assigned to vif?, disconnecting\n");
1154 goto drop_connection
;
1157 chanctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1159 if (local
->use_chanctx
&&
1160 !ieee80211_hw_check(&local
->hw
, CHANCTX_STA_CSA
)) {
1162 "driver doesn't support chan-switch with channel contexts\n");
1163 goto drop_connection
;
1166 ch_switch
.timestamp
= timestamp
;
1167 ch_switch
.device_timestamp
= device_timestamp
;
1168 ch_switch
.block_tx
= csa_ie
.mode
;
1169 ch_switch
.chandef
= csa_ie
.chandef
;
1170 ch_switch
.count
= csa_ie
.count
;
1172 if (drv_pre_channel_switch(sdata
, &ch_switch
)) {
1174 "preparing for channel switch failed, disconnecting\n");
1175 goto drop_connection
;
1178 res
= ieee80211_vif_reserve_chanctx(sdata
, &csa_ie
.chandef
,
1179 chanctx
->mode
, false);
1182 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1184 goto drop_connection
;
1186 mutex_unlock(&local
->chanctx_mtx
);
1188 sdata
->vif
.csa_active
= true;
1189 sdata
->csa_chandef
= csa_ie
.chandef
;
1190 sdata
->csa_block_tx
= csa_ie
.mode
;
1191 ifmgd
->csa_ignored_same_chan
= false;
1193 if (sdata
->csa_block_tx
)
1194 ieee80211_stop_vif_queues(local
, sdata
,
1195 IEEE80211_QUEUE_STOP_REASON_CSA
);
1196 mutex_unlock(&local
->mtx
);
1198 cfg80211_ch_switch_started_notify(sdata
->dev
, &csa_ie
.chandef
,
1201 if (local
->ops
->channel_switch
) {
1202 /* use driver's channel switch callback */
1203 drv_channel_switch(local
, sdata
, &ch_switch
);
1207 /* channel switch handled in software */
1208 if (csa_ie
.count
<= 1)
1209 ieee80211_queue_work(&local
->hw
, &ifmgd
->chswitch_work
);
1211 mod_timer(&ifmgd
->chswitch_timer
,
1212 TU_TO_EXP_TIME((csa_ie
.count
- 1) *
1213 cbss
->beacon_interval
));
1216 ieee80211_queue_work(&local
->hw
, &ifmgd
->csa_connection_drop_work
);
1217 mutex_unlock(&local
->chanctx_mtx
);
1218 mutex_unlock(&local
->mtx
);
1222 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1223 struct ieee80211_channel
*channel
,
1224 const u8
*country_ie
, u8 country_ie_len
,
1225 const u8
*pwr_constr_elem
,
1226 int *chan_pwr
, int *pwr_reduction
)
1228 struct ieee80211_country_ie_triplet
*triplet
;
1229 int chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1230 int i
, chan_increment
;
1231 bool have_chan_pwr
= false;
1234 if (country_ie_len
% 2 || country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1237 triplet
= (void *)(country_ie
+ 3);
1238 country_ie_len
-= 3;
1240 switch (channel
->band
) {
1244 case NL80211_BAND_2GHZ
:
1245 case NL80211_BAND_60GHZ
:
1248 case NL80211_BAND_5GHZ
:
1254 while (country_ie_len
>= 3) {
1255 u8 first_channel
= triplet
->chans
.first_channel
;
1257 if (first_channel
>= IEEE80211_COUNTRY_EXTENSION_ID
)
1260 for (i
= 0; i
< triplet
->chans
.num_channels
; i
++) {
1261 if (first_channel
+ i
* chan_increment
== chan
) {
1262 have_chan_pwr
= true;
1263 *chan_pwr
= triplet
->chans
.max_power
;
1272 country_ie_len
-= 3;
1275 if (have_chan_pwr
&& pwr_constr_elem
)
1276 *pwr_reduction
= *pwr_constr_elem
;
1280 return have_chan_pwr
;
1283 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data
*sdata
,
1284 struct ieee80211_channel
*channel
,
1285 const u8
*cisco_dtpc_ie
,
1288 /* From practical testing, the first data byte of the DTPC element
1289 * seems to contain the requested dBm level, and the CLI on Cisco
1290 * APs clearly state the range is -127 to 127 dBm, which indicates
1291 * a signed byte, although it seemingly never actually goes negative.
1292 * The other byte seems to always be zero.
1294 *pwr_level
= (__s8
)cisco_dtpc_ie
[4];
1297 static u32
ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1298 struct ieee80211_channel
*channel
,
1299 struct ieee80211_mgmt
*mgmt
,
1300 const u8
*country_ie
, u8 country_ie_len
,
1301 const u8
*pwr_constr_ie
,
1302 const u8
*cisco_dtpc_ie
)
1304 bool has_80211h_pwr
= false, has_cisco_pwr
= false;
1305 int chan_pwr
= 0, pwr_reduction_80211h
= 0;
1306 int pwr_level_cisco
, pwr_level_80211h
;
1308 __le16 capab
= mgmt
->u
.probe_resp
.capab_info
;
1311 (capab
& cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT
) ||
1312 capab
& cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE
))) {
1313 has_80211h_pwr
= ieee80211_find_80211h_pwr_constr(
1314 sdata
, channel
, country_ie
, country_ie_len
,
1315 pwr_constr_ie
, &chan_pwr
, &pwr_reduction_80211h
);
1317 max_t(int, 0, chan_pwr
- pwr_reduction_80211h
);
1320 if (cisco_dtpc_ie
) {
1321 ieee80211_find_cisco_dtpc(
1322 sdata
, channel
, cisco_dtpc_ie
, &pwr_level_cisco
);
1323 has_cisco_pwr
= true;
1326 if (!has_80211h_pwr
&& !has_cisco_pwr
)
1329 /* If we have both 802.11h and Cisco DTPC, apply both limits
1330 * by picking the smallest of the two power levels advertised.
1332 if (has_80211h_pwr
&&
1333 (!has_cisco_pwr
|| pwr_level_80211h
<= pwr_level_cisco
)) {
1334 new_ap_level
= pwr_level_80211h
;
1336 if (sdata
->ap_power_level
== new_ap_level
)
1340 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1341 pwr_level_80211h
, chan_pwr
, pwr_reduction_80211h
,
1342 sdata
->u
.mgd
.bssid
);
1343 } else { /* has_cisco_pwr is always true here. */
1344 new_ap_level
= pwr_level_cisco
;
1346 if (sdata
->ap_power_level
== new_ap_level
)
1350 "Limiting TX power to %d dBm as advertised by %pM\n",
1351 pwr_level_cisco
, sdata
->u
.mgd
.bssid
);
1354 sdata
->ap_power_level
= new_ap_level
;
1355 if (__ieee80211_recalc_txpower(sdata
))
1356 return BSS_CHANGED_TXPOWER
;
1361 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
1362 struct ieee80211_sub_if_data
*sdata
)
1364 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1367 * If we are scanning right now then the parameters will
1368 * take effect when scan finishes.
1370 if (local
->scanning
)
1373 if (conf
->dynamic_ps_timeout
> 0 &&
1374 !ieee80211_hw_check(&local
->hw
, SUPPORTS_DYNAMIC_PS
)) {
1375 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1376 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
1378 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
))
1379 ieee80211_send_nullfunc(local
, sdata
, true);
1381 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1382 ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
1385 conf
->flags
|= IEEE80211_CONF_PS
;
1386 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1390 static void ieee80211_change_ps(struct ieee80211_local
*local
)
1392 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1394 if (local
->ps_sdata
) {
1395 ieee80211_enable_ps(local
, local
->ps_sdata
);
1396 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
1397 conf
->flags
&= ~IEEE80211_CONF_PS
;
1398 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1399 del_timer_sync(&local
->dynamic_ps_timer
);
1400 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1404 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
1406 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
1407 struct sta_info
*sta
= NULL
;
1408 bool authorized
= false;
1410 if (!mgd
->powersave
)
1416 if (!mgd
->associated
)
1419 if (mgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1422 if (!mgd
->have_beacon
)
1426 sta
= sta_info_get(sdata
, mgd
->bssid
);
1428 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
1434 /* need to hold RTNL or interface lock */
1435 void ieee80211_recalc_ps(struct ieee80211_local
*local
)
1437 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
1441 if (!ieee80211_hw_check(&local
->hw
, SUPPORTS_PS
)) {
1442 local
->ps_sdata
= NULL
;
1446 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1447 if (!ieee80211_sdata_running(sdata
))
1449 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1450 /* If an AP vif is found, then disable PS
1451 * by setting the count to zero thereby setting
1457 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1463 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
1464 u8 dtimper
= found
->u
.mgd
.dtim_period
;
1466 timeout
= local
->dynamic_ps_forced_timeout
;
1469 local
->hw
.conf
.dynamic_ps_timeout
= timeout
;
1471 /* If the TIM IE is invalid, pretend the value is 1 */
1475 local
->hw
.conf
.ps_dtim_period
= dtimper
;
1476 local
->ps_sdata
= found
;
1478 local
->ps_sdata
= NULL
;
1481 ieee80211_change_ps(local
);
1484 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data
*sdata
)
1486 bool ps_allowed
= ieee80211_powersave_allowed(sdata
);
1488 if (sdata
->vif
.bss_conf
.ps
!= ps_allowed
) {
1489 sdata
->vif
.bss_conf
.ps
= ps_allowed
;
1490 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_PS
);
1494 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
1496 struct ieee80211_local
*local
=
1497 container_of(work
, struct ieee80211_local
,
1498 dynamic_ps_disable_work
);
1500 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1501 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1502 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1505 ieee80211_wake_queues_by_reason(&local
->hw
,
1506 IEEE80211_MAX_QUEUE_MAP
,
1507 IEEE80211_QUEUE_STOP_REASON_PS
,
1511 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
1513 struct ieee80211_local
*local
=
1514 container_of(work
, struct ieee80211_local
,
1515 dynamic_ps_enable_work
);
1516 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
1517 struct ieee80211_if_managed
*ifmgd
;
1518 unsigned long flags
;
1521 /* can only happen when PS was just disabled anyway */
1525 ifmgd
= &sdata
->u
.mgd
;
1527 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
1530 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1531 /* don't enter PS if TX frames are pending */
1532 if (drv_tx_frames_pending(local
)) {
1533 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1535 local
->hw
.conf
.dynamic_ps_timeout
));
1540 * transmission can be stopped by others which leads to
1541 * dynamic_ps_timer expiry. Postpone the ps timer if it
1542 * is not the actual idle state.
1544 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1545 for (q
= 0; q
< local
->hw
.queues
; q
++) {
1546 if (local
->queue_stop_reasons
[q
]) {
1547 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1549 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1551 local
->hw
.conf
.dynamic_ps_timeout
));
1555 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1558 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
1559 !(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1560 if (drv_tx_frames_pending(local
)) {
1561 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1563 local
->hw
.conf
.dynamic_ps_timeout
));
1565 ieee80211_send_nullfunc(local
, sdata
, true);
1566 /* Flush to get the tx status of nullfunc frame */
1567 ieee80211_flush_queues(local
, sdata
, false);
1571 if (!(ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
) &&
1572 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
)) ||
1573 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1574 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
1575 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
1576 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1580 void ieee80211_dynamic_ps_timer(struct timer_list
*t
)
1582 struct ieee80211_local
*local
= from_timer(local
, t
, dynamic_ps_timer
);
1584 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
1587 void ieee80211_dfs_cac_timer_work(struct work_struct
*work
)
1589 struct delayed_work
*delayed_work
= to_delayed_work(work
);
1590 struct ieee80211_sub_if_data
*sdata
=
1591 container_of(delayed_work
, struct ieee80211_sub_if_data
,
1592 dfs_cac_timer_work
);
1593 struct cfg80211_chan_def chandef
= sdata
->vif
.bss_conf
.chandef
;
1595 mutex_lock(&sdata
->local
->mtx
);
1596 if (sdata
->wdev
.cac_started
) {
1597 ieee80211_vif_release_channel(sdata
);
1598 cfg80211_cac_event(sdata
->dev
, &chandef
,
1599 NL80211_RADAR_CAC_FINISHED
,
1602 mutex_unlock(&sdata
->local
->mtx
);
1606 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1608 struct ieee80211_local
*local
= sdata
->local
;
1609 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1613 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1616 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1617 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
1619 unsigned long now
= jiffies
;
1621 if (tx_tspec
->action
== TX_TSPEC_ACTION_NONE
&&
1622 tx_tspec
->admitted_time
&&
1623 time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1624 tx_tspec
->consumed_tx_time
= 0;
1625 tx_tspec
->time_slice_start
= now
;
1627 if (tx_tspec
->downgraded
)
1629 TX_TSPEC_ACTION_STOP_DOWNGRADE
;
1632 switch (tx_tspec
->action
) {
1633 case TX_TSPEC_ACTION_STOP_DOWNGRADE
:
1634 /* take the original parameters */
1635 if (drv_conf_tx(local
, sdata
, ac
, &sdata
->tx_conf
[ac
]))
1637 "failed to set TX queue parameters for queue %d\n",
1639 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1640 tx_tspec
->downgraded
= false;
1643 case TX_TSPEC_ACTION_DOWNGRADE
:
1644 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
1645 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1649 /* downgrade next lower non-ACM AC */
1650 for (non_acm_ac
= ac
+ 1;
1651 non_acm_ac
< IEEE80211_NUM_ACS
;
1653 if (!(sdata
->wmm_acm
& BIT(7 - 2 * non_acm_ac
)))
1655 /* Usually the loop will result in using BK even if it
1656 * requires admission control, but such a configuration
1657 * makes no sense and we have to transmit somehow - the
1658 * AC selection does the same thing.
1659 * If we started out trying to downgrade from BK, then
1660 * the extra condition here might be needed.
1662 if (non_acm_ac
>= IEEE80211_NUM_ACS
)
1663 non_acm_ac
= IEEE80211_AC_BK
;
1664 if (drv_conf_tx(local
, sdata
, ac
,
1665 &sdata
->tx_conf
[non_acm_ac
]))
1667 "failed to set TX queue parameters for queue %d\n",
1669 tx_tspec
->action
= TX_TSPEC_ACTION_NONE
;
1671 schedule_delayed_work(&ifmgd
->tx_tspec_wk
,
1672 tx_tspec
->time_slice_start
+ HZ
- now
+ 1);
1674 case TX_TSPEC_ACTION_NONE
:
1683 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data
*sdata
)
1685 if (__ieee80211_sta_handle_tspec_ac_params(sdata
))
1686 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
1689 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct
*work
)
1691 struct ieee80211_sub_if_data
*sdata
;
1693 sdata
= container_of(work
, struct ieee80211_sub_if_data
,
1694 u
.mgd
.tx_tspec_wk
.work
);
1695 ieee80211_sta_handle_tspec_ac_params(sdata
);
1699 static bool ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
1700 struct ieee80211_sub_if_data
*sdata
,
1701 const u8
*wmm_param
, size_t wmm_param_len
)
1703 struct ieee80211_tx_queue_params params
[IEEE80211_NUM_ACS
];
1704 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1708 u8 uapsd_queues
= 0;
1710 if (!local
->ops
->conf_tx
)
1713 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1719 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
1722 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
1723 uapsd_queues
= ifmgd
->uapsd_queues
;
1725 count
= wmm_param
[6] & 0x0f;
1726 if (count
== ifmgd
->wmm_last_param_set
)
1728 ifmgd
->wmm_last_param_set
= count
;
1730 pos
= wmm_param
+ 8;
1731 left
= wmm_param_len
- 8;
1733 memset(¶ms
, 0, sizeof(params
));
1736 for (; left
>= 4; left
-= 4, pos
+= 4) {
1737 int aci
= (pos
[0] >> 5) & 0x03;
1738 int acm
= (pos
[0] >> 4) & 0x01;
1743 ac
= IEEE80211_AC_BK
;
1745 sdata
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
1746 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1750 ac
= IEEE80211_AC_VI
;
1752 sdata
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
1753 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1757 ac
= IEEE80211_AC_VO
;
1759 sdata
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
1760 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1765 ac
= IEEE80211_AC_BE
;
1767 sdata
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
1768 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1773 params
[ac
].aifs
= pos
[0] & 0x0f;
1775 if (params
[ac
].aifs
< 2) {
1777 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
1778 params
[ac
].aifs
, aci
);
1779 params
[ac
].aifs
= 2;
1781 params
[ac
].cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
1782 params
[ac
].cw_min
= ecw2cw(pos
[1] & 0x0f);
1783 params
[ac
].txop
= get_unaligned_le16(pos
+ 2);
1784 params
[ac
].acm
= acm
;
1785 params
[ac
].uapsd
= uapsd
;
1787 if (params
[ac
].cw_min
> params
[ac
].cw_max
) {
1789 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
1790 params
[ac
].cw_min
, params
[ac
].cw_max
, aci
);
1795 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
1797 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
1799 params
[ac
].aifs
, params
[ac
].cw_min
, params
[ac
].cw_max
,
1800 params
[ac
].txop
, params
[ac
].uapsd
,
1801 ifmgd
->tx_tspec
[ac
].downgraded
);
1802 sdata
->tx_conf
[ac
] = params
[ac
];
1803 if (!ifmgd
->tx_tspec
[ac
].downgraded
&&
1804 drv_conf_tx(local
, sdata
, ac
, ¶ms
[ac
]))
1806 "failed to set TX queue parameters for AC %d\n",
1810 /* enable WMM or activate new settings */
1811 sdata
->vif
.bss_conf
.qos
= true;
1815 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1817 lockdep_assert_held(&sdata
->local
->mtx
);
1819 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_CONNECTION_POLL
;
1820 ieee80211_run_deferred_scan(sdata
->local
);
1823 static void ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1825 mutex_lock(&sdata
->local
->mtx
);
1826 __ieee80211_stop_poll(sdata
);
1827 mutex_unlock(&sdata
->local
->mtx
);
1830 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
1831 u16 capab
, bool erp_valid
, u8 erp
)
1833 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1834 struct ieee80211_supported_band
*sband
;
1836 bool use_protection
;
1837 bool use_short_preamble
;
1838 bool use_short_slot
;
1840 sband
= ieee80211_get_sband(sdata
);
1845 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
1846 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
1848 use_protection
= false;
1849 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
1852 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1853 if (sband
->band
== NL80211_BAND_5GHZ
)
1854 use_short_slot
= true;
1856 if (use_protection
!= bss_conf
->use_cts_prot
) {
1857 bss_conf
->use_cts_prot
= use_protection
;
1858 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1861 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
1862 bss_conf
->use_short_preamble
= use_short_preamble
;
1863 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1866 if (use_short_slot
!= bss_conf
->use_short_slot
) {
1867 bss_conf
->use_short_slot
= use_short_slot
;
1868 changed
|= BSS_CHANGED_ERP_SLOT
;
1874 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
1875 struct cfg80211_bss
*cbss
,
1876 u32 bss_info_changed
)
1878 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
1879 struct ieee80211_local
*local
= sdata
->local
;
1880 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1882 bss_info_changed
|= BSS_CHANGED_ASSOC
;
1883 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
1884 bss_conf
->assoc_capability
, bss
->has_erp_value
, bss
->erp_value
);
1886 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
1887 beacon_loss_count
* bss_conf
->beacon_int
));
1889 sdata
->u
.mgd
.associated
= cbss
;
1890 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
1892 ieee80211_check_rate_mask(sdata
);
1894 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
1896 if (sdata
->vif
.p2p
||
1897 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
1898 const struct cfg80211_bss_ies
*ies
;
1901 ies
= rcu_dereference(cbss
->ies
);
1905 ret
= cfg80211_get_p2p_attr(
1906 ies
->data
, ies
->len
,
1907 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
1908 (u8
*) &bss_conf
->p2p_noa_attr
,
1909 sizeof(bss_conf
->p2p_noa_attr
));
1911 sdata
->u
.mgd
.p2p_noa_index
=
1912 bss_conf
->p2p_noa_attr
.index
;
1913 bss_info_changed
|= BSS_CHANGED_P2P_PS
;
1919 /* just to be sure */
1920 ieee80211_stop_poll(sdata
);
1922 ieee80211_led_assoc(local
, 1);
1924 if (sdata
->u
.mgd
.have_beacon
) {
1926 * If the AP is buggy we may get here with no DTIM period
1927 * known, so assume it's 1 which is the only safe assumption
1928 * in that case, although if the TIM IE is broken powersave
1929 * probably just won't work at all.
1931 bss_conf
->dtim_period
= sdata
->u
.mgd
.dtim_period
?: 1;
1932 bss_conf
->beacon_rate
= bss
->beacon_rate
;
1933 bss_info_changed
|= BSS_CHANGED_BEACON_INFO
;
1935 bss_conf
->beacon_rate
= NULL
;
1936 bss_conf
->dtim_period
= 0;
1939 bss_conf
->assoc
= 1;
1941 /* Tell the driver to monitor connection quality (if supported) */
1942 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
&&
1943 bss_conf
->cqm_rssi_thold
)
1944 bss_info_changed
|= BSS_CHANGED_CQM
;
1946 /* Enable ARP filtering */
1947 if (bss_conf
->arp_addr_cnt
)
1948 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
1950 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
1952 mutex_lock(&local
->iflist_mtx
);
1953 ieee80211_recalc_ps(local
);
1954 mutex_unlock(&local
->iflist_mtx
);
1956 ieee80211_recalc_smps(sdata
);
1957 ieee80211_recalc_ps_vif(sdata
);
1959 netif_carrier_on(sdata
->dev
);
1962 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
1963 u16 stype
, u16 reason
, bool tx
,
1966 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1967 struct ieee80211_local
*local
= sdata
->local
;
1970 sdata_assert_lock(sdata
);
1972 if (WARN_ON_ONCE(tx
&& !frame_buf
))
1975 if (WARN_ON(!ifmgd
->associated
))
1978 ieee80211_stop_poll(sdata
);
1980 ifmgd
->associated
= NULL
;
1981 netif_carrier_off(sdata
->dev
);
1984 * if we want to get out of ps before disassoc (why?) we have
1985 * to do it before sending disassoc, as otherwise the null-packet
1988 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1989 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1990 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1992 local
->ps_sdata
= NULL
;
1994 /* disable per-vif ps */
1995 ieee80211_recalc_ps_vif(sdata
);
1997 /* make sure ongoing transmission finishes */
2001 * drop any frame before deauth/disassoc, this can be data or
2002 * management frame. Since we are disconnecting, we should not
2003 * insist sending these frames which can take time and delay
2004 * the disconnection and possible the roaming.
2007 ieee80211_flush_queues(local
, sdata
, true);
2009 /* deauthenticate/disassociate now */
2010 if (tx
|| frame_buf
)
2011 ieee80211_send_deauth_disassoc(sdata
, ifmgd
->bssid
, stype
,
2012 reason
, tx
, frame_buf
);
2014 /* flush out frame - make sure the deauth was actually sent */
2016 ieee80211_flush_queues(local
, sdata
, false);
2018 /* clear bssid only after building the needed mgmt frames */
2019 eth_zero_addr(ifmgd
->bssid
);
2021 /* remove AP and TDLS peers */
2022 sta_info_flush(sdata
);
2024 /* finally reset all BSS / config parameters */
2025 changed
|= ieee80211_reset_erp_info(sdata
);
2027 ieee80211_led_assoc(local
, 0);
2028 changed
|= BSS_CHANGED_ASSOC
;
2029 sdata
->vif
.bss_conf
.assoc
= false;
2031 ifmgd
->p2p_noa_index
= -1;
2032 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
2033 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
2035 /* on the next assoc, re-program HT/VHT parameters */
2036 memset(&ifmgd
->ht_capa
, 0, sizeof(ifmgd
->ht_capa
));
2037 memset(&ifmgd
->ht_capa_mask
, 0, sizeof(ifmgd
->ht_capa_mask
));
2038 memset(&ifmgd
->vht_capa
, 0, sizeof(ifmgd
->vht_capa
));
2039 memset(&ifmgd
->vht_capa_mask
, 0, sizeof(ifmgd
->vht_capa_mask
));
2041 /* reset MU-MIMO ownership and group data */
2042 memset(sdata
->vif
.bss_conf
.mu_group
.membership
, 0,
2043 sizeof(sdata
->vif
.bss_conf
.mu_group
.membership
));
2044 memset(sdata
->vif
.bss_conf
.mu_group
.position
, 0,
2045 sizeof(sdata
->vif
.bss_conf
.mu_group
.position
));
2046 changed
|= BSS_CHANGED_MU_GROUPS
;
2047 sdata
->vif
.mu_mimo_owner
= false;
2049 sdata
->ap_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
2051 del_timer_sync(&local
->dynamic_ps_timer
);
2052 cancel_work_sync(&local
->dynamic_ps_enable_work
);
2054 /* Disable ARP filtering */
2055 if (sdata
->vif
.bss_conf
.arp_addr_cnt
)
2056 changed
|= BSS_CHANGED_ARP_FILTER
;
2058 sdata
->vif
.bss_conf
.qos
= false;
2059 changed
|= BSS_CHANGED_QOS
;
2061 /* The BSSID (not really interesting) and HT changed */
2062 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
2063 ieee80211_bss_info_change_notify(sdata
, changed
);
2065 /* disassociated - set to defaults now */
2066 ieee80211_set_wmm_default(sdata
, false, false);
2068 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
2069 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
2070 del_timer_sync(&sdata
->u
.mgd
.timer
);
2071 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
2073 sdata
->vif
.bss_conf
.dtim_period
= 0;
2074 sdata
->vif
.bss_conf
.beacon_rate
= NULL
;
2076 ifmgd
->have_beacon
= false;
2079 mutex_lock(&local
->mtx
);
2080 ieee80211_vif_release_channel(sdata
);
2082 sdata
->vif
.csa_active
= false;
2083 ifmgd
->csa_waiting_bcn
= false;
2084 ifmgd
->csa_ignored_same_chan
= false;
2085 if (sdata
->csa_block_tx
) {
2086 ieee80211_wake_vif_queues(local
, sdata
,
2087 IEEE80211_QUEUE_STOP_REASON_CSA
);
2088 sdata
->csa_block_tx
= false;
2090 mutex_unlock(&local
->mtx
);
2092 /* existing TX TSPEC sessions no longer exist */
2093 memset(ifmgd
->tx_tspec
, 0, sizeof(ifmgd
->tx_tspec
));
2094 cancel_delayed_work_sync(&ifmgd
->tx_tspec_wk
);
2096 sdata
->encrypt_headroom
= IEEE80211_ENCRYPT_HEADROOM
;
2099 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data
*sdata
,
2100 struct ieee80211_hdr
*hdr
)
2103 * We can postpone the mgd.timer whenever receiving unicast frames
2104 * from AP because we know that the connection is working both ways
2105 * at that time. But multicast frames (and hence also beacons) must
2106 * be ignored here, because we need to trigger the timer during
2107 * data idle periods for sending the periodic probe request to the
2108 * AP we're connected to.
2110 if (is_multicast_ether_addr(hdr
->addr1
))
2113 ieee80211_sta_reset_conn_monitor(sdata
);
2116 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
2118 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2119 struct ieee80211_local
*local
= sdata
->local
;
2121 mutex_lock(&local
->mtx
);
2122 if (!(ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
))
2125 __ieee80211_stop_poll(sdata
);
2127 mutex_lock(&local
->iflist_mtx
);
2128 ieee80211_recalc_ps(local
);
2129 mutex_unlock(&local
->iflist_mtx
);
2131 if (ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
2135 * We've received a probe response, but are not sure whether
2136 * we have or will be receiving any beacons or data, so let's
2137 * schedule the timers again, just in case.
2139 ieee80211_sta_reset_beacon_monitor(sdata
);
2141 mod_timer(&ifmgd
->conn_mon_timer
,
2142 round_jiffies_up(jiffies
+
2143 IEEE80211_CONNECTION_IDLE_TIME
));
2145 mutex_unlock(&local
->mtx
);
2148 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data
*sdata
,
2149 struct ieee80211_hdr
*hdr
,
2152 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2153 u16 tid
= *ieee80211_get_qos_ctl(hdr
) & IEEE80211_QOS_CTL_TID_MASK
;
2154 int ac
= ieee80211_ac_from_tid(tid
);
2155 struct ieee80211_sta_tx_tspec
*tx_tspec
= &ifmgd
->tx_tspec
[ac
];
2156 unsigned long now
= jiffies
;
2158 if (likely(!tx_tspec
->admitted_time
))
2161 if (time_after(now
, tx_tspec
->time_slice_start
+ HZ
)) {
2162 tx_tspec
->consumed_tx_time
= 0;
2163 tx_tspec
->time_slice_start
= now
;
2165 if (tx_tspec
->downgraded
) {
2166 tx_tspec
->action
= TX_TSPEC_ACTION_STOP_DOWNGRADE
;
2167 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2171 if (tx_tspec
->downgraded
)
2174 tx_tspec
->consumed_tx_time
+= tx_time
;
2176 if (tx_tspec
->consumed_tx_time
>= tx_tspec
->admitted_time
) {
2177 tx_tspec
->downgraded
= true;
2178 tx_tspec
->action
= TX_TSPEC_ACTION_DOWNGRADE
;
2179 schedule_delayed_work(&ifmgd
->tx_tspec_wk
, 0);
2183 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
2184 struct ieee80211_hdr
*hdr
, bool ack
, u16 tx_time
)
2186 ieee80211_sta_tx_wmm_ac_notify(sdata
, hdr
, tx_time
);
2188 if (!ieee80211_is_data(hdr
->frame_control
))
2191 if (ieee80211_is_nullfunc(hdr
->frame_control
) &&
2192 sdata
->u
.mgd
.probe_send_count
> 0) {
2194 ieee80211_sta_reset_conn_monitor(sdata
);
2196 sdata
->u
.mgd
.nullfunc_failed
= true;
2197 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
2202 ieee80211_sta_reset_conn_monitor(sdata
);
2205 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
2207 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2209 u8
*dst
= ifmgd
->associated
->bssid
;
2210 u8 unicast_limit
= max(1, max_probe_tries
- 3);
2211 struct sta_info
*sta
;
2214 * Try sending broadcast probe requests for the last three
2215 * probe requests after the first ones failed since some
2216 * buggy APs only support broadcast probe requests.
2218 if (ifmgd
->probe_send_count
>= unicast_limit
)
2222 * When the hardware reports an accurate Tx ACK status, it's
2223 * better to send a nullfunc frame instead of a probe request,
2224 * as it will kick us off the AP quickly if we aren't associated
2225 * anymore. The timeout will be reset if the frame is ACKed by
2228 ifmgd
->probe_send_count
++;
2231 mutex_lock(&sdata
->local
->sta_mtx
);
2232 sta
= sta_info_get(sdata
, dst
);
2234 ieee80211_check_fast_rx(sta
);
2235 mutex_unlock(&sdata
->local
->sta_mtx
);
2238 if (ieee80211_hw_check(&sdata
->local
->hw
, REPORTS_TX_ACK_STATUS
)) {
2239 ifmgd
->nullfunc_failed
= false;
2240 ieee80211_send_nullfunc(sdata
->local
, sdata
, false);
2245 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
2246 if (WARN_ON_ONCE(ssid
== NULL
))
2251 ieee80211_send_probe_req(sdata
, sdata
->vif
.addr
, dst
,
2252 ssid
+ 2, ssid_len
, NULL
,
2253 0, (u32
) -1, true, 0,
2254 ifmgd
->associated
->channel
, false);
2258 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
2259 run_again(sdata
, ifmgd
->probe_timeout
);
2262 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
2265 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2266 bool already
= false;
2268 if (!ieee80211_sdata_running(sdata
))
2273 if (!ifmgd
->associated
)
2276 mutex_lock(&sdata
->local
->mtx
);
2278 if (sdata
->local
->tmp_channel
|| sdata
->local
->scanning
) {
2279 mutex_unlock(&sdata
->local
->mtx
);
2284 mlme_dbg_ratelimited(sdata
,
2285 "detected beacon loss from AP (missed %d beacons) - probing\n",
2288 ieee80211_cqm_beacon_loss_notify(&sdata
->vif
, GFP_KERNEL
);
2292 * The driver/our work has already reported this event or the
2293 * connection monitoring has kicked in and we have already sent
2294 * a probe request. Or maybe the AP died and the driver keeps
2295 * reporting until we disassociate...
2297 * In either case we have to ignore the current call to this
2298 * function (except for setting the correct probe reason bit)
2299 * because otherwise we would reset the timer every time and
2300 * never check whether we received a probe response!
2302 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
2305 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
2307 mutex_unlock(&sdata
->local
->mtx
);
2312 mutex_lock(&sdata
->local
->iflist_mtx
);
2313 ieee80211_recalc_ps(sdata
->local
);
2314 mutex_unlock(&sdata
->local
->iflist_mtx
);
2316 ifmgd
->probe_send_count
= 0;
2317 ieee80211_mgd_probe_ap_send(sdata
);
2319 sdata_unlock(sdata
);
2322 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
2323 struct ieee80211_vif
*vif
)
2325 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2326 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2327 struct cfg80211_bss
*cbss
;
2328 struct sk_buff
*skb
;
2332 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
2335 sdata_assert_lock(sdata
);
2337 if (ifmgd
->associated
)
2338 cbss
= ifmgd
->associated
;
2339 else if (ifmgd
->auth_data
)
2340 cbss
= ifmgd
->auth_data
->bss
;
2341 else if (ifmgd
->assoc_data
)
2342 cbss
= ifmgd
->assoc_data
->bss
;
2347 ssid
= ieee80211_bss_get_ie(cbss
, WLAN_EID_SSID
);
2348 if (WARN_ON_ONCE(ssid
== NULL
))
2353 skb
= ieee80211_build_probe_req(sdata
, sdata
->vif
.addr
, cbss
->bssid
,
2354 (u32
) -1, cbss
->channel
,
2361 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
2363 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data
*sdata
,
2364 const u8
*buf
, size_t len
, bool tx
,
2367 struct ieee80211_event event
= {
2369 .u
.mlme
.data
= tx
? DEAUTH_TX_EVENT
: DEAUTH_RX_EVENT
,
2370 .u
.mlme
.reason
= reason
,
2374 cfg80211_tx_mlme_mgmt(sdata
->dev
, buf
, len
);
2376 cfg80211_rx_mlme_mgmt(sdata
->dev
, buf
, len
);
2378 drv_event_callback(sdata
->local
, sdata
, &event
);
2381 static void __ieee80211_disconnect(struct ieee80211_sub_if_data
*sdata
)
2383 struct ieee80211_local
*local
= sdata
->local
;
2384 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2385 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2388 if (!ifmgd
->associated
) {
2389 sdata_unlock(sdata
);
2393 /* AP is probably out of range (or not reachable for another reason) so
2394 * remove the bss struct for that AP.
2396 cfg80211_unlink_bss(local
->hw
.wiphy
, ifmgd
->associated
);
2398 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
2399 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2401 mutex_lock(&local
->mtx
);
2402 sdata
->vif
.csa_active
= false;
2403 ifmgd
->csa_waiting_bcn
= false;
2404 if (sdata
->csa_block_tx
) {
2405 ieee80211_wake_vif_queues(local
, sdata
,
2406 IEEE80211_QUEUE_STOP_REASON_CSA
);
2407 sdata
->csa_block_tx
= false;
2409 mutex_unlock(&local
->mtx
);
2411 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
2412 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
2414 sdata_unlock(sdata
);
2417 static void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
2419 struct ieee80211_sub_if_data
*sdata
=
2420 container_of(work
, struct ieee80211_sub_if_data
,
2421 u
.mgd
.beacon_connection_loss_work
);
2422 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2424 if (ifmgd
->associated
)
2425 ifmgd
->beacon_loss_count
++;
2427 if (ifmgd
->connection_loss
) {
2428 sdata_info(sdata
, "Connection to AP %pM lost\n",
2430 __ieee80211_disconnect(sdata
);
2432 ieee80211_mgd_probe_ap(sdata
, true);
2436 static void ieee80211_csa_connection_drop_work(struct work_struct
*work
)
2438 struct ieee80211_sub_if_data
*sdata
=
2439 container_of(work
, struct ieee80211_sub_if_data
,
2440 u
.mgd
.csa_connection_drop_work
);
2442 __ieee80211_disconnect(sdata
);
2445 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
2447 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2448 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2450 trace_api_beacon_loss(sdata
);
2452 sdata
->u
.mgd
.connection_loss
= false;
2453 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2455 EXPORT_SYMBOL(ieee80211_beacon_loss
);
2457 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
2459 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2460 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2462 trace_api_connection_loss(sdata
);
2464 sdata
->u
.mgd
.connection_loss
= true;
2465 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2467 EXPORT_SYMBOL(ieee80211_connection_loss
);
2470 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data
*sdata
,
2473 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2475 sdata_assert_lock(sdata
);
2479 * we are not authenticated yet, the only timer that could be
2480 * running is the timeout for the authentication response which
2481 * which is not relevant anymore.
2483 del_timer_sync(&sdata
->u
.mgd
.timer
);
2484 sta_info_destroy_addr(sdata
, auth_data
->bss
->bssid
);
2486 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2487 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2488 sdata
->u
.mgd
.flags
= 0;
2489 mutex_lock(&sdata
->local
->mtx
);
2490 ieee80211_vif_release_channel(sdata
);
2491 mutex_unlock(&sdata
->local
->mtx
);
2494 cfg80211_put_bss(sdata
->local
->hw
.wiphy
, auth_data
->bss
);
2496 sdata
->u
.mgd
.auth_data
= NULL
;
2499 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data
*sdata
,
2500 bool assoc
, bool abandon
)
2502 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
2504 sdata_assert_lock(sdata
);
2508 * we are not associated yet, the only timer that could be
2509 * running is the timeout for the association response which
2510 * which is not relevant anymore.
2512 del_timer_sync(&sdata
->u
.mgd
.timer
);
2513 sta_info_destroy_addr(sdata
, assoc_data
->bss
->bssid
);
2515 eth_zero_addr(sdata
->u
.mgd
.bssid
);
2516 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2517 sdata
->u
.mgd
.flags
= 0;
2518 sdata
->vif
.mu_mimo_owner
= false;
2520 mutex_lock(&sdata
->local
->mtx
);
2521 ieee80211_vif_release_channel(sdata
);
2522 mutex_unlock(&sdata
->local
->mtx
);
2525 cfg80211_abandon_assoc(sdata
->dev
, assoc_data
->bss
);
2529 sdata
->u
.mgd
.assoc_data
= NULL
;
2532 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
2533 struct ieee80211_mgmt
*mgmt
, size_t len
)
2535 struct ieee80211_local
*local
= sdata
->local
;
2536 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2538 struct ieee802_11_elems elems
;
2541 pos
= mgmt
->u
.auth
.variable
;
2542 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2543 if (!elems
.challenge
)
2545 auth_data
->expected_transaction
= 4;
2546 drv_mgd_prepare_tx(sdata
->local
, sdata
);
2547 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
2548 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2549 IEEE80211_TX_INTFL_MLME_CONN_TX
;
2550 ieee80211_send_auth(sdata
, 3, auth_data
->algorithm
, 0,
2551 elems
.challenge
- 2, elems
.challenge_len
+ 2,
2552 auth_data
->bss
->bssid
, auth_data
->bss
->bssid
,
2553 auth_data
->key
, auth_data
->key_len
,
2554 auth_data
->key_idx
, tx_flags
);
2557 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
2558 struct ieee80211_mgmt
*mgmt
, size_t len
)
2560 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2562 u16 auth_alg
, auth_transaction
, status_code
;
2563 struct sta_info
*sta
;
2564 struct ieee80211_event event
= {
2566 .u
.mlme
.data
= AUTH_EVENT
,
2569 sdata_assert_lock(sdata
);
2574 if (!ifmgd
->auth_data
|| ifmgd
->auth_data
->done
)
2577 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
2579 if (!ether_addr_equal(bssid
, mgmt
->bssid
))
2582 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
2583 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
2584 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
2586 if (auth_alg
!= ifmgd
->auth_data
->algorithm
||
2587 auth_transaction
!= ifmgd
->auth_data
->expected_transaction
) {
2588 sdata_info(sdata
, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2589 mgmt
->sa
, auth_alg
, ifmgd
->auth_data
->algorithm
,
2591 ifmgd
->auth_data
->expected_transaction
);
2595 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2596 sdata_info(sdata
, "%pM denied authentication (status %d)\n",
2597 mgmt
->sa
, status_code
);
2598 ieee80211_destroy_auth_data(sdata
, false);
2599 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2600 event
.u
.mlme
.status
= MLME_DENIED
;
2601 event
.u
.mlme
.reason
= status_code
;
2602 drv_event_callback(sdata
->local
, sdata
, &event
);
2606 switch (ifmgd
->auth_data
->algorithm
) {
2607 case WLAN_AUTH_OPEN
:
2608 case WLAN_AUTH_LEAP
:
2611 case WLAN_AUTH_FILS_SK
:
2612 case WLAN_AUTH_FILS_SK_PFS
:
2613 case WLAN_AUTH_FILS_PK
:
2615 case WLAN_AUTH_SHARED_KEY
:
2616 if (ifmgd
->auth_data
->expected_transaction
!= 4) {
2617 ieee80211_auth_challenge(sdata
, mgmt
, len
);
2618 /* need another frame */
2623 WARN_ONCE(1, "invalid auth alg %d",
2624 ifmgd
->auth_data
->algorithm
);
2628 event
.u
.mlme
.status
= MLME_SUCCESS
;
2629 drv_event_callback(sdata
->local
, sdata
, &event
);
2630 sdata_info(sdata
, "authenticated\n");
2631 ifmgd
->auth_data
->done
= true;
2632 ifmgd
->auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_WAIT_ASSOC
;
2633 ifmgd
->auth_data
->timeout_started
= true;
2634 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2636 if (ifmgd
->auth_data
->algorithm
== WLAN_AUTH_SAE
&&
2637 ifmgd
->auth_data
->expected_transaction
!= 2) {
2639 * Report auth frame to user space for processing since another
2640 * round of Authentication frames is still needed.
2642 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2646 /* move station state to auth */
2647 mutex_lock(&sdata
->local
->sta_mtx
);
2648 sta
= sta_info_get(sdata
, bssid
);
2650 WARN_ONCE(1, "%s: STA %pM not found", sdata
->name
, bssid
);
2653 if (sta_info_move_state(sta
, IEEE80211_STA_AUTH
)) {
2654 sdata_info(sdata
, "failed moving %pM to auth\n", bssid
);
2657 mutex_unlock(&sdata
->local
->sta_mtx
);
2659 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2662 mutex_unlock(&sdata
->local
->sta_mtx
);
2663 /* ignore frame -- wait for timeout */
2666 #define case_WLAN(type) \
2667 case WLAN_REASON_##type: return #type
2669 static const char *ieee80211_get_reason_code_string(u16 reason_code
)
2671 switch (reason_code
) {
2672 case_WLAN(UNSPECIFIED
);
2673 case_WLAN(PREV_AUTH_NOT_VALID
);
2674 case_WLAN(DEAUTH_LEAVING
);
2675 case_WLAN(DISASSOC_DUE_TO_INACTIVITY
);
2676 case_WLAN(DISASSOC_AP_BUSY
);
2677 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA
);
2678 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA
);
2679 case_WLAN(DISASSOC_STA_HAS_LEFT
);
2680 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH
);
2681 case_WLAN(DISASSOC_BAD_POWER
);
2682 case_WLAN(DISASSOC_BAD_SUPP_CHAN
);
2683 case_WLAN(INVALID_IE
);
2684 case_WLAN(MIC_FAILURE
);
2685 case_WLAN(4WAY_HANDSHAKE_TIMEOUT
);
2686 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT
);
2687 case_WLAN(IE_DIFFERENT
);
2688 case_WLAN(INVALID_GROUP_CIPHER
);
2689 case_WLAN(INVALID_PAIRWISE_CIPHER
);
2690 case_WLAN(INVALID_AKMP
);
2691 case_WLAN(UNSUPP_RSN_VERSION
);
2692 case_WLAN(INVALID_RSN_IE_CAP
);
2693 case_WLAN(IEEE8021X_FAILED
);
2694 case_WLAN(CIPHER_SUITE_REJECTED
);
2695 case_WLAN(DISASSOC_UNSPECIFIED_QOS
);
2696 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH
);
2697 case_WLAN(DISASSOC_LOW_ACK
);
2698 case_WLAN(DISASSOC_QAP_EXCEED_TXOP
);
2699 case_WLAN(QSTA_LEAVE_QBSS
);
2700 case_WLAN(QSTA_NOT_USE
);
2701 case_WLAN(QSTA_REQUIRE_SETUP
);
2702 case_WLAN(QSTA_TIMEOUT
);
2703 case_WLAN(QSTA_CIPHER_NOT_SUPP
);
2704 case_WLAN(MESH_PEER_CANCELED
);
2705 case_WLAN(MESH_MAX_PEERS
);
2706 case_WLAN(MESH_CONFIG
);
2707 case_WLAN(MESH_CLOSE
);
2708 case_WLAN(MESH_MAX_RETRIES
);
2709 case_WLAN(MESH_CONFIRM_TIMEOUT
);
2710 case_WLAN(MESH_INVALID_GTK
);
2711 case_WLAN(MESH_INCONSISTENT_PARAM
);
2712 case_WLAN(MESH_INVALID_SECURITY
);
2713 case_WLAN(MESH_PATH_ERROR
);
2714 case_WLAN(MESH_PATH_NOFORWARD
);
2715 case_WLAN(MESH_PATH_DEST_UNREACHABLE
);
2716 case_WLAN(MAC_EXISTS_IN_MBSS
);
2717 case_WLAN(MESH_CHAN_REGULATORY
);
2718 case_WLAN(MESH_CHAN
);
2719 default: return "<unknown>";
2723 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
2724 struct ieee80211_mgmt
*mgmt
, size_t len
)
2726 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2727 u16 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
2729 sdata_assert_lock(sdata
);
2734 if (ifmgd
->associated
&&
2735 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
)) {
2736 const u8
*bssid
= ifmgd
->associated
->bssid
;
2738 sdata_info(sdata
, "deauthenticated from %pM (Reason: %u=%s)\n",
2740 ieee80211_get_reason_code_string(reason_code
));
2742 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2744 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false,
2749 if (ifmgd
->assoc_data
&&
2750 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
2751 const u8
*bssid
= ifmgd
->assoc_data
->bss
->bssid
;
2754 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
2756 ieee80211_get_reason_code_string(reason_code
));
2758 ieee80211_destroy_assoc_data(sdata
, false, true);
2760 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2766 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
2767 struct ieee80211_mgmt
*mgmt
, size_t len
)
2769 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2772 sdata_assert_lock(sdata
);
2777 if (!ifmgd
->associated
||
2778 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2781 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
2783 sdata_info(sdata
, "disassociated from %pM (Reason: %u=%s)\n",
2784 mgmt
->sa
, reason_code
,
2785 ieee80211_get_reason_code_string(reason_code
));
2787 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2789 ieee80211_report_disconnect(sdata
, (u8
*)mgmt
, len
, false, reason_code
);
2792 static void ieee80211_get_rates(struct ieee80211_supported_band
*sband
,
2793 u8
*supp_rates
, unsigned int supp_rates_len
,
2794 u32
*rates
, u32
*basic_rates
,
2795 bool *have_higher_than_11mbit
,
2796 int *min_rate
, int *min_rate_index
,
2801 for (i
= 0; i
< supp_rates_len
; i
++) {
2802 int rate
= supp_rates
[i
] & 0x7f;
2803 bool is_basic
= !!(supp_rates
[i
] & 0x80);
2805 if ((rate
* 5 * (1 << shift
)) > 110)
2806 *have_higher_than_11mbit
= true;
2809 * Skip HT and VHT BSS membership selectors since they're not
2812 * Note: Even though the membership selector and the basic
2813 * rate flag share the same bit, they are not exactly
2816 if (supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY
) ||
2817 supp_rates
[i
] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY
))
2820 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2821 struct ieee80211_rate
*br
;
2824 br
= &sband
->bitrates
[j
];
2826 brate
= DIV_ROUND_UP(br
->bitrate
, (1 << shift
) * 5);
2827 if (brate
== rate
) {
2830 *basic_rates
|= BIT(j
);
2831 if ((rate
* 5) < *min_rate
) {
2832 *min_rate
= rate
* 5;
2833 *min_rate_index
= j
;
2841 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data
*sdata
,
2842 struct cfg80211_bss
*cbss
,
2843 struct ieee80211_mgmt
*mgmt
, size_t len
)
2845 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2846 struct ieee80211_local
*local
= sdata
->local
;
2847 struct ieee80211_supported_band
*sband
;
2848 struct sta_info
*sta
;
2850 u16 capab_info
, aid
;
2851 struct ieee802_11_elems elems
;
2852 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2853 const struct cfg80211_bss_ies
*bss_ies
= NULL
;
2854 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
2859 /* AssocResp and ReassocResp have identical structure */
2861 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
2862 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
2864 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2865 sdata_info(sdata
, "invalid AID value 0x%x; bits 15:14 not set\n",
2867 aid
&= ~(BIT(15) | BIT(14));
2869 ifmgd
->broken_ap
= false;
2871 if (aid
== 0 || aid
> IEEE80211_MAX_AID
) {
2872 sdata_info(sdata
, "invalid AID value %d (out of range), turn off PS\n",
2875 ifmgd
->broken_ap
= true;
2878 pos
= mgmt
->u
.assoc_resp
.variable
;
2879 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2881 if (!elems
.supp_rates
) {
2882 sdata_info(sdata
, "no SuppRates element in AssocResp\n");
2887 ifmgd
->tdls_chan_switch_prohibited
=
2888 elems
.ext_capab
&& elems
.ext_capab_len
>= 5 &&
2889 (elems
.ext_capab
[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED
);
2892 * Some APs are erroneously not including some information in their
2893 * (re)association response frames. Try to recover by using the data
2894 * from the beacon or probe response. This seems to afflict mobile
2895 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2896 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2898 if ((assoc_data
->wmm
&& !elems
.wmm_param
) ||
2899 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
2900 (!elems
.ht_cap_elem
|| !elems
.ht_operation
)) ||
2901 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
2902 (!elems
.vht_cap_elem
|| !elems
.vht_operation
))) {
2903 const struct cfg80211_bss_ies
*ies
;
2904 struct ieee802_11_elems bss_elems
;
2907 ies
= rcu_dereference(cbss
->ies
);
2909 bss_ies
= kmemdup(ies
, sizeof(*ies
) + ies
->len
,
2915 ieee802_11_parse_elems(bss_ies
->data
, bss_ies
->len
,
2917 if (assoc_data
->wmm
&&
2918 !elems
.wmm_param
&& bss_elems
.wmm_param
) {
2919 elems
.wmm_param
= bss_elems
.wmm_param
;
2921 "AP bug: WMM param missing from AssocResp\n");
2925 * Also check if we requested HT/VHT, otherwise the AP doesn't
2926 * have to include the IEs in the (re)association response.
2928 if (!elems
.ht_cap_elem
&& bss_elems
.ht_cap_elem
&&
2929 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
2930 elems
.ht_cap_elem
= bss_elems
.ht_cap_elem
;
2932 "AP bug: HT capability missing from AssocResp\n");
2934 if (!elems
.ht_operation
&& bss_elems
.ht_operation
&&
2935 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
2936 elems
.ht_operation
= bss_elems
.ht_operation
;
2938 "AP bug: HT operation missing from AssocResp\n");
2940 if (!elems
.vht_cap_elem
&& bss_elems
.vht_cap_elem
&&
2941 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
2942 elems
.vht_cap_elem
= bss_elems
.vht_cap_elem
;
2944 "AP bug: VHT capa missing from AssocResp\n");
2946 if (!elems
.vht_operation
&& bss_elems
.vht_operation
&&
2947 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
2948 elems
.vht_operation
= bss_elems
.vht_operation
;
2950 "AP bug: VHT operation missing from AssocResp\n");
2955 * We previously checked these in the beacon/probe response, so
2956 * they should be present here. This is just a safety net.
2958 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
2959 (!elems
.wmm_param
|| !elems
.ht_cap_elem
|| !elems
.ht_operation
)) {
2961 "HT AP is missing WMM params or HT capability/operation\n");
2966 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
2967 (!elems
.vht_cap_elem
|| !elems
.vht_operation
)) {
2969 "VHT AP is missing VHT capability/operation\n");
2974 mutex_lock(&sdata
->local
->sta_mtx
);
2976 * station info was already allocated and inserted before
2977 * the association and should be available to us
2979 sta
= sta_info_get(sdata
, cbss
->bssid
);
2980 if (WARN_ON(!sta
)) {
2981 mutex_unlock(&sdata
->local
->sta_mtx
);
2986 sband
= ieee80211_get_sband(sdata
);
2988 mutex_unlock(&sdata
->local
->sta_mtx
);
2993 /* Set up internal HT/VHT capabilities */
2994 if (elems
.ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
2995 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
2996 elems
.ht_cap_elem
, sta
);
2998 if (elems
.vht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
2999 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
3000 elems
.vht_cap_elem
, sta
);
3003 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3004 * in their association response, so ignore that data for our own
3005 * configuration. If it changed since the last beacon, we'll get the
3006 * next beacon and update then.
3010 * If an operating mode notification IE is present, override the
3011 * NSS calculation (that would be done in rate_control_rate_init())
3012 * and use the # of streams from that element.
3014 if (elems
.opmode_notif
&&
3015 !(*elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)) {
3018 nss
= *elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
3019 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
3021 sta
->sta
.rx_nss
= nss
;
3024 rate_control_rate_init(sta
);
3026 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
) {
3027 set_sta_flag(sta
, WLAN_STA_MFP
);
3028 sta
->sta
.mfp
= true;
3030 sta
->sta
.mfp
= false;
3033 sta
->sta
.wme
= elems
.wmm_param
&& local
->hw
.queues
>= IEEE80211_NUM_ACS
;
3035 err
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
3036 if (!err
&& !(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
3037 err
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
3040 "failed to move station %pM to desired state\n",
3042 WARN_ON(__sta_info_destroy(sta
));
3043 mutex_unlock(&sdata
->local
->sta_mtx
);
3048 mutex_unlock(&sdata
->local
->sta_mtx
);
3051 * Always handle WMM once after association regardless
3052 * of the first value the AP uses. Setting -1 here has
3053 * that effect because the AP values is an unsigned
3056 ifmgd
->wmm_last_param_set
= -1;
3058 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
3059 ieee80211_set_wmm_default(sdata
, false, false);
3060 } else if (!ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3061 elems
.wmm_param_len
)) {
3062 /* still enable QoS since we might have HT/VHT */
3063 ieee80211_set_wmm_default(sdata
, false, true);
3064 /* set the disable-WMM flag in this case to disable
3065 * tracking WMM parameter changes in the beacon if
3066 * the parameters weren't actually valid. Doing so
3067 * avoids changing parameters very strangely when
3068 * the AP is going back and forth between valid and
3069 * invalid parameters.
3071 ifmgd
->flags
|= IEEE80211_STA_DISABLE_WMM
;
3073 changed
|= BSS_CHANGED_QOS
;
3075 if (elems
.max_idle_period_ie
) {
3076 bss_conf
->max_idle_period
=
3077 le16_to_cpu(elems
.max_idle_period_ie
->max_idle_period
);
3078 bss_conf
->protected_keep_alive
=
3079 !!(elems
.max_idle_period_ie
->idle_options
&
3080 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE
);
3081 changed
|= BSS_CHANGED_KEEP_ALIVE
;
3083 bss_conf
->max_idle_period
= 0;
3084 bss_conf
->protected_keep_alive
= false;
3087 /* set AID and assoc capability,
3088 * ieee80211_set_associated() will tell the driver */
3089 bss_conf
->aid
= aid
;
3090 bss_conf
->assoc_capability
= capab_info
;
3091 ieee80211_set_associated(sdata
, cbss
, changed
);
3094 * If we're using 4-addr mode, let the AP know that we're
3095 * doing so, so that it can create the STA VLAN on its side
3097 if (ifmgd
->use_4addr
)
3098 ieee80211_send_4addr_nullfunc(local
, sdata
);
3101 * Start timer to probe the connection to the AP now.
3102 * Also start the timer that will detect beacon loss.
3104 ieee80211_sta_rx_notify(sdata
, (struct ieee80211_hdr
*)mgmt
);
3105 ieee80211_sta_reset_beacon_monitor(sdata
);
3113 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
3114 struct ieee80211_mgmt
*mgmt
,
3117 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3118 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
3119 u16 capab_info
, status_code
, aid
;
3120 struct ieee802_11_elems elems
;
3121 int ac
, uapsd_queues
= -1;
3124 struct cfg80211_bss
*bss
;
3125 struct ieee80211_event event
= {
3127 .u
.mlme
.data
= ASSOC_EVENT
,
3130 sdata_assert_lock(sdata
);
3134 if (!ether_addr_equal(assoc_data
->bss
->bssid
, mgmt
->bssid
))
3138 * AssocResp and ReassocResp have identical structure, so process both
3139 * of them in this function.
3145 reassoc
= ieee80211_is_reassoc_resp(mgmt
->frame_control
);
3146 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
3147 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
3148 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
3151 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3152 reassoc
? "Rea" : "A", mgmt
->sa
,
3153 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
3155 if (assoc_data
->fils_kek_len
&&
3156 fils_decrypt_assoc_resp(sdata
, (u8
*)mgmt
, &len
, assoc_data
) < 0)
3159 pos
= mgmt
->u
.assoc_resp
.variable
;
3160 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
3162 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
3163 elems
.timeout_int
&&
3164 elems
.timeout_int
->type
== WLAN_TIMEOUT_ASSOC_COMEBACK
) {
3166 tu
= le32_to_cpu(elems
.timeout_int
->value
);
3167 ms
= tu
* 1024 / 1000;
3169 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3171 assoc_data
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
3172 assoc_data
->timeout_started
= true;
3173 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
3174 run_again(sdata
, assoc_data
->timeout
);
3178 bss
= assoc_data
->bss
;
3180 if (status_code
!= WLAN_STATUS_SUCCESS
) {
3181 sdata_info(sdata
, "%pM denied association (code=%d)\n",
3182 mgmt
->sa
, status_code
);
3183 ieee80211_destroy_assoc_data(sdata
, false, false);
3184 event
.u
.mlme
.status
= MLME_DENIED
;
3185 event
.u
.mlme
.reason
= status_code
;
3186 drv_event_callback(sdata
->local
, sdata
, &event
);
3188 if (!ieee80211_assoc_success(sdata
, bss
, mgmt
, len
)) {
3189 /* oops -- internal error -- send timeout for now */
3190 ieee80211_destroy_assoc_data(sdata
, false, false);
3191 cfg80211_assoc_timeout(sdata
->dev
, bss
);
3194 event
.u
.mlme
.status
= MLME_SUCCESS
;
3195 drv_event_callback(sdata
->local
, sdata
, &event
);
3196 sdata_info(sdata
, "associated\n");
3199 * destroy assoc_data afterwards, as otherwise an idle
3200 * recalc after assoc_data is NULL but before associated
3201 * is set can cause the interface to go idle
3203 ieee80211_destroy_assoc_data(sdata
, true, false);
3205 /* get uapsd queues configuration */
3207 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
3208 if (sdata
->tx_conf
[ac
].uapsd
)
3209 uapsd_queues
|= ieee80211_ac_to_qos_mask
[ac
];
3212 cfg80211_rx_assoc_resp(sdata
->dev
, bss
, (u8
*)mgmt
, len
, uapsd_queues
);
3215 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
3216 struct ieee80211_mgmt
*mgmt
, size_t len
,
3217 struct ieee80211_rx_status
*rx_status
,
3218 struct ieee802_11_elems
*elems
)
3220 struct ieee80211_local
*local
= sdata
->local
;
3221 struct ieee80211_bss
*bss
;
3222 struct ieee80211_channel
*channel
;
3224 sdata_assert_lock(sdata
);
3226 channel
= ieee80211_get_channel(local
->hw
.wiphy
, rx_status
->freq
);
3230 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
3233 sdata
->vif
.bss_conf
.beacon_rate
= bss
->beacon_rate
;
3234 ieee80211_rx_bss_put(local
, bss
);
3239 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
3240 struct sk_buff
*skb
)
3242 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
3243 struct ieee80211_if_managed
*ifmgd
;
3244 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
3245 size_t baselen
, len
= skb
->len
;
3246 struct ieee802_11_elems elems
;
3248 ifmgd
= &sdata
->u
.mgd
;
3250 sdata_assert_lock(sdata
);
3252 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
3253 return; /* ignore ProbeResp to foreign address */
3255 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
3259 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
3262 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3264 if (ifmgd
->associated
&&
3265 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3266 ieee80211_reset_ap_probe(sdata
);
3270 * This is the canonical list of information elements we care about,
3271 * the filter code also gives us all changes to the Microsoft OUI
3272 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3273 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3274 * changes to requested client power.
3276 * We implement beacon filtering in software since that means we can
3277 * avoid processing the frame here and in cfg80211, and userspace
3278 * will not be able to tell whether the hardware supports it or not.
3280 * XXX: This list needs to be dynamic -- userspace needs to be able to
3281 * add items it requires. It also needs to be able to tell us to
3282 * look out for other vendor IEs.
3284 static const u64 care_about_ies
=
3285 (1ULL << WLAN_EID_COUNTRY
) |
3286 (1ULL << WLAN_EID_ERP_INFO
) |
3287 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
3288 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
3289 (1ULL << WLAN_EID_HT_CAPABILITY
) |
3290 (1ULL << WLAN_EID_HT_OPERATION
) |
3291 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN
);
3293 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
3294 struct ieee80211_mgmt
*mgmt
, size_t len
,
3295 struct ieee80211_rx_status
*rx_status
)
3297 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3298 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
3300 struct ieee802_11_elems elems
;
3301 struct ieee80211_local
*local
= sdata
->local
;
3302 struct ieee80211_chanctx_conf
*chanctx_conf
;
3303 struct ieee80211_channel
*chan
;
3304 struct sta_info
*sta
;
3310 u8 deauth_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3312 sdata_assert_lock(sdata
);
3314 /* Process beacon from the current BSS */
3315 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
3320 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3321 if (!chanctx_conf
) {
3326 if (rx_status
->freq
!= chanctx_conf
->def
.chan
->center_freq
) {
3330 chan
= chanctx_conf
->def
.chan
;
3333 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->need_beacon
&&
3334 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
3335 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
3336 len
- baselen
, false, &elems
);
3338 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3339 if (elems
.tim
&& !elems
.parse_error
) {
3340 const struct ieee80211_tim_ie
*tim_ie
= elems
.tim
;
3341 ifmgd
->dtim_period
= tim_ie
->dtim_period
;
3343 ifmgd
->have_beacon
= true;
3344 ifmgd
->assoc_data
->need_beacon
= false;
3345 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3346 sdata
->vif
.bss_conf
.sync_tsf
=
3347 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3348 sdata
->vif
.bss_conf
.sync_device_ts
=
3349 rx_status
->device_timestamp
;
3351 sdata
->vif
.bss_conf
.sync_dtim_count
=
3352 elems
.tim
->dtim_count
;
3354 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3356 /* continue assoc process */
3357 ifmgd
->assoc_data
->timeout
= jiffies
;
3358 ifmgd
->assoc_data
->timeout_started
= true;
3359 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3363 if (!ifmgd
->associated
||
3364 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
3366 bssid
= ifmgd
->associated
->bssid
;
3368 /* Track average RSSI from the Beacon frames of the current AP */
3369 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
3370 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
3371 ewma_beacon_signal_init(&ifmgd
->ave_beacon_signal
);
3372 ifmgd
->last_cqm_event_signal
= 0;
3373 ifmgd
->count_beacon_signal
= 1;
3374 ifmgd
->last_ave_beacon_signal
= 0;
3376 ifmgd
->count_beacon_signal
++;
3379 ewma_beacon_signal_add(&ifmgd
->ave_beacon_signal
, -rx_status
->signal
);
3381 if (ifmgd
->rssi_min_thold
!= ifmgd
->rssi_max_thold
&&
3382 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3383 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3384 int last_sig
= ifmgd
->last_ave_beacon_signal
;
3385 struct ieee80211_event event
= {
3390 * if signal crosses either of the boundaries, invoke callback
3391 * with appropriate parameters
3393 if (sig
> ifmgd
->rssi_max_thold
&&
3394 (last_sig
<= ifmgd
->rssi_min_thold
|| last_sig
== 0)) {
3395 ifmgd
->last_ave_beacon_signal
= sig
;
3396 event
.u
.rssi
.data
= RSSI_EVENT_HIGH
;
3397 drv_event_callback(local
, sdata
, &event
);
3398 } else if (sig
< ifmgd
->rssi_min_thold
&&
3399 (last_sig
>= ifmgd
->rssi_max_thold
||
3401 ifmgd
->last_ave_beacon_signal
= sig
;
3402 event
.u
.rssi
.data
= RSSI_EVENT_LOW
;
3403 drv_event_callback(local
, sdata
, &event
);
3407 if (bss_conf
->cqm_rssi_thold
&&
3408 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
3409 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)) {
3410 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3411 int last_event
= ifmgd
->last_cqm_event_signal
;
3412 int thold
= bss_conf
->cqm_rssi_thold
;
3413 int hyst
= bss_conf
->cqm_rssi_hyst
;
3416 (last_event
== 0 || sig
< last_event
- hyst
)) {
3417 ifmgd
->last_cqm_event_signal
= sig
;
3418 ieee80211_cqm_rssi_notify(
3420 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3422 } else if (sig
> thold
&&
3423 (last_event
== 0 || sig
> last_event
+ hyst
)) {
3424 ifmgd
->last_cqm_event_signal
= sig
;
3425 ieee80211_cqm_rssi_notify(
3427 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3432 if (bss_conf
->cqm_rssi_low
&&
3433 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
3434 int sig
= -ewma_beacon_signal_read(&ifmgd
->ave_beacon_signal
);
3435 int last_event
= ifmgd
->last_cqm_event_signal
;
3436 int low
= bss_conf
->cqm_rssi_low
;
3437 int high
= bss_conf
->cqm_rssi_high
;
3440 (last_event
== 0 || last_event
>= low
)) {
3441 ifmgd
->last_cqm_event_signal
= sig
;
3442 ieee80211_cqm_rssi_notify(
3444 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
3446 } else if (sig
> high
&&
3447 (last_event
== 0 || last_event
<= high
)) {
3448 ifmgd
->last_cqm_event_signal
= sig
;
3449 ieee80211_cqm_rssi_notify(
3451 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
3456 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
) {
3457 mlme_dbg_ratelimited(sdata
,
3458 "cancelling AP probe due to a received beacon\n");
3459 ieee80211_reset_ap_probe(sdata
);
3463 * Push the beacon loss detection into the future since
3464 * we are processing a beacon from the AP just now.
3466 ieee80211_sta_reset_beacon_monitor(sdata
);
3468 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
3469 ncrc
= ieee802_11_parse_elems_crc(mgmt
->u
.beacon
.variable
,
3470 len
- baselen
, false, &elems
,
3471 care_about_ies
, ncrc
);
3473 if (ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
) &&
3474 ieee80211_check_tim(elems
.tim
, elems
.tim_len
, ifmgd
->aid
)) {
3475 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
3476 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
3477 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
3478 ieee80211_hw_config(local
,
3479 IEEE80211_CONF_CHANGE_PS
);
3481 ieee80211_send_nullfunc(local
, sdata
, false);
3482 } else if (!local
->pspolling
&& sdata
->u
.mgd
.powersave
) {
3483 local
->pspolling
= true;
3486 * Here is assumed that the driver will be
3487 * able to send ps-poll frame and receive a
3488 * response even though power save mode is
3489 * enabled, but some drivers might require
3490 * to disable power save here. This needs
3491 * to be investigated.
3493 ieee80211_send_pspoll(local
, sdata
);
3497 if (sdata
->vif
.p2p
||
3498 sdata
->vif
.driver_flags
& IEEE80211_VIF_GET_NOA_UPDATE
) {
3499 struct ieee80211_p2p_noa_attr noa
= {};
3502 ret
= cfg80211_get_p2p_attr(mgmt
->u
.beacon
.variable
,
3504 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
3505 (u8
*) &noa
, sizeof(noa
));
3507 if (sdata
->u
.mgd
.p2p_noa_index
!= noa
.index
) {
3508 /* valid noa_attr and index changed */
3509 sdata
->u
.mgd
.p2p_noa_index
= noa
.index
;
3510 memcpy(&bss_conf
->p2p_noa_attr
, &noa
, sizeof(noa
));
3511 changed
|= BSS_CHANGED_P2P_PS
;
3513 * make sure we update all information, the CRC
3514 * mechanism doesn't look at P2P attributes.
3516 ifmgd
->beacon_crc_valid
= false;
3518 } else if (sdata
->u
.mgd
.p2p_noa_index
!= -1) {
3519 /* noa_attr not found and we had valid noa_attr before */
3520 sdata
->u
.mgd
.p2p_noa_index
= -1;
3521 memset(&bss_conf
->p2p_noa_attr
, 0, sizeof(bss_conf
->p2p_noa_attr
));
3522 changed
|= BSS_CHANGED_P2P_PS
;
3523 ifmgd
->beacon_crc_valid
= false;
3527 if (ifmgd
->csa_waiting_bcn
)
3528 ieee80211_chswitch_post_beacon(sdata
);
3531 * Update beacon timing and dtim count on every beacon appearance. This
3532 * will allow the driver to use the most updated values. Do it before
3533 * comparing this one with last received beacon.
3534 * IMPORTANT: These parameters would possibly be out of sync by the time
3535 * the driver will use them. The synchronized view is currently
3536 * guaranteed only in certain callbacks.
3538 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
3539 sdata
->vif
.bss_conf
.sync_tsf
=
3540 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3541 sdata
->vif
.bss_conf
.sync_device_ts
=
3542 rx_status
->device_timestamp
;
3544 sdata
->vif
.bss_conf
.sync_dtim_count
=
3545 elems
.tim
->dtim_count
;
3547 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3550 if (ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
)
3552 ifmgd
->beacon_crc
= ncrc
;
3553 ifmgd
->beacon_crc_valid
= true;
3555 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
3557 ieee80211_sta_process_chanswitch(sdata
, rx_status
->mactime
,
3558 rx_status
->device_timestamp
,
3561 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) &&
3562 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
3563 elems
.wmm_param_len
))
3564 changed
|= BSS_CHANGED_QOS
;
3567 * If we haven't had a beacon before, tell the driver about the
3568 * DTIM period (and beacon timing if desired) now.
3570 if (!ifmgd
->have_beacon
) {
3571 /* a few bogus AP send dtim_period = 0 or no TIM IE */
3573 bss_conf
->dtim_period
= elems
.tim
->dtim_period
?: 1;
3575 bss_conf
->dtim_period
= 1;
3577 changed
|= BSS_CHANGED_BEACON_INFO
;
3578 ifmgd
->have_beacon
= true;
3580 mutex_lock(&local
->iflist_mtx
);
3581 ieee80211_recalc_ps(local
);
3582 mutex_unlock(&local
->iflist_mtx
);
3584 ieee80211_recalc_ps_vif(sdata
);
3587 if (elems
.erp_info
) {
3589 erp_value
= elems
.erp_info
[0];
3593 changed
|= ieee80211_handle_bss_capability(sdata
,
3594 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
3595 erp_valid
, erp_value
);
3597 mutex_lock(&local
->sta_mtx
);
3598 sta
= sta_info_get(sdata
, bssid
);
3600 if (ieee80211_config_bw(sdata
, sta
,
3601 elems
.ht_cap_elem
, elems
.ht_operation
,
3602 elems
.vht_operation
, bssid
, &changed
)) {
3603 mutex_unlock(&local
->sta_mtx
);
3605 "failed to follow AP %pM bandwidth change, disconnect\n",
3607 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
3608 WLAN_REASON_DEAUTH_LEAVING
,
3610 ieee80211_report_disconnect(sdata
, deauth_buf
,
3611 sizeof(deauth_buf
), true,
3612 WLAN_REASON_DEAUTH_LEAVING
);
3616 if (sta
&& elems
.opmode_notif
)
3617 ieee80211_vht_handle_opmode(sdata
, sta
, *elems
.opmode_notif
,
3619 mutex_unlock(&local
->sta_mtx
);
3621 changed
|= ieee80211_handle_pwr_constr(sdata
, chan
, mgmt
,
3623 elems
.country_elem_len
,
3624 elems
.pwr_constr_elem
,
3625 elems
.cisco_dtpc_elem
);
3627 ieee80211_bss_info_change_notify(sdata
, changed
);
3630 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
3631 struct sk_buff
*skb
)
3633 struct ieee80211_rx_status
*rx_status
;
3634 struct ieee80211_mgmt
*mgmt
;
3636 struct ieee802_11_elems elems
;
3639 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3640 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3641 fc
= le16_to_cpu(mgmt
->frame_control
);
3645 switch (fc
& IEEE80211_FCTL_STYPE
) {
3646 case IEEE80211_STYPE_BEACON
:
3647 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3649 case IEEE80211_STYPE_PROBE_RESP
:
3650 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
3652 case IEEE80211_STYPE_AUTH
:
3653 ieee80211_rx_mgmt_auth(sdata
, mgmt
, skb
->len
);
3655 case IEEE80211_STYPE_DEAUTH
:
3656 ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
3658 case IEEE80211_STYPE_DISASSOC
:
3659 ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
3661 case IEEE80211_STYPE_ASSOC_RESP
:
3662 case IEEE80211_STYPE_REASSOC_RESP
:
3663 ieee80211_rx_mgmt_assoc_resp(sdata
, mgmt
, skb
->len
);
3665 case IEEE80211_STYPE_ACTION
:
3666 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
) {
3667 ies_len
= skb
->len
-
3668 offsetof(struct ieee80211_mgmt
,
3669 u
.action
.u
.chan_switch
.variable
);
3674 ieee802_11_parse_elems(
3675 mgmt
->u
.action
.u
.chan_switch
.variable
,
3676 ies_len
, true, &elems
);
3678 if (elems
.parse_error
)
3681 ieee80211_sta_process_chanswitch(sdata
,
3683 rx_status
->device_timestamp
,
3685 } else if (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
) {
3686 ies_len
= skb
->len
-
3687 offsetof(struct ieee80211_mgmt
,
3688 u
.action
.u
.ext_chan_switch
.variable
);
3693 ieee802_11_parse_elems(
3694 mgmt
->u
.action
.u
.ext_chan_switch
.variable
,
3695 ies_len
, true, &elems
);
3697 if (elems
.parse_error
)
3700 /* for the handling code pretend this was also an IE */
3701 elems
.ext_chansw_ie
=
3702 &mgmt
->u
.action
.u
.ext_chan_switch
.data
;
3704 ieee80211_sta_process_chanswitch(sdata
,
3706 rx_status
->device_timestamp
,
3711 sdata_unlock(sdata
);
3714 static void ieee80211_sta_timer(struct timer_list
*t
)
3716 struct ieee80211_sub_if_data
*sdata
=
3717 from_timer(sdata
, t
, u
.mgd
.timer
);
3719 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
3722 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
3723 u8
*bssid
, u8 reason
, bool tx
)
3725 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3727 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
, reason
,
3730 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
3734 static int ieee80211_auth(struct ieee80211_sub_if_data
*sdata
)
3736 struct ieee80211_local
*local
= sdata
->local
;
3737 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3738 struct ieee80211_mgd_auth_data
*auth_data
= ifmgd
->auth_data
;
3743 sdata_assert_lock(sdata
);
3745 if (WARN_ON_ONCE(!auth_data
))
3750 if (auth_data
->tries
> IEEE80211_AUTH_MAX_TRIES
) {
3751 sdata_info(sdata
, "authentication with %pM timed out\n",
3752 auth_data
->bss
->bssid
);
3755 * Most likely AP is not in the range so remove the
3756 * bss struct for that AP.
3758 cfg80211_unlink_bss(local
->hw
.wiphy
, auth_data
->bss
);
3763 drv_mgd_prepare_tx(local
, sdata
);
3765 sdata_info(sdata
, "send auth to %pM (try %d/%d)\n",
3766 auth_data
->bss
->bssid
, auth_data
->tries
,
3767 IEEE80211_AUTH_MAX_TRIES
);
3769 auth_data
->expected_transaction
= 2;
3771 if (auth_data
->algorithm
== WLAN_AUTH_SAE
) {
3772 trans
= auth_data
->sae_trans
;
3773 status
= auth_data
->sae_status
;
3774 auth_data
->expected_transaction
= trans
;
3777 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
3778 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3779 IEEE80211_TX_INTFL_MLME_CONN_TX
;
3781 ieee80211_send_auth(sdata
, trans
, auth_data
->algorithm
, status
,
3782 auth_data
->data
, auth_data
->data_len
,
3783 auth_data
->bss
->bssid
,
3784 auth_data
->bss
->bssid
, NULL
, 0, 0,
3787 if (tx_flags
== 0) {
3788 auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
3789 auth_data
->timeout_started
= true;
3790 run_again(sdata
, auth_data
->timeout
);
3792 auth_data
->timeout
=
3793 round_jiffies_up(jiffies
+ IEEE80211_AUTH_TIMEOUT_LONG
);
3794 auth_data
->timeout_started
= true;
3795 run_again(sdata
, auth_data
->timeout
);
3801 static int ieee80211_do_assoc(struct ieee80211_sub_if_data
*sdata
)
3803 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
3804 struct ieee80211_local
*local
= sdata
->local
;
3806 sdata_assert_lock(sdata
);
3808 assoc_data
->tries
++;
3809 if (assoc_data
->tries
> IEEE80211_ASSOC_MAX_TRIES
) {
3810 sdata_info(sdata
, "association with %pM timed out\n",
3811 assoc_data
->bss
->bssid
);
3814 * Most likely AP is not in the range so remove the
3815 * bss struct for that AP.
3817 cfg80211_unlink_bss(local
->hw
.wiphy
, assoc_data
->bss
);
3822 sdata_info(sdata
, "associate with %pM (try %d/%d)\n",
3823 assoc_data
->bss
->bssid
, assoc_data
->tries
,
3824 IEEE80211_ASSOC_MAX_TRIES
);
3825 ieee80211_send_assoc(sdata
);
3827 if (!ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
3828 assoc_data
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
3829 assoc_data
->timeout_started
= true;
3830 run_again(sdata
, assoc_data
->timeout
);
3832 assoc_data
->timeout
=
3833 round_jiffies_up(jiffies
+
3834 IEEE80211_ASSOC_TIMEOUT_LONG
);
3835 assoc_data
->timeout_started
= true;
3836 run_again(sdata
, assoc_data
->timeout
);
3842 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data
*sdata
,
3843 __le16 fc
, bool acked
)
3845 struct ieee80211_local
*local
= sdata
->local
;
3847 sdata
->u
.mgd
.status_fc
= fc
;
3848 sdata
->u
.mgd
.status_acked
= acked
;
3849 sdata
->u
.mgd
.status_received
= true;
3851 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
3854 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
3856 struct ieee80211_local
*local
= sdata
->local
;
3857 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3861 if (ifmgd
->status_received
) {
3862 __le16 fc
= ifmgd
->status_fc
;
3863 bool status_acked
= ifmgd
->status_acked
;
3865 ifmgd
->status_received
= false;
3866 if (ifmgd
->auth_data
&& ieee80211_is_auth(fc
)) {
3868 ifmgd
->auth_data
->timeout
=
3869 jiffies
+ IEEE80211_AUTH_TIMEOUT_SHORT
;
3870 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3872 ifmgd
->auth_data
->timeout
= jiffies
- 1;
3874 ifmgd
->auth_data
->timeout_started
= true;
3875 } else if (ifmgd
->assoc_data
&&
3876 (ieee80211_is_assoc_req(fc
) ||
3877 ieee80211_is_reassoc_req(fc
))) {
3879 ifmgd
->assoc_data
->timeout
=
3880 jiffies
+ IEEE80211_ASSOC_TIMEOUT_SHORT
;
3881 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3883 ifmgd
->assoc_data
->timeout
= jiffies
- 1;
3885 ifmgd
->assoc_data
->timeout_started
= true;
3889 if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
&&
3890 time_after(jiffies
, ifmgd
->auth_data
->timeout
)) {
3891 if (ifmgd
->auth_data
->done
) {
3893 * ok ... we waited for assoc but userspace didn't,
3894 * so let's just kill the auth data
3896 ieee80211_destroy_auth_data(sdata
, false);
3897 } else if (ieee80211_auth(sdata
)) {
3899 struct ieee80211_event event
= {
3901 .u
.mlme
.data
= AUTH_EVENT
,
3902 .u
.mlme
.status
= MLME_TIMEOUT
,
3905 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
3907 ieee80211_destroy_auth_data(sdata
, false);
3909 cfg80211_auth_timeout(sdata
->dev
, bssid
);
3910 drv_event_callback(sdata
->local
, sdata
, &event
);
3912 } else if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
)
3913 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3915 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
&&
3916 time_after(jiffies
, ifmgd
->assoc_data
->timeout
)) {
3917 if ((ifmgd
->assoc_data
->need_beacon
&& !ifmgd
->have_beacon
) ||
3918 ieee80211_do_assoc(sdata
)) {
3919 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
3920 struct ieee80211_event event
= {
3922 .u
.mlme
.data
= ASSOC_EVENT
,
3923 .u
.mlme
.status
= MLME_TIMEOUT
,
3926 ieee80211_destroy_assoc_data(sdata
, false, false);
3927 cfg80211_assoc_timeout(sdata
->dev
, bss
);
3928 drv_event_callback(sdata
->local
, sdata
, &event
);
3930 } else if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
)
3931 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3933 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
&&
3934 ifmgd
->associated
) {
3938 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
3940 if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
))
3941 max_tries
= max_nullfunc_tries
;
3943 max_tries
= max_probe_tries
;
3945 /* ACK received for nullfunc probing frame */
3946 if (!ifmgd
->probe_send_count
)
3947 ieee80211_reset_ap_probe(sdata
);
3948 else if (ifmgd
->nullfunc_failed
) {
3949 if (ifmgd
->probe_send_count
< max_tries
) {
3951 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3952 bssid
, ifmgd
->probe_send_count
,
3954 ieee80211_mgd_probe_ap_send(sdata
);
3957 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3959 ieee80211_sta_connection_lost(sdata
, bssid
,
3960 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
3963 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
3964 run_again(sdata
, ifmgd
->probe_timeout
);
3965 else if (ieee80211_hw_check(&local
->hw
, REPORTS_TX_ACK_STATUS
)) {
3967 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3968 bssid
, probe_wait_ms
);
3969 ieee80211_sta_connection_lost(sdata
, bssid
,
3970 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
3971 } else if (ifmgd
->probe_send_count
< max_tries
) {
3973 "No probe response from AP %pM after %dms, try %d/%i\n",
3974 bssid
, probe_wait_ms
,
3975 ifmgd
->probe_send_count
, max_tries
);
3976 ieee80211_mgd_probe_ap_send(sdata
);
3979 * We actually lost the connection ... or did we?
3983 "No probe response from AP %pM after %dms, disconnecting.\n",
3984 bssid
, probe_wait_ms
);
3986 ieee80211_sta_connection_lost(sdata
, bssid
,
3987 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
3991 sdata_unlock(sdata
);
3994 static void ieee80211_sta_bcn_mon_timer(struct timer_list
*t
)
3996 struct ieee80211_sub_if_data
*sdata
=
3997 from_timer(sdata
, t
, u
.mgd
.bcn_mon_timer
);
3998 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4000 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4003 sdata
->u
.mgd
.connection_loss
= false;
4004 ieee80211_queue_work(&sdata
->local
->hw
,
4005 &sdata
->u
.mgd
.beacon_connection_loss_work
);
4008 static void ieee80211_sta_conn_mon_timer(struct timer_list
*t
)
4010 struct ieee80211_sub_if_data
*sdata
=
4011 from_timer(sdata
, t
, u
.mgd
.conn_mon_timer
);
4012 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4013 struct ieee80211_local
*local
= sdata
->local
;
4015 if (sdata
->vif
.csa_active
&& !ifmgd
->csa_waiting_bcn
)
4018 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
4021 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
4023 struct ieee80211_sub_if_data
*sdata
=
4024 container_of(work
, struct ieee80211_sub_if_data
,
4025 u
.mgd
.monitor_work
);
4027 ieee80211_mgd_probe_ap(sdata
, false);
4030 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
4032 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
4033 __ieee80211_stop_poll(sdata
);
4035 /* let's probe the connection once */
4036 if (!ieee80211_hw_check(&sdata
->local
->hw
, CONNECTION_MONITOR
))
4037 ieee80211_queue_work(&sdata
->local
->hw
,
4038 &sdata
->u
.mgd
.monitor_work
);
4043 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data
*sdata
)
4045 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4046 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4050 if (ifmgd
->auth_data
|| ifmgd
->assoc_data
) {
4051 const u8
*bssid
= ifmgd
->auth_data
?
4052 ifmgd
->auth_data
->bss
->bssid
:
4053 ifmgd
->assoc_data
->bss
->bssid
;
4056 * If we are trying to authenticate / associate while suspending,
4057 * cfg80211 won't know and won't actually abort those attempts,
4058 * thus we need to do that ourselves.
4060 ieee80211_send_deauth_disassoc(sdata
, bssid
,
4061 IEEE80211_STYPE_DEAUTH
,
4062 WLAN_REASON_DEAUTH_LEAVING
,
4064 if (ifmgd
->assoc_data
)
4065 ieee80211_destroy_assoc_data(sdata
, false, true);
4066 if (ifmgd
->auth_data
)
4067 ieee80211_destroy_auth_data(sdata
, false);
4068 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4069 IEEE80211_DEAUTH_FRAME_LEN
);
4072 /* This is a bit of a hack - we should find a better and more generic
4073 * solution to this. Normally when suspending, cfg80211 will in fact
4074 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4075 * auth (not so important) or assoc (this is the problem) process.
4077 * As a consequence, it can happen that we are in the process of both
4078 * associating and suspending, and receive an association response
4079 * after cfg80211 has checked if it needs to disconnect, but before
4080 * we actually set the flag to drop incoming frames. This will then
4081 * cause the workqueue flush to process the association response in
4082 * the suspend, resulting in a successful association just before it
4083 * tries to remove the interface from the driver, which now though
4084 * has a channel context assigned ... this results in issues.
4086 * To work around this (for now) simply deauth here again if we're
4089 if (ifmgd
->associated
&& !sdata
->local
->wowlan
) {
4091 struct cfg80211_deauth_request req
= {
4092 .reason_code
= WLAN_REASON_DEAUTH_LEAVING
,
4096 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
4097 ieee80211_mgd_deauth(sdata
, &req
);
4100 sdata_unlock(sdata
);
4103 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
4105 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4108 if (!ifmgd
->associated
) {
4109 sdata_unlock(sdata
);
4113 if (sdata
->flags
& IEEE80211_SDATA_DISCONNECT_RESUME
) {
4114 sdata
->flags
&= ~IEEE80211_SDATA_DISCONNECT_RESUME
;
4115 mlme_dbg(sdata
, "driver requested disconnect after resume\n");
4116 ieee80211_sta_connection_lost(sdata
,
4117 ifmgd
->associated
->bssid
,
4118 WLAN_REASON_UNSPECIFIED
,
4120 sdata_unlock(sdata
);
4123 sdata_unlock(sdata
);
4127 /* interface setup */
4128 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
4130 struct ieee80211_if_managed
*ifmgd
;
4132 ifmgd
= &sdata
->u
.mgd
;
4133 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
4134 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
4135 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
4136 ieee80211_beacon_connection_loss_work
);
4137 INIT_WORK(&ifmgd
->csa_connection_drop_work
,
4138 ieee80211_csa_connection_drop_work
);
4139 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_mgd_work
);
4140 INIT_DELAYED_WORK(&ifmgd
->tdls_peer_del_work
,
4141 ieee80211_tdls_peer_del_work
);
4142 timer_setup(&ifmgd
->timer
, ieee80211_sta_timer
, 0);
4143 timer_setup(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
, 0);
4144 timer_setup(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
, 0);
4145 timer_setup(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
, 0);
4146 INIT_DELAYED_WORK(&ifmgd
->tx_tspec_wk
,
4147 ieee80211_sta_handle_tspec_ac_params_wk
);
4150 ifmgd
->powersave
= sdata
->wdev
.ps
;
4151 ifmgd
->uapsd_queues
= sdata
->local
->hw
.uapsd_queues
;
4152 ifmgd
->uapsd_max_sp_len
= sdata
->local
->hw
.uapsd_max_sp_len
;
4153 ifmgd
->p2p_noa_index
= -1;
4155 if (sdata
->local
->hw
.wiphy
->features
& NL80211_FEATURE_DYNAMIC_SMPS
)
4156 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
4158 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
4160 /* Setup TDLS data */
4161 spin_lock_init(&ifmgd
->teardown_lock
);
4162 ifmgd
->teardown_skb
= NULL
;
4163 ifmgd
->orig_teardown_skb
= NULL
;
4166 /* scan finished notification */
4167 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
4169 struct ieee80211_sub_if_data
*sdata
;
4171 /* Restart STA timers */
4173 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
4174 if (ieee80211_sdata_running(sdata
))
4175 ieee80211_restart_sta_timer(sdata
);
4180 static u8
ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data
*sdata
,
4181 struct cfg80211_bss
*cbss
)
4183 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4184 const u8
*ht_cap_ie
, *vht_cap_ie
;
4185 const struct ieee80211_ht_cap
*ht_cap
;
4186 const struct ieee80211_vht_cap
*vht_cap
;
4189 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)
4192 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4193 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
)) {
4194 ht_cap
= (void *)(ht_cap_ie
+ 2);
4195 chains
= ieee80211_mcs_to_chains(&ht_cap
->mcs
);
4197 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4198 * "Tx Unequal Modulation Supported" fields.
4202 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
4205 vht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4206 if (vht_cap_ie
&& vht_cap_ie
[1] >= sizeof(*vht_cap
)) {
4210 vht_cap
= (void *)(vht_cap_ie
+ 2);
4211 tx_mcs_map
= le16_to_cpu(vht_cap
->supp_mcs
.tx_mcs_map
);
4212 for (nss
= 8; nss
> 0; nss
--) {
4213 if (((tx_mcs_map
>> (2 * (nss
- 1))) & 3) !=
4214 IEEE80211_VHT_MCS_NOT_SUPPORTED
)
4217 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4218 chains
= max(chains
, nss
);
4224 static int ieee80211_prep_channel(struct ieee80211_sub_if_data
*sdata
,
4225 struct cfg80211_bss
*cbss
)
4227 struct ieee80211_local
*local
= sdata
->local
;
4228 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4229 const struct ieee80211_ht_cap
*ht_cap
= NULL
;
4230 const struct ieee80211_ht_operation
*ht_oper
= NULL
;
4231 const struct ieee80211_vht_operation
*vht_oper
= NULL
;
4232 struct ieee80211_supported_band
*sband
;
4233 struct cfg80211_chan_def chandef
;
4238 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4240 ifmgd
->flags
&= ~(IEEE80211_STA_DISABLE_40MHZ
|
4241 IEEE80211_STA_DISABLE_80P80MHZ
|
4242 IEEE80211_STA_DISABLE_160MHZ
);
4246 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
4247 sband
->ht_cap
.ht_supported
) {
4248 const u8
*ht_oper_ie
, *ht_cap_ie
;
4250 ht_oper_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_OPERATION
);
4251 if (ht_oper_ie
&& ht_oper_ie
[1] >= sizeof(*ht_oper
))
4252 ht_oper
= (void *)(ht_oper_ie
+ 2);
4254 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
4255 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
))
4256 ht_cap
= (void *)(ht_cap_ie
+ 2);
4259 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4264 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
4265 sband
->vht_cap
.vht_supported
) {
4266 const u8
*vht_oper_ie
, *vht_cap
;
4268 vht_oper_ie
= ieee80211_bss_get_ie(cbss
,
4269 WLAN_EID_VHT_OPERATION
);
4270 if (vht_oper_ie
&& vht_oper_ie
[1] >= sizeof(*vht_oper
))
4271 vht_oper
= (void *)(vht_oper_ie
+ 2);
4272 if (vht_oper
&& !ht_oper
) {
4275 "AP advertised VHT without HT, disabling both\n");
4276 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4277 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4280 vht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
4281 if (!vht_cap
|| vht_cap
[1] < sizeof(struct ieee80211_vht_cap
)) {
4282 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4287 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4289 for (i
= 0; i
< sband
->n_channels
; i
++) {
4290 if (sband
->channels
[i
].flags
& (IEEE80211_CHAN_DISABLED
|
4291 IEEE80211_CHAN_NO_80MHZ
))
4299 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4301 ifmgd
->flags
|= ieee80211_determine_chantype(sdata
, sband
,
4306 sdata
->needed_rx_chains
= min(ieee80211_ht_vht_rx_chains(sdata
, cbss
),
4311 /* will change later if needed */
4312 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4314 mutex_lock(&local
->mtx
);
4316 * If this fails (possibly due to channel context sharing
4317 * on incompatible channels, e.g. 80+80 and 160 sharing the
4318 * same control channel) try to use a smaller bandwidth.
4320 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4321 IEEE80211_CHANCTX_SHARED
);
4323 /* don't downgrade for 5 and 10 MHz channels, though. */
4324 if (chandef
.width
== NL80211_CHAN_WIDTH_5
||
4325 chandef
.width
== NL80211_CHAN_WIDTH_10
)
4328 while (ret
&& chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) {
4329 ifmgd
->flags
|= ieee80211_chandef_downgrade(&chandef
);
4330 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
4331 IEEE80211_CHANCTX_SHARED
);
4334 mutex_unlock(&local
->mtx
);
4338 static int ieee80211_prep_connection(struct ieee80211_sub_if_data
*sdata
,
4339 struct cfg80211_bss
*cbss
, bool assoc
,
4342 struct ieee80211_local
*local
= sdata
->local
;
4343 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4344 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
4345 struct sta_info
*new_sta
= NULL
;
4346 struct ieee80211_supported_band
*sband
;
4347 bool have_sta
= false;
4350 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
4352 if (WARN_ON(!ifmgd
->auth_data
&& !ifmgd
->assoc_data
))
4355 /* If a reconfig is happening, bail out */
4356 if (local
->in_reconfig
)
4361 have_sta
= sta_info_get(sdata
, cbss
->bssid
);
4366 new_sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
4372 * Set up the information for the new channel before setting the
4373 * new channel. We can't - completely race-free - change the basic
4374 * rates bitmap and the channel (sband) that it refers to, but if
4375 * we set it up before we at least avoid calling into the driver's
4376 * bss_info_changed() method with invalid information (since we do
4377 * call that from changing the channel - only for IDLE and perhaps
4378 * some others, but ...).
4380 * So to avoid that, just set up all the new information before the
4381 * channel, but tell the driver to apply it only afterwards, since
4382 * it might need the new channel for that.
4385 u32 rates
= 0, basic_rates
= 0;
4386 bool have_higher_than_11mbit
;
4387 int min_rate
= INT_MAX
, min_rate_index
= -1;
4388 const struct cfg80211_bss_ies
*ies
;
4389 int shift
= ieee80211_vif_get_shift(&sdata
->vif
);
4391 ieee80211_get_rates(sband
, bss
->supp_rates
,
4392 bss
->supp_rates_len
,
4393 &rates
, &basic_rates
,
4394 &have_higher_than_11mbit
,
4395 &min_rate
, &min_rate_index
,
4399 * This used to be a workaround for basic rates missing
4400 * in the association response frame. Now that we no
4401 * longer use the basic rates from there, it probably
4402 * doesn't happen any more, but keep the workaround so
4403 * in case some *other* APs are buggy in different ways
4404 * we can connect -- with a warning.
4406 if (!basic_rates
&& min_rate_index
>= 0) {
4408 "No basic rates, using min rate instead\n");
4409 basic_rates
= BIT(min_rate_index
);
4412 new_sta
->sta
.supp_rates
[cbss
->channel
->band
] = rates
;
4413 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
4415 /* cf. IEEE 802.11 9.2.12 */
4416 if (cbss
->channel
->band
== NL80211_BAND_2GHZ
&&
4417 have_higher_than_11mbit
)
4418 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
4420 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
4422 memcpy(ifmgd
->bssid
, cbss
->bssid
, ETH_ALEN
);
4424 /* set timing information */
4425 sdata
->vif
.bss_conf
.beacon_int
= cbss
->beacon_interval
;
4427 ies
= rcu_dereference(cbss
->beacon_ies
);
4431 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4432 sdata
->vif
.bss_conf
.sync_device_ts
=
4433 bss
->device_ts_beacon
;
4434 tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4435 ies
->data
, ies
->len
);
4436 if (tim_ie
&& tim_ie
[1] >= 2)
4437 sdata
->vif
.bss_conf
.sync_dtim_count
= tim_ie
[2];
4439 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4440 } else if (!ieee80211_hw_check(&sdata
->local
->hw
,
4441 TIMING_BEACON_ONLY
)) {
4442 ies
= rcu_dereference(cbss
->proberesp_ies
);
4443 /* must be non-NULL since beacon IEs were NULL */
4444 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
4445 sdata
->vif
.bss_conf
.sync_device_ts
=
4446 bss
->device_ts_presp
;
4447 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4449 sdata
->vif
.bss_conf
.sync_tsf
= 0;
4450 sdata
->vif
.bss_conf
.sync_device_ts
= 0;
4451 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
4456 if (new_sta
|| override
) {
4457 err
= ieee80211_prep_channel(sdata
, cbss
);
4460 sta_info_free(local
, new_sta
);
4467 * tell driver about BSSID, basic rates and timing
4468 * this was set up above, before setting the channel
4470 ieee80211_bss_info_change_notify(sdata
,
4471 BSS_CHANGED_BSSID
| BSS_CHANGED_BASIC_RATES
|
4472 BSS_CHANGED_BEACON_INT
);
4475 sta_info_pre_move_state(new_sta
, IEEE80211_STA_AUTH
);
4477 err
= sta_info_insert(new_sta
);
4481 "failed to insert STA entry for the AP (error %d)\n",
4486 WARN_ON_ONCE(!ether_addr_equal(ifmgd
->bssid
, cbss
->bssid
));
4488 /* Cancel scan to ensure that nothing interferes with connection */
4489 if (local
->scanning
)
4490 ieee80211_scan_cancel(local
);
4496 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
4497 struct cfg80211_auth_request
*req
)
4499 struct ieee80211_local
*local
= sdata
->local
;
4500 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4501 struct ieee80211_mgd_auth_data
*auth_data
;
4505 /* prepare auth data structure */
4507 switch (req
->auth_type
) {
4508 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
4509 auth_alg
= WLAN_AUTH_OPEN
;
4511 case NL80211_AUTHTYPE_SHARED_KEY
:
4512 if (IS_ERR(local
->wep_tx_tfm
))
4514 auth_alg
= WLAN_AUTH_SHARED_KEY
;
4516 case NL80211_AUTHTYPE_FT
:
4517 auth_alg
= WLAN_AUTH_FT
;
4519 case NL80211_AUTHTYPE_NETWORK_EAP
:
4520 auth_alg
= WLAN_AUTH_LEAP
;
4522 case NL80211_AUTHTYPE_SAE
:
4523 auth_alg
= WLAN_AUTH_SAE
;
4525 case NL80211_AUTHTYPE_FILS_SK
:
4526 auth_alg
= WLAN_AUTH_FILS_SK
;
4528 case NL80211_AUTHTYPE_FILS_SK_PFS
:
4529 auth_alg
= WLAN_AUTH_FILS_SK_PFS
;
4531 case NL80211_AUTHTYPE_FILS_PK
:
4532 auth_alg
= WLAN_AUTH_FILS_PK
;
4538 auth_data
= kzalloc(sizeof(*auth_data
) + req
->auth_data_len
+
4539 req
->ie_len
, GFP_KERNEL
);
4543 auth_data
->bss
= req
->bss
;
4545 if (req
->auth_data_len
>= 4) {
4546 if (req
->auth_type
== NL80211_AUTHTYPE_SAE
) {
4547 __le16
*pos
= (__le16
*) req
->auth_data
;
4549 auth_data
->sae_trans
= le16_to_cpu(pos
[0]);
4550 auth_data
->sae_status
= le16_to_cpu(pos
[1]);
4552 memcpy(auth_data
->data
, req
->auth_data
+ 4,
4553 req
->auth_data_len
- 4);
4554 auth_data
->data_len
+= req
->auth_data_len
- 4;
4557 if (req
->ie
&& req
->ie_len
) {
4558 memcpy(&auth_data
->data
[auth_data
->data_len
],
4559 req
->ie
, req
->ie_len
);
4560 auth_data
->data_len
+= req
->ie_len
;
4563 if (req
->key
&& req
->key_len
) {
4564 auth_data
->key_len
= req
->key_len
;
4565 auth_data
->key_idx
= req
->key_idx
;
4566 memcpy(auth_data
->key
, req
->key
, req
->key_len
);
4569 auth_data
->algorithm
= auth_alg
;
4571 /* try to authenticate/probe */
4573 if ((ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) ||
4574 ifmgd
->assoc_data
) {
4579 if (ifmgd
->auth_data
)
4580 ieee80211_destroy_auth_data(sdata
, false);
4582 /* prep auth_data so we don't go into idle on disassoc */
4583 ifmgd
->auth_data
= auth_data
;
4585 if (ifmgd
->associated
) {
4586 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4589 "disconnect from AP %pM for new auth to %pM\n",
4590 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
4591 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4592 WLAN_REASON_UNSPECIFIED
,
4595 ieee80211_report_disconnect(sdata
, frame_buf
,
4596 sizeof(frame_buf
), true,
4597 WLAN_REASON_UNSPECIFIED
);
4600 sdata_info(sdata
, "authenticate with %pM\n", req
->bss
->bssid
);
4602 err
= ieee80211_prep_connection(sdata
, req
->bss
, false, false);
4606 err
= ieee80211_auth(sdata
);
4608 sta_info_destroy_addr(sdata
, req
->bss
->bssid
);
4612 /* hold our own reference */
4613 cfg80211_ref_bss(local
->hw
.wiphy
, auth_data
->bss
);
4617 eth_zero_addr(ifmgd
->bssid
);
4618 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
4619 ifmgd
->auth_data
= NULL
;
4620 mutex_lock(&sdata
->local
->mtx
);
4621 ieee80211_vif_release_channel(sdata
);
4622 mutex_unlock(&sdata
->local
->mtx
);
4628 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
4629 struct cfg80211_assoc_request
*req
)
4631 struct ieee80211_local
*local
= sdata
->local
;
4632 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4633 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
4634 struct ieee80211_mgd_assoc_data
*assoc_data
;
4635 const struct cfg80211_bss_ies
*beacon_ies
;
4636 struct ieee80211_supported_band
*sband
;
4637 const u8
*ssidie
, *ht_ie
, *vht_ie
;
4639 bool override
= false;
4641 assoc_data
= kzalloc(sizeof(*assoc_data
) + req
->ie_len
, GFP_KERNEL
);
4646 ssidie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
4652 memcpy(assoc_data
->ssid
, ssidie
+ 2, ssidie
[1]);
4653 assoc_data
->ssid_len
= ssidie
[1];
4656 if (ifmgd
->associated
) {
4657 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4660 "disconnect from AP %pM for new assoc to %pM\n",
4661 ifmgd
->associated
->bssid
, req
->bss
->bssid
);
4662 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4663 WLAN_REASON_UNSPECIFIED
,
4666 ieee80211_report_disconnect(sdata
, frame_buf
,
4667 sizeof(frame_buf
), true,
4668 WLAN_REASON_UNSPECIFIED
);
4671 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) {
4676 if (ifmgd
->assoc_data
) {
4681 if (ifmgd
->auth_data
) {
4684 /* keep sta info, bssid if matching */
4685 match
= ether_addr_equal(ifmgd
->bssid
, req
->bss
->bssid
);
4686 ieee80211_destroy_auth_data(sdata
, match
);
4689 /* prepare assoc data */
4691 ifmgd
->beacon_crc_valid
= false;
4693 assoc_data
->wmm
= bss
->wmm_used
&&
4694 (local
->hw
.queues
>= IEEE80211_NUM_ACS
);
4697 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4698 * We still associate in non-HT mode (11a/b/g) if any one of these
4699 * ciphers is configured as pairwise.
4700 * We can set this to true for non-11n hardware, that'll be checked
4701 * separately along with the peer capabilities.
4703 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++) {
4704 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
4705 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
4706 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
) {
4707 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4708 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4709 netdev_info(sdata
->dev
,
4710 "disabling HT/VHT due to WEP/TKIP use\n");
4714 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4715 sband
= local
->hw
.wiphy
->bands
[req
->bss
->channel
->band
];
4716 if (!sband
->ht_cap
.ht_supported
||
4717 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4718 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4719 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4720 if (!bss
->wmm_used
&&
4721 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4722 netdev_info(sdata
->dev
,
4723 "disabling HT as WMM/QoS is not supported by the AP\n");
4726 /* disable VHT if we don't support it or the AP doesn't use WMM */
4727 if (!sband
->vht_cap
.vht_supported
||
4728 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4729 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4730 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4731 if (!bss
->wmm_used
&&
4732 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4733 netdev_info(sdata
->dev
,
4734 "disabling VHT as WMM/QoS is not supported by the AP\n");
4737 memcpy(&ifmgd
->ht_capa
, &req
->ht_capa
, sizeof(ifmgd
->ht_capa
));
4738 memcpy(&ifmgd
->ht_capa_mask
, &req
->ht_capa_mask
,
4739 sizeof(ifmgd
->ht_capa_mask
));
4741 memcpy(&ifmgd
->vht_capa
, &req
->vht_capa
, sizeof(ifmgd
->vht_capa
));
4742 memcpy(&ifmgd
->vht_capa_mask
, &req
->vht_capa_mask
,
4743 sizeof(ifmgd
->vht_capa_mask
));
4745 if (req
->ie
&& req
->ie_len
) {
4746 memcpy(assoc_data
->ie
, req
->ie
, req
->ie_len
);
4747 assoc_data
->ie_len
= req
->ie_len
;
4750 if (req
->fils_kek
) {
4751 /* should already be checked in cfg80211 - so warn */
4752 if (WARN_ON(req
->fils_kek_len
> FILS_MAX_KEK_LEN
)) {
4756 memcpy(assoc_data
->fils_kek
, req
->fils_kek
,
4758 assoc_data
->fils_kek_len
= req
->fils_kek_len
;
4761 if (req
->fils_nonces
)
4762 memcpy(assoc_data
->fils_nonces
, req
->fils_nonces
,
4763 2 * FILS_NONCE_LEN
);
4765 assoc_data
->bss
= req
->bss
;
4767 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
4768 if (ifmgd
->powersave
)
4769 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
4771 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4773 sdata
->smps_mode
= ifmgd
->req_smps
;
4775 assoc_data
->capability
= req
->bss
->capability
;
4776 assoc_data
->supp_rates
= bss
->supp_rates
;
4777 assoc_data
->supp_rates_len
= bss
->supp_rates_len
;
4780 ht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_OPERATION
);
4781 if (ht_ie
&& ht_ie
[1] >= sizeof(struct ieee80211_ht_operation
))
4782 assoc_data
->ap_ht_param
=
4783 ((struct ieee80211_ht_operation
*)(ht_ie
+ 2))->ht_param
;
4785 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4786 vht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_VHT_CAPABILITY
);
4787 if (vht_ie
&& vht_ie
[1] >= sizeof(struct ieee80211_vht_cap
))
4788 memcpy(&assoc_data
->ap_vht_cap
, vht_ie
+ 2,
4789 sizeof(struct ieee80211_vht_cap
));
4791 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4794 if (WARN((sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
) &&
4795 ieee80211_hw_check(&local
->hw
, PS_NULLFUNC_STACK
),
4796 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
4797 sdata
->vif
.driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
4799 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
4800 (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_UAPSD
)) {
4801 assoc_data
->uapsd
= true;
4802 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
4804 assoc_data
->uapsd
= false;
4805 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
4808 if (req
->prev_bssid
)
4809 memcpy(assoc_data
->prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
4812 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
4813 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
4815 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
4816 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
4819 if (req
->flags
& ASSOC_REQ_USE_RRM
)
4820 ifmgd
->flags
|= IEEE80211_STA_ENABLE_RRM
;
4822 ifmgd
->flags
&= ~IEEE80211_STA_ENABLE_RRM
;
4824 if (req
->crypto
.control_port
)
4825 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
4827 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
4829 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
4830 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
4831 sdata
->encrypt_headroom
= ieee80211_cs_headroom(local
, &req
->crypto
,
4834 /* kick off associate process */
4836 ifmgd
->assoc_data
= assoc_data
;
4837 ifmgd
->dtim_period
= 0;
4838 ifmgd
->have_beacon
= false;
4840 /* override HT/VHT configuration only if the AP and we support it */
4841 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
4842 struct ieee80211_sta_ht_cap sta_ht_cap
;
4844 if (req
->flags
& ASSOC_REQ_DISABLE_HT
)
4847 memcpy(&sta_ht_cap
, &sband
->ht_cap
, sizeof(sta_ht_cap
));
4848 ieee80211_apply_htcap_overrides(sdata
, &sta_ht_cap
);
4850 /* check for 40 MHz disable override */
4851 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
) &&
4852 sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
&&
4853 !(sta_ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
4856 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
4857 req
->flags
& ASSOC_REQ_DISABLE_VHT
)
4861 if (req
->flags
& ASSOC_REQ_DISABLE_HT
) {
4862 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4863 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4866 if (req
->flags
& ASSOC_REQ_DISABLE_VHT
)
4867 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4869 err
= ieee80211_prep_connection(sdata
, req
->bss
, true, override
);
4874 beacon_ies
= rcu_dereference(req
->bss
->beacon_ies
);
4876 if (ieee80211_hw_check(&sdata
->local
->hw
, NEED_DTIM_BEFORE_ASSOC
) &&
4879 * Wait up to one beacon interval ...
4880 * should this be more if we miss one?
4882 sdata_info(sdata
, "waiting for beacon from %pM\n",
4884 assoc_data
->timeout
= TU_TO_EXP_TIME(req
->bss
->beacon_interval
);
4885 assoc_data
->timeout_started
= true;
4886 assoc_data
->need_beacon
= true;
4887 } else if (beacon_ies
) {
4888 const u8
*tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4893 if (tim_ie
&& tim_ie
[1] >= sizeof(struct ieee80211_tim_ie
)) {
4894 const struct ieee80211_tim_ie
*tim
;
4895 tim
= (void *)(tim_ie
+ 2);
4896 ifmgd
->dtim_period
= tim
->dtim_period
;
4897 dtim_count
= tim
->dtim_count
;
4899 ifmgd
->have_beacon
= true;
4900 assoc_data
->timeout
= jiffies
;
4901 assoc_data
->timeout_started
= true;
4903 if (ieee80211_hw_check(&local
->hw
, TIMING_BEACON_ONLY
)) {
4904 sdata
->vif
.bss_conf
.sync_tsf
= beacon_ies
->tsf
;
4905 sdata
->vif
.bss_conf
.sync_device_ts
=
4906 bss
->device_ts_beacon
;
4907 sdata
->vif
.bss_conf
.sync_dtim_count
= dtim_count
;
4910 assoc_data
->timeout
= jiffies
;
4911 assoc_data
->timeout_started
= true;
4915 run_again(sdata
, assoc_data
->timeout
);
4917 if (bss
->corrupt_data
) {
4918 char *corrupt_type
= "data";
4919 if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_BEACON
) {
4920 if (bss
->corrupt_data
&
4921 IEEE80211_BSS_CORRUPT_PROBE_RESP
)
4922 corrupt_type
= "beacon and probe response";
4924 corrupt_type
= "beacon";
4925 } else if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_PROBE_RESP
)
4926 corrupt_type
= "probe response";
4927 sdata_info(sdata
, "associating with AP with corrupt %s\n",
4933 eth_zero_addr(ifmgd
->bssid
);
4934 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
4935 ifmgd
->assoc_data
= NULL
;
4941 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
4942 struct cfg80211_deauth_request
*req
)
4944 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4945 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4946 bool tx
= !req
->local_state_change
;
4948 if (ifmgd
->auth_data
&&
4949 ether_addr_equal(ifmgd
->auth_data
->bss
->bssid
, req
->bssid
)) {
4951 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
4952 req
->bssid
, req
->reason_code
,
4953 ieee80211_get_reason_code_string(req
->reason_code
));
4955 drv_mgd_prepare_tx(sdata
->local
, sdata
);
4956 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
4957 IEEE80211_STYPE_DEAUTH
,
4958 req
->reason_code
, tx
,
4960 ieee80211_destroy_auth_data(sdata
, false);
4961 ieee80211_report_disconnect(sdata
, frame_buf
,
4962 sizeof(frame_buf
), true,
4968 if (ifmgd
->assoc_data
&&
4969 ether_addr_equal(ifmgd
->assoc_data
->bss
->bssid
, req
->bssid
)) {
4971 "aborting association with %pM by local choice (Reason: %u=%s)\n",
4972 req
->bssid
, req
->reason_code
,
4973 ieee80211_get_reason_code_string(req
->reason_code
));
4975 drv_mgd_prepare_tx(sdata
->local
, sdata
);
4976 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
4977 IEEE80211_STYPE_DEAUTH
,
4978 req
->reason_code
, tx
,
4980 ieee80211_destroy_assoc_data(sdata
, false, true);
4981 ieee80211_report_disconnect(sdata
, frame_buf
,
4982 sizeof(frame_buf
), true,
4987 if (ifmgd
->associated
&&
4988 ether_addr_equal(ifmgd
->associated
->bssid
, req
->bssid
)) {
4990 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
4991 req
->bssid
, req
->reason_code
,
4992 ieee80211_get_reason_code_string(req
->reason_code
));
4994 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4995 req
->reason_code
, tx
, frame_buf
);
4996 ieee80211_report_disconnect(sdata
, frame_buf
,
4997 sizeof(frame_buf
), true,
5005 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
5006 struct cfg80211_disassoc_request
*req
)
5008 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5010 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
5013 * cfg80211 should catch this ... but it's racy since
5014 * we can receive a disassoc frame, process it, hand it
5015 * to cfg80211 while that's in a locked section already
5016 * trying to tell us that the user wants to disconnect.
5018 if (ifmgd
->associated
!= req
->bss
)
5022 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5023 req
->bss
->bssid
, req
->reason_code
, ieee80211_get_reason_code_string(req
->reason_code
));
5025 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
5026 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DISASSOC
,
5027 req
->reason_code
, !req
->local_state_change
,
5030 ieee80211_report_disconnect(sdata
, frame_buf
, sizeof(frame_buf
), true,
5036 void ieee80211_mgd_stop(struct ieee80211_sub_if_data
*sdata
)
5038 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
5041 * Make sure some work items will not run after this,
5042 * they will not do anything but might not have been
5043 * cancelled when disconnecting.
5045 cancel_work_sync(&ifmgd
->monitor_work
);
5046 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
5047 cancel_work_sync(&ifmgd
->request_smps_work
);
5048 cancel_work_sync(&ifmgd
->csa_connection_drop_work
);
5049 cancel_work_sync(&ifmgd
->chswitch_work
);
5050 cancel_delayed_work_sync(&ifmgd
->tdls_peer_del_work
);
5053 if (ifmgd
->assoc_data
) {
5054 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
5055 ieee80211_destroy_assoc_data(sdata
, false, false);
5056 cfg80211_assoc_timeout(sdata
->dev
, bss
);
5058 if (ifmgd
->auth_data
)
5059 ieee80211_destroy_auth_data(sdata
, false);
5060 spin_lock_bh(&ifmgd
->teardown_lock
);
5061 if (ifmgd
->teardown_skb
) {
5062 kfree_skb(ifmgd
->teardown_skb
);
5063 ifmgd
->teardown_skb
= NULL
;
5064 ifmgd
->orig_teardown_skb
= NULL
;
5066 spin_unlock_bh(&ifmgd
->teardown_lock
);
5067 del_timer_sync(&ifmgd
->timer
);
5068 sdata_unlock(sdata
);
5071 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
5072 enum nl80211_cqm_rssi_threshold_event rssi_event
,
5076 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5078 trace_api_cqm_rssi_notify(sdata
, rssi_event
, rssi_level
);
5080 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, rssi_level
, gfp
);
5082 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);
5084 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif
*vif
, gfp_t gfp
)
5086 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
5088 trace_api_cqm_beacon_loss_notify(sdata
->local
, sdata
);
5090 cfg80211_cqm_beacon_loss_notify(sdata
->dev
, gfp
);
5092 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify
);