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 - 2021 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 u32 vht_cap_info = 0;
377 /* if HT was/is disabled, don't track any bandwidth changes */
378 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
381 /* don't check VHT if we associated as non-VHT station */
382 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
385 /* don't check HE if we associated as non-HE station */
386 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
387 !ieee80211_get_he_iftype_cap(sband,
388 ieee80211_vif_type_p2p(&sdata->vif)))
392 if (WARN_ON_ONCE(!sta))
396 * if bss configuration changed store the new one -
397 * this may be applicable even if channel is identical
399 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
400 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
401 *changed |= BSS_CHANGED_HT;
402 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
406 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
408 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
409 flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info,
410 ht_oper, vht_oper, he_oper,
411 s1g_oper, &chandef, true);
414 * Downgrade the new channel if we associated with restricted
415 * capabilities. For example, if we associated as a 20 MHz STA
416 * to a 40 MHz AP (due to regulatory, capabilities or config
417 * reasons) then switching to a 40 MHz channel now won't do us
418 * any good -- we couldn't use it with the AP.
420 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
421 chandef.width == NL80211_CHAN_WIDTH_80P80)
422 flags |= ieee80211_chandef_downgrade(&chandef);
423 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
424 chandef.width == NL80211_CHAN_WIDTH_160)
425 flags |= ieee80211_chandef_downgrade(&chandef);
426 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
427 chandef.width > NL80211_CHAN_WIDTH_20)
428 flags |= ieee80211_chandef_downgrade(&chandef);
430 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
434 "AP %pM changed bandwidth, new config is %d.%03d MHz, "
435 "width %d (%d.%03d/%d MHz)\n",
436 ifmgd->bssid, chandef.chan->center_freq,
437 chandef.chan->freq_offset, chandef.width,
438 chandef.center_freq1, chandef.freq1_offset,
439 chandef.center_freq2);
441 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
442 IEEE80211_STA_DISABLE_VHT |
443 IEEE80211_STA_DISABLE_HE |
444 IEEE80211_STA_DISABLE_40MHZ |
445 IEEE80211_STA_DISABLE_80P80MHZ |
446 IEEE80211_STA_DISABLE_160MHZ)) ||
447 !cfg80211_chandef_valid(&chandef)) {
449 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
450 ifmgd->bssid, flags, ifmgd->flags);
454 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
458 "AP %pM changed bandwidth to incompatible one - disconnect\n",
466 /* frame sending functions */
468 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
469 struct sk_buff *skb, u8 ap_ht_param,
470 struct ieee80211_supported_band *sband,
471 struct ieee80211_channel *channel,
472 enum ieee80211_smps_mode smps)
475 u32 flags = channel->flags;
477 struct ieee80211_sta_ht_cap ht_cap;
479 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
481 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
482 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
484 /* determine capability flags */
487 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
488 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
489 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
490 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
491 cap &= ~IEEE80211_HT_CAP_SGI_40;
494 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
495 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
496 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
497 cap &= ~IEEE80211_HT_CAP_SGI_40;
503 * If 40 MHz was disabled associate as though we weren't
504 * capable of 40 MHz -- some broken APs will never fall
505 * back to trying to transmit in 20 MHz.
507 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
508 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
509 cap &= ~IEEE80211_HT_CAP_SGI_40;
512 /* set SM PS mode properly */
513 cap &= ~IEEE80211_HT_CAP_SM_PS;
515 case IEEE80211_SMPS_AUTOMATIC:
516 case IEEE80211_SMPS_NUM_MODES:
519 case IEEE80211_SMPS_OFF:
520 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
521 IEEE80211_HT_CAP_SM_PS_SHIFT;
523 case IEEE80211_SMPS_STATIC:
524 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
525 IEEE80211_HT_CAP_SM_PS_SHIFT;
527 case IEEE80211_SMPS_DYNAMIC:
528 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
529 IEEE80211_HT_CAP_SM_PS_SHIFT;
533 /* reserve and fill IE */
534 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
535 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
538 /* This function determines vht capability flags for the association
540 * Note - the function may set the owner of the MU-MIMO capability
542 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
544 struct ieee80211_supported_band *sband,
545 struct ieee80211_vht_cap *ap_vht_cap)
547 struct ieee80211_local *local = sdata->local;
550 struct ieee80211_sta_vht_cap vht_cap;
551 u32 mask, ap_bf_sts, our_bf_sts;
553 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
555 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
556 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
558 /* determine capability flags */
561 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
562 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
564 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
565 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
566 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
567 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
570 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
571 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
572 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
576 * Some APs apparently get confused if our capabilities are better
577 * than theirs, so restrict what we advertise in the assoc request.
579 if (!(ap_vht_cap->vht_cap_info &
580 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
581 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
582 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
583 else if (!(ap_vht_cap->vht_cap_info &
584 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
585 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
588 * If some other vif is using the MU-MIMO capability we cannot associate
589 * using MU-MIMO - this will lead to contradictions in the group-id
591 * Ownership is defined since association request, in order to avoid
592 * simultaneous associations with MU-MIMO.
594 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
595 bool disable_mu_mimo = false;
596 struct ieee80211_sub_if_data *other;
598 list_for_each_entry_rcu(other, &local->interfaces, list) {
599 if (other->vif.mu_mimo_owner) {
600 disable_mu_mimo = true;
605 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
607 sdata->vif.mu_mimo_owner = true;
610 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
612 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
613 our_bf_sts = cap & mask;
615 if (ap_bf_sts < our_bf_sts) {
620 /* reserve and fill IE */
621 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
622 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
625 /* This function determines HE capability flags for the association
628 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
630 struct ieee80211_supported_band *sband)
633 const struct ieee80211_sta_he_cap *he_cap = NULL;
634 struct ieee80211_chanctx_conf *chanctx_conf;
636 bool reg_cap = false;
639 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
640 if (!WARN_ON_ONCE(!chanctx_conf))
641 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
643 IEEE80211_CHAN_NO_HE);
647 he_cap = ieee80211_get_he_iftype_cap(sband,
648 ieee80211_vif_type_p2p(&sdata->vif));
649 if (!he_cap || !reg_cap)
653 * TODO: the 1 added is because this temporarily is under the EXTENSION
654 * IE. Get rid of it when it moves.
657 2 + 1 + sizeof(he_cap->he_cap_elem) +
658 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
659 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
660 he_cap->he_cap_elem.phy_cap_info);
661 pos = skb_put(skb, he_cap_size);
662 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
664 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
667 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
669 struct ieee80211_local *local = sdata->local;
670 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
671 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
673 struct ieee80211_mgmt *mgmt;
674 u8 *pos, qos_info, *ie_start;
675 size_t offset = 0, noffset;
676 int i, count, rates_len, supp_rates_len, shift;
678 struct ieee80211_supported_band *sband;
679 struct ieee80211_chanctx_conf *chanctx_conf;
680 struct ieee80211_channel *chan;
683 struct element *ext_capa = NULL;
684 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
685 const struct ieee80211_sband_iftype_data *iftd;
686 struct ieee80211_prep_tx_info info = {};
689 /* we know it's writable, cast away the const */
690 if (assoc_data->ie_len)
691 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
695 sdata_assert_lock(sdata);
698 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
699 if (WARN_ON(!chanctx_conf)) {
703 chan = chanctx_conf->def.chan;
705 sband = local->hw.wiphy->bands[chan->band];
706 shift = ieee80211_vif_get_shift(&sdata->vif);
708 if (assoc_data->supp_rates_len) {
710 * Get all rates supported by the device and the AP as
711 * some APs don't like getting a superset of their rates
712 * in the association request (e.g. D-Link DAP 1353 in
715 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
716 assoc_data->supp_rates,
717 assoc_data->supp_rates_len,
721 * In case AP not provide any supported rates information
722 * before association, we send information element(s) with
723 * all rates that we support.
726 for (i = 0; i < sband->n_bitrates; i++) {
732 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
734 skb = alloc_skb(local->hw.extra_tx_headroom +
735 sizeof(*mgmt) + /* bit too much but doesn't matter */
736 2 + assoc_data->ssid_len + /* SSID */
737 4 + rates_len + /* (extended) rates */
738 4 + /* power capability */
739 2 + 2 * sband->n_channels + /* supported channels */
740 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
741 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
742 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
743 sizeof(struct ieee80211_he_mcs_nss_supp) +
744 IEEE80211_HE_PPE_THRES_MAX_LEN +
745 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
746 assoc_data->ie_len + /* extra IEs */
747 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
749 (iftd ? iftd->vendor_elems.len : 0),
754 skb_reserve(skb, local->hw.extra_tx_headroom);
756 capab = WLAN_CAPABILITY_ESS;
758 if (sband->band == NL80211_BAND_2GHZ) {
759 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
760 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
763 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
764 capab |= WLAN_CAPABILITY_PRIVACY;
766 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
767 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
768 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
770 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
771 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
773 mgmt = skb_put_zero(skb, 24);
774 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
775 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
776 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
778 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
779 ieee80211_encode_usf(local->hw.conf.listen_interval) :
780 local->hw.conf.listen_interval);
781 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
783 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
784 IEEE80211_STYPE_REASSOC_REQ);
785 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
786 mgmt->u.reassoc_req.listen_interval = listen_int;
787 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
789 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
792 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
793 IEEE80211_STYPE_ASSOC_REQ);
794 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
795 mgmt->u.assoc_req.listen_interval = listen_int;
796 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
800 pos = skb_put(skb, 2 + assoc_data->ssid_len);
802 *pos++ = WLAN_EID_SSID;
803 *pos++ = assoc_data->ssid_len;
804 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
806 if (sband->band == NL80211_BAND_S1GHZ)
809 /* add all rates which were marked to be used above */
810 supp_rates_len = rates_len;
811 if (supp_rates_len > 8)
814 pos = skb_put(skb, supp_rates_len + 2);
815 *pos++ = WLAN_EID_SUPP_RATES;
816 *pos++ = supp_rates_len;
819 for (i = 0; i < sband->n_bitrates; i++) {
820 if (BIT(i) & rates) {
821 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
829 if (rates_len > count) {
830 pos = skb_put(skb, rates_len - count + 2);
831 *pos++ = WLAN_EID_EXT_SUPP_RATES;
832 *pos++ = rates_len - count;
834 for (i++; i < sband->n_bitrates; i++) {
835 if (BIT(i) & rates) {
837 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
845 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
846 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
847 pos = skb_put(skb, 4);
848 *pos++ = WLAN_EID_PWR_CAPABILITY;
850 *pos++ = 0; /* min tx power */
852 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
856 * Per spec, we shouldn't include the list of channels if we advertise
857 * support for extended channel switching, but we've always done that;
858 * (for now?) apply this restriction only on the (new) 6 GHz band.
860 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
861 (sband->band != NL80211_BAND_6GHZ ||
862 !ext_capa || ext_capa->datalen < 1 ||
863 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
864 /* TODO: get this in reg domain format */
865 pos = skb_put(skb, 2 * sband->n_channels + 2);
866 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
867 *pos++ = 2 * sband->n_channels;
868 for (i = 0; i < sband->n_channels; i++) {
869 *pos++ = ieee80211_frequency_to_channel(
870 sband->channels[i].center_freq);
871 *pos++ = 1; /* one channel in the subband*/
875 /* Set MBSSID support for HE AP if needed */
876 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
877 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
878 ext_capa && ext_capa->datalen >= 3)
879 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
881 /* if present, add any custom IEs that go before HT */
882 if (assoc_data->ie_len) {
883 static const u8 before_ht[] = {
886 WLAN_EID_EXT_SUPP_RATES,
887 WLAN_EID_PWR_CAPABILITY,
888 WLAN_EID_SUPPORTED_CHANNELS,
891 WLAN_EID_RRM_ENABLED_CAPABILITIES,
892 WLAN_EID_MOBILITY_DOMAIN,
893 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
894 WLAN_EID_RIC_DATA, /* reassoc only */
895 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
897 static const u8 after_ric[] = {
898 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
899 WLAN_EID_HT_CAPABILITY,
900 WLAN_EID_BSS_COEX_2040,
901 /* luckily this is almost always there */
902 WLAN_EID_EXT_CAPABILITY,
903 WLAN_EID_QOS_TRAFFIC_CAPA,
904 WLAN_EID_TIM_BCAST_REQ,
905 WLAN_EID_INTERWORKING,
906 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
907 WLAN_EID_VHT_CAPABILITY,
908 WLAN_EID_OPMODE_NOTIF,
911 noffset = ieee80211_ie_split_ric(assoc_data->ie,
914 ARRAY_SIZE(before_ht),
916 ARRAY_SIZE(after_ric),
918 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
922 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
923 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
924 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
926 if (sband->band != NL80211_BAND_6GHZ &&
927 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
928 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
929 sband, chan, sdata->smps_mode);
931 /* if present, add any custom IEs that go before VHT */
932 if (assoc_data->ie_len) {
933 static const u8 before_vht[] = {
935 * no need to list the ones split off before HT
938 WLAN_EID_BSS_COEX_2040,
939 WLAN_EID_EXT_CAPABILITY,
940 WLAN_EID_QOS_TRAFFIC_CAPA,
941 WLAN_EID_TIM_BCAST_REQ,
942 WLAN_EID_INTERWORKING,
943 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
946 /* RIC already taken above, so no need to handle here anymore */
947 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
948 before_vht, ARRAY_SIZE(before_vht),
950 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
954 /* if present, add any custom IEs that go before HE */
955 if (assoc_data->ie_len) {
956 static const u8 before_he[] = {
958 * no need to list the ones split off before VHT
961 WLAN_EID_OPMODE_NOTIF,
962 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
964 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
965 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
966 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
967 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
968 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
969 /* TODO: add 11ah/11aj/11ak elements */
972 /* RIC already taken above, so no need to handle here anymore */
973 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
974 before_he, ARRAY_SIZE(before_he),
976 pos = skb_put(skb, noffset - offset);
977 memcpy(pos, assoc_data->ie + offset, noffset - offset);
981 if (sband->band != NL80211_BAND_6GHZ &&
982 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
983 ieee80211_add_vht_ie(sdata, skb, sband,
984 &assoc_data->ap_vht_cap);
987 * If AP doesn't support HT, mark HE as disabled.
988 * If on the 5GHz band, make sure it supports VHT.
990 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
991 (sband->band == NL80211_BAND_5GHZ &&
992 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
993 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
995 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
996 ieee80211_add_he_ie(sdata, skb, sband);
998 /* if present, add any custom non-vendor IEs that go after HE */
999 if (assoc_data->ie_len) {
1000 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1003 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1007 if (assoc_data->wmm) {
1008 if (assoc_data->uapsd) {
1009 qos_info = ifmgd->uapsd_queues;
1010 qos_info |= (ifmgd->uapsd_max_sp_len <<
1011 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1016 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1019 if (sband->band == NL80211_BAND_S1GHZ) {
1020 ieee80211_add_aid_request_ie(sdata, skb);
1021 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1024 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1025 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1027 /* add any remaining custom (i.e. vendor specific here) IEs */
1028 if (assoc_data->ie_len) {
1029 noffset = assoc_data->ie_len;
1030 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1033 if (assoc_data->fils_kek_len) {
1034 ret = fils_encrypt_assoc_req(skb, assoc_data);
1041 pos = skb_tail_pointer(skb);
1042 kfree(ifmgd->assoc_req_ies);
1043 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1044 if (!ifmgd->assoc_req_ies) {
1049 ifmgd->assoc_req_ies_len = pos - ie_start;
1051 drv_mgd_prepare_tx(local, sdata, &info);
1053 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1054 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1055 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1056 IEEE80211_TX_INTFL_MLME_CONN_TX;
1057 ieee80211_tx_skb(sdata, skb);
1062 void ieee80211_send_pspoll(struct ieee80211_local *local,
1063 struct ieee80211_sub_if_data *sdata)
1065 struct ieee80211_pspoll *pspoll;
1066 struct sk_buff *skb;
1068 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1072 pspoll = (struct ieee80211_pspoll *) skb->data;
1073 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1075 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1076 ieee80211_tx_skb(sdata, skb);
1079 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1080 struct ieee80211_sub_if_data *sdata,
1083 struct sk_buff *skb;
1084 struct ieee80211_hdr_3addr *nullfunc;
1085 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1087 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1088 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1092 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1094 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1096 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1097 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1099 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1100 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1102 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1103 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1105 ieee80211_tx_skb(sdata, skb);
1108 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1109 struct ieee80211_sub_if_data *sdata)
1111 struct sk_buff *skb;
1112 struct ieee80211_hdr *nullfunc;
1115 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1118 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1122 skb_reserve(skb, local->hw.extra_tx_headroom);
1124 nullfunc = skb_put_zero(skb, 30);
1125 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1126 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1127 nullfunc->frame_control = fc;
1128 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1129 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1130 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1131 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1133 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1134 ieee80211_tx_skb(sdata, skb);
1137 /* spectrum management related things */
1138 static void ieee80211_chswitch_work(struct work_struct *work)
1140 struct ieee80211_sub_if_data *sdata =
1141 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1142 struct ieee80211_local *local = sdata->local;
1143 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1146 if (!ieee80211_sdata_running(sdata))
1150 mutex_lock(&local->mtx);
1151 mutex_lock(&local->chanctx_mtx);
1153 if (!ifmgd->associated)
1156 if (!sdata->vif.csa_active)
1160 * using reservation isn't immediate as it may be deferred until later
1161 * with multi-vif. once reservation is complete it will re-schedule the
1162 * work with no reserved_chanctx so verify chandef to check if it
1163 * completed successfully
1166 if (sdata->reserved_chanctx) {
1168 * with multi-vif csa driver may call ieee80211_csa_finish()
1169 * many times while waiting for other interfaces to use their
1172 if (sdata->reserved_ready)
1175 ret = ieee80211_vif_use_reserved_context(sdata);
1178 "failed to use reserved channel context, disconnecting (err=%d)\n",
1180 ieee80211_queue_work(&sdata->local->hw,
1181 &ifmgd->csa_connection_drop_work);
1188 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1189 &sdata->csa_chandef)) {
1191 "failed to finalize channel switch, disconnecting\n");
1192 ieee80211_queue_work(&sdata->local->hw,
1193 &ifmgd->csa_connection_drop_work);
1197 ifmgd->csa_waiting_bcn = true;
1199 ieee80211_sta_reset_beacon_monitor(sdata);
1200 ieee80211_sta_reset_conn_monitor(sdata);
1203 mutex_unlock(&local->chanctx_mtx);
1204 mutex_unlock(&local->mtx);
1205 sdata_unlock(sdata);
1208 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1210 struct ieee80211_local *local = sdata->local;
1211 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1214 sdata_assert_lock(sdata);
1216 WARN_ON(!sdata->vif.csa_active);
1218 if (sdata->csa_block_tx) {
1219 ieee80211_wake_vif_queues(local, sdata,
1220 IEEE80211_QUEUE_STOP_REASON_CSA);
1221 sdata->csa_block_tx = false;
1224 sdata->vif.csa_active = false;
1225 ifmgd->csa_waiting_bcn = false;
1227 * If the CSA IE is still present on the beacon after the switch,
1228 * we need to consider it as a new CSA (possibly to self).
1230 ifmgd->beacon_crc_valid = false;
1232 ret = drv_post_channel_switch(sdata);
1235 "driver post channel switch failed, disconnecting\n");
1236 ieee80211_queue_work(&local->hw,
1237 &ifmgd->csa_connection_drop_work);
1241 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1244 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1246 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1247 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1249 trace_api_chswitch_done(sdata, success);
1252 "driver channel switch failed, disconnecting\n");
1253 ieee80211_queue_work(&sdata->local->hw,
1254 &ifmgd->csa_connection_drop_work);
1256 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1259 EXPORT_SYMBOL(ieee80211_chswitch_done);
1261 static void ieee80211_chswitch_timer(struct timer_list *t)
1263 struct ieee80211_sub_if_data *sdata =
1264 from_timer(sdata, t, u.mgd.chswitch_timer);
1266 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1270 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1272 struct ieee80211_local *local = sdata->local;
1274 if (!local->ops->abort_channel_switch)
1277 mutex_lock(&local->mtx);
1279 mutex_lock(&local->chanctx_mtx);
1280 ieee80211_vif_unreserve_chanctx(sdata);
1281 mutex_unlock(&local->chanctx_mtx);
1283 if (sdata->csa_block_tx)
1284 ieee80211_wake_vif_queues(local, sdata,
1285 IEEE80211_QUEUE_STOP_REASON_CSA);
1287 sdata->csa_block_tx = false;
1288 sdata->vif.csa_active = false;
1290 mutex_unlock(&local->mtx);
1292 drv_abort_channel_switch(sdata);
1296 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1297 u64 timestamp, u32 device_timestamp,
1298 struct ieee802_11_elems *elems,
1301 struct ieee80211_local *local = sdata->local;
1302 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1303 struct cfg80211_bss *cbss = ifmgd->associated;
1304 struct ieee80211_chanctx_conf *conf;
1305 struct ieee80211_chanctx *chanctx;
1306 enum nl80211_band current_band;
1307 struct ieee80211_csa_ie csa_ie;
1308 struct ieee80211_channel_switch ch_switch;
1309 struct ieee80211_bss *bss;
1312 sdata_assert_lock(sdata);
1317 if (local->scanning)
1320 current_band = cbss->channel->band;
1321 bss = (void *)cbss->priv;
1322 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1325 ifmgd->associated->bssid, &csa_ie);
1328 ch_switch.timestamp = timestamp;
1329 ch_switch.device_timestamp = device_timestamp;
1330 ch_switch.block_tx = csa_ie.mode;
1331 ch_switch.chandef = csa_ie.chandef;
1332 ch_switch.count = csa_ie.count;
1333 ch_switch.delay = csa_ie.max_switch_time;
1337 goto lock_and_drop_connection;
1339 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1341 ieee80211_sta_abort_chanswitch(sdata);
1343 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1345 } else if (sdata->vif.csa_active || res) {
1346 /* disregard subsequent announcements if already processing */
1350 if (sdata->vif.bss_conf.chandef.chan->band !=
1351 csa_ie.chandef.chan->band) {
1353 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1354 ifmgd->associated->bssid,
1355 csa_ie.chandef.chan->center_freq,
1356 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1357 csa_ie.chandef.center_freq2);
1358 goto lock_and_drop_connection;
1361 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1362 IEEE80211_CHAN_DISABLED)) {
1364 "AP %pM switches to unsupported channel "
1365 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1367 ifmgd->associated->bssid,
1368 csa_ie.chandef.chan->center_freq,
1369 csa_ie.chandef.chan->freq_offset,
1370 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1371 csa_ie.chandef.freq1_offset,
1372 csa_ie.chandef.center_freq2);
1373 goto lock_and_drop_connection;
1376 if (cfg80211_chandef_identical(&csa_ie.chandef,
1377 &sdata->vif.bss_conf.chandef) &&
1378 (!csa_ie.mode || !beacon)) {
1379 if (ifmgd->csa_ignored_same_chan)
1382 "AP %pM tries to chanswitch to same channel, ignore\n",
1383 ifmgd->associated->bssid);
1384 ifmgd->csa_ignored_same_chan = true;
1389 * Drop all TDLS peers - either we disconnect or move to a different
1390 * channel from this point on. There's no telling what our peer will do.
1391 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1392 * have an incompatible wider chandef.
1394 ieee80211_teardown_tdls_peers(sdata);
1396 mutex_lock(&local->mtx);
1397 mutex_lock(&local->chanctx_mtx);
1398 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1399 lockdep_is_held(&local->chanctx_mtx));
1402 "no channel context assigned to vif?, disconnecting\n");
1403 goto drop_connection;
1406 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1408 if (local->use_chanctx &&
1409 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1411 "driver doesn't support chan-switch with channel contexts\n");
1412 goto drop_connection;
1415 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1417 "preparing for channel switch failed, disconnecting\n");
1418 goto drop_connection;
1421 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1422 chanctx->mode, false);
1425 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1427 goto drop_connection;
1429 mutex_unlock(&local->chanctx_mtx);
1431 sdata->vif.csa_active = true;
1432 sdata->csa_chandef = csa_ie.chandef;
1433 sdata->csa_block_tx = csa_ie.mode;
1434 ifmgd->csa_ignored_same_chan = false;
1435 ifmgd->beacon_crc_valid = false;
1437 if (sdata->csa_block_tx)
1438 ieee80211_stop_vif_queues(local, sdata,
1439 IEEE80211_QUEUE_STOP_REASON_CSA);
1440 mutex_unlock(&local->mtx);
1442 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1443 csa_ie.count, csa_ie.mode);
1445 if (local->ops->channel_switch) {
1446 /* use driver's channel switch callback */
1447 drv_channel_switch(local, sdata, &ch_switch);
1451 /* channel switch handled in software */
1452 if (csa_ie.count <= 1)
1453 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1455 mod_timer(&ifmgd->chswitch_timer,
1456 TU_TO_EXP_TIME((csa_ie.count - 1) *
1457 cbss->beacon_interval));
1459 lock_and_drop_connection:
1460 mutex_lock(&local->mtx);
1461 mutex_lock(&local->chanctx_mtx);
1464 * This is just so that the disconnect flow will know that
1465 * we were trying to switch channel and failed. In case the
1466 * mode is 1 (we are not allowed to Tx), we will know not to
1467 * send a deauthentication frame. Those two fields will be
1468 * reset when the disconnection worker runs.
1470 sdata->vif.csa_active = true;
1471 sdata->csa_block_tx = csa_ie.mode;
1473 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1474 mutex_unlock(&local->chanctx_mtx);
1475 mutex_unlock(&local->mtx);
1479 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1480 struct ieee80211_channel *channel,
1481 const u8 *country_ie, u8 country_ie_len,
1482 const u8 *pwr_constr_elem,
1483 int *chan_pwr, int *pwr_reduction)
1485 struct ieee80211_country_ie_triplet *triplet;
1486 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1487 int i, chan_increment;
1488 bool have_chan_pwr = false;
1491 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1494 triplet = (void *)(country_ie + 3);
1495 country_ie_len -= 3;
1497 switch (channel->band) {
1501 case NL80211_BAND_2GHZ:
1502 case NL80211_BAND_60GHZ:
1505 case NL80211_BAND_5GHZ:
1508 case NL80211_BAND_6GHZ:
1510 * In the 6 GHz band, the "maximum transmit power level"
1511 * field in the triplets is reserved, and thus will be
1512 * zero and we shouldn't use it to control TX power.
1513 * The actual TX power will be given in the transmit
1514 * power envelope element instead.
1520 while (country_ie_len >= 3) {
1521 u8 first_channel = triplet->chans.first_channel;
1523 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1526 for (i = 0; i < triplet->chans.num_channels; i++) {
1527 if (first_channel + i * chan_increment == chan) {
1528 have_chan_pwr = true;
1529 *chan_pwr = triplet->chans.max_power;
1538 country_ie_len -= 3;
1541 if (have_chan_pwr && pwr_constr_elem)
1542 *pwr_reduction = *pwr_constr_elem;
1546 return have_chan_pwr;
1549 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1550 struct ieee80211_channel *channel,
1551 const u8 *cisco_dtpc_ie,
1554 /* From practical testing, the first data byte of the DTPC element
1555 * seems to contain the requested dBm level, and the CLI on Cisco
1556 * APs clearly state the range is -127 to 127 dBm, which indicates
1557 * a signed byte, although it seemingly never actually goes negative.
1558 * The other byte seems to always be zero.
1560 *pwr_level = (__s8)cisco_dtpc_ie[4];
1563 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1564 struct ieee80211_channel *channel,
1565 struct ieee80211_mgmt *mgmt,
1566 const u8 *country_ie, u8 country_ie_len,
1567 const u8 *pwr_constr_ie,
1568 const u8 *cisco_dtpc_ie)
1570 bool has_80211h_pwr = false, has_cisco_pwr = false;
1571 int chan_pwr = 0, pwr_reduction_80211h = 0;
1572 int pwr_level_cisco, pwr_level_80211h;
1574 __le16 capab = mgmt->u.probe_resp.capab_info;
1576 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1577 return 0; /* TODO */
1580 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1581 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1582 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1583 sdata, channel, country_ie, country_ie_len,
1584 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1586 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1589 if (cisco_dtpc_ie) {
1590 ieee80211_find_cisco_dtpc(
1591 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1592 has_cisco_pwr = true;
1595 if (!has_80211h_pwr && !has_cisco_pwr)
1598 /* If we have both 802.11h and Cisco DTPC, apply both limits
1599 * by picking the smallest of the two power levels advertised.
1601 if (has_80211h_pwr &&
1602 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1603 new_ap_level = pwr_level_80211h;
1605 if (sdata->ap_power_level == new_ap_level)
1609 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1610 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1611 sdata->u.mgd.bssid);
1612 } else { /* has_cisco_pwr is always true here. */
1613 new_ap_level = pwr_level_cisco;
1615 if (sdata->ap_power_level == new_ap_level)
1619 "Limiting TX power to %d dBm as advertised by %pM\n",
1620 pwr_level_cisco, sdata->u.mgd.bssid);
1623 sdata->ap_power_level = new_ap_level;
1624 if (__ieee80211_recalc_txpower(sdata))
1625 return BSS_CHANGED_TXPOWER;
1630 static void ieee80211_enable_ps(struct ieee80211_local *local,
1631 struct ieee80211_sub_if_data *sdata)
1633 struct ieee80211_conf *conf = &local->hw.conf;
1636 * If we are scanning right now then the parameters will
1637 * take effect when scan finishes.
1639 if (local->scanning)
1642 if (conf->dynamic_ps_timeout > 0 &&
1643 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1644 mod_timer(&local->dynamic_ps_timer, jiffies +
1645 msecs_to_jiffies(conf->dynamic_ps_timeout));
1647 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1648 ieee80211_send_nullfunc(local, sdata, true);
1650 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1651 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1654 conf->flags |= IEEE80211_CONF_PS;
1655 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1659 static void ieee80211_change_ps(struct ieee80211_local *local)
1661 struct ieee80211_conf *conf = &local->hw.conf;
1663 if (local->ps_sdata) {
1664 ieee80211_enable_ps(local, local->ps_sdata);
1665 } else if (conf->flags & IEEE80211_CONF_PS) {
1666 conf->flags &= ~IEEE80211_CONF_PS;
1667 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1668 del_timer_sync(&local->dynamic_ps_timer);
1669 cancel_work_sync(&local->dynamic_ps_enable_work);
1673 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1675 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1676 struct sta_info *sta = NULL;
1677 bool authorized = false;
1679 if (!mgd->powersave)
1685 if (!mgd->associated)
1688 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1691 if (!mgd->have_beacon)
1695 sta = sta_info_get(sdata, mgd->bssid);
1697 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1703 /* need to hold RTNL or interface lock */
1704 void ieee80211_recalc_ps(struct ieee80211_local *local)
1706 struct ieee80211_sub_if_data *sdata, *found = NULL;
1710 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1711 local->ps_sdata = NULL;
1715 list_for_each_entry(sdata, &local->interfaces, list) {
1716 if (!ieee80211_sdata_running(sdata))
1718 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1719 /* If an AP vif is found, then disable PS
1720 * by setting the count to zero thereby setting
1726 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1732 if (count == 1 && ieee80211_powersave_allowed(found)) {
1733 u8 dtimper = found->u.mgd.dtim_period;
1735 timeout = local->dynamic_ps_forced_timeout;
1738 local->hw.conf.dynamic_ps_timeout = timeout;
1740 /* If the TIM IE is invalid, pretend the value is 1 */
1744 local->hw.conf.ps_dtim_period = dtimper;
1745 local->ps_sdata = found;
1747 local->ps_sdata = NULL;
1750 ieee80211_change_ps(local);
1753 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1755 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1757 if (sdata->vif.bss_conf.ps != ps_allowed) {
1758 sdata->vif.bss_conf.ps = ps_allowed;
1759 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1763 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1765 struct ieee80211_local *local =
1766 container_of(work, struct ieee80211_local,
1767 dynamic_ps_disable_work);
1769 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1770 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1771 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1774 ieee80211_wake_queues_by_reason(&local->hw,
1775 IEEE80211_MAX_QUEUE_MAP,
1776 IEEE80211_QUEUE_STOP_REASON_PS,
1780 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1782 struct ieee80211_local *local =
1783 container_of(work, struct ieee80211_local,
1784 dynamic_ps_enable_work);
1785 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1786 struct ieee80211_if_managed *ifmgd;
1787 unsigned long flags;
1790 /* can only happen when PS was just disabled anyway */
1794 ifmgd = &sdata->u.mgd;
1796 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1799 if (local->hw.conf.dynamic_ps_timeout > 0) {
1800 /* don't enter PS if TX frames are pending */
1801 if (drv_tx_frames_pending(local)) {
1802 mod_timer(&local->dynamic_ps_timer, jiffies +
1804 local->hw.conf.dynamic_ps_timeout));
1809 * transmission can be stopped by others which leads to
1810 * dynamic_ps_timer expiry. Postpone the ps timer if it
1811 * is not the actual idle state.
1813 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1814 for (q = 0; q < local->hw.queues; q++) {
1815 if (local->queue_stop_reasons[q]) {
1816 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1818 mod_timer(&local->dynamic_ps_timer, jiffies +
1820 local->hw.conf.dynamic_ps_timeout));
1824 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1827 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1828 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1829 if (drv_tx_frames_pending(local)) {
1830 mod_timer(&local->dynamic_ps_timer, jiffies +
1832 local->hw.conf.dynamic_ps_timeout));
1834 ieee80211_send_nullfunc(local, sdata, true);
1835 /* Flush to get the tx status of nullfunc frame */
1836 ieee80211_flush_queues(local, sdata, false);
1840 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1841 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1842 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1843 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1844 local->hw.conf.flags |= IEEE80211_CONF_PS;
1845 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1849 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1851 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1853 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1856 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1858 struct delayed_work *delayed_work = to_delayed_work(work);
1859 struct ieee80211_sub_if_data *sdata =
1860 container_of(delayed_work, struct ieee80211_sub_if_data,
1861 dfs_cac_timer_work);
1862 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1864 mutex_lock(&sdata->local->mtx);
1865 if (sdata->wdev.cac_started) {
1866 ieee80211_vif_release_channel(sdata);
1867 cfg80211_cac_event(sdata->dev, &chandef,
1868 NL80211_RADAR_CAC_FINISHED,
1871 mutex_unlock(&sdata->local->mtx);
1875 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1877 struct ieee80211_local *local = sdata->local;
1878 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1882 if (local->hw.queues < IEEE80211_NUM_ACS)
1885 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1886 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1888 unsigned long now = jiffies;
1890 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1891 tx_tspec->admitted_time &&
1892 time_after(now, tx_tspec->time_slice_start + HZ)) {
1893 tx_tspec->consumed_tx_time = 0;
1894 tx_tspec->time_slice_start = now;
1896 if (tx_tspec->downgraded)
1898 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1901 switch (tx_tspec->action) {
1902 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1903 /* take the original parameters */
1904 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1906 "failed to set TX queue parameters for queue %d\n",
1908 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1909 tx_tspec->downgraded = false;
1912 case TX_TSPEC_ACTION_DOWNGRADE:
1913 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1914 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1918 /* downgrade next lower non-ACM AC */
1919 for (non_acm_ac = ac + 1;
1920 non_acm_ac < IEEE80211_NUM_ACS;
1922 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1924 /* Usually the loop will result in using BK even if it
1925 * requires admission control, but such a configuration
1926 * makes no sense and we have to transmit somehow - the
1927 * AC selection does the same thing.
1928 * If we started out trying to downgrade from BK, then
1929 * the extra condition here might be needed.
1931 if (non_acm_ac >= IEEE80211_NUM_ACS)
1932 non_acm_ac = IEEE80211_AC_BK;
1933 if (drv_conf_tx(local, sdata, ac,
1934 &sdata->tx_conf[non_acm_ac]))
1936 "failed to set TX queue parameters for queue %d\n",
1938 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1940 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1941 tx_tspec->time_slice_start + HZ - now + 1);
1943 case TX_TSPEC_ACTION_NONE:
1952 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1954 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1955 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1958 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1960 struct ieee80211_sub_if_data *sdata;
1962 sdata = container_of(work, struct ieee80211_sub_if_data,
1963 u.mgd.tx_tspec_wk.work);
1964 ieee80211_sta_handle_tspec_ac_params(sdata);
1969 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1970 struct ieee80211_sub_if_data *sdata,
1971 const u8 *wmm_param, size_t wmm_param_len,
1972 const struct ieee80211_mu_edca_param_set *mu_edca)
1974 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1975 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1977 int count, mu_edca_count, ac;
1979 u8 uapsd_queues = 0;
1981 if (!local->ops->conf_tx)
1984 if (local->hw.queues < IEEE80211_NUM_ACS)
1990 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1993 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1994 uapsd_queues = ifmgd->uapsd_queues;
1996 count = wmm_param[6] & 0x0f;
1997 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1998 * if mu_edca was preset before and now it disappeared tell
1999 * the driver about it.
2001 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2002 if (count == ifmgd->wmm_last_param_set &&
2003 mu_edca_count == ifmgd->mu_edca_last_param_set)
2005 ifmgd->wmm_last_param_set = count;
2006 ifmgd->mu_edca_last_param_set = mu_edca_count;
2008 pos = wmm_param + 8;
2009 left = wmm_param_len - 8;
2011 memset(¶ms, 0, sizeof(params));
2014 for (; left >= 4; left -= 4, pos += 4) {
2015 int aci = (pos[0] >> 5) & 0x03;
2016 int acm = (pos[0] >> 4) & 0x01;
2021 ac = IEEE80211_AC_BK;
2023 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2024 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2026 params[ac].mu_edca = !!mu_edca;
2028 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2031 ac = IEEE80211_AC_VI;
2033 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2034 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2036 params[ac].mu_edca = !!mu_edca;
2038 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2041 ac = IEEE80211_AC_VO;
2043 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2044 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2046 params[ac].mu_edca = !!mu_edca;
2048 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2052 ac = IEEE80211_AC_BE;
2054 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2055 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2057 params[ac].mu_edca = !!mu_edca;
2059 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2063 params[ac].aifs = pos[0] & 0x0f;
2065 if (params[ac].aifs < 2) {
2067 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2068 params[ac].aifs, aci);
2069 params[ac].aifs = 2;
2071 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2072 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2073 params[ac].txop = get_unaligned_le16(pos + 2);
2074 params[ac].acm = acm;
2075 params[ac].uapsd = uapsd;
2077 if (params[ac].cw_min == 0 ||
2078 params[ac].cw_min > params[ac].cw_max) {
2080 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2081 params[ac].cw_min, params[ac].cw_max, aci);
2084 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2087 /* WMM specification requires all 4 ACIs. */
2088 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2089 if (params[ac].cw_min == 0) {
2091 "AP has invalid WMM params (missing AC %d), using defaults\n",
2097 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2099 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2101 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2102 params[ac].txop, params[ac].uapsd,
2103 ifmgd->tx_tspec[ac].downgraded);
2104 sdata->tx_conf[ac] = params[ac];
2105 if (!ifmgd->tx_tspec[ac].downgraded &&
2106 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2108 "failed to set TX queue parameters for AC %d\n",
2112 /* enable WMM or activate new settings */
2113 sdata->vif.bss_conf.qos = true;
2117 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2119 lockdep_assert_held(&sdata->local->mtx);
2121 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2122 ieee80211_run_deferred_scan(sdata->local);
2125 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2127 mutex_lock(&sdata->local->mtx);
2128 __ieee80211_stop_poll(sdata);
2129 mutex_unlock(&sdata->local->mtx);
2132 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2133 u16 capab, bool erp_valid, u8 erp)
2135 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2136 struct ieee80211_supported_band *sband;
2138 bool use_protection;
2139 bool use_short_preamble;
2140 bool use_short_slot;
2142 sband = ieee80211_get_sband(sdata);
2147 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2148 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2150 use_protection = false;
2151 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2154 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2155 if (sband->band == NL80211_BAND_5GHZ ||
2156 sband->band == NL80211_BAND_6GHZ)
2157 use_short_slot = true;
2159 if (use_protection != bss_conf->use_cts_prot) {
2160 bss_conf->use_cts_prot = use_protection;
2161 changed |= BSS_CHANGED_ERP_CTS_PROT;
2164 if (use_short_preamble != bss_conf->use_short_preamble) {
2165 bss_conf->use_short_preamble = use_short_preamble;
2166 changed |= BSS_CHANGED_ERP_PREAMBLE;
2169 if (use_short_slot != bss_conf->use_short_slot) {
2170 bss_conf->use_short_slot = use_short_slot;
2171 changed |= BSS_CHANGED_ERP_SLOT;
2177 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2178 struct cfg80211_bss *cbss,
2179 u32 bss_info_changed)
2181 struct ieee80211_bss *bss = (void *)cbss->priv;
2182 struct ieee80211_local *local = sdata->local;
2183 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2185 bss_info_changed |= BSS_CHANGED_ASSOC;
2186 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2187 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2189 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2190 beacon_loss_count * bss_conf->beacon_int));
2192 sdata->u.mgd.associated = cbss;
2193 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2195 ieee80211_check_rate_mask(sdata);
2197 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2199 if (sdata->vif.p2p ||
2200 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2201 const struct cfg80211_bss_ies *ies;
2204 ies = rcu_dereference(cbss->ies);
2208 ret = cfg80211_get_p2p_attr(
2209 ies->data, ies->len,
2210 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2211 (u8 *) &bss_conf->p2p_noa_attr,
2212 sizeof(bss_conf->p2p_noa_attr));
2214 sdata->u.mgd.p2p_noa_index =
2215 bss_conf->p2p_noa_attr.index;
2216 bss_info_changed |= BSS_CHANGED_P2P_PS;
2222 /* just to be sure */
2223 ieee80211_stop_poll(sdata);
2225 ieee80211_led_assoc(local, 1);
2227 if (sdata->u.mgd.have_beacon) {
2229 * If the AP is buggy we may get here with no DTIM period
2230 * known, so assume it's 1 which is the only safe assumption
2231 * in that case, although if the TIM IE is broken powersave
2232 * probably just won't work at all.
2234 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2235 bss_conf->beacon_rate = bss->beacon_rate;
2236 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2238 bss_conf->beacon_rate = NULL;
2239 bss_conf->dtim_period = 0;
2242 bss_conf->assoc = 1;
2244 /* Tell the driver to monitor connection quality (if supported) */
2245 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2246 bss_conf->cqm_rssi_thold)
2247 bss_info_changed |= BSS_CHANGED_CQM;
2249 /* Enable ARP filtering */
2250 if (bss_conf->arp_addr_cnt)
2251 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2253 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2255 mutex_lock(&local->iflist_mtx);
2256 ieee80211_recalc_ps(local);
2257 mutex_unlock(&local->iflist_mtx);
2259 ieee80211_recalc_smps(sdata);
2260 ieee80211_recalc_ps_vif(sdata);
2262 netif_carrier_on(sdata->dev);
2265 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2266 u16 stype, u16 reason, bool tx,
2269 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2270 struct ieee80211_local *local = sdata->local;
2272 struct ieee80211_prep_tx_info info = {
2276 sdata_assert_lock(sdata);
2278 if (WARN_ON_ONCE(tx && !frame_buf))
2281 if (WARN_ON(!ifmgd->associated))
2284 ieee80211_stop_poll(sdata);
2286 ifmgd->associated = NULL;
2287 netif_carrier_off(sdata->dev);
2290 * if we want to get out of ps before disassoc (why?) we have
2291 * to do it before sending disassoc, as otherwise the null-packet
2294 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2295 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2296 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2298 local->ps_sdata = NULL;
2300 /* disable per-vif ps */
2301 ieee80211_recalc_ps_vif(sdata);
2303 /* make sure ongoing transmission finishes */
2307 * drop any frame before deauth/disassoc, this can be data or
2308 * management frame. Since we are disconnecting, we should not
2309 * insist sending these frames which can take time and delay
2310 * the disconnection and possible the roaming.
2313 ieee80211_flush_queues(local, sdata, true);
2315 /* deauthenticate/disassociate now */
2316 if (tx || frame_buf) {
2318 * In multi channel scenarios guarantee that the virtual
2319 * interface is granted immediate airtime to transmit the
2320 * deauthentication frame by calling mgd_prepare_tx, if the
2321 * driver requested so.
2323 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2324 !ifmgd->have_beacon) {
2325 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2328 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2329 ifmgd->bssid, stype, reason,
2333 /* flush out frame - make sure the deauth was actually sent */
2335 ieee80211_flush_queues(local, sdata, false);
2337 drv_mgd_complete_tx(sdata->local, sdata, &info);
2339 /* clear bssid only after building the needed mgmt frames */
2340 eth_zero_addr(ifmgd->bssid);
2342 sdata->vif.bss_conf.ssid_len = 0;
2344 /* remove AP and TDLS peers */
2345 sta_info_flush(sdata);
2347 /* finally reset all BSS / config parameters */
2348 changed |= ieee80211_reset_erp_info(sdata);
2350 ieee80211_led_assoc(local, 0);
2351 changed |= BSS_CHANGED_ASSOC;
2352 sdata->vif.bss_conf.assoc = false;
2354 ifmgd->p2p_noa_index = -1;
2355 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2356 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2358 /* on the next assoc, re-program HT/VHT parameters */
2359 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2360 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2361 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2362 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2364 /* reset MU-MIMO ownership and group data */
2365 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2366 sizeof(sdata->vif.bss_conf.mu_group.membership));
2367 memset(sdata->vif.bss_conf.mu_group.position, 0,
2368 sizeof(sdata->vif.bss_conf.mu_group.position));
2369 changed |= BSS_CHANGED_MU_GROUPS;
2370 sdata->vif.mu_mimo_owner = false;
2372 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2374 del_timer_sync(&local->dynamic_ps_timer);
2375 cancel_work_sync(&local->dynamic_ps_enable_work);
2377 /* Disable ARP filtering */
2378 if (sdata->vif.bss_conf.arp_addr_cnt)
2379 changed |= BSS_CHANGED_ARP_FILTER;
2381 sdata->vif.bss_conf.qos = false;
2382 changed |= BSS_CHANGED_QOS;
2384 /* The BSSID (not really interesting) and HT changed */
2385 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2386 ieee80211_bss_info_change_notify(sdata, changed);
2388 /* disassociated - set to defaults now */
2389 ieee80211_set_wmm_default(sdata, false, false);
2391 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2392 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2393 del_timer_sync(&sdata->u.mgd.timer);
2394 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2396 sdata->vif.bss_conf.dtim_period = 0;
2397 sdata->vif.bss_conf.beacon_rate = NULL;
2399 ifmgd->have_beacon = false;
2402 mutex_lock(&local->mtx);
2403 ieee80211_vif_release_channel(sdata);
2405 sdata->vif.csa_active = false;
2406 ifmgd->csa_waiting_bcn = false;
2407 ifmgd->csa_ignored_same_chan = false;
2408 if (sdata->csa_block_tx) {
2409 ieee80211_wake_vif_queues(local, sdata,
2410 IEEE80211_QUEUE_STOP_REASON_CSA);
2411 sdata->csa_block_tx = false;
2413 mutex_unlock(&local->mtx);
2415 /* existing TX TSPEC sessions no longer exist */
2416 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2417 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2419 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2422 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2425 struct ieee80211_local *local = sdata->local;
2427 mutex_lock(&local->mtx);
2428 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2431 __ieee80211_stop_poll(sdata);
2433 mutex_lock(&local->iflist_mtx);
2434 ieee80211_recalc_ps(local);
2435 mutex_unlock(&local->iflist_mtx);
2437 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2441 * We've received a probe response, but are not sure whether
2442 * we have or will be receiving any beacons or data, so let's
2443 * schedule the timers again, just in case.
2445 ieee80211_sta_reset_beacon_monitor(sdata);
2447 mod_timer(&ifmgd->conn_mon_timer,
2448 round_jiffies_up(jiffies +
2449 IEEE80211_CONNECTION_IDLE_TIME));
2451 mutex_unlock(&local->mtx);
2454 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2455 struct ieee80211_hdr *hdr,
2458 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2461 struct ieee80211_sta_tx_tspec *tx_tspec;
2462 unsigned long now = jiffies;
2464 if (!ieee80211_is_data_qos(hdr->frame_control))
2467 tid = ieee80211_get_tid(hdr);
2468 ac = ieee80211_ac_from_tid(tid);
2469 tx_tspec = &ifmgd->tx_tspec[ac];
2471 if (likely(!tx_tspec->admitted_time))
2474 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2475 tx_tspec->consumed_tx_time = 0;
2476 tx_tspec->time_slice_start = now;
2478 if (tx_tspec->downgraded) {
2479 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2480 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2484 if (tx_tspec->downgraded)
2487 tx_tspec->consumed_tx_time += tx_time;
2489 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2490 tx_tspec->downgraded = true;
2491 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2492 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2496 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2497 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2499 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2501 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2502 !sdata->u.mgd.probe_send_count)
2506 sdata->u.mgd.probe_send_count = 0;
2508 sdata->u.mgd.nullfunc_failed = true;
2509 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2512 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2513 const u8 *src, const u8 *dst,
2514 const u8 *ssid, size_t ssid_len,
2515 struct ieee80211_channel *channel)
2517 struct sk_buff *skb;
2519 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2520 ssid, ssid_len, NULL, 0,
2521 IEEE80211_PROBE_FLAG_DIRECTED);
2523 ieee80211_tx_skb(sdata, skb);
2526 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2528 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2530 u8 *dst = ifmgd->associated->bssid;
2531 u8 unicast_limit = max(1, max_probe_tries - 3);
2532 struct sta_info *sta;
2535 * Try sending broadcast probe requests for the last three
2536 * probe requests after the first ones failed since some
2537 * buggy APs only support broadcast probe requests.
2539 if (ifmgd->probe_send_count >= unicast_limit)
2543 * When the hardware reports an accurate Tx ACK status, it's
2544 * better to send a nullfunc frame instead of a probe request,
2545 * as it will kick us off the AP quickly if we aren't associated
2546 * anymore. The timeout will be reset if the frame is ACKed by
2549 ifmgd->probe_send_count++;
2552 mutex_lock(&sdata->local->sta_mtx);
2553 sta = sta_info_get(sdata, dst);
2555 ieee80211_check_fast_rx(sta);
2556 mutex_unlock(&sdata->local->sta_mtx);
2559 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2560 ifmgd->nullfunc_failed = false;
2561 ieee80211_send_nullfunc(sdata->local, sdata, false);
2566 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2567 if (WARN_ON_ONCE(ssid == NULL))
2572 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2574 ifmgd->associated->channel);
2578 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2579 run_again(sdata, ifmgd->probe_timeout);
2582 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2585 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2586 bool already = false;
2588 if (!ieee80211_sdata_running(sdata))
2593 if (!ifmgd->associated)
2596 mutex_lock(&sdata->local->mtx);
2598 if (sdata->local->tmp_channel || sdata->local->scanning) {
2599 mutex_unlock(&sdata->local->mtx);
2604 mlme_dbg_ratelimited(sdata,
2605 "detected beacon loss from AP (missed %d beacons) - probing\n",
2608 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2612 * The driver/our work has already reported this event or the
2613 * connection monitoring has kicked in and we have already sent
2614 * a probe request. Or maybe the AP died and the driver keeps
2615 * reporting until we disassociate...
2617 * In either case we have to ignore the current call to this
2618 * function (except for setting the correct probe reason bit)
2619 * because otherwise we would reset the timer every time and
2620 * never check whether we received a probe response!
2622 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2625 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2627 mutex_unlock(&sdata->local->mtx);
2632 mutex_lock(&sdata->local->iflist_mtx);
2633 ieee80211_recalc_ps(sdata->local);
2634 mutex_unlock(&sdata->local->iflist_mtx);
2636 ifmgd->probe_send_count = 0;
2637 ieee80211_mgd_probe_ap_send(sdata);
2639 sdata_unlock(sdata);
2642 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2643 struct ieee80211_vif *vif)
2645 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2646 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2647 struct cfg80211_bss *cbss;
2648 struct sk_buff *skb;
2652 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2655 sdata_assert_lock(sdata);
2657 if (ifmgd->associated)
2658 cbss = ifmgd->associated;
2659 else if (ifmgd->auth_data)
2660 cbss = ifmgd->auth_data->bss;
2661 else if (ifmgd->assoc_data)
2662 cbss = ifmgd->assoc_data->bss;
2667 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2668 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2669 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
2674 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2675 (u32) -1, cbss->channel,
2677 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2682 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2684 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2685 const u8 *buf, size_t len, bool tx,
2686 u16 reason, bool reconnect)
2688 struct ieee80211_event event = {
2690 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2691 .u.mlme.reason = reason,
2695 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2697 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2699 drv_event_callback(sdata->local, sdata, &event);
2702 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2704 struct ieee80211_local *local = sdata->local;
2705 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2706 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2710 if (!ifmgd->associated) {
2711 sdata_unlock(sdata);
2715 tx = !sdata->csa_block_tx;
2717 if (!ifmgd->driver_disconnect) {
2719 * AP is probably out of range (or not reachable for another
2720 * reason) so remove the bss struct for that AP.
2722 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2725 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2726 ifmgd->driver_disconnect ?
2727 WLAN_REASON_DEAUTH_LEAVING :
2728 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2730 mutex_lock(&local->mtx);
2731 sdata->vif.csa_active = false;
2732 ifmgd->csa_waiting_bcn = false;
2733 if (sdata->csa_block_tx) {
2734 ieee80211_wake_vif_queues(local, sdata,
2735 IEEE80211_QUEUE_STOP_REASON_CSA);
2736 sdata->csa_block_tx = false;
2738 mutex_unlock(&local->mtx);
2740 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2741 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2743 ifmgd->reconnect = false;
2745 sdata_unlock(sdata);
2748 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2750 struct ieee80211_sub_if_data *sdata =
2751 container_of(work, struct ieee80211_sub_if_data,
2752 u.mgd.beacon_connection_loss_work);
2753 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2755 if (ifmgd->associated)
2756 ifmgd->beacon_loss_count++;
2758 if (ifmgd->connection_loss) {
2759 sdata_info(sdata, "Connection to AP %pM lost\n",
2761 __ieee80211_disconnect(sdata);
2762 ifmgd->connection_loss = false;
2763 } else if (ifmgd->driver_disconnect) {
2765 "Driver requested disconnection from AP %pM\n",
2767 __ieee80211_disconnect(sdata);
2768 ifmgd->driver_disconnect = false;
2770 ieee80211_mgd_probe_ap(sdata, true);
2774 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2776 struct ieee80211_sub_if_data *sdata =
2777 container_of(work, struct ieee80211_sub_if_data,
2778 u.mgd.csa_connection_drop_work);
2780 __ieee80211_disconnect(sdata);
2783 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2785 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2786 struct ieee80211_hw *hw = &sdata->local->hw;
2788 trace_api_beacon_loss(sdata);
2790 sdata->u.mgd.connection_loss = false;
2791 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2793 EXPORT_SYMBOL(ieee80211_beacon_loss);
2795 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2797 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2798 struct ieee80211_hw *hw = &sdata->local->hw;
2800 trace_api_connection_loss(sdata);
2802 sdata->u.mgd.connection_loss = true;
2803 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2805 EXPORT_SYMBOL(ieee80211_connection_loss);
2807 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2809 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2810 struct ieee80211_hw *hw = &sdata->local->hw;
2812 trace_api_disconnect(sdata, reconnect);
2814 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2817 sdata->u.mgd.driver_disconnect = true;
2818 sdata->u.mgd.reconnect = reconnect;
2819 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2821 EXPORT_SYMBOL(ieee80211_disconnect);
2823 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2826 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2828 sdata_assert_lock(sdata);
2832 * we are not authenticated yet, the only timer that could be
2833 * running is the timeout for the authentication response which
2834 * which is not relevant anymore.
2836 del_timer_sync(&sdata->u.mgd.timer);
2837 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2839 eth_zero_addr(sdata->u.mgd.bssid);
2840 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2841 sdata->u.mgd.flags = 0;
2842 mutex_lock(&sdata->local->mtx);
2843 ieee80211_vif_release_channel(sdata);
2844 mutex_unlock(&sdata->local->mtx);
2847 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2849 sdata->u.mgd.auth_data = NULL;
2852 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2853 bool assoc, bool abandon)
2855 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2857 sdata_assert_lock(sdata);
2861 * we are not associated yet, the only timer that could be
2862 * running is the timeout for the association response which
2863 * which is not relevant anymore.
2865 del_timer_sync(&sdata->u.mgd.timer);
2866 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2868 eth_zero_addr(sdata->u.mgd.bssid);
2869 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2870 sdata->u.mgd.flags = 0;
2871 sdata->vif.mu_mimo_owner = false;
2873 mutex_lock(&sdata->local->mtx);
2874 ieee80211_vif_release_channel(sdata);
2875 mutex_unlock(&sdata->local->mtx);
2878 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2882 sdata->u.mgd.assoc_data = NULL;
2885 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2886 struct ieee80211_mgmt *mgmt, size_t len)
2888 struct ieee80211_local *local = sdata->local;
2889 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2891 struct ieee802_11_elems elems;
2893 struct ieee80211_prep_tx_info info = {
2894 .subtype = IEEE80211_STYPE_AUTH,
2897 pos = mgmt->u.auth.variable;
2898 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2899 mgmt->bssid, auth_data->bss->bssid);
2900 if (!elems.challenge)
2902 auth_data->expected_transaction = 4;
2903 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2904 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2905 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2906 IEEE80211_TX_INTFL_MLME_CONN_TX;
2907 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2908 elems.challenge - 2, elems.challenge_len + 2,
2909 auth_data->bss->bssid, auth_data->bss->bssid,
2910 auth_data->key, auth_data->key_len,
2911 auth_data->key_idx, tx_flags);
2914 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2917 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2918 struct sta_info *sta;
2921 sdata_info(sdata, "authenticated\n");
2922 ifmgd->auth_data->done = true;
2923 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2924 ifmgd->auth_data->timeout_started = true;
2925 run_again(sdata, ifmgd->auth_data->timeout);
2927 /* move station state to auth */
2928 mutex_lock(&sdata->local->sta_mtx);
2929 sta = sta_info_get(sdata, bssid);
2931 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2935 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2936 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2942 mutex_unlock(&sdata->local->sta_mtx);
2946 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2947 struct ieee80211_mgmt *mgmt, size_t len)
2949 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2951 u16 auth_alg, auth_transaction, status_code;
2952 struct ieee80211_event event = {
2954 .u.mlme.data = AUTH_EVENT,
2956 struct ieee80211_prep_tx_info info = {
2957 .subtype = IEEE80211_STYPE_AUTH,
2960 sdata_assert_lock(sdata);
2965 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2968 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2970 if (!ether_addr_equal(bssid, mgmt->bssid))
2973 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2974 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2975 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2977 if (auth_alg != ifmgd->auth_data->algorithm ||
2978 (auth_alg != WLAN_AUTH_SAE &&
2979 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2980 (auth_alg == WLAN_AUTH_SAE &&
2981 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2982 auth_transaction > 2))) {
2983 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2984 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2986 ifmgd->auth_data->expected_transaction);
2990 if (status_code != WLAN_STATUS_SUCCESS) {
2991 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2993 if (auth_alg == WLAN_AUTH_SAE &&
2994 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
2995 (auth_transaction == 1 &&
2996 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
2997 status_code == WLAN_STATUS_SAE_PK))))
3000 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3001 mgmt->sa, status_code);
3002 ieee80211_destroy_auth_data(sdata, false);
3003 event.u.mlme.status = MLME_DENIED;
3004 event.u.mlme.reason = status_code;
3005 drv_event_callback(sdata->local, sdata, &event);
3009 switch (ifmgd->auth_data->algorithm) {
3010 case WLAN_AUTH_OPEN:
3011 case WLAN_AUTH_LEAP:
3014 case WLAN_AUTH_FILS_SK:
3015 case WLAN_AUTH_FILS_SK_PFS:
3016 case WLAN_AUTH_FILS_PK:
3018 case WLAN_AUTH_SHARED_KEY:
3019 if (ifmgd->auth_data->expected_transaction != 4) {
3020 ieee80211_auth_challenge(sdata, mgmt, len);
3021 /* need another frame */
3026 WARN_ONCE(1, "invalid auth alg %d",
3027 ifmgd->auth_data->algorithm);
3031 event.u.mlme.status = MLME_SUCCESS;
3033 drv_event_callback(sdata->local, sdata, &event);
3034 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3035 (auth_transaction == 2 &&
3036 ifmgd->auth_data->expected_transaction == 2)) {
3037 if (!ieee80211_mark_sta_auth(sdata, bssid))
3038 return; /* ignore frame -- wait for timeout */
3039 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3040 auth_transaction == 2) {
3041 sdata_info(sdata, "SAE peer confirmed\n");
3042 ifmgd->auth_data->peer_confirmed = true;
3045 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3047 drv_mgd_complete_tx(sdata->local, sdata, &info);
3050 #define case_WLAN(type) \
3051 case WLAN_REASON_##type: return #type
3053 const char *ieee80211_get_reason_code_string(u16 reason_code)
3055 switch (reason_code) {
3056 case_WLAN(UNSPECIFIED);
3057 case_WLAN(PREV_AUTH_NOT_VALID);
3058 case_WLAN(DEAUTH_LEAVING);
3059 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3060 case_WLAN(DISASSOC_AP_BUSY);
3061 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3062 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3063 case_WLAN(DISASSOC_STA_HAS_LEFT);
3064 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3065 case_WLAN(DISASSOC_BAD_POWER);
3066 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3067 case_WLAN(INVALID_IE);
3068 case_WLAN(MIC_FAILURE);
3069 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3070 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3071 case_WLAN(IE_DIFFERENT);
3072 case_WLAN(INVALID_GROUP_CIPHER);
3073 case_WLAN(INVALID_PAIRWISE_CIPHER);
3074 case_WLAN(INVALID_AKMP);
3075 case_WLAN(UNSUPP_RSN_VERSION);
3076 case_WLAN(INVALID_RSN_IE_CAP);
3077 case_WLAN(IEEE8021X_FAILED);
3078 case_WLAN(CIPHER_SUITE_REJECTED);
3079 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3080 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3081 case_WLAN(DISASSOC_LOW_ACK);
3082 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3083 case_WLAN(QSTA_LEAVE_QBSS);
3084 case_WLAN(QSTA_NOT_USE);
3085 case_WLAN(QSTA_REQUIRE_SETUP);
3086 case_WLAN(QSTA_TIMEOUT);
3087 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3088 case_WLAN(MESH_PEER_CANCELED);
3089 case_WLAN(MESH_MAX_PEERS);
3090 case_WLAN(MESH_CONFIG);
3091 case_WLAN(MESH_CLOSE);
3092 case_WLAN(MESH_MAX_RETRIES);
3093 case_WLAN(MESH_CONFIRM_TIMEOUT);
3094 case_WLAN(MESH_INVALID_GTK);
3095 case_WLAN(MESH_INCONSISTENT_PARAM);
3096 case_WLAN(MESH_INVALID_SECURITY);
3097 case_WLAN(MESH_PATH_ERROR);
3098 case_WLAN(MESH_PATH_NOFORWARD);
3099 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3100 case_WLAN(MAC_EXISTS_IN_MBSS);
3101 case_WLAN(MESH_CHAN_REGULATORY);
3102 case_WLAN(MESH_CHAN);
3103 default: return "<unknown>";
3107 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3108 struct ieee80211_mgmt *mgmt, size_t len)
3110 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3111 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3113 sdata_assert_lock(sdata);
3118 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3119 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3123 if (ifmgd->associated &&
3124 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3125 const u8 *bssid = ifmgd->associated->bssid;
3127 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3129 ieee80211_get_reason_code_string(reason_code));
3131 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3133 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3134 reason_code, false);
3138 if (ifmgd->assoc_data &&
3139 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3140 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3143 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3145 ieee80211_get_reason_code_string(reason_code));
3147 ieee80211_destroy_assoc_data(sdata, false, true);
3149 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3155 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3156 struct ieee80211_mgmt *mgmt, size_t len)
3158 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3161 sdata_assert_lock(sdata);
3166 if (!ifmgd->associated ||
3167 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3170 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3172 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3173 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3177 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3178 mgmt->sa, reason_code,
3179 ieee80211_get_reason_code_string(reason_code));
3181 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3183 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3187 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3188 u8 *supp_rates, unsigned int supp_rates_len,
3189 u32 *rates, u32 *basic_rates,
3190 bool *have_higher_than_11mbit,
3191 int *min_rate, int *min_rate_index,
3196 for (i = 0; i < supp_rates_len; i++) {
3197 int rate = supp_rates[i] & 0x7f;
3198 bool is_basic = !!(supp_rates[i] & 0x80);
3200 if ((rate * 5 * (1 << shift)) > 110)
3201 *have_higher_than_11mbit = true;
3204 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3205 * since they're not rates.
3207 * Note: Even though the membership selector and the basic
3208 * rate flag share the same bit, they are not exactly
3211 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3212 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3213 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3214 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3217 for (j = 0; j < sband->n_bitrates; j++) {
3218 struct ieee80211_rate *br;
3221 br = &sband->bitrates[j];
3223 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3224 if (brate == rate) {
3227 *basic_rates |= BIT(j);
3228 if ((rate * 5) < *min_rate) {
3229 *min_rate = rate * 5;
3230 *min_rate_index = j;
3238 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3239 const struct ieee802_11_elems *elems)
3241 if (elems->ext_capab_len < 10)
3244 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3247 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3248 IEEE80211_HE_MAC_CAP0_TWT_RES;
3251 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3252 struct sta_info *sta,
3253 struct ieee802_11_elems *elems)
3255 bool twt = ieee80211_twt_req_supported(sta, elems);
3257 if (sdata->vif.bss_conf.twt_requester != twt) {
3258 sdata->vif.bss_conf.twt_requester = twt;
3259 return BSS_CHANGED_TWT;
3264 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3265 struct ieee80211_bss_conf *bss_conf,
3266 struct ieee80211_supported_band *sband,
3267 struct sta_info *sta)
3269 const struct ieee80211_sta_he_cap *own_he_cap =
3270 ieee80211_get_he_iftype_cap(sband,
3271 ieee80211_vif_type_p2p(&sdata->vif));
3273 return bss_conf->he_support &&
3274 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3275 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3277 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3278 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3281 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3282 struct cfg80211_bss *cbss,
3283 struct ieee80211_mgmt *mgmt, size_t len,
3284 struct ieee802_11_elems *elems)
3286 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3287 struct ieee80211_local *local = sdata->local;
3288 struct ieee80211_supported_band *sband;
3289 struct sta_info *sta;
3290 u16 capab_info, aid;
3291 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3292 const struct cfg80211_bss_ies *bss_ies = NULL;
3293 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3294 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3295 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3301 /* AssocResp and ReassocResp have identical structure */
3303 pos = mgmt->u.assoc_resp.variable;
3304 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3306 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3309 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3310 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, elems,
3311 mgmt->bssid, assoc_data->bss->bssid);
3313 if (elems->aid_resp)
3314 aid = le16_to_cpu(elems->aid_resp->aid);
3317 * The 5 MSB of the AID field are reserved
3318 * (802.11-2016 9.4.1.8 AID field)
3322 ifmgd->broken_ap = false;
3324 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3325 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3328 ifmgd->broken_ap = true;
3331 if (!is_s1g && !elems->supp_rates) {
3332 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3336 sdata->vif.bss_conf.aid = aid;
3337 ifmgd->tdls_chan_switch_prohibited =
3338 elems->ext_capab && elems->ext_capab_len >= 5 &&
3339 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3342 * Some APs are erroneously not including some information in their
3343 * (re)association response frames. Try to recover by using the data
3344 * from the beacon or probe response. This seems to afflict mobile
3345 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3346 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3349 ((assoc_data->wmm && !elems->wmm_param) ||
3350 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3351 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3352 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3353 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3354 const struct cfg80211_bss_ies *ies;
3355 struct ieee802_11_elems bss_elems;
3358 ies = rcu_dereference(cbss->ies);
3360 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3366 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3369 assoc_data->bss->bssid);
3370 if (assoc_data->wmm &&
3371 !elems->wmm_param && bss_elems.wmm_param) {
3372 elems->wmm_param = bss_elems.wmm_param;
3374 "AP bug: WMM param missing from AssocResp\n");
3378 * Also check if we requested HT/VHT, otherwise the AP doesn't
3379 * have to include the IEs in the (re)association response.
3381 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
3382 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3383 elems->ht_cap_elem = bss_elems.ht_cap_elem;
3385 "AP bug: HT capability missing from AssocResp\n");
3387 if (!elems->ht_operation && bss_elems.ht_operation &&
3388 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3389 elems->ht_operation = bss_elems.ht_operation;
3391 "AP bug: HT operation missing from AssocResp\n");
3393 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
3394 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3395 elems->vht_cap_elem = bss_elems.vht_cap_elem;
3397 "AP bug: VHT capa missing from AssocResp\n");
3399 if (!elems->vht_operation && bss_elems.vht_operation &&
3400 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3401 elems->vht_operation = bss_elems.vht_operation;
3403 "AP bug: VHT operation missing from AssocResp\n");
3408 * We previously checked these in the beacon/probe response, so
3409 * they should be present here. This is just a safety net.
3411 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3412 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3414 "HT AP is missing WMM params or HT capability/operation\n");
3419 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3420 (!elems->vht_cap_elem || !elems->vht_operation)) {
3422 "VHT AP is missing VHT capability/operation\n");
3427 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3428 !elems->he_6ghz_capa) {
3430 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3435 mutex_lock(&sdata->local->sta_mtx);
3437 * station info was already allocated and inserted before
3438 * the association and should be available to us
3440 sta = sta_info_get(sdata, cbss->bssid);
3441 if (WARN_ON(!sta)) {
3442 mutex_unlock(&sdata->local->sta_mtx);
3447 sband = ieee80211_get_sband(sdata);
3449 mutex_unlock(&sdata->local->sta_mtx);
3454 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3455 (!elems->he_cap || !elems->he_operation)) {
3456 mutex_unlock(&sdata->local->sta_mtx);
3458 "HE AP is missing HE capability/operation\n");
3463 /* Set up internal HT/VHT capabilities */
3464 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3465 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3466 elems->ht_cap_elem, sta);
3468 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3469 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3470 elems->vht_cap_elem, sta);
3472 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3474 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3477 elems->he_6ghz_capa,
3480 bss_conf->he_support = sta->sta.he_cap.has_he;
3481 if (elems->rsnx && elems->rsnx_len &&
3482 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3483 wiphy_ext_feature_isset(local->hw.wiphy,
3484 NL80211_EXT_FEATURE_PROTECTED_TWT))
3485 bss_conf->twt_protected = true;
3487 bss_conf->twt_protected = false;
3489 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3491 bss_conf->he_support = false;
3492 bss_conf->twt_requester = false;
3493 bss_conf->twt_protected = false;
3496 bss_conf->twt_broadcast =
3497 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3499 if (bss_conf->he_support) {
3500 bss_conf->he_bss_color.color =
3501 le32_get_bits(elems->he_operation->he_oper_params,
3502 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3503 bss_conf->he_bss_color.partial =
3504 le32_get_bits(elems->he_operation->he_oper_params,
3505 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3506 bss_conf->he_bss_color.enabled =
3507 !le32_get_bits(elems->he_operation->he_oper_params,
3508 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3510 if (bss_conf->he_bss_color.enabled)
3511 changed |= BSS_CHANGED_HE_BSS_COLOR;
3513 bss_conf->htc_trig_based_pkt_ext =
3514 le32_get_bits(elems->he_operation->he_oper_params,
3515 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3516 bss_conf->frame_time_rts_th =
3517 le32_get_bits(elems->he_operation->he_oper_params,
3518 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3520 bss_conf->uora_exists = !!elems->uora_element;
3521 if (elems->uora_element)
3522 bss_conf->uora_ocw_range = elems->uora_element[0];
3524 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3525 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3526 /* TODO: OPEN: what happens if BSS color disable is set? */
3529 if (cbss->transmitted_bss) {
3530 bss_conf->nontransmitted = true;
3531 ether_addr_copy(bss_conf->transmitter_bssid,
3532 cbss->transmitted_bss->bssid);
3533 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3534 bss_conf->bssid_index = cbss->bssid_index;
3538 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3539 * in their association response, so ignore that data for our own
3540 * configuration. If it changed since the last beacon, we'll get the
3541 * next beacon and update then.
3545 * If an operating mode notification IE is present, override the
3546 * NSS calculation (that would be done in rate_control_rate_init())
3547 * and use the # of streams from that element.
3549 if (elems->opmode_notif &&
3550 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3553 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3554 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3556 sta->sta.rx_nss = nss;
3559 rate_control_rate_init(sta);
3561 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3562 set_sta_flag(sta, WLAN_STA_MFP);
3563 sta->sta.mfp = true;
3565 sta->sta.mfp = false;
3568 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3569 local->hw.queues >= IEEE80211_NUM_ACS;
3571 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3572 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3573 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3576 "failed to move station %pM to desired state\n",
3578 WARN_ON(__sta_info_destroy(sta));
3579 mutex_unlock(&sdata->local->sta_mtx);
3584 if (sdata->wdev.use_4addr)
3585 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3587 mutex_unlock(&sdata->local->sta_mtx);
3590 * Always handle WMM once after association regardless
3591 * of the first value the AP uses. Setting -1 here has
3592 * that effect because the AP values is an unsigned
3595 ifmgd->wmm_last_param_set = -1;
3596 ifmgd->mu_edca_last_param_set = -1;
3598 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3599 ieee80211_set_wmm_default(sdata, false, false);
3600 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3601 elems->wmm_param_len,
3602 elems->mu_edca_param_set)) {
3603 /* still enable QoS since we might have HT/VHT */
3604 ieee80211_set_wmm_default(sdata, false, true);
3605 /* set the disable-WMM flag in this case to disable
3606 * tracking WMM parameter changes in the beacon if
3607 * the parameters weren't actually valid. Doing so
3608 * avoids changing parameters very strangely when
3609 * the AP is going back and forth between valid and
3610 * invalid parameters.
3612 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3614 changed |= BSS_CHANGED_QOS;
3616 if (elems->max_idle_period_ie) {
3617 bss_conf->max_idle_period =
3618 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3619 bss_conf->protected_keep_alive =
3620 !!(elems->max_idle_period_ie->idle_options &
3621 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3622 changed |= BSS_CHANGED_KEEP_ALIVE;
3624 bss_conf->max_idle_period = 0;
3625 bss_conf->protected_keep_alive = false;
3628 /* set assoc capability (AID was already set earlier),
3629 * ieee80211_set_associated() will tell the driver */
3630 bss_conf->assoc_capability = capab_info;
3631 ieee80211_set_associated(sdata, cbss, changed);
3634 * If we're using 4-addr mode, let the AP know that we're
3635 * doing so, so that it can create the STA VLAN on its side
3637 if (ifmgd->use_4addr)
3638 ieee80211_send_4addr_nullfunc(local, sdata);
3641 * Start timer to probe the connection to the AP now.
3642 * Also start the timer that will detect beacon loss.
3644 ieee80211_sta_reset_beacon_monitor(sdata);
3645 ieee80211_sta_reset_conn_monitor(sdata);
3653 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3654 struct ieee80211_mgmt *mgmt,
3657 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3658 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3659 u16 capab_info, status_code, aid;
3660 struct ieee802_11_elems elems;
3661 int ac, uapsd_queues = -1;
3664 struct cfg80211_bss *cbss;
3665 struct ieee80211_event event = {
3667 .u.mlme.data = ASSOC_EVENT,
3669 struct ieee80211_prep_tx_info info = {};
3671 sdata_assert_lock(sdata);
3676 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3679 cbss = assoc_data->bss;
3682 * AssocResp and ReassocResp have identical structure, so process both
3683 * of them in this function.
3689 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3690 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3691 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3692 pos = mgmt->u.assoc_resp.variable;
3693 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3694 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3695 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3700 * Note: this may not be perfect, AP might misbehave - if
3701 * anyone needs to rely on perfect complete notification
3702 * with the exact right subtype, then we need to track what
3703 * we actually transmitted.
3705 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3706 IEEE80211_STYPE_ASSOC_REQ;
3709 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3710 reassoc ? "Rea" : "A", mgmt->sa,
3711 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3713 if (assoc_data->fils_kek_len &&
3714 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3717 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3718 mgmt->bssid, assoc_data->bss->bssid);
3720 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3721 elems.timeout_int &&
3722 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3724 tu = le32_to_cpu(elems.timeout_int->value);
3725 ms = tu * 1024 / 1000;
3727 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3729 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3730 assoc_data->timeout_started = true;
3731 if (ms > IEEE80211_ASSOC_TIMEOUT)
3732 run_again(sdata, assoc_data->timeout);
3736 if (status_code != WLAN_STATUS_SUCCESS) {
3737 sdata_info(sdata, "%pM denied association (code=%d)\n",
3738 mgmt->sa, status_code);
3739 ieee80211_destroy_assoc_data(sdata, false, false);
3740 event.u.mlme.status = MLME_DENIED;
3741 event.u.mlme.reason = status_code;
3742 drv_event_callback(sdata->local, sdata, &event);
3744 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, &elems)) {
3745 /* oops -- internal error -- send timeout for now */
3746 ieee80211_destroy_assoc_data(sdata, false, false);
3747 cfg80211_assoc_timeout(sdata->dev, cbss);
3750 event.u.mlme.status = MLME_SUCCESS;
3751 drv_event_callback(sdata->local, sdata, &event);
3752 sdata_info(sdata, "associated\n");
3755 * destroy assoc_data afterwards, as otherwise an idle
3756 * recalc after assoc_data is NULL but before associated
3757 * is set can cause the interface to go idle
3759 ieee80211_destroy_assoc_data(sdata, true, false);
3761 /* get uapsd queues configuration */
3763 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3764 if (sdata->tx_conf[ac].uapsd)
3765 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3770 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3771 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3773 drv_mgd_complete_tx(sdata->local, sdata, &info);
3776 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3777 struct ieee80211_mgmt *mgmt, size_t len,
3778 struct ieee80211_rx_status *rx_status)
3780 struct ieee80211_local *local = sdata->local;
3781 struct ieee80211_bss *bss;
3782 struct ieee80211_channel *channel;
3784 sdata_assert_lock(sdata);
3786 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3787 ieee80211_rx_status_to_khz(rx_status));
3791 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3793 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3794 ieee80211_rx_bss_put(local, bss);
3799 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3800 struct sk_buff *skb)
3802 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3803 struct ieee80211_if_managed *ifmgd;
3804 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3805 struct ieee80211_channel *channel;
3806 size_t baselen, len = skb->len;
3808 ifmgd = &sdata->u.mgd;
3810 sdata_assert_lock(sdata);
3813 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3814 * "If a 6 GHz AP receives a Probe Request frame and responds with
3815 * a Probe Response frame [..], the Address 1 field of the Probe
3816 * Response frame shall be set to the broadcast address [..]"
3817 * So, on 6GHz band we should also accept broadcast responses.
3819 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3824 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3825 (channel->band != NL80211_BAND_6GHZ ||
3826 !is_broadcast_ether_addr(mgmt->da)))
3827 return; /* ignore ProbeResp to foreign address */
3829 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3833 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3835 if (ifmgd->associated &&
3836 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3837 ieee80211_reset_ap_probe(sdata);
3841 * This is the canonical list of information elements we care about,
3842 * the filter code also gives us all changes to the Microsoft OUI
3843 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3844 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3845 * changes to requested client power.
3847 * We implement beacon filtering in software since that means we can
3848 * avoid processing the frame here and in cfg80211, and userspace
3849 * will not be able to tell whether the hardware supports it or not.
3851 * XXX: This list needs to be dynamic -- userspace needs to be able to
3852 * add items it requires. It also needs to be able to tell us to
3853 * look out for other vendor IEs.
3855 static const u64 care_about_ies =
3856 (1ULL << WLAN_EID_COUNTRY) |
3857 (1ULL << WLAN_EID_ERP_INFO) |
3858 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3859 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3860 (1ULL << WLAN_EID_HT_CAPABILITY) |
3861 (1ULL << WLAN_EID_HT_OPERATION) |
3862 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3864 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3865 struct ieee80211_if_managed *ifmgd,
3866 struct ieee80211_bss_conf *bss_conf,
3867 struct ieee80211_local *local,
3868 struct ieee80211_rx_status *rx_status)
3870 /* Track average RSSI from the Beacon frames of the current AP */
3872 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3873 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3874 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3875 ifmgd->last_cqm_event_signal = 0;
3876 ifmgd->count_beacon_signal = 1;
3877 ifmgd->last_ave_beacon_signal = 0;
3879 ifmgd->count_beacon_signal++;
3882 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3884 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3885 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3886 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3887 int last_sig = ifmgd->last_ave_beacon_signal;
3888 struct ieee80211_event event = {
3893 * if signal crosses either of the boundaries, invoke callback
3894 * with appropriate parameters
3896 if (sig > ifmgd->rssi_max_thold &&
3897 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3898 ifmgd->last_ave_beacon_signal = sig;
3899 event.u.rssi.data = RSSI_EVENT_HIGH;
3900 drv_event_callback(local, sdata, &event);
3901 } else if (sig < ifmgd->rssi_min_thold &&
3902 (last_sig >= ifmgd->rssi_max_thold ||
3904 ifmgd->last_ave_beacon_signal = sig;
3905 event.u.rssi.data = RSSI_EVENT_LOW;
3906 drv_event_callback(local, sdata, &event);
3910 if (bss_conf->cqm_rssi_thold &&
3911 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3912 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3913 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3914 int last_event = ifmgd->last_cqm_event_signal;
3915 int thold = bss_conf->cqm_rssi_thold;
3916 int hyst = bss_conf->cqm_rssi_hyst;
3919 (last_event == 0 || sig < last_event - hyst)) {
3920 ifmgd->last_cqm_event_signal = sig;
3921 ieee80211_cqm_rssi_notify(
3923 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3925 } else if (sig > thold &&
3926 (last_event == 0 || sig > last_event + hyst)) {
3927 ifmgd->last_cqm_event_signal = sig;
3928 ieee80211_cqm_rssi_notify(
3930 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3935 if (bss_conf->cqm_rssi_low &&
3936 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3937 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3938 int last_event = ifmgd->last_cqm_event_signal;
3939 int low = bss_conf->cqm_rssi_low;
3940 int high = bss_conf->cqm_rssi_high;
3943 (last_event == 0 || last_event >= low)) {
3944 ifmgd->last_cqm_event_signal = sig;
3945 ieee80211_cqm_rssi_notify(
3947 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3949 } else if (sig > high &&
3950 (last_event == 0 || last_event <= high)) {
3951 ifmgd->last_cqm_event_signal = sig;
3952 ieee80211_cqm_rssi_notify(
3954 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3960 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3961 struct cfg80211_bss *bss)
3963 if (ether_addr_equal(tx_bssid, bss->bssid))
3965 if (!bss->transmitted_bss)
3967 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3970 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3971 struct ieee80211_hdr *hdr, size_t len,
3972 struct ieee80211_rx_status *rx_status)
3974 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3975 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3976 struct ieee80211_mgmt *mgmt = (void *) hdr;
3978 struct ieee802_11_elems elems;
3979 struct ieee80211_local *local = sdata->local;
3980 struct ieee80211_chanctx_conf *chanctx_conf;
3981 struct ieee80211_channel *chan;
3982 struct sta_info *sta;
3987 u8 *bssid, *variable = mgmt->u.beacon.variable;
3988 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3990 sdata_assert_lock(sdata);
3992 /* Process beacon from the current BSS */
3993 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
3994 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
3995 struct ieee80211_ext *ext = (void *) mgmt;
3997 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
3998 variable = ext->u.s1g_short_beacon.variable;
4000 variable = ext->u.s1g_beacon.variable;
4003 baselen = (u8 *) variable - (u8 *) mgmt;
4008 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4009 if (!chanctx_conf) {
4014 if (ieee80211_rx_status_to_khz(rx_status) !=
4015 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4019 chan = chanctx_conf->def.chan;
4022 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4023 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4024 ieee802_11_parse_elems(variable,
4025 len - baselen, false, &elems,
4027 ifmgd->assoc_data->bss->bssid);
4029 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4031 if (elems.dtim_period)
4032 ifmgd->dtim_period = elems.dtim_period;
4033 ifmgd->have_beacon = true;
4034 ifmgd->assoc_data->need_beacon = false;
4035 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4036 sdata->vif.bss_conf.sync_tsf =
4037 le64_to_cpu(mgmt->u.beacon.timestamp);
4038 sdata->vif.bss_conf.sync_device_ts =
4039 rx_status->device_timestamp;
4040 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4043 if (elems.mbssid_config_ie)
4044 bss_conf->profile_periodicity =
4045 elems.mbssid_config_ie->profile_periodicity;
4047 bss_conf->profile_periodicity = 0;
4049 if (elems.ext_capab_len >= 11 &&
4050 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4051 bss_conf->ema_ap = true;
4053 bss_conf->ema_ap = false;
4055 /* continue assoc process */
4056 ifmgd->assoc_data->timeout = jiffies;
4057 ifmgd->assoc_data->timeout_started = true;
4058 run_again(sdata, ifmgd->assoc_data->timeout);
4062 if (!ifmgd->associated ||
4063 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4065 bssid = ifmgd->associated->bssid;
4067 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4068 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4071 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4072 mlme_dbg_ratelimited(sdata,
4073 "cancelling AP probe due to a received beacon\n");
4074 ieee80211_reset_ap_probe(sdata);
4078 * Push the beacon loss detection into the future since
4079 * we are processing a beacon from the AP just now.
4081 ieee80211_sta_reset_beacon_monitor(sdata);
4083 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4084 * element (which carries the beacon interval). Don't forget to add a
4085 * bit to care_about_ies[] above if mac80211 is interested in a
4086 * changing S1G element.
4088 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4089 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4090 ncrc = ieee802_11_parse_elems_crc(variable,
4091 len - baselen, false, &elems,
4092 care_about_ies, ncrc,
4093 mgmt->bssid, bssid);
4095 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4096 ieee80211_check_tim(elems.tim, elems.tim_len, bss_conf->aid)) {
4097 if (local->hw.conf.dynamic_ps_timeout > 0) {
4098 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4099 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4100 ieee80211_hw_config(local,
4101 IEEE80211_CONF_CHANGE_PS);
4103 ieee80211_send_nullfunc(local, sdata, false);
4104 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4105 local->pspolling = true;
4108 * Here is assumed that the driver will be
4109 * able to send ps-poll frame and receive a
4110 * response even though power save mode is
4111 * enabled, but some drivers might require
4112 * to disable power save here. This needs
4113 * to be investigated.
4115 ieee80211_send_pspoll(local, sdata);
4119 if (sdata->vif.p2p ||
4120 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4121 struct ieee80211_p2p_noa_attr noa = {};
4124 ret = cfg80211_get_p2p_attr(variable,
4126 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4127 (u8 *) &noa, sizeof(noa));
4129 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4130 /* valid noa_attr and index changed */
4131 sdata->u.mgd.p2p_noa_index = noa.index;
4132 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4133 changed |= BSS_CHANGED_P2P_PS;
4135 * make sure we update all information, the CRC
4136 * mechanism doesn't look at P2P attributes.
4138 ifmgd->beacon_crc_valid = false;
4140 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4141 /* noa_attr not found and we had valid noa_attr before */
4142 sdata->u.mgd.p2p_noa_index = -1;
4143 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4144 changed |= BSS_CHANGED_P2P_PS;
4145 ifmgd->beacon_crc_valid = false;
4149 if (ifmgd->csa_waiting_bcn)
4150 ieee80211_chswitch_post_beacon(sdata);
4153 * Update beacon timing and dtim count on every beacon appearance. This
4154 * will allow the driver to use the most updated values. Do it before
4155 * comparing this one with last received beacon.
4156 * IMPORTANT: These parameters would possibly be out of sync by the time
4157 * the driver will use them. The synchronized view is currently
4158 * guaranteed only in certain callbacks.
4160 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4161 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4162 sdata->vif.bss_conf.sync_tsf =
4163 le64_to_cpu(mgmt->u.beacon.timestamp);
4164 sdata->vif.bss_conf.sync_device_ts =
4165 rx_status->device_timestamp;
4166 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4169 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4170 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4172 ifmgd->beacon_crc = ncrc;
4173 ifmgd->beacon_crc_valid = true;
4175 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4177 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4178 rx_status->device_timestamp,
4181 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4182 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
4183 elems.wmm_param_len,
4184 elems.mu_edca_param_set))
4185 changed |= BSS_CHANGED_QOS;
4188 * If we haven't had a beacon before, tell the driver about the
4189 * DTIM period (and beacon timing if desired) now.
4191 if (!ifmgd->have_beacon) {
4192 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4193 bss_conf->dtim_period = elems.dtim_period ?: 1;
4195 changed |= BSS_CHANGED_BEACON_INFO;
4196 ifmgd->have_beacon = true;
4198 mutex_lock(&local->iflist_mtx);
4199 ieee80211_recalc_ps(local);
4200 mutex_unlock(&local->iflist_mtx);
4202 ieee80211_recalc_ps_vif(sdata);
4205 if (elems.erp_info) {
4207 erp_value = elems.erp_info[0];
4212 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4213 changed |= ieee80211_handle_bss_capability(sdata,
4214 le16_to_cpu(mgmt->u.beacon.capab_info),
4215 erp_valid, erp_value);
4217 mutex_lock(&local->sta_mtx);
4218 sta = sta_info_get(sdata, bssid);
4220 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4222 if (ieee80211_config_bw(sdata, sta, elems.ht_cap_elem,
4223 elems.vht_cap_elem, elems.ht_operation,
4224 elems.vht_operation, elems.he_operation,
4225 elems.s1g_oper, bssid, &changed)) {
4226 mutex_unlock(&local->sta_mtx);
4228 "failed to follow AP %pM bandwidth change, disconnect\n",
4230 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4231 WLAN_REASON_DEAUTH_LEAVING,
4233 ieee80211_report_disconnect(sdata, deauth_buf,
4234 sizeof(deauth_buf), true,
4235 WLAN_REASON_DEAUTH_LEAVING,
4240 if (sta && elems.opmode_notif)
4241 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
4243 mutex_unlock(&local->sta_mtx);
4245 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4247 elems.country_elem_len,
4248 elems.pwr_constr_elem,
4249 elems.cisco_dtpc_elem);
4251 ieee80211_bss_info_change_notify(sdata, changed);
4254 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4255 struct sk_buff *skb)
4257 struct ieee80211_rx_status *rx_status;
4258 struct ieee80211_hdr *hdr;
4261 rx_status = (struct ieee80211_rx_status *) skb->cb;
4262 hdr = (struct ieee80211_hdr *) skb->data;
4263 fc = le16_to_cpu(hdr->frame_control);
4266 switch (fc & IEEE80211_FCTL_STYPE) {
4267 case IEEE80211_STYPE_S1G_BEACON:
4268 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4271 sdata_unlock(sdata);
4274 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4275 struct sk_buff *skb)
4277 struct ieee80211_rx_status *rx_status;
4278 struct ieee80211_mgmt *mgmt;
4280 struct ieee802_11_elems elems;
4283 rx_status = (struct ieee80211_rx_status *) skb->cb;
4284 mgmt = (struct ieee80211_mgmt *) skb->data;
4285 fc = le16_to_cpu(mgmt->frame_control);
4289 switch (fc & IEEE80211_FCTL_STYPE) {
4290 case IEEE80211_STYPE_BEACON:
4291 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4292 skb->len, rx_status);
4294 case IEEE80211_STYPE_PROBE_RESP:
4295 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4297 case IEEE80211_STYPE_AUTH:
4298 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4300 case IEEE80211_STYPE_DEAUTH:
4301 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4303 case IEEE80211_STYPE_DISASSOC:
4304 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4306 case IEEE80211_STYPE_ASSOC_RESP:
4307 case IEEE80211_STYPE_REASSOC_RESP:
4308 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4310 case IEEE80211_STYPE_ACTION:
4311 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4312 ies_len = skb->len -
4313 offsetof(struct ieee80211_mgmt,
4314 u.action.u.chan_switch.variable);
4319 /* CSA IE cannot be overridden, no need for BSSID */
4320 ieee802_11_parse_elems(
4321 mgmt->u.action.u.chan_switch.variable,
4322 ies_len, true, &elems, mgmt->bssid, NULL);
4324 if (elems.parse_error)
4327 ieee80211_sta_process_chanswitch(sdata,
4329 rx_status->device_timestamp,
4331 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4332 ies_len = skb->len -
4333 offsetof(struct ieee80211_mgmt,
4334 u.action.u.ext_chan_switch.variable);
4340 * extended CSA IE can't be overridden, no need for
4343 ieee802_11_parse_elems(
4344 mgmt->u.action.u.ext_chan_switch.variable,
4345 ies_len, true, &elems, mgmt->bssid, NULL);
4347 if (elems.parse_error)
4350 /* for the handling code pretend this was also an IE */
4351 elems.ext_chansw_ie =
4352 &mgmt->u.action.u.ext_chan_switch.data;
4354 ieee80211_sta_process_chanswitch(sdata,
4356 rx_status->device_timestamp,
4361 sdata_unlock(sdata);
4364 static void ieee80211_sta_timer(struct timer_list *t)
4366 struct ieee80211_sub_if_data *sdata =
4367 from_timer(sdata, t, u.mgd.timer);
4369 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4372 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4373 u8 *bssid, u8 reason, bool tx)
4375 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4377 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4380 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4384 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4386 struct ieee80211_local *local = sdata->local;
4387 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4388 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4392 struct ieee80211_prep_tx_info info = {
4393 .subtype = IEEE80211_STYPE_AUTH,
4396 sdata_assert_lock(sdata);
4398 if (WARN_ON_ONCE(!auth_data))
4403 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4404 sdata_info(sdata, "authentication with %pM timed out\n",
4405 auth_data->bss->bssid);
4408 * Most likely AP is not in the range so remove the
4409 * bss struct for that AP.
4411 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4416 if (auth_data->algorithm == WLAN_AUTH_SAE)
4417 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4419 drv_mgd_prepare_tx(local, sdata, &info);
4421 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4422 auth_data->bss->bssid, auth_data->tries,
4423 IEEE80211_AUTH_MAX_TRIES);
4425 auth_data->expected_transaction = 2;
4427 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4428 trans = auth_data->sae_trans;
4429 status = auth_data->sae_status;
4430 auth_data->expected_transaction = trans;
4433 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4434 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4435 IEEE80211_TX_INTFL_MLME_CONN_TX;
4437 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4438 auth_data->data, auth_data->data_len,
4439 auth_data->bss->bssid,
4440 auth_data->bss->bssid, NULL, 0, 0,
4443 if (tx_flags == 0) {
4444 if (auth_data->algorithm == WLAN_AUTH_SAE)
4445 auth_data->timeout = jiffies +
4446 IEEE80211_AUTH_TIMEOUT_SAE;
4448 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4450 auth_data->timeout =
4451 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4454 auth_data->timeout_started = true;
4455 run_again(sdata, auth_data->timeout);
4460 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4462 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4463 struct ieee80211_local *local = sdata->local;
4466 sdata_assert_lock(sdata);
4468 assoc_data->tries++;
4469 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4470 sdata_info(sdata, "association with %pM timed out\n",
4471 assoc_data->bss->bssid);
4474 * Most likely AP is not in the range so remove the
4475 * bss struct for that AP.
4477 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4482 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4483 assoc_data->bss->bssid, assoc_data->tries,
4484 IEEE80211_ASSOC_MAX_TRIES);
4485 ret = ieee80211_send_assoc(sdata);
4489 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4490 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4491 assoc_data->timeout_started = true;
4492 run_again(sdata, assoc_data->timeout);
4494 assoc_data->timeout =
4495 round_jiffies_up(jiffies +
4496 IEEE80211_ASSOC_TIMEOUT_LONG);
4497 assoc_data->timeout_started = true;
4498 run_again(sdata, assoc_data->timeout);
4504 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4505 __le16 fc, bool acked)
4507 struct ieee80211_local *local = sdata->local;
4509 sdata->u.mgd.status_fc = fc;
4510 sdata->u.mgd.status_acked = acked;
4511 sdata->u.mgd.status_received = true;
4513 ieee80211_queue_work(&local->hw, &sdata->work);
4516 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4518 struct ieee80211_local *local = sdata->local;
4519 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4523 if (ifmgd->status_received) {
4524 __le16 fc = ifmgd->status_fc;
4525 bool status_acked = ifmgd->status_acked;
4527 ifmgd->status_received = false;
4528 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4530 if (ifmgd->auth_data->algorithm ==
4532 ifmgd->auth_data->timeout =
4534 IEEE80211_AUTH_TIMEOUT_SAE;
4536 ifmgd->auth_data->timeout =
4538 IEEE80211_AUTH_TIMEOUT_SHORT;
4539 run_again(sdata, ifmgd->auth_data->timeout);
4541 ifmgd->auth_data->timeout = jiffies - 1;
4543 ifmgd->auth_data->timeout_started = true;
4544 } else if (ifmgd->assoc_data &&
4545 (ieee80211_is_assoc_req(fc) ||
4546 ieee80211_is_reassoc_req(fc))) {
4548 ifmgd->assoc_data->timeout =
4549 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4550 run_again(sdata, ifmgd->assoc_data->timeout);
4552 ifmgd->assoc_data->timeout = jiffies - 1;
4554 ifmgd->assoc_data->timeout_started = true;
4558 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4559 time_after(jiffies, ifmgd->auth_data->timeout)) {
4560 if (ifmgd->auth_data->done) {
4562 * ok ... we waited for assoc but userspace didn't,
4563 * so let's just kill the auth data
4565 ieee80211_destroy_auth_data(sdata, false);
4566 } else if (ieee80211_auth(sdata)) {
4568 struct ieee80211_event event = {
4570 .u.mlme.data = AUTH_EVENT,
4571 .u.mlme.status = MLME_TIMEOUT,
4574 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4576 ieee80211_destroy_auth_data(sdata, false);
4578 cfg80211_auth_timeout(sdata->dev, bssid);
4579 drv_event_callback(sdata->local, sdata, &event);
4581 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4582 run_again(sdata, ifmgd->auth_data->timeout);
4584 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4585 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4586 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4587 ieee80211_do_assoc(sdata)) {
4588 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4589 struct ieee80211_event event = {
4591 .u.mlme.data = ASSOC_EVENT,
4592 .u.mlme.status = MLME_TIMEOUT,
4595 ieee80211_destroy_assoc_data(sdata, false, false);
4596 cfg80211_assoc_timeout(sdata->dev, bss);
4597 drv_event_callback(sdata->local, sdata, &event);
4599 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4600 run_again(sdata, ifmgd->assoc_data->timeout);
4602 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4603 ifmgd->associated) {
4607 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4609 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4610 max_tries = max_nullfunc_tries;
4612 max_tries = max_probe_tries;
4614 /* ACK received for nullfunc probing frame */
4615 if (!ifmgd->probe_send_count)
4616 ieee80211_reset_ap_probe(sdata);
4617 else if (ifmgd->nullfunc_failed) {
4618 if (ifmgd->probe_send_count < max_tries) {
4620 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4621 bssid, ifmgd->probe_send_count,
4623 ieee80211_mgd_probe_ap_send(sdata);
4626 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4628 ieee80211_sta_connection_lost(sdata, bssid,
4629 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4632 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4633 run_again(sdata, ifmgd->probe_timeout);
4634 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4636 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4637 bssid, probe_wait_ms);
4638 ieee80211_sta_connection_lost(sdata, bssid,
4639 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4640 } else if (ifmgd->probe_send_count < max_tries) {
4642 "No probe response from AP %pM after %dms, try %d/%i\n",
4643 bssid, probe_wait_ms,
4644 ifmgd->probe_send_count, max_tries);
4645 ieee80211_mgd_probe_ap_send(sdata);
4648 * We actually lost the connection ... or did we?
4652 "No probe response from AP %pM after %dms, disconnecting.\n",
4653 bssid, probe_wait_ms);
4655 ieee80211_sta_connection_lost(sdata, bssid,
4656 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4660 sdata_unlock(sdata);
4663 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4665 struct ieee80211_sub_if_data *sdata =
4666 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4667 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4669 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4672 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4675 sdata->u.mgd.connection_loss = false;
4676 ieee80211_queue_work(&sdata->local->hw,
4677 &sdata->u.mgd.beacon_connection_loss_work);
4680 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4682 struct ieee80211_sub_if_data *sdata =
4683 from_timer(sdata, t, u.mgd.conn_mon_timer);
4684 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4685 struct ieee80211_local *local = sdata->local;
4686 struct sta_info *sta;
4687 unsigned long timeout;
4689 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4692 sta = sta_info_get(sdata, ifmgd->bssid);
4696 timeout = sta->status_stats.last_ack;
4697 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4698 timeout = sta->rx_stats.last_rx;
4699 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4701 /* If timeout is after now, then update timer to fire at
4702 * the later date, but do not actually probe at this time.
4704 if (time_is_after_jiffies(timeout)) {
4705 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4709 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4712 static void ieee80211_sta_monitor_work(struct work_struct *work)
4714 struct ieee80211_sub_if_data *sdata =
4715 container_of(work, struct ieee80211_sub_if_data,
4716 u.mgd.monitor_work);
4718 ieee80211_mgd_probe_ap(sdata, false);
4721 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4723 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4724 __ieee80211_stop_poll(sdata);
4726 /* let's probe the connection once */
4727 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4728 ieee80211_queue_work(&sdata->local->hw,
4729 &sdata->u.mgd.monitor_work);
4734 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4736 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4737 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4741 if (ifmgd->auth_data || ifmgd->assoc_data) {
4742 const u8 *bssid = ifmgd->auth_data ?
4743 ifmgd->auth_data->bss->bssid :
4744 ifmgd->assoc_data->bss->bssid;
4747 * If we are trying to authenticate / associate while suspending,
4748 * cfg80211 won't know and won't actually abort those attempts,
4749 * thus we need to do that ourselves.
4751 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4752 IEEE80211_STYPE_DEAUTH,
4753 WLAN_REASON_DEAUTH_LEAVING,
4755 if (ifmgd->assoc_data)
4756 ieee80211_destroy_assoc_data(sdata, false, true);
4757 if (ifmgd->auth_data)
4758 ieee80211_destroy_auth_data(sdata, false);
4759 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4760 IEEE80211_DEAUTH_FRAME_LEN,
4764 /* This is a bit of a hack - we should find a better and more generic
4765 * solution to this. Normally when suspending, cfg80211 will in fact
4766 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4767 * auth (not so important) or assoc (this is the problem) process.
4769 * As a consequence, it can happen that we are in the process of both
4770 * associating and suspending, and receive an association response
4771 * after cfg80211 has checked if it needs to disconnect, but before
4772 * we actually set the flag to drop incoming frames. This will then
4773 * cause the workqueue flush to process the association response in
4774 * the suspend, resulting in a successful association just before it
4775 * tries to remove the interface from the driver, which now though
4776 * has a channel context assigned ... this results in issues.
4778 * To work around this (for now) simply deauth here again if we're
4781 if (ifmgd->associated && !sdata->local->wowlan) {
4783 struct cfg80211_deauth_request req = {
4784 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4788 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4789 ieee80211_mgd_deauth(sdata, &req);
4792 sdata_unlock(sdata);
4795 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4797 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4800 if (!ifmgd->associated) {
4801 sdata_unlock(sdata);
4805 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4806 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4807 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4808 ieee80211_sta_connection_lost(sdata,
4809 ifmgd->associated->bssid,
4810 WLAN_REASON_UNSPECIFIED,
4812 sdata_unlock(sdata);
4815 sdata_unlock(sdata);
4819 /* interface setup */
4820 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4822 struct ieee80211_if_managed *ifmgd;
4824 ifmgd = &sdata->u.mgd;
4825 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4826 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4827 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4828 ieee80211_beacon_connection_loss_work);
4829 INIT_WORK(&ifmgd->csa_connection_drop_work,
4830 ieee80211_csa_connection_drop_work);
4831 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4832 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4833 ieee80211_tdls_peer_del_work);
4834 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4835 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4836 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4837 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4838 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4839 ieee80211_sta_handle_tspec_ac_params_wk);
4842 ifmgd->powersave = sdata->wdev.ps;
4843 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4844 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4845 ifmgd->p2p_noa_index = -1;
4847 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4848 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4850 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4852 /* Setup TDLS data */
4853 spin_lock_init(&ifmgd->teardown_lock);
4854 ifmgd->teardown_skb = NULL;
4855 ifmgd->orig_teardown_skb = NULL;
4858 /* scan finished notification */
4859 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4861 struct ieee80211_sub_if_data *sdata;
4863 /* Restart STA timers */
4865 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4866 if (ieee80211_sdata_running(sdata))
4867 ieee80211_restart_sta_timer(sdata);
4872 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4873 struct cfg80211_bss *cbss)
4875 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4876 const u8 *ht_cap_ie, *vht_cap_ie;
4877 const struct ieee80211_ht_cap *ht_cap;
4878 const struct ieee80211_vht_cap *vht_cap;
4881 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4884 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4885 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4886 ht_cap = (void *)(ht_cap_ie + 2);
4887 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4889 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4890 * "Tx Unequal Modulation Supported" fields.
4894 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4897 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4898 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4902 vht_cap = (void *)(vht_cap_ie + 2);
4903 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4904 for (nss = 8; nss > 0; nss--) {
4905 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4906 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4909 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4910 chains = max(chains, nss);
4917 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4918 struct ieee80211_supported_band *sband,
4919 const struct ieee80211_he_operation *he_op)
4921 const struct ieee80211_sta_he_cap *sta_he_cap =
4922 ieee80211_get_he_iftype_cap(sband,
4923 ieee80211_vif_type_p2p(&sdata->vif));
4927 if (!sta_he_cap || !he_op)
4930 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4932 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4933 for (i = 0; i < 3; i++) {
4934 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4935 &sta_he_cap->he_mcs_nss_supp;
4936 u16 sta_mcs_map_rx =
4937 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4938 u16 sta_mcs_map_tx =
4939 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4941 bool verified = true;
4944 * For each band there is a maximum of 8 spatial streams
4945 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4946 * of 2 bits per NSS (1-8), with the values defined in enum
4947 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4948 * capabilities aren't less than the AP's minimum requirements
4949 * for this HE BSS per SS.
4950 * It is enough to find one such band that meets the reqs.
4952 for (nss = 8; nss > 0; nss--) {
4953 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4954 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4955 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4957 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4961 * Make sure the HE AP doesn't require MCSs that aren't
4962 * supported by the client
4964 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4965 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4966 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4976 /* If here, STA doesn't meet AP's HE min requirements */
4980 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4981 struct cfg80211_bss *cbss)
4983 struct ieee80211_local *local = sdata->local;
4984 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4985 const struct ieee80211_ht_cap *ht_cap = NULL;
4986 const struct ieee80211_ht_operation *ht_oper = NULL;
4987 const struct ieee80211_vht_operation *vht_oper = NULL;
4988 const struct ieee80211_he_operation *he_oper = NULL;
4989 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4990 struct ieee80211_supported_band *sband;
4991 struct cfg80211_chan_def chandef;
4992 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4993 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4994 struct ieee80211_bss *bss = (void *)cbss->priv;
4999 sband = local->hw.wiphy->bands[cbss->channel->band];
5001 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5002 IEEE80211_STA_DISABLE_80P80MHZ |
5003 IEEE80211_STA_DISABLE_160MHZ);
5005 /* disable HT/VHT/HE if we don't support them */
5006 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5007 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5008 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5009 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5012 if (!sband->vht_cap.vht_supported && is_5ghz) {
5013 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5014 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5017 if (!ieee80211_get_he_iftype_cap(sband,
5018 ieee80211_vif_type_p2p(&sdata->vif)))
5019 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5023 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5024 const u8 *ht_oper_ie, *ht_cap_ie;
5026 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
5027 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
5028 ht_oper = (void *)(ht_oper_ie + 2);
5030 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
5031 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
5032 ht_cap = (void *)(ht_cap_ie + 2);
5035 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5040 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5041 const u8 *vht_oper_ie, *vht_cap;
5043 vht_oper_ie = ieee80211_bss_get_ie(cbss,
5044 WLAN_EID_VHT_OPERATION);
5045 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
5046 vht_oper = (void *)(vht_oper_ie + 2);
5047 if (vht_oper && !ht_oper) {
5050 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5051 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5052 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5053 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5056 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
5057 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
5058 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5063 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5064 const struct cfg80211_bss_ies *ies;
5065 const u8 *he_oper_ie;
5067 ies = rcu_dereference(cbss->ies);
5068 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
5069 ies->data, ies->len);
5071 he_oper_ie[1] >= ieee80211_he_oper_size(&he_oper_ie[3]))
5072 he_oper = (void *)(he_oper_ie + 3);
5076 if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5077 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5080 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5082 for (i = 0; i < sband->n_channels; i++) {
5083 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5084 IEEE80211_CHAN_NO_80MHZ))
5092 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5094 if (sband->band == NL80211_BAND_S1GHZ) {
5095 const u8 *s1g_oper_ie;
5097 s1g_oper_ie = ieee80211_bss_get_ie(cbss,
5098 WLAN_EID_S1G_OPERATION);
5099 if (s1g_oper_ie && s1g_oper_ie[1] >= sizeof(*s1g_oper))
5100 s1g_oper = (void *)(s1g_oper_ie + 2);
5103 "AP missing S1G operation element?\n");
5106 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5109 ht_oper, vht_oper, he_oper,
5113 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5118 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5119 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5123 /* will change later if needed */
5124 sdata->smps_mode = IEEE80211_SMPS_OFF;
5126 mutex_lock(&local->mtx);
5128 * If this fails (possibly due to channel context sharing
5129 * on incompatible channels, e.g. 80+80 and 160 sharing the
5130 * same control channel) try to use a smaller bandwidth.
5132 ret = ieee80211_vif_use_channel(sdata, &chandef,
5133 IEEE80211_CHANCTX_SHARED);
5135 /* don't downgrade for 5 and 10 MHz channels, though. */
5136 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5137 chandef.width == NL80211_CHAN_WIDTH_10)
5140 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5141 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5142 ret = ieee80211_vif_use_channel(sdata, &chandef,
5143 IEEE80211_CHANCTX_SHARED);
5146 mutex_unlock(&local->mtx);
5150 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5151 u8 *dtim_count, u8 *dtim_period)
5153 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5154 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5156 const struct ieee80211_tim_ie *tim = NULL;
5157 const struct ieee80211_bssid_index *idx;
5158 bool valid = tim_ie && tim_ie[1] >= 2;
5161 tim = (void *)(tim_ie + 2);
5164 *dtim_count = valid ? tim->dtim_count : 0;
5167 *dtim_period = valid ? tim->dtim_period : 0;
5169 /* Check if value is overridden by non-transmitted profile */
5170 if (!idx_ie || idx_ie[1] < 3)
5173 idx = (void *)(idx_ie + 2);
5176 *dtim_count = idx->dtim_count;
5179 *dtim_period = idx->dtim_period;
5184 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5185 struct cfg80211_bss *cbss, bool assoc,
5188 struct ieee80211_local *local = sdata->local;
5189 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5190 struct ieee80211_bss *bss = (void *)cbss->priv;
5191 struct sta_info *new_sta = NULL;
5192 struct ieee80211_supported_band *sband;
5193 bool have_sta = false;
5196 sband = local->hw.wiphy->bands[cbss->channel->band];
5198 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5201 /* If a reconfig is happening, bail out */
5202 if (local->in_reconfig)
5207 have_sta = sta_info_get(sdata, cbss->bssid);
5212 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5218 * Set up the information for the new channel before setting the
5219 * new channel. We can't - completely race-free - change the basic
5220 * rates bitmap and the channel (sband) that it refers to, but if
5221 * we set it up before we at least avoid calling into the driver's
5222 * bss_info_changed() method with invalid information (since we do
5223 * call that from changing the channel - only for IDLE and perhaps
5224 * some others, but ...).
5226 * So to avoid that, just set up all the new information before the
5227 * channel, but tell the driver to apply it only afterwards, since
5228 * it might need the new channel for that.
5231 u32 rates = 0, basic_rates = 0;
5232 bool have_higher_than_11mbit = false;
5233 int min_rate = INT_MAX, min_rate_index = -1;
5234 const struct cfg80211_bss_ies *ies;
5235 int shift = ieee80211_vif_get_shift(&sdata->vif);
5237 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5238 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5239 ieee80211_s1g_sta_rate_init(new_sta);
5243 ieee80211_get_rates(sband, bss->supp_rates,
5244 bss->supp_rates_len,
5245 &rates, &basic_rates,
5246 &have_higher_than_11mbit,
5247 &min_rate, &min_rate_index,
5251 * This used to be a workaround for basic rates missing
5252 * in the association response frame. Now that we no
5253 * longer use the basic rates from there, it probably
5254 * doesn't happen any more, but keep the workaround so
5255 * in case some *other* APs are buggy in different ways
5256 * we can connect -- with a warning.
5257 * Allow this workaround only in case the AP provided at least
5260 if (min_rate_index < 0) {
5262 "No legacy rates in association response\n");
5264 sta_info_free(local, new_sta);
5266 } else if (!basic_rates) {
5268 "No basic rates, using min rate instead\n");
5269 basic_rates = BIT(min_rate_index);
5273 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5276 "No rates found, keeping mandatory only\n");
5278 sdata->vif.bss_conf.basic_rates = basic_rates;
5280 /* cf. IEEE 802.11 9.2.12 */
5281 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5282 have_higher_than_11mbit)
5283 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5285 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5288 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5290 /* set timing information */
5291 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5293 ies = rcu_dereference(cbss->beacon_ies);
5295 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5296 sdata->vif.bss_conf.sync_device_ts =
5297 bss->device_ts_beacon;
5299 ieee80211_get_dtim(ies,
5300 &sdata->vif.bss_conf.sync_dtim_count,
5302 } else if (!ieee80211_hw_check(&sdata->local->hw,
5303 TIMING_BEACON_ONLY)) {
5304 ies = rcu_dereference(cbss->proberesp_ies);
5305 /* must be non-NULL since beacon IEs were NULL */
5306 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5307 sdata->vif.bss_conf.sync_device_ts =
5308 bss->device_ts_presp;
5309 sdata->vif.bss_conf.sync_dtim_count = 0;
5311 sdata->vif.bss_conf.sync_tsf = 0;
5312 sdata->vif.bss_conf.sync_device_ts = 0;
5313 sdata->vif.bss_conf.sync_dtim_count = 0;
5318 if (new_sta || override) {
5319 err = ieee80211_prep_channel(sdata, cbss);
5322 sta_info_free(local, new_sta);
5329 * tell driver about BSSID, basic rates and timing
5330 * this was set up above, before setting the channel
5332 ieee80211_bss_info_change_notify(sdata,
5333 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5334 BSS_CHANGED_BEACON_INT);
5337 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5339 err = sta_info_insert(new_sta);
5343 "failed to insert STA entry for the AP (error %d)\n",
5348 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5350 /* Cancel scan to ensure that nothing interferes with connection */
5351 if (local->scanning)
5352 ieee80211_scan_cancel(local);
5358 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5359 struct cfg80211_auth_request *req)
5361 struct ieee80211_local *local = sdata->local;
5362 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5363 struct ieee80211_mgd_auth_data *auth_data;
5368 /* prepare auth data structure */
5370 switch (req->auth_type) {
5371 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5372 auth_alg = WLAN_AUTH_OPEN;
5374 case NL80211_AUTHTYPE_SHARED_KEY:
5377 auth_alg = WLAN_AUTH_SHARED_KEY;
5379 case NL80211_AUTHTYPE_FT:
5380 auth_alg = WLAN_AUTH_FT;
5382 case NL80211_AUTHTYPE_NETWORK_EAP:
5383 auth_alg = WLAN_AUTH_LEAP;
5385 case NL80211_AUTHTYPE_SAE:
5386 auth_alg = WLAN_AUTH_SAE;
5388 case NL80211_AUTHTYPE_FILS_SK:
5389 auth_alg = WLAN_AUTH_FILS_SK;
5391 case NL80211_AUTHTYPE_FILS_SK_PFS:
5392 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5394 case NL80211_AUTHTYPE_FILS_PK:
5395 auth_alg = WLAN_AUTH_FILS_PK;
5401 if (ifmgd->assoc_data)
5404 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5405 req->ie_len, GFP_KERNEL);
5409 auth_data->bss = req->bss;
5411 if (req->auth_data_len >= 4) {
5412 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5413 __le16 *pos = (__le16 *) req->auth_data;
5415 auth_data->sae_trans = le16_to_cpu(pos[0]);
5416 auth_data->sae_status = le16_to_cpu(pos[1]);
5418 memcpy(auth_data->data, req->auth_data + 4,
5419 req->auth_data_len - 4);
5420 auth_data->data_len += req->auth_data_len - 4;
5423 /* Check if continuing authentication or trying to authenticate with the
5424 * same BSS that we were in the process of authenticating with and avoid
5425 * removal and re-addition of the STA entry in
5426 * ieee80211_prep_connection().
5428 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5430 if (req->ie && req->ie_len) {
5431 memcpy(&auth_data->data[auth_data->data_len],
5432 req->ie, req->ie_len);
5433 auth_data->data_len += req->ie_len;
5436 if (req->key && req->key_len) {
5437 auth_data->key_len = req->key_len;
5438 auth_data->key_idx = req->key_idx;
5439 memcpy(auth_data->key, req->key, req->key_len);
5442 auth_data->algorithm = auth_alg;
5444 /* try to authenticate/probe */
5446 if (ifmgd->auth_data) {
5447 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5448 auth_data->peer_confirmed =
5449 ifmgd->auth_data->peer_confirmed;
5451 ieee80211_destroy_auth_data(sdata, cont_auth);
5454 /* prep auth_data so we don't go into idle on disassoc */
5455 ifmgd->auth_data = auth_data;
5457 /* If this is continuation of an ongoing SAE authentication exchange
5458 * (i.e., request to send SAE Confirm) and the peer has already
5459 * confirmed, mark authentication completed since we are about to send
5462 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5463 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5464 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5466 if (ifmgd->associated) {
5467 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5470 "disconnect from AP %pM for new auth to %pM\n",
5471 ifmgd->associated->bssid, req->bss->bssid);
5472 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5473 WLAN_REASON_UNSPECIFIED,
5476 ieee80211_report_disconnect(sdata, frame_buf,
5477 sizeof(frame_buf), true,
5478 WLAN_REASON_UNSPECIFIED,
5482 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5484 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5488 err = ieee80211_auth(sdata);
5490 sta_info_destroy_addr(sdata, req->bss->bssid);
5494 /* hold our own reference */
5495 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5499 eth_zero_addr(ifmgd->bssid);
5500 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5501 ifmgd->auth_data = NULL;
5502 mutex_lock(&sdata->local->mtx);
5503 ieee80211_vif_release_channel(sdata);
5504 mutex_unlock(&sdata->local->mtx);
5509 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5510 struct cfg80211_assoc_request *req)
5512 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5513 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5514 struct ieee80211_local *local = sdata->local;
5515 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5516 struct ieee80211_bss *bss = (void *)req->bss->priv;
5517 struct ieee80211_mgd_assoc_data *assoc_data;
5518 const struct cfg80211_bss_ies *beacon_ies;
5519 struct ieee80211_supported_band *sband;
5520 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5521 const u8 *ssidie, *ht_ie, *vht_ie;
5523 bool override = false;
5525 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5530 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5531 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
5536 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5537 assoc_data->ssid_len = ssidie[1];
5538 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5539 bss_conf->ssid_len = assoc_data->ssid_len;
5542 if (ifmgd->associated) {
5543 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5546 "disconnect from AP %pM for new assoc to %pM\n",
5547 ifmgd->associated->bssid, req->bss->bssid);
5548 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5549 WLAN_REASON_UNSPECIFIED,
5552 ieee80211_report_disconnect(sdata, frame_buf,
5553 sizeof(frame_buf), true,
5554 WLAN_REASON_UNSPECIFIED,
5558 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5563 if (ifmgd->assoc_data) {
5568 if (ifmgd->auth_data) {
5571 /* keep sta info, bssid if matching */
5572 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5573 ieee80211_destroy_auth_data(sdata, match);
5576 /* prepare assoc data */
5578 ifmgd->beacon_crc_valid = false;
5580 assoc_data->wmm = bss->wmm_used &&
5581 (local->hw.queues >= IEEE80211_NUM_ACS);
5584 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5585 * We still associate in non-HT mode (11a/b/g) if any one of these
5586 * ciphers is configured as pairwise.
5587 * We can set this to true for non-11n hardware, that'll be checked
5588 * separately along with the peer capabilities.
5590 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5591 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5592 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5593 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5594 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5595 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5596 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5597 netdev_info(sdata->dev,
5598 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5602 sband = local->hw.wiphy->bands[req->bss->channel->band];
5604 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5605 if (!bss->wmm_used) {
5606 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5607 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5608 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5609 netdev_info(sdata->dev,
5610 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5613 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5614 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5615 sizeof(ifmgd->ht_capa_mask));
5617 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5618 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5619 sizeof(ifmgd->vht_capa_mask));
5621 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5622 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5623 sizeof(ifmgd->s1g_capa_mask));
5625 if (req->ie && req->ie_len) {
5626 memcpy(assoc_data->ie, req->ie, req->ie_len);
5627 assoc_data->ie_len = req->ie_len;
5630 if (req->fils_kek) {
5631 /* should already be checked in cfg80211 - so warn */
5632 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5636 memcpy(assoc_data->fils_kek, req->fils_kek,
5638 assoc_data->fils_kek_len = req->fils_kek_len;
5641 if (req->fils_nonces)
5642 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5643 2 * FILS_NONCE_LEN);
5645 assoc_data->bss = req->bss;
5646 assoc_data->capability = req->bss->capability;
5647 assoc_data->supp_rates = bss->supp_rates;
5648 assoc_data->supp_rates_len = bss->supp_rates_len;
5651 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5652 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5653 assoc_data->ap_ht_param =
5654 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5656 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5657 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5658 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5659 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5660 sizeof(struct ieee80211_vht_cap));
5662 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5663 IEEE80211_STA_DISABLE_HE;
5666 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5667 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5668 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5669 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5671 if (bss->wmm_used && bss->uapsd_supported &&
5672 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5673 assoc_data->uapsd = true;
5674 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5676 assoc_data->uapsd = false;
5677 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5680 if (req->prev_bssid)
5681 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5684 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5685 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5687 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5688 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5691 if (req->flags & ASSOC_REQ_USE_RRM)
5692 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5694 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5696 if (req->crypto.control_port)
5697 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5699 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5701 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5702 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5703 sdata->control_port_over_nl80211 =
5704 req->crypto.control_port_over_nl80211;
5705 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5706 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5709 /* kick off associate process */
5711 ifmgd->assoc_data = assoc_data;
5712 ifmgd->dtim_period = 0;
5713 ifmgd->have_beacon = false;
5715 /* override HT/VHT configuration only if the AP and we support it */
5716 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5717 struct ieee80211_sta_ht_cap sta_ht_cap;
5719 if (req->flags & ASSOC_REQ_DISABLE_HT)
5722 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5723 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5725 /* check for 40 MHz disable override */
5726 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5727 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5728 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5731 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5732 req->flags & ASSOC_REQ_DISABLE_VHT)
5736 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5737 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5738 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5739 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5742 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5743 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5745 if (req->flags & ASSOC_REQ_DISABLE_HE)
5746 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5748 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5752 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5753 if (ifmgd->powersave)
5754 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5756 sdata->smps_mode = IEEE80211_SMPS_OFF;
5758 sdata->smps_mode = ifmgd->req_smps;
5762 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5764 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5767 * Wait up to one beacon interval ...
5768 * should this be more if we miss one?
5770 sdata_info(sdata, "waiting for beacon from %pM\n",
5772 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5773 assoc_data->timeout_started = true;
5774 assoc_data->need_beacon = true;
5775 } else if (beacon_ies) {
5776 const struct element *elem;
5779 ieee80211_get_dtim(beacon_ies, &dtim_count,
5780 &ifmgd->dtim_period);
5782 ifmgd->have_beacon = true;
5783 assoc_data->timeout = jiffies;
5784 assoc_data->timeout_started = true;
5786 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5787 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5788 sdata->vif.bss_conf.sync_device_ts =
5789 bss->device_ts_beacon;
5790 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5793 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5794 beacon_ies->data, beacon_ies->len);
5795 if (elem && elem->datalen >= 3)
5796 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5798 sdata->vif.bss_conf.profile_periodicity = 0;
5800 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5801 beacon_ies->data, beacon_ies->len);
5802 if (elem && elem->datalen >= 11 &&
5803 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5804 sdata->vif.bss_conf.ema_ap = true;
5806 sdata->vif.bss_conf.ema_ap = false;
5808 assoc_data->timeout = jiffies;
5809 assoc_data->timeout_started = true;
5813 run_again(sdata, assoc_data->timeout);
5815 if (bss->corrupt_data) {
5816 char *corrupt_type = "data";
5817 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5818 if (bss->corrupt_data &
5819 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5820 corrupt_type = "beacon and probe response";
5822 corrupt_type = "beacon";
5823 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5824 corrupt_type = "probe response";
5825 sdata_info(sdata, "associating with AP with corrupt %s\n",
5831 eth_zero_addr(ifmgd->bssid);
5832 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5833 ifmgd->assoc_data = NULL;
5839 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5840 struct cfg80211_deauth_request *req)
5842 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5843 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5844 bool tx = !req->local_state_change;
5845 struct ieee80211_prep_tx_info info = {
5846 .subtype = IEEE80211_STYPE_DEAUTH,
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, &info);
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);
5865 drv_mgd_complete_tx(sdata->local, sdata, &info);
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, &info);
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);
5900 drv_mgd_complete_tx(sdata->local, sdata, &info);
5907 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5908 struct cfg80211_disassoc_request *req)
5910 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5912 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5915 * cfg80211 should catch this ... but it's racy since
5916 * we can receive a disassoc frame, process it, hand it
5917 * to cfg80211 while that's in a locked section already
5918 * trying to tell us that the user wants to disconnect.
5920 if (ifmgd->associated != req->bss)
5924 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5925 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5927 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5928 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5929 req->reason_code, !req->local_state_change,
5932 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5933 req->reason_code, false);
5938 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5940 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5943 * Make sure some work items will not run after this,
5944 * they will not do anything but might not have been
5945 * cancelled when disconnecting.
5947 cancel_work_sync(&ifmgd->monitor_work);
5948 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5949 cancel_work_sync(&ifmgd->request_smps_work);
5950 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5951 cancel_work_sync(&ifmgd->chswitch_work);
5952 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5955 if (ifmgd->assoc_data) {
5956 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5957 ieee80211_destroy_assoc_data(sdata, false, false);
5958 cfg80211_assoc_timeout(sdata->dev, bss);
5960 if (ifmgd->auth_data)
5961 ieee80211_destroy_auth_data(sdata, false);
5962 spin_lock_bh(&ifmgd->teardown_lock);
5963 if (ifmgd->teardown_skb) {
5964 kfree_skb(ifmgd->teardown_skb);
5965 ifmgd->teardown_skb = NULL;
5966 ifmgd->orig_teardown_skb = NULL;
5968 kfree(ifmgd->assoc_req_ies);
5969 ifmgd->assoc_req_ies = NULL;
5970 ifmgd->assoc_req_ies_len = 0;
5971 spin_unlock_bh(&ifmgd->teardown_lock);
5972 del_timer_sync(&ifmgd->timer);
5973 sdata_unlock(sdata);
5976 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5977 enum nl80211_cqm_rssi_threshold_event rssi_event,
5981 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5983 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5985 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5987 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5989 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5991 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5993 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5995 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5997 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);