1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2020 Intel Corporation
14 #include <linux/delay.h>
15 #include <linux/fips.h>
16 #include <linux/if_ether.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/etherdevice.h>
20 #include <linux/moduleparam.h>
21 #include <linux/rtnetlink.h>
22 #include <linux/crc32.h>
23 #include <linux/slab.h>
24 #include <linux/export.h>
25 #include <net/mac80211.h>
26 #include <asm/unaligned.h>
28 #include "ieee80211_i.h"
29 #include "driver-ops.h"
32 #include "fils_aead.h"
34 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
35 #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
36 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
37 #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
38 #define IEEE80211_AUTH_MAX_TRIES 3
39 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
40 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
41 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
42 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
43 #define IEEE80211_ASSOC_MAX_TRIES 3
45 static int max_nullfunc_tries = 2;
46 module_param(max_nullfunc_tries, int, 0644);
47 MODULE_PARM_DESC(max_nullfunc_tries,
48 "Maximum nullfunc tx tries before disconnecting (reason 4).");
50 static int max_probe_tries = 5;
51 module_param(max_probe_tries, int, 0644);
52 MODULE_PARM_DESC(max_probe_tries,
53 "Maximum probe tries before disconnecting (reason 4).");
56 * Beacon loss timeout is calculated as N frames times the
57 * advertised beacon interval. This may need to be somewhat
58 * higher than what hardware might detect to account for
59 * delays in the host processing frames. But since we also
60 * probe on beacon miss before declaring the connection lost
61 * default to what we want.
63 static int beacon_loss_count = 7;
64 module_param(beacon_loss_count, int, 0644);
65 MODULE_PARM_DESC(beacon_loss_count,
66 "Number of beacon intervals before we decide beacon was lost.");
69 * Time the connection can be idle before we probe
70 * it to see if we can still talk to the AP.
72 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
74 * Time we wait for a probe response after sending
75 * a probe request because of beacon loss or for
76 * checking the connection still works.
78 static int probe_wait_ms = 500;
79 module_param(probe_wait_ms, int, 0644);
80 MODULE_PARM_DESC(probe_wait_ms,
81 "Maximum time(ms) to wait for probe response"
82 " before disconnecting (reason 4).");
85 * How many Beacon frames need to have been used in average signal strength
86 * before starting to indicate signal change events.
88 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
91 * We can have multiple work items (and connection probing)
92 * scheduling this timer, but we need to take care to only
93 * reschedule it when it should fire _earlier_ than it was
94 * asked for before, or if it's not pending right now. This
95 * function ensures that. Note that it then is required to
96 * run this function for all timeouts after the first one
97 * has happened -- the work that runs from this timer will
100 static void run_again(struct ieee80211_sub_if_data *sdata,
101 unsigned long timeout)
103 sdata_assert_lock(sdata);
105 if (!timer_pending(&sdata->u.mgd.timer) ||
106 time_before(timeout, sdata->u.mgd.timer.expires))
107 mod_timer(&sdata->u.mgd.timer, timeout);
110 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
112 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
115 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
118 mod_timer(&sdata->u.mgd.bcn_mon_timer,
119 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
122 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
126 if (unlikely(!ifmgd->associated))
129 if (ifmgd->probe_send_count)
130 ifmgd->probe_send_count = 0;
132 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
135 mod_timer(&ifmgd->conn_mon_timer,
136 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
139 static int ecw2cw(int ecw)
141 return (1 << ecw) - 1;
145 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
146 struct ieee80211_supported_band *sband,
147 struct ieee80211_channel *channel,
149 const struct ieee80211_ht_operation *ht_oper,
150 const struct ieee80211_vht_operation *vht_oper,
151 const struct ieee80211_he_operation *he_oper,
152 const struct ieee80211_s1g_oper_ie *s1g_oper,
153 struct cfg80211_chan_def *chandef, bool tracking)
155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
156 struct cfg80211_chan_def vht_chandef;
157 struct ieee80211_sta_ht_cap sta_ht_cap;
160 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
161 chandef->chan = channel;
162 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
163 chandef->center_freq1 = channel->center_freq;
164 chandef->freq1_offset = channel->freq_offset;
166 if (channel->band == NL80211_BAND_6GHZ) {
167 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, chandef))
168 ret = IEEE80211_STA_DISABLE_HT |
169 IEEE80211_STA_DISABLE_VHT |
170 IEEE80211_STA_DISABLE_HE;
173 vht_chandef = *chandef;
175 } else if (sband->band == NL80211_BAND_S1GHZ) {
176 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
178 "Missing S1G Operation Element? Trying operating == primary\n");
179 chandef->width = ieee80211_s1g_channel_width(channel);
182 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_40MHZ |
183 IEEE80211_STA_DISABLE_VHT |
184 IEEE80211_STA_DISABLE_80P80MHZ |
185 IEEE80211_STA_DISABLE_160MHZ;
189 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
190 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
192 if (!ht_oper || !sta_ht_cap.ht_supported) {
193 ret = IEEE80211_STA_DISABLE_HT |
194 IEEE80211_STA_DISABLE_VHT |
195 IEEE80211_STA_DISABLE_HE;
199 chandef->width = NL80211_CHAN_WIDTH_20;
201 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
203 /* check that channel matches the right operating channel */
204 if (!tracking && channel->center_freq != ht_cfreq) {
206 * It's possible that some APs are confused here;
207 * Netgear WNDR3700 sometimes reports 4 higher than
208 * the actual channel in association responses, but
209 * since we look at probe response/beacon data here
213 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
214 channel->center_freq, ht_cfreq,
215 ht_oper->primary_chan, channel->band);
216 ret = IEEE80211_STA_DISABLE_HT |
217 IEEE80211_STA_DISABLE_VHT |
218 IEEE80211_STA_DISABLE_HE;
222 /* check 40 MHz support, if we have it */
223 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
224 ieee80211_chandef_ht_oper(ht_oper, chandef);
226 /* 40 MHz (and 80 MHz) must be supported for VHT */
227 ret = IEEE80211_STA_DISABLE_VHT;
228 /* also mark 40 MHz disabled */
229 ret |= IEEE80211_STA_DISABLE_40MHZ;
233 if (!vht_oper || !sband->vht_cap.vht_supported) {
234 ret = IEEE80211_STA_DISABLE_VHT;
238 vht_chandef = *chandef;
239 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
240 (le32_to_cpu(he_oper->he_oper_params) &
241 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
242 struct ieee80211_vht_operation he_oper_vht_cap;
245 * Set only first 3 bytes (other 2 aren't used in
246 * ieee80211_chandef_vht_oper() anyway)
248 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
249 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
251 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
252 &he_oper_vht_cap, ht_oper,
254 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
256 "HE AP VHT information is invalid, disable HE\n");
257 ret = IEEE80211_STA_DISABLE_HE;
260 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
264 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
266 "AP VHT information is invalid, disable VHT\n");
267 ret = IEEE80211_STA_DISABLE_VHT;
271 if (!cfg80211_chandef_valid(&vht_chandef)) {
272 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
274 "AP VHT information is invalid, disable VHT\n");
275 ret = IEEE80211_STA_DISABLE_VHT;
279 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
284 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
285 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
287 "AP VHT information doesn't match HT, disable VHT\n");
288 ret = IEEE80211_STA_DISABLE_VHT;
292 *chandef = vht_chandef;
298 * When tracking the current AP, don't do any further checks if the
299 * new chandef is identical to the one we're currently using for the
300 * connection. This keeps us from playing ping-pong with regulatory,
301 * without it the following can happen (for example):
302 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
303 * - AP advertises regdom US
304 * - CRDA loads regdom US with 80 MHz prohibited (old database)
305 * - the code below detects an unsupported channel, downgrades, and
306 * we disconnect from the AP in the caller
307 * - disconnect causes CRDA to reload world regdomain and the game
309 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
311 * It seems possible that there are still scenarios with CSA or real
312 * bandwidth changes where a this could happen, but those cases are
313 * less common and wouldn't completely prevent using the AP.
316 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
319 /* don't print the message below for VHT mismatch if VHT is disabled */
320 if (ret & IEEE80211_STA_DISABLE_VHT)
321 vht_chandef = *chandef;
324 * Ignore the DISABLED flag when we're already connected and only
325 * tracking the APs beacon for bandwidth changes - otherwise we
326 * might get disconnected here if we connect to an AP, update our
327 * regulatory information based on the AP's country IE and the
328 * information we have is wrong/outdated and disables the channel
329 * that we're actually using for the connection to the AP.
331 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
333 IEEE80211_CHAN_DISABLED)) {
334 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
335 ret = IEEE80211_STA_DISABLE_HT |
336 IEEE80211_STA_DISABLE_VHT |
337 IEEE80211_STA_DISABLE_HE;
341 ret |= ieee80211_chandef_downgrade(chandef);
344 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
345 IEEE80211_CHAN_NO_HE))
346 ret |= IEEE80211_STA_DISABLE_HE;
348 if (chandef->width != vht_chandef.width && !tracking)
350 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
352 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
356 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
357 struct sta_info *sta,
358 const struct ieee80211_ht_cap *ht_cap,
359 const struct ieee80211_vht_cap *vht_cap,
360 const struct ieee80211_ht_operation *ht_oper,
361 const struct ieee80211_vht_operation *vht_oper,
362 const struct ieee80211_he_operation *he_oper,
363 const struct ieee80211_s1g_oper_ie *s1g_oper,
364 const u8 *bssid, u32 *changed)
366 struct ieee80211_local *local = sdata->local;
367 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
368 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
369 struct ieee80211_supported_band *sband =
370 local->hw.wiphy->bands[chan->band];
371 struct cfg80211_chan_def chandef;
374 enum ieee80211_sta_rx_bandwidth new_sta_bw;
375 u32 vht_cap_info = 0;
378 /* if HT was/is disabled, don't track any bandwidth changes */
379 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
382 /* don't check VHT if we associated as non-VHT station */
383 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
386 /* don't check HE if we associated as non-HE station */
387 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
388 !ieee80211_get_he_sta_cap(sband))
391 if (WARN_ON_ONCE(!sta))
395 * if bss configuration changed store the new one -
396 * this may be applicable even if channel is identical
398 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
399 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
400 *changed |= BSS_CHANGED_HT;
401 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
405 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
407 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
408 flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info,
409 ht_oper, vht_oper, he_oper,
410 s1g_oper, &chandef, true);
413 * Downgrade the new channel if we associated with restricted
414 * capabilities. For example, if we associated as a 20 MHz STA
415 * to a 40 MHz AP (due to regulatory, capabilities or config
416 * reasons) then switching to a 40 MHz channel now won't do us
417 * any good -- we couldn't use it with the AP.
419 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
420 chandef.width == NL80211_CHAN_WIDTH_80P80)
421 flags |= ieee80211_chandef_downgrade(&chandef);
422 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
423 chandef.width == NL80211_CHAN_WIDTH_160)
424 flags |= ieee80211_chandef_downgrade(&chandef);
425 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
426 chandef.width > NL80211_CHAN_WIDTH_20)
427 flags |= ieee80211_chandef_downgrade(&chandef);
429 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
433 "AP %pM changed bandwidth, new config is %d.%03d MHz, "
434 "width %d (%d.%03d/%d MHz)\n",
435 ifmgd->bssid, chandef.chan->center_freq,
436 chandef.chan->freq_offset, chandef.width,
437 chandef.center_freq1, chandef.freq1_offset,
438 chandef.center_freq2);
440 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
441 IEEE80211_STA_DISABLE_VHT |
442 IEEE80211_STA_DISABLE_HE |
443 IEEE80211_STA_DISABLE_40MHZ |
444 IEEE80211_STA_DISABLE_80P80MHZ |
445 IEEE80211_STA_DISABLE_160MHZ)) ||
446 !cfg80211_chandef_valid(&chandef)) {
448 "AP %pM changed bandwidth in a way we can't support - disconnect\n",
453 switch (chandef.width) {
454 case NL80211_CHAN_WIDTH_20_NOHT:
455 case NL80211_CHAN_WIDTH_20:
456 new_sta_bw = IEEE80211_STA_RX_BW_20;
458 case NL80211_CHAN_WIDTH_40:
459 new_sta_bw = IEEE80211_STA_RX_BW_40;
461 case NL80211_CHAN_WIDTH_80:
462 new_sta_bw = IEEE80211_STA_RX_BW_80;
464 case NL80211_CHAN_WIDTH_80P80:
465 case NL80211_CHAN_WIDTH_160:
466 new_sta_bw = IEEE80211_STA_RX_BW_160;
472 if (new_sta_bw > sta->cur_max_bandwidth)
473 new_sta_bw = sta->cur_max_bandwidth;
475 if (new_sta_bw < sta->sta.bandwidth) {
476 sta->sta.bandwidth = new_sta_bw;
477 rate_control_rate_update(local, sband, sta,
478 IEEE80211_RC_BW_CHANGED);
481 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
484 "AP %pM changed bandwidth to incompatible one - disconnect\n",
489 if (new_sta_bw > sta->sta.bandwidth) {
490 sta->sta.bandwidth = new_sta_bw;
491 rate_control_rate_update(local, sband, sta,
492 IEEE80211_RC_BW_CHANGED);
498 /* frame sending functions */
500 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
501 struct sk_buff *skb, u8 ap_ht_param,
502 struct ieee80211_supported_band *sband,
503 struct ieee80211_channel *channel,
504 enum ieee80211_smps_mode smps)
507 u32 flags = channel->flags;
509 struct ieee80211_sta_ht_cap ht_cap;
511 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
513 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
514 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
516 /* determine capability flags */
519 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
520 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
521 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
522 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
523 cap &= ~IEEE80211_HT_CAP_SGI_40;
526 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
527 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
528 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
529 cap &= ~IEEE80211_HT_CAP_SGI_40;
535 * If 40 MHz was disabled associate as though we weren't
536 * capable of 40 MHz -- some broken APs will never fall
537 * back to trying to transmit in 20 MHz.
539 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
540 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
541 cap &= ~IEEE80211_HT_CAP_SGI_40;
544 /* set SM PS mode properly */
545 cap &= ~IEEE80211_HT_CAP_SM_PS;
547 case IEEE80211_SMPS_AUTOMATIC:
548 case IEEE80211_SMPS_NUM_MODES:
551 case IEEE80211_SMPS_OFF:
552 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
553 IEEE80211_HT_CAP_SM_PS_SHIFT;
555 case IEEE80211_SMPS_STATIC:
556 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
557 IEEE80211_HT_CAP_SM_PS_SHIFT;
559 case IEEE80211_SMPS_DYNAMIC:
560 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
561 IEEE80211_HT_CAP_SM_PS_SHIFT;
565 /* reserve and fill IE */
566 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
567 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
570 /* This function determines vht capability flags for the association
572 * Note - the function may set the owner of the MU-MIMO capability
574 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
576 struct ieee80211_supported_band *sband,
577 struct ieee80211_vht_cap *ap_vht_cap)
579 struct ieee80211_local *local = sdata->local;
582 struct ieee80211_sta_vht_cap vht_cap;
583 u32 mask, ap_bf_sts, our_bf_sts;
585 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
587 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
588 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
590 /* determine capability flags */
593 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
594 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
596 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
597 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
598 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
599 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
602 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
603 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
604 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
608 * Some APs apparently get confused if our capabilities are better
609 * than theirs, so restrict what we advertise in the assoc request.
611 if (!(ap_vht_cap->vht_cap_info &
612 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
613 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
614 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
615 else if (!(ap_vht_cap->vht_cap_info &
616 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
617 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
620 * If some other vif is using the MU-MIMO capablity we cannot associate
621 * using MU-MIMO - this will lead to contradictions in the group-id
623 * Ownership is defined since association request, in order to avoid
624 * simultaneous associations with MU-MIMO.
626 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
627 bool disable_mu_mimo = false;
628 struct ieee80211_sub_if_data *other;
630 list_for_each_entry_rcu(other, &local->interfaces, list) {
631 if (other->vif.mu_mimo_owner) {
632 disable_mu_mimo = true;
637 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
639 sdata->vif.mu_mimo_owner = true;
642 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
644 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
645 our_bf_sts = cap & mask;
647 if (ap_bf_sts < our_bf_sts) {
652 /* reserve and fill IE */
653 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
654 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
657 /* This function determines HE capability flags for the association
660 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
662 struct ieee80211_supported_band *sband)
665 const struct ieee80211_sta_he_cap *he_cap = NULL;
666 struct ieee80211_chanctx_conf *chanctx_conf;
668 bool reg_cap = false;
671 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
672 if (!WARN_ON_ONCE(!chanctx_conf))
673 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
675 IEEE80211_CHAN_NO_HE);
679 he_cap = ieee80211_get_he_sta_cap(sband);
680 if (!he_cap || !reg_cap)
684 * TODO: the 1 added is because this temporarily is under the EXTENSION
685 * IE. Get rid of it when it moves.
688 2 + 1 + sizeof(he_cap->he_cap_elem) +
689 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
690 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
691 he_cap->he_cap_elem.phy_cap_info);
692 pos = skb_put(skb, he_cap_size);
693 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
695 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
698 static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
700 struct ieee80211_local *local = sdata->local;
701 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
702 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
704 struct ieee80211_mgmt *mgmt;
705 u8 *pos, qos_info, *ie_start;
706 size_t offset = 0, noffset;
707 int i, count, rates_len, supp_rates_len, shift;
709 struct ieee80211_supported_band *sband;
710 struct ieee80211_chanctx_conf *chanctx_conf;
711 struct ieee80211_channel *chan;
714 struct element *ext_capa = NULL;
716 /* we know it's writable, cast away the const */
717 if (assoc_data->ie_len)
718 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
722 sdata_assert_lock(sdata);
725 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
726 if (WARN_ON(!chanctx_conf)) {
730 chan = chanctx_conf->def.chan;
732 sband = local->hw.wiphy->bands[chan->band];
733 shift = ieee80211_vif_get_shift(&sdata->vif);
735 if (assoc_data->supp_rates_len) {
737 * Get all rates supported by the device and the AP as
738 * some APs don't like getting a superset of their rates
739 * in the association request (e.g. D-Link DAP 1353 in
742 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
743 assoc_data->supp_rates,
744 assoc_data->supp_rates_len,
748 * In case AP not provide any supported rates information
749 * before association, we send information element(s) with
750 * all rates that we support.
753 for (i = 0; i < sband->n_bitrates; i++) {
759 skb = alloc_skb(local->hw.extra_tx_headroom +
760 sizeof(*mgmt) + /* bit too much but doesn't matter */
761 2 + assoc_data->ssid_len + /* SSID */
762 4 + rates_len + /* (extended) rates */
763 4 + /* power capability */
764 2 + 2 * sband->n_channels + /* supported channels */
765 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
766 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
767 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
768 sizeof(struct ieee80211_he_mcs_nss_supp) +
769 IEEE80211_HE_PPE_THRES_MAX_LEN +
770 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
771 assoc_data->ie_len + /* extra IEs */
772 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
778 skb_reserve(skb, local->hw.extra_tx_headroom);
780 capab = WLAN_CAPABILITY_ESS;
782 if (sband->band == NL80211_BAND_2GHZ) {
783 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
784 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
787 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
788 capab |= WLAN_CAPABILITY_PRIVACY;
790 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
791 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
792 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
794 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
795 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
797 mgmt = skb_put_zero(skb, 24);
798 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
799 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
800 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
802 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
803 ieee80211_encode_usf(local->hw.conf.listen_interval) :
804 local->hw.conf.listen_interval);
805 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
807 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
808 IEEE80211_STYPE_REASSOC_REQ);
809 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
810 mgmt->u.reassoc_req.listen_interval = listen_int;
811 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
815 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
816 IEEE80211_STYPE_ASSOC_REQ);
817 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
818 mgmt->u.assoc_req.listen_interval = listen_int;
822 pos = skb_put(skb, 2 + assoc_data->ssid_len);
824 *pos++ = WLAN_EID_SSID;
825 *pos++ = assoc_data->ssid_len;
826 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
828 if (sband->band == NL80211_BAND_S1GHZ)
831 /* add all rates which were marked to be used above */
832 supp_rates_len = rates_len;
833 if (supp_rates_len > 8)
836 pos = skb_put(skb, supp_rates_len + 2);
837 *pos++ = WLAN_EID_SUPP_RATES;
838 *pos++ = supp_rates_len;
841 for (i = 0; i < sband->n_bitrates; i++) {
842 if (BIT(i) & rates) {
843 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
851 if (rates_len > count) {
852 pos = skb_put(skb, rates_len - count + 2);
853 *pos++ = WLAN_EID_EXT_SUPP_RATES;
854 *pos++ = rates_len - count;
856 for (i++; i < sband->n_bitrates; i++) {
857 if (BIT(i) & rates) {
859 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
867 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
868 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
869 pos = skb_put(skb, 4);
870 *pos++ = WLAN_EID_PWR_CAPABILITY;
872 *pos++ = 0; /* min tx power */
874 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
878 * Per spec, we shouldn't include the list of channels if we advertise
879 * support for extended channel switching, but we've always done that;
880 * (for now?) apply this restriction only on the (new) 6 GHz band.
882 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
883 (sband->band != NL80211_BAND_6GHZ ||
884 !ext_capa || ext_capa->datalen < 1 ||
885 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
886 /* TODO: get this in reg domain format */
887 pos = skb_put(skb, 2 * sband->n_channels + 2);
888 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
889 *pos++ = 2 * sband->n_channels;
890 for (i = 0; i < sband->n_channels; i++) {
891 *pos++ = ieee80211_frequency_to_channel(
892 sband->channels[i].center_freq);
893 *pos++ = 1; /* one channel in the subband*/
897 /* Set MBSSID support for HE AP if needed */
898 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
899 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
900 ext_capa && ext_capa->datalen >= 3)
901 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
903 /* if present, add any custom IEs that go before HT */
904 if (assoc_data->ie_len) {
905 static const u8 before_ht[] = {
908 WLAN_EID_EXT_SUPP_RATES,
909 WLAN_EID_PWR_CAPABILITY,
910 WLAN_EID_SUPPORTED_CHANNELS,
913 WLAN_EID_RRM_ENABLED_CAPABILITIES,
914 WLAN_EID_MOBILITY_DOMAIN,
915 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
916 WLAN_EID_RIC_DATA, /* reassoc only */
917 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
919 static const u8 after_ric[] = {
920 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
921 WLAN_EID_HT_CAPABILITY,
922 WLAN_EID_BSS_COEX_2040,
923 /* luckily this is almost always there */
924 WLAN_EID_EXT_CAPABILITY,
925 WLAN_EID_QOS_TRAFFIC_CAPA,
926 WLAN_EID_TIM_BCAST_REQ,
927 WLAN_EID_INTERWORKING,
928 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
929 WLAN_EID_VHT_CAPABILITY,
930 WLAN_EID_OPMODE_NOTIF,
933 noffset = ieee80211_ie_split_ric(assoc_data->ie,
936 ARRAY_SIZE(before_ht),
938 ARRAY_SIZE(after_ric),
940 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
944 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
945 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
946 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
948 if (sband->band != NL80211_BAND_6GHZ &&
949 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
950 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
951 sband, chan, sdata->smps_mode);
953 /* if present, add any custom IEs that go before VHT */
954 if (assoc_data->ie_len) {
955 static const u8 before_vht[] = {
957 * no need to list the ones split off before HT
960 WLAN_EID_BSS_COEX_2040,
961 WLAN_EID_EXT_CAPABILITY,
962 WLAN_EID_QOS_TRAFFIC_CAPA,
963 WLAN_EID_TIM_BCAST_REQ,
964 WLAN_EID_INTERWORKING,
965 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
968 /* RIC already taken above, so no need to handle here anymore */
969 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
970 before_vht, ARRAY_SIZE(before_vht),
972 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
976 /* if present, add any custom IEs that go before HE */
977 if (assoc_data->ie_len) {
978 static const u8 before_he[] = {
980 * no need to list the ones split off before VHT
983 WLAN_EID_OPMODE_NOTIF,
984 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
986 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
987 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
988 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
989 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
990 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
991 /* TODO: add 11ah/11aj/11ak elements */
994 /* RIC already taken above, so no need to handle here anymore */
995 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
996 before_he, ARRAY_SIZE(before_he),
998 pos = skb_put(skb, noffset - offset);
999 memcpy(pos, assoc_data->ie + offset, noffset - offset);
1003 if (sband->band != NL80211_BAND_6GHZ &&
1004 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
1005 ieee80211_add_vht_ie(sdata, skb, sband,
1006 &assoc_data->ap_vht_cap);
1009 * If AP doesn't support HT, mark HE as disabled.
1010 * If on the 5GHz band, make sure it supports VHT.
1012 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
1013 (sband->band == NL80211_BAND_5GHZ &&
1014 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
1015 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
1017 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
1018 ieee80211_add_he_ie(sdata, skb, sband);
1020 /* if present, add any custom non-vendor IEs that go after HE */
1021 if (assoc_data->ie_len) {
1022 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1025 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1029 if (assoc_data->wmm) {
1030 if (assoc_data->uapsd) {
1031 qos_info = ifmgd->uapsd_queues;
1032 qos_info |= (ifmgd->uapsd_max_sp_len <<
1033 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1038 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1041 if (sband->band == NL80211_BAND_S1GHZ) {
1042 ieee80211_add_aid_request_ie(sdata, skb);
1043 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1046 /* add any remaining custom (i.e. vendor specific here) IEs */
1047 if (assoc_data->ie_len) {
1048 noffset = assoc_data->ie_len;
1049 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1052 if (assoc_data->fils_kek_len &&
1053 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
1058 pos = skb_tail_pointer(skb);
1059 kfree(ifmgd->assoc_req_ies);
1060 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1061 ifmgd->assoc_req_ies_len = pos - ie_start;
1063 drv_mgd_prepare_tx(local, sdata, 0);
1065 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1066 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1067 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1068 IEEE80211_TX_INTFL_MLME_CONN_TX;
1069 ieee80211_tx_skb(sdata, skb);
1072 void ieee80211_send_pspoll(struct ieee80211_local *local,
1073 struct ieee80211_sub_if_data *sdata)
1075 struct ieee80211_pspoll *pspoll;
1076 struct sk_buff *skb;
1078 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1082 pspoll = (struct ieee80211_pspoll *) skb->data;
1083 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1085 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1086 ieee80211_tx_skb(sdata, skb);
1089 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1090 struct ieee80211_sub_if_data *sdata,
1093 struct sk_buff *skb;
1094 struct ieee80211_hdr_3addr *nullfunc;
1095 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1097 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1098 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1102 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1104 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1106 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1107 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1109 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1110 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1112 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1113 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1115 ieee80211_tx_skb(sdata, skb);
1118 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1119 struct ieee80211_sub_if_data *sdata)
1121 struct sk_buff *skb;
1122 struct ieee80211_hdr *nullfunc;
1125 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1128 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1132 skb_reserve(skb, local->hw.extra_tx_headroom);
1134 nullfunc = skb_put_zero(skb, 30);
1135 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1136 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1137 nullfunc->frame_control = fc;
1138 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1139 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1140 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1141 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1143 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1144 ieee80211_tx_skb(sdata, skb);
1147 /* spectrum management related things */
1148 static void ieee80211_chswitch_work(struct work_struct *work)
1150 struct ieee80211_sub_if_data *sdata =
1151 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1152 struct ieee80211_local *local = sdata->local;
1153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1156 if (!ieee80211_sdata_running(sdata))
1160 mutex_lock(&local->mtx);
1161 mutex_lock(&local->chanctx_mtx);
1163 if (!ifmgd->associated)
1166 if (!sdata->vif.csa_active)
1170 * using reservation isn't immediate as it may be deferred until later
1171 * with multi-vif. once reservation is complete it will re-schedule the
1172 * work with no reserved_chanctx so verify chandef to check if it
1173 * completed successfully
1176 if (sdata->reserved_chanctx) {
1177 struct ieee80211_supported_band *sband = NULL;
1178 struct sta_info *mgd_sta = NULL;
1179 enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
1182 * with multi-vif csa driver may call ieee80211_csa_finish()
1183 * many times while waiting for other interfaces to use their
1186 if (sdata->reserved_ready)
1189 if (sdata->vif.bss_conf.chandef.width !=
1190 sdata->csa_chandef.width) {
1192 * For managed interface, we need to also update the AP
1193 * station bandwidth and align the rate scale algorithm
1194 * on the bandwidth change. Here we only consider the
1195 * bandwidth of the new channel definition (as channel
1196 * switch flow does not have the full HT/VHT/HE
1197 * information), assuming that if additional changes are
1198 * required they would be done as part of the processing
1199 * of the next beacon from the AP.
1201 switch (sdata->csa_chandef.width) {
1202 case NL80211_CHAN_WIDTH_20_NOHT:
1203 case NL80211_CHAN_WIDTH_20:
1205 bw = IEEE80211_STA_RX_BW_20;
1207 case NL80211_CHAN_WIDTH_40:
1208 bw = IEEE80211_STA_RX_BW_40;
1210 case NL80211_CHAN_WIDTH_80:
1211 bw = IEEE80211_STA_RX_BW_80;
1213 case NL80211_CHAN_WIDTH_80P80:
1214 case NL80211_CHAN_WIDTH_160:
1215 bw = IEEE80211_STA_RX_BW_160;
1219 mgd_sta = sta_info_get(sdata, ifmgd->bssid);
1221 local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
1224 if (sdata->vif.bss_conf.chandef.width >
1225 sdata->csa_chandef.width) {
1226 mgd_sta->sta.bandwidth = bw;
1227 rate_control_rate_update(local, sband, mgd_sta,
1228 IEEE80211_RC_BW_CHANGED);
1231 ret = ieee80211_vif_use_reserved_context(sdata);
1234 "failed to use reserved channel context, disconnecting (err=%d)\n",
1236 ieee80211_queue_work(&sdata->local->hw,
1237 &ifmgd->csa_connection_drop_work);
1241 if (sdata->vif.bss_conf.chandef.width <
1242 sdata->csa_chandef.width) {
1243 mgd_sta->sta.bandwidth = bw;
1244 rate_control_rate_update(local, sband, mgd_sta,
1245 IEEE80211_RC_BW_CHANGED);
1251 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1252 &sdata->csa_chandef)) {
1254 "failed to finalize channel switch, disconnecting\n");
1255 ieee80211_queue_work(&sdata->local->hw,
1256 &ifmgd->csa_connection_drop_work);
1260 ifmgd->csa_waiting_bcn = true;
1262 ieee80211_sta_reset_beacon_monitor(sdata);
1263 ieee80211_sta_reset_conn_monitor(sdata);
1266 mutex_unlock(&local->chanctx_mtx);
1267 mutex_unlock(&local->mtx);
1268 sdata_unlock(sdata);
1271 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1273 struct ieee80211_local *local = sdata->local;
1274 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1277 sdata_assert_lock(sdata);
1279 WARN_ON(!sdata->vif.csa_active);
1281 if (sdata->csa_block_tx) {
1282 ieee80211_wake_vif_queues(local, sdata,
1283 IEEE80211_QUEUE_STOP_REASON_CSA);
1284 sdata->csa_block_tx = false;
1287 sdata->vif.csa_active = false;
1288 ifmgd->csa_waiting_bcn = false;
1290 * If the CSA IE is still present on the beacon after the switch,
1291 * we need to consider it as a new CSA (possibly to self).
1293 ifmgd->beacon_crc_valid = false;
1295 ret = drv_post_channel_switch(sdata);
1298 "driver post channel switch failed, disconnecting\n");
1299 ieee80211_queue_work(&local->hw,
1300 &ifmgd->csa_connection_drop_work);
1304 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1307 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1309 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1310 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1312 trace_api_chswitch_done(sdata, success);
1315 "driver channel switch failed, disconnecting\n");
1316 ieee80211_queue_work(&sdata->local->hw,
1317 &ifmgd->csa_connection_drop_work);
1319 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1322 EXPORT_SYMBOL(ieee80211_chswitch_done);
1324 static void ieee80211_chswitch_timer(struct timer_list *t)
1326 struct ieee80211_sub_if_data *sdata =
1327 from_timer(sdata, t, u.mgd.chswitch_timer);
1329 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1333 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1335 struct ieee80211_local *local = sdata->local;
1337 if (!local->ops->abort_channel_switch)
1340 mutex_lock(&local->mtx);
1342 mutex_lock(&local->chanctx_mtx);
1343 ieee80211_vif_unreserve_chanctx(sdata);
1344 mutex_unlock(&local->chanctx_mtx);
1346 if (sdata->csa_block_tx)
1347 ieee80211_wake_vif_queues(local, sdata,
1348 IEEE80211_QUEUE_STOP_REASON_CSA);
1350 sdata->csa_block_tx = false;
1351 sdata->vif.csa_active = false;
1353 mutex_unlock(&local->mtx);
1355 drv_abort_channel_switch(sdata);
1359 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1360 u64 timestamp, u32 device_timestamp,
1361 struct ieee802_11_elems *elems,
1364 struct ieee80211_local *local = sdata->local;
1365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1366 struct cfg80211_bss *cbss = ifmgd->associated;
1367 struct ieee80211_chanctx_conf *conf;
1368 struct ieee80211_chanctx *chanctx;
1369 enum nl80211_band current_band;
1370 struct ieee80211_csa_ie csa_ie;
1371 struct ieee80211_channel_switch ch_switch;
1372 struct ieee80211_bss *bss;
1375 sdata_assert_lock(sdata);
1380 if (local->scanning)
1383 current_band = cbss->channel->band;
1384 bss = (void *)cbss->priv;
1385 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1388 ifmgd->associated->bssid, &csa_ie);
1391 ch_switch.timestamp = timestamp;
1392 ch_switch.device_timestamp = device_timestamp;
1393 ch_switch.block_tx = csa_ie.mode;
1394 ch_switch.chandef = csa_ie.chandef;
1395 ch_switch.count = csa_ie.count;
1396 ch_switch.delay = csa_ie.max_switch_time;
1400 goto lock_and_drop_connection;
1402 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1404 ieee80211_sta_abort_chanswitch(sdata);
1406 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1408 } else if (sdata->vif.csa_active || res) {
1409 /* disregard subsequent announcements if already processing */
1413 if (sdata->vif.bss_conf.chandef.chan->band !=
1414 csa_ie.chandef.chan->band) {
1416 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1417 ifmgd->associated->bssid,
1418 csa_ie.chandef.chan->center_freq,
1419 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1420 csa_ie.chandef.center_freq2);
1421 goto lock_and_drop_connection;
1424 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1425 IEEE80211_CHAN_DISABLED)) {
1427 "AP %pM switches to unsupported channel "
1428 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1430 ifmgd->associated->bssid,
1431 csa_ie.chandef.chan->center_freq,
1432 csa_ie.chandef.chan->freq_offset,
1433 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1434 csa_ie.chandef.freq1_offset,
1435 csa_ie.chandef.center_freq2);
1436 goto lock_and_drop_connection;
1439 if (cfg80211_chandef_identical(&csa_ie.chandef,
1440 &sdata->vif.bss_conf.chandef) &&
1441 (!csa_ie.mode || !beacon)) {
1442 if (ifmgd->csa_ignored_same_chan)
1445 "AP %pM tries to chanswitch to same channel, ignore\n",
1446 ifmgd->associated->bssid);
1447 ifmgd->csa_ignored_same_chan = true;
1452 * Drop all TDLS peers - either we disconnect or move to a different
1453 * channel from this point on. There's no telling what our peer will do.
1454 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1455 * have an incompatible wider chandef.
1457 ieee80211_teardown_tdls_peers(sdata);
1459 mutex_lock(&local->mtx);
1460 mutex_lock(&local->chanctx_mtx);
1461 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1462 lockdep_is_held(&local->chanctx_mtx));
1465 "no channel context assigned to vif?, disconnecting\n");
1466 goto drop_connection;
1469 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1471 if (local->use_chanctx &&
1472 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1474 "driver doesn't support chan-switch with channel contexts\n");
1475 goto drop_connection;
1478 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1480 "preparing for channel switch failed, disconnecting\n");
1481 goto drop_connection;
1484 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1485 chanctx->mode, false);
1488 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1490 goto drop_connection;
1492 mutex_unlock(&local->chanctx_mtx);
1494 sdata->vif.csa_active = true;
1495 sdata->csa_chandef = csa_ie.chandef;
1496 sdata->csa_block_tx = csa_ie.mode;
1497 ifmgd->csa_ignored_same_chan = false;
1498 ifmgd->beacon_crc_valid = false;
1500 if (sdata->csa_block_tx)
1501 ieee80211_stop_vif_queues(local, sdata,
1502 IEEE80211_QUEUE_STOP_REASON_CSA);
1503 mutex_unlock(&local->mtx);
1505 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1506 csa_ie.count, csa_ie.mode);
1508 if (local->ops->channel_switch) {
1509 /* use driver's channel switch callback */
1510 drv_channel_switch(local, sdata, &ch_switch);
1514 /* channel switch handled in software */
1515 if (csa_ie.count <= 1)
1516 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1518 mod_timer(&ifmgd->chswitch_timer,
1519 TU_TO_EXP_TIME((csa_ie.count - 1) *
1520 cbss->beacon_interval));
1522 lock_and_drop_connection:
1523 mutex_lock(&local->mtx);
1524 mutex_lock(&local->chanctx_mtx);
1527 * This is just so that the disconnect flow will know that
1528 * we were trying to switch channel and failed. In case the
1529 * mode is 1 (we are not allowed to Tx), we will know not to
1530 * send a deauthentication frame. Those two fields will be
1531 * reset when the disconnection worker runs.
1533 sdata->vif.csa_active = true;
1534 sdata->csa_block_tx = csa_ie.mode;
1536 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1537 mutex_unlock(&local->chanctx_mtx);
1538 mutex_unlock(&local->mtx);
1542 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1543 struct ieee80211_channel *channel,
1544 const u8 *country_ie, u8 country_ie_len,
1545 const u8 *pwr_constr_elem,
1546 int *chan_pwr, int *pwr_reduction)
1548 struct ieee80211_country_ie_triplet *triplet;
1549 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1550 int i, chan_increment;
1551 bool have_chan_pwr = false;
1554 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1557 triplet = (void *)(country_ie + 3);
1558 country_ie_len -= 3;
1560 switch (channel->band) {
1564 case NL80211_BAND_2GHZ:
1565 case NL80211_BAND_60GHZ:
1568 case NL80211_BAND_5GHZ:
1571 case NL80211_BAND_6GHZ:
1573 * In the 6 GHz band, the "maximum transmit power level"
1574 * field in the triplets is reserved, and thus will be
1575 * zero and we shouldn't use it to control TX power.
1576 * The actual TX power will be given in the transmit
1577 * power envelope element instead.
1583 while (country_ie_len >= 3) {
1584 u8 first_channel = triplet->chans.first_channel;
1586 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1589 for (i = 0; i < triplet->chans.num_channels; i++) {
1590 if (first_channel + i * chan_increment == chan) {
1591 have_chan_pwr = true;
1592 *chan_pwr = triplet->chans.max_power;
1601 country_ie_len -= 3;
1604 if (have_chan_pwr && pwr_constr_elem)
1605 *pwr_reduction = *pwr_constr_elem;
1609 return have_chan_pwr;
1612 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1613 struct ieee80211_channel *channel,
1614 const u8 *cisco_dtpc_ie,
1617 /* From practical testing, the first data byte of the DTPC element
1618 * seems to contain the requested dBm level, and the CLI on Cisco
1619 * APs clearly state the range is -127 to 127 dBm, which indicates
1620 * a signed byte, although it seemingly never actually goes negative.
1621 * The other byte seems to always be zero.
1623 *pwr_level = (__s8)cisco_dtpc_ie[4];
1626 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1627 struct ieee80211_channel *channel,
1628 struct ieee80211_mgmt *mgmt,
1629 const u8 *country_ie, u8 country_ie_len,
1630 const u8 *pwr_constr_ie,
1631 const u8 *cisco_dtpc_ie)
1633 bool has_80211h_pwr = false, has_cisco_pwr = false;
1634 int chan_pwr = 0, pwr_reduction_80211h = 0;
1635 int pwr_level_cisco, pwr_level_80211h;
1637 __le16 capab = mgmt->u.probe_resp.capab_info;
1639 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1640 return 0; /* TODO */
1643 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1644 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1645 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1646 sdata, channel, country_ie, country_ie_len,
1647 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1649 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1652 if (cisco_dtpc_ie) {
1653 ieee80211_find_cisco_dtpc(
1654 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1655 has_cisco_pwr = true;
1658 if (!has_80211h_pwr && !has_cisco_pwr)
1661 /* If we have both 802.11h and Cisco DTPC, apply both limits
1662 * by picking the smallest of the two power levels advertised.
1664 if (has_80211h_pwr &&
1665 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1666 new_ap_level = pwr_level_80211h;
1668 if (sdata->ap_power_level == new_ap_level)
1672 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1673 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1674 sdata->u.mgd.bssid);
1675 } else { /* has_cisco_pwr is always true here. */
1676 new_ap_level = pwr_level_cisco;
1678 if (sdata->ap_power_level == new_ap_level)
1682 "Limiting TX power to %d dBm as advertised by %pM\n",
1683 pwr_level_cisco, sdata->u.mgd.bssid);
1686 sdata->ap_power_level = new_ap_level;
1687 if (__ieee80211_recalc_txpower(sdata))
1688 return BSS_CHANGED_TXPOWER;
1693 static void ieee80211_enable_ps(struct ieee80211_local *local,
1694 struct ieee80211_sub_if_data *sdata)
1696 struct ieee80211_conf *conf = &local->hw.conf;
1699 * If we are scanning right now then the parameters will
1700 * take effect when scan finishes.
1702 if (local->scanning)
1705 if (conf->dynamic_ps_timeout > 0 &&
1706 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1707 mod_timer(&local->dynamic_ps_timer, jiffies +
1708 msecs_to_jiffies(conf->dynamic_ps_timeout));
1710 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1711 ieee80211_send_nullfunc(local, sdata, true);
1713 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1714 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1717 conf->flags |= IEEE80211_CONF_PS;
1718 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1722 static void ieee80211_change_ps(struct ieee80211_local *local)
1724 struct ieee80211_conf *conf = &local->hw.conf;
1726 if (local->ps_sdata) {
1727 ieee80211_enable_ps(local, local->ps_sdata);
1728 } else if (conf->flags & IEEE80211_CONF_PS) {
1729 conf->flags &= ~IEEE80211_CONF_PS;
1730 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1731 del_timer_sync(&local->dynamic_ps_timer);
1732 cancel_work_sync(&local->dynamic_ps_enable_work);
1736 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1738 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1739 struct sta_info *sta = NULL;
1740 bool authorized = false;
1742 if (!mgd->powersave)
1748 if (!mgd->associated)
1751 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1754 if (!mgd->have_beacon)
1758 sta = sta_info_get(sdata, mgd->bssid);
1760 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1766 /* need to hold RTNL or interface lock */
1767 void ieee80211_recalc_ps(struct ieee80211_local *local)
1769 struct ieee80211_sub_if_data *sdata, *found = NULL;
1773 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1774 local->ps_sdata = NULL;
1778 list_for_each_entry(sdata, &local->interfaces, list) {
1779 if (!ieee80211_sdata_running(sdata))
1781 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1782 /* If an AP vif is found, then disable PS
1783 * by setting the count to zero thereby setting
1789 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1795 if (count == 1 && ieee80211_powersave_allowed(found)) {
1796 u8 dtimper = found->u.mgd.dtim_period;
1798 timeout = local->dynamic_ps_forced_timeout;
1801 local->hw.conf.dynamic_ps_timeout = timeout;
1803 /* If the TIM IE is invalid, pretend the value is 1 */
1807 local->hw.conf.ps_dtim_period = dtimper;
1808 local->ps_sdata = found;
1810 local->ps_sdata = NULL;
1813 ieee80211_change_ps(local);
1816 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1818 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1820 if (sdata->vif.bss_conf.ps != ps_allowed) {
1821 sdata->vif.bss_conf.ps = ps_allowed;
1822 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1826 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1828 struct ieee80211_local *local =
1829 container_of(work, struct ieee80211_local,
1830 dynamic_ps_disable_work);
1832 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1833 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1834 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1837 ieee80211_wake_queues_by_reason(&local->hw,
1838 IEEE80211_MAX_QUEUE_MAP,
1839 IEEE80211_QUEUE_STOP_REASON_PS,
1843 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1845 struct ieee80211_local *local =
1846 container_of(work, struct ieee80211_local,
1847 dynamic_ps_enable_work);
1848 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1849 struct ieee80211_if_managed *ifmgd;
1850 unsigned long flags;
1853 /* can only happen when PS was just disabled anyway */
1857 ifmgd = &sdata->u.mgd;
1859 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1862 if (local->hw.conf.dynamic_ps_timeout > 0) {
1863 /* don't enter PS if TX frames are pending */
1864 if (drv_tx_frames_pending(local)) {
1865 mod_timer(&local->dynamic_ps_timer, jiffies +
1867 local->hw.conf.dynamic_ps_timeout));
1872 * transmission can be stopped by others which leads to
1873 * dynamic_ps_timer expiry. Postpone the ps timer if it
1874 * is not the actual idle state.
1876 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1877 for (q = 0; q < local->hw.queues; q++) {
1878 if (local->queue_stop_reasons[q]) {
1879 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1881 mod_timer(&local->dynamic_ps_timer, jiffies +
1883 local->hw.conf.dynamic_ps_timeout));
1887 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1890 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1891 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1892 if (drv_tx_frames_pending(local)) {
1893 mod_timer(&local->dynamic_ps_timer, jiffies +
1895 local->hw.conf.dynamic_ps_timeout));
1897 ieee80211_send_nullfunc(local, sdata, true);
1898 /* Flush to get the tx status of nullfunc frame */
1899 ieee80211_flush_queues(local, sdata, false);
1903 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1904 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1905 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1906 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1907 local->hw.conf.flags |= IEEE80211_CONF_PS;
1908 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1912 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1914 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1916 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1919 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1921 struct delayed_work *delayed_work = to_delayed_work(work);
1922 struct ieee80211_sub_if_data *sdata =
1923 container_of(delayed_work, struct ieee80211_sub_if_data,
1924 dfs_cac_timer_work);
1925 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1927 mutex_lock(&sdata->local->mtx);
1928 if (sdata->wdev.cac_started) {
1929 ieee80211_vif_release_channel(sdata);
1930 cfg80211_cac_event(sdata->dev, &chandef,
1931 NL80211_RADAR_CAC_FINISHED,
1934 mutex_unlock(&sdata->local->mtx);
1938 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1940 struct ieee80211_local *local = sdata->local;
1941 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1945 if (local->hw.queues < IEEE80211_NUM_ACS)
1948 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1949 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1951 unsigned long now = jiffies;
1953 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1954 tx_tspec->admitted_time &&
1955 time_after(now, tx_tspec->time_slice_start + HZ)) {
1956 tx_tspec->consumed_tx_time = 0;
1957 tx_tspec->time_slice_start = now;
1959 if (tx_tspec->downgraded)
1961 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1964 switch (tx_tspec->action) {
1965 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1966 /* take the original parameters */
1967 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1969 "failed to set TX queue parameters for queue %d\n",
1971 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1972 tx_tspec->downgraded = false;
1975 case TX_TSPEC_ACTION_DOWNGRADE:
1976 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1977 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1981 /* downgrade next lower non-ACM AC */
1982 for (non_acm_ac = ac + 1;
1983 non_acm_ac < IEEE80211_NUM_ACS;
1985 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1987 /* Usually the loop will result in using BK even if it
1988 * requires admission control, but such a configuration
1989 * makes no sense and we have to transmit somehow - the
1990 * AC selection does the same thing.
1991 * If we started out trying to downgrade from BK, then
1992 * the extra condition here might be needed.
1994 if (non_acm_ac >= IEEE80211_NUM_ACS)
1995 non_acm_ac = IEEE80211_AC_BK;
1996 if (drv_conf_tx(local, sdata, ac,
1997 &sdata->tx_conf[non_acm_ac]))
1999 "failed to set TX queue parameters for queue %d\n",
2001 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2003 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2004 tx_tspec->time_slice_start + HZ - now + 1);
2006 case TX_TSPEC_ACTION_NONE:
2015 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2017 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2018 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2021 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2023 struct ieee80211_sub_if_data *sdata;
2025 sdata = container_of(work, struct ieee80211_sub_if_data,
2026 u.mgd.tx_tspec_wk.work);
2027 ieee80211_sta_handle_tspec_ac_params(sdata);
2032 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2033 struct ieee80211_sub_if_data *sdata,
2034 const u8 *wmm_param, size_t wmm_param_len,
2035 const struct ieee80211_mu_edca_param_set *mu_edca)
2037 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2038 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2040 int count, mu_edca_count, ac;
2042 u8 uapsd_queues = 0;
2044 if (!local->ops->conf_tx)
2047 if (local->hw.queues < IEEE80211_NUM_ACS)
2053 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2056 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2057 uapsd_queues = ifmgd->uapsd_queues;
2059 count = wmm_param[6] & 0x0f;
2060 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2061 * if mu_edca was preset before and now it disappeared tell
2062 * the driver about it.
2064 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2065 if (count == ifmgd->wmm_last_param_set &&
2066 mu_edca_count == ifmgd->mu_edca_last_param_set)
2068 ifmgd->wmm_last_param_set = count;
2069 ifmgd->mu_edca_last_param_set = mu_edca_count;
2071 pos = wmm_param + 8;
2072 left = wmm_param_len - 8;
2074 memset(¶ms, 0, sizeof(params));
2077 for (; left >= 4; left -= 4, pos += 4) {
2078 int aci = (pos[0] >> 5) & 0x03;
2079 int acm = (pos[0] >> 4) & 0x01;
2084 ac = IEEE80211_AC_BK;
2086 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2087 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2089 params[ac].mu_edca = !!mu_edca;
2091 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2094 ac = IEEE80211_AC_VI;
2096 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2097 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2099 params[ac].mu_edca = !!mu_edca;
2101 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2104 ac = IEEE80211_AC_VO;
2106 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2107 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2109 params[ac].mu_edca = !!mu_edca;
2111 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2115 ac = IEEE80211_AC_BE;
2117 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2118 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2120 params[ac].mu_edca = !!mu_edca;
2122 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2126 params[ac].aifs = pos[0] & 0x0f;
2128 if (params[ac].aifs < 2) {
2130 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2131 params[ac].aifs, aci);
2132 params[ac].aifs = 2;
2134 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2135 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2136 params[ac].txop = get_unaligned_le16(pos + 2);
2137 params[ac].acm = acm;
2138 params[ac].uapsd = uapsd;
2140 if (params[ac].cw_min == 0 ||
2141 params[ac].cw_min > params[ac].cw_max) {
2143 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2144 params[ac].cw_min, params[ac].cw_max, aci);
2147 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2150 /* WMM specification requires all 4 ACIs. */
2151 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2152 if (params[ac].cw_min == 0) {
2154 "AP has invalid WMM params (missing AC %d), using defaults\n",
2160 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2162 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2164 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2165 params[ac].txop, params[ac].uapsd,
2166 ifmgd->tx_tspec[ac].downgraded);
2167 sdata->tx_conf[ac] = params[ac];
2168 if (!ifmgd->tx_tspec[ac].downgraded &&
2169 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2171 "failed to set TX queue parameters for AC %d\n",
2175 /* enable WMM or activate new settings */
2176 sdata->vif.bss_conf.qos = true;
2180 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2182 lockdep_assert_held(&sdata->local->mtx);
2184 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2185 ieee80211_run_deferred_scan(sdata->local);
2188 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2190 mutex_lock(&sdata->local->mtx);
2191 __ieee80211_stop_poll(sdata);
2192 mutex_unlock(&sdata->local->mtx);
2195 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2196 u16 capab, bool erp_valid, u8 erp)
2198 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2199 struct ieee80211_supported_band *sband;
2201 bool use_protection;
2202 bool use_short_preamble;
2203 bool use_short_slot;
2205 sband = ieee80211_get_sband(sdata);
2210 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2211 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2213 use_protection = false;
2214 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2217 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2218 if (sband->band == NL80211_BAND_5GHZ ||
2219 sband->band == NL80211_BAND_6GHZ)
2220 use_short_slot = true;
2222 if (use_protection != bss_conf->use_cts_prot) {
2223 bss_conf->use_cts_prot = use_protection;
2224 changed |= BSS_CHANGED_ERP_CTS_PROT;
2227 if (use_short_preamble != bss_conf->use_short_preamble) {
2228 bss_conf->use_short_preamble = use_short_preamble;
2229 changed |= BSS_CHANGED_ERP_PREAMBLE;
2232 if (use_short_slot != bss_conf->use_short_slot) {
2233 bss_conf->use_short_slot = use_short_slot;
2234 changed |= BSS_CHANGED_ERP_SLOT;
2240 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2241 struct cfg80211_bss *cbss,
2242 u32 bss_info_changed)
2244 struct ieee80211_bss *bss = (void *)cbss->priv;
2245 struct ieee80211_local *local = sdata->local;
2246 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2248 bss_info_changed |= BSS_CHANGED_ASSOC;
2249 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2250 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2252 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2253 beacon_loss_count * bss_conf->beacon_int));
2255 sdata->u.mgd.associated = cbss;
2256 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2258 ieee80211_check_rate_mask(sdata);
2260 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2262 if (sdata->vif.p2p ||
2263 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2264 const struct cfg80211_bss_ies *ies;
2267 ies = rcu_dereference(cbss->ies);
2271 ret = cfg80211_get_p2p_attr(
2272 ies->data, ies->len,
2273 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2274 (u8 *) &bss_conf->p2p_noa_attr,
2275 sizeof(bss_conf->p2p_noa_attr));
2277 sdata->u.mgd.p2p_noa_index =
2278 bss_conf->p2p_noa_attr.index;
2279 bss_info_changed |= BSS_CHANGED_P2P_PS;
2285 /* just to be sure */
2286 ieee80211_stop_poll(sdata);
2288 ieee80211_led_assoc(local, 1);
2290 if (sdata->u.mgd.have_beacon) {
2292 * If the AP is buggy we may get here with no DTIM period
2293 * known, so assume it's 1 which is the only safe assumption
2294 * in that case, although if the TIM IE is broken powersave
2295 * probably just won't work at all.
2297 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2298 bss_conf->beacon_rate = bss->beacon_rate;
2299 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2301 bss_conf->beacon_rate = NULL;
2302 bss_conf->dtim_period = 0;
2305 bss_conf->assoc = 1;
2307 /* Tell the driver to monitor connection quality (if supported) */
2308 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2309 bss_conf->cqm_rssi_thold)
2310 bss_info_changed |= BSS_CHANGED_CQM;
2312 /* Enable ARP filtering */
2313 if (bss_conf->arp_addr_cnt)
2314 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2316 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2318 mutex_lock(&local->iflist_mtx);
2319 ieee80211_recalc_ps(local);
2320 mutex_unlock(&local->iflist_mtx);
2322 ieee80211_recalc_smps(sdata);
2323 ieee80211_recalc_ps_vif(sdata);
2325 netif_carrier_on(sdata->dev);
2328 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2329 u16 stype, u16 reason, bool tx,
2332 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2333 struct ieee80211_local *local = sdata->local;
2336 sdata_assert_lock(sdata);
2338 if (WARN_ON_ONCE(tx && !frame_buf))
2341 if (WARN_ON(!ifmgd->associated))
2344 ieee80211_stop_poll(sdata);
2346 ifmgd->associated = NULL;
2347 netif_carrier_off(sdata->dev);
2350 * if we want to get out of ps before disassoc (why?) we have
2351 * to do it before sending disassoc, as otherwise the null-packet
2354 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2355 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2356 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2358 local->ps_sdata = NULL;
2360 /* disable per-vif ps */
2361 ieee80211_recalc_ps_vif(sdata);
2363 /* make sure ongoing transmission finishes */
2367 * drop any frame before deauth/disassoc, this can be data or
2368 * management frame. Since we are disconnecting, we should not
2369 * insist sending these frames which can take time and delay
2370 * the disconnection and possible the roaming.
2373 ieee80211_flush_queues(local, sdata, true);
2375 /* deauthenticate/disassociate now */
2376 if (tx || frame_buf) {
2378 * In multi channel scenarios guarantee that the virtual
2379 * interface is granted immediate airtime to transmit the
2380 * deauthentication frame by calling mgd_prepare_tx, if the
2381 * driver requested so.
2383 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2384 !ifmgd->have_beacon)
2385 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2387 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2388 ifmgd->bssid, stype, reason,
2392 /* flush out frame - make sure the deauth was actually sent */
2394 ieee80211_flush_queues(local, sdata, false);
2396 /* clear bssid only after building the needed mgmt frames */
2397 eth_zero_addr(ifmgd->bssid);
2399 sdata->vif.bss_conf.ssid_len = 0;
2401 /* remove AP and TDLS peers */
2402 sta_info_flush(sdata);
2404 /* finally reset all BSS / config parameters */
2405 changed |= ieee80211_reset_erp_info(sdata);
2407 ieee80211_led_assoc(local, 0);
2408 changed |= BSS_CHANGED_ASSOC;
2409 sdata->vif.bss_conf.assoc = false;
2411 ifmgd->p2p_noa_index = -1;
2412 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2413 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2415 /* on the next assoc, re-program HT/VHT parameters */
2416 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2417 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2418 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2419 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2421 /* reset MU-MIMO ownership and group data */
2422 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2423 sizeof(sdata->vif.bss_conf.mu_group.membership));
2424 memset(sdata->vif.bss_conf.mu_group.position, 0,
2425 sizeof(sdata->vif.bss_conf.mu_group.position));
2426 changed |= BSS_CHANGED_MU_GROUPS;
2427 sdata->vif.mu_mimo_owner = false;
2429 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2431 del_timer_sync(&local->dynamic_ps_timer);
2432 cancel_work_sync(&local->dynamic_ps_enable_work);
2434 /* Disable ARP filtering */
2435 if (sdata->vif.bss_conf.arp_addr_cnt)
2436 changed |= BSS_CHANGED_ARP_FILTER;
2438 sdata->vif.bss_conf.qos = false;
2439 changed |= BSS_CHANGED_QOS;
2441 /* The BSSID (not really interesting) and HT changed */
2442 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2443 ieee80211_bss_info_change_notify(sdata, changed);
2445 /* disassociated - set to defaults now */
2446 ieee80211_set_wmm_default(sdata, false, false);
2448 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2449 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2450 del_timer_sync(&sdata->u.mgd.timer);
2451 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2453 sdata->vif.bss_conf.dtim_period = 0;
2454 sdata->vif.bss_conf.beacon_rate = NULL;
2456 ifmgd->have_beacon = false;
2459 mutex_lock(&local->mtx);
2460 ieee80211_vif_release_channel(sdata);
2462 sdata->vif.csa_active = false;
2463 ifmgd->csa_waiting_bcn = false;
2464 ifmgd->csa_ignored_same_chan = false;
2465 if (sdata->csa_block_tx) {
2466 ieee80211_wake_vif_queues(local, sdata,
2467 IEEE80211_QUEUE_STOP_REASON_CSA);
2468 sdata->csa_block_tx = false;
2470 mutex_unlock(&local->mtx);
2472 /* existing TX TSPEC sessions no longer exist */
2473 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2474 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2476 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2479 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2481 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2482 struct ieee80211_local *local = sdata->local;
2484 mutex_lock(&local->mtx);
2485 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2488 __ieee80211_stop_poll(sdata);
2490 mutex_lock(&local->iflist_mtx);
2491 ieee80211_recalc_ps(local);
2492 mutex_unlock(&local->iflist_mtx);
2494 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2498 * We've received a probe response, but are not sure whether
2499 * we have or will be receiving any beacons or data, so let's
2500 * schedule the timers again, just in case.
2502 ieee80211_sta_reset_beacon_monitor(sdata);
2504 mod_timer(&ifmgd->conn_mon_timer,
2505 round_jiffies_up(jiffies +
2506 IEEE80211_CONNECTION_IDLE_TIME));
2508 mutex_unlock(&local->mtx);
2511 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2512 struct ieee80211_hdr *hdr,
2515 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2516 u16 tid = ieee80211_get_tid(hdr);
2517 int ac = ieee80211_ac_from_tid(tid);
2518 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2519 unsigned long now = jiffies;
2521 if (likely(!tx_tspec->admitted_time))
2524 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2525 tx_tspec->consumed_tx_time = 0;
2526 tx_tspec->time_slice_start = now;
2528 if (tx_tspec->downgraded) {
2529 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2530 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2534 if (tx_tspec->downgraded)
2537 tx_tspec->consumed_tx_time += tx_time;
2539 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2540 tx_tspec->downgraded = true;
2541 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2542 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2546 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2547 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2549 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2551 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2552 !sdata->u.mgd.probe_send_count)
2556 sdata->u.mgd.probe_send_count = 0;
2558 sdata->u.mgd.nullfunc_failed = true;
2559 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2562 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2563 const u8 *src, const u8 *dst,
2564 const u8 *ssid, size_t ssid_len,
2565 struct ieee80211_channel *channel)
2567 struct sk_buff *skb;
2569 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2570 ssid, ssid_len, NULL, 0,
2571 IEEE80211_PROBE_FLAG_DIRECTED);
2573 ieee80211_tx_skb(sdata, skb);
2576 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2578 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2580 u8 *dst = ifmgd->associated->bssid;
2581 u8 unicast_limit = max(1, max_probe_tries - 3);
2582 struct sta_info *sta;
2585 * Try sending broadcast probe requests for the last three
2586 * probe requests after the first ones failed since some
2587 * buggy APs only support broadcast probe requests.
2589 if (ifmgd->probe_send_count >= unicast_limit)
2593 * When the hardware reports an accurate Tx ACK status, it's
2594 * better to send a nullfunc frame instead of a probe request,
2595 * as it will kick us off the AP quickly if we aren't associated
2596 * anymore. The timeout will be reset if the frame is ACKed by
2599 ifmgd->probe_send_count++;
2602 mutex_lock(&sdata->local->sta_mtx);
2603 sta = sta_info_get(sdata, dst);
2605 ieee80211_check_fast_rx(sta);
2606 mutex_unlock(&sdata->local->sta_mtx);
2609 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2610 ifmgd->nullfunc_failed = false;
2611 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
2612 ifmgd->probe_send_count--;
2614 ieee80211_send_nullfunc(sdata->local, sdata, false);
2619 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2620 if (WARN_ON_ONCE(ssid == NULL))
2625 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2627 ifmgd->associated->channel);
2631 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2632 run_again(sdata, ifmgd->probe_timeout);
2635 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2638 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2639 bool already = false;
2641 if (!ieee80211_sdata_running(sdata))
2646 if (!ifmgd->associated)
2649 mutex_lock(&sdata->local->mtx);
2651 if (sdata->local->tmp_channel || sdata->local->scanning) {
2652 mutex_unlock(&sdata->local->mtx);
2657 mlme_dbg_ratelimited(sdata,
2658 "detected beacon loss from AP (missed %d beacons) - probing\n",
2661 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2665 * The driver/our work has already reported this event or the
2666 * connection monitoring has kicked in and we have already sent
2667 * a probe request. Or maybe the AP died and the driver keeps
2668 * reporting until we disassociate...
2670 * In either case we have to ignore the current call to this
2671 * function (except for setting the correct probe reason bit)
2672 * because otherwise we would reset the timer every time and
2673 * never check whether we received a probe response!
2675 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2678 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2680 mutex_unlock(&sdata->local->mtx);
2685 mutex_lock(&sdata->local->iflist_mtx);
2686 ieee80211_recalc_ps(sdata->local);
2687 mutex_unlock(&sdata->local->iflist_mtx);
2689 ifmgd->probe_send_count = 0;
2690 ieee80211_mgd_probe_ap_send(sdata);
2692 sdata_unlock(sdata);
2695 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2696 struct ieee80211_vif *vif)
2698 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2699 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2700 struct cfg80211_bss *cbss;
2701 struct sk_buff *skb;
2705 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2708 sdata_assert_lock(sdata);
2710 if (ifmgd->associated)
2711 cbss = ifmgd->associated;
2712 else if (ifmgd->auth_data)
2713 cbss = ifmgd->auth_data->bss;
2714 else if (ifmgd->assoc_data)
2715 cbss = ifmgd->assoc_data->bss;
2720 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2721 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2722 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
2727 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2728 (u32) -1, cbss->channel,
2730 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2735 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2737 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2738 const u8 *buf, size_t len, bool tx,
2739 u16 reason, bool reconnect)
2741 struct ieee80211_event event = {
2743 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2744 .u.mlme.reason = reason,
2748 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2750 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2752 drv_event_callback(sdata->local, sdata, &event);
2755 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2757 struct ieee80211_local *local = sdata->local;
2758 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2759 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2763 if (!ifmgd->associated) {
2764 sdata_unlock(sdata);
2768 tx = !sdata->csa_block_tx;
2770 if (!ifmgd->driver_disconnect) {
2772 * AP is probably out of range (or not reachable for another
2773 * reason) so remove the bss struct for that AP.
2775 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2778 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2779 ifmgd->driver_disconnect ?
2780 WLAN_REASON_DEAUTH_LEAVING :
2781 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2783 mutex_lock(&local->mtx);
2784 sdata->vif.csa_active = false;
2785 ifmgd->csa_waiting_bcn = false;
2786 if (sdata->csa_block_tx) {
2787 ieee80211_wake_vif_queues(local, sdata,
2788 IEEE80211_QUEUE_STOP_REASON_CSA);
2789 sdata->csa_block_tx = false;
2791 mutex_unlock(&local->mtx);
2793 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2794 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2796 ifmgd->reconnect = false;
2798 sdata_unlock(sdata);
2801 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2803 struct ieee80211_sub_if_data *sdata =
2804 container_of(work, struct ieee80211_sub_if_data,
2805 u.mgd.beacon_connection_loss_work);
2806 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2808 if (ifmgd->associated)
2809 ifmgd->beacon_loss_count++;
2811 if (ifmgd->connection_loss) {
2812 sdata_info(sdata, "Connection to AP %pM lost\n",
2814 __ieee80211_disconnect(sdata);
2815 ifmgd->connection_loss = false;
2816 } else if (ifmgd->driver_disconnect) {
2818 "Driver requested disconnection from AP %pM\n",
2820 __ieee80211_disconnect(sdata);
2821 ifmgd->driver_disconnect = false;
2823 ieee80211_mgd_probe_ap(sdata, true);
2827 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2829 struct ieee80211_sub_if_data *sdata =
2830 container_of(work, struct ieee80211_sub_if_data,
2831 u.mgd.csa_connection_drop_work);
2833 __ieee80211_disconnect(sdata);
2836 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2838 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2839 struct ieee80211_hw *hw = &sdata->local->hw;
2841 trace_api_beacon_loss(sdata);
2843 sdata->u.mgd.connection_loss = false;
2844 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2846 EXPORT_SYMBOL(ieee80211_beacon_loss);
2848 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2850 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2851 struct ieee80211_hw *hw = &sdata->local->hw;
2853 trace_api_connection_loss(sdata);
2855 sdata->u.mgd.connection_loss = true;
2856 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2858 EXPORT_SYMBOL(ieee80211_connection_loss);
2860 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2862 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2863 struct ieee80211_hw *hw = &sdata->local->hw;
2865 trace_api_disconnect(sdata, reconnect);
2867 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2870 sdata->u.mgd.driver_disconnect = true;
2871 sdata->u.mgd.reconnect = reconnect;
2872 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2874 EXPORT_SYMBOL(ieee80211_disconnect);
2876 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2879 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2881 sdata_assert_lock(sdata);
2885 * we are not authenticated yet, the only timer that could be
2886 * running is the timeout for the authentication response which
2887 * which is not relevant anymore.
2889 del_timer_sync(&sdata->u.mgd.timer);
2890 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2892 eth_zero_addr(sdata->u.mgd.bssid);
2893 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2894 sdata->u.mgd.flags = 0;
2895 mutex_lock(&sdata->local->mtx);
2896 ieee80211_vif_release_channel(sdata);
2897 mutex_unlock(&sdata->local->mtx);
2900 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2902 sdata->u.mgd.auth_data = NULL;
2905 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2906 bool assoc, bool abandon)
2908 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2910 sdata_assert_lock(sdata);
2914 * we are not associated yet, the only timer that could be
2915 * running is the timeout for the association response which
2916 * which is not relevant anymore.
2918 del_timer_sync(&sdata->u.mgd.timer);
2919 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2921 eth_zero_addr(sdata->u.mgd.bssid);
2922 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2923 sdata->u.mgd.flags = 0;
2924 sdata->vif.mu_mimo_owner = false;
2926 mutex_lock(&sdata->local->mtx);
2927 ieee80211_vif_release_channel(sdata);
2928 mutex_unlock(&sdata->local->mtx);
2931 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2935 sdata->u.mgd.assoc_data = NULL;
2938 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2939 struct ieee80211_mgmt *mgmt, size_t len)
2941 struct ieee80211_local *local = sdata->local;
2942 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2944 struct ieee802_11_elems elems;
2947 pos = mgmt->u.auth.variable;
2948 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2949 mgmt->bssid, auth_data->bss->bssid);
2950 if (!elems.challenge)
2952 auth_data->expected_transaction = 4;
2953 drv_mgd_prepare_tx(sdata->local, sdata, 0);
2954 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2955 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2956 IEEE80211_TX_INTFL_MLME_CONN_TX;
2957 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2958 elems.challenge - 2, elems.challenge_len + 2,
2959 auth_data->bss->bssid, auth_data->bss->bssid,
2960 auth_data->key, auth_data->key_len,
2961 auth_data->key_idx, tx_flags);
2964 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2967 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2968 struct sta_info *sta;
2971 sdata_info(sdata, "authenticated\n");
2972 ifmgd->auth_data->done = true;
2973 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2974 ifmgd->auth_data->timeout_started = true;
2975 run_again(sdata, ifmgd->auth_data->timeout);
2977 /* move station state to auth */
2978 mutex_lock(&sdata->local->sta_mtx);
2979 sta = sta_info_get(sdata, bssid);
2981 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2985 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2986 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2992 mutex_unlock(&sdata->local->sta_mtx);
2996 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2997 struct ieee80211_mgmt *mgmt, size_t len)
2999 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3001 u16 auth_alg, auth_transaction, status_code;
3002 struct ieee80211_event event = {
3004 .u.mlme.data = AUTH_EVENT,
3007 sdata_assert_lock(sdata);
3012 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3015 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3017 if (!ether_addr_equal(bssid, mgmt->bssid))
3020 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3021 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3022 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3024 if (auth_alg != ifmgd->auth_data->algorithm ||
3025 (auth_alg != WLAN_AUTH_SAE &&
3026 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3027 (auth_alg == WLAN_AUTH_SAE &&
3028 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3029 auth_transaction > 2))) {
3030 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3031 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3033 ifmgd->auth_data->expected_transaction);
3037 if (status_code != WLAN_STATUS_SUCCESS) {
3038 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3040 if (auth_alg == WLAN_AUTH_SAE &&
3041 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3042 (auth_transaction == 1 &&
3043 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3044 status_code == WLAN_STATUS_SAE_PK))))
3047 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3048 mgmt->sa, status_code);
3049 ieee80211_destroy_auth_data(sdata, false);
3050 event.u.mlme.status = MLME_DENIED;
3051 event.u.mlme.reason = status_code;
3052 drv_event_callback(sdata->local, sdata, &event);
3056 switch (ifmgd->auth_data->algorithm) {
3057 case WLAN_AUTH_OPEN:
3058 case WLAN_AUTH_LEAP:
3061 case WLAN_AUTH_FILS_SK:
3062 case WLAN_AUTH_FILS_SK_PFS:
3063 case WLAN_AUTH_FILS_PK:
3065 case WLAN_AUTH_SHARED_KEY:
3066 if (ifmgd->auth_data->expected_transaction != 4) {
3067 ieee80211_auth_challenge(sdata, mgmt, len);
3068 /* need another frame */
3073 WARN_ONCE(1, "invalid auth alg %d",
3074 ifmgd->auth_data->algorithm);
3078 event.u.mlme.status = MLME_SUCCESS;
3079 drv_event_callback(sdata->local, sdata, &event);
3080 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3081 (auth_transaction == 2 &&
3082 ifmgd->auth_data->expected_transaction == 2)) {
3083 if (!ieee80211_mark_sta_auth(sdata, bssid))
3084 return; /* ignore frame -- wait for timeout */
3085 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3086 auth_transaction == 2) {
3087 sdata_info(sdata, "SAE peer confirmed\n");
3088 ifmgd->auth_data->peer_confirmed = true;
3091 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3094 #define case_WLAN(type) \
3095 case WLAN_REASON_##type: return #type
3097 const char *ieee80211_get_reason_code_string(u16 reason_code)
3099 switch (reason_code) {
3100 case_WLAN(UNSPECIFIED);
3101 case_WLAN(PREV_AUTH_NOT_VALID);
3102 case_WLAN(DEAUTH_LEAVING);
3103 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3104 case_WLAN(DISASSOC_AP_BUSY);
3105 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3106 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3107 case_WLAN(DISASSOC_STA_HAS_LEFT);
3108 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3109 case_WLAN(DISASSOC_BAD_POWER);
3110 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3111 case_WLAN(INVALID_IE);
3112 case_WLAN(MIC_FAILURE);
3113 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3114 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3115 case_WLAN(IE_DIFFERENT);
3116 case_WLAN(INVALID_GROUP_CIPHER);
3117 case_WLAN(INVALID_PAIRWISE_CIPHER);
3118 case_WLAN(INVALID_AKMP);
3119 case_WLAN(UNSUPP_RSN_VERSION);
3120 case_WLAN(INVALID_RSN_IE_CAP);
3121 case_WLAN(IEEE8021X_FAILED);
3122 case_WLAN(CIPHER_SUITE_REJECTED);
3123 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3124 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3125 case_WLAN(DISASSOC_LOW_ACK);
3126 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3127 case_WLAN(QSTA_LEAVE_QBSS);
3128 case_WLAN(QSTA_NOT_USE);
3129 case_WLAN(QSTA_REQUIRE_SETUP);
3130 case_WLAN(QSTA_TIMEOUT);
3131 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3132 case_WLAN(MESH_PEER_CANCELED);
3133 case_WLAN(MESH_MAX_PEERS);
3134 case_WLAN(MESH_CONFIG);
3135 case_WLAN(MESH_CLOSE);
3136 case_WLAN(MESH_MAX_RETRIES);
3137 case_WLAN(MESH_CONFIRM_TIMEOUT);
3138 case_WLAN(MESH_INVALID_GTK);
3139 case_WLAN(MESH_INCONSISTENT_PARAM);
3140 case_WLAN(MESH_INVALID_SECURITY);
3141 case_WLAN(MESH_PATH_ERROR);
3142 case_WLAN(MESH_PATH_NOFORWARD);
3143 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3144 case_WLAN(MAC_EXISTS_IN_MBSS);
3145 case_WLAN(MESH_CHAN_REGULATORY);
3146 case_WLAN(MESH_CHAN);
3147 default: return "<unknown>";
3151 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3152 struct ieee80211_mgmt *mgmt, size_t len)
3154 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3155 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3157 sdata_assert_lock(sdata);
3162 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3163 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3167 if (ifmgd->associated &&
3168 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3169 const u8 *bssid = ifmgd->associated->bssid;
3171 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3173 ieee80211_get_reason_code_string(reason_code));
3175 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3177 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3178 reason_code, false);
3182 if (ifmgd->assoc_data &&
3183 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3184 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3187 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3189 ieee80211_get_reason_code_string(reason_code));
3191 ieee80211_destroy_assoc_data(sdata, false, true);
3193 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3199 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3200 struct ieee80211_mgmt *mgmt, size_t len)
3202 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3205 sdata_assert_lock(sdata);
3210 if (!ifmgd->associated ||
3211 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3214 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3216 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3217 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3221 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3222 mgmt->sa, reason_code,
3223 ieee80211_get_reason_code_string(reason_code));
3225 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3227 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3231 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3232 u8 *supp_rates, unsigned int supp_rates_len,
3233 u32 *rates, u32 *basic_rates,
3234 bool *have_higher_than_11mbit,
3235 int *min_rate, int *min_rate_index,
3240 for (i = 0; i < supp_rates_len; i++) {
3241 int rate = supp_rates[i] & 0x7f;
3242 bool is_basic = !!(supp_rates[i] & 0x80);
3244 if ((rate * 5 * (1 << shift)) > 110)
3245 *have_higher_than_11mbit = true;
3248 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3249 * since they're not rates.
3251 * Note: Even though the membership selector and the basic
3252 * rate flag share the same bit, they are not exactly
3255 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3256 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3257 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3258 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3261 for (j = 0; j < sband->n_bitrates; j++) {
3262 struct ieee80211_rate *br;
3265 br = &sband->bitrates[j];
3267 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3268 if (brate == rate) {
3271 *basic_rates |= BIT(j);
3272 if ((rate * 5) < *min_rate) {
3273 *min_rate = rate * 5;
3274 *min_rate_index = j;
3282 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3283 const struct ieee802_11_elems *elems)
3285 if (elems->ext_capab_len < 10)
3288 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3291 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3292 IEEE80211_HE_MAC_CAP0_TWT_RES;
3295 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3296 struct sta_info *sta,
3297 struct ieee802_11_elems *elems)
3299 bool twt = ieee80211_twt_req_supported(sta, elems);
3301 if (sdata->vif.bss_conf.twt_requester != twt) {
3302 sdata->vif.bss_conf.twt_requester = twt;
3303 return BSS_CHANGED_TWT;
3308 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3309 struct cfg80211_bss *cbss,
3310 struct ieee80211_mgmt *mgmt, size_t len,
3311 struct ieee802_11_elems *elems)
3313 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3314 struct ieee80211_local *local = sdata->local;
3315 struct ieee80211_supported_band *sband;
3316 struct sta_info *sta;
3317 u16 capab_info, aid;
3318 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3319 const struct cfg80211_bss_ies *bss_ies = NULL;
3320 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3321 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3322 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3328 /* AssocResp and ReassocResp have identical structure */
3330 pos = mgmt->u.assoc_resp.variable;
3331 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3333 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3336 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3337 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, elems,
3338 mgmt->bssid, assoc_data->bss->bssid);
3340 if (elems->aid_resp)
3341 aid = le16_to_cpu(elems->aid_resp->aid);
3344 * The 5 MSB of the AID field are reserved
3345 * (802.11-2016 9.4.1.8 AID field)
3349 ifmgd->broken_ap = false;
3351 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3352 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3355 ifmgd->broken_ap = true;
3358 if (!is_s1g && !elems->supp_rates) {
3359 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3363 sdata->vif.bss_conf.aid = aid;
3364 ifmgd->tdls_chan_switch_prohibited =
3365 elems->ext_capab && elems->ext_capab_len >= 5 &&
3366 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3369 * Some APs are erroneously not including some information in their
3370 * (re)association response frames. Try to recover by using the data
3371 * from the beacon or probe response. This seems to afflict mobile
3372 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3373 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3376 ((assoc_data->wmm && !elems->wmm_param) ||
3377 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3378 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3379 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3380 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3381 const struct cfg80211_bss_ies *ies;
3382 struct ieee802_11_elems bss_elems;
3385 ies = rcu_dereference(cbss->ies);
3387 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3393 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3396 assoc_data->bss->bssid);
3397 if (assoc_data->wmm &&
3398 !elems->wmm_param && bss_elems.wmm_param) {
3399 elems->wmm_param = bss_elems.wmm_param;
3401 "AP bug: WMM param missing from AssocResp\n");
3405 * Also check if we requested HT/VHT, otherwise the AP doesn't
3406 * have to include the IEs in the (re)association response.
3408 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
3409 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3410 elems->ht_cap_elem = bss_elems.ht_cap_elem;
3412 "AP bug: HT capability missing from AssocResp\n");
3414 if (!elems->ht_operation && bss_elems.ht_operation &&
3415 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3416 elems->ht_operation = bss_elems.ht_operation;
3418 "AP bug: HT operation missing from AssocResp\n");
3420 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
3421 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3422 elems->vht_cap_elem = bss_elems.vht_cap_elem;
3424 "AP bug: VHT capa missing from AssocResp\n");
3426 if (!elems->vht_operation && bss_elems.vht_operation &&
3427 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3428 elems->vht_operation = bss_elems.vht_operation;
3430 "AP bug: VHT operation missing from AssocResp\n");
3435 * We previously checked these in the beacon/probe response, so
3436 * they should be present here. This is just a safety net.
3438 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3439 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3441 "HT AP is missing WMM params or HT capability/operation\n");
3446 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3447 (!elems->vht_cap_elem || !elems->vht_operation)) {
3449 "VHT AP is missing VHT capability/operation\n");
3454 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3455 !elems->he_6ghz_capa) {
3457 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3462 mutex_lock(&sdata->local->sta_mtx);
3464 * station info was already allocated and inserted before
3465 * the association and should be available to us
3467 sta = sta_info_get(sdata, cbss->bssid);
3468 if (WARN_ON(!sta)) {
3469 mutex_unlock(&sdata->local->sta_mtx);
3474 sband = ieee80211_get_sband(sdata);
3476 mutex_unlock(&sdata->local->sta_mtx);
3481 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3482 (!elems->he_cap || !elems->he_operation)) {
3483 mutex_unlock(&sdata->local->sta_mtx);
3485 "HE AP is missing HE capability/operation\n");
3490 /* Set up internal HT/VHT capabilities */
3491 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3492 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3493 elems->ht_cap_elem, sta);
3495 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3496 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3497 elems->vht_cap_elem, sta);
3499 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3501 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3504 elems->he_6ghz_capa,
3507 bss_conf->he_support = sta->sta.he_cap.has_he;
3508 if (elems->rsnx && elems->rsnx_len &&
3509 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3510 wiphy_ext_feature_isset(local->hw.wiphy,
3511 NL80211_EXT_FEATURE_PROTECTED_TWT))
3512 bss_conf->twt_protected = true;
3514 bss_conf->twt_protected = false;
3516 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3518 bss_conf->he_support = false;
3519 bss_conf->twt_requester = false;
3520 bss_conf->twt_protected = false;
3523 if (bss_conf->he_support) {
3524 bss_conf->he_bss_color.color =
3525 le32_get_bits(elems->he_operation->he_oper_params,
3526 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3527 bss_conf->he_bss_color.partial =
3528 le32_get_bits(elems->he_operation->he_oper_params,
3529 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3530 bss_conf->he_bss_color.enabled =
3531 !le32_get_bits(elems->he_operation->he_oper_params,
3532 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3534 if (bss_conf->he_bss_color.enabled)
3535 changed |= BSS_CHANGED_HE_BSS_COLOR;
3537 bss_conf->htc_trig_based_pkt_ext =
3538 le32_get_bits(elems->he_operation->he_oper_params,
3539 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3540 bss_conf->frame_time_rts_th =
3541 le32_get_bits(elems->he_operation->he_oper_params,
3542 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3544 bss_conf->uora_exists = !!elems->uora_element;
3545 if (elems->uora_element)
3546 bss_conf->uora_ocw_range = elems->uora_element[0];
3548 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3549 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3550 /* TODO: OPEN: what happens if BSS color disable is set? */
3553 if (cbss->transmitted_bss) {
3554 bss_conf->nontransmitted = true;
3555 ether_addr_copy(bss_conf->transmitter_bssid,
3556 cbss->transmitted_bss->bssid);
3557 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3558 bss_conf->bssid_index = cbss->bssid_index;
3562 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3563 * in their association response, so ignore that data for our own
3564 * configuration. If it changed since the last beacon, we'll get the
3565 * next beacon and update then.
3569 * If an operating mode notification IE is present, override the
3570 * NSS calculation (that would be done in rate_control_rate_init())
3571 * and use the # of streams from that element.
3573 if (elems->opmode_notif &&
3574 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3577 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3578 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3580 sta->sta.rx_nss = nss;
3583 rate_control_rate_init(sta);
3585 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3586 set_sta_flag(sta, WLAN_STA_MFP);
3587 sta->sta.mfp = true;
3589 sta->sta.mfp = false;
3592 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3593 local->hw.queues >= IEEE80211_NUM_ACS;
3595 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3596 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3597 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3600 "failed to move station %pM to desired state\n",
3602 WARN_ON(__sta_info_destroy(sta));
3603 mutex_unlock(&sdata->local->sta_mtx);
3608 if (sdata->wdev.use_4addr)
3609 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3611 mutex_unlock(&sdata->local->sta_mtx);
3614 * Always handle WMM once after association regardless
3615 * of the first value the AP uses. Setting -1 here has
3616 * that effect because the AP values is an unsigned
3619 ifmgd->wmm_last_param_set = -1;
3620 ifmgd->mu_edca_last_param_set = -1;
3622 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3623 ieee80211_set_wmm_default(sdata, false, false);
3624 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3625 elems->wmm_param_len,
3626 elems->mu_edca_param_set)) {
3627 /* still enable QoS since we might have HT/VHT */
3628 ieee80211_set_wmm_default(sdata, false, true);
3629 /* set the disable-WMM flag in this case to disable
3630 * tracking WMM parameter changes in the beacon if
3631 * the parameters weren't actually valid. Doing so
3632 * avoids changing parameters very strangely when
3633 * the AP is going back and forth between valid and
3634 * invalid parameters.
3636 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3638 changed |= BSS_CHANGED_QOS;
3640 if (elems->max_idle_period_ie) {
3641 bss_conf->max_idle_period =
3642 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3643 bss_conf->protected_keep_alive =
3644 !!(elems->max_idle_period_ie->idle_options &
3645 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3646 changed |= BSS_CHANGED_KEEP_ALIVE;
3648 bss_conf->max_idle_period = 0;
3649 bss_conf->protected_keep_alive = false;
3652 /* set assoc capability (AID was already set earlier),
3653 * ieee80211_set_associated() will tell the driver */
3654 bss_conf->assoc_capability = capab_info;
3655 ieee80211_set_associated(sdata, cbss, changed);
3658 * If we're using 4-addr mode, let the AP know that we're
3659 * doing so, so that it can create the STA VLAN on its side
3661 if (ifmgd->use_4addr)
3662 ieee80211_send_4addr_nullfunc(local, sdata);
3665 * Start timer to probe the connection to the AP now.
3666 * Also start the timer that will detect beacon loss.
3668 ieee80211_sta_reset_beacon_monitor(sdata);
3669 ieee80211_sta_reset_conn_monitor(sdata);
3677 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3678 struct ieee80211_mgmt *mgmt,
3681 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3682 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3683 u16 capab_info, status_code, aid;
3684 struct ieee802_11_elems elems;
3685 int ac, uapsd_queues = -1;
3688 struct cfg80211_bss *cbss;
3689 struct ieee80211_event event = {
3691 .u.mlme.data = ASSOC_EVENT,
3694 sdata_assert_lock(sdata);
3699 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3702 cbss = assoc_data->bss;
3705 * AssocResp and ReassocResp have identical structure, so process both
3706 * of them in this function.
3712 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3713 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3714 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3715 pos = mgmt->u.assoc_resp.variable;
3716 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3717 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3718 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3723 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3724 reassoc ? "Rea" : "A", mgmt->sa,
3725 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3727 if (assoc_data->fils_kek_len &&
3728 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3731 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3732 mgmt->bssid, assoc_data->bss->bssid);
3734 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3735 elems.timeout_int &&
3736 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3738 tu = le32_to_cpu(elems.timeout_int->value);
3739 ms = tu * 1024 / 1000;
3741 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3743 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3744 assoc_data->timeout_started = true;
3745 if (ms > IEEE80211_ASSOC_TIMEOUT)
3746 run_again(sdata, assoc_data->timeout);
3750 if (status_code != WLAN_STATUS_SUCCESS) {
3751 sdata_info(sdata, "%pM denied association (code=%d)\n",
3752 mgmt->sa, status_code);
3753 ieee80211_destroy_assoc_data(sdata, false, false);
3754 event.u.mlme.status = MLME_DENIED;
3755 event.u.mlme.reason = status_code;
3756 drv_event_callback(sdata->local, sdata, &event);
3758 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, &elems)) {
3759 /* oops -- internal error -- send timeout for now */
3760 ieee80211_destroy_assoc_data(sdata, false, false);
3761 cfg80211_assoc_timeout(sdata->dev, cbss);
3764 event.u.mlme.status = MLME_SUCCESS;
3765 drv_event_callback(sdata->local, sdata, &event);
3766 sdata_info(sdata, "associated\n");
3769 * destroy assoc_data afterwards, as otherwise an idle
3770 * recalc after assoc_data is NULL but before associated
3771 * is set can cause the interface to go idle
3773 ieee80211_destroy_assoc_data(sdata, true, false);
3775 /* get uapsd queues configuration */
3777 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3778 if (sdata->tx_conf[ac].uapsd)
3779 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3782 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3783 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3786 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3787 struct ieee80211_mgmt *mgmt, size_t len,
3788 struct ieee80211_rx_status *rx_status)
3790 struct ieee80211_local *local = sdata->local;
3791 struct ieee80211_bss *bss;
3792 struct ieee80211_channel *channel;
3794 sdata_assert_lock(sdata);
3796 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3797 ieee80211_rx_status_to_khz(rx_status));
3801 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3803 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3804 ieee80211_rx_bss_put(local, bss);
3809 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3810 struct sk_buff *skb)
3812 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3813 struct ieee80211_if_managed *ifmgd;
3814 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3815 struct ieee80211_channel *channel;
3816 size_t baselen, len = skb->len;
3818 ifmgd = &sdata->u.mgd;
3820 sdata_assert_lock(sdata);
3823 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3824 * "If a 6 GHz AP receives a Probe Request frame and responds with
3825 * a Probe Response frame [..], the Address 1 field of the Probe
3826 * Response frame shall be set to the broadcast address [..]"
3827 * So, on 6GHz band we should also accept broadcast responses.
3829 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3834 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3835 (channel->band != NL80211_BAND_6GHZ ||
3836 !is_broadcast_ether_addr(mgmt->da)))
3837 return; /* ignore ProbeResp to foreign address */
3839 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3843 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3845 if (ifmgd->associated &&
3846 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3847 ieee80211_reset_ap_probe(sdata);
3851 * This is the canonical list of information elements we care about,
3852 * the filter code also gives us all changes to the Microsoft OUI
3853 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3854 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3855 * changes to requested client power.
3857 * We implement beacon filtering in software since that means we can
3858 * avoid processing the frame here and in cfg80211, and userspace
3859 * will not be able to tell whether the hardware supports it or not.
3861 * XXX: This list needs to be dynamic -- userspace needs to be able to
3862 * add items it requires. It also needs to be able to tell us to
3863 * look out for other vendor IEs.
3865 static const u64 care_about_ies =
3866 (1ULL << WLAN_EID_COUNTRY) |
3867 (1ULL << WLAN_EID_ERP_INFO) |
3868 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3869 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3870 (1ULL << WLAN_EID_HT_CAPABILITY) |
3871 (1ULL << WLAN_EID_HT_OPERATION) |
3872 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3874 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3875 struct ieee80211_if_managed *ifmgd,
3876 struct ieee80211_bss_conf *bss_conf,
3877 struct ieee80211_local *local,
3878 struct ieee80211_rx_status *rx_status)
3880 /* Track average RSSI from the Beacon frames of the current AP */
3882 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3883 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3884 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3885 ifmgd->last_cqm_event_signal = 0;
3886 ifmgd->count_beacon_signal = 1;
3887 ifmgd->last_ave_beacon_signal = 0;
3889 ifmgd->count_beacon_signal++;
3892 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3894 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3895 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3896 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3897 int last_sig = ifmgd->last_ave_beacon_signal;
3898 struct ieee80211_event event = {
3903 * if signal crosses either of the boundaries, invoke callback
3904 * with appropriate parameters
3906 if (sig > ifmgd->rssi_max_thold &&
3907 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3908 ifmgd->last_ave_beacon_signal = sig;
3909 event.u.rssi.data = RSSI_EVENT_HIGH;
3910 drv_event_callback(local, sdata, &event);
3911 } else if (sig < ifmgd->rssi_min_thold &&
3912 (last_sig >= ifmgd->rssi_max_thold ||
3914 ifmgd->last_ave_beacon_signal = sig;
3915 event.u.rssi.data = RSSI_EVENT_LOW;
3916 drv_event_callback(local, sdata, &event);
3920 if (bss_conf->cqm_rssi_thold &&
3921 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3922 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3923 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3924 int last_event = ifmgd->last_cqm_event_signal;
3925 int thold = bss_conf->cqm_rssi_thold;
3926 int hyst = bss_conf->cqm_rssi_hyst;
3929 (last_event == 0 || sig < last_event - hyst)) {
3930 ifmgd->last_cqm_event_signal = sig;
3931 ieee80211_cqm_rssi_notify(
3933 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3935 } else if (sig > thold &&
3936 (last_event == 0 || sig > last_event + hyst)) {
3937 ifmgd->last_cqm_event_signal = sig;
3938 ieee80211_cqm_rssi_notify(
3940 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3945 if (bss_conf->cqm_rssi_low &&
3946 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3947 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3948 int last_event = ifmgd->last_cqm_event_signal;
3949 int low = bss_conf->cqm_rssi_low;
3950 int high = bss_conf->cqm_rssi_high;
3953 (last_event == 0 || last_event >= low)) {
3954 ifmgd->last_cqm_event_signal = sig;
3955 ieee80211_cqm_rssi_notify(
3957 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3959 } else if (sig > high &&
3960 (last_event == 0 || last_event <= high)) {
3961 ifmgd->last_cqm_event_signal = sig;
3962 ieee80211_cqm_rssi_notify(
3964 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3970 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3971 struct cfg80211_bss *bss)
3973 if (ether_addr_equal(tx_bssid, bss->bssid))
3975 if (!bss->transmitted_bss)
3977 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3980 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3981 struct ieee80211_hdr *hdr, size_t len,
3982 struct ieee80211_rx_status *rx_status)
3984 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3985 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3986 struct ieee80211_mgmt *mgmt = (void *) hdr;
3988 struct ieee802_11_elems elems;
3989 struct ieee80211_local *local = sdata->local;
3990 struct ieee80211_chanctx_conf *chanctx_conf;
3991 struct ieee80211_channel *chan;
3992 struct sta_info *sta;
3997 u8 *bssid, *variable = mgmt->u.beacon.variable;
3998 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4000 sdata_assert_lock(sdata);
4002 /* Process beacon from the current BSS */
4003 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4004 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4005 struct ieee80211_ext *ext = (void *) mgmt;
4007 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4008 variable = ext->u.s1g_short_beacon.variable;
4010 variable = ext->u.s1g_beacon.variable;
4013 baselen = (u8 *) variable - (u8 *) mgmt;
4018 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4019 if (!chanctx_conf) {
4024 if (ieee80211_rx_status_to_khz(rx_status) !=
4025 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4029 chan = chanctx_conf->def.chan;
4032 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4033 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4034 ieee802_11_parse_elems(variable,
4035 len - baselen, false, &elems,
4037 ifmgd->assoc_data->bss->bssid);
4039 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4041 if (elems.dtim_period)
4042 ifmgd->dtim_period = elems.dtim_period;
4043 ifmgd->have_beacon = true;
4044 ifmgd->assoc_data->need_beacon = false;
4045 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4046 sdata->vif.bss_conf.sync_tsf =
4047 le64_to_cpu(mgmt->u.beacon.timestamp);
4048 sdata->vif.bss_conf.sync_device_ts =
4049 rx_status->device_timestamp;
4050 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4053 if (elems.mbssid_config_ie)
4054 bss_conf->profile_periodicity =
4055 elems.mbssid_config_ie->profile_periodicity;
4057 bss_conf->profile_periodicity = 0;
4059 if (elems.ext_capab_len >= 11 &&
4060 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4061 bss_conf->ema_ap = true;
4063 bss_conf->ema_ap = false;
4065 /* continue assoc process */
4066 ifmgd->assoc_data->timeout = jiffies;
4067 ifmgd->assoc_data->timeout_started = true;
4068 run_again(sdata, ifmgd->assoc_data->timeout);
4072 if (!ifmgd->associated ||
4073 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4075 bssid = ifmgd->associated->bssid;
4077 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4078 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4081 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4082 mlme_dbg_ratelimited(sdata,
4083 "cancelling AP probe due to a received beacon\n");
4084 ieee80211_reset_ap_probe(sdata);
4088 * Push the beacon loss detection into the future since
4089 * we are processing a beacon from the AP just now.
4091 ieee80211_sta_reset_beacon_monitor(sdata);
4093 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4094 * element (which carries the beacon interval). Don't forget to add a
4095 * bit to care_about_ies[] above if mac80211 is interested in a
4096 * changing S1G element.
4098 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4099 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4100 ncrc = ieee802_11_parse_elems_crc(variable,
4101 len - baselen, false, &elems,
4102 care_about_ies, ncrc,
4103 mgmt->bssid, bssid);
4105 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4106 ieee80211_check_tim(elems.tim, elems.tim_len, bss_conf->aid)) {
4107 if (local->hw.conf.dynamic_ps_timeout > 0) {
4108 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4109 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4110 ieee80211_hw_config(local,
4111 IEEE80211_CONF_CHANGE_PS);
4113 ieee80211_send_nullfunc(local, sdata, false);
4114 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4115 local->pspolling = true;
4118 * Here is assumed that the driver will be
4119 * able to send ps-poll frame and receive a
4120 * response even though power save mode is
4121 * enabled, but some drivers might require
4122 * to disable power save here. This needs
4123 * to be investigated.
4125 ieee80211_send_pspoll(local, sdata);
4129 if (sdata->vif.p2p ||
4130 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4131 struct ieee80211_p2p_noa_attr noa = {};
4134 ret = cfg80211_get_p2p_attr(variable,
4136 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4137 (u8 *) &noa, sizeof(noa));
4139 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4140 /* valid noa_attr and index changed */
4141 sdata->u.mgd.p2p_noa_index = noa.index;
4142 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4143 changed |= BSS_CHANGED_P2P_PS;
4145 * make sure we update all information, the CRC
4146 * mechanism doesn't look at P2P attributes.
4148 ifmgd->beacon_crc_valid = false;
4150 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4151 /* noa_attr not found and we had valid noa_attr before */
4152 sdata->u.mgd.p2p_noa_index = -1;
4153 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4154 changed |= BSS_CHANGED_P2P_PS;
4155 ifmgd->beacon_crc_valid = false;
4159 if (ifmgd->csa_waiting_bcn)
4160 ieee80211_chswitch_post_beacon(sdata);
4163 * Update beacon timing and dtim count on every beacon appearance. This
4164 * will allow the driver to use the most updated values. Do it before
4165 * comparing this one with last received beacon.
4166 * IMPORTANT: These parameters would possibly be out of sync by the time
4167 * the driver will use them. The synchronized view is currently
4168 * guaranteed only in certain callbacks.
4170 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4171 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4172 sdata->vif.bss_conf.sync_tsf =
4173 le64_to_cpu(mgmt->u.beacon.timestamp);
4174 sdata->vif.bss_conf.sync_device_ts =
4175 rx_status->device_timestamp;
4176 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4179 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4180 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4182 ifmgd->beacon_crc = ncrc;
4183 ifmgd->beacon_crc_valid = true;
4185 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4187 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4188 rx_status->device_timestamp,
4191 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4192 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
4193 elems.wmm_param_len,
4194 elems.mu_edca_param_set))
4195 changed |= BSS_CHANGED_QOS;
4198 * If we haven't had a beacon before, tell the driver about the
4199 * DTIM period (and beacon timing if desired) now.
4201 if (!ifmgd->have_beacon) {
4202 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4203 bss_conf->dtim_period = elems.dtim_period ?: 1;
4205 changed |= BSS_CHANGED_BEACON_INFO;
4206 ifmgd->have_beacon = true;
4208 mutex_lock(&local->iflist_mtx);
4209 ieee80211_recalc_ps(local);
4210 mutex_unlock(&local->iflist_mtx);
4212 ieee80211_recalc_ps_vif(sdata);
4215 if (elems.erp_info) {
4217 erp_value = elems.erp_info[0];
4222 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4223 changed |= ieee80211_handle_bss_capability(sdata,
4224 le16_to_cpu(mgmt->u.beacon.capab_info),
4225 erp_valid, erp_value);
4227 mutex_lock(&local->sta_mtx);
4228 sta = sta_info_get(sdata, bssid);
4230 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4232 if (ieee80211_config_bw(sdata, sta, elems.ht_cap_elem,
4233 elems.vht_cap_elem, elems.ht_operation,
4234 elems.vht_operation, elems.he_operation,
4235 elems.s1g_oper, bssid, &changed)) {
4236 mutex_unlock(&local->sta_mtx);
4238 "failed to follow AP %pM bandwidth change, disconnect\n",
4240 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4241 WLAN_REASON_DEAUTH_LEAVING,
4243 ieee80211_report_disconnect(sdata, deauth_buf,
4244 sizeof(deauth_buf), true,
4245 WLAN_REASON_DEAUTH_LEAVING,
4250 if (sta && elems.opmode_notif)
4251 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
4253 mutex_unlock(&local->sta_mtx);
4255 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4257 elems.country_elem_len,
4258 elems.pwr_constr_elem,
4259 elems.cisco_dtpc_elem);
4261 ieee80211_bss_info_change_notify(sdata, changed);
4264 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4265 struct sk_buff *skb)
4267 struct ieee80211_rx_status *rx_status;
4268 struct ieee80211_hdr *hdr;
4271 rx_status = (struct ieee80211_rx_status *) skb->cb;
4272 hdr = (struct ieee80211_hdr *) skb->data;
4273 fc = le16_to_cpu(hdr->frame_control);
4276 switch (fc & IEEE80211_FCTL_STYPE) {
4277 case IEEE80211_STYPE_S1G_BEACON:
4278 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4281 sdata_unlock(sdata);
4284 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4285 struct sk_buff *skb)
4287 struct ieee80211_rx_status *rx_status;
4288 struct ieee80211_mgmt *mgmt;
4290 struct ieee802_11_elems elems;
4293 rx_status = (struct ieee80211_rx_status *) skb->cb;
4294 mgmt = (struct ieee80211_mgmt *) skb->data;
4295 fc = le16_to_cpu(mgmt->frame_control);
4299 switch (fc & IEEE80211_FCTL_STYPE) {
4300 case IEEE80211_STYPE_BEACON:
4301 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4302 skb->len, rx_status);
4304 case IEEE80211_STYPE_PROBE_RESP:
4305 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4307 case IEEE80211_STYPE_AUTH:
4308 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4310 case IEEE80211_STYPE_DEAUTH:
4311 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4313 case IEEE80211_STYPE_DISASSOC:
4314 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4316 case IEEE80211_STYPE_ASSOC_RESP:
4317 case IEEE80211_STYPE_REASSOC_RESP:
4318 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4320 case IEEE80211_STYPE_ACTION:
4321 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4322 ies_len = skb->len -
4323 offsetof(struct ieee80211_mgmt,
4324 u.action.u.chan_switch.variable);
4329 /* CSA IE cannot be overridden, no need for BSSID */
4330 ieee802_11_parse_elems(
4331 mgmt->u.action.u.chan_switch.variable,
4332 ies_len, true, &elems, mgmt->bssid, NULL);
4334 if (elems.parse_error)
4337 ieee80211_sta_process_chanswitch(sdata,
4339 rx_status->device_timestamp,
4341 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4342 ies_len = skb->len -
4343 offsetof(struct ieee80211_mgmt,
4344 u.action.u.ext_chan_switch.variable);
4350 * extended CSA IE can't be overridden, no need for
4353 ieee802_11_parse_elems(
4354 mgmt->u.action.u.ext_chan_switch.variable,
4355 ies_len, true, &elems, mgmt->bssid, NULL);
4357 if (elems.parse_error)
4360 /* for the handling code pretend this was also an IE */
4361 elems.ext_chansw_ie =
4362 &mgmt->u.action.u.ext_chan_switch.data;
4364 ieee80211_sta_process_chanswitch(sdata,
4366 rx_status->device_timestamp,
4371 sdata_unlock(sdata);
4374 static void ieee80211_sta_timer(struct timer_list *t)
4376 struct ieee80211_sub_if_data *sdata =
4377 from_timer(sdata, t, u.mgd.timer);
4379 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4382 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4383 u8 *bssid, u8 reason, bool tx)
4385 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4387 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4390 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4394 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4396 struct ieee80211_local *local = sdata->local;
4397 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4398 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4402 u16 prepare_tx_duration = 0;
4404 sdata_assert_lock(sdata);
4406 if (WARN_ON_ONCE(!auth_data))
4411 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4412 sdata_info(sdata, "authentication with %pM timed out\n",
4413 auth_data->bss->bssid);
4416 * Most likely AP is not in the range so remove the
4417 * bss struct for that AP.
4419 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4424 if (auth_data->algorithm == WLAN_AUTH_SAE)
4425 prepare_tx_duration =
4426 jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4428 drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
4430 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4431 auth_data->bss->bssid, auth_data->tries,
4432 IEEE80211_AUTH_MAX_TRIES);
4434 auth_data->expected_transaction = 2;
4436 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4437 trans = auth_data->sae_trans;
4438 status = auth_data->sae_status;
4439 auth_data->expected_transaction = trans;
4442 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4443 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4444 IEEE80211_TX_INTFL_MLME_CONN_TX;
4446 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4447 auth_data->data, auth_data->data_len,
4448 auth_data->bss->bssid,
4449 auth_data->bss->bssid, NULL, 0, 0,
4452 if (tx_flags == 0) {
4453 if (auth_data->algorithm == WLAN_AUTH_SAE)
4454 auth_data->timeout = jiffies +
4455 IEEE80211_AUTH_TIMEOUT_SAE;
4457 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4459 auth_data->timeout =
4460 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4463 auth_data->timeout_started = true;
4464 run_again(sdata, auth_data->timeout);
4469 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4471 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4472 struct ieee80211_local *local = sdata->local;
4474 sdata_assert_lock(sdata);
4476 assoc_data->tries++;
4477 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4478 sdata_info(sdata, "association with %pM timed out\n",
4479 assoc_data->bss->bssid);
4482 * Most likely AP is not in the range so remove the
4483 * bss struct for that AP.
4485 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4490 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4491 assoc_data->bss->bssid, assoc_data->tries,
4492 IEEE80211_ASSOC_MAX_TRIES);
4493 ieee80211_send_assoc(sdata);
4495 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4496 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4497 assoc_data->timeout_started = true;
4498 run_again(sdata, assoc_data->timeout);
4500 assoc_data->timeout =
4501 round_jiffies_up(jiffies +
4502 IEEE80211_ASSOC_TIMEOUT_LONG);
4503 assoc_data->timeout_started = true;
4504 run_again(sdata, assoc_data->timeout);
4510 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4511 __le16 fc, bool acked)
4513 struct ieee80211_local *local = sdata->local;
4515 sdata->u.mgd.status_fc = fc;
4516 sdata->u.mgd.status_acked = acked;
4517 sdata->u.mgd.status_received = true;
4519 ieee80211_queue_work(&local->hw, &sdata->work);
4522 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4524 struct ieee80211_local *local = sdata->local;
4525 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4529 if (ifmgd->status_received) {
4530 __le16 fc = ifmgd->status_fc;
4531 bool status_acked = ifmgd->status_acked;
4533 ifmgd->status_received = false;
4534 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4536 if (ifmgd->auth_data->algorithm ==
4538 ifmgd->auth_data->timeout =
4540 IEEE80211_AUTH_TIMEOUT_SAE;
4542 ifmgd->auth_data->timeout =
4544 IEEE80211_AUTH_TIMEOUT_SHORT;
4545 run_again(sdata, ifmgd->auth_data->timeout);
4547 ifmgd->auth_data->timeout = jiffies - 1;
4549 ifmgd->auth_data->timeout_started = true;
4550 } else if (ifmgd->assoc_data &&
4551 (ieee80211_is_assoc_req(fc) ||
4552 ieee80211_is_reassoc_req(fc))) {
4554 ifmgd->assoc_data->timeout =
4555 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4556 run_again(sdata, ifmgd->assoc_data->timeout);
4558 ifmgd->assoc_data->timeout = jiffies - 1;
4560 ifmgd->assoc_data->timeout_started = true;
4564 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4565 time_after(jiffies, ifmgd->auth_data->timeout)) {
4566 if (ifmgd->auth_data->done) {
4568 * ok ... we waited for assoc but userspace didn't,
4569 * so let's just kill the auth data
4571 ieee80211_destroy_auth_data(sdata, false);
4572 } else if (ieee80211_auth(sdata)) {
4574 struct ieee80211_event event = {
4576 .u.mlme.data = AUTH_EVENT,
4577 .u.mlme.status = MLME_TIMEOUT,
4580 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4582 ieee80211_destroy_auth_data(sdata, false);
4584 cfg80211_auth_timeout(sdata->dev, bssid);
4585 drv_event_callback(sdata->local, sdata, &event);
4587 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4588 run_again(sdata, ifmgd->auth_data->timeout);
4590 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4591 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4592 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4593 ieee80211_do_assoc(sdata)) {
4594 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4595 struct ieee80211_event event = {
4597 .u.mlme.data = ASSOC_EVENT,
4598 .u.mlme.status = MLME_TIMEOUT,
4601 ieee80211_destroy_assoc_data(sdata, false, false);
4602 cfg80211_assoc_timeout(sdata->dev, bss);
4603 drv_event_callback(sdata->local, sdata, &event);
4605 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4606 run_again(sdata, ifmgd->assoc_data->timeout);
4608 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4609 ifmgd->associated) {
4613 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4615 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4616 max_tries = max_nullfunc_tries;
4618 max_tries = max_probe_tries;
4620 /* ACK received for nullfunc probing frame */
4621 if (!ifmgd->probe_send_count)
4622 ieee80211_reset_ap_probe(sdata);
4623 else if (ifmgd->nullfunc_failed) {
4624 if (ifmgd->probe_send_count < max_tries) {
4626 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4627 bssid, ifmgd->probe_send_count,
4629 ieee80211_mgd_probe_ap_send(sdata);
4632 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4634 ieee80211_sta_connection_lost(sdata, bssid,
4635 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4638 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4639 run_again(sdata, ifmgd->probe_timeout);
4640 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4642 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4643 bssid, probe_wait_ms);
4644 ieee80211_sta_connection_lost(sdata, bssid,
4645 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4646 } else if (ifmgd->probe_send_count < max_tries) {
4648 "No probe response from AP %pM after %dms, try %d/%i\n",
4649 bssid, probe_wait_ms,
4650 ifmgd->probe_send_count, max_tries);
4651 ieee80211_mgd_probe_ap_send(sdata);
4654 * We actually lost the connection ... or did we?
4658 "No probe response from AP %pM after %dms, disconnecting.\n",
4659 bssid, probe_wait_ms);
4661 ieee80211_sta_connection_lost(sdata, bssid,
4662 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4666 sdata_unlock(sdata);
4669 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4671 struct ieee80211_sub_if_data *sdata =
4672 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4673 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4675 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4678 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4681 sdata->u.mgd.connection_loss = false;
4682 ieee80211_queue_work(&sdata->local->hw,
4683 &sdata->u.mgd.beacon_connection_loss_work);
4686 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4688 struct ieee80211_sub_if_data *sdata =
4689 from_timer(sdata, t, u.mgd.conn_mon_timer);
4690 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4691 struct ieee80211_local *local = sdata->local;
4692 struct sta_info *sta;
4693 unsigned long timeout;
4695 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4698 sta = sta_info_get(sdata, ifmgd->bssid);
4702 timeout = sta->status_stats.last_ack;
4703 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4704 timeout = sta->rx_stats.last_rx;
4705 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4707 /* If timeout is after now, then update timer to fire at
4708 * the later date, but do not actually probe at this time.
4710 if (time_is_after_jiffies(timeout)) {
4711 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4715 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4718 static void ieee80211_sta_monitor_work(struct work_struct *work)
4720 struct ieee80211_sub_if_data *sdata =
4721 container_of(work, struct ieee80211_sub_if_data,
4722 u.mgd.monitor_work);
4724 ieee80211_mgd_probe_ap(sdata, false);
4727 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4729 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4730 __ieee80211_stop_poll(sdata);
4732 /* let's probe the connection once */
4733 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4734 ieee80211_queue_work(&sdata->local->hw,
4735 &sdata->u.mgd.monitor_work);
4740 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4742 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4743 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4747 if (ifmgd->auth_data || ifmgd->assoc_data) {
4748 const u8 *bssid = ifmgd->auth_data ?
4749 ifmgd->auth_data->bss->bssid :
4750 ifmgd->assoc_data->bss->bssid;
4753 * If we are trying to authenticate / associate while suspending,
4754 * cfg80211 won't know and won't actually abort those attempts,
4755 * thus we need to do that ourselves.
4757 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4758 IEEE80211_STYPE_DEAUTH,
4759 WLAN_REASON_DEAUTH_LEAVING,
4761 if (ifmgd->assoc_data)
4762 ieee80211_destroy_assoc_data(sdata, false, true);
4763 if (ifmgd->auth_data)
4764 ieee80211_destroy_auth_data(sdata, false);
4765 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4766 IEEE80211_DEAUTH_FRAME_LEN,
4770 /* This is a bit of a hack - we should find a better and more generic
4771 * solution to this. Normally when suspending, cfg80211 will in fact
4772 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4773 * auth (not so important) or assoc (this is the problem) process.
4775 * As a consequence, it can happen that we are in the process of both
4776 * associating and suspending, and receive an association response
4777 * after cfg80211 has checked if it needs to disconnect, but before
4778 * we actually set the flag to drop incoming frames. This will then
4779 * cause the workqueue flush to process the association response in
4780 * the suspend, resulting in a successful association just before it
4781 * tries to remove the interface from the driver, which now though
4782 * has a channel context assigned ... this results in issues.
4784 * To work around this (for now) simply deauth here again if we're
4787 if (ifmgd->associated && !sdata->local->wowlan) {
4789 struct cfg80211_deauth_request req = {
4790 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4794 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4795 ieee80211_mgd_deauth(sdata, &req);
4798 sdata_unlock(sdata);
4801 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4803 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4806 if (!ifmgd->associated) {
4807 sdata_unlock(sdata);
4811 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4812 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4813 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4814 ieee80211_sta_connection_lost(sdata,
4815 ifmgd->associated->bssid,
4816 WLAN_REASON_UNSPECIFIED,
4818 sdata_unlock(sdata);
4821 sdata_unlock(sdata);
4825 /* interface setup */
4826 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4828 struct ieee80211_if_managed *ifmgd;
4830 ifmgd = &sdata->u.mgd;
4831 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4832 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4833 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4834 ieee80211_beacon_connection_loss_work);
4835 INIT_WORK(&ifmgd->csa_connection_drop_work,
4836 ieee80211_csa_connection_drop_work);
4837 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4838 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4839 ieee80211_tdls_peer_del_work);
4840 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4841 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4842 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4843 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4844 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4845 ieee80211_sta_handle_tspec_ac_params_wk);
4848 ifmgd->powersave = sdata->wdev.ps;
4849 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4850 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4851 ifmgd->p2p_noa_index = -1;
4853 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4854 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4856 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4858 /* Setup TDLS data */
4859 spin_lock_init(&ifmgd->teardown_lock);
4860 ifmgd->teardown_skb = NULL;
4861 ifmgd->orig_teardown_skb = NULL;
4864 /* scan finished notification */
4865 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4867 struct ieee80211_sub_if_data *sdata;
4869 /* Restart STA timers */
4871 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4872 if (ieee80211_sdata_running(sdata))
4873 ieee80211_restart_sta_timer(sdata);
4878 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4879 struct cfg80211_bss *cbss)
4881 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4882 const u8 *ht_cap_ie, *vht_cap_ie;
4883 const struct ieee80211_ht_cap *ht_cap;
4884 const struct ieee80211_vht_cap *vht_cap;
4887 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4890 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4891 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4892 ht_cap = (void *)(ht_cap_ie + 2);
4893 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4895 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4896 * "Tx Unequal Modulation Supported" fields.
4900 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4903 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4904 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4908 vht_cap = (void *)(vht_cap_ie + 2);
4909 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4910 for (nss = 8; nss > 0; nss--) {
4911 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4912 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4915 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4916 chains = max(chains, nss);
4923 ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
4924 const struct ieee80211_he_operation *he_op)
4926 const struct ieee80211_sta_he_cap *sta_he_cap =
4927 ieee80211_get_he_sta_cap(sband);
4931 if (!sta_he_cap || !he_op)
4934 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4936 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4937 for (i = 0; i < 3; i++) {
4938 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4939 &sta_he_cap->he_mcs_nss_supp;
4940 u16 sta_mcs_map_rx =
4941 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4942 u16 sta_mcs_map_tx =
4943 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4945 bool verified = true;
4948 * For each band there is a maximum of 8 spatial streams
4949 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4950 * of 2 bits per NSS (1-8), with the values defined in enum
4951 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4952 * capabilities aren't less than the AP's minimum requirements
4953 * for this HE BSS per SS.
4954 * It is enough to find one such band that meets the reqs.
4956 for (nss = 8; nss > 0; nss--) {
4957 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4958 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4959 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4961 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4965 * Make sure the HE AP doesn't require MCSs that aren't
4966 * supported by the client
4968 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4969 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4970 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4980 /* If here, STA doesn't meet AP's HE min requirements */
4984 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4985 struct cfg80211_bss *cbss)
4987 struct ieee80211_local *local = sdata->local;
4988 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4989 const struct ieee80211_ht_cap *ht_cap = NULL;
4990 const struct ieee80211_ht_operation *ht_oper = NULL;
4991 const struct ieee80211_vht_operation *vht_oper = NULL;
4992 const struct ieee80211_he_operation *he_oper = NULL;
4993 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4994 struct ieee80211_supported_band *sband;
4995 struct cfg80211_chan_def chandef;
4996 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4997 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4998 struct ieee80211_bss *bss = (void *)cbss->priv;
5003 sband = local->hw.wiphy->bands[cbss->channel->band];
5005 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5006 IEEE80211_STA_DISABLE_80P80MHZ |
5007 IEEE80211_STA_DISABLE_160MHZ);
5009 /* disable HT/VHT/HE if we don't support them */
5010 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5011 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5012 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5013 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5016 if (!sband->vht_cap.vht_supported && is_5ghz) {
5017 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5018 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5021 if (!ieee80211_get_he_sta_cap(sband))
5022 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5026 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5027 const u8 *ht_oper_ie, *ht_cap_ie;
5029 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
5030 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
5031 ht_oper = (void *)(ht_oper_ie + 2);
5033 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
5034 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
5035 ht_cap = (void *)(ht_cap_ie + 2);
5038 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5043 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5044 const u8 *vht_oper_ie, *vht_cap;
5046 vht_oper_ie = ieee80211_bss_get_ie(cbss,
5047 WLAN_EID_VHT_OPERATION);
5048 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
5049 vht_oper = (void *)(vht_oper_ie + 2);
5050 if (vht_oper && !ht_oper) {
5053 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5054 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5055 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5056 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5059 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
5060 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
5061 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5066 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5067 const struct cfg80211_bss_ies *ies;
5068 const u8 *he_oper_ie;
5070 ies = rcu_dereference(cbss->ies);
5071 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
5072 ies->data, ies->len);
5074 he_oper_ie[1] >= ieee80211_he_oper_size(&he_oper_ie[3]))
5075 he_oper = (void *)(he_oper_ie + 3);
5079 if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
5080 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5083 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5085 for (i = 0; i < sband->n_channels; i++) {
5086 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5087 IEEE80211_CHAN_NO_80MHZ))
5095 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5097 if (sband->band == NL80211_BAND_S1GHZ) {
5098 const u8 *s1g_oper_ie;
5100 s1g_oper_ie = ieee80211_bss_get_ie(cbss,
5101 WLAN_EID_S1G_OPERATION);
5102 if (s1g_oper_ie && s1g_oper_ie[1] >= sizeof(*s1g_oper))
5103 s1g_oper = (void *)(s1g_oper_ie + 2);
5106 "AP missing S1G operation element?\n");
5109 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5112 ht_oper, vht_oper, he_oper,
5116 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5121 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5122 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5126 /* will change later if needed */
5127 sdata->smps_mode = IEEE80211_SMPS_OFF;
5129 mutex_lock(&local->mtx);
5131 * If this fails (possibly due to channel context sharing
5132 * on incompatible channels, e.g. 80+80 and 160 sharing the
5133 * same control channel) try to use a smaller bandwidth.
5135 ret = ieee80211_vif_use_channel(sdata, &chandef,
5136 IEEE80211_CHANCTX_SHARED);
5138 /* don't downgrade for 5 and 10 MHz channels, though. */
5139 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5140 chandef.width == NL80211_CHAN_WIDTH_10)
5143 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5144 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5145 ret = ieee80211_vif_use_channel(sdata, &chandef,
5146 IEEE80211_CHANCTX_SHARED);
5149 mutex_unlock(&local->mtx);
5153 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5154 u8 *dtim_count, u8 *dtim_period)
5156 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5157 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5159 const struct ieee80211_tim_ie *tim = NULL;
5160 const struct ieee80211_bssid_index *idx;
5161 bool valid = tim_ie && tim_ie[1] >= 2;
5164 tim = (void *)(tim_ie + 2);
5167 *dtim_count = valid ? tim->dtim_count : 0;
5170 *dtim_period = valid ? tim->dtim_period : 0;
5172 /* Check if value is overridden by non-transmitted profile */
5173 if (!idx_ie || idx_ie[1] < 3)
5176 idx = (void *)(idx_ie + 2);
5179 *dtim_count = idx->dtim_count;
5182 *dtim_period = idx->dtim_period;
5187 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5188 struct cfg80211_bss *cbss, bool assoc,
5191 struct ieee80211_local *local = sdata->local;
5192 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5193 struct ieee80211_bss *bss = (void *)cbss->priv;
5194 struct sta_info *new_sta = NULL;
5195 struct ieee80211_supported_band *sband;
5196 bool have_sta = false;
5199 sband = local->hw.wiphy->bands[cbss->channel->band];
5201 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5204 /* If a reconfig is happening, bail out */
5205 if (local->in_reconfig)
5210 have_sta = sta_info_get(sdata, cbss->bssid);
5215 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5221 * Set up the information for the new channel before setting the
5222 * new channel. We can't - completely race-free - change the basic
5223 * rates bitmap and the channel (sband) that it refers to, but if
5224 * we set it up before we at least avoid calling into the driver's
5225 * bss_info_changed() method with invalid information (since we do
5226 * call that from changing the channel - only for IDLE and perhaps
5227 * some others, but ...).
5229 * So to avoid that, just set up all the new information before the
5230 * channel, but tell the driver to apply it only afterwards, since
5231 * it might need the new channel for that.
5234 u32 rates = 0, basic_rates = 0;
5235 bool have_higher_than_11mbit;
5236 int min_rate = INT_MAX, min_rate_index = -1;
5237 const struct cfg80211_bss_ies *ies;
5238 int shift = ieee80211_vif_get_shift(&sdata->vif);
5240 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5241 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5242 ieee80211_s1g_sta_rate_init(new_sta);
5246 ieee80211_get_rates(sband, bss->supp_rates,
5247 bss->supp_rates_len,
5248 &rates, &basic_rates,
5249 &have_higher_than_11mbit,
5250 &min_rate, &min_rate_index,
5254 * This used to be a workaround for basic rates missing
5255 * in the association response frame. Now that we no
5256 * longer use the basic rates from there, it probably
5257 * doesn't happen any more, but keep the workaround so
5258 * in case some *other* APs are buggy in different ways
5259 * we can connect -- with a warning.
5260 * Allow this workaround only in case the AP provided at least
5263 if (min_rate_index < 0) {
5265 "No legacy rates in association response\n");
5267 sta_info_free(local, new_sta);
5269 } else if (!basic_rates) {
5271 "No basic rates, using min rate instead\n");
5272 basic_rates = BIT(min_rate_index);
5276 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5279 "No rates found, keeping mandatory only\n");
5281 sdata->vif.bss_conf.basic_rates = basic_rates;
5283 /* cf. IEEE 802.11 9.2.12 */
5284 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5285 have_higher_than_11mbit)
5286 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5288 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5291 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5293 /* set timing information */
5294 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5296 ies = rcu_dereference(cbss->beacon_ies);
5298 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5299 sdata->vif.bss_conf.sync_device_ts =
5300 bss->device_ts_beacon;
5302 ieee80211_get_dtim(ies,
5303 &sdata->vif.bss_conf.sync_dtim_count,
5305 } else if (!ieee80211_hw_check(&sdata->local->hw,
5306 TIMING_BEACON_ONLY)) {
5307 ies = rcu_dereference(cbss->proberesp_ies);
5308 /* must be non-NULL since beacon IEs were NULL */
5309 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5310 sdata->vif.bss_conf.sync_device_ts =
5311 bss->device_ts_presp;
5312 sdata->vif.bss_conf.sync_dtim_count = 0;
5314 sdata->vif.bss_conf.sync_tsf = 0;
5315 sdata->vif.bss_conf.sync_device_ts = 0;
5316 sdata->vif.bss_conf.sync_dtim_count = 0;
5321 if (new_sta || override) {
5322 err = ieee80211_prep_channel(sdata, cbss);
5325 sta_info_free(local, new_sta);
5332 * tell driver about BSSID, basic rates and timing
5333 * this was set up above, before setting the channel
5335 ieee80211_bss_info_change_notify(sdata,
5336 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5337 BSS_CHANGED_BEACON_INT);
5340 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5342 err = sta_info_insert(new_sta);
5346 "failed to insert STA entry for the AP (error %d)\n",
5351 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5353 /* Cancel scan to ensure that nothing interferes with connection */
5354 if (local->scanning)
5355 ieee80211_scan_cancel(local);
5361 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5362 struct cfg80211_auth_request *req)
5364 struct ieee80211_local *local = sdata->local;
5365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5366 struct ieee80211_mgd_auth_data *auth_data;
5371 /* prepare auth data structure */
5373 switch (req->auth_type) {
5374 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5375 auth_alg = WLAN_AUTH_OPEN;
5377 case NL80211_AUTHTYPE_SHARED_KEY:
5380 auth_alg = WLAN_AUTH_SHARED_KEY;
5382 case NL80211_AUTHTYPE_FT:
5383 auth_alg = WLAN_AUTH_FT;
5385 case NL80211_AUTHTYPE_NETWORK_EAP:
5386 auth_alg = WLAN_AUTH_LEAP;
5388 case NL80211_AUTHTYPE_SAE:
5389 auth_alg = WLAN_AUTH_SAE;
5391 case NL80211_AUTHTYPE_FILS_SK:
5392 auth_alg = WLAN_AUTH_FILS_SK;
5394 case NL80211_AUTHTYPE_FILS_SK_PFS:
5395 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5397 case NL80211_AUTHTYPE_FILS_PK:
5398 auth_alg = WLAN_AUTH_FILS_PK;
5404 if (ifmgd->assoc_data)
5407 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5408 req->ie_len, GFP_KERNEL);
5412 auth_data->bss = req->bss;
5414 if (req->auth_data_len >= 4) {
5415 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5416 __le16 *pos = (__le16 *) req->auth_data;
5418 auth_data->sae_trans = le16_to_cpu(pos[0]);
5419 auth_data->sae_status = le16_to_cpu(pos[1]);
5421 memcpy(auth_data->data, req->auth_data + 4,
5422 req->auth_data_len - 4);
5423 auth_data->data_len += req->auth_data_len - 4;
5426 /* Check if continuing authentication or trying to authenticate with the
5427 * same BSS that we were in the process of authenticating with and avoid
5428 * removal and re-addition of the STA entry in
5429 * ieee80211_prep_connection().
5431 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5433 if (req->ie && req->ie_len) {
5434 memcpy(&auth_data->data[auth_data->data_len],
5435 req->ie, req->ie_len);
5436 auth_data->data_len += req->ie_len;
5439 if (req->key && req->key_len) {
5440 auth_data->key_len = req->key_len;
5441 auth_data->key_idx = req->key_idx;
5442 memcpy(auth_data->key, req->key, req->key_len);
5445 auth_data->algorithm = auth_alg;
5447 /* try to authenticate/probe */
5449 if (ifmgd->auth_data) {
5450 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5451 auth_data->peer_confirmed =
5452 ifmgd->auth_data->peer_confirmed;
5454 ieee80211_destroy_auth_data(sdata, cont_auth);
5457 /* prep auth_data so we don't go into idle on disassoc */
5458 ifmgd->auth_data = auth_data;
5460 /* If this is continuation of an ongoing SAE authentication exchange
5461 * (i.e., request to send SAE Confirm) and the peer has already
5462 * confirmed, mark authentication completed since we are about to send
5465 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5466 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5467 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5469 if (ifmgd->associated) {
5470 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5473 "disconnect from AP %pM for new auth to %pM\n",
5474 ifmgd->associated->bssid, req->bss->bssid);
5475 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5476 WLAN_REASON_UNSPECIFIED,
5479 ieee80211_report_disconnect(sdata, frame_buf,
5480 sizeof(frame_buf), true,
5481 WLAN_REASON_UNSPECIFIED,
5485 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5487 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5491 err = ieee80211_auth(sdata);
5493 sta_info_destroy_addr(sdata, req->bss->bssid);
5497 /* hold our own reference */
5498 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5502 eth_zero_addr(ifmgd->bssid);
5503 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5504 ifmgd->auth_data = NULL;
5505 mutex_lock(&sdata->local->mtx);
5506 ieee80211_vif_release_channel(sdata);
5507 mutex_unlock(&sdata->local->mtx);
5512 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5513 struct cfg80211_assoc_request *req)
5515 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5516 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5517 struct ieee80211_local *local = sdata->local;
5518 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5519 struct ieee80211_bss *bss = (void *)req->bss->priv;
5520 struct ieee80211_mgd_assoc_data *assoc_data;
5521 const struct cfg80211_bss_ies *beacon_ies;
5522 struct ieee80211_supported_band *sband;
5523 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5524 const u8 *ssidie, *ht_ie, *vht_ie;
5526 bool override = false;
5528 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5533 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5534 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
5539 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5540 assoc_data->ssid_len = ssidie[1];
5541 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5542 bss_conf->ssid_len = assoc_data->ssid_len;
5545 if (ifmgd->associated) {
5546 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5549 "disconnect from AP %pM for new assoc to %pM\n",
5550 ifmgd->associated->bssid, req->bss->bssid);
5551 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5552 WLAN_REASON_UNSPECIFIED,
5555 ieee80211_report_disconnect(sdata, frame_buf,
5556 sizeof(frame_buf), true,
5557 WLAN_REASON_UNSPECIFIED,
5561 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5566 if (ifmgd->assoc_data) {
5571 if (ifmgd->auth_data) {
5574 /* keep sta info, bssid if matching */
5575 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5576 ieee80211_destroy_auth_data(sdata, match);
5579 /* prepare assoc data */
5581 ifmgd->beacon_crc_valid = false;
5583 assoc_data->wmm = bss->wmm_used &&
5584 (local->hw.queues >= IEEE80211_NUM_ACS);
5587 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5588 * We still associate in non-HT mode (11a/b/g) if any one of these
5589 * ciphers is configured as pairwise.
5590 * We can set this to true for non-11n hardware, that'll be checked
5591 * separately along with the peer capabilities.
5593 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5594 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5595 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5596 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5597 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5598 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5599 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5600 netdev_info(sdata->dev,
5601 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5605 sband = local->hw.wiphy->bands[req->bss->channel->band];
5607 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5608 if (!bss->wmm_used) {
5609 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5610 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5611 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5612 netdev_info(sdata->dev,
5613 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5616 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5617 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5618 sizeof(ifmgd->ht_capa_mask));
5620 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5621 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5622 sizeof(ifmgd->vht_capa_mask));
5624 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5625 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5626 sizeof(ifmgd->s1g_capa_mask));
5628 if (req->ie && req->ie_len) {
5629 memcpy(assoc_data->ie, req->ie, req->ie_len);
5630 assoc_data->ie_len = req->ie_len;
5633 if (req->fils_kek) {
5634 /* should already be checked in cfg80211 - so warn */
5635 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5639 memcpy(assoc_data->fils_kek, req->fils_kek,
5641 assoc_data->fils_kek_len = req->fils_kek_len;
5644 if (req->fils_nonces)
5645 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5646 2 * FILS_NONCE_LEN);
5648 assoc_data->bss = req->bss;
5650 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5651 if (ifmgd->powersave)
5652 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5654 sdata->smps_mode = IEEE80211_SMPS_OFF;
5656 sdata->smps_mode = ifmgd->req_smps;
5658 assoc_data->capability = req->bss->capability;
5659 assoc_data->supp_rates = bss->supp_rates;
5660 assoc_data->supp_rates_len = bss->supp_rates_len;
5663 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5664 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5665 assoc_data->ap_ht_param =
5666 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5668 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5669 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5670 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5671 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5672 sizeof(struct ieee80211_vht_cap));
5674 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5675 IEEE80211_STA_DISABLE_HE;
5678 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5679 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5680 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5681 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5683 if (bss->wmm_used && bss->uapsd_supported &&
5684 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5685 assoc_data->uapsd = true;
5686 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5688 assoc_data->uapsd = false;
5689 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5692 if (req->prev_bssid)
5693 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5696 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5697 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5699 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5700 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5703 if (req->flags & ASSOC_REQ_USE_RRM)
5704 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5706 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5708 if (req->crypto.control_port)
5709 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5711 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5713 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5714 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5715 sdata->control_port_over_nl80211 =
5716 req->crypto.control_port_over_nl80211;
5717 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5718 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5721 /* kick off associate process */
5723 ifmgd->assoc_data = assoc_data;
5724 ifmgd->dtim_period = 0;
5725 ifmgd->have_beacon = false;
5727 /* override HT/VHT configuration only if the AP and we support it */
5728 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5729 struct ieee80211_sta_ht_cap sta_ht_cap;
5731 if (req->flags & ASSOC_REQ_DISABLE_HT)
5734 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5735 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5737 /* check for 40 MHz disable override */
5738 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5739 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5740 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5743 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5744 req->flags & ASSOC_REQ_DISABLE_VHT)
5748 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5749 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5750 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5751 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5754 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5755 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5757 if (req->flags & ASSOC_REQ_DISABLE_HE)
5758 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5760 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5765 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5767 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5770 * Wait up to one beacon interval ...
5771 * should this be more if we miss one?
5773 sdata_info(sdata, "waiting for beacon from %pM\n",
5775 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5776 assoc_data->timeout_started = true;
5777 assoc_data->need_beacon = true;
5778 } else if (beacon_ies) {
5779 const struct element *elem;
5782 ieee80211_get_dtim(beacon_ies, &dtim_count,
5783 &ifmgd->dtim_period);
5785 ifmgd->have_beacon = true;
5786 assoc_data->timeout = jiffies;
5787 assoc_data->timeout_started = true;
5789 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5790 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5791 sdata->vif.bss_conf.sync_device_ts =
5792 bss->device_ts_beacon;
5793 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5796 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5797 beacon_ies->data, beacon_ies->len);
5798 if (elem && elem->datalen >= 3)
5799 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5801 sdata->vif.bss_conf.profile_periodicity = 0;
5803 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5804 beacon_ies->data, beacon_ies->len);
5805 if (elem && elem->datalen >= 11 &&
5806 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5807 sdata->vif.bss_conf.ema_ap = true;
5809 sdata->vif.bss_conf.ema_ap = false;
5811 assoc_data->timeout = jiffies;
5812 assoc_data->timeout_started = true;
5816 run_again(sdata, assoc_data->timeout);
5818 if (bss->corrupt_data) {
5819 char *corrupt_type = "data";
5820 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5821 if (bss->corrupt_data &
5822 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5823 corrupt_type = "beacon and probe response";
5825 corrupt_type = "beacon";
5826 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5827 corrupt_type = "probe response";
5828 sdata_info(sdata, "associating with AP with corrupt %s\n",
5834 eth_zero_addr(ifmgd->bssid);
5835 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5836 ifmgd->assoc_data = NULL;
5842 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5843 struct cfg80211_deauth_request *req)
5845 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5846 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5847 bool tx = !req->local_state_change;
5849 if (ifmgd->auth_data &&
5850 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5852 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5853 req->bssid, req->reason_code,
5854 ieee80211_get_reason_code_string(req->reason_code));
5856 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5857 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5858 IEEE80211_STYPE_DEAUTH,
5859 req->reason_code, tx,
5861 ieee80211_destroy_auth_data(sdata, false);
5862 ieee80211_report_disconnect(sdata, frame_buf,
5863 sizeof(frame_buf), true,
5864 req->reason_code, false);
5869 if (ifmgd->assoc_data &&
5870 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5872 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5873 req->bssid, req->reason_code,
5874 ieee80211_get_reason_code_string(req->reason_code));
5876 drv_mgd_prepare_tx(sdata->local, sdata, 0);
5877 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5878 IEEE80211_STYPE_DEAUTH,
5879 req->reason_code, tx,
5881 ieee80211_destroy_assoc_data(sdata, false, true);
5882 ieee80211_report_disconnect(sdata, frame_buf,
5883 sizeof(frame_buf), true,
5884 req->reason_code, false);
5888 if (ifmgd->associated &&
5889 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5891 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5892 req->bssid, req->reason_code,
5893 ieee80211_get_reason_code_string(req->reason_code));
5895 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5896 req->reason_code, tx, frame_buf);
5897 ieee80211_report_disconnect(sdata, frame_buf,
5898 sizeof(frame_buf), true,
5899 req->reason_code, false);
5906 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5907 struct cfg80211_disassoc_request *req)
5909 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5911 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5914 * cfg80211 should catch this ... but it's racy since
5915 * we can receive a disassoc frame, process it, hand it
5916 * to cfg80211 while that's in a locked section already
5917 * trying to tell us that the user wants to disconnect.
5919 if (ifmgd->associated != req->bss)
5923 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5924 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5926 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5927 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5928 req->reason_code, !req->local_state_change,
5931 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5932 req->reason_code, false);
5937 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5939 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5942 * Make sure some work items will not run after this,
5943 * they will not do anything but might not have been
5944 * cancelled when disconnecting.
5946 cancel_work_sync(&ifmgd->monitor_work);
5947 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5948 cancel_work_sync(&ifmgd->request_smps_work);
5949 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5950 cancel_work_sync(&ifmgd->chswitch_work);
5951 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5954 if (ifmgd->assoc_data) {
5955 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5956 ieee80211_destroy_assoc_data(sdata, false, false);
5957 cfg80211_assoc_timeout(sdata->dev, bss);
5959 if (ifmgd->auth_data)
5960 ieee80211_destroy_auth_data(sdata, false);
5961 spin_lock_bh(&ifmgd->teardown_lock);
5962 if (ifmgd->teardown_skb) {
5963 kfree_skb(ifmgd->teardown_skb);
5964 ifmgd->teardown_skb = NULL;
5965 ifmgd->orig_teardown_skb = NULL;
5967 kfree(ifmgd->assoc_req_ies);
5968 ifmgd->assoc_req_ies = NULL;
5969 ifmgd->assoc_req_ies_len = 0;
5970 spin_unlock_bh(&ifmgd->teardown_lock);
5971 del_timer_sync(&ifmgd->timer);
5972 sdata_unlock(sdata);
5975 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5976 enum nl80211_cqm_rssi_threshold_event rssi_event,
5980 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5982 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5984 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5986 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5988 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5990 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5992 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5994 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5996 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);