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:
1493 case NL80211_BAND_LC:
1496 case NL80211_BAND_5GHZ:
1499 case NL80211_BAND_6GHZ:
1501 * In the 6 GHz band, the "maximum transmit power level"
1502 * field in the triplets is reserved, and thus will be
1503 * zero and we shouldn't use it to control TX power.
1504 * The actual TX power will be given in the transmit
1505 * power envelope element instead.
1511 while (country_ie_len >= 3) {
1512 u8 first_channel = triplet->chans.first_channel;
1514 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1517 for (i = 0; i < triplet->chans.num_channels; i++) {
1518 if (first_channel + i * chan_increment == chan) {
1519 have_chan_pwr = true;
1520 *chan_pwr = triplet->chans.max_power;
1529 country_ie_len -= 3;
1532 if (have_chan_pwr && pwr_constr_elem)
1533 *pwr_reduction = *pwr_constr_elem;
1537 return have_chan_pwr;
1540 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1541 struct ieee80211_channel *channel,
1542 const u8 *cisco_dtpc_ie,
1545 /* From practical testing, the first data byte of the DTPC element
1546 * seems to contain the requested dBm level, and the CLI on Cisco
1547 * APs clearly state the range is -127 to 127 dBm, which indicates
1548 * a signed byte, although it seemingly never actually goes negative.
1549 * The other byte seems to always be zero.
1551 *pwr_level = (__s8)cisco_dtpc_ie[4];
1554 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1555 struct ieee80211_channel *channel,
1556 struct ieee80211_mgmt *mgmt,
1557 const u8 *country_ie, u8 country_ie_len,
1558 const u8 *pwr_constr_ie,
1559 const u8 *cisco_dtpc_ie)
1561 bool has_80211h_pwr = false, has_cisco_pwr = false;
1562 int chan_pwr = 0, pwr_reduction_80211h = 0;
1563 int pwr_level_cisco, pwr_level_80211h;
1565 __le16 capab = mgmt->u.probe_resp.capab_info;
1567 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1568 return 0; /* TODO */
1571 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1572 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1573 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1574 sdata, channel, country_ie, country_ie_len,
1575 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1577 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1580 if (cisco_dtpc_ie) {
1581 ieee80211_find_cisco_dtpc(
1582 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1583 has_cisco_pwr = true;
1586 if (!has_80211h_pwr && !has_cisco_pwr)
1589 /* If we have both 802.11h and Cisco DTPC, apply both limits
1590 * by picking the smallest of the two power levels advertised.
1592 if (has_80211h_pwr &&
1593 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1594 new_ap_level = pwr_level_80211h;
1596 if (sdata->ap_power_level == new_ap_level)
1600 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1601 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1602 sdata->u.mgd.bssid);
1603 } else { /* has_cisco_pwr is always true here. */
1604 new_ap_level = pwr_level_cisco;
1606 if (sdata->ap_power_level == new_ap_level)
1610 "Limiting TX power to %d dBm as advertised by %pM\n",
1611 pwr_level_cisco, sdata->u.mgd.bssid);
1614 sdata->ap_power_level = new_ap_level;
1615 if (__ieee80211_recalc_txpower(sdata))
1616 return BSS_CHANGED_TXPOWER;
1621 static void ieee80211_enable_ps(struct ieee80211_local *local,
1622 struct ieee80211_sub_if_data *sdata)
1624 struct ieee80211_conf *conf = &local->hw.conf;
1627 * If we are scanning right now then the parameters will
1628 * take effect when scan finishes.
1630 if (local->scanning)
1633 if (conf->dynamic_ps_timeout > 0 &&
1634 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1635 mod_timer(&local->dynamic_ps_timer, jiffies +
1636 msecs_to_jiffies(conf->dynamic_ps_timeout));
1638 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1639 ieee80211_send_nullfunc(local, sdata, true);
1641 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1642 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1645 conf->flags |= IEEE80211_CONF_PS;
1646 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1650 static void ieee80211_change_ps(struct ieee80211_local *local)
1652 struct ieee80211_conf *conf = &local->hw.conf;
1654 if (local->ps_sdata) {
1655 ieee80211_enable_ps(local, local->ps_sdata);
1656 } else if (conf->flags & IEEE80211_CONF_PS) {
1657 conf->flags &= ~IEEE80211_CONF_PS;
1658 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1659 del_timer_sync(&local->dynamic_ps_timer);
1660 cancel_work_sync(&local->dynamic_ps_enable_work);
1664 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1666 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1667 struct sta_info *sta = NULL;
1668 bool authorized = false;
1670 if (!mgd->powersave)
1676 if (!mgd->associated)
1679 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1682 if (!mgd->have_beacon)
1686 sta = sta_info_get(sdata, mgd->bssid);
1688 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1694 /* need to hold RTNL or interface lock */
1695 void ieee80211_recalc_ps(struct ieee80211_local *local)
1697 struct ieee80211_sub_if_data *sdata, *found = NULL;
1701 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1702 local->ps_sdata = NULL;
1706 list_for_each_entry(sdata, &local->interfaces, list) {
1707 if (!ieee80211_sdata_running(sdata))
1709 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1710 /* If an AP vif is found, then disable PS
1711 * by setting the count to zero thereby setting
1717 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1723 if (count == 1 && ieee80211_powersave_allowed(found)) {
1724 u8 dtimper = found->u.mgd.dtim_period;
1726 timeout = local->dynamic_ps_forced_timeout;
1729 local->hw.conf.dynamic_ps_timeout = timeout;
1731 /* If the TIM IE is invalid, pretend the value is 1 */
1735 local->hw.conf.ps_dtim_period = dtimper;
1736 local->ps_sdata = found;
1738 local->ps_sdata = NULL;
1741 ieee80211_change_ps(local);
1744 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1746 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1748 if (sdata->vif.bss_conf.ps != ps_allowed) {
1749 sdata->vif.bss_conf.ps = ps_allowed;
1750 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1754 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1756 struct ieee80211_local *local =
1757 container_of(work, struct ieee80211_local,
1758 dynamic_ps_disable_work);
1760 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1761 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1762 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1765 ieee80211_wake_queues_by_reason(&local->hw,
1766 IEEE80211_MAX_QUEUE_MAP,
1767 IEEE80211_QUEUE_STOP_REASON_PS,
1771 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1773 struct ieee80211_local *local =
1774 container_of(work, struct ieee80211_local,
1775 dynamic_ps_enable_work);
1776 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1777 struct ieee80211_if_managed *ifmgd;
1778 unsigned long flags;
1781 /* can only happen when PS was just disabled anyway */
1785 ifmgd = &sdata->u.mgd;
1787 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1790 if (local->hw.conf.dynamic_ps_timeout > 0) {
1791 /* don't enter PS if TX frames are pending */
1792 if (drv_tx_frames_pending(local)) {
1793 mod_timer(&local->dynamic_ps_timer, jiffies +
1795 local->hw.conf.dynamic_ps_timeout));
1800 * transmission can be stopped by others which leads to
1801 * dynamic_ps_timer expiry. Postpone the ps timer if it
1802 * is not the actual idle state.
1804 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1805 for (q = 0; q < local->hw.queues; q++) {
1806 if (local->queue_stop_reasons[q]) {
1807 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1809 mod_timer(&local->dynamic_ps_timer, jiffies +
1811 local->hw.conf.dynamic_ps_timeout));
1815 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1818 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1819 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1820 if (drv_tx_frames_pending(local)) {
1821 mod_timer(&local->dynamic_ps_timer, jiffies +
1823 local->hw.conf.dynamic_ps_timeout));
1825 ieee80211_send_nullfunc(local, sdata, true);
1826 /* Flush to get the tx status of nullfunc frame */
1827 ieee80211_flush_queues(local, sdata, false);
1831 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1832 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1833 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1834 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1835 local->hw.conf.flags |= IEEE80211_CONF_PS;
1836 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1840 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1842 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1844 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1847 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1849 struct delayed_work *delayed_work = to_delayed_work(work);
1850 struct ieee80211_sub_if_data *sdata =
1851 container_of(delayed_work, struct ieee80211_sub_if_data,
1852 dfs_cac_timer_work);
1853 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1855 mutex_lock(&sdata->local->mtx);
1856 if (sdata->wdev.cac_started) {
1857 ieee80211_vif_release_channel(sdata);
1858 cfg80211_cac_event(sdata->dev, &chandef,
1859 NL80211_RADAR_CAC_FINISHED,
1862 mutex_unlock(&sdata->local->mtx);
1866 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1868 struct ieee80211_local *local = sdata->local;
1869 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1873 if (local->hw.queues < IEEE80211_NUM_ACS)
1876 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1877 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1879 unsigned long now = jiffies;
1881 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1882 tx_tspec->admitted_time &&
1883 time_after(now, tx_tspec->time_slice_start + HZ)) {
1884 tx_tspec->consumed_tx_time = 0;
1885 tx_tspec->time_slice_start = now;
1887 if (tx_tspec->downgraded)
1889 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1892 switch (tx_tspec->action) {
1893 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1894 /* take the original parameters */
1895 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1897 "failed to set TX queue parameters for queue %d\n",
1899 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1900 tx_tspec->downgraded = false;
1903 case TX_TSPEC_ACTION_DOWNGRADE:
1904 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1905 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1909 /* downgrade next lower non-ACM AC */
1910 for (non_acm_ac = ac + 1;
1911 non_acm_ac < IEEE80211_NUM_ACS;
1913 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1915 /* Usually the loop will result in using BK even if it
1916 * requires admission control, but such a configuration
1917 * makes no sense and we have to transmit somehow - the
1918 * AC selection does the same thing.
1919 * If we started out trying to downgrade from BK, then
1920 * the extra condition here might be needed.
1922 if (non_acm_ac >= IEEE80211_NUM_ACS)
1923 non_acm_ac = IEEE80211_AC_BK;
1924 if (drv_conf_tx(local, sdata, ac,
1925 &sdata->tx_conf[non_acm_ac]))
1927 "failed to set TX queue parameters for queue %d\n",
1929 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1931 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1932 tx_tspec->time_slice_start + HZ - now + 1);
1934 case TX_TSPEC_ACTION_NONE:
1943 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1945 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1946 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1949 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1951 struct ieee80211_sub_if_data *sdata;
1953 sdata = container_of(work, struct ieee80211_sub_if_data,
1954 u.mgd.tx_tspec_wk.work);
1955 ieee80211_sta_handle_tspec_ac_params(sdata);
1960 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1961 struct ieee80211_sub_if_data *sdata,
1962 const u8 *wmm_param, size_t wmm_param_len,
1963 const struct ieee80211_mu_edca_param_set *mu_edca)
1965 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1966 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1968 int count, mu_edca_count, ac;
1970 u8 uapsd_queues = 0;
1972 if (!local->ops->conf_tx)
1975 if (local->hw.queues < IEEE80211_NUM_ACS)
1981 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1984 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1985 uapsd_queues = ifmgd->uapsd_queues;
1987 count = wmm_param[6] & 0x0f;
1988 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
1989 * if mu_edca was preset before and now it disappeared tell
1990 * the driver about it.
1992 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
1993 if (count == ifmgd->wmm_last_param_set &&
1994 mu_edca_count == ifmgd->mu_edca_last_param_set)
1996 ifmgd->wmm_last_param_set = count;
1997 ifmgd->mu_edca_last_param_set = mu_edca_count;
1999 pos = wmm_param + 8;
2000 left = wmm_param_len - 8;
2002 memset(¶ms, 0, sizeof(params));
2005 for (; left >= 4; left -= 4, pos += 4) {
2006 int aci = (pos[0] >> 5) & 0x03;
2007 int acm = (pos[0] >> 4) & 0x01;
2012 ac = IEEE80211_AC_BK;
2014 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2015 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2017 params[ac].mu_edca = !!mu_edca;
2019 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2022 ac = IEEE80211_AC_VI;
2024 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2025 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2027 params[ac].mu_edca = !!mu_edca;
2029 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2032 ac = IEEE80211_AC_VO;
2034 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2035 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2037 params[ac].mu_edca = !!mu_edca;
2039 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2043 ac = IEEE80211_AC_BE;
2045 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2046 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2048 params[ac].mu_edca = !!mu_edca;
2050 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2054 params[ac].aifs = pos[0] & 0x0f;
2056 if (params[ac].aifs < 2) {
2058 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2059 params[ac].aifs, aci);
2060 params[ac].aifs = 2;
2062 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2063 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2064 params[ac].txop = get_unaligned_le16(pos + 2);
2065 params[ac].acm = acm;
2066 params[ac].uapsd = uapsd;
2068 if (params[ac].cw_min == 0 ||
2069 params[ac].cw_min > params[ac].cw_max) {
2071 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2072 params[ac].cw_min, params[ac].cw_max, aci);
2075 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2078 /* WMM specification requires all 4 ACIs. */
2079 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2080 if (params[ac].cw_min == 0) {
2082 "AP has invalid WMM params (missing AC %d), using defaults\n",
2088 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2090 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2092 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2093 params[ac].txop, params[ac].uapsd,
2094 ifmgd->tx_tspec[ac].downgraded);
2095 sdata->tx_conf[ac] = params[ac];
2096 if (!ifmgd->tx_tspec[ac].downgraded &&
2097 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2099 "failed to set TX queue parameters for AC %d\n",
2103 /* enable WMM or activate new settings */
2104 sdata->vif.bss_conf.qos = true;
2108 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2110 lockdep_assert_held(&sdata->local->mtx);
2112 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2113 ieee80211_run_deferred_scan(sdata->local);
2116 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2118 mutex_lock(&sdata->local->mtx);
2119 __ieee80211_stop_poll(sdata);
2120 mutex_unlock(&sdata->local->mtx);
2123 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2124 u16 capab, bool erp_valid, u8 erp)
2126 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2127 struct ieee80211_supported_band *sband;
2129 bool use_protection;
2130 bool use_short_preamble;
2131 bool use_short_slot;
2133 sband = ieee80211_get_sband(sdata);
2138 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2139 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2141 use_protection = false;
2142 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2145 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2146 if (sband->band == NL80211_BAND_5GHZ ||
2147 sband->band == NL80211_BAND_6GHZ)
2148 use_short_slot = true;
2150 if (use_protection != bss_conf->use_cts_prot) {
2151 bss_conf->use_cts_prot = use_protection;
2152 changed |= BSS_CHANGED_ERP_CTS_PROT;
2155 if (use_short_preamble != bss_conf->use_short_preamble) {
2156 bss_conf->use_short_preamble = use_short_preamble;
2157 changed |= BSS_CHANGED_ERP_PREAMBLE;
2160 if (use_short_slot != bss_conf->use_short_slot) {
2161 bss_conf->use_short_slot = use_short_slot;
2162 changed |= BSS_CHANGED_ERP_SLOT;
2168 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2169 struct cfg80211_bss *cbss,
2170 u32 bss_info_changed)
2172 struct ieee80211_bss *bss = (void *)cbss->priv;
2173 struct ieee80211_local *local = sdata->local;
2174 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2176 bss_info_changed |= BSS_CHANGED_ASSOC;
2177 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2178 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2180 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2181 beacon_loss_count * bss_conf->beacon_int));
2183 sdata->u.mgd.associated = cbss;
2184 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2186 ieee80211_check_rate_mask(sdata);
2188 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2190 if (sdata->vif.p2p ||
2191 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2192 const struct cfg80211_bss_ies *ies;
2195 ies = rcu_dereference(cbss->ies);
2199 ret = cfg80211_get_p2p_attr(
2200 ies->data, ies->len,
2201 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2202 (u8 *) &bss_conf->p2p_noa_attr,
2203 sizeof(bss_conf->p2p_noa_attr));
2205 sdata->u.mgd.p2p_noa_index =
2206 bss_conf->p2p_noa_attr.index;
2207 bss_info_changed |= BSS_CHANGED_P2P_PS;
2213 /* just to be sure */
2214 ieee80211_stop_poll(sdata);
2216 ieee80211_led_assoc(local, 1);
2218 if (sdata->u.mgd.have_beacon) {
2220 * If the AP is buggy we may get here with no DTIM period
2221 * known, so assume it's 1 which is the only safe assumption
2222 * in that case, although if the TIM IE is broken powersave
2223 * probably just won't work at all.
2225 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2226 bss_conf->beacon_rate = bss->beacon_rate;
2227 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2229 bss_conf->beacon_rate = NULL;
2230 bss_conf->dtim_period = 0;
2233 bss_conf->assoc = 1;
2235 /* Tell the driver to monitor connection quality (if supported) */
2236 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2237 bss_conf->cqm_rssi_thold)
2238 bss_info_changed |= BSS_CHANGED_CQM;
2240 /* Enable ARP filtering */
2241 if (bss_conf->arp_addr_cnt)
2242 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2244 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2246 mutex_lock(&local->iflist_mtx);
2247 ieee80211_recalc_ps(local);
2248 mutex_unlock(&local->iflist_mtx);
2250 ieee80211_recalc_smps(sdata);
2251 ieee80211_recalc_ps_vif(sdata);
2253 netif_carrier_on(sdata->dev);
2256 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2257 u16 stype, u16 reason, bool tx,
2260 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2261 struct ieee80211_local *local = sdata->local;
2262 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2264 struct ieee80211_prep_tx_info info = {
2268 sdata_assert_lock(sdata);
2270 if (WARN_ON_ONCE(tx && !frame_buf))
2273 if (WARN_ON(!ifmgd->associated))
2276 ieee80211_stop_poll(sdata);
2278 ifmgd->associated = NULL;
2279 netif_carrier_off(sdata->dev);
2282 * if we want to get out of ps before disassoc (why?) we have
2283 * to do it before sending disassoc, as otherwise the null-packet
2286 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2287 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2288 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2290 local->ps_sdata = NULL;
2292 /* disable per-vif ps */
2293 ieee80211_recalc_ps_vif(sdata);
2295 /* make sure ongoing transmission finishes */
2299 * drop any frame before deauth/disassoc, this can be data or
2300 * management frame. Since we are disconnecting, we should not
2301 * insist sending these frames which can take time and delay
2302 * the disconnection and possible the roaming.
2305 ieee80211_flush_queues(local, sdata, true);
2307 /* deauthenticate/disassociate now */
2308 if (tx || frame_buf) {
2310 * In multi channel scenarios guarantee that the virtual
2311 * interface is granted immediate airtime to transmit the
2312 * deauthentication frame by calling mgd_prepare_tx, if the
2313 * driver requested so.
2315 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2316 !ifmgd->have_beacon) {
2317 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2320 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2321 ifmgd->bssid, stype, reason,
2325 /* flush out frame - make sure the deauth was actually sent */
2327 ieee80211_flush_queues(local, sdata, false);
2329 drv_mgd_complete_tx(sdata->local, sdata, &info);
2331 /* clear bssid only after building the needed mgmt frames */
2332 eth_zero_addr(ifmgd->bssid);
2334 sdata->vif.bss_conf.ssid_len = 0;
2336 /* remove AP and TDLS peers */
2337 sta_info_flush(sdata);
2339 /* finally reset all BSS / config parameters */
2340 changed |= ieee80211_reset_erp_info(sdata);
2342 ieee80211_led_assoc(local, 0);
2343 changed |= BSS_CHANGED_ASSOC;
2344 sdata->vif.bss_conf.assoc = false;
2346 ifmgd->p2p_noa_index = -1;
2347 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2348 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2350 /* on the next assoc, re-program HT/VHT parameters */
2351 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2352 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2353 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2354 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2356 /* reset MU-MIMO ownership and group data */
2357 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2358 sizeof(sdata->vif.bss_conf.mu_group.membership));
2359 memset(sdata->vif.bss_conf.mu_group.position, 0,
2360 sizeof(sdata->vif.bss_conf.mu_group.position));
2361 changed |= BSS_CHANGED_MU_GROUPS;
2362 sdata->vif.mu_mimo_owner = false;
2364 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2366 del_timer_sync(&local->dynamic_ps_timer);
2367 cancel_work_sync(&local->dynamic_ps_enable_work);
2369 /* Disable ARP filtering */
2370 if (sdata->vif.bss_conf.arp_addr_cnt)
2371 changed |= BSS_CHANGED_ARP_FILTER;
2373 sdata->vif.bss_conf.qos = false;
2374 changed |= BSS_CHANGED_QOS;
2376 /* The BSSID (not really interesting) and HT changed */
2377 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2378 ieee80211_bss_info_change_notify(sdata, changed);
2380 /* disassociated - set to defaults now */
2381 ieee80211_set_wmm_default(sdata, false, false);
2383 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2384 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2385 del_timer_sync(&sdata->u.mgd.timer);
2386 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2388 sdata->vif.bss_conf.dtim_period = 0;
2389 sdata->vif.bss_conf.beacon_rate = NULL;
2391 ifmgd->have_beacon = false;
2394 mutex_lock(&local->mtx);
2395 ieee80211_vif_release_channel(sdata);
2397 sdata->vif.csa_active = false;
2398 ifmgd->csa_waiting_bcn = false;
2399 ifmgd->csa_ignored_same_chan = false;
2400 if (sdata->csa_block_tx) {
2401 ieee80211_wake_vif_queues(local, sdata,
2402 IEEE80211_QUEUE_STOP_REASON_CSA);
2403 sdata->csa_block_tx = false;
2405 mutex_unlock(&local->mtx);
2407 /* existing TX TSPEC sessions no longer exist */
2408 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2409 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2411 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2413 bss_conf->pwr_reduction = 0;
2414 bss_conf->tx_pwr_env_num = 0;
2415 memset(bss_conf->tx_pwr_env, 0, sizeof(bss_conf->tx_pwr_env));
2418 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2421 struct ieee80211_local *local = sdata->local;
2423 mutex_lock(&local->mtx);
2424 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2427 __ieee80211_stop_poll(sdata);
2429 mutex_lock(&local->iflist_mtx);
2430 ieee80211_recalc_ps(local);
2431 mutex_unlock(&local->iflist_mtx);
2433 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2437 * We've received a probe response, but are not sure whether
2438 * we have or will be receiving any beacons or data, so let's
2439 * schedule the timers again, just in case.
2441 ieee80211_sta_reset_beacon_monitor(sdata);
2443 mod_timer(&ifmgd->conn_mon_timer,
2444 round_jiffies_up(jiffies +
2445 IEEE80211_CONNECTION_IDLE_TIME));
2447 mutex_unlock(&local->mtx);
2450 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2451 struct ieee80211_hdr *hdr,
2454 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2455 u16 tid = ieee80211_get_tid(hdr);
2456 int ac = ieee80211_ac_from_tid(tid);
2457 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2458 unsigned long now = jiffies;
2460 if (likely(!tx_tspec->admitted_time))
2463 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2464 tx_tspec->consumed_tx_time = 0;
2465 tx_tspec->time_slice_start = now;
2467 if (tx_tspec->downgraded) {
2468 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2469 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2473 if (tx_tspec->downgraded)
2476 tx_tspec->consumed_tx_time += tx_time;
2478 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2479 tx_tspec->downgraded = true;
2480 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2481 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2485 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2486 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2488 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2490 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2491 !sdata->u.mgd.probe_send_count)
2495 sdata->u.mgd.probe_send_count = 0;
2497 sdata->u.mgd.nullfunc_failed = true;
2498 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2501 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2502 const u8 *src, const u8 *dst,
2503 const u8 *ssid, size_t ssid_len,
2504 struct ieee80211_channel *channel)
2506 struct sk_buff *skb;
2508 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2509 ssid, ssid_len, NULL, 0,
2510 IEEE80211_PROBE_FLAG_DIRECTED);
2512 ieee80211_tx_skb(sdata, skb);
2515 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2517 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2518 const struct element *ssid;
2519 u8 *dst = ifmgd->associated->bssid;
2520 u8 unicast_limit = max(1, max_probe_tries - 3);
2521 struct sta_info *sta;
2524 * Try sending broadcast probe requests for the last three
2525 * probe requests after the first ones failed since some
2526 * buggy APs only support broadcast probe requests.
2528 if (ifmgd->probe_send_count >= unicast_limit)
2532 * When the hardware reports an accurate Tx ACK status, it's
2533 * better to send a nullfunc frame instead of a probe request,
2534 * as it will kick us off the AP quickly if we aren't associated
2535 * anymore. The timeout will be reset if the frame is ACKed by
2538 ifmgd->probe_send_count++;
2541 mutex_lock(&sdata->local->sta_mtx);
2542 sta = sta_info_get(sdata, dst);
2544 ieee80211_check_fast_rx(sta);
2545 mutex_unlock(&sdata->local->sta_mtx);
2548 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2549 ifmgd->nullfunc_failed = false;
2550 ieee80211_send_nullfunc(sdata->local, sdata, false);
2555 ssid = ieee80211_bss_get_elem(ifmgd->associated, WLAN_EID_SSID);
2556 if (WARN_ON_ONCE(ssid == NULL))
2559 ssid_len = ssid->datalen;
2561 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2562 ssid->data, ssid_len,
2563 ifmgd->associated->channel);
2567 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2568 run_again(sdata, ifmgd->probe_timeout);
2571 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2574 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2575 bool already = false;
2577 if (!ieee80211_sdata_running(sdata))
2582 if (!ifmgd->associated)
2585 mutex_lock(&sdata->local->mtx);
2587 if (sdata->local->tmp_channel || sdata->local->scanning) {
2588 mutex_unlock(&sdata->local->mtx);
2592 if (sdata->local->suspending) {
2593 /* reschedule after resume */
2594 mutex_unlock(&sdata->local->mtx);
2595 ieee80211_reset_ap_probe(sdata);
2600 mlme_dbg_ratelimited(sdata,
2601 "detected beacon loss from AP (missed %d beacons) - probing\n",
2604 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2608 * The driver/our work has already reported this event or the
2609 * connection monitoring has kicked in and we have already sent
2610 * a probe request. Or maybe the AP died and the driver keeps
2611 * reporting until we disassociate...
2613 * In either case we have to ignore the current call to this
2614 * function (except for setting the correct probe reason bit)
2615 * because otherwise we would reset the timer every time and
2616 * never check whether we received a probe response!
2618 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2621 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2623 mutex_unlock(&sdata->local->mtx);
2628 mutex_lock(&sdata->local->iflist_mtx);
2629 ieee80211_recalc_ps(sdata->local);
2630 mutex_unlock(&sdata->local->iflist_mtx);
2632 ifmgd->probe_send_count = 0;
2633 ieee80211_mgd_probe_ap_send(sdata);
2635 sdata_unlock(sdata);
2638 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2639 struct ieee80211_vif *vif)
2641 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2642 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2643 struct cfg80211_bss *cbss;
2644 struct sk_buff *skb;
2645 const struct element *ssid;
2648 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2651 sdata_assert_lock(sdata);
2653 if (ifmgd->associated)
2654 cbss = ifmgd->associated;
2655 else if (ifmgd->auth_data)
2656 cbss = ifmgd->auth_data->bss;
2657 else if (ifmgd->assoc_data)
2658 cbss = ifmgd->assoc_data->bss;
2663 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
2664 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
2665 "invalid SSID element (len=%d)",
2666 ssid ? ssid->datalen : -1))
2669 ssid_len = ssid->datalen;
2671 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2672 (u32) -1, cbss->channel,
2673 ssid->data, ssid_len,
2674 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2679 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2681 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2682 const u8 *buf, size_t len, bool tx,
2683 u16 reason, bool reconnect)
2685 struct ieee80211_event event = {
2687 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2688 .u.mlme.reason = reason,
2692 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2694 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2696 drv_event_callback(sdata->local, sdata, &event);
2699 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2701 struct ieee80211_local *local = sdata->local;
2702 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2703 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2707 if (!ifmgd->associated) {
2708 sdata_unlock(sdata);
2712 tx = !sdata->csa_block_tx;
2714 if (!ifmgd->driver_disconnect) {
2716 * AP is probably out of range (or not reachable for another
2717 * reason) so remove the bss struct for that AP.
2719 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2722 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2723 ifmgd->driver_disconnect ?
2724 WLAN_REASON_DEAUTH_LEAVING :
2725 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2727 mutex_lock(&local->mtx);
2728 sdata->vif.csa_active = false;
2729 ifmgd->csa_waiting_bcn = false;
2730 if (sdata->csa_block_tx) {
2731 ieee80211_wake_vif_queues(local, sdata,
2732 IEEE80211_QUEUE_STOP_REASON_CSA);
2733 sdata->csa_block_tx = false;
2735 mutex_unlock(&local->mtx);
2737 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2738 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2740 ifmgd->reconnect = false;
2742 sdata_unlock(sdata);
2745 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2747 struct ieee80211_sub_if_data *sdata =
2748 container_of(work, struct ieee80211_sub_if_data,
2749 u.mgd.beacon_connection_loss_work);
2750 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2752 if (ifmgd->associated)
2753 ifmgd->beacon_loss_count++;
2755 if (ifmgd->connection_loss) {
2756 sdata_info(sdata, "Connection to AP %pM lost\n",
2758 __ieee80211_disconnect(sdata);
2759 ifmgd->connection_loss = false;
2760 } else if (ifmgd->driver_disconnect) {
2762 "Driver requested disconnection from AP %pM\n",
2764 __ieee80211_disconnect(sdata);
2765 ifmgd->driver_disconnect = false;
2767 ieee80211_mgd_probe_ap(sdata, true);
2771 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2773 struct ieee80211_sub_if_data *sdata =
2774 container_of(work, struct ieee80211_sub_if_data,
2775 u.mgd.csa_connection_drop_work);
2777 __ieee80211_disconnect(sdata);
2780 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2782 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2783 struct ieee80211_hw *hw = &sdata->local->hw;
2785 trace_api_beacon_loss(sdata);
2787 sdata->u.mgd.connection_loss = false;
2788 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2790 EXPORT_SYMBOL(ieee80211_beacon_loss);
2792 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2794 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2795 struct ieee80211_hw *hw = &sdata->local->hw;
2797 trace_api_connection_loss(sdata);
2799 sdata->u.mgd.connection_loss = true;
2800 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2802 EXPORT_SYMBOL(ieee80211_connection_loss);
2804 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2806 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2807 struct ieee80211_hw *hw = &sdata->local->hw;
2809 trace_api_disconnect(sdata, reconnect);
2811 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2814 sdata->u.mgd.driver_disconnect = true;
2815 sdata->u.mgd.reconnect = reconnect;
2816 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2818 EXPORT_SYMBOL(ieee80211_disconnect);
2820 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2823 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2825 sdata_assert_lock(sdata);
2829 * we are not authenticated yet, the only timer that could be
2830 * running is the timeout for the authentication response which
2831 * which is not relevant anymore.
2833 del_timer_sync(&sdata->u.mgd.timer);
2834 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2836 eth_zero_addr(sdata->u.mgd.bssid);
2837 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2838 sdata->u.mgd.flags = 0;
2839 mutex_lock(&sdata->local->mtx);
2840 ieee80211_vif_release_channel(sdata);
2841 mutex_unlock(&sdata->local->mtx);
2844 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2846 sdata->u.mgd.auth_data = NULL;
2849 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2850 bool assoc, bool abandon)
2852 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2854 sdata_assert_lock(sdata);
2858 * we are not associated yet, the only timer that could be
2859 * running is the timeout for the association response which
2860 * which is not relevant anymore.
2862 del_timer_sync(&sdata->u.mgd.timer);
2863 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2865 eth_zero_addr(sdata->u.mgd.bssid);
2866 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2867 sdata->u.mgd.flags = 0;
2868 sdata->vif.mu_mimo_owner = false;
2870 mutex_lock(&sdata->local->mtx);
2871 ieee80211_vif_release_channel(sdata);
2872 mutex_unlock(&sdata->local->mtx);
2875 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2879 sdata->u.mgd.assoc_data = NULL;
2882 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2883 struct ieee80211_mgmt *mgmt, size_t len)
2885 struct ieee80211_local *local = sdata->local;
2886 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2887 const struct element *challenge;
2890 struct ieee80211_prep_tx_info info = {
2891 .subtype = IEEE80211_STYPE_AUTH,
2894 pos = mgmt->u.auth.variable;
2895 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
2896 len - (pos - (u8 *)mgmt));
2899 auth_data->expected_transaction = 4;
2900 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2901 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2902 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2903 IEEE80211_TX_INTFL_MLME_CONN_TX;
2904 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2906 challenge->datalen + sizeof(*challenge),
2907 auth_data->bss->bssid, auth_data->bss->bssid,
2908 auth_data->key, auth_data->key_len,
2909 auth_data->key_idx, tx_flags);
2912 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2915 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2916 struct sta_info *sta;
2919 sdata_info(sdata, "authenticated\n");
2920 ifmgd->auth_data->done = true;
2921 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2922 ifmgd->auth_data->timeout_started = true;
2923 run_again(sdata, ifmgd->auth_data->timeout);
2925 /* move station state to auth */
2926 mutex_lock(&sdata->local->sta_mtx);
2927 sta = sta_info_get(sdata, bssid);
2929 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2933 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2934 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2940 mutex_unlock(&sdata->local->sta_mtx);
2944 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2945 struct ieee80211_mgmt *mgmt, size_t len)
2947 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2949 u16 auth_alg, auth_transaction, status_code;
2950 struct ieee80211_event event = {
2952 .u.mlme.data = AUTH_EVENT,
2954 struct ieee80211_prep_tx_info info = {
2955 .subtype = IEEE80211_STYPE_AUTH,
2958 sdata_assert_lock(sdata);
2963 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2966 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2968 if (!ether_addr_equal(bssid, mgmt->bssid))
2971 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2972 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2973 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2975 if (auth_alg != ifmgd->auth_data->algorithm ||
2976 (auth_alg != WLAN_AUTH_SAE &&
2977 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2978 (auth_alg == WLAN_AUTH_SAE &&
2979 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2980 auth_transaction > 2))) {
2981 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2982 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2984 ifmgd->auth_data->expected_transaction);
2988 if (status_code != WLAN_STATUS_SUCCESS) {
2989 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2991 if (auth_alg == WLAN_AUTH_SAE &&
2992 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
2993 (auth_transaction == 1 &&
2994 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
2995 status_code == WLAN_STATUS_SAE_PK))))
2998 sdata_info(sdata, "%pM denied authentication (status %d)\n",
2999 mgmt->sa, status_code);
3000 ieee80211_destroy_auth_data(sdata, false);
3001 event.u.mlme.status = MLME_DENIED;
3002 event.u.mlme.reason = status_code;
3003 drv_event_callback(sdata->local, sdata, &event);
3007 switch (ifmgd->auth_data->algorithm) {
3008 case WLAN_AUTH_OPEN:
3009 case WLAN_AUTH_LEAP:
3012 case WLAN_AUTH_FILS_SK:
3013 case WLAN_AUTH_FILS_SK_PFS:
3014 case WLAN_AUTH_FILS_PK:
3016 case WLAN_AUTH_SHARED_KEY:
3017 if (ifmgd->auth_data->expected_transaction != 4) {
3018 ieee80211_auth_challenge(sdata, mgmt, len);
3019 /* need another frame */
3024 WARN_ONCE(1, "invalid auth alg %d",
3025 ifmgd->auth_data->algorithm);
3029 event.u.mlme.status = MLME_SUCCESS;
3031 drv_event_callback(sdata->local, sdata, &event);
3032 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3033 (auth_transaction == 2 &&
3034 ifmgd->auth_data->expected_transaction == 2)) {
3035 if (!ieee80211_mark_sta_auth(sdata, bssid))
3036 return; /* ignore frame -- wait for timeout */
3037 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3038 auth_transaction == 2) {
3039 sdata_info(sdata, "SAE peer confirmed\n");
3040 ifmgd->auth_data->peer_confirmed = true;
3043 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3045 drv_mgd_complete_tx(sdata->local, sdata, &info);
3048 #define case_WLAN(type) \
3049 case WLAN_REASON_##type: return #type
3051 const char *ieee80211_get_reason_code_string(u16 reason_code)
3053 switch (reason_code) {
3054 case_WLAN(UNSPECIFIED);
3055 case_WLAN(PREV_AUTH_NOT_VALID);
3056 case_WLAN(DEAUTH_LEAVING);
3057 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3058 case_WLAN(DISASSOC_AP_BUSY);
3059 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3060 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3061 case_WLAN(DISASSOC_STA_HAS_LEFT);
3062 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3063 case_WLAN(DISASSOC_BAD_POWER);
3064 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3065 case_WLAN(INVALID_IE);
3066 case_WLAN(MIC_FAILURE);
3067 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3068 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3069 case_WLAN(IE_DIFFERENT);
3070 case_WLAN(INVALID_GROUP_CIPHER);
3071 case_WLAN(INVALID_PAIRWISE_CIPHER);
3072 case_WLAN(INVALID_AKMP);
3073 case_WLAN(UNSUPP_RSN_VERSION);
3074 case_WLAN(INVALID_RSN_IE_CAP);
3075 case_WLAN(IEEE8021X_FAILED);
3076 case_WLAN(CIPHER_SUITE_REJECTED);
3077 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3078 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3079 case_WLAN(DISASSOC_LOW_ACK);
3080 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3081 case_WLAN(QSTA_LEAVE_QBSS);
3082 case_WLAN(QSTA_NOT_USE);
3083 case_WLAN(QSTA_REQUIRE_SETUP);
3084 case_WLAN(QSTA_TIMEOUT);
3085 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3086 case_WLAN(MESH_PEER_CANCELED);
3087 case_WLAN(MESH_MAX_PEERS);
3088 case_WLAN(MESH_CONFIG);
3089 case_WLAN(MESH_CLOSE);
3090 case_WLAN(MESH_MAX_RETRIES);
3091 case_WLAN(MESH_CONFIRM_TIMEOUT);
3092 case_WLAN(MESH_INVALID_GTK);
3093 case_WLAN(MESH_INCONSISTENT_PARAM);
3094 case_WLAN(MESH_INVALID_SECURITY);
3095 case_WLAN(MESH_PATH_ERROR);
3096 case_WLAN(MESH_PATH_NOFORWARD);
3097 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3098 case_WLAN(MAC_EXISTS_IN_MBSS);
3099 case_WLAN(MESH_CHAN_REGULATORY);
3100 case_WLAN(MESH_CHAN);
3101 default: return "<unknown>";
3105 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3106 struct ieee80211_mgmt *mgmt, size_t len)
3108 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3109 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3111 sdata_assert_lock(sdata);
3116 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3117 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3121 if (ifmgd->associated &&
3122 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3123 const u8 *bssid = ifmgd->associated->bssid;
3125 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3127 ieee80211_get_reason_code_string(reason_code));
3129 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3131 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3132 reason_code, false);
3136 if (ifmgd->assoc_data &&
3137 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3138 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3141 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3143 ieee80211_get_reason_code_string(reason_code));
3145 ieee80211_destroy_assoc_data(sdata, false, true);
3147 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3153 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3154 struct ieee80211_mgmt *mgmt, size_t len)
3156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3159 sdata_assert_lock(sdata);
3164 if (!ifmgd->associated ||
3165 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3168 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3170 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3171 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3175 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3176 mgmt->sa, reason_code,
3177 ieee80211_get_reason_code_string(reason_code));
3179 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3181 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3185 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3186 u8 *supp_rates, unsigned int supp_rates_len,
3187 u32 *rates, u32 *basic_rates,
3188 bool *have_higher_than_11mbit,
3189 int *min_rate, int *min_rate_index,
3194 for (i = 0; i < supp_rates_len; i++) {
3195 int rate = supp_rates[i] & 0x7f;
3196 bool is_basic = !!(supp_rates[i] & 0x80);
3198 if ((rate * 5 * (1 << shift)) > 110)
3199 *have_higher_than_11mbit = true;
3202 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3203 * since they're not rates.
3205 * Note: Even though the membership selector and the basic
3206 * rate flag share the same bit, they are not exactly
3209 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3210 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3211 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3212 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3215 for (j = 0; j < sband->n_bitrates; j++) {
3216 struct ieee80211_rate *br;
3219 br = &sband->bitrates[j];
3221 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3222 if (brate == rate) {
3225 *basic_rates |= BIT(j);
3226 if ((rate * 5) < *min_rate) {
3227 *min_rate = rate * 5;
3228 *min_rate_index = j;
3236 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3237 const struct ieee802_11_elems *elems)
3239 if (elems->ext_capab_len < 10)
3242 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3245 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3246 IEEE80211_HE_MAC_CAP0_TWT_RES;
3249 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3250 struct sta_info *sta,
3251 struct ieee802_11_elems *elems)
3253 bool twt = ieee80211_twt_req_supported(sta, elems);
3255 if (sdata->vif.bss_conf.twt_requester != twt) {
3256 sdata->vif.bss_conf.twt_requester = twt;
3257 return BSS_CHANGED_TWT;
3262 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3263 struct ieee80211_bss_conf *bss_conf,
3264 struct ieee80211_supported_band *sband,
3265 struct sta_info *sta)
3267 const struct ieee80211_sta_he_cap *own_he_cap =
3268 ieee80211_get_he_iftype_cap(sband,
3269 ieee80211_vif_type_p2p(&sdata->vif));
3271 return bss_conf->he_support &&
3272 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3273 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3275 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3276 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3279 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3280 struct cfg80211_bss *cbss,
3281 struct ieee80211_mgmt *mgmt, size_t len,
3282 struct ieee802_11_elems *elems)
3284 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3285 struct ieee80211_local *local = sdata->local;
3286 struct ieee80211_supported_band *sband;
3287 struct sta_info *sta;
3288 u16 capab_info, aid;
3289 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3290 const struct cfg80211_bss_ies *bss_ies = NULL;
3291 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3292 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3293 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3299 /* AssocResp and ReassocResp have identical structure */
3301 pos = mgmt->u.assoc_resp.variable;
3302 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3304 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3307 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3308 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3309 mgmt->bssid, assoc_data->bss->bssid);
3314 if (elems->aid_resp)
3315 aid = le16_to_cpu(elems->aid_resp->aid);
3318 * The 5 MSB of the AID field are reserved
3319 * (802.11-2016 9.4.1.8 AID field)
3323 ifmgd->broken_ap = false;
3325 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3326 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3329 ifmgd->broken_ap = true;
3332 if (!is_s1g && !elems->supp_rates) {
3333 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3338 sdata->vif.bss_conf.aid = aid;
3339 ifmgd->tdls_chan_switch_prohibited =
3340 elems->ext_capab && elems->ext_capab_len >= 5 &&
3341 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3344 * Some APs are erroneously not including some information in their
3345 * (re)association response frames. Try to recover by using the data
3346 * from the beacon or probe response. This seems to afflict mobile
3347 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3348 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3351 ((assoc_data->wmm && !elems->wmm_param) ||
3352 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3353 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3354 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3355 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3356 const struct cfg80211_bss_ies *ies;
3357 struct ieee802_11_elems *bss_elems;
3360 ies = rcu_dereference(cbss->ies);
3362 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3370 bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3372 assoc_data->bss->bssid);
3378 if (assoc_data->wmm &&
3379 !elems->wmm_param && bss_elems->wmm_param) {
3380 elems->wmm_param = bss_elems->wmm_param;
3382 "AP bug: WMM param missing from AssocResp\n");
3386 * Also check if we requested HT/VHT, otherwise the AP doesn't
3387 * have to include the IEs in the (re)association response.
3389 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3390 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3391 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3393 "AP bug: HT capability missing from AssocResp\n");
3395 if (!elems->ht_operation && bss_elems->ht_operation &&
3396 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3397 elems->ht_operation = bss_elems->ht_operation;
3399 "AP bug: HT operation missing from AssocResp\n");
3401 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3402 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3403 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3405 "AP bug: VHT capa missing from AssocResp\n");
3407 if (!elems->vht_operation && bss_elems->vht_operation &&
3408 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3409 elems->vht_operation = bss_elems->vht_operation;
3411 "AP bug: VHT operation missing from AssocResp\n");
3418 * We previously checked these in the beacon/probe response, so
3419 * they should be present here. This is just a safety net.
3421 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3422 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3424 "HT AP is missing WMM params or HT capability/operation\n");
3429 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3430 (!elems->vht_cap_elem || !elems->vht_operation)) {
3432 "VHT AP is missing VHT capability/operation\n");
3437 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3438 !elems->he_6ghz_capa) {
3440 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3445 mutex_lock(&sdata->local->sta_mtx);
3447 * station info was already allocated and inserted before
3448 * the association and should be available to us
3450 sta = sta_info_get(sdata, cbss->bssid);
3451 if (WARN_ON(!sta)) {
3452 mutex_unlock(&sdata->local->sta_mtx);
3457 sband = ieee80211_get_sband(sdata);
3459 mutex_unlock(&sdata->local->sta_mtx);
3464 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3465 (!elems->he_cap || !elems->he_operation)) {
3466 mutex_unlock(&sdata->local->sta_mtx);
3468 "HE AP is missing HE capability/operation\n");
3473 /* Set up internal HT/VHT capabilities */
3474 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3475 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3476 elems->ht_cap_elem, sta);
3478 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3479 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3480 elems->vht_cap_elem, sta);
3482 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3484 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3487 elems->he_6ghz_capa,
3490 bss_conf->he_support = sta->sta.he_cap.has_he;
3491 if (elems->rsnx && elems->rsnx_len &&
3492 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3493 wiphy_ext_feature_isset(local->hw.wiphy,
3494 NL80211_EXT_FEATURE_PROTECTED_TWT))
3495 bss_conf->twt_protected = true;
3497 bss_conf->twt_protected = false;
3499 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3501 bss_conf->he_support = false;
3502 bss_conf->twt_requester = false;
3503 bss_conf->twt_protected = false;
3506 bss_conf->twt_broadcast =
3507 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3509 if (bss_conf->he_support) {
3510 bss_conf->he_bss_color.color =
3511 le32_get_bits(elems->he_operation->he_oper_params,
3512 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3513 bss_conf->he_bss_color.partial =
3514 le32_get_bits(elems->he_operation->he_oper_params,
3515 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3516 bss_conf->he_bss_color.enabled =
3517 !le32_get_bits(elems->he_operation->he_oper_params,
3518 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3520 if (bss_conf->he_bss_color.enabled)
3521 changed |= BSS_CHANGED_HE_BSS_COLOR;
3523 bss_conf->htc_trig_based_pkt_ext =
3524 le32_get_bits(elems->he_operation->he_oper_params,
3525 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3526 bss_conf->frame_time_rts_th =
3527 le32_get_bits(elems->he_operation->he_oper_params,
3528 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3530 bss_conf->uora_exists = !!elems->uora_element;
3531 if (elems->uora_element)
3532 bss_conf->uora_ocw_range = elems->uora_element[0];
3534 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3535 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3536 /* TODO: OPEN: what happens if BSS color disable is set? */
3539 if (cbss->transmitted_bss) {
3540 bss_conf->nontransmitted = true;
3541 ether_addr_copy(bss_conf->transmitter_bssid,
3542 cbss->transmitted_bss->bssid);
3543 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3544 bss_conf->bssid_index = cbss->bssid_index;
3548 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3549 * in their association response, so ignore that data for our own
3550 * configuration. If it changed since the last beacon, we'll get the
3551 * next beacon and update then.
3555 * If an operating mode notification IE is present, override the
3556 * NSS calculation (that would be done in rate_control_rate_init())
3557 * and use the # of streams from that element.
3559 if (elems->opmode_notif &&
3560 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3563 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3564 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3566 sta->sta.rx_nss = nss;
3569 rate_control_rate_init(sta);
3571 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3572 set_sta_flag(sta, WLAN_STA_MFP);
3573 sta->sta.mfp = true;
3575 sta->sta.mfp = false;
3578 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3579 local->hw.queues >= IEEE80211_NUM_ACS;
3581 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3582 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3583 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3586 "failed to move station %pM to desired state\n",
3588 WARN_ON(__sta_info_destroy(sta));
3589 mutex_unlock(&sdata->local->sta_mtx);
3594 if (sdata->wdev.use_4addr)
3595 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3597 mutex_unlock(&sdata->local->sta_mtx);
3600 * Always handle WMM once after association regardless
3601 * of the first value the AP uses. Setting -1 here has
3602 * that effect because the AP values is an unsigned
3605 ifmgd->wmm_last_param_set = -1;
3606 ifmgd->mu_edca_last_param_set = -1;
3608 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3609 ieee80211_set_wmm_default(sdata, false, false);
3610 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3611 elems->wmm_param_len,
3612 elems->mu_edca_param_set)) {
3613 /* still enable QoS since we might have HT/VHT */
3614 ieee80211_set_wmm_default(sdata, false, true);
3615 /* set the disable-WMM flag in this case to disable
3616 * tracking WMM parameter changes in the beacon if
3617 * the parameters weren't actually valid. Doing so
3618 * avoids changing parameters very strangely when
3619 * the AP is going back and forth between valid and
3620 * invalid parameters.
3622 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3624 changed |= BSS_CHANGED_QOS;
3626 if (elems->max_idle_period_ie) {
3627 bss_conf->max_idle_period =
3628 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3629 bss_conf->protected_keep_alive =
3630 !!(elems->max_idle_period_ie->idle_options &
3631 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3632 changed |= BSS_CHANGED_KEEP_ALIVE;
3634 bss_conf->max_idle_period = 0;
3635 bss_conf->protected_keep_alive = false;
3638 /* set assoc capability (AID was already set earlier),
3639 * ieee80211_set_associated() will tell the driver */
3640 bss_conf->assoc_capability = capab_info;
3641 ieee80211_set_associated(sdata, cbss, changed);
3644 * If we're using 4-addr mode, let the AP know that we're
3645 * doing so, so that it can create the STA VLAN on its side
3647 if (ifmgd->use_4addr)
3648 ieee80211_send_4addr_nullfunc(local, sdata);
3651 * Start timer to probe the connection to the AP now.
3652 * Also start the timer that will detect beacon loss.
3654 ieee80211_sta_reset_beacon_monitor(sdata);
3655 ieee80211_sta_reset_conn_monitor(sdata);
3664 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3665 struct ieee80211_mgmt *mgmt,
3668 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3669 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3670 u16 capab_info, status_code, aid;
3671 struct ieee802_11_elems *elems;
3672 int ac, uapsd_queues = -1;
3675 struct cfg80211_bss *cbss;
3676 struct ieee80211_event event = {
3678 .u.mlme.data = ASSOC_EVENT,
3680 struct ieee80211_prep_tx_info info = {};
3682 sdata_assert_lock(sdata);
3687 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3690 cbss = assoc_data->bss;
3693 * AssocResp and ReassocResp have identical structure, so process both
3694 * of them in this function.
3700 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3701 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3702 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3703 pos = mgmt->u.assoc_resp.variable;
3704 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3705 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3706 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3711 * Note: this may not be perfect, AP might misbehave - if
3712 * anyone needs to rely on perfect complete notification
3713 * with the exact right subtype, then we need to track what
3714 * we actually transmitted.
3716 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3717 IEEE80211_STYPE_ASSOC_REQ;
3720 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3721 reassoc ? "Rea" : "A", mgmt->sa,
3722 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3724 if (assoc_data->fils_kek_len &&
3725 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3728 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3729 mgmt->bssid, assoc_data->bss->bssid);
3733 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3734 elems->timeout_int &&
3735 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3737 tu = le32_to_cpu(elems->timeout_int->value);
3738 ms = tu * 1024 / 1000;
3740 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3742 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3743 assoc_data->timeout_started = true;
3744 if (ms > IEEE80211_ASSOC_TIMEOUT)
3745 run_again(sdata, assoc_data->timeout);
3749 if (status_code != WLAN_STATUS_SUCCESS) {
3750 sdata_info(sdata, "%pM denied association (code=%d)\n",
3751 mgmt->sa, status_code);
3752 ieee80211_destroy_assoc_data(sdata, false, false);
3753 event.u.mlme.status = MLME_DENIED;
3754 event.u.mlme.reason = status_code;
3755 drv_event_callback(sdata->local, sdata, &event);
3757 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) {
3758 /* oops -- internal error -- send timeout for now */
3759 ieee80211_destroy_assoc_data(sdata, false, false);
3760 cfg80211_assoc_timeout(sdata->dev, cbss);
3763 event.u.mlme.status = MLME_SUCCESS;
3764 drv_event_callback(sdata->local, sdata, &event);
3765 sdata_info(sdata, "associated\n");
3768 * destroy assoc_data afterwards, as otherwise an idle
3769 * recalc after assoc_data is NULL but before associated
3770 * is set can cause the interface to go idle
3772 ieee80211_destroy_assoc_data(sdata, true, false);
3774 /* get uapsd queues configuration */
3776 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3777 if (sdata->tx_conf[ac].uapsd)
3778 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3783 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3784 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3786 drv_mgd_complete_tx(sdata->local, sdata, &info);
3790 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3791 struct ieee80211_mgmt *mgmt, size_t len,
3792 struct ieee80211_rx_status *rx_status)
3794 struct ieee80211_local *local = sdata->local;
3795 struct ieee80211_bss *bss;
3796 struct ieee80211_channel *channel;
3798 sdata_assert_lock(sdata);
3800 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3801 ieee80211_rx_status_to_khz(rx_status));
3805 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3807 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3808 ieee80211_rx_bss_put(local, bss);
3813 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3814 struct sk_buff *skb)
3816 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3817 struct ieee80211_if_managed *ifmgd;
3818 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3819 struct ieee80211_channel *channel;
3820 size_t baselen, len = skb->len;
3822 ifmgd = &sdata->u.mgd;
3824 sdata_assert_lock(sdata);
3827 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3828 * "If a 6 GHz AP receives a Probe Request frame and responds with
3829 * a Probe Response frame [..], the Address 1 field of the Probe
3830 * Response frame shall be set to the broadcast address [..]"
3831 * So, on 6GHz band we should also accept broadcast responses.
3833 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3838 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3839 (channel->band != NL80211_BAND_6GHZ ||
3840 !is_broadcast_ether_addr(mgmt->da)))
3841 return; /* ignore ProbeResp to foreign address */
3843 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3847 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3849 if (ifmgd->associated &&
3850 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3851 ieee80211_reset_ap_probe(sdata);
3855 * This is the canonical list of information elements we care about,
3856 * the filter code also gives us all changes to the Microsoft OUI
3857 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3858 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3859 * changes to requested client power.
3861 * We implement beacon filtering in software since that means we can
3862 * avoid processing the frame here and in cfg80211, and userspace
3863 * will not be able to tell whether the hardware supports it or not.
3865 * XXX: This list needs to be dynamic -- userspace needs to be able to
3866 * add items it requires. It also needs to be able to tell us to
3867 * look out for other vendor IEs.
3869 static const u64 care_about_ies =
3870 (1ULL << WLAN_EID_COUNTRY) |
3871 (1ULL << WLAN_EID_ERP_INFO) |
3872 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3873 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3874 (1ULL << WLAN_EID_HT_CAPABILITY) |
3875 (1ULL << WLAN_EID_HT_OPERATION) |
3876 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3878 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3879 struct ieee80211_if_managed *ifmgd,
3880 struct ieee80211_bss_conf *bss_conf,
3881 struct ieee80211_local *local,
3882 struct ieee80211_rx_status *rx_status)
3884 /* Track average RSSI from the Beacon frames of the current AP */
3886 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3887 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3888 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3889 ifmgd->last_cqm_event_signal = 0;
3890 ifmgd->count_beacon_signal = 1;
3891 ifmgd->last_ave_beacon_signal = 0;
3893 ifmgd->count_beacon_signal++;
3896 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3898 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3899 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3900 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3901 int last_sig = ifmgd->last_ave_beacon_signal;
3902 struct ieee80211_event event = {
3907 * if signal crosses either of the boundaries, invoke callback
3908 * with appropriate parameters
3910 if (sig > ifmgd->rssi_max_thold &&
3911 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3912 ifmgd->last_ave_beacon_signal = sig;
3913 event.u.rssi.data = RSSI_EVENT_HIGH;
3914 drv_event_callback(local, sdata, &event);
3915 } else if (sig < ifmgd->rssi_min_thold &&
3916 (last_sig >= ifmgd->rssi_max_thold ||
3918 ifmgd->last_ave_beacon_signal = sig;
3919 event.u.rssi.data = RSSI_EVENT_LOW;
3920 drv_event_callback(local, sdata, &event);
3924 if (bss_conf->cqm_rssi_thold &&
3925 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3926 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3927 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3928 int last_event = ifmgd->last_cqm_event_signal;
3929 int thold = bss_conf->cqm_rssi_thold;
3930 int hyst = bss_conf->cqm_rssi_hyst;
3933 (last_event == 0 || sig < last_event - hyst)) {
3934 ifmgd->last_cqm_event_signal = sig;
3935 ieee80211_cqm_rssi_notify(
3937 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3939 } else if (sig > thold &&
3940 (last_event == 0 || sig > last_event + hyst)) {
3941 ifmgd->last_cqm_event_signal = sig;
3942 ieee80211_cqm_rssi_notify(
3944 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3949 if (bss_conf->cqm_rssi_low &&
3950 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3951 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3952 int last_event = ifmgd->last_cqm_event_signal;
3953 int low = bss_conf->cqm_rssi_low;
3954 int high = bss_conf->cqm_rssi_high;
3957 (last_event == 0 || last_event >= low)) {
3958 ifmgd->last_cqm_event_signal = sig;
3959 ieee80211_cqm_rssi_notify(
3961 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3963 } else if (sig > high &&
3964 (last_event == 0 || last_event <= high)) {
3965 ifmgd->last_cqm_event_signal = sig;
3966 ieee80211_cqm_rssi_notify(
3968 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3974 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3975 struct cfg80211_bss *bss)
3977 if (ether_addr_equal(tx_bssid, bss->bssid))
3979 if (!bss->transmitted_bss)
3981 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3984 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3985 struct ieee80211_hdr *hdr, size_t len,
3986 struct ieee80211_rx_status *rx_status)
3988 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3989 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3990 struct ieee80211_mgmt *mgmt = (void *) hdr;
3992 struct ieee802_11_elems *elems;
3993 struct ieee80211_local *local = sdata->local;
3994 struct ieee80211_chanctx_conf *chanctx_conf;
3995 struct ieee80211_channel *chan;
3996 struct sta_info *sta;
4001 u8 *bssid, *variable = mgmt->u.beacon.variable;
4002 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4004 sdata_assert_lock(sdata);
4006 /* Process beacon from the current BSS */
4007 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4008 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4009 struct ieee80211_ext *ext = (void *) mgmt;
4011 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4012 variable = ext->u.s1g_short_beacon.variable;
4014 variable = ext->u.s1g_beacon.variable;
4017 baselen = (u8 *) variable - (u8 *) mgmt;
4022 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4023 if (!chanctx_conf) {
4028 if (ieee80211_rx_status_to_khz(rx_status) !=
4029 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4033 chan = chanctx_conf->def.chan;
4036 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4037 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4038 elems = ieee802_11_parse_elems(variable, len - baselen, false,
4040 ifmgd->assoc_data->bss->bssid);
4044 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4046 if (elems->dtim_period)
4047 ifmgd->dtim_period = elems->dtim_period;
4048 ifmgd->have_beacon = true;
4049 ifmgd->assoc_data->need_beacon = false;
4050 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4051 sdata->vif.bss_conf.sync_tsf =
4052 le64_to_cpu(mgmt->u.beacon.timestamp);
4053 sdata->vif.bss_conf.sync_device_ts =
4054 rx_status->device_timestamp;
4055 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4058 if (elems->mbssid_config_ie)
4059 bss_conf->profile_periodicity =
4060 elems->mbssid_config_ie->profile_periodicity;
4062 bss_conf->profile_periodicity = 0;
4064 if (elems->ext_capab_len >= 11 &&
4065 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4066 bss_conf->ema_ap = true;
4068 bss_conf->ema_ap = false;
4070 /* continue assoc process */
4071 ifmgd->assoc_data->timeout = jiffies;
4072 ifmgd->assoc_data->timeout_started = true;
4073 run_again(sdata, ifmgd->assoc_data->timeout);
4078 if (!ifmgd->associated ||
4079 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4081 bssid = ifmgd->associated->bssid;
4083 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4084 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4087 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4088 mlme_dbg_ratelimited(sdata,
4089 "cancelling AP probe due to a received beacon\n");
4090 ieee80211_reset_ap_probe(sdata);
4094 * Push the beacon loss detection into the future since
4095 * we are processing a beacon from the AP just now.
4097 ieee80211_sta_reset_beacon_monitor(sdata);
4099 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4100 * element (which carries the beacon interval). Don't forget to add a
4101 * bit to care_about_ies[] above if mac80211 is interested in a
4102 * changing S1G element.
4104 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4105 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4106 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
4107 false, care_about_ies, ncrc,
4108 mgmt->bssid, bssid);
4113 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4114 ieee80211_check_tim(elems->tim, elems->tim_len, bss_conf->aid)) {
4115 if (local->hw.conf.dynamic_ps_timeout > 0) {
4116 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4117 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4118 ieee80211_hw_config(local,
4119 IEEE80211_CONF_CHANGE_PS);
4121 ieee80211_send_nullfunc(local, sdata, false);
4122 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4123 local->pspolling = true;
4126 * Here is assumed that the driver will be
4127 * able to send ps-poll frame and receive a
4128 * response even though power save mode is
4129 * enabled, but some drivers might require
4130 * to disable power save here. This needs
4131 * to be investigated.
4133 ieee80211_send_pspoll(local, sdata);
4137 if (sdata->vif.p2p ||
4138 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4139 struct ieee80211_p2p_noa_attr noa = {};
4142 ret = cfg80211_get_p2p_attr(variable,
4144 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4145 (u8 *) &noa, sizeof(noa));
4147 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4148 /* valid noa_attr and index changed */
4149 sdata->u.mgd.p2p_noa_index = noa.index;
4150 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4151 changed |= BSS_CHANGED_P2P_PS;
4153 * make sure we update all information, the CRC
4154 * mechanism doesn't look at P2P attributes.
4156 ifmgd->beacon_crc_valid = false;
4158 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4159 /* noa_attr not found and we had valid noa_attr before */
4160 sdata->u.mgd.p2p_noa_index = -1;
4161 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4162 changed |= BSS_CHANGED_P2P_PS;
4163 ifmgd->beacon_crc_valid = false;
4167 if (ifmgd->csa_waiting_bcn)
4168 ieee80211_chswitch_post_beacon(sdata);
4171 * Update beacon timing and dtim count on every beacon appearance. This
4172 * will allow the driver to use the most updated values. Do it before
4173 * comparing this one with last received beacon.
4174 * IMPORTANT: These parameters would possibly be out of sync by the time
4175 * the driver will use them. The synchronized view is currently
4176 * guaranteed only in certain callbacks.
4178 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4179 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4180 sdata->vif.bss_conf.sync_tsf =
4181 le64_to_cpu(mgmt->u.beacon.timestamp);
4182 sdata->vif.bss_conf.sync_device_ts =
4183 rx_status->device_timestamp;
4184 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4187 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4188 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4190 ifmgd->beacon_crc = ncrc;
4191 ifmgd->beacon_crc_valid = true;
4193 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4195 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4196 rx_status->device_timestamp,
4199 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4200 ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
4201 elems->wmm_param_len,
4202 elems->mu_edca_param_set))
4203 changed |= BSS_CHANGED_QOS;
4206 * If we haven't had a beacon before, tell the driver about the
4207 * DTIM period (and beacon timing if desired) now.
4209 if (!ifmgd->have_beacon) {
4210 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4211 bss_conf->dtim_period = elems->dtim_period ?: 1;
4213 changed |= BSS_CHANGED_BEACON_INFO;
4214 ifmgd->have_beacon = true;
4216 mutex_lock(&local->iflist_mtx);
4217 ieee80211_recalc_ps(local);
4218 mutex_unlock(&local->iflist_mtx);
4220 ieee80211_recalc_ps_vif(sdata);
4223 if (elems->erp_info) {
4225 erp_value = elems->erp_info[0];
4230 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4231 changed |= ieee80211_handle_bss_capability(sdata,
4232 le16_to_cpu(mgmt->u.beacon.capab_info),
4233 erp_valid, erp_value);
4235 mutex_lock(&local->sta_mtx);
4236 sta = sta_info_get(sdata, bssid);
4238 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
4240 if (ieee80211_config_bw(sdata, sta, elems->ht_cap_elem,
4241 elems->vht_cap_elem, elems->ht_operation,
4242 elems->vht_operation, elems->he_operation,
4243 elems->s1g_oper, bssid, &changed)) {
4244 mutex_unlock(&local->sta_mtx);
4246 "failed to follow AP %pM bandwidth change, disconnect\n",
4248 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4249 WLAN_REASON_DEAUTH_LEAVING,
4251 ieee80211_report_disconnect(sdata, deauth_buf,
4252 sizeof(deauth_buf), true,
4253 WLAN_REASON_DEAUTH_LEAVING,
4258 if (sta && elems->opmode_notif)
4259 ieee80211_vht_handle_opmode(sdata, sta, *elems->opmode_notif,
4261 mutex_unlock(&local->sta_mtx);
4263 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4264 elems->country_elem,
4265 elems->country_elem_len,
4266 elems->pwr_constr_elem,
4267 elems->cisco_dtpc_elem);
4269 ieee80211_bss_info_change_notify(sdata, changed);
4274 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4275 struct sk_buff *skb)
4277 struct ieee80211_rx_status *rx_status;
4278 struct ieee80211_hdr *hdr;
4281 rx_status = (struct ieee80211_rx_status *) skb->cb;
4282 hdr = (struct ieee80211_hdr *) skb->data;
4283 fc = le16_to_cpu(hdr->frame_control);
4286 switch (fc & IEEE80211_FCTL_STYPE) {
4287 case IEEE80211_STYPE_S1G_BEACON:
4288 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4291 sdata_unlock(sdata);
4294 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4295 struct sk_buff *skb)
4297 struct ieee80211_rx_status *rx_status;
4298 struct ieee80211_mgmt *mgmt;
4302 rx_status = (struct ieee80211_rx_status *) skb->cb;
4303 mgmt = (struct ieee80211_mgmt *) skb->data;
4304 fc = le16_to_cpu(mgmt->frame_control);
4308 switch (fc & IEEE80211_FCTL_STYPE) {
4309 case IEEE80211_STYPE_BEACON:
4310 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4311 skb->len, rx_status);
4313 case IEEE80211_STYPE_PROBE_RESP:
4314 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4316 case IEEE80211_STYPE_AUTH:
4317 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4319 case IEEE80211_STYPE_DEAUTH:
4320 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4322 case IEEE80211_STYPE_DISASSOC:
4323 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4325 case IEEE80211_STYPE_ASSOC_RESP:
4326 case IEEE80211_STYPE_REASSOC_RESP:
4327 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4329 case IEEE80211_STYPE_ACTION:
4330 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4331 struct ieee802_11_elems *elems;
4333 ies_len = skb->len -
4334 offsetof(struct ieee80211_mgmt,
4335 u.action.u.chan_switch.variable);
4340 /* CSA IE cannot be overridden, no need for BSSID */
4341 elems = ieee802_11_parse_elems(
4342 mgmt->u.action.u.chan_switch.variable,
4343 ies_len, true, mgmt->bssid, NULL);
4345 if (elems && !elems->parse_error)
4346 ieee80211_sta_process_chanswitch(sdata,
4348 rx_status->device_timestamp,
4351 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4352 struct ieee802_11_elems *elems;
4354 ies_len = skb->len -
4355 offsetof(struct ieee80211_mgmt,
4356 u.action.u.ext_chan_switch.variable);
4362 * extended CSA IE can't be overridden, no need for
4365 elems = ieee802_11_parse_elems(
4366 mgmt->u.action.u.ext_chan_switch.variable,
4367 ies_len, true, mgmt->bssid, NULL);
4369 if (elems && !elems->parse_error) {
4370 /* for the handling code pretend it was an IE */
4371 elems->ext_chansw_ie =
4372 &mgmt->u.action.u.ext_chan_switch.data;
4374 ieee80211_sta_process_chanswitch(sdata,
4376 rx_status->device_timestamp,
4384 sdata_unlock(sdata);
4387 static void ieee80211_sta_timer(struct timer_list *t)
4389 struct ieee80211_sub_if_data *sdata =
4390 from_timer(sdata, t, u.mgd.timer);
4392 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4395 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4396 u8 *bssid, u8 reason, bool tx)
4398 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4400 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4403 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4407 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4409 struct ieee80211_local *local = sdata->local;
4410 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4411 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4415 struct ieee80211_prep_tx_info info = {
4416 .subtype = IEEE80211_STYPE_AUTH,
4419 sdata_assert_lock(sdata);
4421 if (WARN_ON_ONCE(!auth_data))
4426 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4427 sdata_info(sdata, "authentication with %pM timed out\n",
4428 auth_data->bss->bssid);
4431 * Most likely AP is not in the range so remove the
4432 * bss struct for that AP.
4434 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4439 if (auth_data->algorithm == WLAN_AUTH_SAE)
4440 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4442 drv_mgd_prepare_tx(local, sdata, &info);
4444 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4445 auth_data->bss->bssid, auth_data->tries,
4446 IEEE80211_AUTH_MAX_TRIES);
4448 auth_data->expected_transaction = 2;
4450 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4451 trans = auth_data->sae_trans;
4452 status = auth_data->sae_status;
4453 auth_data->expected_transaction = trans;
4456 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4457 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4458 IEEE80211_TX_INTFL_MLME_CONN_TX;
4460 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4461 auth_data->data, auth_data->data_len,
4462 auth_data->bss->bssid,
4463 auth_data->bss->bssid, NULL, 0, 0,
4466 if (tx_flags == 0) {
4467 if (auth_data->algorithm == WLAN_AUTH_SAE)
4468 auth_data->timeout = jiffies +
4469 IEEE80211_AUTH_TIMEOUT_SAE;
4471 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4473 auth_data->timeout =
4474 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4477 auth_data->timeout_started = true;
4478 run_again(sdata, auth_data->timeout);
4483 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4485 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4486 struct ieee80211_local *local = sdata->local;
4488 sdata_assert_lock(sdata);
4490 assoc_data->tries++;
4491 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4492 sdata_info(sdata, "association with %pM timed out\n",
4493 assoc_data->bss->bssid);
4496 * Most likely AP is not in the range so remove the
4497 * bss struct for that AP.
4499 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4504 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4505 assoc_data->bss->bssid, assoc_data->tries,
4506 IEEE80211_ASSOC_MAX_TRIES);
4507 ieee80211_send_assoc(sdata);
4509 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4510 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4511 assoc_data->timeout_started = true;
4512 run_again(sdata, assoc_data->timeout);
4514 assoc_data->timeout =
4515 round_jiffies_up(jiffies +
4516 IEEE80211_ASSOC_TIMEOUT_LONG);
4517 assoc_data->timeout_started = true;
4518 run_again(sdata, assoc_data->timeout);
4524 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4525 __le16 fc, bool acked)
4527 struct ieee80211_local *local = sdata->local;
4529 sdata->u.mgd.status_fc = fc;
4530 sdata->u.mgd.status_acked = acked;
4531 sdata->u.mgd.status_received = true;
4533 ieee80211_queue_work(&local->hw, &sdata->work);
4536 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4538 struct ieee80211_local *local = sdata->local;
4539 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4543 if (ifmgd->status_received) {
4544 __le16 fc = ifmgd->status_fc;
4545 bool status_acked = ifmgd->status_acked;
4547 ifmgd->status_received = false;
4548 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4550 if (ifmgd->auth_data->algorithm ==
4552 ifmgd->auth_data->timeout =
4554 IEEE80211_AUTH_TIMEOUT_SAE;
4556 ifmgd->auth_data->timeout =
4558 IEEE80211_AUTH_TIMEOUT_SHORT;
4559 run_again(sdata, ifmgd->auth_data->timeout);
4561 ifmgd->auth_data->timeout = jiffies - 1;
4563 ifmgd->auth_data->timeout_started = true;
4564 } else if (ifmgd->assoc_data &&
4565 (ieee80211_is_assoc_req(fc) ||
4566 ieee80211_is_reassoc_req(fc))) {
4568 ifmgd->assoc_data->timeout =
4569 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4570 run_again(sdata, ifmgd->assoc_data->timeout);
4572 ifmgd->assoc_data->timeout = jiffies - 1;
4574 ifmgd->assoc_data->timeout_started = true;
4578 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4579 time_after(jiffies, ifmgd->auth_data->timeout)) {
4580 if (ifmgd->auth_data->done) {
4582 * ok ... we waited for assoc but userspace didn't,
4583 * so let's just kill the auth data
4585 ieee80211_destroy_auth_data(sdata, false);
4586 } else if (ieee80211_auth(sdata)) {
4588 struct ieee80211_event event = {
4590 .u.mlme.data = AUTH_EVENT,
4591 .u.mlme.status = MLME_TIMEOUT,
4594 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4596 ieee80211_destroy_auth_data(sdata, false);
4598 cfg80211_auth_timeout(sdata->dev, bssid);
4599 drv_event_callback(sdata->local, sdata, &event);
4601 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4602 run_again(sdata, ifmgd->auth_data->timeout);
4604 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4605 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4606 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4607 ieee80211_do_assoc(sdata)) {
4608 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4609 struct ieee80211_event event = {
4611 .u.mlme.data = ASSOC_EVENT,
4612 .u.mlme.status = MLME_TIMEOUT,
4615 ieee80211_destroy_assoc_data(sdata, false, false);
4616 cfg80211_assoc_timeout(sdata->dev, bss);
4617 drv_event_callback(sdata->local, sdata, &event);
4619 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4620 run_again(sdata, ifmgd->assoc_data->timeout);
4622 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4623 ifmgd->associated) {
4627 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4629 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4630 max_tries = max_nullfunc_tries;
4632 max_tries = max_probe_tries;
4634 /* ACK received for nullfunc probing frame */
4635 if (!ifmgd->probe_send_count)
4636 ieee80211_reset_ap_probe(sdata);
4637 else if (ifmgd->nullfunc_failed) {
4638 if (ifmgd->probe_send_count < max_tries) {
4640 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4641 bssid, ifmgd->probe_send_count,
4643 ieee80211_mgd_probe_ap_send(sdata);
4646 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4648 ieee80211_sta_connection_lost(sdata, bssid,
4649 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4652 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4653 run_again(sdata, ifmgd->probe_timeout);
4654 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4656 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4657 bssid, probe_wait_ms);
4658 ieee80211_sta_connection_lost(sdata, bssid,
4659 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4660 } else if (ifmgd->probe_send_count < max_tries) {
4662 "No probe response from AP %pM after %dms, try %d/%i\n",
4663 bssid, probe_wait_ms,
4664 ifmgd->probe_send_count, max_tries);
4665 ieee80211_mgd_probe_ap_send(sdata);
4668 * We actually lost the connection ... or did we?
4672 "No probe response from AP %pM after %dms, disconnecting.\n",
4673 bssid, probe_wait_ms);
4675 ieee80211_sta_connection_lost(sdata, bssid,
4676 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4680 sdata_unlock(sdata);
4683 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4685 struct ieee80211_sub_if_data *sdata =
4686 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4687 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4689 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4692 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4695 sdata->u.mgd.connection_loss = false;
4696 ieee80211_queue_work(&sdata->local->hw,
4697 &sdata->u.mgd.beacon_connection_loss_work);
4700 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4702 struct ieee80211_sub_if_data *sdata =
4703 from_timer(sdata, t, u.mgd.conn_mon_timer);
4704 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4705 struct ieee80211_local *local = sdata->local;
4706 struct sta_info *sta;
4707 unsigned long timeout;
4709 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4712 sta = sta_info_get(sdata, ifmgd->bssid);
4716 timeout = sta->status_stats.last_ack;
4717 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4718 timeout = sta->rx_stats.last_rx;
4719 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4721 /* If timeout is after now, then update timer to fire at
4722 * the later date, but do not actually probe at this time.
4724 if (time_is_after_jiffies(timeout)) {
4725 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4729 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4732 static void ieee80211_sta_monitor_work(struct work_struct *work)
4734 struct ieee80211_sub_if_data *sdata =
4735 container_of(work, struct ieee80211_sub_if_data,
4736 u.mgd.monitor_work);
4738 ieee80211_mgd_probe_ap(sdata, false);
4741 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4743 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4744 __ieee80211_stop_poll(sdata);
4746 /* let's probe the connection once */
4747 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4748 ieee80211_queue_work(&sdata->local->hw,
4749 &sdata->u.mgd.monitor_work);
4754 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4756 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4757 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4761 if (ifmgd->auth_data || ifmgd->assoc_data) {
4762 const u8 *bssid = ifmgd->auth_data ?
4763 ifmgd->auth_data->bss->bssid :
4764 ifmgd->assoc_data->bss->bssid;
4767 * If we are trying to authenticate / associate while suspending,
4768 * cfg80211 won't know and won't actually abort those attempts,
4769 * thus we need to do that ourselves.
4771 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4772 IEEE80211_STYPE_DEAUTH,
4773 WLAN_REASON_DEAUTH_LEAVING,
4775 if (ifmgd->assoc_data)
4776 ieee80211_destroy_assoc_data(sdata, false, true);
4777 if (ifmgd->auth_data)
4778 ieee80211_destroy_auth_data(sdata, false);
4779 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4780 IEEE80211_DEAUTH_FRAME_LEN,
4784 /* This is a bit of a hack - we should find a better and more generic
4785 * solution to this. Normally when suspending, cfg80211 will in fact
4786 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4787 * auth (not so important) or assoc (this is the problem) process.
4789 * As a consequence, it can happen that we are in the process of both
4790 * associating and suspending, and receive an association response
4791 * after cfg80211 has checked if it needs to disconnect, but before
4792 * we actually set the flag to drop incoming frames. This will then
4793 * cause the workqueue flush to process the association response in
4794 * the suspend, resulting in a successful association just before it
4795 * tries to remove the interface from the driver, which now though
4796 * has a channel context assigned ... this results in issues.
4798 * To work around this (for now) simply deauth here again if we're
4801 if (ifmgd->associated && !sdata->local->wowlan) {
4803 struct cfg80211_deauth_request req = {
4804 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4808 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4809 ieee80211_mgd_deauth(sdata, &req);
4812 sdata_unlock(sdata);
4815 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4817 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4820 if (!ifmgd->associated) {
4821 sdata_unlock(sdata);
4825 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4826 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4827 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4828 ieee80211_sta_connection_lost(sdata,
4829 ifmgd->associated->bssid,
4830 WLAN_REASON_UNSPECIFIED,
4832 sdata_unlock(sdata);
4835 sdata_unlock(sdata);
4839 /* interface setup */
4840 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4842 struct ieee80211_if_managed *ifmgd;
4844 ifmgd = &sdata->u.mgd;
4845 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4846 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4847 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4848 ieee80211_beacon_connection_loss_work);
4849 INIT_WORK(&ifmgd->csa_connection_drop_work,
4850 ieee80211_csa_connection_drop_work);
4851 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4852 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4853 ieee80211_tdls_peer_del_work);
4854 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4855 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4856 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4857 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4858 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4859 ieee80211_sta_handle_tspec_ac_params_wk);
4862 ifmgd->powersave = sdata->wdev.ps;
4863 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4864 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4865 ifmgd->p2p_noa_index = -1;
4867 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4868 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4870 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4872 /* Setup TDLS data */
4873 spin_lock_init(&ifmgd->teardown_lock);
4874 ifmgd->teardown_skb = NULL;
4875 ifmgd->orig_teardown_skb = NULL;
4878 /* scan finished notification */
4879 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4881 struct ieee80211_sub_if_data *sdata;
4883 /* Restart STA timers */
4885 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4886 if (ieee80211_sdata_running(sdata))
4887 ieee80211_restart_sta_timer(sdata);
4892 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4893 struct cfg80211_bss *cbss)
4895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4896 const u8 *ht_cap_ie, *vht_cap_ie;
4897 const struct ieee80211_ht_cap *ht_cap;
4898 const struct ieee80211_vht_cap *vht_cap;
4901 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4904 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4905 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4906 ht_cap = (void *)(ht_cap_ie + 2);
4907 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4909 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4910 * "Tx Unequal Modulation Supported" fields.
4914 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4917 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4918 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4922 vht_cap = (void *)(vht_cap_ie + 2);
4923 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4924 for (nss = 8; nss > 0; nss--) {
4925 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4926 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4929 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4930 chains = max(chains, nss);
4937 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4938 struct ieee80211_supported_band *sband,
4939 const struct ieee80211_he_operation *he_op)
4941 const struct ieee80211_sta_he_cap *sta_he_cap =
4942 ieee80211_get_he_iftype_cap(sband,
4943 ieee80211_vif_type_p2p(&sdata->vif));
4947 if (!sta_he_cap || !he_op)
4950 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4952 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4953 for (i = 0; i < 3; i++) {
4954 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4955 &sta_he_cap->he_mcs_nss_supp;
4956 u16 sta_mcs_map_rx =
4957 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4958 u16 sta_mcs_map_tx =
4959 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4961 bool verified = true;
4964 * For each band there is a maximum of 8 spatial streams
4965 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4966 * of 2 bits per NSS (1-8), with the values defined in enum
4967 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4968 * capabilities aren't less than the AP's minimum requirements
4969 * for this HE BSS per SS.
4970 * It is enough to find one such band that meets the reqs.
4972 for (nss = 8; nss > 0; nss--) {
4973 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4974 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4975 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4977 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4981 * Make sure the HE AP doesn't require MCSs that aren't
4982 * supported by the client
4984 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4985 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4986 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4996 /* If here, STA doesn't meet AP's HE min requirements */
5000 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5001 struct cfg80211_bss *cbss)
5003 struct ieee80211_local *local = sdata->local;
5004 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5005 const struct ieee80211_ht_cap *ht_cap = NULL;
5006 const struct ieee80211_ht_operation *ht_oper = NULL;
5007 const struct ieee80211_vht_operation *vht_oper = NULL;
5008 const struct ieee80211_he_operation *he_oper = NULL;
5009 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
5010 struct ieee80211_supported_band *sband;
5011 struct cfg80211_chan_def chandef;
5012 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5013 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
5014 struct ieee80211_bss *bss = (void *)cbss->priv;
5015 struct ieee802_11_elems *elems;
5016 const struct cfg80211_bss_ies *ies;
5023 ies = rcu_dereference(cbss->ies);
5024 elems = ieee802_11_parse_elems(ies->data, ies->len, false,
5031 sband = local->hw.wiphy->bands[cbss->channel->band];
5033 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5034 IEEE80211_STA_DISABLE_80P80MHZ |
5035 IEEE80211_STA_DISABLE_160MHZ);
5037 /* disable HT/VHT/HE if we don't support them */
5038 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5039 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5040 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5041 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5044 if (!sband->vht_cap.vht_supported && is_5ghz) {
5045 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5046 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5049 if (!ieee80211_get_he_iftype_cap(sband,
5050 ieee80211_vif_type_p2p(&sdata->vif)))
5051 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5053 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5054 ht_oper = elems->ht_operation;
5055 ht_cap = elems->ht_cap_elem;
5058 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5063 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5064 vht_oper = elems->vht_operation;
5065 if (vht_oper && !ht_oper) {
5068 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5069 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5070 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5071 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5074 if (!elems->vht_cap_elem) {
5075 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5080 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5081 he_oper = elems->he_operation;
5084 struct ieee80211_bss_conf *bss_conf;
5087 bss_conf = &sdata->vif.bss_conf;
5089 if (elems->pwr_constr_elem)
5090 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
5092 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
5093 ARRAY_SIZE(elems->tx_pwr_env));
5095 for (i = 0; i < elems->tx_pwr_env_num; i++) {
5096 if (elems->tx_pwr_env_len[i] >
5097 sizeof(bss_conf->tx_pwr_env[j]))
5100 bss_conf->tx_pwr_env_num++;
5101 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
5102 elems->tx_pwr_env_len[i]);
5107 if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5108 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5111 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5113 for (i = 0; i < sband->n_channels; i++) {
5114 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5115 IEEE80211_CHAN_NO_80MHZ))
5123 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5125 if (sband->band == NL80211_BAND_S1GHZ) {
5126 s1g_oper = elems->s1g_oper;
5129 "AP missing S1G operation element?\n");
5132 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5135 ht_oper, vht_oper, he_oper,
5139 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5143 /* the element data was RCU protected so no longer valid anyway */
5147 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5148 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5152 /* will change later if needed */
5153 sdata->smps_mode = IEEE80211_SMPS_OFF;
5155 mutex_lock(&local->mtx);
5157 * If this fails (possibly due to channel context sharing
5158 * on incompatible channels, e.g. 80+80 and 160 sharing the
5159 * same control channel) try to use a smaller bandwidth.
5161 ret = ieee80211_vif_use_channel(sdata, &chandef,
5162 IEEE80211_CHANCTX_SHARED);
5164 /* don't downgrade for 5 and 10 MHz channels, though. */
5165 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5166 chandef.width == NL80211_CHAN_WIDTH_10)
5169 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5170 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5171 ret = ieee80211_vif_use_channel(sdata, &chandef,
5172 IEEE80211_CHANCTX_SHARED);
5175 mutex_unlock(&local->mtx);
5179 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5180 u8 *dtim_count, u8 *dtim_period)
5182 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5183 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5185 const struct ieee80211_tim_ie *tim = NULL;
5186 const struct ieee80211_bssid_index *idx;
5187 bool valid = tim_ie && tim_ie[1] >= 2;
5190 tim = (void *)(tim_ie + 2);
5193 *dtim_count = valid ? tim->dtim_count : 0;
5196 *dtim_period = valid ? tim->dtim_period : 0;
5198 /* Check if value is overridden by non-transmitted profile */
5199 if (!idx_ie || idx_ie[1] < 3)
5202 idx = (void *)(idx_ie + 2);
5205 *dtim_count = idx->dtim_count;
5208 *dtim_period = idx->dtim_period;
5213 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5214 struct cfg80211_bss *cbss, bool assoc,
5217 struct ieee80211_local *local = sdata->local;
5218 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5219 struct ieee80211_bss *bss = (void *)cbss->priv;
5220 struct sta_info *new_sta = NULL;
5221 struct ieee80211_supported_band *sband;
5222 bool have_sta = false;
5225 sband = local->hw.wiphy->bands[cbss->channel->band];
5227 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5230 /* If a reconfig is happening, bail out */
5231 if (local->in_reconfig)
5236 have_sta = sta_info_get(sdata, cbss->bssid);
5241 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5247 * Set up the information for the new channel before setting the
5248 * new channel. We can't - completely race-free - change the basic
5249 * rates bitmap and the channel (sband) that it refers to, but if
5250 * we set it up before we at least avoid calling into the driver's
5251 * bss_info_changed() method with invalid information (since we do
5252 * call that from changing the channel - only for IDLE and perhaps
5253 * some others, but ...).
5255 * So to avoid that, just set up all the new information before the
5256 * channel, but tell the driver to apply it only afterwards, since
5257 * it might need the new channel for that.
5260 u32 rates = 0, basic_rates = 0;
5261 bool have_higher_than_11mbit;
5262 int min_rate = INT_MAX, min_rate_index = -1;
5263 const struct cfg80211_bss_ies *ies;
5264 int shift = ieee80211_vif_get_shift(&sdata->vif);
5266 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5267 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5268 ieee80211_s1g_sta_rate_init(new_sta);
5272 ieee80211_get_rates(sband, bss->supp_rates,
5273 bss->supp_rates_len,
5274 &rates, &basic_rates,
5275 &have_higher_than_11mbit,
5276 &min_rate, &min_rate_index,
5280 * This used to be a workaround for basic rates missing
5281 * in the association response frame. Now that we no
5282 * longer use the basic rates from there, it probably
5283 * doesn't happen any more, but keep the workaround so
5284 * in case some *other* APs are buggy in different ways
5285 * we can connect -- with a warning.
5286 * Allow this workaround only in case the AP provided at least
5289 if (min_rate_index < 0) {
5291 "No legacy rates in association response\n");
5293 sta_info_free(local, new_sta);
5295 } else if (!basic_rates) {
5297 "No basic rates, using min rate instead\n");
5298 basic_rates = BIT(min_rate_index);
5302 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5305 "No rates found, keeping mandatory only\n");
5307 sdata->vif.bss_conf.basic_rates = basic_rates;
5309 /* cf. IEEE 802.11 9.2.12 */
5310 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5311 have_higher_than_11mbit)
5312 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5314 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5317 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5319 /* set timing information */
5320 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5322 ies = rcu_dereference(cbss->beacon_ies);
5324 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5325 sdata->vif.bss_conf.sync_device_ts =
5326 bss->device_ts_beacon;
5328 ieee80211_get_dtim(ies,
5329 &sdata->vif.bss_conf.sync_dtim_count,
5331 } else if (!ieee80211_hw_check(&sdata->local->hw,
5332 TIMING_BEACON_ONLY)) {
5333 ies = rcu_dereference(cbss->proberesp_ies);
5334 /* must be non-NULL since beacon IEs were NULL */
5335 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5336 sdata->vif.bss_conf.sync_device_ts =
5337 bss->device_ts_presp;
5338 sdata->vif.bss_conf.sync_dtim_count = 0;
5340 sdata->vif.bss_conf.sync_tsf = 0;
5341 sdata->vif.bss_conf.sync_device_ts = 0;
5342 sdata->vif.bss_conf.sync_dtim_count = 0;
5347 if (new_sta || override) {
5348 err = ieee80211_prep_channel(sdata, cbss);
5351 sta_info_free(local, new_sta);
5358 * tell driver about BSSID, basic rates and timing
5359 * this was set up above, before setting the channel
5361 ieee80211_bss_info_change_notify(sdata,
5362 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5363 BSS_CHANGED_BEACON_INT);
5366 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5368 err = sta_info_insert(new_sta);
5372 "failed to insert STA entry for the AP (error %d)\n",
5377 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5379 /* Cancel scan to ensure that nothing interferes with connection */
5380 if (local->scanning)
5381 ieee80211_scan_cancel(local);
5387 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5388 struct cfg80211_auth_request *req)
5390 struct ieee80211_local *local = sdata->local;
5391 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5392 struct ieee80211_mgd_auth_data *auth_data;
5397 /* prepare auth data structure */
5399 switch (req->auth_type) {
5400 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5401 auth_alg = WLAN_AUTH_OPEN;
5403 case NL80211_AUTHTYPE_SHARED_KEY:
5406 auth_alg = WLAN_AUTH_SHARED_KEY;
5408 case NL80211_AUTHTYPE_FT:
5409 auth_alg = WLAN_AUTH_FT;
5411 case NL80211_AUTHTYPE_NETWORK_EAP:
5412 auth_alg = WLAN_AUTH_LEAP;
5414 case NL80211_AUTHTYPE_SAE:
5415 auth_alg = WLAN_AUTH_SAE;
5417 case NL80211_AUTHTYPE_FILS_SK:
5418 auth_alg = WLAN_AUTH_FILS_SK;
5420 case NL80211_AUTHTYPE_FILS_SK_PFS:
5421 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5423 case NL80211_AUTHTYPE_FILS_PK:
5424 auth_alg = WLAN_AUTH_FILS_PK;
5430 if (ifmgd->assoc_data)
5433 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5434 req->ie_len, GFP_KERNEL);
5438 auth_data->bss = req->bss;
5440 if (req->auth_data_len >= 4) {
5441 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5442 __le16 *pos = (__le16 *) req->auth_data;
5444 auth_data->sae_trans = le16_to_cpu(pos[0]);
5445 auth_data->sae_status = le16_to_cpu(pos[1]);
5447 memcpy(auth_data->data, req->auth_data + 4,
5448 req->auth_data_len - 4);
5449 auth_data->data_len += req->auth_data_len - 4;
5452 /* Check if continuing authentication or trying to authenticate with the
5453 * same BSS that we were in the process of authenticating with and avoid
5454 * removal and re-addition of the STA entry in
5455 * ieee80211_prep_connection().
5457 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5459 if (req->ie && req->ie_len) {
5460 memcpy(&auth_data->data[auth_data->data_len],
5461 req->ie, req->ie_len);
5462 auth_data->data_len += req->ie_len;
5465 if (req->key && req->key_len) {
5466 auth_data->key_len = req->key_len;
5467 auth_data->key_idx = req->key_idx;
5468 memcpy(auth_data->key, req->key, req->key_len);
5471 auth_data->algorithm = auth_alg;
5473 /* try to authenticate/probe */
5475 if (ifmgd->auth_data) {
5476 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5477 auth_data->peer_confirmed =
5478 ifmgd->auth_data->peer_confirmed;
5480 ieee80211_destroy_auth_data(sdata, cont_auth);
5483 /* prep auth_data so we don't go into idle on disassoc */
5484 ifmgd->auth_data = auth_data;
5486 /* If this is continuation of an ongoing SAE authentication exchange
5487 * (i.e., request to send SAE Confirm) and the peer has already
5488 * confirmed, mark authentication completed since we are about to send
5491 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5492 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5493 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5495 if (ifmgd->associated) {
5496 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5499 "disconnect from AP %pM for new auth to %pM\n",
5500 ifmgd->associated->bssid, req->bss->bssid);
5501 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5502 WLAN_REASON_UNSPECIFIED,
5505 ieee80211_report_disconnect(sdata, frame_buf,
5506 sizeof(frame_buf), true,
5507 WLAN_REASON_UNSPECIFIED,
5511 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5513 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5517 err = ieee80211_auth(sdata);
5519 sta_info_destroy_addr(sdata, req->bss->bssid);
5523 /* hold our own reference */
5524 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5528 eth_zero_addr(ifmgd->bssid);
5529 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5530 ifmgd->auth_data = NULL;
5531 mutex_lock(&sdata->local->mtx);
5532 ieee80211_vif_release_channel(sdata);
5533 mutex_unlock(&sdata->local->mtx);
5538 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5539 struct cfg80211_assoc_request *req)
5541 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5542 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5543 struct ieee80211_local *local = sdata->local;
5544 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5545 struct ieee80211_bss *bss = (void *)req->bss->priv;
5546 struct ieee80211_mgd_assoc_data *assoc_data;
5547 const struct cfg80211_bss_ies *beacon_ies;
5548 struct ieee80211_supported_band *sband;
5549 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5550 const struct element *ssid_elem, *ht_elem, *vht_elem;
5552 bool override = false;
5554 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5559 ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID);
5560 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
5565 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
5566 assoc_data->ssid_len = ssid_elem->datalen;
5567 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5568 bss_conf->ssid_len = assoc_data->ssid_len;
5571 if (ifmgd->associated) {
5572 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5575 "disconnect from AP %pM for new assoc to %pM\n",
5576 ifmgd->associated->bssid, req->bss->bssid);
5577 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5578 WLAN_REASON_UNSPECIFIED,
5581 ieee80211_report_disconnect(sdata, frame_buf,
5582 sizeof(frame_buf), true,
5583 WLAN_REASON_UNSPECIFIED,
5587 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5592 if (ifmgd->assoc_data) {
5597 if (ifmgd->auth_data) {
5600 /* keep sta info, bssid if matching */
5601 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5602 ieee80211_destroy_auth_data(sdata, match);
5605 /* prepare assoc data */
5607 ifmgd->beacon_crc_valid = false;
5609 assoc_data->wmm = bss->wmm_used &&
5610 (local->hw.queues >= IEEE80211_NUM_ACS);
5613 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5614 * We still associate in non-HT mode (11a/b/g) if any one of these
5615 * ciphers is configured as pairwise.
5616 * We can set this to true for non-11n hardware, that'll be checked
5617 * separately along with the peer capabilities.
5619 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5620 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5621 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5622 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5623 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5624 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5625 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5626 netdev_info(sdata->dev,
5627 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5631 sband = local->hw.wiphy->bands[req->bss->channel->band];
5633 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5634 if (!bss->wmm_used) {
5635 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5636 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5637 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5638 netdev_info(sdata->dev,
5639 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5642 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5643 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5644 sizeof(ifmgd->ht_capa_mask));
5646 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5647 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5648 sizeof(ifmgd->vht_capa_mask));
5650 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5651 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5652 sizeof(ifmgd->s1g_capa_mask));
5654 if (req->ie && req->ie_len) {
5655 memcpy(assoc_data->ie, req->ie, req->ie_len);
5656 assoc_data->ie_len = req->ie_len;
5659 if (req->fils_kek) {
5660 /* should already be checked in cfg80211 - so warn */
5661 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5665 memcpy(assoc_data->fils_kek, req->fils_kek,
5667 assoc_data->fils_kek_len = req->fils_kek_len;
5670 if (req->fils_nonces)
5671 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5672 2 * FILS_NONCE_LEN);
5674 assoc_data->bss = req->bss;
5675 assoc_data->capability = req->bss->capability;
5676 assoc_data->supp_rates = bss->supp_rates;
5677 assoc_data->supp_rates_len = bss->supp_rates_len;
5680 ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION);
5681 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
5682 assoc_data->ap_ht_param =
5683 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
5685 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5686 vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY);
5687 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap))
5688 memcpy(&assoc_data->ap_vht_cap, vht_elem->data,
5689 sizeof(struct ieee80211_vht_cap));
5691 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5692 IEEE80211_STA_DISABLE_HE;
5695 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5696 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5697 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5698 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5700 if (bss->wmm_used && bss->uapsd_supported &&
5701 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5702 assoc_data->uapsd = true;
5703 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5705 assoc_data->uapsd = false;
5706 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5709 if (req->prev_bssid)
5710 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5713 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5714 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5716 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5717 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5720 if (req->flags & ASSOC_REQ_USE_RRM)
5721 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5723 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5725 if (req->crypto.control_port)
5726 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5728 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5730 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5731 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5732 sdata->control_port_over_nl80211 =
5733 req->crypto.control_port_over_nl80211;
5734 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5735 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5738 /* kick off associate process */
5740 ifmgd->assoc_data = assoc_data;
5741 ifmgd->dtim_period = 0;
5742 ifmgd->have_beacon = false;
5744 /* override HT/VHT configuration only if the AP and we support it */
5745 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5746 struct ieee80211_sta_ht_cap sta_ht_cap;
5748 if (req->flags & ASSOC_REQ_DISABLE_HT)
5751 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5752 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5754 /* check for 40 MHz disable override */
5755 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5756 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5757 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5760 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5761 req->flags & ASSOC_REQ_DISABLE_VHT)
5765 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5766 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5767 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5768 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5771 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5772 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5774 if (req->flags & ASSOC_REQ_DISABLE_HE)
5775 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5777 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5781 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5782 if (ifmgd->powersave)
5783 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5785 sdata->smps_mode = IEEE80211_SMPS_OFF;
5787 sdata->smps_mode = ifmgd->req_smps;
5791 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5793 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5796 * Wait up to one beacon interval ...
5797 * should this be more if we miss one?
5799 sdata_info(sdata, "waiting for beacon from %pM\n",
5801 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5802 assoc_data->timeout_started = true;
5803 assoc_data->need_beacon = true;
5804 } else if (beacon_ies) {
5805 const struct element *elem;
5808 ieee80211_get_dtim(beacon_ies, &dtim_count,
5809 &ifmgd->dtim_period);
5811 ifmgd->have_beacon = true;
5812 assoc_data->timeout = jiffies;
5813 assoc_data->timeout_started = true;
5815 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5816 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5817 sdata->vif.bss_conf.sync_device_ts =
5818 bss->device_ts_beacon;
5819 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5822 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5823 beacon_ies->data, beacon_ies->len);
5824 if (elem && elem->datalen >= 3)
5825 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5827 sdata->vif.bss_conf.profile_periodicity = 0;
5829 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5830 beacon_ies->data, beacon_ies->len);
5831 if (elem && elem->datalen >= 11 &&
5832 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5833 sdata->vif.bss_conf.ema_ap = true;
5835 sdata->vif.bss_conf.ema_ap = false;
5837 assoc_data->timeout = jiffies;
5838 assoc_data->timeout_started = true;
5842 run_again(sdata, assoc_data->timeout);
5844 if (bss->corrupt_data) {
5845 char *corrupt_type = "data";
5846 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5847 if (bss->corrupt_data &
5848 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5849 corrupt_type = "beacon and probe response";
5851 corrupt_type = "beacon";
5852 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5853 corrupt_type = "probe response";
5854 sdata_info(sdata, "associating with AP with corrupt %s\n",
5860 eth_zero_addr(ifmgd->bssid);
5861 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5862 ifmgd->assoc_data = NULL;
5868 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5869 struct cfg80211_deauth_request *req)
5871 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5872 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5873 bool tx = !req->local_state_change;
5874 struct ieee80211_prep_tx_info info = {
5875 .subtype = IEEE80211_STYPE_DEAUTH,
5878 if (ifmgd->auth_data &&
5879 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5881 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5882 req->bssid, req->reason_code,
5883 ieee80211_get_reason_code_string(req->reason_code));
5885 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5886 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5887 IEEE80211_STYPE_DEAUTH,
5888 req->reason_code, tx,
5890 ieee80211_destroy_auth_data(sdata, false);
5891 ieee80211_report_disconnect(sdata, frame_buf,
5892 sizeof(frame_buf), true,
5893 req->reason_code, false);
5894 drv_mgd_complete_tx(sdata->local, sdata, &info);
5898 if (ifmgd->assoc_data &&
5899 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5901 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5902 req->bssid, req->reason_code,
5903 ieee80211_get_reason_code_string(req->reason_code));
5905 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5906 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5907 IEEE80211_STYPE_DEAUTH,
5908 req->reason_code, tx,
5910 ieee80211_destroy_assoc_data(sdata, false, true);
5911 ieee80211_report_disconnect(sdata, frame_buf,
5912 sizeof(frame_buf), true,
5913 req->reason_code, false);
5917 if (ifmgd->associated &&
5918 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5920 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5921 req->bssid, req->reason_code,
5922 ieee80211_get_reason_code_string(req->reason_code));
5924 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5925 req->reason_code, tx, frame_buf);
5926 ieee80211_report_disconnect(sdata, frame_buf,
5927 sizeof(frame_buf), true,
5928 req->reason_code, false);
5929 drv_mgd_complete_tx(sdata->local, sdata, &info);
5936 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5937 struct cfg80211_disassoc_request *req)
5939 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5941 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5944 * cfg80211 should catch this ... but it's racy since
5945 * we can receive a disassoc frame, process it, hand it
5946 * to cfg80211 while that's in a locked section already
5947 * trying to tell us that the user wants to disconnect.
5949 if (ifmgd->associated != req->bss)
5953 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5954 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5956 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5957 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5958 req->reason_code, !req->local_state_change,
5961 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5962 req->reason_code, false);
5967 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5969 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5972 * Make sure some work items will not run after this,
5973 * they will not do anything but might not have been
5974 * cancelled when disconnecting.
5976 cancel_work_sync(&ifmgd->monitor_work);
5977 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5978 cancel_work_sync(&ifmgd->request_smps_work);
5979 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5980 cancel_work_sync(&ifmgd->chswitch_work);
5981 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5984 if (ifmgd->assoc_data) {
5985 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5986 ieee80211_destroy_assoc_data(sdata, false, false);
5987 cfg80211_assoc_timeout(sdata->dev, bss);
5989 if (ifmgd->auth_data)
5990 ieee80211_destroy_auth_data(sdata, false);
5991 spin_lock_bh(&ifmgd->teardown_lock);
5992 if (ifmgd->teardown_skb) {
5993 kfree_skb(ifmgd->teardown_skb);
5994 ifmgd->teardown_skb = NULL;
5995 ifmgd->orig_teardown_skb = NULL;
5997 kfree(ifmgd->assoc_req_ies);
5998 ifmgd->assoc_req_ies = NULL;
5999 ifmgd->assoc_req_ies_len = 0;
6000 spin_unlock_bh(&ifmgd->teardown_lock);
6001 del_timer_sync(&ifmgd->timer);
6002 sdata_unlock(sdata);
6005 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
6006 enum nl80211_cqm_rssi_threshold_event rssi_event,
6010 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6012 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
6014 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
6016 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
6018 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
6020 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6022 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
6024 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
6026 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);