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>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/delay.h>
15 #include <linux/if_ether.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/etherdevice.h>
19 #include <linux/moduleparam.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/pm_qos.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
33 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
34 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
35 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
36 #define IEEE80211_AUTH_MAX_TRIES 3
37 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
38 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
39 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
40 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
41 #define IEEE80211_ASSOC_MAX_TRIES 3
43 static int max_nullfunc_tries
= 2;
44 module_param(max_nullfunc_tries
, int, 0644);
45 MODULE_PARM_DESC(max_nullfunc_tries
,
46 "Maximum nullfunc tx tries before disconnecting (reason 4).");
48 static int max_probe_tries
= 5;
49 module_param(max_probe_tries
, int, 0644);
50 MODULE_PARM_DESC(max_probe_tries
,
51 "Maximum probe tries before disconnecting (reason 4).");
54 * Beacon loss timeout is calculated as N frames times the
55 * advertised beacon interval. This may need to be somewhat
56 * higher than what hardware might detect to account for
57 * delays in the host processing frames. But since we also
58 * probe on beacon miss before declaring the connection lost
59 * default to what we want.
61 static int beacon_loss_count
= 7;
62 module_param(beacon_loss_count
, int, 0644);
63 MODULE_PARM_DESC(beacon_loss_count
,
64 "Number of beacon intervals before we decide beacon was lost.");
67 * Time the connection can be idle before we probe
68 * it to see if we can still talk to the AP.
70 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
72 * Time we wait for a probe response after sending
73 * a probe request because of beacon loss or for
74 * checking the connection still works.
76 static int probe_wait_ms
= 500;
77 module_param(probe_wait_ms
, int, 0644);
78 MODULE_PARM_DESC(probe_wait_ms
,
79 "Maximum time(ms) to wait for probe response"
80 " before disconnecting (reason 4).");
83 * Weight given to the latest Beacon frame when calculating average signal
84 * strength for Beacon frames received in the current BSS. This must be
87 #define IEEE80211_SIGNAL_AVE_WEIGHT 3
90 * How many Beacon frames need to have been used in average signal strength
91 * before starting to indicate signal change events.
93 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
96 * We can have multiple work items (and connection probing)
97 * scheduling this timer, but we need to take care to only
98 * reschedule it when it should fire _earlier_ than it was
99 * asked for before, or if it's not pending right now. This
100 * function ensures that. Note that it then is required to
101 * run this function for all timeouts after the first one
102 * has happened -- the work that runs from this timer will
105 static void run_again(struct ieee80211_sub_if_data
*sdata
,
106 unsigned long timeout
)
108 sdata_assert_lock(sdata
);
110 if (!timer_pending(&sdata
->u
.mgd
.timer
) ||
111 time_before(timeout
, sdata
->u
.mgd
.timer
.expires
))
112 mod_timer(&sdata
->u
.mgd
.timer
, timeout
);
115 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
117 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_BEACON_FILTER
)
120 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
123 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
124 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
127 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
129 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
131 if (unlikely(!sdata
->u
.mgd
.associated
))
134 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
137 mod_timer(&sdata
->u
.mgd
.conn_mon_timer
,
138 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
140 ifmgd
->probe_send_count
= 0;
143 static int ecw2cw(int ecw
)
145 return (1 << ecw
) - 1;
149 ieee80211_determine_chantype(struct ieee80211_sub_if_data
*sdata
,
150 struct ieee80211_supported_band
*sband
,
151 struct ieee80211_channel
*channel
,
152 const struct ieee80211_ht_operation
*ht_oper
,
153 const struct ieee80211_vht_operation
*vht_oper
,
154 struct cfg80211_chan_def
*chandef
, bool tracking
)
156 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
157 struct cfg80211_chan_def vht_chandef
;
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
|| !sband
->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 (sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) {
193 switch (ht_oper
->ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
194 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
195 chandef
->width
= NL80211_CHAN_WIDTH_40
;
196 chandef
->center_freq1
+= 10;
198 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
199 chandef
->width
= NL80211_CHAN_WIDTH_40
;
200 chandef
->center_freq1
-= 10;
204 /* 40 MHz (and 80 MHz) must be supported for VHT */
205 ret
= IEEE80211_STA_DISABLE_VHT
;
206 /* also mark 40 MHz disabled */
207 ret
|= IEEE80211_STA_DISABLE_40MHZ
;
211 if (!vht_oper
|| !sband
->vht_cap
.vht_supported
) {
212 ret
= IEEE80211_STA_DISABLE_VHT
;
216 vht_chandef
.chan
= channel
;
217 vht_chandef
.center_freq1
=
218 ieee80211_channel_to_frequency(vht_oper
->center_freq_seg1_idx
,
220 vht_chandef
.center_freq2
= 0;
222 switch (vht_oper
->chan_width
) {
223 case IEEE80211_VHT_CHANWIDTH_USE_HT
:
224 vht_chandef
.width
= chandef
->width
;
226 case IEEE80211_VHT_CHANWIDTH_80MHZ
:
227 vht_chandef
.width
= NL80211_CHAN_WIDTH_80
;
229 case IEEE80211_VHT_CHANWIDTH_160MHZ
:
230 vht_chandef
.width
= NL80211_CHAN_WIDTH_160
;
232 case IEEE80211_VHT_CHANWIDTH_80P80MHZ
:
233 vht_chandef
.width
= NL80211_CHAN_WIDTH_80P80
;
234 vht_chandef
.center_freq2
=
235 ieee80211_channel_to_frequency(
236 vht_oper
->center_freq_seg2_idx
,
240 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
242 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
243 vht_oper
->chan_width
);
244 ret
= IEEE80211_STA_DISABLE_VHT
;
248 if (!cfg80211_chandef_valid(&vht_chandef
)) {
249 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
251 "AP VHT information is invalid, disable VHT\n");
252 ret
= IEEE80211_STA_DISABLE_VHT
;
256 if (cfg80211_chandef_identical(chandef
, &vht_chandef
)) {
261 if (!cfg80211_chandef_compatible(chandef
, &vht_chandef
)) {
262 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
264 "AP VHT information doesn't match HT, disable VHT\n");
265 ret
= IEEE80211_STA_DISABLE_VHT
;
269 *chandef
= vht_chandef
;
274 /* don't print the message below for VHT mismatch if VHT is disabled */
275 if (ret
& IEEE80211_STA_DISABLE_VHT
)
276 vht_chandef
= *chandef
;
279 * Ignore the DISABLED flag when we're already connected and only
280 * tracking the APs beacon for bandwidth changes - otherwise we
281 * might get disconnected here if we connect to an AP, update our
282 * regulatory information based on the AP's country IE and the
283 * information we have is wrong/outdated and disables the channel
284 * that we're actually using for the connection to the AP.
286 while (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
288 IEEE80211_CHAN_DISABLED
)) {
289 if (WARN_ON(chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
)) {
290 ret
= IEEE80211_STA_DISABLE_HT
|
291 IEEE80211_STA_DISABLE_VHT
;
295 ret
|= ieee80211_chandef_downgrade(chandef
);
298 if (chandef
->width
!= vht_chandef
.width
&& !tracking
)
300 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
302 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef
));
306 static int ieee80211_config_bw(struct ieee80211_sub_if_data
*sdata
,
307 struct sta_info
*sta
,
308 const struct ieee80211_ht_operation
*ht_oper
,
309 const struct ieee80211_vht_operation
*vht_oper
,
310 const u8
*bssid
, u32
*changed
)
312 struct ieee80211_local
*local
= sdata
->local
;
313 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
314 struct ieee80211_supported_band
*sband
;
315 struct ieee80211_channel
*chan
;
316 struct cfg80211_chan_def chandef
;
319 enum ieee80211_sta_rx_bandwidth new_sta_bw
;
322 /* if HT was/is disabled, don't track any bandwidth changes */
323 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
|| !ht_oper
)
326 /* don't check VHT if we associated as non-VHT station */
327 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
330 if (WARN_ON_ONCE(!sta
))
334 * if bss configuration changed store the new one -
335 * this may be applicable even if channel is identical
337 ht_opmode
= le16_to_cpu(ht_oper
->operation_mode
);
338 if (sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
) {
339 *changed
|= BSS_CHANGED_HT
;
340 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
343 chan
= sdata
->vif
.bss_conf
.chandef
.chan
;
344 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
346 /* calculate new channel (type) based on HT/VHT operation IEs */
347 flags
= ieee80211_determine_chantype(sdata
, sband
, chan
, ht_oper
,
348 vht_oper
, &chandef
, true);
351 * Downgrade the new channel if we associated with restricted
352 * capabilities. For example, if we associated as a 20 MHz STA
353 * to a 40 MHz AP (due to regulatory, capabilities or config
354 * reasons) then switching to a 40 MHz channel now won't do us
355 * any good -- we couldn't use it with the AP.
357 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_80P80MHZ
&&
358 chandef
.width
== NL80211_CHAN_WIDTH_80P80
)
359 flags
|= ieee80211_chandef_downgrade(&chandef
);
360 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_160MHZ
&&
361 chandef
.width
== NL80211_CHAN_WIDTH_160
)
362 flags
|= ieee80211_chandef_downgrade(&chandef
);
363 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_40MHZ
&&
364 chandef
.width
> NL80211_CHAN_WIDTH_20
)
365 flags
|= ieee80211_chandef_downgrade(&chandef
);
367 if (cfg80211_chandef_identical(&chandef
, &sdata
->vif
.bss_conf
.chandef
))
371 "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
372 ifmgd
->bssid
, chandef
.chan
->center_freq
, chandef
.width
,
373 chandef
.center_freq1
, chandef
.center_freq2
);
375 if (flags
!= (ifmgd
->flags
& (IEEE80211_STA_DISABLE_HT
|
376 IEEE80211_STA_DISABLE_VHT
|
377 IEEE80211_STA_DISABLE_40MHZ
|
378 IEEE80211_STA_DISABLE_80P80MHZ
|
379 IEEE80211_STA_DISABLE_160MHZ
)) ||
380 !cfg80211_chandef_valid(&chandef
)) {
382 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
387 switch (chandef
.width
) {
388 case NL80211_CHAN_WIDTH_20_NOHT
:
389 case NL80211_CHAN_WIDTH_20
:
390 new_sta_bw
= IEEE80211_STA_RX_BW_20
;
392 case NL80211_CHAN_WIDTH_40
:
393 new_sta_bw
= IEEE80211_STA_RX_BW_40
;
395 case NL80211_CHAN_WIDTH_80
:
396 new_sta_bw
= IEEE80211_STA_RX_BW_80
;
398 case NL80211_CHAN_WIDTH_80P80
:
399 case NL80211_CHAN_WIDTH_160
:
400 new_sta_bw
= IEEE80211_STA_RX_BW_160
;
406 if (new_sta_bw
> sta
->cur_max_bandwidth
)
407 new_sta_bw
= sta
->cur_max_bandwidth
;
409 if (new_sta_bw
< sta
->sta
.bandwidth
) {
410 sta
->sta
.bandwidth
= new_sta_bw
;
411 rate_control_rate_update(local
, sband
, sta
,
412 IEEE80211_RC_BW_CHANGED
);
415 ret
= ieee80211_vif_change_bandwidth(sdata
, &chandef
, changed
);
418 "AP %pM changed bandwidth to incompatible one - disconnect\n",
423 if (new_sta_bw
> sta
->sta
.bandwidth
) {
424 sta
->sta
.bandwidth
= new_sta_bw
;
425 rate_control_rate_update(local
, sband
, sta
,
426 IEEE80211_RC_BW_CHANGED
);
432 /* frame sending functions */
434 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data
*sdata
,
435 struct sk_buff
*skb
, u8 ap_ht_param
,
436 struct ieee80211_supported_band
*sband
,
437 struct ieee80211_channel
*channel
,
438 enum ieee80211_smps_mode smps
)
441 u32 flags
= channel
->flags
;
443 struct ieee80211_sta_ht_cap ht_cap
;
445 BUILD_BUG_ON(sizeof(ht_cap
) != sizeof(sband
->ht_cap
));
447 memcpy(&ht_cap
, &sband
->ht_cap
, sizeof(ht_cap
));
448 ieee80211_apply_htcap_overrides(sdata
, &ht_cap
);
450 /* determine capability flags */
453 switch (ap_ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
454 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
455 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
456 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
457 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
460 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
461 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
462 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
463 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
469 * If 40 MHz was disabled associate as though we weren't
470 * capable of 40 MHz -- some broken APs will never fall
471 * back to trying to transmit in 20 MHz.
473 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_40MHZ
) {
474 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
475 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
478 /* set SM PS mode properly */
479 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
481 case IEEE80211_SMPS_AUTOMATIC
:
482 case IEEE80211_SMPS_NUM_MODES
:
484 case IEEE80211_SMPS_OFF
:
485 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
486 IEEE80211_HT_CAP_SM_PS_SHIFT
;
488 case IEEE80211_SMPS_STATIC
:
489 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
490 IEEE80211_HT_CAP_SM_PS_SHIFT
;
492 case IEEE80211_SMPS_DYNAMIC
:
493 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
494 IEEE80211_HT_CAP_SM_PS_SHIFT
;
498 /* reserve and fill IE */
499 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
500 ieee80211_ie_build_ht_cap(pos
, &ht_cap
, cap
);
503 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data
*sdata
,
505 struct ieee80211_supported_band
*sband
,
506 struct ieee80211_vht_cap
*ap_vht_cap
)
510 struct ieee80211_sta_vht_cap vht_cap
;
511 u32 mask
, ap_bf_sts
, our_bf_sts
;
513 BUILD_BUG_ON(sizeof(vht_cap
) != sizeof(sband
->vht_cap
));
515 memcpy(&vht_cap
, &sband
->vht_cap
, sizeof(vht_cap
));
516 ieee80211_apply_vhtcap_overrides(sdata
, &vht_cap
);
518 /* determine capability flags */
521 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_80P80MHZ
) {
522 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
;
523 cap
|= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
526 if (sdata
->u
.mgd
.flags
& IEEE80211_STA_DISABLE_160MHZ
) {
527 cap
&= ~IEEE80211_VHT_CAP_SHORT_GI_160
;
528 cap
&= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ
;
532 * Some APs apparently get confused if our capabilities are better
533 * than theirs, so restrict what we advertise in the assoc request.
535 if (!(ap_vht_cap
->vht_cap_info
&
536 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
)))
537 cap
&= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE
;
539 mask
= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK
;
541 ap_bf_sts
= le32_to_cpu(ap_vht_cap
->vht_cap_info
) & mask
;
542 our_bf_sts
= cap
& mask
;
544 if (ap_bf_sts
< our_bf_sts
) {
549 /* reserve and fill IE */
550 pos
= skb_put(skb
, sizeof(struct ieee80211_vht_cap
) + 2);
551 ieee80211_ie_build_vht_cap(pos
, &vht_cap
, cap
);
554 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
)
556 struct ieee80211_local
*local
= sdata
->local
;
557 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
558 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
560 struct ieee80211_mgmt
*mgmt
;
562 size_t offset
= 0, noffset
;
563 int i
, count
, rates_len
, supp_rates_len
, shift
;
565 struct ieee80211_supported_band
*sband
;
566 struct ieee80211_chanctx_conf
*chanctx_conf
;
567 struct ieee80211_channel
*chan
;
568 u32 rate_flags
, rates
= 0;
570 sdata_assert_lock(sdata
);
573 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
574 if (WARN_ON(!chanctx_conf
)) {
578 chan
= chanctx_conf
->def
.chan
;
579 rate_flags
= ieee80211_chandef_rate_flags(&chanctx_conf
->def
);
581 sband
= local
->hw
.wiphy
->bands
[chan
->band
];
582 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
584 if (assoc_data
->supp_rates_len
) {
586 * Get all rates supported by the device and the AP as
587 * some APs don't like getting a superset of their rates
588 * in the association request (e.g. D-Link DAP 1353 in
591 rates_len
= ieee80211_parse_bitrates(&chanctx_conf
->def
, sband
,
592 assoc_data
->supp_rates
,
593 assoc_data
->supp_rates_len
,
597 * In case AP not provide any supported rates information
598 * before association, we send information element(s) with
599 * all rates that we support.
602 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
603 if ((rate_flags
& sband
->bitrates
[i
].flags
)
611 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
612 sizeof(*mgmt
) + /* bit too much but doesn't matter */
613 2 + assoc_data
->ssid_len
+ /* SSID */
614 4 + rates_len
+ /* (extended) rates */
615 4 + /* power capability */
616 2 + 2 * sband
->n_channels
+ /* supported channels */
617 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
618 2 + sizeof(struct ieee80211_vht_cap
) + /* VHT */
619 assoc_data
->ie_len
+ /* extra IEs */
625 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
627 capab
= WLAN_CAPABILITY_ESS
;
629 if (sband
->band
== IEEE80211_BAND_2GHZ
) {
630 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
631 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
632 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
633 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
636 if (assoc_data
->capability
& WLAN_CAPABILITY_PRIVACY
)
637 capab
|= WLAN_CAPABILITY_PRIVACY
;
639 if ((assoc_data
->capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
640 (local
->hw
.flags
& IEEE80211_HW_SPECTRUM_MGMT
))
641 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
643 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
645 memcpy(mgmt
->da
, assoc_data
->bss
->bssid
, ETH_ALEN
);
646 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
647 memcpy(mgmt
->bssid
, assoc_data
->bss
->bssid
, ETH_ALEN
);
649 if (!is_zero_ether_addr(assoc_data
->prev_bssid
)) {
651 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
652 IEEE80211_STYPE_REASSOC_REQ
);
653 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
654 mgmt
->u
.reassoc_req
.listen_interval
=
655 cpu_to_le16(local
->hw
.conf
.listen_interval
);
656 memcpy(mgmt
->u
.reassoc_req
.current_ap
, assoc_data
->prev_bssid
,
660 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
661 IEEE80211_STYPE_ASSOC_REQ
);
662 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
663 mgmt
->u
.assoc_req
.listen_interval
=
664 cpu_to_le16(local
->hw
.conf
.listen_interval
);
668 pos
= skb_put(skb
, 2 + assoc_data
->ssid_len
);
669 *pos
++ = WLAN_EID_SSID
;
670 *pos
++ = assoc_data
->ssid_len
;
671 memcpy(pos
, assoc_data
->ssid
, assoc_data
->ssid_len
);
673 /* add all rates which were marked to be used above */
674 supp_rates_len
= rates_len
;
675 if (supp_rates_len
> 8)
678 pos
= skb_put(skb
, supp_rates_len
+ 2);
679 *pos
++ = WLAN_EID_SUPP_RATES
;
680 *pos
++ = supp_rates_len
;
683 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
684 if (BIT(i
) & rates
) {
685 int rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
693 if (rates_len
> count
) {
694 pos
= skb_put(skb
, rates_len
- count
+ 2);
695 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
696 *pos
++ = rates_len
- count
;
698 for (i
++; i
< sband
->n_bitrates
; i
++) {
699 if (BIT(i
) & rates
) {
701 rate
= DIV_ROUND_UP(sband
->bitrates
[i
].bitrate
,
708 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
709 /* 1. power capabilities */
710 pos
= skb_put(skb
, 4);
711 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
713 *pos
++ = 0; /* min tx power */
715 *pos
++ = ieee80211_chandef_max_power(&chanctx_conf
->def
);
717 /* 2. supported channels */
718 /* TODO: get this in reg domain format */
719 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
720 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
721 *pos
++ = 2 * sband
->n_channels
;
722 for (i
= 0; i
< sband
->n_channels
; i
++) {
723 *pos
++ = ieee80211_frequency_to_channel(
724 sband
->channels
[i
].center_freq
);
725 *pos
++ = 1; /* one channel in the subband*/
729 /* if present, add any custom IEs that go before HT */
730 if (assoc_data
->ie_len
) {
731 static const u8 before_ht
[] = {
734 WLAN_EID_EXT_SUPP_RATES
,
735 WLAN_EID_PWR_CAPABILITY
,
736 WLAN_EID_SUPPORTED_CHANNELS
,
739 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
740 WLAN_EID_MOBILITY_DOMAIN
,
741 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
743 noffset
= ieee80211_ie_split(assoc_data
->ie
, assoc_data
->ie_len
,
744 before_ht
, ARRAY_SIZE(before_ht
),
746 pos
= skb_put(skb
, noffset
- offset
);
747 memcpy(pos
, assoc_data
->ie
+ offset
, noffset
- offset
);
751 if (WARN_ON_ONCE((ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
752 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)))
753 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
755 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
756 ieee80211_add_ht_ie(sdata
, skb
, assoc_data
->ap_ht_param
,
757 sband
, chan
, sdata
->smps_mode
);
759 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
760 ieee80211_add_vht_ie(sdata
, skb
, sband
,
761 &assoc_data
->ap_vht_cap
);
763 /* if present, add any custom non-vendor IEs that go after HT */
764 if (assoc_data
->ie_len
) {
765 noffset
= ieee80211_ie_split_vendor(assoc_data
->ie
,
768 pos
= skb_put(skb
, noffset
- offset
);
769 memcpy(pos
, assoc_data
->ie
+ offset
, noffset
- offset
);
773 if (assoc_data
->wmm
) {
774 if (assoc_data
->uapsd
) {
775 qos_info
= ifmgd
->uapsd_queues
;
776 qos_info
|= (ifmgd
->uapsd_max_sp_len
<<
777 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
782 pos
= skb_put(skb
, 9);
783 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
784 *pos
++ = 7; /* len */
785 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
788 *pos
++ = 2; /* WME */
789 *pos
++ = 0; /* WME info */
790 *pos
++ = 1; /* WME ver */
794 /* add any remaining custom (i.e. vendor specific here) IEs */
795 if (assoc_data
->ie_len
) {
796 noffset
= assoc_data
->ie_len
;
797 pos
= skb_put(skb
, noffset
- offset
);
798 memcpy(pos
, assoc_data
->ie
+ offset
, noffset
- offset
);
801 drv_mgd_prepare_tx(local
, sdata
);
803 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
804 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
805 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
|
806 IEEE80211_TX_INTFL_MLME_CONN_TX
;
807 ieee80211_tx_skb(sdata
, skb
);
810 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
811 struct ieee80211_sub_if_data
*sdata
)
813 struct ieee80211_pspoll
*pspoll
;
816 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
820 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
821 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
823 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
824 ieee80211_tx_skb(sdata
, skb
);
827 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
828 struct ieee80211_sub_if_data
*sdata
,
832 struct ieee80211_hdr_3addr
*nullfunc
;
833 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
835 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
);
839 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
841 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
843 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
|
844 IEEE80211_TX_INTFL_OFFCHAN_TX_OK
;
846 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
847 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_REQ_TX_STATUS
;
849 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
850 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_CTL_USE_MINRATE
;
852 ieee80211_tx_skb(sdata
, skb
);
855 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
856 struct ieee80211_sub_if_data
*sdata
)
859 struct ieee80211_hdr
*nullfunc
;
862 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
865 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
869 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
871 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 30);
872 memset(nullfunc
, 0, 30);
873 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
874 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
875 nullfunc
->frame_control
= fc
;
876 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
877 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
878 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
879 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
881 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
882 ieee80211_tx_skb(sdata
, skb
);
885 /* spectrum management related things */
886 static void ieee80211_chswitch_work(struct work_struct
*work
)
888 struct ieee80211_sub_if_data
*sdata
=
889 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
890 struct ieee80211_local
*local
= sdata
->local
;
891 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
895 if (!ieee80211_sdata_running(sdata
))
899 if (!ifmgd
->associated
)
902 mutex_lock(&local
->mtx
);
903 ret
= ieee80211_vif_change_channel(sdata
, &changed
);
904 mutex_unlock(&local
->mtx
);
907 "vif channel switch failed, disconnecting\n");
908 ieee80211_queue_work(&sdata
->local
->hw
,
909 &ifmgd
->csa_connection_drop_work
);
913 if (!local
->use_chanctx
) {
914 local
->_oper_chandef
= sdata
->csa_chandef
;
915 /* Call "hw_config" only if doing sw channel switch.
916 * Otherwise update the channel directly
918 if (!local
->ops
->channel_switch
)
919 ieee80211_hw_config(local
, 0);
921 local
->hw
.conf
.chandef
= local
->_oper_chandef
;
924 /* XXX: shouldn't really modify cfg80211-owned data! */
925 ifmgd
->associated
->channel
= sdata
->csa_chandef
.chan
;
927 /* XXX: wait for a beacon first? */
928 ieee80211_wake_queues_by_reason(&local
->hw
,
929 IEEE80211_MAX_QUEUE_MAP
,
930 IEEE80211_QUEUE_STOP_REASON_CSA
);
932 ieee80211_bss_info_change_notify(sdata
, changed
);
935 sdata
->vif
.csa_active
= false;
936 ifmgd
->flags
&= ~IEEE80211_STA_CSA_RECEIVED
;
940 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
942 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
943 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
945 trace_api_chswitch_done(sdata
, success
);
948 "driver channel switch failed, disconnecting\n");
949 ieee80211_queue_work(&sdata
->local
->hw
,
950 &ifmgd
->csa_connection_drop_work
);
952 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
955 EXPORT_SYMBOL(ieee80211_chswitch_done
);
957 static void ieee80211_chswitch_timer(unsigned long data
)
959 struct ieee80211_sub_if_data
*sdata
=
960 (struct ieee80211_sub_if_data
*) data
;
962 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->u
.mgd
.chswitch_work
);
966 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
967 u64 timestamp
, struct ieee802_11_elems
*elems
,
970 struct ieee80211_local
*local
= sdata
->local
;
971 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
972 struct cfg80211_bss
*cbss
= ifmgd
->associated
;
973 struct ieee80211_chanctx
*chanctx
;
974 enum ieee80211_band current_band
;
975 struct ieee80211_csa_ie csa_ie
;
978 sdata_assert_lock(sdata
);
986 /* disregard subsequent announcements if we are already processing */
987 if (ifmgd
->flags
& IEEE80211_STA_CSA_RECEIVED
)
990 current_band
= cbss
->channel
->band
;
991 memset(&csa_ie
, 0, sizeof(csa_ie
));
992 res
= ieee80211_parse_ch_switch_ie(sdata
, elems
, beacon
, current_band
,
994 ifmgd
->associated
->bssid
, &csa_ie
);
996 ieee80211_queue_work(&local
->hw
,
997 &ifmgd
->csa_connection_drop_work
);
1001 if (!cfg80211_chandef_usable(local
->hw
.wiphy
, &csa_ie
.chandef
,
1002 IEEE80211_CHAN_DISABLED
)) {
1004 "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1005 ifmgd
->associated
->bssid
,
1006 csa_ie
.chandef
.chan
->center_freq
,
1007 csa_ie
.chandef
.width
, csa_ie
.chandef
.center_freq1
,
1008 csa_ie
.chandef
.center_freq2
);
1009 ieee80211_queue_work(&local
->hw
,
1010 &ifmgd
->csa_connection_drop_work
);
1014 ifmgd
->flags
|= IEEE80211_STA_CSA_RECEIVED
;
1016 mutex_lock(&local
->chanctx_mtx
);
1017 if (local
->use_chanctx
) {
1018 u32 num_chanctx
= 0;
1019 list_for_each_entry(chanctx
, &local
->chanctx_list
, list
)
1022 if (num_chanctx
> 1 ||
1023 !(local
->hw
.flags
& IEEE80211_HW_CHANCTX_STA_CSA
)) {
1025 "not handling chan-switch with channel contexts\n");
1026 ieee80211_queue_work(&local
->hw
,
1027 &ifmgd
->csa_connection_drop_work
);
1028 mutex_unlock(&local
->chanctx_mtx
);
1033 if (WARN_ON(!rcu_access_pointer(sdata
->vif
.chanctx_conf
))) {
1034 ieee80211_queue_work(&local
->hw
,
1035 &ifmgd
->csa_connection_drop_work
);
1036 mutex_unlock(&local
->chanctx_mtx
);
1039 chanctx
= container_of(rcu_access_pointer(sdata
->vif
.chanctx_conf
),
1040 struct ieee80211_chanctx
, conf
);
1041 if (chanctx
->refcount
> 1) {
1043 "channel switch with multiple interfaces on the same channel, disconnecting\n");
1044 ieee80211_queue_work(&local
->hw
,
1045 &ifmgd
->csa_connection_drop_work
);
1046 mutex_unlock(&local
->chanctx_mtx
);
1049 mutex_unlock(&local
->chanctx_mtx
);
1051 sdata
->csa_chandef
= csa_ie
.chandef
;
1052 sdata
->vif
.csa_active
= true;
1055 ieee80211_stop_queues_by_reason(&local
->hw
,
1056 IEEE80211_MAX_QUEUE_MAP
,
1057 IEEE80211_QUEUE_STOP_REASON_CSA
);
1059 if (local
->ops
->channel_switch
) {
1060 /* use driver's channel switch callback */
1061 struct ieee80211_channel_switch ch_switch
= {
1062 .timestamp
= timestamp
,
1063 .block_tx
= csa_ie
.mode
,
1064 .chandef
= csa_ie
.chandef
,
1065 .count
= csa_ie
.count
,
1068 drv_channel_switch(local
, &ch_switch
);
1072 /* channel switch handled in software */
1073 if (csa_ie
.count
<= 1)
1074 ieee80211_queue_work(&local
->hw
, &ifmgd
->chswitch_work
);
1076 mod_timer(&ifmgd
->chswitch_timer
,
1077 TU_TO_EXP_TIME(csa_ie
.count
* cbss
->beacon_interval
));
1080 static u32
ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
1081 struct ieee80211_channel
*channel
,
1082 const u8
*country_ie
, u8 country_ie_len
,
1083 const u8
*pwr_constr_elem
)
1085 struct ieee80211_country_ie_triplet
*triplet
;
1086 int chan
= ieee80211_frequency_to_channel(channel
->center_freq
);
1087 int i
, chan_pwr
, chan_increment
, new_ap_level
;
1088 bool have_chan_pwr
= false;
1091 if (country_ie_len
% 2 || country_ie_len
< IEEE80211_COUNTRY_IE_MIN_LEN
)
1094 triplet
= (void *)(country_ie
+ 3);
1095 country_ie_len
-= 3;
1097 switch (channel
->band
) {
1101 case IEEE80211_BAND_2GHZ
:
1102 case IEEE80211_BAND_60GHZ
:
1105 case IEEE80211_BAND_5GHZ
:
1111 while (country_ie_len
>= 3) {
1112 u8 first_channel
= triplet
->chans
.first_channel
;
1114 if (first_channel
>= IEEE80211_COUNTRY_EXTENSION_ID
)
1117 for (i
= 0; i
< triplet
->chans
.num_channels
; i
++) {
1118 if (first_channel
+ i
* chan_increment
== chan
) {
1119 have_chan_pwr
= true;
1120 chan_pwr
= triplet
->chans
.max_power
;
1129 country_ie_len
-= 3;
1135 new_ap_level
= max_t(int, 0, chan_pwr
- *pwr_constr_elem
);
1137 if (sdata
->ap_power_level
== new_ap_level
)
1141 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1142 new_ap_level
, chan_pwr
, *pwr_constr_elem
,
1143 sdata
->u
.mgd
.bssid
);
1144 sdata
->ap_power_level
= new_ap_level
;
1145 if (__ieee80211_recalc_txpower(sdata
))
1146 return BSS_CHANGED_TXPOWER
;
1151 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
1152 struct ieee80211_sub_if_data
*sdata
)
1154 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1157 * If we are scanning right now then the parameters will
1158 * take effect when scan finishes.
1160 if (local
->scanning
)
1163 if (conf
->dynamic_ps_timeout
> 0 &&
1164 !(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)) {
1165 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1166 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
1168 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)
1169 ieee80211_send_nullfunc(local
, sdata
, 1);
1171 if ((local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) &&
1172 (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
))
1175 conf
->flags
|= IEEE80211_CONF_PS
;
1176 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1180 static void ieee80211_change_ps(struct ieee80211_local
*local
)
1182 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
1184 if (local
->ps_sdata
) {
1185 ieee80211_enable_ps(local
, local
->ps_sdata
);
1186 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
1187 conf
->flags
&= ~IEEE80211_CONF_PS
;
1188 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1189 del_timer_sync(&local
->dynamic_ps_timer
);
1190 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1194 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
1196 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
1197 struct sta_info
*sta
= NULL
;
1198 bool authorized
= false;
1200 if (!mgd
->powersave
)
1206 if (!mgd
->associated
)
1209 if (mgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1212 if (!mgd
->have_beacon
)
1216 sta
= sta_info_get(sdata
, mgd
->bssid
);
1218 authorized
= test_sta_flag(sta
, WLAN_STA_AUTHORIZED
);
1224 /* need to hold RTNL or interface lock */
1225 void ieee80211_recalc_ps(struct ieee80211_local
*local
, s32 latency
)
1227 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
1231 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
)) {
1232 local
->ps_sdata
= NULL
;
1236 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
1237 if (!ieee80211_sdata_running(sdata
))
1239 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
1240 /* If an AP vif is found, then disable PS
1241 * by setting the count to zero thereby setting
1247 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
1253 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
1257 latency
= pm_qos_request(PM_QOS_NETWORK_LATENCY
);
1259 beaconint_us
= ieee80211_tu_to_usec(
1260 found
->vif
.bss_conf
.beacon_int
);
1262 timeout
= local
->dynamic_ps_forced_timeout
;
1265 * Go to full PSM if the user configures a very low
1266 * latency requirement.
1267 * The 2000 second value is there for compatibility
1268 * until the PM_QOS_NETWORK_LATENCY is configured
1271 if (latency
> (1900 * USEC_PER_MSEC
) &&
1272 latency
!= (2000 * USEC_PER_SEC
))
1277 local
->hw
.conf
.dynamic_ps_timeout
= timeout
;
1279 if (beaconint_us
> latency
) {
1280 local
->ps_sdata
= NULL
;
1283 u8 dtimper
= found
->u
.mgd
.dtim_period
;
1285 /* If the TIM IE is invalid, pretend the value is 1 */
1288 else if (dtimper
> 1)
1289 maxslp
= min_t(int, dtimper
,
1290 latency
/ beaconint_us
);
1292 local
->hw
.conf
.max_sleep_period
= maxslp
;
1293 local
->hw
.conf
.ps_dtim_period
= dtimper
;
1294 local
->ps_sdata
= found
;
1297 local
->ps_sdata
= NULL
;
1300 ieee80211_change_ps(local
);
1303 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data
*sdata
)
1305 bool ps_allowed
= ieee80211_powersave_allowed(sdata
);
1307 if (sdata
->vif
.bss_conf
.ps
!= ps_allowed
) {
1308 sdata
->vif
.bss_conf
.ps
= ps_allowed
;
1309 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_PS
);
1313 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
1315 struct ieee80211_local
*local
=
1316 container_of(work
, struct ieee80211_local
,
1317 dynamic_ps_disable_work
);
1319 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1320 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1321 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1324 ieee80211_wake_queues_by_reason(&local
->hw
,
1325 IEEE80211_MAX_QUEUE_MAP
,
1326 IEEE80211_QUEUE_STOP_REASON_PS
);
1329 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
1331 struct ieee80211_local
*local
=
1332 container_of(work
, struct ieee80211_local
,
1333 dynamic_ps_enable_work
);
1334 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
1335 struct ieee80211_if_managed
*ifmgd
;
1336 unsigned long flags
;
1339 /* can only happen when PS was just disabled anyway */
1343 ifmgd
= &sdata
->u
.mgd
;
1345 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
1348 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1349 /* don't enter PS if TX frames are pending */
1350 if (drv_tx_frames_pending(local
)) {
1351 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1353 local
->hw
.conf
.dynamic_ps_timeout
));
1358 * transmission can be stopped by others which leads to
1359 * dynamic_ps_timer expiry. Postpone the ps timer if it
1360 * is not the actual idle state.
1362 spin_lock_irqsave(&local
->queue_stop_reason_lock
, flags
);
1363 for (q
= 0; q
< local
->hw
.queues
; q
++) {
1364 if (local
->queue_stop_reasons
[q
]) {
1365 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
,
1367 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1369 local
->hw
.conf
.dynamic_ps_timeout
));
1373 spin_unlock_irqrestore(&local
->queue_stop_reason_lock
, flags
);
1376 if ((local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) &&
1377 !(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1378 if (drv_tx_frames_pending(local
)) {
1379 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
1381 local
->hw
.conf
.dynamic_ps_timeout
));
1383 ieee80211_send_nullfunc(local
, sdata
, 1);
1384 /* Flush to get the tx status of nullfunc frame */
1385 ieee80211_flush_queues(local
, sdata
);
1389 if (!((local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) &&
1390 (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)) ||
1391 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
1392 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
1393 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
1394 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1398 void ieee80211_dynamic_ps_timer(unsigned long data
)
1400 struct ieee80211_local
*local
= (void *) data
;
1402 if (local
->quiescing
|| local
->suspended
)
1405 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
1408 void ieee80211_dfs_cac_timer_work(struct work_struct
*work
)
1410 struct delayed_work
*delayed_work
=
1411 container_of(work
, struct delayed_work
, work
);
1412 struct ieee80211_sub_if_data
*sdata
=
1413 container_of(delayed_work
, struct ieee80211_sub_if_data
,
1414 dfs_cac_timer_work
);
1415 struct cfg80211_chan_def chandef
= sdata
->vif
.bss_conf
.chandef
;
1417 mutex_lock(&sdata
->local
->mtx
);
1418 if (sdata
->wdev
.cac_started
) {
1419 ieee80211_vif_release_channel(sdata
);
1420 cfg80211_cac_event(sdata
->dev
, &chandef
,
1421 NL80211_RADAR_CAC_FINISHED
,
1424 mutex_unlock(&sdata
->local
->mtx
);
1428 static bool ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
1429 struct ieee80211_sub_if_data
*sdata
,
1430 const u8
*wmm_param
, size_t wmm_param_len
)
1432 struct ieee80211_tx_queue_params params
;
1433 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1437 u8 uapsd_queues
= 0;
1439 if (!local
->ops
->conf_tx
)
1442 if (local
->hw
.queues
< IEEE80211_NUM_ACS
)
1448 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
1451 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
1452 uapsd_queues
= ifmgd
->uapsd_queues
;
1454 count
= wmm_param
[6] & 0x0f;
1455 if (count
== ifmgd
->wmm_last_param_set
)
1457 ifmgd
->wmm_last_param_set
= count
;
1459 pos
= wmm_param
+ 8;
1460 left
= wmm_param_len
- 8;
1462 memset(¶ms
, 0, sizeof(params
));
1465 for (; left
>= 4; left
-= 4, pos
+= 4) {
1466 int aci
= (pos
[0] >> 5) & 0x03;
1467 int acm
= (pos
[0] >> 4) & 0x01;
1475 sdata
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
1476 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1482 sdata
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
1483 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1489 sdata
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
1490 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1497 sdata
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
1498 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1503 params
.aifs
= pos
[0] & 0x0f;
1504 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
1505 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
1506 params
.txop
= get_unaligned_le16(pos
+ 2);
1508 params
.uapsd
= uapsd
;
1511 "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
1513 params
.aifs
, params
.cw_min
, params
.cw_max
,
1514 params
.txop
, params
.uapsd
);
1515 sdata
->tx_conf
[queue
] = params
;
1516 if (drv_conf_tx(local
, sdata
, queue
, ¶ms
))
1518 "failed to set TX queue parameters for queue %d\n",
1522 /* enable WMM or activate new settings */
1523 sdata
->vif
.bss_conf
.qos
= true;
1527 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1529 lockdep_assert_held(&sdata
->local
->mtx
);
1531 sdata
->u
.mgd
.flags
&= ~IEEE80211_STA_CONNECTION_POLL
;
1532 ieee80211_run_deferred_scan(sdata
->local
);
1535 static void ieee80211_stop_poll(struct ieee80211_sub_if_data
*sdata
)
1537 mutex_lock(&sdata
->local
->mtx
);
1538 __ieee80211_stop_poll(sdata
);
1539 mutex_unlock(&sdata
->local
->mtx
);
1542 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
1543 u16 capab
, bool erp_valid
, u8 erp
)
1545 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1547 bool use_protection
;
1548 bool use_short_preamble
;
1549 bool use_short_slot
;
1552 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
1553 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
1555 use_protection
= false;
1556 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
1559 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
1560 if (ieee80211_get_sdata_band(sdata
) == IEEE80211_BAND_5GHZ
)
1561 use_short_slot
= true;
1563 if (use_protection
!= bss_conf
->use_cts_prot
) {
1564 bss_conf
->use_cts_prot
= use_protection
;
1565 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
1568 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
1569 bss_conf
->use_short_preamble
= use_short_preamble
;
1570 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
1573 if (use_short_slot
!= bss_conf
->use_short_slot
) {
1574 bss_conf
->use_short_slot
= use_short_slot
;
1575 changed
|= BSS_CHANGED_ERP_SLOT
;
1581 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
1582 struct cfg80211_bss
*cbss
,
1583 u32 bss_info_changed
)
1585 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
1586 struct ieee80211_local
*local
= sdata
->local
;
1587 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1589 bss_info_changed
|= BSS_CHANGED_ASSOC
;
1590 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
1591 bss_conf
->assoc_capability
, bss
->has_erp_value
, bss
->erp_value
);
1593 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
1594 beacon_loss_count
* bss_conf
->beacon_int
));
1596 sdata
->u
.mgd
.associated
= cbss
;
1597 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
1599 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
1601 if (sdata
->vif
.p2p
) {
1602 const struct cfg80211_bss_ies
*ies
;
1605 ies
= rcu_dereference(cbss
->ies
);
1609 ret
= cfg80211_get_p2p_attr(
1610 ies
->data
, ies
->len
,
1611 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
1612 (u8
*) &bss_conf
->p2p_noa_attr
,
1613 sizeof(bss_conf
->p2p_noa_attr
));
1615 sdata
->u
.mgd
.p2p_noa_index
=
1616 bss_conf
->p2p_noa_attr
.index
;
1617 bss_info_changed
|= BSS_CHANGED_P2P_PS
;
1623 /* just to be sure */
1624 ieee80211_stop_poll(sdata
);
1626 ieee80211_led_assoc(local
, 1);
1628 if (sdata
->u
.mgd
.have_beacon
) {
1630 * If the AP is buggy we may get here with no DTIM period
1631 * known, so assume it's 1 which is the only safe assumption
1632 * in that case, although if the TIM IE is broken powersave
1633 * probably just won't work at all.
1635 bss_conf
->dtim_period
= sdata
->u
.mgd
.dtim_period
?: 1;
1636 bss_conf
->beacon_rate
= bss
->beacon_rate
;
1637 bss_info_changed
|= BSS_CHANGED_BEACON_INFO
;
1639 bss_conf
->beacon_rate
= NULL
;
1640 bss_conf
->dtim_period
= 0;
1643 bss_conf
->assoc
= 1;
1645 /* Tell the driver to monitor connection quality (if supported) */
1646 if (sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
&&
1647 bss_conf
->cqm_rssi_thold
)
1648 bss_info_changed
|= BSS_CHANGED_CQM
;
1650 /* Enable ARP filtering */
1651 if (bss_conf
->arp_addr_cnt
)
1652 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
1654 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
1656 mutex_lock(&local
->iflist_mtx
);
1657 ieee80211_recalc_ps(local
, -1);
1658 mutex_unlock(&local
->iflist_mtx
);
1660 ieee80211_recalc_smps(sdata
);
1661 ieee80211_recalc_ps_vif(sdata
);
1663 netif_carrier_on(sdata
->dev
);
1666 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
1667 u16 stype
, u16 reason
, bool tx
,
1670 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1671 struct ieee80211_local
*local
= sdata
->local
;
1674 sdata_assert_lock(sdata
);
1676 if (WARN_ON_ONCE(tx
&& !frame_buf
))
1679 if (WARN_ON(!ifmgd
->associated
))
1682 ieee80211_stop_poll(sdata
);
1684 ifmgd
->associated
= NULL
;
1685 netif_carrier_off(sdata
->dev
);
1688 * if we want to get out of ps before disassoc (why?) we have
1689 * to do it before sending disassoc, as otherwise the null-packet
1692 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1693 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1694 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
1696 local
->ps_sdata
= NULL
;
1698 /* disable per-vif ps */
1699 ieee80211_recalc_ps_vif(sdata
);
1701 /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */
1703 ieee80211_flush_queues(local
, sdata
);
1705 /* deauthenticate/disassociate now */
1706 if (tx
|| frame_buf
)
1707 ieee80211_send_deauth_disassoc(sdata
, ifmgd
->bssid
, stype
,
1708 reason
, tx
, frame_buf
);
1710 /* flush out frame */
1712 ieee80211_flush_queues(local
, sdata
);
1714 /* clear bssid only after building the needed mgmt frames */
1715 memset(ifmgd
->bssid
, 0, ETH_ALEN
);
1717 /* remove AP and TDLS peers */
1718 sta_info_flush(sdata
);
1720 /* finally reset all BSS / config parameters */
1721 changed
|= ieee80211_reset_erp_info(sdata
);
1723 ieee80211_led_assoc(local
, 0);
1724 changed
|= BSS_CHANGED_ASSOC
;
1725 sdata
->vif
.bss_conf
.assoc
= false;
1727 ifmgd
->p2p_noa_index
= -1;
1728 memset(&sdata
->vif
.bss_conf
.p2p_noa_attr
, 0,
1729 sizeof(sdata
->vif
.bss_conf
.p2p_noa_attr
));
1731 /* on the next assoc, re-program HT/VHT parameters */
1732 memset(&ifmgd
->ht_capa
, 0, sizeof(ifmgd
->ht_capa
));
1733 memset(&ifmgd
->ht_capa_mask
, 0, sizeof(ifmgd
->ht_capa_mask
));
1734 memset(&ifmgd
->vht_capa
, 0, sizeof(ifmgd
->vht_capa
));
1735 memset(&ifmgd
->vht_capa_mask
, 0, sizeof(ifmgd
->vht_capa_mask
));
1737 sdata
->ap_power_level
= IEEE80211_UNSET_POWER_LEVEL
;
1739 del_timer_sync(&local
->dynamic_ps_timer
);
1740 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1742 /* Disable ARP filtering */
1743 if (sdata
->vif
.bss_conf
.arp_addr_cnt
)
1744 changed
|= BSS_CHANGED_ARP_FILTER
;
1746 sdata
->vif
.bss_conf
.qos
= false;
1747 changed
|= BSS_CHANGED_QOS
;
1749 /* The BSSID (not really interesting) and HT changed */
1750 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
1751 ieee80211_bss_info_change_notify(sdata
, changed
);
1753 /* disassociated - set to defaults now */
1754 ieee80211_set_wmm_default(sdata
, false);
1756 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
1757 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
1758 del_timer_sync(&sdata
->u
.mgd
.timer
);
1759 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
1761 sdata
->vif
.bss_conf
.dtim_period
= 0;
1762 sdata
->vif
.bss_conf
.beacon_rate
= NULL
;
1764 ifmgd
->have_beacon
= false;
1767 mutex_lock(&local
->mtx
);
1768 ieee80211_vif_release_channel(sdata
);
1769 mutex_unlock(&local
->mtx
);
1771 sdata
->encrypt_headroom
= IEEE80211_ENCRYPT_HEADROOM
;
1774 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data
*sdata
,
1775 struct ieee80211_hdr
*hdr
)
1778 * We can postpone the mgd.timer whenever receiving unicast frames
1779 * from AP because we know that the connection is working both ways
1780 * at that time. But multicast frames (and hence also beacons) must
1781 * be ignored here, because we need to trigger the timer during
1782 * data idle periods for sending the periodic probe request to the
1783 * AP we're connected to.
1785 if (is_multicast_ether_addr(hdr
->addr1
))
1788 ieee80211_sta_reset_conn_monitor(sdata
);
1791 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
1793 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1794 struct ieee80211_local
*local
= sdata
->local
;
1796 mutex_lock(&local
->mtx
);
1797 if (!(ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
))
1800 __ieee80211_stop_poll(sdata
);
1802 mutex_lock(&local
->iflist_mtx
);
1803 ieee80211_recalc_ps(local
, -1);
1804 mutex_unlock(&local
->iflist_mtx
);
1806 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
1810 * We've received a probe response, but are not sure whether
1811 * we have or will be receiving any beacons or data, so let's
1812 * schedule the timers again, just in case.
1814 ieee80211_sta_reset_beacon_monitor(sdata
);
1816 mod_timer(&ifmgd
->conn_mon_timer
,
1817 round_jiffies_up(jiffies
+
1818 IEEE80211_CONNECTION_IDLE_TIME
));
1820 mutex_unlock(&local
->mtx
);
1823 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
1824 struct ieee80211_hdr
*hdr
, bool ack
)
1826 if (!ieee80211_is_data(hdr
->frame_control
))
1829 if (ieee80211_is_nullfunc(hdr
->frame_control
) &&
1830 sdata
->u
.mgd
.probe_send_count
> 0) {
1832 ieee80211_sta_reset_conn_monitor(sdata
);
1834 sdata
->u
.mgd
.nullfunc_failed
= true;
1835 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
1840 ieee80211_sta_reset_conn_monitor(sdata
);
1843 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
1845 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1847 u8
*dst
= ifmgd
->associated
->bssid
;
1848 u8 unicast_limit
= max(1, max_probe_tries
- 3);
1851 * Try sending broadcast probe requests for the last three
1852 * probe requests after the first ones failed since some
1853 * buggy APs only support broadcast probe requests.
1855 if (ifmgd
->probe_send_count
>= unicast_limit
)
1859 * When the hardware reports an accurate Tx ACK status, it's
1860 * better to send a nullfunc frame instead of a probe request,
1861 * as it will kick us off the AP quickly if we aren't associated
1862 * anymore. The timeout will be reset if the frame is ACKed by
1865 ifmgd
->probe_send_count
++;
1867 if (sdata
->local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) {
1868 ifmgd
->nullfunc_failed
= false;
1869 ieee80211_send_nullfunc(sdata
->local
, sdata
, 0);
1874 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
1875 if (WARN_ON_ONCE(ssid
== NULL
))
1880 ieee80211_send_probe_req(sdata
, dst
, ssid
+ 2, ssid_len
, NULL
,
1881 0, (u32
) -1, true, 0,
1882 ifmgd
->associated
->channel
, false);
1886 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
1887 run_again(sdata
, ifmgd
->probe_timeout
);
1888 if (sdata
->local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
1889 ieee80211_flush_queues(sdata
->local
, sdata
);
1892 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
1895 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1896 bool already
= false;
1898 if (!ieee80211_sdata_running(sdata
))
1903 if (!ifmgd
->associated
)
1906 mutex_lock(&sdata
->local
->mtx
);
1908 if (sdata
->local
->tmp_channel
|| sdata
->local
->scanning
) {
1909 mutex_unlock(&sdata
->local
->mtx
);
1914 mlme_dbg_ratelimited(sdata
,
1915 "detected beacon loss from AP (missed %d beacons) - probing\n",
1918 ieee80211_cqm_rssi_notify(&sdata
->vif
,
1919 NL80211_CQM_RSSI_BEACON_LOSS_EVENT
,
1924 * The driver/our work has already reported this event or the
1925 * connection monitoring has kicked in and we have already sent
1926 * a probe request. Or maybe the AP died and the driver keeps
1927 * reporting until we disassociate...
1929 * In either case we have to ignore the current call to this
1930 * function (except for setting the correct probe reason bit)
1931 * because otherwise we would reset the timer every time and
1932 * never check whether we received a probe response!
1934 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
)
1937 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
1939 mutex_unlock(&sdata
->local
->mtx
);
1944 mutex_lock(&sdata
->local
->iflist_mtx
);
1945 ieee80211_recalc_ps(sdata
->local
, -1);
1946 mutex_unlock(&sdata
->local
->iflist_mtx
);
1948 ifmgd
->probe_send_count
= 0;
1949 ieee80211_mgd_probe_ap_send(sdata
);
1951 sdata_unlock(sdata
);
1954 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
1955 struct ieee80211_vif
*vif
)
1957 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1958 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1959 struct cfg80211_bss
*cbss
;
1960 struct sk_buff
*skb
;
1964 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
1967 sdata_assert_lock(sdata
);
1969 if (ifmgd
->associated
)
1970 cbss
= ifmgd
->associated
;
1971 else if (ifmgd
->auth_data
)
1972 cbss
= ifmgd
->auth_data
->bss
;
1973 else if (ifmgd
->assoc_data
)
1974 cbss
= ifmgd
->assoc_data
->bss
;
1979 ssid
= ieee80211_bss_get_ie(cbss
, WLAN_EID_SSID
);
1980 if (WARN_ON_ONCE(ssid
== NULL
))
1985 skb
= ieee80211_build_probe_req(sdata
, cbss
->bssid
,
1986 (u32
) -1, cbss
->channel
,
1993 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
1995 static void __ieee80211_disconnect(struct ieee80211_sub_if_data
*sdata
)
1997 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1998 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2001 if (!ifmgd
->associated
) {
2002 sdata_unlock(sdata
);
2006 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
2007 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2009 ifmgd
->flags
&= ~IEEE80211_STA_CSA_RECEIVED
;
2010 sdata
->vif
.csa_active
= false;
2011 ieee80211_wake_queues_by_reason(&sdata
->local
->hw
,
2012 IEEE80211_MAX_QUEUE_MAP
,
2013 IEEE80211_QUEUE_STOP_REASON_CSA
);
2015 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
2016 IEEE80211_DEAUTH_FRAME_LEN
);
2017 sdata_unlock(sdata
);
2020 static void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
2022 struct ieee80211_sub_if_data
*sdata
=
2023 container_of(work
, struct ieee80211_sub_if_data
,
2024 u
.mgd
.beacon_connection_loss_work
);
2025 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2026 struct sta_info
*sta
;
2028 if (ifmgd
->associated
) {
2030 sta
= sta_info_get(sdata
, ifmgd
->bssid
);
2032 sta
->beacon_loss_count
++;
2036 if (ifmgd
->connection_loss
) {
2037 sdata_info(sdata
, "Connection to AP %pM lost\n",
2039 __ieee80211_disconnect(sdata
);
2041 ieee80211_mgd_probe_ap(sdata
, true);
2045 static void ieee80211_csa_connection_drop_work(struct work_struct
*work
)
2047 struct ieee80211_sub_if_data
*sdata
=
2048 container_of(work
, struct ieee80211_sub_if_data
,
2049 u
.mgd
.csa_connection_drop_work
);
2051 __ieee80211_disconnect(sdata
);
2054 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
2056 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2057 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2059 trace_api_beacon_loss(sdata
);
2061 sdata
->u
.mgd
.connection_loss
= false;
2062 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2064 EXPORT_SYMBOL(ieee80211_beacon_loss
);
2066 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
2068 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2069 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
2071 trace_api_connection_loss(sdata
);
2073 sdata
->u
.mgd
.connection_loss
= true;
2074 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
2076 EXPORT_SYMBOL(ieee80211_connection_loss
);
2079 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data
*sdata
,
2082 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2084 sdata_assert_lock(sdata
);
2087 sta_info_destroy_addr(sdata
, auth_data
->bss
->bssid
);
2089 memset(sdata
->u
.mgd
.bssid
, 0, ETH_ALEN
);
2090 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2091 sdata
->u
.mgd
.flags
= 0;
2092 mutex_lock(&sdata
->local
->mtx
);
2093 ieee80211_vif_release_channel(sdata
);
2094 mutex_unlock(&sdata
->local
->mtx
);
2097 cfg80211_put_bss(sdata
->local
->hw
.wiphy
, auth_data
->bss
);
2099 sdata
->u
.mgd
.auth_data
= NULL
;
2102 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data
*sdata
,
2103 struct ieee80211_mgmt
*mgmt
, size_t len
)
2105 struct ieee80211_local
*local
= sdata
->local
;
2106 struct ieee80211_mgd_auth_data
*auth_data
= sdata
->u
.mgd
.auth_data
;
2108 struct ieee802_11_elems elems
;
2111 pos
= mgmt
->u
.auth
.variable
;
2112 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2113 if (!elems
.challenge
)
2115 auth_data
->expected_transaction
= 4;
2116 drv_mgd_prepare_tx(sdata
->local
, sdata
);
2117 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
2118 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
2119 IEEE80211_TX_INTFL_MLME_CONN_TX
;
2120 ieee80211_send_auth(sdata
, 3, auth_data
->algorithm
, 0,
2121 elems
.challenge
- 2, elems
.challenge_len
+ 2,
2122 auth_data
->bss
->bssid
, auth_data
->bss
->bssid
,
2123 auth_data
->key
, auth_data
->key_len
,
2124 auth_data
->key_idx
, tx_flags
);
2127 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data
*sdata
,
2128 struct ieee80211_mgmt
*mgmt
, size_t len
)
2130 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2132 u16 auth_alg
, auth_transaction
, status_code
;
2133 struct sta_info
*sta
;
2135 sdata_assert_lock(sdata
);
2140 if (!ifmgd
->auth_data
|| ifmgd
->auth_data
->done
)
2143 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
2145 if (!ether_addr_equal(bssid
, mgmt
->bssid
))
2148 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
2149 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
2150 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
2152 if (auth_alg
!= ifmgd
->auth_data
->algorithm
||
2153 auth_transaction
!= ifmgd
->auth_data
->expected_transaction
) {
2154 sdata_info(sdata
, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2155 mgmt
->sa
, auth_alg
, ifmgd
->auth_data
->algorithm
,
2157 ifmgd
->auth_data
->expected_transaction
);
2161 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2162 sdata_info(sdata
, "%pM denied authentication (status %d)\n",
2163 mgmt
->sa
, status_code
);
2164 ieee80211_destroy_auth_data(sdata
, false);
2165 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2169 switch (ifmgd
->auth_data
->algorithm
) {
2170 case WLAN_AUTH_OPEN
:
2171 case WLAN_AUTH_LEAP
:
2175 case WLAN_AUTH_SHARED_KEY
:
2176 if (ifmgd
->auth_data
->expected_transaction
!= 4) {
2177 ieee80211_auth_challenge(sdata
, mgmt
, len
);
2178 /* need another frame */
2183 WARN_ONCE(1, "invalid auth alg %d",
2184 ifmgd
->auth_data
->algorithm
);
2188 sdata_info(sdata
, "authenticated\n");
2189 ifmgd
->auth_data
->done
= true;
2190 ifmgd
->auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_WAIT_ASSOC
;
2191 ifmgd
->auth_data
->timeout_started
= true;
2192 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2194 if (ifmgd
->auth_data
->algorithm
== WLAN_AUTH_SAE
&&
2195 ifmgd
->auth_data
->expected_transaction
!= 2) {
2197 * Report auth frame to user space for processing since another
2198 * round of Authentication frames is still needed.
2200 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2204 /* move station state to auth */
2205 mutex_lock(&sdata
->local
->sta_mtx
);
2206 sta
= sta_info_get(sdata
, bssid
);
2208 WARN_ONCE(1, "%s: STA %pM not found", sdata
->name
, bssid
);
2211 if (sta_info_move_state(sta
, IEEE80211_STA_AUTH
)) {
2212 sdata_info(sdata
, "failed moving %pM to auth\n", bssid
);
2215 mutex_unlock(&sdata
->local
->sta_mtx
);
2217 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2220 mutex_unlock(&sdata
->local
->sta_mtx
);
2221 /* ignore frame -- wait for timeout */
2225 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
2226 struct ieee80211_mgmt
*mgmt
, size_t len
)
2228 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2229 const u8
*bssid
= NULL
;
2232 sdata_assert_lock(sdata
);
2237 if (!ifmgd
->associated
||
2238 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2241 bssid
= ifmgd
->associated
->bssid
;
2243 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
2245 sdata_info(sdata
, "deauthenticated from %pM (Reason: %u)\n",
2246 bssid
, reason_code
);
2248 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2250 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2254 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
2255 struct ieee80211_mgmt
*mgmt
, size_t len
)
2257 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2260 sdata_assert_lock(sdata
);
2265 if (!ifmgd
->associated
||
2266 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2269 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
2271 sdata_info(sdata
, "disassociated from %pM (Reason: %u)\n",
2272 mgmt
->sa
, reason_code
);
2274 ieee80211_set_disassoc(sdata
, 0, 0, false, NULL
);
2276 cfg80211_rx_mlme_mgmt(sdata
->dev
, (u8
*)mgmt
, len
);
2279 static void ieee80211_get_rates(struct ieee80211_supported_band
*sband
,
2280 u8
*supp_rates
, unsigned int supp_rates_len
,
2281 u32
*rates
, u32
*basic_rates
,
2282 bool *have_higher_than_11mbit
,
2283 int *min_rate
, int *min_rate_index
,
2284 int shift
, u32 rate_flags
)
2288 for (i
= 0; i
< supp_rates_len
; i
++) {
2289 int rate
= supp_rates
[i
] & 0x7f;
2290 bool is_basic
= !!(supp_rates
[i
] & 0x80);
2292 if ((rate
* 5 * (1 << shift
)) > 110)
2293 *have_higher_than_11mbit
= true;
2296 * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009
2297 * 7.3.2.2 as a magic value instead of a rate. Hence, skip it.
2299 * Note: Even through the membership selector and the basic
2300 * rate flag share the same bit, they are not exactly
2303 if (!!(supp_rates
[i
] & 0x80) &&
2304 (supp_rates
[i
] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
2307 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
2308 struct ieee80211_rate
*br
;
2311 br
= &sband
->bitrates
[j
];
2312 if ((rate_flags
& br
->flags
) != rate_flags
)
2315 brate
= DIV_ROUND_UP(br
->bitrate
, (1 << shift
) * 5);
2316 if (brate
== rate
) {
2319 *basic_rates
|= BIT(j
);
2320 if ((rate
* 5) < *min_rate
) {
2321 *min_rate
= rate
* 5;
2322 *min_rate_index
= j
;
2330 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data
*sdata
,
2333 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
2335 sdata_assert_lock(sdata
);
2338 sta_info_destroy_addr(sdata
, assoc_data
->bss
->bssid
);
2340 memset(sdata
->u
.mgd
.bssid
, 0, ETH_ALEN
);
2341 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
2342 sdata
->u
.mgd
.flags
= 0;
2343 mutex_lock(&sdata
->local
->mtx
);
2344 ieee80211_vif_release_channel(sdata
);
2345 mutex_unlock(&sdata
->local
->mtx
);
2349 sdata
->u
.mgd
.assoc_data
= NULL
;
2352 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data
*sdata
,
2353 struct cfg80211_bss
*cbss
,
2354 struct ieee80211_mgmt
*mgmt
, size_t len
)
2356 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2357 struct ieee80211_local
*local
= sdata
->local
;
2358 struct ieee80211_supported_band
*sband
;
2359 struct sta_info
*sta
;
2361 u16 capab_info
, aid
;
2362 struct ieee802_11_elems elems
;
2363 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2364 const struct cfg80211_bss_ies
*bss_ies
= NULL
;
2365 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
2370 /* AssocResp and ReassocResp have identical structure */
2372 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
2373 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
2375 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2376 sdata_info(sdata
, "invalid AID value 0x%x; bits 15:14 not set\n",
2378 aid
&= ~(BIT(15) | BIT(14));
2380 ifmgd
->broken_ap
= false;
2382 if (aid
== 0 || aid
> IEEE80211_MAX_AID
) {
2383 sdata_info(sdata
, "invalid AID value %d (out of range), turn off PS\n",
2386 ifmgd
->broken_ap
= true;
2389 pos
= mgmt
->u
.assoc_resp
.variable
;
2390 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2392 if (!elems
.supp_rates
) {
2393 sdata_info(sdata
, "no SuppRates element in AssocResp\n");
2400 * Some APs are erroneously not including some information in their
2401 * (re)association response frames. Try to recover by using the data
2402 * from the beacon or probe response. This seems to afflict mobile
2403 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
2404 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
2406 if ((assoc_data
->wmm
&& !elems
.wmm_param
) ||
2407 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
2408 (!elems
.ht_cap_elem
|| !elems
.ht_operation
)) ||
2409 (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
2410 (!elems
.vht_cap_elem
|| !elems
.vht_operation
))) {
2411 const struct cfg80211_bss_ies
*ies
;
2412 struct ieee802_11_elems bss_elems
;
2415 ies
= rcu_dereference(cbss
->ies
);
2417 bss_ies
= kmemdup(ies
, sizeof(*ies
) + ies
->len
,
2423 ieee802_11_parse_elems(bss_ies
->data
, bss_ies
->len
,
2425 if (assoc_data
->wmm
&&
2426 !elems
.wmm_param
&& bss_elems
.wmm_param
) {
2427 elems
.wmm_param
= bss_elems
.wmm_param
;
2429 "AP bug: WMM param missing from AssocResp\n");
2433 * Also check if we requested HT/VHT, otherwise the AP doesn't
2434 * have to include the IEs in the (re)association response.
2436 if (!elems
.ht_cap_elem
&& bss_elems
.ht_cap_elem
&&
2437 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
2438 elems
.ht_cap_elem
= bss_elems
.ht_cap_elem
;
2440 "AP bug: HT capability missing from AssocResp\n");
2442 if (!elems
.ht_operation
&& bss_elems
.ht_operation
&&
2443 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)) {
2444 elems
.ht_operation
= bss_elems
.ht_operation
;
2446 "AP bug: HT operation missing from AssocResp\n");
2448 if (!elems
.vht_cap_elem
&& bss_elems
.vht_cap_elem
&&
2449 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
2450 elems
.vht_cap_elem
= bss_elems
.vht_cap_elem
;
2452 "AP bug: VHT capa missing from AssocResp\n");
2454 if (!elems
.vht_operation
&& bss_elems
.vht_operation
&&
2455 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)) {
2456 elems
.vht_operation
= bss_elems
.vht_operation
;
2458 "AP bug: VHT operation missing from AssocResp\n");
2463 * We previously checked these in the beacon/probe response, so
2464 * they should be present here. This is just a safety net.
2466 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
2467 (!elems
.wmm_param
|| !elems
.ht_cap_elem
|| !elems
.ht_operation
)) {
2469 "HT AP is missing WMM params or HT capability/operation\n");
2474 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
2475 (!elems
.vht_cap_elem
|| !elems
.vht_operation
)) {
2477 "VHT AP is missing VHT capability/operation\n");
2482 mutex_lock(&sdata
->local
->sta_mtx
);
2484 * station info was already allocated and inserted before
2485 * the association and should be available to us
2487 sta
= sta_info_get(sdata
, cbss
->bssid
);
2488 if (WARN_ON(!sta
)) {
2489 mutex_unlock(&sdata
->local
->sta_mtx
);
2494 sband
= local
->hw
.wiphy
->bands
[ieee80211_get_sdata_band(sdata
)];
2496 /* Set up internal HT/VHT capabilities */
2497 if (elems
.ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
))
2498 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata
, sband
,
2499 elems
.ht_cap_elem
, sta
);
2501 if (elems
.vht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
))
2502 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata
, sband
,
2503 elems
.vht_cap_elem
, sta
);
2506 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
2507 * in their association response, so ignore that data for our own
2508 * configuration. If it changed since the last beacon, we'll get the
2509 * next beacon and update then.
2513 * If an operating mode notification IE is present, override the
2514 * NSS calculation (that would be done in rate_control_rate_init())
2515 * and use the # of streams from that element.
2517 if (elems
.opmode_notif
&&
2518 !(*elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF
)) {
2521 nss
= *elems
.opmode_notif
& IEEE80211_OPMODE_NOTIF_RX_NSS_MASK
;
2522 nss
>>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT
;
2524 sta
->sta
.rx_nss
= nss
;
2527 rate_control_rate_init(sta
);
2529 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
)
2530 set_sta_flag(sta
, WLAN_STA_MFP
);
2532 if (elems
.wmm_param
)
2533 set_sta_flag(sta
, WLAN_STA_WME
);
2535 err
= sta_info_move_state(sta
, IEEE80211_STA_ASSOC
);
2536 if (!err
&& !(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
2537 err
= sta_info_move_state(sta
, IEEE80211_STA_AUTHORIZED
);
2540 "failed to move station %pM to desired state\n",
2542 WARN_ON(__sta_info_destroy(sta
));
2543 mutex_unlock(&sdata
->local
->sta_mtx
);
2548 mutex_unlock(&sdata
->local
->sta_mtx
);
2551 * Always handle WMM once after association regardless
2552 * of the first value the AP uses. Setting -1 here has
2553 * that effect because the AP values is an unsigned
2556 ifmgd
->wmm_last_param_set
= -1;
2558 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) && elems
.wmm_param
)
2559 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
2560 elems
.wmm_param_len
);
2562 ieee80211_set_wmm_default(sdata
, false);
2563 changed
|= BSS_CHANGED_QOS
;
2565 /* set AID and assoc capability,
2566 * ieee80211_set_associated() will tell the driver */
2567 bss_conf
->aid
= aid
;
2568 bss_conf
->assoc_capability
= capab_info
;
2569 ieee80211_set_associated(sdata
, cbss
, changed
);
2572 * If we're using 4-addr mode, let the AP know that we're
2573 * doing so, so that it can create the STA VLAN on its side
2575 if (ifmgd
->use_4addr
)
2576 ieee80211_send_4addr_nullfunc(local
, sdata
);
2579 * Start timer to probe the connection to the AP now.
2580 * Also start the timer that will detect beacon loss.
2582 ieee80211_sta_rx_notify(sdata
, (struct ieee80211_hdr
*)mgmt
);
2583 ieee80211_sta_reset_beacon_monitor(sdata
);
2591 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data
*sdata
,
2592 struct ieee80211_mgmt
*mgmt
,
2595 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2596 struct ieee80211_mgd_assoc_data
*assoc_data
= ifmgd
->assoc_data
;
2597 u16 capab_info
, status_code
, aid
;
2598 struct ieee802_11_elems elems
;
2601 struct cfg80211_bss
*bss
;
2603 sdata_assert_lock(sdata
);
2607 if (!ether_addr_equal(assoc_data
->bss
->bssid
, mgmt
->bssid
))
2611 * AssocResp and ReassocResp have identical structure, so process both
2612 * of them in this function.
2618 reassoc
= ieee80211_is_reassoc_req(mgmt
->frame_control
);
2619 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
2620 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
2621 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
2624 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2625 reassoc
? "Rea" : "A", mgmt
->sa
,
2626 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
2628 pos
= mgmt
->u
.assoc_resp
.variable
;
2629 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), false, &elems
);
2631 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
2632 elems
.timeout_int
&&
2633 elems
.timeout_int
->type
== WLAN_TIMEOUT_ASSOC_COMEBACK
) {
2635 tu
= le32_to_cpu(elems
.timeout_int
->value
);
2636 ms
= tu
* 1024 / 1000;
2638 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2640 assoc_data
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
2641 assoc_data
->timeout_started
= true;
2642 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
2643 run_again(sdata
, assoc_data
->timeout
);
2647 bss
= assoc_data
->bss
;
2649 if (status_code
!= WLAN_STATUS_SUCCESS
) {
2650 sdata_info(sdata
, "%pM denied association (code=%d)\n",
2651 mgmt
->sa
, status_code
);
2652 ieee80211_destroy_assoc_data(sdata
, false);
2654 if (!ieee80211_assoc_success(sdata
, bss
, mgmt
, len
)) {
2655 /* oops -- internal error -- send timeout for now */
2656 ieee80211_destroy_assoc_data(sdata
, false);
2657 cfg80211_assoc_timeout(sdata
->dev
, bss
);
2660 sdata_info(sdata
, "associated\n");
2663 * destroy assoc_data afterwards, as otherwise an idle
2664 * recalc after assoc_data is NULL but before associated
2665 * is set can cause the interface to go idle
2667 ieee80211_destroy_assoc_data(sdata
, true);
2670 cfg80211_rx_assoc_resp(sdata
->dev
, bss
, (u8
*)mgmt
, len
);
2673 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
2674 struct ieee80211_mgmt
*mgmt
, size_t len
,
2675 struct ieee80211_rx_status
*rx_status
,
2676 struct ieee802_11_elems
*elems
)
2678 struct ieee80211_local
*local
= sdata
->local
;
2680 struct ieee80211_bss
*bss
;
2681 struct ieee80211_channel
*channel
;
2683 sdata_assert_lock(sdata
);
2685 if (elems
->ds_params
)
2686 freq
= ieee80211_channel_to_frequency(elems
->ds_params
[0],
2689 freq
= rx_status
->freq
;
2691 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
2693 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
2696 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
2699 ieee80211_rx_bss_put(local
, bss
);
2700 sdata
->vif
.bss_conf
.beacon_rate
= bss
->beacon_rate
;
2705 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
2706 struct sk_buff
*skb
)
2708 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
2709 struct ieee80211_if_managed
*ifmgd
;
2710 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
2711 size_t baselen
, len
= skb
->len
;
2712 struct ieee802_11_elems elems
;
2714 ifmgd
= &sdata
->u
.mgd
;
2716 sdata_assert_lock(sdata
);
2718 if (!ether_addr_equal(mgmt
->da
, sdata
->vif
.addr
))
2719 return; /* ignore ProbeResp to foreign address */
2721 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
2725 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
2728 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
2730 if (ifmgd
->associated
&&
2731 ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2732 ieee80211_reset_ap_probe(sdata
);
2734 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->bss
->proberesp_ies
&&
2735 ether_addr_equal(mgmt
->bssid
, ifmgd
->auth_data
->bss
->bssid
)) {
2736 /* got probe response, continue with auth */
2737 sdata_info(sdata
, "direct probe responded\n");
2738 ifmgd
->auth_data
->tries
= 0;
2739 ifmgd
->auth_data
->timeout
= jiffies
;
2740 ifmgd
->auth_data
->timeout_started
= true;
2741 run_again(sdata
, ifmgd
->auth_data
->timeout
);
2746 * This is the canonical list of information elements we care about,
2747 * the filter code also gives us all changes to the Microsoft OUI
2748 * (00:50:F2) vendor IE which is used for WMM which we need to track.
2750 * We implement beacon filtering in software since that means we can
2751 * avoid processing the frame here and in cfg80211, and userspace
2752 * will not be able to tell whether the hardware supports it or not.
2754 * XXX: This list needs to be dynamic -- userspace needs to be able to
2755 * add items it requires. It also needs to be able to tell us to
2756 * look out for other vendor IEs.
2758 static const u64 care_about_ies
=
2759 (1ULL << WLAN_EID_COUNTRY
) |
2760 (1ULL << WLAN_EID_ERP_INFO
) |
2761 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
2762 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
2763 (1ULL << WLAN_EID_HT_CAPABILITY
) |
2764 (1ULL << WLAN_EID_HT_OPERATION
);
2766 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
2767 struct ieee80211_mgmt
*mgmt
, size_t len
,
2768 struct ieee80211_rx_status
*rx_status
)
2770 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2771 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
2773 struct ieee802_11_elems elems
;
2774 struct ieee80211_local
*local
= sdata
->local
;
2775 struct ieee80211_chanctx_conf
*chanctx_conf
;
2776 struct ieee80211_channel
*chan
;
2777 struct sta_info
*sta
;
2783 u8 deauth_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
2785 sdata_assert_lock(sdata
);
2787 /* Process beacon from the current BSS */
2788 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
2793 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
2794 if (!chanctx_conf
) {
2799 if (rx_status
->freq
!= chanctx_conf
->def
.chan
->center_freq
) {
2803 chan
= chanctx_conf
->def
.chan
;
2806 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->need_beacon
&&
2807 ether_addr_equal(mgmt
->bssid
, ifmgd
->assoc_data
->bss
->bssid
)) {
2808 ieee802_11_parse_elems(mgmt
->u
.beacon
.variable
,
2809 len
- baselen
, false, &elems
);
2811 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
2812 if (elems
.tim
&& !elems
.parse_error
) {
2813 const struct ieee80211_tim_ie
*tim_ie
= elems
.tim
;
2814 ifmgd
->dtim_period
= tim_ie
->dtim_period
;
2816 ifmgd
->have_beacon
= true;
2817 ifmgd
->assoc_data
->need_beacon
= false;
2818 if (local
->hw
.flags
& IEEE80211_HW_TIMING_BEACON_ONLY
) {
2819 sdata
->vif
.bss_conf
.sync_tsf
=
2820 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
2821 sdata
->vif
.bss_conf
.sync_device_ts
=
2822 rx_status
->device_timestamp
;
2824 sdata
->vif
.bss_conf
.sync_dtim_count
=
2825 elems
.tim
->dtim_count
;
2827 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
2829 /* continue assoc process */
2830 ifmgd
->assoc_data
->timeout
= jiffies
;
2831 ifmgd
->assoc_data
->timeout_started
= true;
2832 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
2836 if (!ifmgd
->associated
||
2837 !ether_addr_equal(mgmt
->bssid
, ifmgd
->associated
->bssid
))
2839 bssid
= ifmgd
->associated
->bssid
;
2841 /* Track average RSSI from the Beacon frames of the current AP */
2842 ifmgd
->last_beacon_signal
= rx_status
->signal
;
2843 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
2844 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
2845 ifmgd
->ave_beacon_signal
= rx_status
->signal
* 16;
2846 ifmgd
->last_cqm_event_signal
= 0;
2847 ifmgd
->count_beacon_signal
= 1;
2848 ifmgd
->last_ave_beacon_signal
= 0;
2850 ifmgd
->ave_beacon_signal
=
2851 (IEEE80211_SIGNAL_AVE_WEIGHT
* rx_status
->signal
* 16 +
2852 (16 - IEEE80211_SIGNAL_AVE_WEIGHT
) *
2853 ifmgd
->ave_beacon_signal
) / 16;
2854 ifmgd
->count_beacon_signal
++;
2857 if (ifmgd
->rssi_min_thold
!= ifmgd
->rssi_max_thold
&&
2858 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
) {
2859 int sig
= ifmgd
->ave_beacon_signal
;
2860 int last_sig
= ifmgd
->last_ave_beacon_signal
;
2863 * if signal crosses either of the boundaries, invoke callback
2864 * with appropriate parameters
2866 if (sig
> ifmgd
->rssi_max_thold
&&
2867 (last_sig
<= ifmgd
->rssi_min_thold
|| last_sig
== 0)) {
2868 ifmgd
->last_ave_beacon_signal
= sig
;
2869 drv_rssi_callback(local
, sdata
, RSSI_EVENT_HIGH
);
2870 } else if (sig
< ifmgd
->rssi_min_thold
&&
2871 (last_sig
>= ifmgd
->rssi_max_thold
||
2873 ifmgd
->last_ave_beacon_signal
= sig
;
2874 drv_rssi_callback(local
, sdata
, RSSI_EVENT_LOW
);
2878 if (bss_conf
->cqm_rssi_thold
&&
2879 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
2880 !(sdata
->vif
.driver_flags
& IEEE80211_VIF_SUPPORTS_CQM_RSSI
)) {
2881 int sig
= ifmgd
->ave_beacon_signal
/ 16;
2882 int last_event
= ifmgd
->last_cqm_event_signal
;
2883 int thold
= bss_conf
->cqm_rssi_thold
;
2884 int hyst
= bss_conf
->cqm_rssi_hyst
;
2886 (last_event
== 0 || sig
< last_event
- hyst
)) {
2887 ifmgd
->last_cqm_event_signal
= sig
;
2888 ieee80211_cqm_rssi_notify(
2890 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
2892 } else if (sig
> thold
&&
2893 (last_event
== 0 || sig
> last_event
+ hyst
)) {
2894 ifmgd
->last_cqm_event_signal
= sig
;
2895 ieee80211_cqm_rssi_notify(
2897 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
2902 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
) {
2903 mlme_dbg_ratelimited(sdata
,
2904 "cancelling AP probe due to a received beacon\n");
2905 ieee80211_reset_ap_probe(sdata
);
2909 * Push the beacon loss detection into the future since
2910 * we are processing a beacon from the AP just now.
2912 ieee80211_sta_reset_beacon_monitor(sdata
);
2914 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
2915 ncrc
= ieee802_11_parse_elems_crc(mgmt
->u
.beacon
.variable
,
2916 len
- baselen
, false, &elems
,
2917 care_about_ies
, ncrc
);
2919 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) {
2920 bool directed_tim
= ieee80211_check_tim(elems
.tim
,
2924 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
2925 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
2926 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
2927 ieee80211_hw_config(local
,
2928 IEEE80211_CONF_CHANGE_PS
);
2930 ieee80211_send_nullfunc(local
, sdata
, 0);
2931 } else if (!local
->pspolling
&& sdata
->u
.mgd
.powersave
) {
2932 local
->pspolling
= true;
2935 * Here is assumed that the driver will be
2936 * able to send ps-poll frame and receive a
2937 * response even though power save mode is
2938 * enabled, but some drivers might require
2939 * to disable power save here. This needs
2940 * to be investigated.
2942 ieee80211_send_pspoll(local
, sdata
);
2947 if (sdata
->vif
.p2p
) {
2948 struct ieee80211_p2p_noa_attr noa
= {};
2951 ret
= cfg80211_get_p2p_attr(mgmt
->u
.beacon
.variable
,
2953 IEEE80211_P2P_ATTR_ABSENCE_NOTICE
,
2954 (u8
*) &noa
, sizeof(noa
));
2956 if (sdata
->u
.mgd
.p2p_noa_index
!= noa
.index
) {
2957 /* valid noa_attr and index changed */
2958 sdata
->u
.mgd
.p2p_noa_index
= noa
.index
;
2959 memcpy(&bss_conf
->p2p_noa_attr
, &noa
, sizeof(noa
));
2960 changed
|= BSS_CHANGED_P2P_PS
;
2962 * make sure we update all information, the CRC
2963 * mechanism doesn't look at P2P attributes.
2965 ifmgd
->beacon_crc_valid
= false;
2967 } else if (sdata
->u
.mgd
.p2p_noa_index
!= -1) {
2968 /* noa_attr not found and we had valid noa_attr before */
2969 sdata
->u
.mgd
.p2p_noa_index
= -1;
2970 memset(&bss_conf
->p2p_noa_attr
, 0, sizeof(bss_conf
->p2p_noa_attr
));
2971 changed
|= BSS_CHANGED_P2P_PS
;
2972 ifmgd
->beacon_crc_valid
= false;
2976 if (ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
)
2978 ifmgd
->beacon_crc
= ncrc
;
2979 ifmgd
->beacon_crc_valid
= true;
2981 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
);
2983 ieee80211_sta_process_chanswitch(sdata
, rx_status
->mactime
,
2986 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) &&
2987 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
2988 elems
.wmm_param_len
))
2989 changed
|= BSS_CHANGED_QOS
;
2992 * If we haven't had a beacon before, tell the driver about the
2993 * DTIM period (and beacon timing if desired) now.
2995 if (!ifmgd
->have_beacon
) {
2996 /* a few bogus AP send dtim_period = 0 or no TIM IE */
2998 bss_conf
->dtim_period
= elems
.tim
->dtim_period
?: 1;
3000 bss_conf
->dtim_period
= 1;
3002 if (local
->hw
.flags
& IEEE80211_HW_TIMING_BEACON_ONLY
) {
3003 sdata
->vif
.bss_conf
.sync_tsf
=
3004 le64_to_cpu(mgmt
->u
.beacon
.timestamp
);
3005 sdata
->vif
.bss_conf
.sync_device_ts
=
3006 rx_status
->device_timestamp
;
3008 sdata
->vif
.bss_conf
.sync_dtim_count
=
3009 elems
.tim
->dtim_count
;
3011 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3014 changed
|= BSS_CHANGED_BEACON_INFO
;
3015 ifmgd
->have_beacon
= true;
3017 mutex_lock(&local
->iflist_mtx
);
3018 ieee80211_recalc_ps(local
, -1);
3019 mutex_unlock(&local
->iflist_mtx
);
3021 ieee80211_recalc_ps_vif(sdata
);
3024 if (elems
.erp_info
) {
3026 erp_value
= elems
.erp_info
[0];
3030 changed
|= ieee80211_handle_bss_capability(sdata
,
3031 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
3032 erp_valid
, erp_value
);
3034 mutex_lock(&local
->sta_mtx
);
3035 sta
= sta_info_get(sdata
, bssid
);
3037 if (ieee80211_config_bw(sdata
, sta
, elems
.ht_operation
,
3038 elems
.vht_operation
, bssid
, &changed
)) {
3039 mutex_unlock(&local
->sta_mtx
);
3040 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
3041 WLAN_REASON_DEAUTH_LEAVING
,
3043 cfg80211_tx_mlme_mgmt(sdata
->dev
, deauth_buf
,
3044 sizeof(deauth_buf
));
3048 if (sta
&& elems
.opmode_notif
)
3049 ieee80211_vht_handle_opmode(sdata
, sta
, *elems
.opmode_notif
,
3050 rx_status
->band
, true);
3051 mutex_unlock(&local
->sta_mtx
);
3053 if (elems
.country_elem
&& elems
.pwr_constr_elem
&&
3054 mgmt
->u
.probe_resp
.capab_info
&
3055 cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT
))
3056 changed
|= ieee80211_handle_pwr_constr(sdata
, chan
,
3058 elems
.country_elem_len
,
3059 elems
.pwr_constr_elem
);
3061 ieee80211_bss_info_change_notify(sdata
, changed
);
3064 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
3065 struct sk_buff
*skb
)
3067 struct ieee80211_rx_status
*rx_status
;
3068 struct ieee80211_mgmt
*mgmt
;
3070 struct ieee802_11_elems elems
;
3073 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
3074 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
3075 fc
= le16_to_cpu(mgmt
->frame_control
);
3079 switch (fc
& IEEE80211_FCTL_STYPE
) {
3080 case IEEE80211_STYPE_BEACON
:
3081 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
, rx_status
);
3083 case IEEE80211_STYPE_PROBE_RESP
:
3084 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
3086 case IEEE80211_STYPE_AUTH
:
3087 ieee80211_rx_mgmt_auth(sdata
, mgmt
, skb
->len
);
3089 case IEEE80211_STYPE_DEAUTH
:
3090 ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
3092 case IEEE80211_STYPE_DISASSOC
:
3093 ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
3095 case IEEE80211_STYPE_ASSOC_RESP
:
3096 case IEEE80211_STYPE_REASSOC_RESP
:
3097 ieee80211_rx_mgmt_assoc_resp(sdata
, mgmt
, skb
->len
);
3099 case IEEE80211_STYPE_ACTION
:
3100 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_SPECTRUM_MGMT
) {
3101 ies_len
= skb
->len
-
3102 offsetof(struct ieee80211_mgmt
,
3103 u
.action
.u
.chan_switch
.variable
);
3108 ieee802_11_parse_elems(
3109 mgmt
->u
.action
.u
.chan_switch
.variable
,
3110 ies_len
, true, &elems
);
3112 if (elems
.parse_error
)
3115 ieee80211_sta_process_chanswitch(sdata
,
3118 } else if (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
) {
3119 ies_len
= skb
->len
-
3120 offsetof(struct ieee80211_mgmt
,
3121 u
.action
.u
.ext_chan_switch
.variable
);
3126 ieee802_11_parse_elems(
3127 mgmt
->u
.action
.u
.ext_chan_switch
.variable
,
3128 ies_len
, true, &elems
);
3130 if (elems
.parse_error
)
3133 /* for the handling code pretend this was also an IE */
3134 elems
.ext_chansw_ie
=
3135 &mgmt
->u
.action
.u
.ext_chan_switch
.data
;
3137 ieee80211_sta_process_chanswitch(sdata
,
3143 sdata_unlock(sdata
);
3146 static void ieee80211_sta_timer(unsigned long data
)
3148 struct ieee80211_sub_if_data
*sdata
=
3149 (struct ieee80211_sub_if_data
*) data
;
3151 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
3154 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
3155 u8
*bssid
, u8 reason
, bool tx
)
3157 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3159 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
, reason
,
3162 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
3163 IEEE80211_DEAUTH_FRAME_LEN
);
3166 static int ieee80211_probe_auth(struct ieee80211_sub_if_data
*sdata
)
3168 struct ieee80211_local
*local
= sdata
->local
;
3169 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3170 struct ieee80211_mgd_auth_data
*auth_data
= ifmgd
->auth_data
;
3173 sdata_assert_lock(sdata
);
3175 if (WARN_ON_ONCE(!auth_data
))
3180 if (auth_data
->tries
> IEEE80211_AUTH_MAX_TRIES
) {
3181 sdata_info(sdata
, "authentication with %pM timed out\n",
3182 auth_data
->bss
->bssid
);
3185 * Most likely AP is not in the range so remove the
3186 * bss struct for that AP.
3188 cfg80211_unlink_bss(local
->hw
.wiphy
, auth_data
->bss
);
3193 drv_mgd_prepare_tx(local
, sdata
);
3195 if (auth_data
->bss
->proberesp_ies
) {
3199 sdata_info(sdata
, "send auth to %pM (try %d/%d)\n",
3200 auth_data
->bss
->bssid
, auth_data
->tries
,
3201 IEEE80211_AUTH_MAX_TRIES
);
3203 auth_data
->expected_transaction
= 2;
3205 if (auth_data
->algorithm
== WLAN_AUTH_SAE
) {
3206 trans
= auth_data
->sae_trans
;
3207 status
= auth_data
->sae_status
;
3208 auth_data
->expected_transaction
= trans
;
3211 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
3212 tx_flags
= IEEE80211_TX_CTL_REQ_TX_STATUS
|
3213 IEEE80211_TX_INTFL_MLME_CONN_TX
;
3215 ieee80211_send_auth(sdata
, trans
, auth_data
->algorithm
, status
,
3216 auth_data
->data
, auth_data
->data_len
,
3217 auth_data
->bss
->bssid
,
3218 auth_data
->bss
->bssid
, NULL
, 0, 0,
3223 sdata_info(sdata
, "direct probe to %pM (try %d/%i)\n",
3224 auth_data
->bss
->bssid
, auth_data
->tries
,
3225 IEEE80211_AUTH_MAX_TRIES
);
3228 ssidie
= ieee80211_bss_get_ie(auth_data
->bss
, WLAN_EID_SSID
);
3234 * Direct probe is sent to broadcast address as some APs
3235 * will not answer to direct packet in unassociated state.
3237 ieee80211_send_probe_req(sdata
, NULL
, ssidie
+ 2, ssidie
[1],
3238 NULL
, 0, (u32
) -1, true, 0,
3239 auth_data
->bss
->channel
, false);
3243 if (tx_flags
== 0) {
3244 auth_data
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
3245 auth_data
->timeout_started
= true;
3246 run_again(sdata
, auth_data
->timeout
);
3248 auth_data
->timeout
=
3249 round_jiffies_up(jiffies
+ IEEE80211_AUTH_TIMEOUT_LONG
);
3250 auth_data
->timeout_started
= true;
3251 run_again(sdata
, auth_data
->timeout
);
3257 static int ieee80211_do_assoc(struct ieee80211_sub_if_data
*sdata
)
3259 struct ieee80211_mgd_assoc_data
*assoc_data
= sdata
->u
.mgd
.assoc_data
;
3260 struct ieee80211_local
*local
= sdata
->local
;
3262 sdata_assert_lock(sdata
);
3264 assoc_data
->tries
++;
3265 if (assoc_data
->tries
> IEEE80211_ASSOC_MAX_TRIES
) {
3266 sdata_info(sdata
, "association with %pM timed out\n",
3267 assoc_data
->bss
->bssid
);
3270 * Most likely AP is not in the range so remove the
3271 * bss struct for that AP.
3273 cfg80211_unlink_bss(local
->hw
.wiphy
, assoc_data
->bss
);
3278 sdata_info(sdata
, "associate with %pM (try %d/%d)\n",
3279 assoc_data
->bss
->bssid
, assoc_data
->tries
,
3280 IEEE80211_ASSOC_MAX_TRIES
);
3281 ieee80211_send_assoc(sdata
);
3283 if (!(local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)) {
3284 assoc_data
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
3285 assoc_data
->timeout_started
= true;
3286 run_again(sdata
, assoc_data
->timeout
);
3288 assoc_data
->timeout
=
3289 round_jiffies_up(jiffies
+
3290 IEEE80211_ASSOC_TIMEOUT_LONG
);
3291 assoc_data
->timeout_started
= true;
3292 run_again(sdata
, assoc_data
->timeout
);
3298 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data
*sdata
,
3299 __le16 fc
, bool acked
)
3301 struct ieee80211_local
*local
= sdata
->local
;
3303 sdata
->u
.mgd
.status_fc
= fc
;
3304 sdata
->u
.mgd
.status_acked
= acked
;
3305 sdata
->u
.mgd
.status_received
= true;
3307 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
3310 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
3312 struct ieee80211_local
*local
= sdata
->local
;
3313 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3317 if (ifmgd
->status_received
) {
3318 __le16 fc
= ifmgd
->status_fc
;
3319 bool status_acked
= ifmgd
->status_acked
;
3321 ifmgd
->status_received
= false;
3322 if (ifmgd
->auth_data
&&
3323 (ieee80211_is_probe_req(fc
) || ieee80211_is_auth(fc
))) {
3325 ifmgd
->auth_data
->timeout
=
3326 jiffies
+ IEEE80211_AUTH_TIMEOUT_SHORT
;
3327 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3329 ifmgd
->auth_data
->timeout
= jiffies
- 1;
3331 ifmgd
->auth_data
->timeout_started
= true;
3332 } else if (ifmgd
->assoc_data
&&
3333 (ieee80211_is_assoc_req(fc
) ||
3334 ieee80211_is_reassoc_req(fc
))) {
3336 ifmgd
->assoc_data
->timeout
=
3337 jiffies
+ IEEE80211_ASSOC_TIMEOUT_SHORT
;
3338 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3340 ifmgd
->assoc_data
->timeout
= jiffies
- 1;
3342 ifmgd
->assoc_data
->timeout_started
= true;
3346 if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
&&
3347 time_after(jiffies
, ifmgd
->auth_data
->timeout
)) {
3348 if (ifmgd
->auth_data
->done
) {
3350 * ok ... we waited for assoc but userspace didn't,
3351 * so let's just kill the auth data
3353 ieee80211_destroy_auth_data(sdata
, false);
3354 } else if (ieee80211_probe_auth(sdata
)) {
3357 memcpy(bssid
, ifmgd
->auth_data
->bss
->bssid
, ETH_ALEN
);
3359 ieee80211_destroy_auth_data(sdata
, false);
3361 cfg80211_auth_timeout(sdata
->dev
, bssid
);
3363 } else if (ifmgd
->auth_data
&& ifmgd
->auth_data
->timeout_started
)
3364 run_again(sdata
, ifmgd
->auth_data
->timeout
);
3366 if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
&&
3367 time_after(jiffies
, ifmgd
->assoc_data
->timeout
)) {
3368 if ((ifmgd
->assoc_data
->need_beacon
&& !ifmgd
->have_beacon
) ||
3369 ieee80211_do_assoc(sdata
)) {
3370 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
3372 ieee80211_destroy_assoc_data(sdata
, false);
3373 cfg80211_assoc_timeout(sdata
->dev
, bss
);
3375 } else if (ifmgd
->assoc_data
&& ifmgd
->assoc_data
->timeout_started
)
3376 run_again(sdata
, ifmgd
->assoc_data
->timeout
);
3378 if (ifmgd
->flags
& IEEE80211_STA_CONNECTION_POLL
&&
3379 ifmgd
->associated
) {
3383 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
3385 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
3386 max_tries
= max_nullfunc_tries
;
3388 max_tries
= max_probe_tries
;
3390 /* ACK received for nullfunc probing frame */
3391 if (!ifmgd
->probe_send_count
)
3392 ieee80211_reset_ap_probe(sdata
);
3393 else if (ifmgd
->nullfunc_failed
) {
3394 if (ifmgd
->probe_send_count
< max_tries
) {
3396 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
3397 bssid
, ifmgd
->probe_send_count
,
3399 ieee80211_mgd_probe_ap_send(sdata
);
3402 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
3404 ieee80211_sta_connection_lost(sdata
, bssid
,
3405 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
3408 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
3409 run_again(sdata
, ifmgd
->probe_timeout
);
3410 else if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) {
3412 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
3413 bssid
, probe_wait_ms
);
3414 ieee80211_sta_connection_lost(sdata
, bssid
,
3415 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
3416 } else if (ifmgd
->probe_send_count
< max_tries
) {
3418 "No probe response from AP %pM after %dms, try %d/%i\n",
3419 bssid
, probe_wait_ms
,
3420 ifmgd
->probe_send_count
, max_tries
);
3421 ieee80211_mgd_probe_ap_send(sdata
);
3424 * We actually lost the connection ... or did we?
3427 wiphy_debug(local
->hw
.wiphy
,
3428 "%s: No probe response from AP %pM"
3429 " after %dms, disconnecting.\n",
3431 bssid
, probe_wait_ms
);
3433 ieee80211_sta_connection_lost(sdata
, bssid
,
3434 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
, false);
3438 sdata_unlock(sdata
);
3441 static void ieee80211_sta_bcn_mon_timer(unsigned long data
)
3443 struct ieee80211_sub_if_data
*sdata
=
3444 (struct ieee80211_sub_if_data
*) data
;
3445 struct ieee80211_local
*local
= sdata
->local
;
3447 if (local
->quiescing
)
3450 sdata
->u
.mgd
.connection_loss
= false;
3451 ieee80211_queue_work(&sdata
->local
->hw
,
3452 &sdata
->u
.mgd
.beacon_connection_loss_work
);
3455 static void ieee80211_sta_conn_mon_timer(unsigned long data
)
3457 struct ieee80211_sub_if_data
*sdata
=
3458 (struct ieee80211_sub_if_data
*) data
;
3459 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3460 struct ieee80211_local
*local
= sdata
->local
;
3462 if (local
->quiescing
)
3465 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
3468 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
3470 struct ieee80211_sub_if_data
*sdata
=
3471 container_of(work
, struct ieee80211_sub_if_data
,
3472 u
.mgd
.monitor_work
);
3474 ieee80211_mgd_probe_ap(sdata
, false);
3477 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
3481 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
3482 __ieee80211_stop_poll(sdata
);
3484 /* let's probe the connection once */
3485 flags
= sdata
->local
->hw
.flags
;
3486 if (!(flags
& IEEE80211_HW_CONNECTION_MONITOR
))
3487 ieee80211_queue_work(&sdata
->local
->hw
,
3488 &sdata
->u
.mgd
.monitor_work
);
3489 /* and do all the other regular work too */
3490 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
3495 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
3497 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3500 if (!ifmgd
->associated
) {
3501 sdata_unlock(sdata
);
3505 if (sdata
->flags
& IEEE80211_SDATA_DISCONNECT_RESUME
) {
3506 sdata
->flags
&= ~IEEE80211_SDATA_DISCONNECT_RESUME
;
3507 mlme_dbg(sdata
, "driver requested disconnect after resume\n");
3508 ieee80211_sta_connection_lost(sdata
,
3509 ifmgd
->associated
->bssid
,
3510 WLAN_REASON_UNSPECIFIED
,
3512 sdata_unlock(sdata
);
3515 sdata_unlock(sdata
);
3519 /* interface setup */
3520 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
3522 struct ieee80211_if_managed
*ifmgd
;
3524 ifmgd
= &sdata
->u
.mgd
;
3525 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
3526 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
3527 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
3528 ieee80211_beacon_connection_loss_work
);
3529 INIT_WORK(&ifmgd
->csa_connection_drop_work
,
3530 ieee80211_csa_connection_drop_work
);
3531 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_mgd_work
);
3532 setup_timer(&ifmgd
->timer
, ieee80211_sta_timer
,
3533 (unsigned long) sdata
);
3534 setup_timer(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
,
3535 (unsigned long) sdata
);
3536 setup_timer(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
,
3537 (unsigned long) sdata
);
3538 setup_timer(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
,
3539 (unsigned long) sdata
);
3542 ifmgd
->powersave
= sdata
->wdev
.ps
;
3543 ifmgd
->uapsd_queues
= sdata
->local
->hw
.uapsd_queues
;
3544 ifmgd
->uapsd_max_sp_len
= sdata
->local
->hw
.uapsd_max_sp_len
;
3545 ifmgd
->p2p_noa_index
= -1;
3547 if (sdata
->local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
)
3548 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
3550 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
3553 /* scan finished notification */
3554 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
3556 struct ieee80211_sub_if_data
*sdata
;
3558 /* Restart STA timers */
3560 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
3561 if (ieee80211_sdata_running(sdata
))
3562 ieee80211_restart_sta_timer(sdata
);
3567 int ieee80211_max_network_latency(struct notifier_block
*nb
,
3568 unsigned long data
, void *dummy
)
3570 s32 latency_usec
= (s32
) data
;
3571 struct ieee80211_local
*local
=
3572 container_of(nb
, struct ieee80211_local
,
3573 network_latency_notifier
);
3575 mutex_lock(&local
->iflist_mtx
);
3576 ieee80211_recalc_ps(local
, latency_usec
);
3577 mutex_unlock(&local
->iflist_mtx
);
3582 static u8
ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data
*sdata
,
3583 struct cfg80211_bss
*cbss
)
3585 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3586 const u8
*ht_cap_ie
, *vht_cap_ie
;
3587 const struct ieee80211_ht_cap
*ht_cap
;
3588 const struct ieee80211_vht_cap
*vht_cap
;
3591 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
)
3594 ht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
3595 if (ht_cap_ie
&& ht_cap_ie
[1] >= sizeof(*ht_cap
)) {
3596 ht_cap
= (void *)(ht_cap_ie
+ 2);
3597 chains
= ieee80211_mcs_to_chains(&ht_cap
->mcs
);
3599 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
3600 * "Tx Unequal Modulation Supported" fields.
3604 if (ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
)
3607 vht_cap_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
3608 if (vht_cap_ie
&& vht_cap_ie
[1] >= sizeof(*vht_cap
)) {
3612 vht_cap
= (void *)(vht_cap_ie
+ 2);
3613 tx_mcs_map
= le16_to_cpu(vht_cap
->supp_mcs
.tx_mcs_map
);
3614 for (nss
= 8; nss
> 0; nss
--) {
3615 if (((tx_mcs_map
>> (2 * (nss
- 1))) & 3) !=
3616 IEEE80211_VHT_MCS_NOT_SUPPORTED
)
3619 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
3620 chains
= max(chains
, nss
);
3626 static int ieee80211_prep_channel(struct ieee80211_sub_if_data
*sdata
,
3627 struct cfg80211_bss
*cbss
)
3629 struct ieee80211_local
*local
= sdata
->local
;
3630 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3631 const struct ieee80211_ht_operation
*ht_oper
= NULL
;
3632 const struct ieee80211_vht_operation
*vht_oper
= NULL
;
3633 struct ieee80211_supported_band
*sband
;
3634 struct cfg80211_chan_def chandef
;
3637 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
3639 ifmgd
->flags
&= ~(IEEE80211_STA_DISABLE_40MHZ
|
3640 IEEE80211_STA_DISABLE_80P80MHZ
|
3641 IEEE80211_STA_DISABLE_160MHZ
);
3645 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_HT
) &&
3646 sband
->ht_cap
.ht_supported
) {
3647 const u8
*ht_oper_ie
, *ht_cap
;
3649 ht_oper_ie
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_OPERATION
);
3650 if (ht_oper_ie
&& ht_oper_ie
[1] >= sizeof(*ht_oper
))
3651 ht_oper
= (void *)(ht_oper_ie
+ 2);
3653 ht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_HT_CAPABILITY
);
3654 if (!ht_cap
|| ht_cap
[1] < sizeof(struct ieee80211_ht_cap
)) {
3655 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
3660 if (!(ifmgd
->flags
& IEEE80211_STA_DISABLE_VHT
) &&
3661 sband
->vht_cap
.vht_supported
) {
3662 const u8
*vht_oper_ie
, *vht_cap
;
3664 vht_oper_ie
= ieee80211_bss_get_ie(cbss
,
3665 WLAN_EID_VHT_OPERATION
);
3666 if (vht_oper_ie
&& vht_oper_ie
[1] >= sizeof(*vht_oper
))
3667 vht_oper
= (void *)(vht_oper_ie
+ 2);
3668 if (vht_oper
&& !ht_oper
) {
3671 "AP advertised VHT without HT, disabling both\n");
3672 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
3673 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
3676 vht_cap
= ieee80211_bss_get_ie(cbss
, WLAN_EID_VHT_CAPABILITY
);
3677 if (!vht_cap
|| vht_cap
[1] < sizeof(struct ieee80211_vht_cap
)) {
3678 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
3683 ifmgd
->flags
|= ieee80211_determine_chantype(sdata
, sband
,
3688 sdata
->needed_rx_chains
= min(ieee80211_ht_vht_rx_chains(sdata
, cbss
),
3693 /* will change later if needed */
3694 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
3696 mutex_lock(&local
->mtx
);
3698 * If this fails (possibly due to channel context sharing
3699 * on incompatible channels, e.g. 80+80 and 160 sharing the
3700 * same control channel) try to use a smaller bandwidth.
3702 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
3703 IEEE80211_CHANCTX_SHARED
);
3705 /* don't downgrade for 5 and 10 MHz channels, though. */
3706 if (chandef
.width
== NL80211_CHAN_WIDTH_5
||
3707 chandef
.width
== NL80211_CHAN_WIDTH_10
)
3710 while (ret
&& chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) {
3711 ifmgd
->flags
|= ieee80211_chandef_downgrade(&chandef
);
3712 ret
= ieee80211_vif_use_channel(sdata
, &chandef
,
3713 IEEE80211_CHANCTX_SHARED
);
3716 mutex_unlock(&local
->mtx
);
3720 static int ieee80211_prep_connection(struct ieee80211_sub_if_data
*sdata
,
3721 struct cfg80211_bss
*cbss
, bool assoc
)
3723 struct ieee80211_local
*local
= sdata
->local
;
3724 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3725 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
3726 struct sta_info
*new_sta
= NULL
;
3727 bool have_sta
= false;
3730 if (WARN_ON(!ifmgd
->auth_data
&& !ifmgd
->assoc_data
))
3735 have_sta
= sta_info_get(sdata
, cbss
->bssid
);
3740 new_sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
3745 u32 rates
= 0, basic_rates
= 0;
3746 bool have_higher_than_11mbit
;
3747 int min_rate
= INT_MAX
, min_rate_index
= -1;
3748 struct ieee80211_chanctx_conf
*chanctx_conf
;
3749 struct ieee80211_supported_band
*sband
;
3750 const struct cfg80211_bss_ies
*ies
;
3754 sband
= local
->hw
.wiphy
->bands
[cbss
->channel
->band
];
3756 err
= ieee80211_prep_channel(sdata
, cbss
);
3758 sta_info_free(local
, new_sta
);
3761 shift
= ieee80211_vif_get_shift(&sdata
->vif
);
3764 chanctx_conf
= rcu_dereference(sdata
->vif
.chanctx_conf
);
3765 if (WARN_ON(!chanctx_conf
)) {
3769 rate_flags
= ieee80211_chandef_rate_flags(&chanctx_conf
->def
);
3772 ieee80211_get_rates(sband
, bss
->supp_rates
,
3773 bss
->supp_rates_len
,
3774 &rates
, &basic_rates
,
3775 &have_higher_than_11mbit
,
3776 &min_rate
, &min_rate_index
,
3780 * This used to be a workaround for basic rates missing
3781 * in the association response frame. Now that we no
3782 * longer use the basic rates from there, it probably
3783 * doesn't happen any more, but keep the workaround so
3784 * in case some *other* APs are buggy in different ways
3785 * we can connect -- with a warning.
3787 if (!basic_rates
&& min_rate_index
>= 0) {
3789 "No basic rates, using min rate instead\n");
3790 basic_rates
= BIT(min_rate_index
);
3793 new_sta
->sta
.supp_rates
[cbss
->channel
->band
] = rates
;
3794 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
3796 /* cf. IEEE 802.11 9.2.12 */
3797 if (cbss
->channel
->band
== IEEE80211_BAND_2GHZ
&&
3798 have_higher_than_11mbit
)
3799 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
3801 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
3803 memcpy(ifmgd
->bssid
, cbss
->bssid
, ETH_ALEN
);
3805 /* set timing information */
3806 sdata
->vif
.bss_conf
.beacon_int
= cbss
->beacon_interval
;
3808 ies
= rcu_dereference(cbss
->beacon_ies
);
3812 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
3813 sdata
->vif
.bss_conf
.sync_device_ts
=
3814 bss
->device_ts_beacon
;
3815 tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
3816 ies
->data
, ies
->len
);
3817 if (tim_ie
&& tim_ie
[1] >= 2)
3818 sdata
->vif
.bss_conf
.sync_dtim_count
= tim_ie
[2];
3820 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3821 } else if (!(local
->hw
.flags
&
3822 IEEE80211_HW_TIMING_BEACON_ONLY
)) {
3823 ies
= rcu_dereference(cbss
->proberesp_ies
);
3824 /* must be non-NULL since beacon IEs were NULL */
3825 sdata
->vif
.bss_conf
.sync_tsf
= ies
->tsf
;
3826 sdata
->vif
.bss_conf
.sync_device_ts
=
3827 bss
->device_ts_presp
;
3828 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3830 sdata
->vif
.bss_conf
.sync_tsf
= 0;
3831 sdata
->vif
.bss_conf
.sync_device_ts
= 0;
3832 sdata
->vif
.bss_conf
.sync_dtim_count
= 0;
3836 /* tell driver about BSSID, basic rates and timing */
3837 ieee80211_bss_info_change_notify(sdata
,
3838 BSS_CHANGED_BSSID
| BSS_CHANGED_BASIC_RATES
|
3839 BSS_CHANGED_BEACON_INT
);
3842 sta_info_pre_move_state(new_sta
, IEEE80211_STA_AUTH
);
3844 err
= sta_info_insert(new_sta
);
3848 "failed to insert STA entry for the AP (error %d)\n",
3853 WARN_ON_ONCE(!ether_addr_equal(ifmgd
->bssid
, cbss
->bssid
));
3859 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
3860 struct cfg80211_auth_request
*req
)
3862 struct ieee80211_local
*local
= sdata
->local
;
3863 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
3864 struct ieee80211_mgd_auth_data
*auth_data
;
3868 /* prepare auth data structure */
3870 switch (req
->auth_type
) {
3871 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
3872 auth_alg
= WLAN_AUTH_OPEN
;
3874 case NL80211_AUTHTYPE_SHARED_KEY
:
3875 if (IS_ERR(local
->wep_tx_tfm
))
3877 auth_alg
= WLAN_AUTH_SHARED_KEY
;
3879 case NL80211_AUTHTYPE_FT
:
3880 auth_alg
= WLAN_AUTH_FT
;
3882 case NL80211_AUTHTYPE_NETWORK_EAP
:
3883 auth_alg
= WLAN_AUTH_LEAP
;
3885 case NL80211_AUTHTYPE_SAE
:
3886 auth_alg
= WLAN_AUTH_SAE
;
3892 auth_data
= kzalloc(sizeof(*auth_data
) + req
->sae_data_len
+
3893 req
->ie_len
, GFP_KERNEL
);
3897 auth_data
->bss
= req
->bss
;
3899 if (req
->sae_data_len
>= 4) {
3900 __le16
*pos
= (__le16
*) req
->sae_data
;
3901 auth_data
->sae_trans
= le16_to_cpu(pos
[0]);
3902 auth_data
->sae_status
= le16_to_cpu(pos
[1]);
3903 memcpy(auth_data
->data
, req
->sae_data
+ 4,
3904 req
->sae_data_len
- 4);
3905 auth_data
->data_len
+= req
->sae_data_len
- 4;
3908 if (req
->ie
&& req
->ie_len
) {
3909 memcpy(&auth_data
->data
[auth_data
->data_len
],
3910 req
->ie
, req
->ie_len
);
3911 auth_data
->data_len
+= req
->ie_len
;
3914 if (req
->key
&& req
->key_len
) {
3915 auth_data
->key_len
= req
->key_len
;
3916 auth_data
->key_idx
= req
->key_idx
;
3917 memcpy(auth_data
->key
, req
->key
, req
->key_len
);
3920 auth_data
->algorithm
= auth_alg
;
3922 /* try to authenticate/probe */
3924 if ((ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) ||
3925 ifmgd
->assoc_data
) {
3930 if (ifmgd
->auth_data
)
3931 ieee80211_destroy_auth_data(sdata
, false);
3933 /* prep auth_data so we don't go into idle on disassoc */
3934 ifmgd
->auth_data
= auth_data
;
3936 if (ifmgd
->associated
) {
3937 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
3939 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
3940 WLAN_REASON_UNSPECIFIED
,
3943 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
3947 sdata_info(sdata
, "authenticate with %pM\n", req
->bss
->bssid
);
3949 err
= ieee80211_prep_connection(sdata
, req
->bss
, false);
3953 err
= ieee80211_probe_auth(sdata
);
3955 sta_info_destroy_addr(sdata
, req
->bss
->bssid
);
3959 /* hold our own reference */
3960 cfg80211_ref_bss(local
->hw
.wiphy
, auth_data
->bss
);
3964 memset(ifmgd
->bssid
, 0, ETH_ALEN
);
3965 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
3966 ifmgd
->auth_data
= NULL
;
3972 static bool ieee80211_usable_wmm_params(struct ieee80211_sub_if_data
*sdata
,
3973 const u8
*wmm_param
, int len
)
3981 if (wmm_param
[5] != 1 /* version */)
3984 pos
= wmm_param
+ 8;
3987 for (; left
>= 4; left
-= 4, pos
+= 4) {
3988 u8 aifsn
= pos
[0] & 0x0f;
3989 u8 ecwmin
= pos
[1] & 0x0f;
3990 u8 ecwmax
= (pos
[1] & 0xf0) >> 4;
3991 int aci
= (pos
[0] >> 5) & 0x03;
3995 "AP has invalid WMM params (AIFSN=%d for ACI %d), disabling WMM\n",
3999 if (ecwmin
> ecwmax
) {
4001 "AP has invalid WMM params (ECWmin/max=%d/%d for ACI %d), disabling WMM\n",
4002 ecwmin
, ecwmax
, aci
);
4010 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
4011 struct cfg80211_assoc_request
*req
)
4013 struct ieee80211_local
*local
= sdata
->local
;
4014 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4015 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
4016 struct ieee80211_mgd_assoc_data
*assoc_data
;
4017 const struct cfg80211_bss_ies
*beacon_ies
;
4018 struct ieee80211_supported_band
*sband
;
4019 const u8
*ssidie
, *ht_ie
, *vht_ie
;
4022 assoc_data
= kzalloc(sizeof(*assoc_data
) + req
->ie_len
, GFP_KERNEL
);
4027 ssidie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
4033 memcpy(assoc_data
->ssid
, ssidie
+ 2, ssidie
[1]);
4034 assoc_data
->ssid_len
= ssidie
[1];
4037 if (ifmgd
->associated
) {
4038 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4040 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4041 WLAN_REASON_UNSPECIFIED
,
4044 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4048 if (ifmgd
->auth_data
&& !ifmgd
->auth_data
->done
) {
4053 if (ifmgd
->assoc_data
) {
4058 if (ifmgd
->auth_data
) {
4061 /* keep sta info, bssid if matching */
4062 match
= ether_addr_equal(ifmgd
->bssid
, req
->bss
->bssid
);
4063 ieee80211_destroy_auth_data(sdata
, match
);
4066 /* prepare assoc data */
4068 ifmgd
->beacon_crc_valid
= false;
4070 assoc_data
->wmm
= bss
->wmm_used
&&
4071 (local
->hw
.queues
>= IEEE80211_NUM_ACS
);
4072 if (assoc_data
->wmm
) {
4073 /* try to check validity of WMM params IE */
4074 const struct cfg80211_bss_ies
*ies
;
4075 const u8
*wp
, *start
, *end
;
4078 ies
= rcu_dereference(req
->bss
->ies
);
4080 end
= start
+ ies
->len
;
4083 wp
= cfg80211_find_vendor_ie(
4085 WLAN_OUI_TYPE_MICROSOFT_WMM
,
4086 start
, end
- start
);
4089 start
= wp
+ wp
[1] + 2;
4090 /* if this IE is too short, try the next */
4093 /* if this IE is WMM params, we found what we wanted */
4098 if (!wp
|| !ieee80211_usable_wmm_params(sdata
, wp
+ 2,
4100 assoc_data
->wmm
= false;
4101 ifmgd
->flags
|= IEEE80211_STA_DISABLE_WMM
;
4107 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
4108 * We still associate in non-HT mode (11a/b/g) if any one of these
4109 * ciphers is configured as pairwise.
4110 * We can set this to true for non-11n hardware, that'll be checked
4111 * separately along with the peer capabilities.
4113 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++) {
4114 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
4115 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
4116 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
) {
4117 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4118 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4119 netdev_info(sdata
->dev
,
4120 "disabling HT/VHT due to WEP/TKIP use\n");
4124 if (req
->flags
& ASSOC_REQ_DISABLE_HT
) {
4125 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4126 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4129 if (req
->flags
& ASSOC_REQ_DISABLE_VHT
)
4130 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4132 /* Also disable HT if we don't support it or the AP doesn't use WMM */
4133 sband
= local
->hw
.wiphy
->bands
[req
->bss
->channel
->band
];
4134 if (!sband
->ht_cap
.ht_supported
||
4135 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4136 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4137 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4138 if (!bss
->wmm_used
&&
4139 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4140 netdev_info(sdata
->dev
,
4141 "disabling HT as WMM/QoS is not supported by the AP\n");
4144 /* disable VHT if we don't support it or the AP doesn't use WMM */
4145 if (!sband
->vht_cap
.vht_supported
||
4146 local
->hw
.queues
< IEEE80211_NUM_ACS
|| !bss
->wmm_used
||
4147 ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
) {
4148 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4149 if (!bss
->wmm_used
&&
4150 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_WMM
))
4151 netdev_info(sdata
->dev
,
4152 "disabling VHT as WMM/QoS is not supported by the AP\n");
4155 memcpy(&ifmgd
->ht_capa
, &req
->ht_capa
, sizeof(ifmgd
->ht_capa
));
4156 memcpy(&ifmgd
->ht_capa_mask
, &req
->ht_capa_mask
,
4157 sizeof(ifmgd
->ht_capa_mask
));
4159 memcpy(&ifmgd
->vht_capa
, &req
->vht_capa
, sizeof(ifmgd
->vht_capa
));
4160 memcpy(&ifmgd
->vht_capa_mask
, &req
->vht_capa_mask
,
4161 sizeof(ifmgd
->vht_capa_mask
));
4163 if (req
->ie
&& req
->ie_len
) {
4164 memcpy(assoc_data
->ie
, req
->ie
, req
->ie_len
);
4165 assoc_data
->ie_len
= req
->ie_len
;
4168 assoc_data
->bss
= req
->bss
;
4170 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
4171 if (ifmgd
->powersave
)
4172 sdata
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
4174 sdata
->smps_mode
= IEEE80211_SMPS_OFF
;
4176 sdata
->smps_mode
= ifmgd
->req_smps
;
4178 assoc_data
->capability
= req
->bss
->capability
;
4179 assoc_data
->supp_rates
= bss
->supp_rates
;
4180 assoc_data
->supp_rates_len
= bss
->supp_rates_len
;
4183 ht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_OPERATION
);
4184 if (ht_ie
&& ht_ie
[1] >= sizeof(struct ieee80211_ht_operation
))
4185 assoc_data
->ap_ht_param
=
4186 ((struct ieee80211_ht_operation
*)(ht_ie
+ 2))->ht_param
;
4188 ifmgd
->flags
|= IEEE80211_STA_DISABLE_HT
;
4189 vht_ie
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_VHT_CAPABILITY
);
4190 if (vht_ie
&& vht_ie
[1] >= sizeof(struct ieee80211_vht_cap
))
4191 memcpy(&assoc_data
->ap_vht_cap
, vht_ie
+ 2,
4192 sizeof(struct ieee80211_vht_cap
));
4194 ifmgd
->flags
|= IEEE80211_STA_DISABLE_VHT
;
4197 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
4198 (sdata
->local
->hw
.flags
& IEEE80211_HW_SUPPORTS_UAPSD
) &&
4199 sdata
->wmm_acm
!= 0xff) {
4200 assoc_data
->uapsd
= true;
4201 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
4203 assoc_data
->uapsd
= false;
4204 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
4207 if (req
->prev_bssid
)
4208 memcpy(assoc_data
->prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
4211 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
4212 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
4214 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
4215 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
4218 if (req
->crypto
.control_port
)
4219 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
4221 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
4223 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
4224 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
4225 sdata
->encrypt_headroom
= ieee80211_cs_headroom(local
, &req
->crypto
,
4228 /* kick off associate process */
4230 ifmgd
->assoc_data
= assoc_data
;
4231 ifmgd
->dtim_period
= 0;
4232 ifmgd
->have_beacon
= false;
4234 err
= ieee80211_prep_connection(sdata
, req
->bss
, true);
4239 beacon_ies
= rcu_dereference(req
->bss
->beacon_ies
);
4241 if (sdata
->local
->hw
.flags
& IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC
&&
4244 * Wait up to one beacon interval ...
4245 * should this be more if we miss one?
4247 sdata_info(sdata
, "waiting for beacon from %pM\n",
4249 assoc_data
->timeout
= TU_TO_EXP_TIME(req
->bss
->beacon_interval
);
4250 assoc_data
->timeout_started
= true;
4251 assoc_data
->need_beacon
= true;
4252 } else if (beacon_ies
) {
4253 const u8
*tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
,
4258 if (tim_ie
&& tim_ie
[1] >= sizeof(struct ieee80211_tim_ie
)) {
4259 const struct ieee80211_tim_ie
*tim
;
4260 tim
= (void *)(tim_ie
+ 2);
4261 ifmgd
->dtim_period
= tim
->dtim_period
;
4262 dtim_count
= tim
->dtim_count
;
4264 ifmgd
->have_beacon
= true;
4265 assoc_data
->timeout
= jiffies
;
4266 assoc_data
->timeout_started
= true;
4268 if (local
->hw
.flags
& IEEE80211_HW_TIMING_BEACON_ONLY
) {
4269 sdata
->vif
.bss_conf
.sync_tsf
= beacon_ies
->tsf
;
4270 sdata
->vif
.bss_conf
.sync_device_ts
=
4271 bss
->device_ts_beacon
;
4272 sdata
->vif
.bss_conf
.sync_dtim_count
= dtim_count
;
4275 assoc_data
->timeout
= jiffies
;
4276 assoc_data
->timeout_started
= true;
4280 run_again(sdata
, assoc_data
->timeout
);
4282 if (bss
->corrupt_data
) {
4283 char *corrupt_type
= "data";
4284 if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_BEACON
) {
4285 if (bss
->corrupt_data
&
4286 IEEE80211_BSS_CORRUPT_PROBE_RESP
)
4287 corrupt_type
= "beacon and probe response";
4289 corrupt_type
= "beacon";
4290 } else if (bss
->corrupt_data
& IEEE80211_BSS_CORRUPT_PROBE_RESP
)
4291 corrupt_type
= "probe response";
4292 sdata_info(sdata
, "associating with AP with corrupt %s\n",
4298 memset(ifmgd
->bssid
, 0, ETH_ALEN
);
4299 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_BSSID
);
4300 ifmgd
->assoc_data
= NULL
;
4306 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
4307 struct cfg80211_deauth_request
*req
)
4309 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4310 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4311 bool tx
= !req
->local_state_change
;
4312 bool report_frame
= false;
4315 "deauthenticating from %pM by local choice (reason=%d)\n",
4316 req
->bssid
, req
->reason_code
);
4318 if (ifmgd
->auth_data
) {
4319 drv_mgd_prepare_tx(sdata
->local
, sdata
);
4320 ieee80211_send_deauth_disassoc(sdata
, req
->bssid
,
4321 IEEE80211_STYPE_DEAUTH
,
4322 req
->reason_code
, tx
,
4324 ieee80211_destroy_auth_data(sdata
, false);
4326 report_frame
= true;
4330 if (ifmgd
->associated
&&
4331 ether_addr_equal(ifmgd
->associated
->bssid
, req
->bssid
)) {
4332 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DEAUTH
,
4333 req
->reason_code
, tx
, frame_buf
);
4334 report_frame
= true;
4339 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4340 IEEE80211_DEAUTH_FRAME_LEN
);
4345 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
4346 struct cfg80211_disassoc_request
*req
)
4348 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4350 u8 frame_buf
[IEEE80211_DEAUTH_FRAME_LEN
];
4353 * cfg80211 should catch this ... but it's racy since
4354 * we can receive a disassoc frame, process it, hand it
4355 * to cfg80211 while that's in a locked section already
4356 * trying to tell us that the user wants to disconnect.
4358 if (ifmgd
->associated
!= req
->bss
)
4362 "disassociating from %pM by local choice (reason=%d)\n",
4363 req
->bss
->bssid
, req
->reason_code
);
4365 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
4366 ieee80211_set_disassoc(sdata
, IEEE80211_STYPE_DISASSOC
,
4367 req
->reason_code
, !req
->local_state_change
,
4370 cfg80211_tx_mlme_mgmt(sdata
->dev
, frame_buf
,
4371 IEEE80211_DEAUTH_FRAME_LEN
);
4376 void ieee80211_mgd_stop(struct ieee80211_sub_if_data
*sdata
)
4378 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
4381 * Make sure some work items will not run after this,
4382 * they will not do anything but might not have been
4383 * cancelled when disconnecting.
4385 cancel_work_sync(&ifmgd
->monitor_work
);
4386 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
4387 cancel_work_sync(&ifmgd
->request_smps_work
);
4388 cancel_work_sync(&ifmgd
->csa_connection_drop_work
);
4389 cancel_work_sync(&ifmgd
->chswitch_work
);
4392 if (ifmgd
->assoc_data
) {
4393 struct cfg80211_bss
*bss
= ifmgd
->assoc_data
->bss
;
4394 ieee80211_destroy_assoc_data(sdata
, false);
4395 cfg80211_assoc_timeout(sdata
->dev
, bss
);
4397 if (ifmgd
->auth_data
)
4398 ieee80211_destroy_auth_data(sdata
, false);
4399 del_timer_sync(&ifmgd
->timer
);
4400 sdata_unlock(sdata
);
4403 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
4404 enum nl80211_cqm_rssi_threshold_event rssi_event
,
4407 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
4409 trace_api_cqm_rssi_notify(sdata
, rssi_event
);
4411 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, gfp
);
4413 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);