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 void 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 = {};
688 /* we know it's writable, cast away the const */
689 if (assoc_data->ie_len)
690 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
694 sdata_assert_lock(sdata);
697 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
698 if (WARN_ON(!chanctx_conf)) {
702 chan = chanctx_conf->def.chan;
704 sband = local->hw.wiphy->bands[chan->band];
705 shift = ieee80211_vif_get_shift(&sdata->vif);
707 if (assoc_data->supp_rates_len) {
709 * Get all rates supported by the device and the AP as
710 * some APs don't like getting a superset of their rates
711 * in the association request (e.g. D-Link DAP 1353 in
714 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
715 assoc_data->supp_rates,
716 assoc_data->supp_rates_len,
720 * In case AP not provide any supported rates information
721 * before association, we send information element(s) with
722 * all rates that we support.
725 for (i = 0; i < sband->n_bitrates; i++) {
731 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
733 skb = alloc_skb(local->hw.extra_tx_headroom +
734 sizeof(*mgmt) + /* bit too much but doesn't matter */
735 2 + assoc_data->ssid_len + /* SSID */
736 4 + rates_len + /* (extended) rates */
737 4 + /* power capability */
738 2 + 2 * sband->n_channels + /* supported channels */
739 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
740 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
741 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
742 sizeof(struct ieee80211_he_mcs_nss_supp) +
743 IEEE80211_HE_PPE_THRES_MAX_LEN +
744 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
745 assoc_data->ie_len + /* extra IEs */
746 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
748 (iftd ? iftd->vendor_elems.len : 0),
753 skb_reserve(skb, local->hw.extra_tx_headroom);
755 capab = WLAN_CAPABILITY_ESS;
757 if (sband->band == NL80211_BAND_2GHZ) {
758 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
759 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
762 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
763 capab |= WLAN_CAPABILITY_PRIVACY;
765 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
766 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
767 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
769 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
770 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
772 mgmt = skb_put_zero(skb, 24);
773 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
774 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
775 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
777 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
778 ieee80211_encode_usf(local->hw.conf.listen_interval) :
779 local->hw.conf.listen_interval);
780 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
782 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
783 IEEE80211_STYPE_REASSOC_REQ);
784 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
785 mgmt->u.reassoc_req.listen_interval = listen_int;
786 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
788 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
791 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
792 IEEE80211_STYPE_ASSOC_REQ);
793 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
794 mgmt->u.assoc_req.listen_interval = listen_int;
795 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
799 pos = skb_put(skb, 2 + assoc_data->ssid_len);
801 *pos++ = WLAN_EID_SSID;
802 *pos++ = assoc_data->ssid_len;
803 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
805 if (sband->band == NL80211_BAND_S1GHZ)
808 /* add all rates which were marked to be used above */
809 supp_rates_len = rates_len;
810 if (supp_rates_len > 8)
813 pos = skb_put(skb, supp_rates_len + 2);
814 *pos++ = WLAN_EID_SUPP_RATES;
815 *pos++ = supp_rates_len;
818 for (i = 0; i < sband->n_bitrates; i++) {
819 if (BIT(i) & rates) {
820 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
828 if (rates_len > count) {
829 pos = skb_put(skb, rates_len - count + 2);
830 *pos++ = WLAN_EID_EXT_SUPP_RATES;
831 *pos++ = rates_len - count;
833 for (i++; i < sband->n_bitrates; i++) {
834 if (BIT(i) & rates) {
836 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
844 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
845 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
846 pos = skb_put(skb, 4);
847 *pos++ = WLAN_EID_PWR_CAPABILITY;
849 *pos++ = 0; /* min tx power */
851 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
855 * Per spec, we shouldn't include the list of channels if we advertise
856 * support for extended channel switching, but we've always done that;
857 * (for now?) apply this restriction only on the (new) 6 GHz band.
859 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
860 (sband->band != NL80211_BAND_6GHZ ||
861 !ext_capa || ext_capa->datalen < 1 ||
862 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
863 /* TODO: get this in reg domain format */
864 pos = skb_put(skb, 2 * sband->n_channels + 2);
865 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
866 *pos++ = 2 * sband->n_channels;
867 for (i = 0; i < sband->n_channels; i++) {
868 *pos++ = ieee80211_frequency_to_channel(
869 sband->channels[i].center_freq);
870 *pos++ = 1; /* one channel in the subband*/
874 /* Set MBSSID support for HE AP if needed */
875 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
876 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
877 ext_capa && ext_capa->datalen >= 3)
878 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
880 /* if present, add any custom IEs that go before HT */
881 if (assoc_data->ie_len) {
882 static const u8 before_ht[] = {
885 WLAN_EID_EXT_SUPP_RATES,
886 WLAN_EID_PWR_CAPABILITY,
887 WLAN_EID_SUPPORTED_CHANNELS,
890 WLAN_EID_RRM_ENABLED_CAPABILITIES,
891 WLAN_EID_MOBILITY_DOMAIN,
892 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
893 WLAN_EID_RIC_DATA, /* reassoc only */
894 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
896 static const u8 after_ric[] = {
897 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
898 WLAN_EID_HT_CAPABILITY,
899 WLAN_EID_BSS_COEX_2040,
900 /* luckily this is almost always there */
901 WLAN_EID_EXT_CAPABILITY,
902 WLAN_EID_QOS_TRAFFIC_CAPA,
903 WLAN_EID_TIM_BCAST_REQ,
904 WLAN_EID_INTERWORKING,
905 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
906 WLAN_EID_VHT_CAPABILITY,
907 WLAN_EID_OPMODE_NOTIF,
910 noffset = ieee80211_ie_split_ric(assoc_data->ie,
913 ARRAY_SIZE(before_ht),
915 ARRAY_SIZE(after_ric),
917 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
921 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
922 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
923 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
925 if (sband->band != NL80211_BAND_6GHZ &&
926 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
927 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
928 sband, chan, sdata->smps_mode);
930 /* if present, add any custom IEs that go before VHT */
931 if (assoc_data->ie_len) {
932 static const u8 before_vht[] = {
934 * no need to list the ones split off before HT
937 WLAN_EID_BSS_COEX_2040,
938 WLAN_EID_EXT_CAPABILITY,
939 WLAN_EID_QOS_TRAFFIC_CAPA,
940 WLAN_EID_TIM_BCAST_REQ,
941 WLAN_EID_INTERWORKING,
942 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
945 /* RIC already taken above, so no need to handle here anymore */
946 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
947 before_vht, ARRAY_SIZE(before_vht),
949 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
953 /* if present, add any custom IEs that go before HE */
954 if (assoc_data->ie_len) {
955 static const u8 before_he[] = {
957 * no need to list the ones split off before VHT
960 WLAN_EID_OPMODE_NOTIF,
961 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
963 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
964 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
965 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
966 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
967 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
968 /* TODO: add 11ah/11aj/11ak elements */
971 /* RIC already taken above, so no need to handle here anymore */
972 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
973 before_he, ARRAY_SIZE(before_he),
975 pos = skb_put(skb, noffset - offset);
976 memcpy(pos, assoc_data->ie + offset, noffset - offset);
980 if (sband->band != NL80211_BAND_6GHZ &&
981 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
982 ieee80211_add_vht_ie(sdata, skb, sband,
983 &assoc_data->ap_vht_cap);
986 * If AP doesn't support HT, mark HE as disabled.
987 * If on the 5GHz band, make sure it supports VHT.
989 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
990 (sband->band == NL80211_BAND_5GHZ &&
991 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
992 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
994 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
995 ieee80211_add_he_ie(sdata, skb, sband);
997 /* if present, add any custom non-vendor IEs that go after HE */
998 if (assoc_data->ie_len) {
999 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1002 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1006 if (assoc_data->wmm) {
1007 if (assoc_data->uapsd) {
1008 qos_info = ifmgd->uapsd_queues;
1009 qos_info |= (ifmgd->uapsd_max_sp_len <<
1010 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1015 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1018 if (sband->band == NL80211_BAND_S1GHZ) {
1019 ieee80211_add_aid_request_ie(sdata, skb);
1020 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1023 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1024 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1026 /* add any remaining custom (i.e. vendor specific here) IEs */
1027 if (assoc_data->ie_len) {
1028 noffset = assoc_data->ie_len;
1029 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1032 if (assoc_data->fils_kek_len &&
1033 fils_encrypt_assoc_req(skb, assoc_data) < 0) {
1038 pos = skb_tail_pointer(skb);
1039 kfree(ifmgd->assoc_req_ies);
1040 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1041 ifmgd->assoc_req_ies_len = pos - ie_start;
1043 drv_mgd_prepare_tx(local, sdata, &info);
1045 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1046 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1047 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1048 IEEE80211_TX_INTFL_MLME_CONN_TX;
1049 ieee80211_tx_skb(sdata, skb);
1052 void ieee80211_send_pspoll(struct ieee80211_local *local,
1053 struct ieee80211_sub_if_data *sdata)
1055 struct ieee80211_pspoll *pspoll;
1056 struct sk_buff *skb;
1058 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1062 pspoll = (struct ieee80211_pspoll *) skb->data;
1063 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1065 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1066 ieee80211_tx_skb(sdata, skb);
1069 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1070 struct ieee80211_sub_if_data *sdata,
1073 struct sk_buff *skb;
1074 struct ieee80211_hdr_3addr *nullfunc;
1075 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1077 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1078 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1082 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1084 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1086 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1087 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1089 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1090 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1092 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1093 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1095 ieee80211_tx_skb(sdata, skb);
1098 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1099 struct ieee80211_sub_if_data *sdata)
1101 struct sk_buff *skb;
1102 struct ieee80211_hdr *nullfunc;
1105 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1108 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1112 skb_reserve(skb, local->hw.extra_tx_headroom);
1114 nullfunc = skb_put_zero(skb, 30);
1115 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1116 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1117 nullfunc->frame_control = fc;
1118 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1119 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1120 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1121 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1123 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1124 ieee80211_tx_skb(sdata, skb);
1127 /* spectrum management related things */
1128 static void ieee80211_chswitch_work(struct work_struct *work)
1130 struct ieee80211_sub_if_data *sdata =
1131 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1132 struct ieee80211_local *local = sdata->local;
1133 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1136 if (!ieee80211_sdata_running(sdata))
1140 mutex_lock(&local->mtx);
1141 mutex_lock(&local->chanctx_mtx);
1143 if (!ifmgd->associated)
1146 if (!sdata->vif.csa_active)
1150 * using reservation isn't immediate as it may be deferred until later
1151 * with multi-vif. once reservation is complete it will re-schedule the
1152 * work with no reserved_chanctx so verify chandef to check if it
1153 * completed successfully
1156 if (sdata->reserved_chanctx) {
1158 * with multi-vif csa driver may call ieee80211_csa_finish()
1159 * many times while waiting for other interfaces to use their
1162 if (sdata->reserved_ready)
1165 ret = ieee80211_vif_use_reserved_context(sdata);
1168 "failed to use reserved channel context, disconnecting (err=%d)\n",
1170 ieee80211_queue_work(&sdata->local->hw,
1171 &ifmgd->csa_connection_drop_work);
1178 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1179 &sdata->csa_chandef)) {
1181 "failed to finalize channel switch, disconnecting\n");
1182 ieee80211_queue_work(&sdata->local->hw,
1183 &ifmgd->csa_connection_drop_work);
1187 ifmgd->csa_waiting_bcn = true;
1189 ieee80211_sta_reset_beacon_monitor(sdata);
1190 ieee80211_sta_reset_conn_monitor(sdata);
1193 mutex_unlock(&local->chanctx_mtx);
1194 mutex_unlock(&local->mtx);
1195 sdata_unlock(sdata);
1198 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1200 struct ieee80211_local *local = sdata->local;
1201 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1204 sdata_assert_lock(sdata);
1206 WARN_ON(!sdata->vif.csa_active);
1208 if (sdata->csa_block_tx) {
1209 ieee80211_wake_vif_queues(local, sdata,
1210 IEEE80211_QUEUE_STOP_REASON_CSA);
1211 sdata->csa_block_tx = false;
1214 sdata->vif.csa_active = false;
1215 ifmgd->csa_waiting_bcn = false;
1217 * If the CSA IE is still present on the beacon after the switch,
1218 * we need to consider it as a new CSA (possibly to self).
1220 ifmgd->beacon_crc_valid = false;
1222 ret = drv_post_channel_switch(sdata);
1225 "driver post channel switch failed, disconnecting\n");
1226 ieee80211_queue_work(&local->hw,
1227 &ifmgd->csa_connection_drop_work);
1231 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1234 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1236 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1237 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1239 trace_api_chswitch_done(sdata, success);
1242 "driver channel switch failed, disconnecting\n");
1243 ieee80211_queue_work(&sdata->local->hw,
1244 &ifmgd->csa_connection_drop_work);
1246 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1249 EXPORT_SYMBOL(ieee80211_chswitch_done);
1251 static void ieee80211_chswitch_timer(struct timer_list *t)
1253 struct ieee80211_sub_if_data *sdata =
1254 from_timer(sdata, t, u.mgd.chswitch_timer);
1256 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1260 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1262 struct ieee80211_local *local = sdata->local;
1264 if (!local->ops->abort_channel_switch)
1267 mutex_lock(&local->mtx);
1269 mutex_lock(&local->chanctx_mtx);
1270 ieee80211_vif_unreserve_chanctx(sdata);
1271 mutex_unlock(&local->chanctx_mtx);
1273 if (sdata->csa_block_tx)
1274 ieee80211_wake_vif_queues(local, sdata,
1275 IEEE80211_QUEUE_STOP_REASON_CSA);
1277 sdata->csa_block_tx = false;
1278 sdata->vif.csa_active = false;
1280 mutex_unlock(&local->mtx);
1282 drv_abort_channel_switch(sdata);
1286 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1287 u64 timestamp, u32 device_timestamp,
1288 struct ieee802_11_elems *elems,
1291 struct ieee80211_local *local = sdata->local;
1292 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1293 struct cfg80211_bss *cbss = ifmgd->associated;
1294 struct ieee80211_chanctx_conf *conf;
1295 struct ieee80211_chanctx *chanctx;
1296 enum nl80211_band current_band;
1297 struct ieee80211_csa_ie csa_ie;
1298 struct ieee80211_channel_switch ch_switch;
1299 struct ieee80211_bss *bss;
1302 sdata_assert_lock(sdata);
1307 if (local->scanning)
1310 current_band = cbss->channel->band;
1311 bss = (void *)cbss->priv;
1312 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1315 ifmgd->associated->bssid, &csa_ie);
1318 ch_switch.timestamp = timestamp;
1319 ch_switch.device_timestamp = device_timestamp;
1320 ch_switch.block_tx = csa_ie.mode;
1321 ch_switch.chandef = csa_ie.chandef;
1322 ch_switch.count = csa_ie.count;
1323 ch_switch.delay = csa_ie.max_switch_time;
1327 goto lock_and_drop_connection;
1329 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1331 ieee80211_sta_abort_chanswitch(sdata);
1333 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1335 } else if (sdata->vif.csa_active || res) {
1336 /* disregard subsequent announcements if already processing */
1340 if (sdata->vif.bss_conf.chandef.chan->band !=
1341 csa_ie.chandef.chan->band) {
1343 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1344 ifmgd->associated->bssid,
1345 csa_ie.chandef.chan->center_freq,
1346 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1347 csa_ie.chandef.center_freq2);
1348 goto lock_and_drop_connection;
1351 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1352 IEEE80211_CHAN_DISABLED)) {
1354 "AP %pM switches to unsupported channel "
1355 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1357 ifmgd->associated->bssid,
1358 csa_ie.chandef.chan->center_freq,
1359 csa_ie.chandef.chan->freq_offset,
1360 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1361 csa_ie.chandef.freq1_offset,
1362 csa_ie.chandef.center_freq2);
1363 goto lock_and_drop_connection;
1366 if (cfg80211_chandef_identical(&csa_ie.chandef,
1367 &sdata->vif.bss_conf.chandef) &&
1368 (!csa_ie.mode || !beacon)) {
1369 if (ifmgd->csa_ignored_same_chan)
1372 "AP %pM tries to chanswitch to same channel, ignore\n",
1373 ifmgd->associated->bssid);
1374 ifmgd->csa_ignored_same_chan = true;
1379 * Drop all TDLS peers - either we disconnect or move to a different
1380 * channel from this point on. There's no telling what our peer will do.
1381 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1382 * have an incompatible wider chandef.
1384 ieee80211_teardown_tdls_peers(sdata);
1386 mutex_lock(&local->mtx);
1387 mutex_lock(&local->chanctx_mtx);
1388 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1389 lockdep_is_held(&local->chanctx_mtx));
1392 "no channel context assigned to vif?, disconnecting\n");
1393 goto drop_connection;
1396 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1398 if (local->use_chanctx &&
1399 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1401 "driver doesn't support chan-switch with channel contexts\n");
1402 goto drop_connection;
1405 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1407 "preparing for channel switch failed, disconnecting\n");
1408 goto drop_connection;
1411 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1412 chanctx->mode, false);
1415 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1417 goto drop_connection;
1419 mutex_unlock(&local->chanctx_mtx);
1421 sdata->vif.csa_active = true;
1422 sdata->csa_chandef = csa_ie.chandef;
1423 sdata->csa_block_tx = csa_ie.mode;
1424 ifmgd->csa_ignored_same_chan = false;
1425 ifmgd->beacon_crc_valid = false;
1427 if (sdata->csa_block_tx)
1428 ieee80211_stop_vif_queues(local, sdata,
1429 IEEE80211_QUEUE_STOP_REASON_CSA);
1430 mutex_unlock(&local->mtx);
1432 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1433 csa_ie.count, csa_ie.mode);
1435 if (local->ops->channel_switch) {
1436 /* use driver's channel switch callback */
1437 drv_channel_switch(local, sdata, &ch_switch);
1441 /* channel switch handled in software */
1442 if (csa_ie.count <= 1)
1443 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1445 mod_timer(&ifmgd->chswitch_timer,
1446 TU_TO_EXP_TIME((csa_ie.count - 1) *
1447 cbss->beacon_interval));
1449 lock_and_drop_connection:
1450 mutex_lock(&local->mtx);
1451 mutex_lock(&local->chanctx_mtx);
1454 * This is just so that the disconnect flow will know that
1455 * we were trying to switch channel and failed. In case the
1456 * mode is 1 (we are not allowed to Tx), we will know not to
1457 * send a deauthentication frame. Those two fields will be
1458 * reset when the disconnection worker runs.
1460 sdata->vif.csa_active = true;
1461 sdata->csa_block_tx = csa_ie.mode;
1463 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1464 mutex_unlock(&local->chanctx_mtx);
1465 mutex_unlock(&local->mtx);
1469 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1470 struct ieee80211_channel *channel,
1471 const u8 *country_ie, u8 country_ie_len,
1472 const u8 *pwr_constr_elem,
1473 int *chan_pwr, int *pwr_reduction)
1475 struct ieee80211_country_ie_triplet *triplet;
1476 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1477 int i, chan_increment;
1478 bool have_chan_pwr = false;
1481 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1484 triplet = (void *)(country_ie + 3);
1485 country_ie_len -= 3;
1487 switch (channel->band) {
1491 case NL80211_BAND_2GHZ:
1492 case NL80211_BAND_60GHZ:
1495 case NL80211_BAND_5GHZ:
1498 case NL80211_BAND_6GHZ:
1500 * In the 6 GHz band, the "maximum transmit power level"
1501 * field in the triplets is reserved, and thus will be
1502 * zero and we shouldn't use it to control TX power.
1503 * The actual TX power will be given in the transmit
1504 * power envelope element instead.
1510 while (country_ie_len >= 3) {
1511 u8 first_channel = triplet->chans.first_channel;
1513 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1516 for (i = 0; i < triplet->chans.num_channels; i++) {
1517 if (first_channel + i * chan_increment == chan) {
1518 have_chan_pwr = true;
1519 *chan_pwr = triplet->chans.max_power;
1528 country_ie_len -= 3;
1531 if (have_chan_pwr && pwr_constr_elem)
1532 *pwr_reduction = *pwr_constr_elem;
1536 return have_chan_pwr;
1539 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1540 struct ieee80211_channel *channel,
1541 const u8 *cisco_dtpc_ie,
1544 /* From practical testing, the first data byte of the DTPC element
1545 * seems to contain the requested dBm level, and the CLI on Cisco
1546 * APs clearly state the range is -127 to 127 dBm, which indicates
1547 * a signed byte, although it seemingly never actually goes negative.
1548 * The other byte seems to always be zero.
1550 *pwr_level = (__s8)cisco_dtpc_ie[4];
1553 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1554 struct ieee80211_channel *channel,
1555 struct ieee80211_mgmt *mgmt,
1556 const u8 *country_ie, u8 country_ie_len,
1557 const u8 *pwr_constr_ie,
1558 const u8 *cisco_dtpc_ie)
1560 bool has_80211h_pwr = false, has_cisco_pwr = false;
1561 int chan_pwr = 0, pwr_reduction_80211h = 0;
1562 int pwr_level_cisco, pwr_level_80211h;
1564 __le16 capab = mgmt->u.probe_resp.capab_info;
1566 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1567 return 0; /* TODO */
1570 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1571 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1572 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1573 sdata, channel, country_ie, country_ie_len,
1574 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1576 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1579 if (cisco_dtpc_ie) {
1580 ieee80211_find_cisco_dtpc(
1581 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1582 has_cisco_pwr = true;
1585 if (!has_80211h_pwr && !has_cisco_pwr)
1588 /* If we have both 802.11h and Cisco DTPC, apply both limits
1589 * by picking the smallest of the two power levels advertised.
1591 if (has_80211h_pwr &&
1592 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1593 new_ap_level = pwr_level_80211h;
1595 if (sdata->ap_power_level == new_ap_level)
1599 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1600 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1601 sdata->u.mgd.bssid);
1602 } else { /* has_cisco_pwr is always true here. */
1603 new_ap_level = pwr_level_cisco;
1605 if (sdata->ap_power_level == new_ap_level)
1609 "Limiting TX power to %d dBm as advertised by %pM\n",
1610 pwr_level_cisco, sdata->u.mgd.bssid);
1613 sdata->ap_power_level = new_ap_level;
1614 if (__ieee80211_recalc_txpower(sdata))
1615 return BSS_CHANGED_TXPOWER;
1620 static void ieee80211_enable_ps(struct ieee80211_local *local,
1621 struct ieee80211_sub_if_data *sdata)
1623 struct ieee80211_conf *conf = &local->hw.conf;
1626 * If we are scanning right now then the parameters will
1627 * take effect when scan finishes.
1629 if (local->scanning)
1632 if (conf->dynamic_ps_timeout > 0 &&
1633 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1634 mod_timer(&local->dynamic_ps_timer, jiffies +
1635 msecs_to_jiffies(conf->dynamic_ps_timeout));
1637 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1638 ieee80211_send_nullfunc(local, sdata, true);
1640 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1641 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1644 conf->flags |= IEEE80211_CONF_PS;
1645 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1649 static void ieee80211_change_ps(struct ieee80211_local *local)
1651 struct ieee80211_conf *conf = &local->hw.conf;
1653 if (local->ps_sdata) {
1654 ieee80211_enable_ps(local, local->ps_sdata);
1655 } else if (conf->flags & IEEE80211_CONF_PS) {
1656 conf->flags &= ~IEEE80211_CONF_PS;
1657 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1658 del_timer_sync(&local->dynamic_ps_timer);
1659 cancel_work_sync(&local->dynamic_ps_enable_work);
1663 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1665 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1666 struct sta_info *sta = NULL;
1667 bool authorized = false;
1669 if (!mgd->powersave)
1675 if (!mgd->associated)
1678 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1681 if (!mgd->have_beacon)
1685 sta = sta_info_get(sdata, mgd->bssid);
1687 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1693 /* need to hold RTNL or interface lock */
1694 void ieee80211_recalc_ps(struct ieee80211_local *local)
1696 struct ieee80211_sub_if_data *sdata, *found = NULL;
1700 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1701 local->ps_sdata = NULL;
1705 list_for_each_entry(sdata, &local->interfaces, list) {
1706 if (!ieee80211_sdata_running(sdata))
1708 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1709 /* If an AP vif is found, then disable PS
1710 * by setting the count to zero thereby setting
1716 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1722 if (count == 1 && ieee80211_powersave_allowed(found)) {
1723 u8 dtimper = found->u.mgd.dtim_period;
1725 timeout = local->dynamic_ps_forced_timeout;
1728 local->hw.conf.dynamic_ps_timeout = timeout;
1730 /* If the TIM IE is invalid, pretend the value is 1 */
1734 local->hw.conf.ps_dtim_period = dtimper;
1735 local->ps_sdata = found;
1737 local->ps_sdata = NULL;
1740 ieee80211_change_ps(local);
1743 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1745 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1747 if (sdata->vif.bss_conf.ps != ps_allowed) {
1748 sdata->vif.bss_conf.ps = ps_allowed;
1749 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1753 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1755 struct ieee80211_local *local =
1756 container_of(work, struct ieee80211_local,
1757 dynamic_ps_disable_work);
1759 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1760 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1761 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1764 ieee80211_wake_queues_by_reason(&local->hw,
1765 IEEE80211_MAX_QUEUE_MAP,
1766 IEEE80211_QUEUE_STOP_REASON_PS,
1770 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1772 struct ieee80211_local *local =
1773 container_of(work, struct ieee80211_local,
1774 dynamic_ps_enable_work);
1775 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1776 struct ieee80211_if_managed *ifmgd;
1777 unsigned long flags;
1780 /* can only happen when PS was just disabled anyway */
1784 ifmgd = &sdata->u.mgd;
1786 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1789 if (local->hw.conf.dynamic_ps_timeout > 0) {
1790 /* don't enter PS if TX frames are pending */
1791 if (drv_tx_frames_pending(local)) {
1792 mod_timer(&local->dynamic_ps_timer, jiffies +
1794 local->hw.conf.dynamic_ps_timeout));
1799 * transmission can be stopped by others which leads to
1800 * dynamic_ps_timer expiry. Postpone the ps timer if it
1801 * is not the actual idle state.
1803 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1804 for (q = 0; q < local->hw.queues; q++) {
1805 if (local->queue_stop_reasons[q]) {
1806 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1808 mod_timer(&local->dynamic_ps_timer, jiffies +
1810 local->hw.conf.dynamic_ps_timeout));
1814 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1817 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1818 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1819 if (drv_tx_frames_pending(local)) {
1820 mod_timer(&local->dynamic_ps_timer, jiffies +
1822 local->hw.conf.dynamic_ps_timeout));
1824 ieee80211_send_nullfunc(local, sdata, true);
1825 /* Flush to get the tx status of nullfunc frame */
1826 ieee80211_flush_queues(local, sdata, false);
1830 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1831 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1832 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1833 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1834 local->hw.conf.flags |= IEEE80211_CONF_PS;
1835 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1839 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1841 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1843 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1846 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1848 struct delayed_work *delayed_work = to_delayed_work(work);
1849 struct ieee80211_sub_if_data *sdata =
1850 container_of(delayed_work, struct ieee80211_sub_if_data,
1851 dfs_cac_timer_work);
1852 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1854 mutex_lock(&sdata->local->mtx);
1855 if (sdata->wdev.cac_started) {
1856 ieee80211_vif_release_channel(sdata);
1857 cfg80211_cac_event(sdata->dev, &chandef,
1858 NL80211_RADAR_CAC_FINISHED,
1861 mutex_unlock(&sdata->local->mtx);
1865 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1867 struct ieee80211_local *local = sdata->local;
1868 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1872 if (local->hw.queues < IEEE80211_NUM_ACS)
1875 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1876 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1878 unsigned long now = jiffies;
1880 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1881 tx_tspec->admitted_time &&
1882 time_after(now, tx_tspec->time_slice_start + HZ)) {
1883 tx_tspec->consumed_tx_time = 0;
1884 tx_tspec->time_slice_start = now;
1886 if (tx_tspec->downgraded)
1888 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1891 switch (tx_tspec->action) {
1892 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1893 /* take the original parameters */
1894 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1896 "failed to set TX queue parameters for queue %d\n",
1898 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1899 tx_tspec->downgraded = false;
1902 case TX_TSPEC_ACTION_DOWNGRADE:
1903 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1904 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1908 /* downgrade next lower non-ACM AC */
1909 for (non_acm_ac = ac + 1;
1910 non_acm_ac < IEEE80211_NUM_ACS;
1912 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1914 /* Usually the loop will result in using BK even if it
1915 * requires admission control, but such a configuration
1916 * makes no sense and we have to transmit somehow - the
1917 * AC selection does the same thing.
1918 * If we started out trying to downgrade from BK, then
1919 * the extra condition here might be needed.
1921 if (non_acm_ac >= IEEE80211_NUM_ACS)
1922 non_acm_ac = IEEE80211_AC_BK;
1923 if (drv_conf_tx(local, sdata, ac,
1924 &sdata->tx_conf[non_acm_ac]))
1926 "failed to set TX queue parameters for queue %d\n",
1928 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1930 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1931 tx_tspec->time_slice_start + HZ - now + 1);
1933 case TX_TSPEC_ACTION_NONE:
1942 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1944 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1945 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1948 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1950 struct ieee80211_sub_if_data *sdata;
1952 sdata = container_of(work, struct ieee80211_sub_if_data,
1953 u.mgd.tx_tspec_wk.work);
1954 ieee80211_sta_handle_tspec_ac_params(sdata);
1959 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1960 struct ieee80211_sub_if_data *sdata,
1961 const u8 *wmm_param, size_t wmm_param_len,
1962 const struct ieee80211_mu_edca_param_set *mu_edca)
1964 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1965 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1967 int count, mu_edca_count, ac;
1969 u8 uapsd_queues = 0;
1971 if (!local->ops->conf_tx)
1974 if (local->hw.queues < IEEE80211_NUM_ACS)
1980 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1983 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1984 uapsd_queues = ifmgd->uapsd_queues;
1986 count = wmm_param[6] & 0x0f;
1987 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1988 * if mu_edca was preset before and now it disappeared tell
1989 * the driver about it.
1991 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1992 if (count == ifmgd->wmm_last_param_set &&
1993 mu_edca_count == ifmgd->mu_edca_last_param_set)
1995 ifmgd->wmm_last_param_set = count;
1996 ifmgd->mu_edca_last_param_set = mu_edca_count;
1998 pos = wmm_param + 8;
1999 left = wmm_param_len - 8;
2001 memset(¶ms, 0, sizeof(params));
2004 for (; left >= 4; left -= 4, pos += 4) {
2005 int aci = (pos[0] >> 5) & 0x03;
2006 int acm = (pos[0] >> 4) & 0x01;
2011 ac = IEEE80211_AC_BK;
2013 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2014 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2016 params[ac].mu_edca = !!mu_edca;
2018 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2021 ac = IEEE80211_AC_VI;
2023 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2024 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2026 params[ac].mu_edca = !!mu_edca;
2028 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2031 ac = IEEE80211_AC_VO;
2033 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2034 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2036 params[ac].mu_edca = !!mu_edca;
2038 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2042 ac = IEEE80211_AC_BE;
2044 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2045 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2047 params[ac].mu_edca = !!mu_edca;
2049 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2053 params[ac].aifs = pos[0] & 0x0f;
2055 if (params[ac].aifs < 2) {
2057 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2058 params[ac].aifs, aci);
2059 params[ac].aifs = 2;
2061 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2062 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2063 params[ac].txop = get_unaligned_le16(pos + 2);
2064 params[ac].acm = acm;
2065 params[ac].uapsd = uapsd;
2067 if (params[ac].cw_min == 0 ||
2068 params[ac].cw_min > params[ac].cw_max) {
2070 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2071 params[ac].cw_min, params[ac].cw_max, aci);
2074 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2077 /* WMM specification requires all 4 ACIs. */
2078 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2079 if (params[ac].cw_min == 0) {
2081 "AP has invalid WMM params (missing AC %d), using defaults\n",
2087 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2089 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2091 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2092 params[ac].txop, params[ac].uapsd,
2093 ifmgd->tx_tspec[ac].downgraded);
2094 sdata->tx_conf[ac] = params[ac];
2095 if (!ifmgd->tx_tspec[ac].downgraded &&
2096 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2098 "failed to set TX queue parameters for AC %d\n",
2102 /* enable WMM or activate new settings */
2103 sdata->vif.bss_conf.qos = true;
2107 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2109 lockdep_assert_held(&sdata->local->mtx);
2111 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2112 ieee80211_run_deferred_scan(sdata->local);
2115 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2117 mutex_lock(&sdata->local->mtx);
2118 __ieee80211_stop_poll(sdata);
2119 mutex_unlock(&sdata->local->mtx);
2122 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2123 u16 capab, bool erp_valid, u8 erp)
2125 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2126 struct ieee80211_supported_band *sband;
2128 bool use_protection;
2129 bool use_short_preamble;
2130 bool use_short_slot;
2132 sband = ieee80211_get_sband(sdata);
2137 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2138 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2140 use_protection = false;
2141 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2144 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2145 if (sband->band == NL80211_BAND_5GHZ ||
2146 sband->band == NL80211_BAND_6GHZ)
2147 use_short_slot = true;
2149 if (use_protection != bss_conf->use_cts_prot) {
2150 bss_conf->use_cts_prot = use_protection;
2151 changed |= BSS_CHANGED_ERP_CTS_PROT;
2154 if (use_short_preamble != bss_conf->use_short_preamble) {
2155 bss_conf->use_short_preamble = use_short_preamble;
2156 changed |= BSS_CHANGED_ERP_PREAMBLE;
2159 if (use_short_slot != bss_conf->use_short_slot) {
2160 bss_conf->use_short_slot = use_short_slot;
2161 changed |= BSS_CHANGED_ERP_SLOT;
2167 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2168 struct cfg80211_bss *cbss,
2169 u32 bss_info_changed)
2171 struct ieee80211_bss *bss = (void *)cbss->priv;
2172 struct ieee80211_local *local = sdata->local;
2173 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2175 bss_info_changed |= BSS_CHANGED_ASSOC;
2176 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2177 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2179 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2180 beacon_loss_count * bss_conf->beacon_int));
2182 sdata->u.mgd.associated = cbss;
2183 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2185 ieee80211_check_rate_mask(sdata);
2187 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2189 if (sdata->vif.p2p ||
2190 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2191 const struct cfg80211_bss_ies *ies;
2194 ies = rcu_dereference(cbss->ies);
2198 ret = cfg80211_get_p2p_attr(
2199 ies->data, ies->len,
2200 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2201 (u8 *) &bss_conf->p2p_noa_attr,
2202 sizeof(bss_conf->p2p_noa_attr));
2204 sdata->u.mgd.p2p_noa_index =
2205 bss_conf->p2p_noa_attr.index;
2206 bss_info_changed |= BSS_CHANGED_P2P_PS;
2212 /* just to be sure */
2213 ieee80211_stop_poll(sdata);
2215 ieee80211_led_assoc(local, 1);
2217 if (sdata->u.mgd.have_beacon) {
2219 * If the AP is buggy we may get here with no DTIM period
2220 * known, so assume it's 1 which is the only safe assumption
2221 * in that case, although if the TIM IE is broken powersave
2222 * probably just won't work at all.
2224 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2225 bss_conf->beacon_rate = bss->beacon_rate;
2226 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2228 bss_conf->beacon_rate = NULL;
2229 bss_conf->dtim_period = 0;
2232 bss_conf->assoc = 1;
2234 /* Tell the driver to monitor connection quality (if supported) */
2235 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2236 bss_conf->cqm_rssi_thold)
2237 bss_info_changed |= BSS_CHANGED_CQM;
2239 /* Enable ARP filtering */
2240 if (bss_conf->arp_addr_cnt)
2241 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2243 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2245 mutex_lock(&local->iflist_mtx);
2246 ieee80211_recalc_ps(local);
2247 mutex_unlock(&local->iflist_mtx);
2249 ieee80211_recalc_smps(sdata);
2250 ieee80211_recalc_ps_vif(sdata);
2252 netif_carrier_on(sdata->dev);
2255 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2256 u16 stype, u16 reason, bool tx,
2259 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2260 struct ieee80211_local *local = sdata->local;
2262 struct ieee80211_prep_tx_info info = {
2266 sdata_assert_lock(sdata);
2268 if (WARN_ON_ONCE(tx && !frame_buf))
2271 if (WARN_ON(!ifmgd->associated))
2274 ieee80211_stop_poll(sdata);
2276 ifmgd->associated = NULL;
2277 netif_carrier_off(sdata->dev);
2280 * if we want to get out of ps before disassoc (why?) we have
2281 * to do it before sending disassoc, as otherwise the null-packet
2284 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2285 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2286 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2288 local->ps_sdata = NULL;
2290 /* disable per-vif ps */
2291 ieee80211_recalc_ps_vif(sdata);
2293 /* make sure ongoing transmission finishes */
2297 * drop any frame before deauth/disassoc, this can be data or
2298 * management frame. Since we are disconnecting, we should not
2299 * insist sending these frames which can take time and delay
2300 * the disconnection and possible the roaming.
2303 ieee80211_flush_queues(local, sdata, true);
2305 /* deauthenticate/disassociate now */
2306 if (tx || frame_buf) {
2308 * In multi channel scenarios guarantee that the virtual
2309 * interface is granted immediate airtime to transmit the
2310 * deauthentication frame by calling mgd_prepare_tx, if the
2311 * driver requested so.
2313 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2314 !ifmgd->have_beacon) {
2315 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2318 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2319 ifmgd->bssid, stype, reason,
2323 /* flush out frame - make sure the deauth was actually sent */
2325 ieee80211_flush_queues(local, sdata, false);
2327 drv_mgd_complete_tx(sdata->local, sdata, &info);
2329 /* clear bssid only after building the needed mgmt frames */
2330 eth_zero_addr(ifmgd->bssid);
2332 sdata->vif.bss_conf.ssid_len = 0;
2334 /* remove AP and TDLS peers */
2335 sta_info_flush(sdata);
2337 /* finally reset all BSS / config parameters */
2338 changed |= ieee80211_reset_erp_info(sdata);
2340 ieee80211_led_assoc(local, 0);
2341 changed |= BSS_CHANGED_ASSOC;
2342 sdata->vif.bss_conf.assoc = false;
2344 ifmgd->p2p_noa_index = -1;
2345 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2346 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2348 /* on the next assoc, re-program HT/VHT parameters */
2349 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2350 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2351 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2352 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2354 /* reset MU-MIMO ownership and group data */
2355 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2356 sizeof(sdata->vif.bss_conf.mu_group.membership));
2357 memset(sdata->vif.bss_conf.mu_group.position, 0,
2358 sizeof(sdata->vif.bss_conf.mu_group.position));
2359 changed |= BSS_CHANGED_MU_GROUPS;
2360 sdata->vif.mu_mimo_owner = false;
2362 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2364 del_timer_sync(&local->dynamic_ps_timer);
2365 cancel_work_sync(&local->dynamic_ps_enable_work);
2367 /* Disable ARP filtering */
2368 if (sdata->vif.bss_conf.arp_addr_cnt)
2369 changed |= BSS_CHANGED_ARP_FILTER;
2371 sdata->vif.bss_conf.qos = false;
2372 changed |= BSS_CHANGED_QOS;
2374 /* The BSSID (not really interesting) and HT changed */
2375 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2376 ieee80211_bss_info_change_notify(sdata, changed);
2378 /* disassociated - set to defaults now */
2379 ieee80211_set_wmm_default(sdata, false, false);
2381 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2382 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2383 del_timer_sync(&sdata->u.mgd.timer);
2384 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2386 sdata->vif.bss_conf.dtim_period = 0;
2387 sdata->vif.bss_conf.beacon_rate = NULL;
2389 ifmgd->have_beacon = false;
2392 mutex_lock(&local->mtx);
2393 ieee80211_vif_release_channel(sdata);
2395 sdata->vif.csa_active = false;
2396 ifmgd->csa_waiting_bcn = false;
2397 ifmgd->csa_ignored_same_chan = false;
2398 if (sdata->csa_block_tx) {
2399 ieee80211_wake_vif_queues(local, sdata,
2400 IEEE80211_QUEUE_STOP_REASON_CSA);
2401 sdata->csa_block_tx = false;
2403 mutex_unlock(&local->mtx);
2405 /* existing TX TSPEC sessions no longer exist */
2406 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2407 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2409 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2412 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2414 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2415 struct ieee80211_local *local = sdata->local;
2417 mutex_lock(&local->mtx);
2418 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2421 __ieee80211_stop_poll(sdata);
2423 mutex_lock(&local->iflist_mtx);
2424 ieee80211_recalc_ps(local);
2425 mutex_unlock(&local->iflist_mtx);
2427 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2431 * We've received a probe response, but are not sure whether
2432 * we have or will be receiving any beacons or data, so let's
2433 * schedule the timers again, just in case.
2435 ieee80211_sta_reset_beacon_monitor(sdata);
2437 mod_timer(&ifmgd->conn_mon_timer,
2438 round_jiffies_up(jiffies +
2439 IEEE80211_CONNECTION_IDLE_TIME));
2441 mutex_unlock(&local->mtx);
2444 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2445 struct ieee80211_hdr *hdr,
2448 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2449 u16 tid = ieee80211_get_tid(hdr);
2450 int ac = ieee80211_ac_from_tid(tid);
2451 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2452 unsigned long now = jiffies;
2454 if (likely(!tx_tspec->admitted_time))
2457 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2458 tx_tspec->consumed_tx_time = 0;
2459 tx_tspec->time_slice_start = now;
2461 if (tx_tspec->downgraded) {
2462 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2463 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2467 if (tx_tspec->downgraded)
2470 tx_tspec->consumed_tx_time += tx_time;
2472 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2473 tx_tspec->downgraded = true;
2474 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2475 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2479 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2480 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2482 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2484 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2485 !sdata->u.mgd.probe_send_count)
2489 sdata->u.mgd.probe_send_count = 0;
2491 sdata->u.mgd.nullfunc_failed = true;
2492 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2495 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2496 const u8 *src, const u8 *dst,
2497 const u8 *ssid, size_t ssid_len,
2498 struct ieee80211_channel *channel)
2500 struct sk_buff *skb;
2502 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2503 ssid, ssid_len, NULL, 0,
2504 IEEE80211_PROBE_FLAG_DIRECTED);
2506 ieee80211_tx_skb(sdata, skb);
2509 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2511 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2513 u8 *dst = ifmgd->associated->bssid;
2514 u8 unicast_limit = max(1, max_probe_tries - 3);
2515 struct sta_info *sta;
2518 * Try sending broadcast probe requests for the last three
2519 * probe requests after the first ones failed since some
2520 * buggy APs only support broadcast probe requests.
2522 if (ifmgd->probe_send_count >= unicast_limit)
2526 * When the hardware reports an accurate Tx ACK status, it's
2527 * better to send a nullfunc frame instead of a probe request,
2528 * as it will kick us off the AP quickly if we aren't associated
2529 * anymore. The timeout will be reset if the frame is ACKed by
2532 ifmgd->probe_send_count++;
2535 mutex_lock(&sdata->local->sta_mtx);
2536 sta = sta_info_get(sdata, dst);
2538 ieee80211_check_fast_rx(sta);
2539 mutex_unlock(&sdata->local->sta_mtx);
2542 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2543 ifmgd->nullfunc_failed = false;
2544 ieee80211_send_nullfunc(sdata->local, sdata, false);
2549 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
2550 if (WARN_ON_ONCE(ssid == NULL))
2555 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2557 ifmgd->associated->channel);
2561 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2562 run_again(sdata, ifmgd->probe_timeout);
2565 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2568 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2569 bool already = false;
2571 if (!ieee80211_sdata_running(sdata))
2576 if (!ifmgd->associated)
2579 mutex_lock(&sdata->local->mtx);
2581 if (sdata->local->tmp_channel || sdata->local->scanning) {
2582 mutex_unlock(&sdata->local->mtx);
2587 mlme_dbg_ratelimited(sdata,
2588 "detected beacon loss from AP (missed %d beacons) - probing\n",
2591 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2595 * The driver/our work has already reported this event or the
2596 * connection monitoring has kicked in and we have already sent
2597 * a probe request. Or maybe the AP died and the driver keeps
2598 * reporting until we disassociate...
2600 * In either case we have to ignore the current call to this
2601 * function (except for setting the correct probe reason bit)
2602 * because otherwise we would reset the timer every time and
2603 * never check whether we received a probe response!
2605 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2608 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2610 mutex_unlock(&sdata->local->mtx);
2615 mutex_lock(&sdata->local->iflist_mtx);
2616 ieee80211_recalc_ps(sdata->local);
2617 mutex_unlock(&sdata->local->iflist_mtx);
2619 ifmgd->probe_send_count = 0;
2620 ieee80211_mgd_probe_ap_send(sdata);
2622 sdata_unlock(sdata);
2625 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2626 struct ieee80211_vif *vif)
2628 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2629 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2630 struct cfg80211_bss *cbss;
2631 struct sk_buff *skb;
2635 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2638 sdata_assert_lock(sdata);
2640 if (ifmgd->associated)
2641 cbss = ifmgd->associated;
2642 else if (ifmgd->auth_data)
2643 cbss = ifmgd->auth_data->bss;
2644 else if (ifmgd->assoc_data)
2645 cbss = ifmgd->assoc_data->bss;
2650 ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
2651 if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
2652 "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
2657 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2658 (u32) -1, cbss->channel,
2660 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2665 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2667 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2668 const u8 *buf, size_t len, bool tx,
2669 u16 reason, bool reconnect)
2671 struct ieee80211_event event = {
2673 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2674 .u.mlme.reason = reason,
2678 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2680 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2682 drv_event_callback(sdata->local, sdata, &event);
2685 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2687 struct ieee80211_local *local = sdata->local;
2688 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2689 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2693 if (!ifmgd->associated) {
2694 sdata_unlock(sdata);
2698 tx = !sdata->csa_block_tx;
2700 if (!ifmgd->driver_disconnect) {
2702 * AP is probably out of range (or not reachable for another
2703 * reason) so remove the bss struct for that AP.
2705 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2708 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2709 ifmgd->driver_disconnect ?
2710 WLAN_REASON_DEAUTH_LEAVING :
2711 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2713 mutex_lock(&local->mtx);
2714 sdata->vif.csa_active = false;
2715 ifmgd->csa_waiting_bcn = false;
2716 if (sdata->csa_block_tx) {
2717 ieee80211_wake_vif_queues(local, sdata,
2718 IEEE80211_QUEUE_STOP_REASON_CSA);
2719 sdata->csa_block_tx = false;
2721 mutex_unlock(&local->mtx);
2723 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2724 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2726 ifmgd->reconnect = false;
2728 sdata_unlock(sdata);
2731 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2733 struct ieee80211_sub_if_data *sdata =
2734 container_of(work, struct ieee80211_sub_if_data,
2735 u.mgd.beacon_connection_loss_work);
2736 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2738 if (ifmgd->associated)
2739 ifmgd->beacon_loss_count++;
2741 if (ifmgd->connection_loss) {
2742 sdata_info(sdata, "Connection to AP %pM lost\n",
2744 __ieee80211_disconnect(sdata);
2745 ifmgd->connection_loss = false;
2746 } else if (ifmgd->driver_disconnect) {
2748 "Driver requested disconnection from AP %pM\n",
2750 __ieee80211_disconnect(sdata);
2751 ifmgd->driver_disconnect = false;
2753 ieee80211_mgd_probe_ap(sdata, true);
2757 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2759 struct ieee80211_sub_if_data *sdata =
2760 container_of(work, struct ieee80211_sub_if_data,
2761 u.mgd.csa_connection_drop_work);
2763 __ieee80211_disconnect(sdata);
2766 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2768 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2769 struct ieee80211_hw *hw = &sdata->local->hw;
2771 trace_api_beacon_loss(sdata);
2773 sdata->u.mgd.connection_loss = false;
2774 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2776 EXPORT_SYMBOL(ieee80211_beacon_loss);
2778 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2780 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2781 struct ieee80211_hw *hw = &sdata->local->hw;
2783 trace_api_connection_loss(sdata);
2785 sdata->u.mgd.connection_loss = true;
2786 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2788 EXPORT_SYMBOL(ieee80211_connection_loss);
2790 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2792 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2793 struct ieee80211_hw *hw = &sdata->local->hw;
2795 trace_api_disconnect(sdata, reconnect);
2797 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2800 sdata->u.mgd.driver_disconnect = true;
2801 sdata->u.mgd.reconnect = reconnect;
2802 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2804 EXPORT_SYMBOL(ieee80211_disconnect);
2806 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2809 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2811 sdata_assert_lock(sdata);
2815 * we are not authenticated yet, the only timer that could be
2816 * running is the timeout for the authentication response which
2817 * which is not relevant anymore.
2819 del_timer_sync(&sdata->u.mgd.timer);
2820 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2822 eth_zero_addr(sdata->u.mgd.bssid);
2823 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2824 sdata->u.mgd.flags = 0;
2825 mutex_lock(&sdata->local->mtx);
2826 ieee80211_vif_release_channel(sdata);
2827 mutex_unlock(&sdata->local->mtx);
2830 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2832 sdata->u.mgd.auth_data = NULL;
2835 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2836 bool assoc, bool abandon)
2838 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2840 sdata_assert_lock(sdata);
2844 * we are not associated yet, the only timer that could be
2845 * running is the timeout for the association response which
2846 * which is not relevant anymore.
2848 del_timer_sync(&sdata->u.mgd.timer);
2849 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2851 eth_zero_addr(sdata->u.mgd.bssid);
2852 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2853 sdata->u.mgd.flags = 0;
2854 sdata->vif.mu_mimo_owner = false;
2856 mutex_lock(&sdata->local->mtx);
2857 ieee80211_vif_release_channel(sdata);
2858 mutex_unlock(&sdata->local->mtx);
2861 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2865 sdata->u.mgd.assoc_data = NULL;
2868 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2869 struct ieee80211_mgmt *mgmt, size_t len)
2871 struct ieee80211_local *local = sdata->local;
2872 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2874 struct ieee802_11_elems elems;
2876 struct ieee80211_prep_tx_info info = {
2877 .subtype = IEEE80211_STYPE_AUTH,
2880 pos = mgmt->u.auth.variable;
2881 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
2882 mgmt->bssid, auth_data->bss->bssid);
2883 if (!elems.challenge)
2885 auth_data->expected_transaction = 4;
2886 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2887 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2888 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2889 IEEE80211_TX_INTFL_MLME_CONN_TX;
2890 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2891 elems.challenge - 2, elems.challenge_len + 2,
2892 auth_data->bss->bssid, auth_data->bss->bssid,
2893 auth_data->key, auth_data->key_len,
2894 auth_data->key_idx, tx_flags);
2897 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2900 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2901 struct sta_info *sta;
2904 sdata_info(sdata, "authenticated\n");
2905 ifmgd->auth_data->done = true;
2906 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2907 ifmgd->auth_data->timeout_started = true;
2908 run_again(sdata, ifmgd->auth_data->timeout);
2910 /* move station state to auth */
2911 mutex_lock(&sdata->local->sta_mtx);
2912 sta = sta_info_get(sdata, bssid);
2914 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2918 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2919 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2925 mutex_unlock(&sdata->local->sta_mtx);
2929 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2930 struct ieee80211_mgmt *mgmt, size_t len)
2932 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2934 u16 auth_alg, auth_transaction, status_code;
2935 struct ieee80211_event event = {
2937 .u.mlme.data = AUTH_EVENT,
2939 struct ieee80211_prep_tx_info info = {
2940 .subtype = IEEE80211_STYPE_AUTH,
2943 sdata_assert_lock(sdata);
2948 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2951 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2953 if (!ether_addr_equal(bssid, mgmt->bssid))
2956 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2957 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2958 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2960 if (auth_alg != ifmgd->auth_data->algorithm ||
2961 (auth_alg != WLAN_AUTH_SAE &&
2962 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2963 (auth_alg == WLAN_AUTH_SAE &&
2964 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2965 auth_transaction > 2))) {
2966 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2967 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2969 ifmgd->auth_data->expected_transaction);
2973 if (status_code != WLAN_STATUS_SUCCESS) {
2974 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2976 if (auth_alg == WLAN_AUTH_SAE &&
2977 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
2978 (auth_transaction == 1 &&
2979 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
2980 status_code == WLAN_STATUS_SAE_PK))))
2983 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2984 mgmt->sa, status_code);
2985 ieee80211_destroy_auth_data(sdata, false);
2986 event.u.mlme.status = MLME_DENIED;
2987 event.u.mlme.reason = status_code;
2988 drv_event_callback(sdata->local, sdata, &event);
2992 switch (ifmgd->auth_data->algorithm) {
2993 case WLAN_AUTH_OPEN:
2994 case WLAN_AUTH_LEAP:
2997 case WLAN_AUTH_FILS_SK:
2998 case WLAN_AUTH_FILS_SK_PFS:
2999 case WLAN_AUTH_FILS_PK:
3001 case WLAN_AUTH_SHARED_KEY:
3002 if (ifmgd->auth_data->expected_transaction != 4) {
3003 ieee80211_auth_challenge(sdata, mgmt, len);
3004 /* need another frame */
3009 WARN_ONCE(1, "invalid auth alg %d",
3010 ifmgd->auth_data->algorithm);
3014 event.u.mlme.status = MLME_SUCCESS;
3016 drv_event_callback(sdata->local, sdata, &event);
3017 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3018 (auth_transaction == 2 &&
3019 ifmgd->auth_data->expected_transaction == 2)) {
3020 if (!ieee80211_mark_sta_auth(sdata, bssid))
3021 return; /* ignore frame -- wait for timeout */
3022 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3023 auth_transaction == 2) {
3024 sdata_info(sdata, "SAE peer confirmed\n");
3025 ifmgd->auth_data->peer_confirmed = true;
3028 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3030 drv_mgd_complete_tx(sdata->local, sdata, &info);
3033 #define case_WLAN(type) \
3034 case WLAN_REASON_##type: return #type
3036 const char *ieee80211_get_reason_code_string(u16 reason_code)
3038 switch (reason_code) {
3039 case_WLAN(UNSPECIFIED);
3040 case_WLAN(PREV_AUTH_NOT_VALID);
3041 case_WLAN(DEAUTH_LEAVING);
3042 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3043 case_WLAN(DISASSOC_AP_BUSY);
3044 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3045 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3046 case_WLAN(DISASSOC_STA_HAS_LEFT);
3047 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3048 case_WLAN(DISASSOC_BAD_POWER);
3049 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3050 case_WLAN(INVALID_IE);
3051 case_WLAN(MIC_FAILURE);
3052 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3053 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3054 case_WLAN(IE_DIFFERENT);
3055 case_WLAN(INVALID_GROUP_CIPHER);
3056 case_WLAN(INVALID_PAIRWISE_CIPHER);
3057 case_WLAN(INVALID_AKMP);
3058 case_WLAN(UNSUPP_RSN_VERSION);
3059 case_WLAN(INVALID_RSN_IE_CAP);
3060 case_WLAN(IEEE8021X_FAILED);
3061 case_WLAN(CIPHER_SUITE_REJECTED);
3062 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3063 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3064 case_WLAN(DISASSOC_LOW_ACK);
3065 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3066 case_WLAN(QSTA_LEAVE_QBSS);
3067 case_WLAN(QSTA_NOT_USE);
3068 case_WLAN(QSTA_REQUIRE_SETUP);
3069 case_WLAN(QSTA_TIMEOUT);
3070 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3071 case_WLAN(MESH_PEER_CANCELED);
3072 case_WLAN(MESH_MAX_PEERS);
3073 case_WLAN(MESH_CONFIG);
3074 case_WLAN(MESH_CLOSE);
3075 case_WLAN(MESH_MAX_RETRIES);
3076 case_WLAN(MESH_CONFIRM_TIMEOUT);
3077 case_WLAN(MESH_INVALID_GTK);
3078 case_WLAN(MESH_INCONSISTENT_PARAM);
3079 case_WLAN(MESH_INVALID_SECURITY);
3080 case_WLAN(MESH_PATH_ERROR);
3081 case_WLAN(MESH_PATH_NOFORWARD);
3082 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3083 case_WLAN(MAC_EXISTS_IN_MBSS);
3084 case_WLAN(MESH_CHAN_REGULATORY);
3085 case_WLAN(MESH_CHAN);
3086 default: return "<unknown>";
3090 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3091 struct ieee80211_mgmt *mgmt, size_t len)
3093 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3094 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3096 sdata_assert_lock(sdata);
3101 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3102 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3106 if (ifmgd->associated &&
3107 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3108 const u8 *bssid = ifmgd->associated->bssid;
3110 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3112 ieee80211_get_reason_code_string(reason_code));
3114 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3116 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3117 reason_code, false);
3121 if (ifmgd->assoc_data &&
3122 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3123 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3126 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3128 ieee80211_get_reason_code_string(reason_code));
3130 ieee80211_destroy_assoc_data(sdata, false, true);
3132 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3138 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3139 struct ieee80211_mgmt *mgmt, size_t len)
3141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3144 sdata_assert_lock(sdata);
3149 if (!ifmgd->associated ||
3150 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3153 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3155 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3156 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3160 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3161 mgmt->sa, reason_code,
3162 ieee80211_get_reason_code_string(reason_code));
3164 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3166 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3170 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3171 u8 *supp_rates, unsigned int supp_rates_len,
3172 u32 *rates, u32 *basic_rates,
3173 bool *have_higher_than_11mbit,
3174 int *min_rate, int *min_rate_index,
3179 for (i = 0; i < supp_rates_len; i++) {
3180 int rate = supp_rates[i] & 0x7f;
3181 bool is_basic = !!(supp_rates[i] & 0x80);
3183 if ((rate * 5 * (1 << shift)) > 110)
3184 *have_higher_than_11mbit = true;
3187 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3188 * since they're not rates.
3190 * Note: Even though the membership selector and the basic
3191 * rate flag share the same bit, they are not exactly
3194 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3195 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3196 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3197 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3200 for (j = 0; j < sband->n_bitrates; j++) {
3201 struct ieee80211_rate *br;
3204 br = &sband->bitrates[j];
3206 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3207 if (brate == rate) {
3210 *basic_rates |= BIT(j);
3211 if ((rate * 5) < *min_rate) {
3212 *min_rate = rate * 5;
3213 *min_rate_index = j;
3221 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3222 const struct ieee802_11_elems *elems)
3224 if (elems->ext_capab_len < 10)
3227 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3230 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3231 IEEE80211_HE_MAC_CAP0_TWT_RES;
3234 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3235 struct sta_info *sta,
3236 struct ieee802_11_elems *elems)
3238 bool twt = ieee80211_twt_req_supported(sta, elems);
3240 if (sdata->vif.bss_conf.twt_requester != twt) {
3241 sdata->vif.bss_conf.twt_requester = twt;
3242 return BSS_CHANGED_TWT;
3247 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3248 struct ieee80211_bss_conf *bss_conf,
3249 struct ieee80211_supported_band *sband,
3250 struct sta_info *sta)
3252 const struct ieee80211_sta_he_cap *own_he_cap =
3253 ieee80211_get_he_iftype_cap(sband,
3254 ieee80211_vif_type_p2p(&sdata->vif));
3256 return bss_conf->he_support &&
3257 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3258 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3260 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3261 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3264 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3265 struct cfg80211_bss *cbss,
3266 struct ieee80211_mgmt *mgmt, size_t len,
3267 struct ieee802_11_elems *elems)
3269 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3270 struct ieee80211_local *local = sdata->local;
3271 struct ieee80211_supported_band *sband;
3272 struct sta_info *sta;
3273 u16 capab_info, aid;
3274 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3275 const struct cfg80211_bss_ies *bss_ies = NULL;
3276 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3277 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3278 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3284 /* AssocResp and ReassocResp have identical structure */
3286 pos = mgmt->u.assoc_resp.variable;
3287 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3289 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3292 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3293 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, elems,
3294 mgmt->bssid, assoc_data->bss->bssid);
3296 if (elems->aid_resp)
3297 aid = le16_to_cpu(elems->aid_resp->aid);
3300 * The 5 MSB of the AID field are reserved
3301 * (802.11-2016 9.4.1.8 AID field)
3305 ifmgd->broken_ap = false;
3307 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3308 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3311 ifmgd->broken_ap = true;
3314 if (!is_s1g && !elems->supp_rates) {
3315 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3319 sdata->vif.bss_conf.aid = aid;
3320 ifmgd->tdls_chan_switch_prohibited =
3321 elems->ext_capab && elems->ext_capab_len >= 5 &&
3322 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3325 * Some APs are erroneously not including some information in their
3326 * (re)association response frames. Try to recover by using the data
3327 * from the beacon or probe response. This seems to afflict mobile
3328 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3329 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3332 ((assoc_data->wmm && !elems->wmm_param) ||
3333 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3334 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3335 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3336 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3337 const struct cfg80211_bss_ies *ies;
3338 struct ieee802_11_elems bss_elems;
3341 ies = rcu_dereference(cbss->ies);
3343 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3349 ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3352 assoc_data->bss->bssid);
3353 if (assoc_data->wmm &&
3354 !elems->wmm_param && bss_elems.wmm_param) {
3355 elems->wmm_param = bss_elems.wmm_param;
3357 "AP bug: WMM param missing from AssocResp\n");
3361 * Also check if we requested HT/VHT, otherwise the AP doesn't
3362 * have to include the IEs in the (re)association response.
3364 if (!elems->ht_cap_elem && bss_elems.ht_cap_elem &&
3365 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3366 elems->ht_cap_elem = bss_elems.ht_cap_elem;
3368 "AP bug: HT capability missing from AssocResp\n");
3370 if (!elems->ht_operation && bss_elems.ht_operation &&
3371 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3372 elems->ht_operation = bss_elems.ht_operation;
3374 "AP bug: HT operation missing from AssocResp\n");
3376 if (!elems->vht_cap_elem && bss_elems.vht_cap_elem &&
3377 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3378 elems->vht_cap_elem = bss_elems.vht_cap_elem;
3380 "AP bug: VHT capa missing from AssocResp\n");
3382 if (!elems->vht_operation && bss_elems.vht_operation &&
3383 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3384 elems->vht_operation = bss_elems.vht_operation;
3386 "AP bug: VHT operation missing from AssocResp\n");
3391 * We previously checked these in the beacon/probe response, so
3392 * they should be present here. This is just a safety net.
3394 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3395 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3397 "HT AP is missing WMM params or HT capability/operation\n");
3402 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3403 (!elems->vht_cap_elem || !elems->vht_operation)) {
3405 "VHT AP is missing VHT capability/operation\n");
3410 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3411 !elems->he_6ghz_capa) {
3413 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3418 mutex_lock(&sdata->local->sta_mtx);
3420 * station info was already allocated and inserted before
3421 * the association and should be available to us
3423 sta = sta_info_get(sdata, cbss->bssid);
3424 if (WARN_ON(!sta)) {
3425 mutex_unlock(&sdata->local->sta_mtx);
3430 sband = ieee80211_get_sband(sdata);
3432 mutex_unlock(&sdata->local->sta_mtx);
3437 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3438 (!elems->he_cap || !elems->he_operation)) {
3439 mutex_unlock(&sdata->local->sta_mtx);
3441 "HE AP is missing HE capability/operation\n");
3446 /* Set up internal HT/VHT capabilities */
3447 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3448 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3449 elems->ht_cap_elem, sta);
3451 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3452 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3453 elems->vht_cap_elem, sta);
3455 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3457 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3460 elems->he_6ghz_capa,
3463 bss_conf->he_support = sta->sta.he_cap.has_he;
3464 if (elems->rsnx && elems->rsnx_len &&
3465 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3466 wiphy_ext_feature_isset(local->hw.wiphy,
3467 NL80211_EXT_FEATURE_PROTECTED_TWT))
3468 bss_conf->twt_protected = true;
3470 bss_conf->twt_protected = false;
3472 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3474 bss_conf->he_support = false;
3475 bss_conf->twt_requester = false;
3476 bss_conf->twt_protected = false;
3479 bss_conf->twt_broadcast =
3480 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3482 if (bss_conf->he_support) {
3483 bss_conf->he_bss_color.color =
3484 le32_get_bits(elems->he_operation->he_oper_params,
3485 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3486 bss_conf->he_bss_color.partial =
3487 le32_get_bits(elems->he_operation->he_oper_params,
3488 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3489 bss_conf->he_bss_color.enabled =
3490 !le32_get_bits(elems->he_operation->he_oper_params,
3491 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3493 if (bss_conf->he_bss_color.enabled)
3494 changed |= BSS_CHANGED_HE_BSS_COLOR;
3496 bss_conf->htc_trig_based_pkt_ext =
3497 le32_get_bits(elems->he_operation->he_oper_params,
3498 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3499 bss_conf->frame_time_rts_th =
3500 le32_get_bits(elems->he_operation->he_oper_params,
3501 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3503 bss_conf->uora_exists = !!elems->uora_element;
3504 if (elems->uora_element)
3505 bss_conf->uora_ocw_range = elems->uora_element[0];
3507 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3508 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3509 /* TODO: OPEN: what happens if BSS color disable is set? */
3512 if (cbss->transmitted_bss) {
3513 bss_conf->nontransmitted = true;
3514 ether_addr_copy(bss_conf->transmitter_bssid,
3515 cbss->transmitted_bss->bssid);
3516 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3517 bss_conf->bssid_index = cbss->bssid_index;
3521 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3522 * in their association response, so ignore that data for our own
3523 * configuration. If it changed since the last beacon, we'll get the
3524 * next beacon and update then.
3528 * If an operating mode notification IE is present, override the
3529 * NSS calculation (that would be done in rate_control_rate_init())
3530 * and use the # of streams from that element.
3532 if (elems->opmode_notif &&
3533 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3536 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3537 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3539 sta->sta.rx_nss = nss;
3542 rate_control_rate_init(sta);
3544 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3545 set_sta_flag(sta, WLAN_STA_MFP);
3546 sta->sta.mfp = true;
3548 sta->sta.mfp = false;
3551 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3552 local->hw.queues >= IEEE80211_NUM_ACS;
3554 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3555 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3556 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3559 "failed to move station %pM to desired state\n",
3561 WARN_ON(__sta_info_destroy(sta));
3562 mutex_unlock(&sdata->local->sta_mtx);
3567 if (sdata->wdev.use_4addr)
3568 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3570 mutex_unlock(&sdata->local->sta_mtx);
3573 * Always handle WMM once after association regardless
3574 * of the first value the AP uses. Setting -1 here has
3575 * that effect because the AP values is an unsigned
3578 ifmgd->wmm_last_param_set = -1;
3579 ifmgd->mu_edca_last_param_set = -1;
3581 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3582 ieee80211_set_wmm_default(sdata, false, false);
3583 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3584 elems->wmm_param_len,
3585 elems->mu_edca_param_set)) {
3586 /* still enable QoS since we might have HT/VHT */
3587 ieee80211_set_wmm_default(sdata, false, true);
3588 /* set the disable-WMM flag in this case to disable
3589 * tracking WMM parameter changes in the beacon if
3590 * the parameters weren't actually valid. Doing so
3591 * avoids changing parameters very strangely when
3592 * the AP is going back and forth between valid and
3593 * invalid parameters.
3595 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3597 changed |= BSS_CHANGED_QOS;
3599 if (elems->max_idle_period_ie) {
3600 bss_conf->max_idle_period =
3601 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3602 bss_conf->protected_keep_alive =
3603 !!(elems->max_idle_period_ie->idle_options &
3604 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3605 changed |= BSS_CHANGED_KEEP_ALIVE;
3607 bss_conf->max_idle_period = 0;
3608 bss_conf->protected_keep_alive = false;
3611 /* set assoc capability (AID was already set earlier),
3612 * ieee80211_set_associated() will tell the driver */
3613 bss_conf->assoc_capability = capab_info;
3614 ieee80211_set_associated(sdata, cbss, changed);
3617 * If we're using 4-addr mode, let the AP know that we're
3618 * doing so, so that it can create the STA VLAN on its side
3620 if (ifmgd->use_4addr)
3621 ieee80211_send_4addr_nullfunc(local, sdata);
3624 * Start timer to probe the connection to the AP now.
3625 * Also start the timer that will detect beacon loss.
3627 ieee80211_sta_reset_beacon_monitor(sdata);
3628 ieee80211_sta_reset_conn_monitor(sdata);
3636 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3637 struct ieee80211_mgmt *mgmt,
3640 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3641 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3642 u16 capab_info, status_code, aid;
3643 struct ieee802_11_elems elems;
3644 int ac, uapsd_queues = -1;
3647 struct cfg80211_bss *cbss;
3648 struct ieee80211_event event = {
3650 .u.mlme.data = ASSOC_EVENT,
3652 struct ieee80211_prep_tx_info info = {};
3654 sdata_assert_lock(sdata);
3659 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3662 cbss = assoc_data->bss;
3665 * AssocResp and ReassocResp have identical structure, so process both
3666 * of them in this function.
3672 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3673 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3674 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3675 pos = mgmt->u.assoc_resp.variable;
3676 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3677 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3678 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3683 * Note: this may not be perfect, AP might misbehave - if
3684 * anyone needs to rely on perfect complete notification
3685 * with the exact right subtype, then we need to track what
3686 * we actually transmitted.
3688 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3689 IEEE80211_STYPE_ASSOC_REQ;
3692 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3693 reassoc ? "Rea" : "A", mgmt->sa,
3694 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3696 if (assoc_data->fils_kek_len &&
3697 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3700 ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false, &elems,
3701 mgmt->bssid, assoc_data->bss->bssid);
3703 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3704 elems.timeout_int &&
3705 elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3707 tu = le32_to_cpu(elems.timeout_int->value);
3708 ms = tu * 1024 / 1000;
3710 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3712 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3713 assoc_data->timeout_started = true;
3714 if (ms > IEEE80211_ASSOC_TIMEOUT)
3715 run_again(sdata, assoc_data->timeout);
3719 if (status_code != WLAN_STATUS_SUCCESS) {
3720 sdata_info(sdata, "%pM denied association (code=%d)\n",
3721 mgmt->sa, status_code);
3722 ieee80211_destroy_assoc_data(sdata, false, false);
3723 event.u.mlme.status = MLME_DENIED;
3724 event.u.mlme.reason = status_code;
3725 drv_event_callback(sdata->local, sdata, &event);
3727 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, &elems)) {
3728 /* oops -- internal error -- send timeout for now */
3729 ieee80211_destroy_assoc_data(sdata, false, false);
3730 cfg80211_assoc_timeout(sdata->dev, cbss);
3733 event.u.mlme.status = MLME_SUCCESS;
3734 drv_event_callback(sdata->local, sdata, &event);
3735 sdata_info(sdata, "associated\n");
3738 * destroy assoc_data afterwards, as otherwise an idle
3739 * recalc after assoc_data is NULL but before associated
3740 * is set can cause the interface to go idle
3742 ieee80211_destroy_assoc_data(sdata, true, false);
3744 /* get uapsd queues configuration */
3746 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3747 if (sdata->tx_conf[ac].uapsd)
3748 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3753 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3754 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3756 drv_mgd_complete_tx(sdata->local, sdata, &info);
3759 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3760 struct ieee80211_mgmt *mgmt, size_t len,
3761 struct ieee80211_rx_status *rx_status)
3763 struct ieee80211_local *local = sdata->local;
3764 struct ieee80211_bss *bss;
3765 struct ieee80211_channel *channel;
3767 sdata_assert_lock(sdata);
3769 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3770 ieee80211_rx_status_to_khz(rx_status));
3774 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3776 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3777 ieee80211_rx_bss_put(local, bss);
3782 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3783 struct sk_buff *skb)
3785 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3786 struct ieee80211_if_managed *ifmgd;
3787 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3788 struct ieee80211_channel *channel;
3789 size_t baselen, len = skb->len;
3791 ifmgd = &sdata->u.mgd;
3793 sdata_assert_lock(sdata);
3796 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3797 * "If a 6 GHz AP receives a Probe Request frame and responds with
3798 * a Probe Response frame [..], the Address 1 field of the Probe
3799 * Response frame shall be set to the broadcast address [..]"
3800 * So, on 6GHz band we should also accept broadcast responses.
3802 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3807 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3808 (channel->band != NL80211_BAND_6GHZ ||
3809 !is_broadcast_ether_addr(mgmt->da)))
3810 return; /* ignore ProbeResp to foreign address */
3812 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3816 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3818 if (ifmgd->associated &&
3819 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3820 ieee80211_reset_ap_probe(sdata);
3824 * This is the canonical list of information elements we care about,
3825 * the filter code also gives us all changes to the Microsoft OUI
3826 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3827 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3828 * changes to requested client power.
3830 * We implement beacon filtering in software since that means we can
3831 * avoid processing the frame here and in cfg80211, and userspace
3832 * will not be able to tell whether the hardware supports it or not.
3834 * XXX: This list needs to be dynamic -- userspace needs to be able to
3835 * add items it requires. It also needs to be able to tell us to
3836 * look out for other vendor IEs.
3838 static const u64 care_about_ies =
3839 (1ULL << WLAN_EID_COUNTRY) |
3840 (1ULL << WLAN_EID_ERP_INFO) |
3841 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3842 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3843 (1ULL << WLAN_EID_HT_CAPABILITY) |
3844 (1ULL << WLAN_EID_HT_OPERATION) |
3845 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3847 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3848 struct ieee80211_if_managed *ifmgd,
3849 struct ieee80211_bss_conf *bss_conf,
3850 struct ieee80211_local *local,
3851 struct ieee80211_rx_status *rx_status)
3853 /* Track average RSSI from the Beacon frames of the current AP */
3855 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3856 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3857 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3858 ifmgd->last_cqm_event_signal = 0;
3859 ifmgd->count_beacon_signal = 1;
3860 ifmgd->last_ave_beacon_signal = 0;
3862 ifmgd->count_beacon_signal++;
3865 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3867 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3868 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3869 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3870 int last_sig = ifmgd->last_ave_beacon_signal;
3871 struct ieee80211_event event = {
3876 * if signal crosses either of the boundaries, invoke callback
3877 * with appropriate parameters
3879 if (sig > ifmgd->rssi_max_thold &&
3880 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3881 ifmgd->last_ave_beacon_signal = sig;
3882 event.u.rssi.data = RSSI_EVENT_HIGH;
3883 drv_event_callback(local, sdata, &event);
3884 } else if (sig < ifmgd->rssi_min_thold &&
3885 (last_sig >= ifmgd->rssi_max_thold ||
3887 ifmgd->last_ave_beacon_signal = sig;
3888 event.u.rssi.data = RSSI_EVENT_LOW;
3889 drv_event_callback(local, sdata, &event);
3893 if (bss_conf->cqm_rssi_thold &&
3894 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3895 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3896 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3897 int last_event = ifmgd->last_cqm_event_signal;
3898 int thold = bss_conf->cqm_rssi_thold;
3899 int hyst = bss_conf->cqm_rssi_hyst;
3902 (last_event == 0 || sig < last_event - hyst)) {
3903 ifmgd->last_cqm_event_signal = sig;
3904 ieee80211_cqm_rssi_notify(
3906 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3908 } else if (sig > thold &&
3909 (last_event == 0 || sig > last_event + hyst)) {
3910 ifmgd->last_cqm_event_signal = sig;
3911 ieee80211_cqm_rssi_notify(
3913 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3918 if (bss_conf->cqm_rssi_low &&
3919 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3920 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3921 int last_event = ifmgd->last_cqm_event_signal;
3922 int low = bss_conf->cqm_rssi_low;
3923 int high = bss_conf->cqm_rssi_high;
3926 (last_event == 0 || last_event >= low)) {
3927 ifmgd->last_cqm_event_signal = sig;
3928 ieee80211_cqm_rssi_notify(
3930 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3932 } else if (sig > high &&
3933 (last_event == 0 || last_event <= high)) {
3934 ifmgd->last_cqm_event_signal = sig;
3935 ieee80211_cqm_rssi_notify(
3937 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3943 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3944 struct cfg80211_bss *bss)
3946 if (ether_addr_equal(tx_bssid, bss->bssid))
3948 if (!bss->transmitted_bss)
3950 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3953 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3954 struct ieee80211_hdr *hdr, size_t len,
3955 struct ieee80211_rx_status *rx_status)
3957 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3958 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3959 struct ieee80211_mgmt *mgmt = (void *) hdr;
3961 struct ieee802_11_elems elems;
3962 struct ieee80211_local *local = sdata->local;
3963 struct ieee80211_chanctx_conf *chanctx_conf;
3964 struct ieee80211_channel *chan;
3965 struct sta_info *sta;
3970 u8 *bssid, *variable = mgmt->u.beacon.variable;
3971 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
3973 sdata_assert_lock(sdata);
3975 /* Process beacon from the current BSS */
3976 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
3977 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
3978 struct ieee80211_ext *ext = (void *) mgmt;
3980 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
3981 variable = ext->u.s1g_short_beacon.variable;
3983 variable = ext->u.s1g_beacon.variable;
3986 baselen = (u8 *) variable - (u8 *) mgmt;
3991 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3992 if (!chanctx_conf) {
3997 if (ieee80211_rx_status_to_khz(rx_status) !=
3998 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4002 chan = chanctx_conf->def.chan;
4005 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4006 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4007 ieee802_11_parse_elems(variable,
4008 len - baselen, false, &elems,
4010 ifmgd->assoc_data->bss->bssid);
4012 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4014 if (elems.dtim_period)
4015 ifmgd->dtim_period = elems.dtim_period;
4016 ifmgd->have_beacon = true;
4017 ifmgd->assoc_data->need_beacon = false;
4018 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4019 sdata->vif.bss_conf.sync_tsf =
4020 le64_to_cpu(mgmt->u.beacon.timestamp);
4021 sdata->vif.bss_conf.sync_device_ts =
4022 rx_status->device_timestamp;
4023 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4026 if (elems.mbssid_config_ie)
4027 bss_conf->profile_periodicity =
4028 elems.mbssid_config_ie->profile_periodicity;
4030 bss_conf->profile_periodicity = 0;
4032 if (elems.ext_capab_len >= 11 &&
4033 (elems.ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4034 bss_conf->ema_ap = true;
4036 bss_conf->ema_ap = false;
4038 /* continue assoc process */
4039 ifmgd->assoc_data->timeout = jiffies;
4040 ifmgd->assoc_data->timeout_started = true;
4041 run_again(sdata, ifmgd->assoc_data->timeout);
4045 if (!ifmgd->associated ||
4046 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4048 bssid = ifmgd->associated->bssid;
4050 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4051 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4054 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4055 mlme_dbg_ratelimited(sdata,
4056 "cancelling AP probe due to a received beacon\n");
4057 ieee80211_reset_ap_probe(sdata);
4061 * Push the beacon loss detection into the future since
4062 * we are processing a beacon from the AP just now.
4064 ieee80211_sta_reset_beacon_monitor(sdata);
4066 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4067 * element (which carries the beacon interval). Don't forget to add a
4068 * bit to care_about_ies[] above if mac80211 is interested in a
4069 * changing S1G element.
4071 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4072 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4073 ncrc = ieee802_11_parse_elems_crc(variable,
4074 len - baselen, false, &elems,
4075 care_about_ies, ncrc,
4076 mgmt->bssid, bssid);
4078 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4079 ieee80211_check_tim(elems.tim, elems.tim_len, bss_conf->aid)) {
4080 if (local->hw.conf.dynamic_ps_timeout > 0) {
4081 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4082 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4083 ieee80211_hw_config(local,
4084 IEEE80211_CONF_CHANGE_PS);
4086 ieee80211_send_nullfunc(local, sdata, false);
4087 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4088 local->pspolling = true;
4091 * Here is assumed that the driver will be
4092 * able to send ps-poll frame and receive a
4093 * response even though power save mode is
4094 * enabled, but some drivers might require
4095 * to disable power save here. This needs
4096 * to be investigated.
4098 ieee80211_send_pspoll(local, sdata);
4102 if (sdata->vif.p2p ||
4103 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4104 struct ieee80211_p2p_noa_attr noa = {};
4107 ret = cfg80211_get_p2p_attr(variable,
4109 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4110 (u8 *) &noa, sizeof(noa));
4112 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4113 /* valid noa_attr and index changed */
4114 sdata->u.mgd.p2p_noa_index = noa.index;
4115 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4116 changed |= BSS_CHANGED_P2P_PS;
4118 * make sure we update all information, the CRC
4119 * mechanism doesn't look at P2P attributes.
4121 ifmgd->beacon_crc_valid = false;
4123 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4124 /* noa_attr not found and we had valid noa_attr before */
4125 sdata->u.mgd.p2p_noa_index = -1;
4126 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4127 changed |= BSS_CHANGED_P2P_PS;
4128 ifmgd->beacon_crc_valid = false;
4132 if (ifmgd->csa_waiting_bcn)
4133 ieee80211_chswitch_post_beacon(sdata);
4136 * Update beacon timing and dtim count on every beacon appearance. This
4137 * will allow the driver to use the most updated values. Do it before
4138 * comparing this one with last received beacon.
4139 * IMPORTANT: These parameters would possibly be out of sync by the time
4140 * the driver will use them. The synchronized view is currently
4141 * guaranteed only in certain callbacks.
4143 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4144 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4145 sdata->vif.bss_conf.sync_tsf =
4146 le64_to_cpu(mgmt->u.beacon.timestamp);
4147 sdata->vif.bss_conf.sync_device_ts =
4148 rx_status->device_timestamp;
4149 sdata->vif.bss_conf.sync_dtim_count = elems.dtim_count;
4152 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4153 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4155 ifmgd->beacon_crc = ncrc;
4156 ifmgd->beacon_crc_valid = true;
4158 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4160 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4161 rx_status->device_timestamp,
4164 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4165 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
4166 elems.wmm_param_len,
4167 elems.mu_edca_param_set))
4168 changed |= BSS_CHANGED_QOS;
4171 * If we haven't had a beacon before, tell the driver about the
4172 * DTIM period (and beacon timing if desired) now.
4174 if (!ifmgd->have_beacon) {
4175 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4176 bss_conf->dtim_period = elems.dtim_period ?: 1;
4178 changed |= BSS_CHANGED_BEACON_INFO;
4179 ifmgd->have_beacon = true;
4181 mutex_lock(&local->iflist_mtx);
4182 ieee80211_recalc_ps(local);
4183 mutex_unlock(&local->iflist_mtx);
4185 ieee80211_recalc_ps_vif(sdata);
4188 if (elems.erp_info) {
4190 erp_value = elems.erp_info[0];
4195 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4196 changed |= ieee80211_handle_bss_capability(sdata,
4197 le16_to_cpu(mgmt->u.beacon.capab_info),
4198 erp_valid, erp_value);
4200 mutex_lock(&local->sta_mtx);
4201 sta = sta_info_get(sdata, bssid);
4203 changed |= ieee80211_recalc_twt_req(sdata, sta, &elems);
4205 if (ieee80211_config_bw(sdata, sta, elems.ht_cap_elem,
4206 elems.vht_cap_elem, elems.ht_operation,
4207 elems.vht_operation, elems.he_operation,
4208 elems.s1g_oper, bssid, &changed)) {
4209 mutex_unlock(&local->sta_mtx);
4211 "failed to follow AP %pM bandwidth change, disconnect\n",
4213 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4214 WLAN_REASON_DEAUTH_LEAVING,
4216 ieee80211_report_disconnect(sdata, deauth_buf,
4217 sizeof(deauth_buf), true,
4218 WLAN_REASON_DEAUTH_LEAVING,
4223 if (sta && elems.opmode_notif)
4224 ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
4226 mutex_unlock(&local->sta_mtx);
4228 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4230 elems.country_elem_len,
4231 elems.pwr_constr_elem,
4232 elems.cisco_dtpc_elem);
4234 ieee80211_bss_info_change_notify(sdata, changed);
4237 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4238 struct sk_buff *skb)
4240 struct ieee80211_rx_status *rx_status;
4241 struct ieee80211_hdr *hdr;
4244 rx_status = (struct ieee80211_rx_status *) skb->cb;
4245 hdr = (struct ieee80211_hdr *) skb->data;
4246 fc = le16_to_cpu(hdr->frame_control);
4249 switch (fc & IEEE80211_FCTL_STYPE) {
4250 case IEEE80211_STYPE_S1G_BEACON:
4251 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4254 sdata_unlock(sdata);
4257 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4258 struct sk_buff *skb)
4260 struct ieee80211_rx_status *rx_status;
4261 struct ieee80211_mgmt *mgmt;
4263 struct ieee802_11_elems elems;
4266 rx_status = (struct ieee80211_rx_status *) skb->cb;
4267 mgmt = (struct ieee80211_mgmt *) skb->data;
4268 fc = le16_to_cpu(mgmt->frame_control);
4272 switch (fc & IEEE80211_FCTL_STYPE) {
4273 case IEEE80211_STYPE_BEACON:
4274 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4275 skb->len, rx_status);
4277 case IEEE80211_STYPE_PROBE_RESP:
4278 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4280 case IEEE80211_STYPE_AUTH:
4281 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4283 case IEEE80211_STYPE_DEAUTH:
4284 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4286 case IEEE80211_STYPE_DISASSOC:
4287 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4289 case IEEE80211_STYPE_ASSOC_RESP:
4290 case IEEE80211_STYPE_REASSOC_RESP:
4291 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4293 case IEEE80211_STYPE_ACTION:
4294 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4295 ies_len = skb->len -
4296 offsetof(struct ieee80211_mgmt,
4297 u.action.u.chan_switch.variable);
4302 /* CSA IE cannot be overridden, no need for BSSID */
4303 ieee802_11_parse_elems(
4304 mgmt->u.action.u.chan_switch.variable,
4305 ies_len, true, &elems, mgmt->bssid, NULL);
4307 if (elems.parse_error)
4310 ieee80211_sta_process_chanswitch(sdata,
4312 rx_status->device_timestamp,
4314 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4315 ies_len = skb->len -
4316 offsetof(struct ieee80211_mgmt,
4317 u.action.u.ext_chan_switch.variable);
4323 * extended CSA IE can't be overridden, no need for
4326 ieee802_11_parse_elems(
4327 mgmt->u.action.u.ext_chan_switch.variable,
4328 ies_len, true, &elems, mgmt->bssid, NULL);
4330 if (elems.parse_error)
4333 /* for the handling code pretend this was also an IE */
4334 elems.ext_chansw_ie =
4335 &mgmt->u.action.u.ext_chan_switch.data;
4337 ieee80211_sta_process_chanswitch(sdata,
4339 rx_status->device_timestamp,
4344 sdata_unlock(sdata);
4347 static void ieee80211_sta_timer(struct timer_list *t)
4349 struct ieee80211_sub_if_data *sdata =
4350 from_timer(sdata, t, u.mgd.timer);
4352 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4355 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4356 u8 *bssid, u8 reason, bool tx)
4358 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4360 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4363 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4367 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4369 struct ieee80211_local *local = sdata->local;
4370 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4371 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4375 struct ieee80211_prep_tx_info info = {
4376 .subtype = IEEE80211_STYPE_AUTH,
4379 sdata_assert_lock(sdata);
4381 if (WARN_ON_ONCE(!auth_data))
4386 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4387 sdata_info(sdata, "authentication with %pM timed out\n",
4388 auth_data->bss->bssid);
4391 * Most likely AP is not in the range so remove the
4392 * bss struct for that AP.
4394 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4399 if (auth_data->algorithm == WLAN_AUTH_SAE)
4400 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4402 drv_mgd_prepare_tx(local, sdata, &info);
4404 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4405 auth_data->bss->bssid, auth_data->tries,
4406 IEEE80211_AUTH_MAX_TRIES);
4408 auth_data->expected_transaction = 2;
4410 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4411 trans = auth_data->sae_trans;
4412 status = auth_data->sae_status;
4413 auth_data->expected_transaction = trans;
4416 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4417 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4418 IEEE80211_TX_INTFL_MLME_CONN_TX;
4420 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4421 auth_data->data, auth_data->data_len,
4422 auth_data->bss->bssid,
4423 auth_data->bss->bssid, NULL, 0, 0,
4426 if (tx_flags == 0) {
4427 if (auth_data->algorithm == WLAN_AUTH_SAE)
4428 auth_data->timeout = jiffies +
4429 IEEE80211_AUTH_TIMEOUT_SAE;
4431 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4433 auth_data->timeout =
4434 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4437 auth_data->timeout_started = true;
4438 run_again(sdata, auth_data->timeout);
4443 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4445 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4446 struct ieee80211_local *local = sdata->local;
4448 sdata_assert_lock(sdata);
4450 assoc_data->tries++;
4451 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4452 sdata_info(sdata, "association with %pM timed out\n",
4453 assoc_data->bss->bssid);
4456 * Most likely AP is not in the range so remove the
4457 * bss struct for that AP.
4459 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4464 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4465 assoc_data->bss->bssid, assoc_data->tries,
4466 IEEE80211_ASSOC_MAX_TRIES);
4467 ieee80211_send_assoc(sdata);
4469 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4470 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4471 assoc_data->timeout_started = true;
4472 run_again(sdata, assoc_data->timeout);
4474 assoc_data->timeout =
4475 round_jiffies_up(jiffies +
4476 IEEE80211_ASSOC_TIMEOUT_LONG);
4477 assoc_data->timeout_started = true;
4478 run_again(sdata, assoc_data->timeout);
4484 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4485 __le16 fc, bool acked)
4487 struct ieee80211_local *local = sdata->local;
4489 sdata->u.mgd.status_fc = fc;
4490 sdata->u.mgd.status_acked = acked;
4491 sdata->u.mgd.status_received = true;
4493 ieee80211_queue_work(&local->hw, &sdata->work);
4496 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4498 struct ieee80211_local *local = sdata->local;
4499 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4503 if (ifmgd->status_received) {
4504 __le16 fc = ifmgd->status_fc;
4505 bool status_acked = ifmgd->status_acked;
4507 ifmgd->status_received = false;
4508 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4510 if (ifmgd->auth_data->algorithm ==
4512 ifmgd->auth_data->timeout =
4514 IEEE80211_AUTH_TIMEOUT_SAE;
4516 ifmgd->auth_data->timeout =
4518 IEEE80211_AUTH_TIMEOUT_SHORT;
4519 run_again(sdata, ifmgd->auth_data->timeout);
4521 ifmgd->auth_data->timeout = jiffies - 1;
4523 ifmgd->auth_data->timeout_started = true;
4524 } else if (ifmgd->assoc_data &&
4525 (ieee80211_is_assoc_req(fc) ||
4526 ieee80211_is_reassoc_req(fc))) {
4528 ifmgd->assoc_data->timeout =
4529 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4530 run_again(sdata, ifmgd->assoc_data->timeout);
4532 ifmgd->assoc_data->timeout = jiffies - 1;
4534 ifmgd->assoc_data->timeout_started = true;
4538 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4539 time_after(jiffies, ifmgd->auth_data->timeout)) {
4540 if (ifmgd->auth_data->done) {
4542 * ok ... we waited for assoc but userspace didn't,
4543 * so let's just kill the auth data
4545 ieee80211_destroy_auth_data(sdata, false);
4546 } else if (ieee80211_auth(sdata)) {
4548 struct ieee80211_event event = {
4550 .u.mlme.data = AUTH_EVENT,
4551 .u.mlme.status = MLME_TIMEOUT,
4554 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4556 ieee80211_destroy_auth_data(sdata, false);
4558 cfg80211_auth_timeout(sdata->dev, bssid);
4559 drv_event_callback(sdata->local, sdata, &event);
4561 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4562 run_again(sdata, ifmgd->auth_data->timeout);
4564 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4565 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4566 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4567 ieee80211_do_assoc(sdata)) {
4568 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4569 struct ieee80211_event event = {
4571 .u.mlme.data = ASSOC_EVENT,
4572 .u.mlme.status = MLME_TIMEOUT,
4575 ieee80211_destroy_assoc_data(sdata, false, false);
4576 cfg80211_assoc_timeout(sdata->dev, bss);
4577 drv_event_callback(sdata->local, sdata, &event);
4579 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4580 run_again(sdata, ifmgd->assoc_data->timeout);
4582 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4583 ifmgd->associated) {
4587 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4589 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4590 max_tries = max_nullfunc_tries;
4592 max_tries = max_probe_tries;
4594 /* ACK received for nullfunc probing frame */
4595 if (!ifmgd->probe_send_count)
4596 ieee80211_reset_ap_probe(sdata);
4597 else if (ifmgd->nullfunc_failed) {
4598 if (ifmgd->probe_send_count < max_tries) {
4600 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4601 bssid, ifmgd->probe_send_count,
4603 ieee80211_mgd_probe_ap_send(sdata);
4606 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4608 ieee80211_sta_connection_lost(sdata, bssid,
4609 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4612 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4613 run_again(sdata, ifmgd->probe_timeout);
4614 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4616 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4617 bssid, probe_wait_ms);
4618 ieee80211_sta_connection_lost(sdata, bssid,
4619 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4620 } else if (ifmgd->probe_send_count < max_tries) {
4622 "No probe response from AP %pM after %dms, try %d/%i\n",
4623 bssid, probe_wait_ms,
4624 ifmgd->probe_send_count, max_tries);
4625 ieee80211_mgd_probe_ap_send(sdata);
4628 * We actually lost the connection ... or did we?
4632 "No probe response from AP %pM after %dms, disconnecting.\n",
4633 bssid, probe_wait_ms);
4635 ieee80211_sta_connection_lost(sdata, bssid,
4636 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4640 sdata_unlock(sdata);
4643 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4645 struct ieee80211_sub_if_data *sdata =
4646 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4647 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4649 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4652 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4655 sdata->u.mgd.connection_loss = false;
4656 ieee80211_queue_work(&sdata->local->hw,
4657 &sdata->u.mgd.beacon_connection_loss_work);
4660 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4662 struct ieee80211_sub_if_data *sdata =
4663 from_timer(sdata, t, u.mgd.conn_mon_timer);
4664 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4665 struct ieee80211_local *local = sdata->local;
4666 struct sta_info *sta;
4667 unsigned long timeout;
4669 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4672 sta = sta_info_get(sdata, ifmgd->bssid);
4676 timeout = sta->status_stats.last_ack;
4677 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4678 timeout = sta->rx_stats.last_rx;
4679 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4681 /* If timeout is after now, then update timer to fire at
4682 * the later date, but do not actually probe at this time.
4684 if (time_is_after_jiffies(timeout)) {
4685 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4689 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4692 static void ieee80211_sta_monitor_work(struct work_struct *work)
4694 struct ieee80211_sub_if_data *sdata =
4695 container_of(work, struct ieee80211_sub_if_data,
4696 u.mgd.monitor_work);
4698 ieee80211_mgd_probe_ap(sdata, false);
4701 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4703 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4704 __ieee80211_stop_poll(sdata);
4706 /* let's probe the connection once */
4707 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4708 ieee80211_queue_work(&sdata->local->hw,
4709 &sdata->u.mgd.monitor_work);
4714 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4716 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4717 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4721 if (ifmgd->auth_data || ifmgd->assoc_data) {
4722 const u8 *bssid = ifmgd->auth_data ?
4723 ifmgd->auth_data->bss->bssid :
4724 ifmgd->assoc_data->bss->bssid;
4727 * If we are trying to authenticate / associate while suspending,
4728 * cfg80211 won't know and won't actually abort those attempts,
4729 * thus we need to do that ourselves.
4731 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4732 IEEE80211_STYPE_DEAUTH,
4733 WLAN_REASON_DEAUTH_LEAVING,
4735 if (ifmgd->assoc_data)
4736 ieee80211_destroy_assoc_data(sdata, false, true);
4737 if (ifmgd->auth_data)
4738 ieee80211_destroy_auth_data(sdata, false);
4739 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4740 IEEE80211_DEAUTH_FRAME_LEN,
4744 /* This is a bit of a hack - we should find a better and more generic
4745 * solution to this. Normally when suspending, cfg80211 will in fact
4746 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4747 * auth (not so important) or assoc (this is the problem) process.
4749 * As a consequence, it can happen that we are in the process of both
4750 * associating and suspending, and receive an association response
4751 * after cfg80211 has checked if it needs to disconnect, but before
4752 * we actually set the flag to drop incoming frames. This will then
4753 * cause the workqueue flush to process the association response in
4754 * the suspend, resulting in a successful association just before it
4755 * tries to remove the interface from the driver, which now though
4756 * has a channel context assigned ... this results in issues.
4758 * To work around this (for now) simply deauth here again if we're
4761 if (ifmgd->associated && !sdata->local->wowlan) {
4763 struct cfg80211_deauth_request req = {
4764 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4768 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4769 ieee80211_mgd_deauth(sdata, &req);
4772 sdata_unlock(sdata);
4775 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4777 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4780 if (!ifmgd->associated) {
4781 sdata_unlock(sdata);
4785 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4786 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4787 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4788 ieee80211_sta_connection_lost(sdata,
4789 ifmgd->associated->bssid,
4790 WLAN_REASON_UNSPECIFIED,
4792 sdata_unlock(sdata);
4795 sdata_unlock(sdata);
4799 /* interface setup */
4800 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4802 struct ieee80211_if_managed *ifmgd;
4804 ifmgd = &sdata->u.mgd;
4805 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4806 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4807 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4808 ieee80211_beacon_connection_loss_work);
4809 INIT_WORK(&ifmgd->csa_connection_drop_work,
4810 ieee80211_csa_connection_drop_work);
4811 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4812 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4813 ieee80211_tdls_peer_del_work);
4814 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4815 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4816 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4817 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4818 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4819 ieee80211_sta_handle_tspec_ac_params_wk);
4822 ifmgd->powersave = sdata->wdev.ps;
4823 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4824 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4825 ifmgd->p2p_noa_index = -1;
4827 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4828 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4830 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4832 /* Setup TDLS data */
4833 spin_lock_init(&ifmgd->teardown_lock);
4834 ifmgd->teardown_skb = NULL;
4835 ifmgd->orig_teardown_skb = NULL;
4838 /* scan finished notification */
4839 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4841 struct ieee80211_sub_if_data *sdata;
4843 /* Restart STA timers */
4845 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4846 if (ieee80211_sdata_running(sdata))
4847 ieee80211_restart_sta_timer(sdata);
4852 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4853 struct cfg80211_bss *cbss)
4855 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4856 const u8 *ht_cap_ie, *vht_cap_ie;
4857 const struct ieee80211_ht_cap *ht_cap;
4858 const struct ieee80211_vht_cap *vht_cap;
4861 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4864 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4865 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4866 ht_cap = (void *)(ht_cap_ie + 2);
4867 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4869 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4870 * "Tx Unequal Modulation Supported" fields.
4874 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4877 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4878 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4882 vht_cap = (void *)(vht_cap_ie + 2);
4883 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4884 for (nss = 8; nss > 0; nss--) {
4885 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4886 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4889 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4890 chains = max(chains, nss);
4897 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4898 struct ieee80211_supported_band *sband,
4899 const struct ieee80211_he_operation *he_op)
4901 const struct ieee80211_sta_he_cap *sta_he_cap =
4902 ieee80211_get_he_iftype_cap(sband,
4903 ieee80211_vif_type_p2p(&sdata->vif));
4907 if (!sta_he_cap || !he_op)
4910 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4912 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4913 for (i = 0; i < 3; i++) {
4914 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4915 &sta_he_cap->he_mcs_nss_supp;
4916 u16 sta_mcs_map_rx =
4917 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4918 u16 sta_mcs_map_tx =
4919 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4921 bool verified = true;
4924 * For each band there is a maximum of 8 spatial streams
4925 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4926 * of 2 bits per NSS (1-8), with the values defined in enum
4927 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4928 * capabilities aren't less than the AP's minimum requirements
4929 * for this HE BSS per SS.
4930 * It is enough to find one such band that meets the reqs.
4932 for (nss = 8; nss > 0; nss--) {
4933 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4934 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4935 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4937 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4941 * Make sure the HE AP doesn't require MCSs that aren't
4942 * supported by the client
4944 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4945 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4946 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4956 /* If here, STA doesn't meet AP's HE min requirements */
4960 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4961 struct cfg80211_bss *cbss)
4963 struct ieee80211_local *local = sdata->local;
4964 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4965 const struct ieee80211_ht_cap *ht_cap = NULL;
4966 const struct ieee80211_ht_operation *ht_oper = NULL;
4967 const struct ieee80211_vht_operation *vht_oper = NULL;
4968 const struct ieee80211_he_operation *he_oper = NULL;
4969 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4970 struct ieee80211_supported_band *sband;
4971 struct cfg80211_chan_def chandef;
4972 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4973 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4974 struct ieee80211_bss *bss = (void *)cbss->priv;
4979 sband = local->hw.wiphy->bands[cbss->channel->band];
4981 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
4982 IEEE80211_STA_DISABLE_80P80MHZ |
4983 IEEE80211_STA_DISABLE_160MHZ);
4985 /* disable HT/VHT/HE if we don't support them */
4986 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4987 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
4988 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4989 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4992 if (!sband->vht_cap.vht_supported && is_5ghz) {
4993 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
4994 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
4997 if (!ieee80211_get_he_iftype_cap(sband,
4998 ieee80211_vif_type_p2p(&sdata->vif)))
4999 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5003 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5004 const u8 *ht_oper_ie, *ht_cap_ie;
5006 ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
5007 if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
5008 ht_oper = (void *)(ht_oper_ie + 2);
5010 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
5011 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
5012 ht_cap = (void *)(ht_cap_ie + 2);
5015 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5020 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5021 const u8 *vht_oper_ie, *vht_cap;
5023 vht_oper_ie = ieee80211_bss_get_ie(cbss,
5024 WLAN_EID_VHT_OPERATION);
5025 if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
5026 vht_oper = (void *)(vht_oper_ie + 2);
5027 if (vht_oper && !ht_oper) {
5030 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5031 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5032 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5033 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5036 vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
5037 if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
5038 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5043 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5044 const struct cfg80211_bss_ies *ies;
5045 const u8 *he_oper_ie;
5047 ies = rcu_dereference(cbss->ies);
5048 he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
5049 ies->data, ies->len);
5051 he_oper_ie[1] >= ieee80211_he_oper_size(&he_oper_ie[3]))
5052 he_oper = (void *)(he_oper_ie + 3);
5056 if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5057 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5060 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5062 for (i = 0; i < sband->n_channels; i++) {
5063 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5064 IEEE80211_CHAN_NO_80MHZ))
5072 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5074 if (sband->band == NL80211_BAND_S1GHZ) {
5075 const u8 *s1g_oper_ie;
5077 s1g_oper_ie = ieee80211_bss_get_ie(cbss,
5078 WLAN_EID_S1G_OPERATION);
5079 if (s1g_oper_ie && s1g_oper_ie[1] >= sizeof(*s1g_oper))
5080 s1g_oper = (void *)(s1g_oper_ie + 2);
5083 "AP missing S1G operation element?\n");
5086 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5089 ht_oper, vht_oper, he_oper,
5093 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5098 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5099 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5103 /* will change later if needed */
5104 sdata->smps_mode = IEEE80211_SMPS_OFF;
5106 mutex_lock(&local->mtx);
5108 * If this fails (possibly due to channel context sharing
5109 * on incompatible channels, e.g. 80+80 and 160 sharing the
5110 * same control channel) try to use a smaller bandwidth.
5112 ret = ieee80211_vif_use_channel(sdata, &chandef,
5113 IEEE80211_CHANCTX_SHARED);
5115 /* don't downgrade for 5 and 10 MHz channels, though. */
5116 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5117 chandef.width == NL80211_CHAN_WIDTH_10)
5120 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5121 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5122 ret = ieee80211_vif_use_channel(sdata, &chandef,
5123 IEEE80211_CHANCTX_SHARED);
5126 mutex_unlock(&local->mtx);
5130 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5131 u8 *dtim_count, u8 *dtim_period)
5133 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5134 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5136 const struct ieee80211_tim_ie *tim = NULL;
5137 const struct ieee80211_bssid_index *idx;
5138 bool valid = tim_ie && tim_ie[1] >= 2;
5141 tim = (void *)(tim_ie + 2);
5144 *dtim_count = valid ? tim->dtim_count : 0;
5147 *dtim_period = valid ? tim->dtim_period : 0;
5149 /* Check if value is overridden by non-transmitted profile */
5150 if (!idx_ie || idx_ie[1] < 3)
5153 idx = (void *)(idx_ie + 2);
5156 *dtim_count = idx->dtim_count;
5159 *dtim_period = idx->dtim_period;
5164 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5165 struct cfg80211_bss *cbss, bool assoc,
5168 struct ieee80211_local *local = sdata->local;
5169 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5170 struct ieee80211_bss *bss = (void *)cbss->priv;
5171 struct sta_info *new_sta = NULL;
5172 struct ieee80211_supported_band *sband;
5173 bool have_sta = false;
5176 sband = local->hw.wiphy->bands[cbss->channel->band];
5178 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5181 /* If a reconfig is happening, bail out */
5182 if (local->in_reconfig)
5187 have_sta = sta_info_get(sdata, cbss->bssid);
5192 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5198 * Set up the information for the new channel before setting the
5199 * new channel. We can't - completely race-free - change the basic
5200 * rates bitmap and the channel (sband) that it refers to, but if
5201 * we set it up before we at least avoid calling into the driver's
5202 * bss_info_changed() method with invalid information (since we do
5203 * call that from changing the channel - only for IDLE and perhaps
5204 * some others, but ...).
5206 * So to avoid that, just set up all the new information before the
5207 * channel, but tell the driver to apply it only afterwards, since
5208 * it might need the new channel for that.
5211 u32 rates = 0, basic_rates = 0;
5212 bool have_higher_than_11mbit;
5213 int min_rate = INT_MAX, min_rate_index = -1;
5214 const struct cfg80211_bss_ies *ies;
5215 int shift = ieee80211_vif_get_shift(&sdata->vif);
5217 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5218 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5219 ieee80211_s1g_sta_rate_init(new_sta);
5223 ieee80211_get_rates(sband, bss->supp_rates,
5224 bss->supp_rates_len,
5225 &rates, &basic_rates,
5226 &have_higher_than_11mbit,
5227 &min_rate, &min_rate_index,
5231 * This used to be a workaround for basic rates missing
5232 * in the association response frame. Now that we no
5233 * longer use the basic rates from there, it probably
5234 * doesn't happen any more, but keep the workaround so
5235 * in case some *other* APs are buggy in different ways
5236 * we can connect -- with a warning.
5237 * Allow this workaround only in case the AP provided at least
5240 if (min_rate_index < 0) {
5242 "No legacy rates in association response\n");
5244 sta_info_free(local, new_sta);
5246 } else if (!basic_rates) {
5248 "No basic rates, using min rate instead\n");
5249 basic_rates = BIT(min_rate_index);
5253 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5256 "No rates found, keeping mandatory only\n");
5258 sdata->vif.bss_conf.basic_rates = basic_rates;
5260 /* cf. IEEE 802.11 9.2.12 */
5261 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5262 have_higher_than_11mbit)
5263 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5265 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5268 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5270 /* set timing information */
5271 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5273 ies = rcu_dereference(cbss->beacon_ies);
5275 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5276 sdata->vif.bss_conf.sync_device_ts =
5277 bss->device_ts_beacon;
5279 ieee80211_get_dtim(ies,
5280 &sdata->vif.bss_conf.sync_dtim_count,
5282 } else if (!ieee80211_hw_check(&sdata->local->hw,
5283 TIMING_BEACON_ONLY)) {
5284 ies = rcu_dereference(cbss->proberesp_ies);
5285 /* must be non-NULL since beacon IEs were NULL */
5286 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5287 sdata->vif.bss_conf.sync_device_ts =
5288 bss->device_ts_presp;
5289 sdata->vif.bss_conf.sync_dtim_count = 0;
5291 sdata->vif.bss_conf.sync_tsf = 0;
5292 sdata->vif.bss_conf.sync_device_ts = 0;
5293 sdata->vif.bss_conf.sync_dtim_count = 0;
5298 if (new_sta || override) {
5299 err = ieee80211_prep_channel(sdata, cbss);
5302 sta_info_free(local, new_sta);
5309 * tell driver about BSSID, basic rates and timing
5310 * this was set up above, before setting the channel
5312 ieee80211_bss_info_change_notify(sdata,
5313 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5314 BSS_CHANGED_BEACON_INT);
5317 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5319 err = sta_info_insert(new_sta);
5323 "failed to insert STA entry for the AP (error %d)\n",
5328 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5330 /* Cancel scan to ensure that nothing interferes with connection */
5331 if (local->scanning)
5332 ieee80211_scan_cancel(local);
5338 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5339 struct cfg80211_auth_request *req)
5341 struct ieee80211_local *local = sdata->local;
5342 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5343 struct ieee80211_mgd_auth_data *auth_data;
5348 /* prepare auth data structure */
5350 switch (req->auth_type) {
5351 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5352 auth_alg = WLAN_AUTH_OPEN;
5354 case NL80211_AUTHTYPE_SHARED_KEY:
5357 auth_alg = WLAN_AUTH_SHARED_KEY;
5359 case NL80211_AUTHTYPE_FT:
5360 auth_alg = WLAN_AUTH_FT;
5362 case NL80211_AUTHTYPE_NETWORK_EAP:
5363 auth_alg = WLAN_AUTH_LEAP;
5365 case NL80211_AUTHTYPE_SAE:
5366 auth_alg = WLAN_AUTH_SAE;
5368 case NL80211_AUTHTYPE_FILS_SK:
5369 auth_alg = WLAN_AUTH_FILS_SK;
5371 case NL80211_AUTHTYPE_FILS_SK_PFS:
5372 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5374 case NL80211_AUTHTYPE_FILS_PK:
5375 auth_alg = WLAN_AUTH_FILS_PK;
5381 if (ifmgd->assoc_data)
5384 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5385 req->ie_len, GFP_KERNEL);
5389 auth_data->bss = req->bss;
5391 if (req->auth_data_len >= 4) {
5392 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5393 __le16 *pos = (__le16 *) req->auth_data;
5395 auth_data->sae_trans = le16_to_cpu(pos[0]);
5396 auth_data->sae_status = le16_to_cpu(pos[1]);
5398 memcpy(auth_data->data, req->auth_data + 4,
5399 req->auth_data_len - 4);
5400 auth_data->data_len += req->auth_data_len - 4;
5403 /* Check if continuing authentication or trying to authenticate with the
5404 * same BSS that we were in the process of authenticating with and avoid
5405 * removal and re-addition of the STA entry in
5406 * ieee80211_prep_connection().
5408 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5410 if (req->ie && req->ie_len) {
5411 memcpy(&auth_data->data[auth_data->data_len],
5412 req->ie, req->ie_len);
5413 auth_data->data_len += req->ie_len;
5416 if (req->key && req->key_len) {
5417 auth_data->key_len = req->key_len;
5418 auth_data->key_idx = req->key_idx;
5419 memcpy(auth_data->key, req->key, req->key_len);
5422 auth_data->algorithm = auth_alg;
5424 /* try to authenticate/probe */
5426 if (ifmgd->auth_data) {
5427 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5428 auth_data->peer_confirmed =
5429 ifmgd->auth_data->peer_confirmed;
5431 ieee80211_destroy_auth_data(sdata, cont_auth);
5434 /* prep auth_data so we don't go into idle on disassoc */
5435 ifmgd->auth_data = auth_data;
5437 /* If this is continuation of an ongoing SAE authentication exchange
5438 * (i.e., request to send SAE Confirm) and the peer has already
5439 * confirmed, mark authentication completed since we are about to send
5442 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5443 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5444 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5446 if (ifmgd->associated) {
5447 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5450 "disconnect from AP %pM for new auth to %pM\n",
5451 ifmgd->associated->bssid, req->bss->bssid);
5452 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5453 WLAN_REASON_UNSPECIFIED,
5456 ieee80211_report_disconnect(sdata, frame_buf,
5457 sizeof(frame_buf), true,
5458 WLAN_REASON_UNSPECIFIED,
5462 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5464 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5468 err = ieee80211_auth(sdata);
5470 sta_info_destroy_addr(sdata, req->bss->bssid);
5474 /* hold our own reference */
5475 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5479 eth_zero_addr(ifmgd->bssid);
5480 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5481 ifmgd->auth_data = NULL;
5482 mutex_lock(&sdata->local->mtx);
5483 ieee80211_vif_release_channel(sdata);
5484 mutex_unlock(&sdata->local->mtx);
5489 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5490 struct cfg80211_assoc_request *req)
5492 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5493 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5494 struct ieee80211_local *local = sdata->local;
5495 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5496 struct ieee80211_bss *bss = (void *)req->bss->priv;
5497 struct ieee80211_mgd_assoc_data *assoc_data;
5498 const struct cfg80211_bss_ies *beacon_ies;
5499 struct ieee80211_supported_band *sband;
5500 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5501 const u8 *ssidie, *ht_ie, *vht_ie;
5503 bool override = false;
5505 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5510 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
5511 if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
5516 memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
5517 assoc_data->ssid_len = ssidie[1];
5518 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5519 bss_conf->ssid_len = assoc_data->ssid_len;
5522 if (ifmgd->associated) {
5523 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5526 "disconnect from AP %pM for new assoc to %pM\n",
5527 ifmgd->associated->bssid, req->bss->bssid);
5528 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5529 WLAN_REASON_UNSPECIFIED,
5532 ieee80211_report_disconnect(sdata, frame_buf,
5533 sizeof(frame_buf), true,
5534 WLAN_REASON_UNSPECIFIED,
5538 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5543 if (ifmgd->assoc_data) {
5548 if (ifmgd->auth_data) {
5551 /* keep sta info, bssid if matching */
5552 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5553 ieee80211_destroy_auth_data(sdata, match);
5556 /* prepare assoc data */
5558 ifmgd->beacon_crc_valid = false;
5560 assoc_data->wmm = bss->wmm_used &&
5561 (local->hw.queues >= IEEE80211_NUM_ACS);
5564 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5565 * We still associate in non-HT mode (11a/b/g) if any one of these
5566 * ciphers is configured as pairwise.
5567 * We can set this to true for non-11n hardware, that'll be checked
5568 * separately along with the peer capabilities.
5570 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5571 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5572 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5573 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5574 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5575 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5576 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5577 netdev_info(sdata->dev,
5578 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5582 sband = local->hw.wiphy->bands[req->bss->channel->band];
5584 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5585 if (!bss->wmm_used) {
5586 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5587 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5588 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5589 netdev_info(sdata->dev,
5590 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5593 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5594 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5595 sizeof(ifmgd->ht_capa_mask));
5597 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5598 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5599 sizeof(ifmgd->vht_capa_mask));
5601 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5602 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5603 sizeof(ifmgd->s1g_capa_mask));
5605 if (req->ie && req->ie_len) {
5606 memcpy(assoc_data->ie, req->ie, req->ie_len);
5607 assoc_data->ie_len = req->ie_len;
5610 if (req->fils_kek) {
5611 /* should already be checked in cfg80211 - so warn */
5612 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5616 memcpy(assoc_data->fils_kek, req->fils_kek,
5618 assoc_data->fils_kek_len = req->fils_kek_len;
5621 if (req->fils_nonces)
5622 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5623 2 * FILS_NONCE_LEN);
5625 assoc_data->bss = req->bss;
5626 assoc_data->capability = req->bss->capability;
5627 assoc_data->supp_rates = bss->supp_rates;
5628 assoc_data->supp_rates_len = bss->supp_rates_len;
5631 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
5632 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
5633 assoc_data->ap_ht_param =
5634 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
5636 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5637 vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
5638 if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
5639 memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
5640 sizeof(struct ieee80211_vht_cap));
5642 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5643 IEEE80211_STA_DISABLE_HE;
5646 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5647 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5648 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5649 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5651 if (bss->wmm_used && bss->uapsd_supported &&
5652 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5653 assoc_data->uapsd = true;
5654 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5656 assoc_data->uapsd = false;
5657 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5660 if (req->prev_bssid)
5661 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5664 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5665 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5667 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5668 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5671 if (req->flags & ASSOC_REQ_USE_RRM)
5672 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5674 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5676 if (req->crypto.control_port)
5677 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5679 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5681 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5682 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5683 sdata->control_port_over_nl80211 =
5684 req->crypto.control_port_over_nl80211;
5685 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5686 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5689 /* kick off associate process */
5691 ifmgd->assoc_data = assoc_data;
5692 ifmgd->dtim_period = 0;
5693 ifmgd->have_beacon = false;
5695 /* override HT/VHT configuration only if the AP and we support it */
5696 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5697 struct ieee80211_sta_ht_cap sta_ht_cap;
5699 if (req->flags & ASSOC_REQ_DISABLE_HT)
5702 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5703 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5705 /* check for 40 MHz disable override */
5706 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5707 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5708 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5711 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5712 req->flags & ASSOC_REQ_DISABLE_VHT)
5716 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5717 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5718 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5719 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5722 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5723 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5725 if (req->flags & ASSOC_REQ_DISABLE_HE)
5726 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5728 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5732 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5733 if (ifmgd->powersave)
5734 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5736 sdata->smps_mode = IEEE80211_SMPS_OFF;
5738 sdata->smps_mode = ifmgd->req_smps;
5742 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5744 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5747 * Wait up to one beacon interval ...
5748 * should this be more if we miss one?
5750 sdata_info(sdata, "waiting for beacon from %pM\n",
5752 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5753 assoc_data->timeout_started = true;
5754 assoc_data->need_beacon = true;
5755 } else if (beacon_ies) {
5756 const struct element *elem;
5759 ieee80211_get_dtim(beacon_ies, &dtim_count,
5760 &ifmgd->dtim_period);
5762 ifmgd->have_beacon = true;
5763 assoc_data->timeout = jiffies;
5764 assoc_data->timeout_started = true;
5766 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5767 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5768 sdata->vif.bss_conf.sync_device_ts =
5769 bss->device_ts_beacon;
5770 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5773 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5774 beacon_ies->data, beacon_ies->len);
5775 if (elem && elem->datalen >= 3)
5776 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5778 sdata->vif.bss_conf.profile_periodicity = 0;
5780 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5781 beacon_ies->data, beacon_ies->len);
5782 if (elem && elem->datalen >= 11 &&
5783 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5784 sdata->vif.bss_conf.ema_ap = true;
5786 sdata->vif.bss_conf.ema_ap = false;
5788 assoc_data->timeout = jiffies;
5789 assoc_data->timeout_started = true;
5793 run_again(sdata, assoc_data->timeout);
5795 if (bss->corrupt_data) {
5796 char *corrupt_type = "data";
5797 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5798 if (bss->corrupt_data &
5799 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5800 corrupt_type = "beacon and probe response";
5802 corrupt_type = "beacon";
5803 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5804 corrupt_type = "probe response";
5805 sdata_info(sdata, "associating with AP with corrupt %s\n",
5811 eth_zero_addr(ifmgd->bssid);
5812 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5813 ifmgd->assoc_data = NULL;
5819 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5820 struct cfg80211_deauth_request *req)
5822 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5823 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5824 bool tx = !req->local_state_change;
5825 struct ieee80211_prep_tx_info info = {
5826 .subtype = IEEE80211_STYPE_DEAUTH,
5829 if (ifmgd->auth_data &&
5830 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5832 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5833 req->bssid, req->reason_code,
5834 ieee80211_get_reason_code_string(req->reason_code));
5836 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5837 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5838 IEEE80211_STYPE_DEAUTH,
5839 req->reason_code, tx,
5841 ieee80211_destroy_auth_data(sdata, false);
5842 ieee80211_report_disconnect(sdata, frame_buf,
5843 sizeof(frame_buf), true,
5844 req->reason_code, false);
5845 drv_mgd_complete_tx(sdata->local, sdata, &info);
5849 if (ifmgd->assoc_data &&
5850 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5852 "aborting association 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_assoc_data(sdata, false, true);
5862 ieee80211_report_disconnect(sdata, frame_buf,
5863 sizeof(frame_buf), true,
5864 req->reason_code, false);
5868 if (ifmgd->associated &&
5869 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5871 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5872 req->bssid, req->reason_code,
5873 ieee80211_get_reason_code_string(req->reason_code));
5875 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5876 req->reason_code, tx, frame_buf);
5877 ieee80211_report_disconnect(sdata, frame_buf,
5878 sizeof(frame_buf), true,
5879 req->reason_code, false);
5880 drv_mgd_complete_tx(sdata->local, sdata, &info);
5887 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5888 struct cfg80211_disassoc_request *req)
5890 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5892 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5895 * cfg80211 should catch this ... but it's racy since
5896 * we can receive a disassoc frame, process it, hand it
5897 * to cfg80211 while that's in a locked section already
5898 * trying to tell us that the user wants to disconnect.
5900 if (ifmgd->associated != req->bss)
5904 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5905 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5907 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5908 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5909 req->reason_code, !req->local_state_change,
5912 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5913 req->reason_code, false);
5918 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5920 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5923 * Make sure some work items will not run after this,
5924 * they will not do anything but might not have been
5925 * cancelled when disconnecting.
5927 cancel_work_sync(&ifmgd->monitor_work);
5928 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5929 cancel_work_sync(&ifmgd->request_smps_work);
5930 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5931 cancel_work_sync(&ifmgd->chswitch_work);
5932 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5935 if (ifmgd->assoc_data) {
5936 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5937 ieee80211_destroy_assoc_data(sdata, false, false);
5938 cfg80211_assoc_timeout(sdata->dev, bss);
5940 if (ifmgd->auth_data)
5941 ieee80211_destroy_auth_data(sdata, false);
5942 spin_lock_bh(&ifmgd->teardown_lock);
5943 if (ifmgd->teardown_skb) {
5944 kfree_skb(ifmgd->teardown_skb);
5945 ifmgd->teardown_skb = NULL;
5946 ifmgd->orig_teardown_skb = NULL;
5948 kfree(ifmgd->assoc_req_ies);
5949 ifmgd->assoc_req_ies = NULL;
5950 ifmgd->assoc_req_ies_len = 0;
5951 spin_unlock_bh(&ifmgd->teardown_lock);
5952 del_timer_sync(&ifmgd->timer);
5953 sdata_unlock(sdata);
5956 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
5957 enum nl80211_cqm_rssi_threshold_event rssi_event,
5961 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5963 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
5965 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
5967 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
5969 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
5971 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5973 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
5975 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
5977 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);