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;
2457 struct ieee80211_sta_tx_tspec *tx_tspec;
2458 unsigned long now = jiffies;
2460 if (!ieee80211_is_data_qos(hdr->frame_control))
2463 tid = ieee80211_get_tid(hdr);
2464 ac = ieee80211_ac_from_tid(tid);
2465 tx_tspec = &ifmgd->tx_tspec[ac];
2467 if (likely(!tx_tspec->admitted_time))
2470 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2471 tx_tspec->consumed_tx_time = 0;
2472 tx_tspec->time_slice_start = now;
2474 if (tx_tspec->downgraded) {
2475 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2476 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2480 if (tx_tspec->downgraded)
2483 tx_tspec->consumed_tx_time += tx_time;
2485 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2486 tx_tspec->downgraded = true;
2487 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2488 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2492 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2493 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2495 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2497 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2498 !sdata->u.mgd.probe_send_count)
2502 sdata->u.mgd.probe_send_count = 0;
2504 sdata->u.mgd.nullfunc_failed = true;
2505 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2508 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2509 const u8 *src, const u8 *dst,
2510 const u8 *ssid, size_t ssid_len,
2511 struct ieee80211_channel *channel)
2513 struct sk_buff *skb;
2515 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2516 ssid, ssid_len, NULL, 0,
2517 IEEE80211_PROBE_FLAG_DIRECTED);
2519 ieee80211_tx_skb(sdata, skb);
2522 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2524 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2525 const struct element *ssid;
2526 u8 *dst = ifmgd->associated->bssid;
2527 u8 unicast_limit = max(1, max_probe_tries - 3);
2528 struct sta_info *sta;
2531 * Try sending broadcast probe requests for the last three
2532 * probe requests after the first ones failed since some
2533 * buggy APs only support broadcast probe requests.
2535 if (ifmgd->probe_send_count >= unicast_limit)
2539 * When the hardware reports an accurate Tx ACK status, it's
2540 * better to send a nullfunc frame instead of a probe request,
2541 * as it will kick us off the AP quickly if we aren't associated
2542 * anymore. The timeout will be reset if the frame is ACKed by
2545 ifmgd->probe_send_count++;
2548 mutex_lock(&sdata->local->sta_mtx);
2549 sta = sta_info_get(sdata, dst);
2551 ieee80211_check_fast_rx(sta);
2552 mutex_unlock(&sdata->local->sta_mtx);
2555 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2556 ifmgd->nullfunc_failed = false;
2557 ieee80211_send_nullfunc(sdata->local, sdata, false);
2562 ssid = ieee80211_bss_get_elem(ifmgd->associated, WLAN_EID_SSID);
2563 if (WARN_ON_ONCE(ssid == NULL))
2566 ssid_len = ssid->datalen;
2568 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2569 ssid->data, ssid_len,
2570 ifmgd->associated->channel);
2574 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2575 run_again(sdata, ifmgd->probe_timeout);
2578 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2581 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2582 bool already = false;
2584 if (!ieee80211_sdata_running(sdata))
2589 if (!ifmgd->associated)
2592 mutex_lock(&sdata->local->mtx);
2594 if (sdata->local->tmp_channel || sdata->local->scanning) {
2595 mutex_unlock(&sdata->local->mtx);
2599 if (sdata->local->suspending) {
2600 /* reschedule after resume */
2601 mutex_unlock(&sdata->local->mtx);
2602 ieee80211_reset_ap_probe(sdata);
2607 mlme_dbg_ratelimited(sdata,
2608 "detected beacon loss from AP (missed %d beacons) - probing\n",
2611 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2615 * The driver/our work has already reported this event or the
2616 * connection monitoring has kicked in and we have already sent
2617 * a probe request. Or maybe the AP died and the driver keeps
2618 * reporting until we disassociate...
2620 * In either case we have to ignore the current call to this
2621 * function (except for setting the correct probe reason bit)
2622 * because otherwise we would reset the timer every time and
2623 * never check whether we received a probe response!
2625 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2628 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2630 mutex_unlock(&sdata->local->mtx);
2635 mutex_lock(&sdata->local->iflist_mtx);
2636 ieee80211_recalc_ps(sdata->local);
2637 mutex_unlock(&sdata->local->iflist_mtx);
2639 ifmgd->probe_send_count = 0;
2640 ieee80211_mgd_probe_ap_send(sdata);
2642 sdata_unlock(sdata);
2645 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2646 struct ieee80211_vif *vif)
2648 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2649 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2650 struct cfg80211_bss *cbss;
2651 struct sk_buff *skb;
2652 const struct element *ssid;
2655 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2658 sdata_assert_lock(sdata);
2660 if (ifmgd->associated)
2661 cbss = ifmgd->associated;
2662 else if (ifmgd->auth_data)
2663 cbss = ifmgd->auth_data->bss;
2664 else if (ifmgd->assoc_data)
2665 cbss = ifmgd->assoc_data->bss;
2670 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
2671 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
2672 "invalid SSID element (len=%d)",
2673 ssid ? ssid->datalen : -1))
2676 ssid_len = ssid->datalen;
2678 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2679 (u32) -1, cbss->channel,
2680 ssid->data, ssid_len,
2681 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2686 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2688 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2689 const u8 *buf, size_t len, bool tx,
2690 u16 reason, bool reconnect)
2692 struct ieee80211_event event = {
2694 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2695 .u.mlme.reason = reason,
2699 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2701 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2703 drv_event_callback(sdata->local, sdata, &event);
2706 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2708 struct ieee80211_local *local = sdata->local;
2709 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2710 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2714 if (!ifmgd->associated) {
2715 sdata_unlock(sdata);
2719 tx = !sdata->csa_block_tx;
2721 if (!ifmgd->driver_disconnect) {
2723 * AP is probably out of range (or not reachable for another
2724 * reason) so remove the bss struct for that AP.
2726 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2729 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2730 ifmgd->driver_disconnect ?
2731 WLAN_REASON_DEAUTH_LEAVING :
2732 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2734 mutex_lock(&local->mtx);
2735 sdata->vif.csa_active = false;
2736 ifmgd->csa_waiting_bcn = false;
2737 if (sdata->csa_block_tx) {
2738 ieee80211_wake_vif_queues(local, sdata,
2739 IEEE80211_QUEUE_STOP_REASON_CSA);
2740 sdata->csa_block_tx = false;
2742 mutex_unlock(&local->mtx);
2744 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2745 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2747 ifmgd->reconnect = false;
2749 sdata_unlock(sdata);
2752 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2754 struct ieee80211_sub_if_data *sdata =
2755 container_of(work, struct ieee80211_sub_if_data,
2756 u.mgd.beacon_connection_loss_work);
2757 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2759 if (ifmgd->associated)
2760 ifmgd->beacon_loss_count++;
2762 if (ifmgd->connection_loss) {
2763 sdata_info(sdata, "Connection to AP %pM lost\n",
2765 __ieee80211_disconnect(sdata);
2766 ifmgd->connection_loss = false;
2767 } else if (ifmgd->driver_disconnect) {
2769 "Driver requested disconnection from AP %pM\n",
2771 __ieee80211_disconnect(sdata);
2772 ifmgd->driver_disconnect = false;
2774 ieee80211_mgd_probe_ap(sdata, true);
2778 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2780 struct ieee80211_sub_if_data *sdata =
2781 container_of(work, struct ieee80211_sub_if_data,
2782 u.mgd.csa_connection_drop_work);
2784 __ieee80211_disconnect(sdata);
2787 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2789 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2790 struct ieee80211_hw *hw = &sdata->local->hw;
2792 trace_api_beacon_loss(sdata);
2794 sdata->u.mgd.connection_loss = false;
2795 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2797 EXPORT_SYMBOL(ieee80211_beacon_loss);
2799 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2801 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2802 struct ieee80211_hw *hw = &sdata->local->hw;
2804 trace_api_connection_loss(sdata);
2806 sdata->u.mgd.connection_loss = true;
2807 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2809 EXPORT_SYMBOL(ieee80211_connection_loss);
2811 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2813 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2814 struct ieee80211_hw *hw = &sdata->local->hw;
2816 trace_api_disconnect(sdata, reconnect);
2818 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2821 sdata->u.mgd.driver_disconnect = true;
2822 sdata->u.mgd.reconnect = reconnect;
2823 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2825 EXPORT_SYMBOL(ieee80211_disconnect);
2827 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2830 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2832 sdata_assert_lock(sdata);
2836 * we are not authenticated yet, the only timer that could be
2837 * running is the timeout for the authentication response which
2838 * which is not relevant anymore.
2840 del_timer_sync(&sdata->u.mgd.timer);
2841 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2843 eth_zero_addr(sdata->u.mgd.bssid);
2844 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2845 sdata->u.mgd.flags = 0;
2846 mutex_lock(&sdata->local->mtx);
2847 ieee80211_vif_release_channel(sdata);
2848 mutex_unlock(&sdata->local->mtx);
2851 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2853 sdata->u.mgd.auth_data = NULL;
2856 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2857 bool assoc, bool abandon)
2859 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2861 sdata_assert_lock(sdata);
2865 * we are not associated yet, the only timer that could be
2866 * running is the timeout for the association response which
2867 * which is not relevant anymore.
2869 del_timer_sync(&sdata->u.mgd.timer);
2870 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2872 eth_zero_addr(sdata->u.mgd.bssid);
2873 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2874 sdata->u.mgd.flags = 0;
2875 sdata->vif.mu_mimo_owner = false;
2877 mutex_lock(&sdata->local->mtx);
2878 ieee80211_vif_release_channel(sdata);
2879 mutex_unlock(&sdata->local->mtx);
2882 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2886 sdata->u.mgd.assoc_data = NULL;
2889 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2890 struct ieee80211_mgmt *mgmt, size_t len)
2892 struct ieee80211_local *local = sdata->local;
2893 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2894 const struct element *challenge;
2897 struct ieee80211_prep_tx_info info = {
2898 .subtype = IEEE80211_STYPE_AUTH,
2901 pos = mgmt->u.auth.variable;
2902 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
2903 len - (pos - (u8 *)mgmt));
2906 auth_data->expected_transaction = 4;
2907 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2908 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2909 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2910 IEEE80211_TX_INTFL_MLME_CONN_TX;
2911 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2913 challenge->datalen + sizeof(*challenge),
2914 auth_data->bss->bssid, auth_data->bss->bssid,
2915 auth_data->key, auth_data->key_len,
2916 auth_data->key_idx, tx_flags);
2919 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2922 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2923 struct sta_info *sta;
2926 sdata_info(sdata, "authenticated\n");
2927 ifmgd->auth_data->done = true;
2928 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2929 ifmgd->auth_data->timeout_started = true;
2930 run_again(sdata, ifmgd->auth_data->timeout);
2932 /* move station state to auth */
2933 mutex_lock(&sdata->local->sta_mtx);
2934 sta = sta_info_get(sdata, bssid);
2936 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2940 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2941 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2947 mutex_unlock(&sdata->local->sta_mtx);
2951 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2952 struct ieee80211_mgmt *mgmt, size_t len)
2954 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2956 u16 auth_alg, auth_transaction, status_code;
2957 struct ieee80211_event event = {
2959 .u.mlme.data = AUTH_EVENT,
2961 struct ieee80211_prep_tx_info info = {
2962 .subtype = IEEE80211_STYPE_AUTH,
2965 sdata_assert_lock(sdata);
2970 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2973 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2975 if (!ether_addr_equal(bssid, mgmt->bssid))
2978 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2979 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2980 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2982 if (auth_alg != ifmgd->auth_data->algorithm ||
2983 (auth_alg != WLAN_AUTH_SAE &&
2984 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2985 (auth_alg == WLAN_AUTH_SAE &&
2986 (auth_transaction < ifmgd->auth_data->expected_transaction ||
2987 auth_transaction > 2))) {
2988 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
2989 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
2991 ifmgd->auth_data->expected_transaction);
2995 if (status_code != WLAN_STATUS_SUCCESS) {
2996 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
2998 if (auth_alg == WLAN_AUTH_SAE &&
2999 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3000 (auth_transaction == 1 &&
3001 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3002 status_code == WLAN_STATUS_SAE_PK))))
3005 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3006 mgmt->sa, status_code);
3007 ieee80211_destroy_auth_data(sdata, false);
3008 event.u.mlme.status = MLME_DENIED;
3009 event.u.mlme.reason = status_code;
3010 drv_event_callback(sdata->local, sdata, &event);
3014 switch (ifmgd->auth_data->algorithm) {
3015 case WLAN_AUTH_OPEN:
3016 case WLAN_AUTH_LEAP:
3019 case WLAN_AUTH_FILS_SK:
3020 case WLAN_AUTH_FILS_SK_PFS:
3021 case WLAN_AUTH_FILS_PK:
3023 case WLAN_AUTH_SHARED_KEY:
3024 if (ifmgd->auth_data->expected_transaction != 4) {
3025 ieee80211_auth_challenge(sdata, mgmt, len);
3026 /* need another frame */
3031 WARN_ONCE(1, "invalid auth alg %d",
3032 ifmgd->auth_data->algorithm);
3036 event.u.mlme.status = MLME_SUCCESS;
3038 drv_event_callback(sdata->local, sdata, &event);
3039 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3040 (auth_transaction == 2 &&
3041 ifmgd->auth_data->expected_transaction == 2)) {
3042 if (!ieee80211_mark_sta_auth(sdata, bssid))
3043 return; /* ignore frame -- wait for timeout */
3044 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3045 auth_transaction == 2) {
3046 sdata_info(sdata, "SAE peer confirmed\n");
3047 ifmgd->auth_data->peer_confirmed = true;
3050 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3052 drv_mgd_complete_tx(sdata->local, sdata, &info);
3055 #define case_WLAN(type) \
3056 case WLAN_REASON_##type: return #type
3058 const char *ieee80211_get_reason_code_string(u16 reason_code)
3060 switch (reason_code) {
3061 case_WLAN(UNSPECIFIED);
3062 case_WLAN(PREV_AUTH_NOT_VALID);
3063 case_WLAN(DEAUTH_LEAVING);
3064 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3065 case_WLAN(DISASSOC_AP_BUSY);
3066 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3067 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3068 case_WLAN(DISASSOC_STA_HAS_LEFT);
3069 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3070 case_WLAN(DISASSOC_BAD_POWER);
3071 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3072 case_WLAN(INVALID_IE);
3073 case_WLAN(MIC_FAILURE);
3074 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3075 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3076 case_WLAN(IE_DIFFERENT);
3077 case_WLAN(INVALID_GROUP_CIPHER);
3078 case_WLAN(INVALID_PAIRWISE_CIPHER);
3079 case_WLAN(INVALID_AKMP);
3080 case_WLAN(UNSUPP_RSN_VERSION);
3081 case_WLAN(INVALID_RSN_IE_CAP);
3082 case_WLAN(IEEE8021X_FAILED);
3083 case_WLAN(CIPHER_SUITE_REJECTED);
3084 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3085 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3086 case_WLAN(DISASSOC_LOW_ACK);
3087 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3088 case_WLAN(QSTA_LEAVE_QBSS);
3089 case_WLAN(QSTA_NOT_USE);
3090 case_WLAN(QSTA_REQUIRE_SETUP);
3091 case_WLAN(QSTA_TIMEOUT);
3092 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3093 case_WLAN(MESH_PEER_CANCELED);
3094 case_WLAN(MESH_MAX_PEERS);
3095 case_WLAN(MESH_CONFIG);
3096 case_WLAN(MESH_CLOSE);
3097 case_WLAN(MESH_MAX_RETRIES);
3098 case_WLAN(MESH_CONFIRM_TIMEOUT);
3099 case_WLAN(MESH_INVALID_GTK);
3100 case_WLAN(MESH_INCONSISTENT_PARAM);
3101 case_WLAN(MESH_INVALID_SECURITY);
3102 case_WLAN(MESH_PATH_ERROR);
3103 case_WLAN(MESH_PATH_NOFORWARD);
3104 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3105 case_WLAN(MAC_EXISTS_IN_MBSS);
3106 case_WLAN(MESH_CHAN_REGULATORY);
3107 case_WLAN(MESH_CHAN);
3108 default: return "<unknown>";
3112 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3113 struct ieee80211_mgmt *mgmt, size_t len)
3115 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3116 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3118 sdata_assert_lock(sdata);
3123 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3124 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3128 if (ifmgd->associated &&
3129 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3130 const u8 *bssid = ifmgd->associated->bssid;
3132 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3134 ieee80211_get_reason_code_string(reason_code));
3136 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3138 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3139 reason_code, false);
3143 if (ifmgd->assoc_data &&
3144 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3145 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3148 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3150 ieee80211_get_reason_code_string(reason_code));
3152 ieee80211_destroy_assoc_data(sdata, false, true);
3154 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3160 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3161 struct ieee80211_mgmt *mgmt, size_t len)
3163 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3166 sdata_assert_lock(sdata);
3171 if (!ifmgd->associated ||
3172 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3175 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3177 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3178 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3182 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3183 mgmt->sa, reason_code,
3184 ieee80211_get_reason_code_string(reason_code));
3186 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3188 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3192 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3193 u8 *supp_rates, unsigned int supp_rates_len,
3194 u32 *rates, u32 *basic_rates,
3195 bool *have_higher_than_11mbit,
3196 int *min_rate, int *min_rate_index,
3201 for (i = 0; i < supp_rates_len; i++) {
3202 int rate = supp_rates[i] & 0x7f;
3203 bool is_basic = !!(supp_rates[i] & 0x80);
3205 if ((rate * 5 * (1 << shift)) > 110)
3206 *have_higher_than_11mbit = true;
3209 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3210 * since they're not rates.
3212 * Note: Even though the membership selector and the basic
3213 * rate flag share the same bit, they are not exactly
3216 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3217 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3218 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3219 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3222 for (j = 0; j < sband->n_bitrates; j++) {
3223 struct ieee80211_rate *br;
3226 br = &sband->bitrates[j];
3228 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3229 if (brate == rate) {
3232 *basic_rates |= BIT(j);
3233 if ((rate * 5) < *min_rate) {
3234 *min_rate = rate * 5;
3235 *min_rate_index = j;
3243 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3244 const struct ieee802_11_elems *elems)
3246 if (elems->ext_capab_len < 10)
3249 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3252 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3253 IEEE80211_HE_MAC_CAP0_TWT_RES;
3256 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3257 struct sta_info *sta,
3258 struct ieee802_11_elems *elems)
3260 bool twt = ieee80211_twt_req_supported(sta, elems);
3262 if (sdata->vif.bss_conf.twt_requester != twt) {
3263 sdata->vif.bss_conf.twt_requester = twt;
3264 return BSS_CHANGED_TWT;
3269 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3270 struct ieee80211_bss_conf *bss_conf,
3271 struct ieee80211_supported_band *sband,
3272 struct sta_info *sta)
3274 const struct ieee80211_sta_he_cap *own_he_cap =
3275 ieee80211_get_he_iftype_cap(sband,
3276 ieee80211_vif_type_p2p(&sdata->vif));
3278 return bss_conf->he_support &&
3279 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3280 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3282 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3283 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3286 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3287 struct cfg80211_bss *cbss,
3288 struct ieee80211_mgmt *mgmt, size_t len,
3289 struct ieee802_11_elems *elems)
3291 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3292 struct ieee80211_local *local = sdata->local;
3293 struct ieee80211_supported_band *sband;
3294 struct sta_info *sta;
3295 u16 capab_info, aid;
3296 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3297 const struct cfg80211_bss_ies *bss_ies = NULL;
3298 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3299 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3300 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3306 /* AssocResp and ReassocResp have identical structure */
3308 pos = mgmt->u.assoc_resp.variable;
3309 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3311 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3314 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3315 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3316 mgmt->bssid, assoc_data->bss->bssid);
3321 if (elems->aid_resp)
3322 aid = le16_to_cpu(elems->aid_resp->aid);
3325 * The 5 MSB of the AID field are reserved
3326 * (802.11-2016 9.4.1.8 AID field)
3330 ifmgd->broken_ap = false;
3332 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3333 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3336 ifmgd->broken_ap = true;
3339 if (!is_s1g && !elems->supp_rates) {
3340 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3345 sdata->vif.bss_conf.aid = aid;
3346 ifmgd->tdls_chan_switch_prohibited =
3347 elems->ext_capab && elems->ext_capab_len >= 5 &&
3348 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3351 * Some APs are erroneously not including some information in their
3352 * (re)association response frames. Try to recover by using the data
3353 * from the beacon or probe response. This seems to afflict mobile
3354 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3355 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3358 ((assoc_data->wmm && !elems->wmm_param) ||
3359 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3360 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3361 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3362 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3363 const struct cfg80211_bss_ies *ies;
3364 struct ieee802_11_elems *bss_elems;
3367 ies = rcu_dereference(cbss->ies);
3369 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3377 bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3379 assoc_data->bss->bssid);
3385 if (assoc_data->wmm &&
3386 !elems->wmm_param && bss_elems->wmm_param) {
3387 elems->wmm_param = bss_elems->wmm_param;
3389 "AP bug: WMM param missing from AssocResp\n");
3393 * Also check if we requested HT/VHT, otherwise the AP doesn't
3394 * have to include the IEs in the (re)association response.
3396 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3397 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3398 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3400 "AP bug: HT capability missing from AssocResp\n");
3402 if (!elems->ht_operation && bss_elems->ht_operation &&
3403 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3404 elems->ht_operation = bss_elems->ht_operation;
3406 "AP bug: HT operation missing from AssocResp\n");
3408 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3409 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3410 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3412 "AP bug: VHT capa missing from AssocResp\n");
3414 if (!elems->vht_operation && bss_elems->vht_operation &&
3415 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3416 elems->vht_operation = bss_elems->vht_operation;
3418 "AP bug: VHT operation missing from AssocResp\n");
3425 * We previously checked these in the beacon/probe response, so
3426 * they should be present here. This is just a safety net.
3428 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3429 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3431 "HT AP is missing WMM params or HT capability/operation\n");
3436 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3437 (!elems->vht_cap_elem || !elems->vht_operation)) {
3439 "VHT AP is missing VHT capability/operation\n");
3444 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3445 !elems->he_6ghz_capa) {
3447 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3452 mutex_lock(&sdata->local->sta_mtx);
3454 * station info was already allocated and inserted before
3455 * the association and should be available to us
3457 sta = sta_info_get(sdata, cbss->bssid);
3458 if (WARN_ON(!sta)) {
3459 mutex_unlock(&sdata->local->sta_mtx);
3464 sband = ieee80211_get_sband(sdata);
3466 mutex_unlock(&sdata->local->sta_mtx);
3471 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3472 (!elems->he_cap || !elems->he_operation)) {
3473 mutex_unlock(&sdata->local->sta_mtx);
3475 "HE AP is missing HE capability/operation\n");
3480 /* Set up internal HT/VHT capabilities */
3481 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3482 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3483 elems->ht_cap_elem, sta);
3485 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3486 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3487 elems->vht_cap_elem, sta);
3489 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3491 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3494 elems->he_6ghz_capa,
3497 bss_conf->he_support = sta->sta.he_cap.has_he;
3498 if (elems->rsnx && elems->rsnx_len &&
3499 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3500 wiphy_ext_feature_isset(local->hw.wiphy,
3501 NL80211_EXT_FEATURE_PROTECTED_TWT))
3502 bss_conf->twt_protected = true;
3504 bss_conf->twt_protected = false;
3506 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3508 bss_conf->he_support = false;
3509 bss_conf->twt_requester = false;
3510 bss_conf->twt_protected = false;
3513 bss_conf->twt_broadcast =
3514 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3516 if (bss_conf->he_support) {
3517 bss_conf->he_bss_color.color =
3518 le32_get_bits(elems->he_operation->he_oper_params,
3519 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3520 bss_conf->he_bss_color.partial =
3521 le32_get_bits(elems->he_operation->he_oper_params,
3522 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3523 bss_conf->he_bss_color.enabled =
3524 !le32_get_bits(elems->he_operation->he_oper_params,
3525 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3527 if (bss_conf->he_bss_color.enabled)
3528 changed |= BSS_CHANGED_HE_BSS_COLOR;
3530 bss_conf->htc_trig_based_pkt_ext =
3531 le32_get_bits(elems->he_operation->he_oper_params,
3532 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3533 bss_conf->frame_time_rts_th =
3534 le32_get_bits(elems->he_operation->he_oper_params,
3535 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3537 bss_conf->uora_exists = !!elems->uora_element;
3538 if (elems->uora_element)
3539 bss_conf->uora_ocw_range = elems->uora_element[0];
3541 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3542 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3543 /* TODO: OPEN: what happens if BSS color disable is set? */
3546 if (cbss->transmitted_bss) {
3547 bss_conf->nontransmitted = true;
3548 ether_addr_copy(bss_conf->transmitter_bssid,
3549 cbss->transmitted_bss->bssid);
3550 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3551 bss_conf->bssid_index = cbss->bssid_index;
3555 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3556 * in their association response, so ignore that data for our own
3557 * configuration. If it changed since the last beacon, we'll get the
3558 * next beacon and update then.
3562 * If an operating mode notification IE is present, override the
3563 * NSS calculation (that would be done in rate_control_rate_init())
3564 * and use the # of streams from that element.
3566 if (elems->opmode_notif &&
3567 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3570 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3571 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3573 sta->sta.rx_nss = nss;
3576 rate_control_rate_init(sta);
3578 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3579 set_sta_flag(sta, WLAN_STA_MFP);
3580 sta->sta.mfp = true;
3582 sta->sta.mfp = false;
3585 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3586 local->hw.queues >= IEEE80211_NUM_ACS;
3588 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3589 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3590 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3593 "failed to move station %pM to desired state\n",
3595 WARN_ON(__sta_info_destroy(sta));
3596 mutex_unlock(&sdata->local->sta_mtx);
3601 if (sdata->wdev.use_4addr)
3602 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3604 mutex_unlock(&sdata->local->sta_mtx);
3607 * Always handle WMM once after association regardless
3608 * of the first value the AP uses. Setting -1 here has
3609 * that effect because the AP values is an unsigned
3612 ifmgd->wmm_last_param_set = -1;
3613 ifmgd->mu_edca_last_param_set = -1;
3615 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3616 ieee80211_set_wmm_default(sdata, false, false);
3617 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3618 elems->wmm_param_len,
3619 elems->mu_edca_param_set)) {
3620 /* still enable QoS since we might have HT/VHT */
3621 ieee80211_set_wmm_default(sdata, false, true);
3622 /* set the disable-WMM flag in this case to disable
3623 * tracking WMM parameter changes in the beacon if
3624 * the parameters weren't actually valid. Doing so
3625 * avoids changing parameters very strangely when
3626 * the AP is going back and forth between valid and
3627 * invalid parameters.
3629 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3631 changed |= BSS_CHANGED_QOS;
3633 if (elems->max_idle_period_ie) {
3634 bss_conf->max_idle_period =
3635 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3636 bss_conf->protected_keep_alive =
3637 !!(elems->max_idle_period_ie->idle_options &
3638 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3639 changed |= BSS_CHANGED_KEEP_ALIVE;
3641 bss_conf->max_idle_period = 0;
3642 bss_conf->protected_keep_alive = false;
3645 /* set assoc capability (AID was already set earlier),
3646 * ieee80211_set_associated() will tell the driver */
3647 bss_conf->assoc_capability = capab_info;
3648 ieee80211_set_associated(sdata, cbss, changed);
3651 * If we're using 4-addr mode, let the AP know that we're
3652 * doing so, so that it can create the STA VLAN on its side
3654 if (ifmgd->use_4addr)
3655 ieee80211_send_4addr_nullfunc(local, sdata);
3658 * Start timer to probe the connection to the AP now.
3659 * Also start the timer that will detect beacon loss.
3661 ieee80211_sta_reset_beacon_monitor(sdata);
3662 ieee80211_sta_reset_conn_monitor(sdata);
3671 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3672 struct ieee80211_mgmt *mgmt,
3675 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3676 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3677 u16 capab_info, status_code, aid;
3678 struct ieee802_11_elems *elems;
3679 int ac, uapsd_queues = -1;
3682 struct cfg80211_bss *cbss;
3683 struct ieee80211_event event = {
3685 .u.mlme.data = ASSOC_EVENT,
3687 struct ieee80211_prep_tx_info info = {};
3689 sdata_assert_lock(sdata);
3694 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3697 cbss = assoc_data->bss;
3700 * AssocResp and ReassocResp have identical structure, so process both
3701 * of them in this function.
3707 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3708 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3709 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3710 pos = mgmt->u.assoc_resp.variable;
3711 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3712 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3713 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3718 * Note: this may not be perfect, AP might misbehave - if
3719 * anyone needs to rely on perfect complete notification
3720 * with the exact right subtype, then we need to track what
3721 * we actually transmitted.
3723 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3724 IEEE80211_STYPE_ASSOC_REQ;
3727 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3728 reassoc ? "Rea" : "A", mgmt->sa,
3729 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3731 if (assoc_data->fils_kek_len &&
3732 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3735 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3736 mgmt->bssid, assoc_data->bss->bssid);
3740 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3741 elems->timeout_int &&
3742 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3744 tu = le32_to_cpu(elems->timeout_int->value);
3745 ms = tu * 1024 / 1000;
3747 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3749 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3750 assoc_data->timeout_started = true;
3751 if (ms > IEEE80211_ASSOC_TIMEOUT)
3752 run_again(sdata, assoc_data->timeout);
3756 if (status_code != WLAN_STATUS_SUCCESS) {
3757 sdata_info(sdata, "%pM denied association (code=%d)\n",
3758 mgmt->sa, status_code);
3759 ieee80211_destroy_assoc_data(sdata, false, false);
3760 event.u.mlme.status = MLME_DENIED;
3761 event.u.mlme.reason = status_code;
3762 drv_event_callback(sdata->local, sdata, &event);
3764 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) {
3765 /* oops -- internal error -- send timeout for now */
3766 ieee80211_destroy_assoc_data(sdata, false, false);
3767 cfg80211_assoc_timeout(sdata->dev, cbss);
3770 event.u.mlme.status = MLME_SUCCESS;
3771 drv_event_callback(sdata->local, sdata, &event);
3772 sdata_info(sdata, "associated\n");
3775 * destroy assoc_data afterwards, as otherwise an idle
3776 * recalc after assoc_data is NULL but before associated
3777 * is set can cause the interface to go idle
3779 ieee80211_destroy_assoc_data(sdata, true, false);
3781 /* get uapsd queues configuration */
3783 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3784 if (sdata->tx_conf[ac].uapsd)
3785 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3790 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3791 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3793 drv_mgd_complete_tx(sdata->local, sdata, &info);
3797 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3798 struct ieee80211_mgmt *mgmt, size_t len,
3799 struct ieee80211_rx_status *rx_status)
3801 struct ieee80211_local *local = sdata->local;
3802 struct ieee80211_bss *bss;
3803 struct ieee80211_channel *channel;
3805 sdata_assert_lock(sdata);
3807 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3808 ieee80211_rx_status_to_khz(rx_status));
3812 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3814 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3815 ieee80211_rx_bss_put(local, bss);
3820 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3821 struct sk_buff *skb)
3823 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3824 struct ieee80211_if_managed *ifmgd;
3825 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3826 struct ieee80211_channel *channel;
3827 size_t baselen, len = skb->len;
3829 ifmgd = &sdata->u.mgd;
3831 sdata_assert_lock(sdata);
3834 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3835 * "If a 6 GHz AP receives a Probe Request frame and responds with
3836 * a Probe Response frame [..], the Address 1 field of the Probe
3837 * Response frame shall be set to the broadcast address [..]"
3838 * So, on 6GHz band we should also accept broadcast responses.
3840 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3845 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3846 (channel->band != NL80211_BAND_6GHZ ||
3847 !is_broadcast_ether_addr(mgmt->da)))
3848 return; /* ignore ProbeResp to foreign address */
3850 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3854 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3856 if (ifmgd->associated &&
3857 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3858 ieee80211_reset_ap_probe(sdata);
3862 * This is the canonical list of information elements we care about,
3863 * the filter code also gives us all changes to the Microsoft OUI
3864 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3865 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3866 * changes to requested client power.
3868 * We implement beacon filtering in software since that means we can
3869 * avoid processing the frame here and in cfg80211, and userspace
3870 * will not be able to tell whether the hardware supports it or not.
3872 * XXX: This list needs to be dynamic -- userspace needs to be able to
3873 * add items it requires. It also needs to be able to tell us to
3874 * look out for other vendor IEs.
3876 static const u64 care_about_ies =
3877 (1ULL << WLAN_EID_COUNTRY) |
3878 (1ULL << WLAN_EID_ERP_INFO) |
3879 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3880 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3881 (1ULL << WLAN_EID_HT_CAPABILITY) |
3882 (1ULL << WLAN_EID_HT_OPERATION) |
3883 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3885 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3886 struct ieee80211_if_managed *ifmgd,
3887 struct ieee80211_bss_conf *bss_conf,
3888 struct ieee80211_local *local,
3889 struct ieee80211_rx_status *rx_status)
3891 /* Track average RSSI from the Beacon frames of the current AP */
3893 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3894 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3895 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3896 ifmgd->last_cqm_event_signal = 0;
3897 ifmgd->count_beacon_signal = 1;
3898 ifmgd->last_ave_beacon_signal = 0;
3900 ifmgd->count_beacon_signal++;
3903 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3905 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3906 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3907 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3908 int last_sig = ifmgd->last_ave_beacon_signal;
3909 struct ieee80211_event event = {
3914 * if signal crosses either of the boundaries, invoke callback
3915 * with appropriate parameters
3917 if (sig > ifmgd->rssi_max_thold &&
3918 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3919 ifmgd->last_ave_beacon_signal = sig;
3920 event.u.rssi.data = RSSI_EVENT_HIGH;
3921 drv_event_callback(local, sdata, &event);
3922 } else if (sig < ifmgd->rssi_min_thold &&
3923 (last_sig >= ifmgd->rssi_max_thold ||
3925 ifmgd->last_ave_beacon_signal = sig;
3926 event.u.rssi.data = RSSI_EVENT_LOW;
3927 drv_event_callback(local, sdata, &event);
3931 if (bss_conf->cqm_rssi_thold &&
3932 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3933 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3934 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3935 int last_event = ifmgd->last_cqm_event_signal;
3936 int thold = bss_conf->cqm_rssi_thold;
3937 int hyst = bss_conf->cqm_rssi_hyst;
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_LOW,
3946 } else if (sig > thold &&
3947 (last_event == 0 || sig > last_event + hyst)) {
3948 ifmgd->last_cqm_event_signal = sig;
3949 ieee80211_cqm_rssi_notify(
3951 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3956 if (bss_conf->cqm_rssi_low &&
3957 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3958 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3959 int last_event = ifmgd->last_cqm_event_signal;
3960 int low = bss_conf->cqm_rssi_low;
3961 int high = bss_conf->cqm_rssi_high;
3964 (last_event == 0 || last_event >= low)) {
3965 ifmgd->last_cqm_event_signal = sig;
3966 ieee80211_cqm_rssi_notify(
3968 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3970 } else if (sig > high &&
3971 (last_event == 0 || last_event <= high)) {
3972 ifmgd->last_cqm_event_signal = sig;
3973 ieee80211_cqm_rssi_notify(
3975 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3981 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
3982 struct cfg80211_bss *bss)
3984 if (ether_addr_equal(tx_bssid, bss->bssid))
3986 if (!bss->transmitted_bss)
3988 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
3991 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
3992 struct ieee80211_hdr *hdr, size_t len,
3993 struct ieee80211_rx_status *rx_status)
3995 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3996 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3997 struct ieee80211_mgmt *mgmt = (void *) hdr;
3999 struct ieee802_11_elems *elems;
4000 struct ieee80211_local *local = sdata->local;
4001 struct ieee80211_chanctx_conf *chanctx_conf;
4002 struct ieee80211_channel *chan;
4003 struct sta_info *sta;
4008 u8 *bssid, *variable = mgmt->u.beacon.variable;
4009 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4011 sdata_assert_lock(sdata);
4013 /* Process beacon from the current BSS */
4014 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4015 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4016 struct ieee80211_ext *ext = (void *) mgmt;
4018 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4019 variable = ext->u.s1g_short_beacon.variable;
4021 variable = ext->u.s1g_beacon.variable;
4024 baselen = (u8 *) variable - (u8 *) mgmt;
4029 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4030 if (!chanctx_conf) {
4035 if (ieee80211_rx_status_to_khz(rx_status) !=
4036 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4040 chan = chanctx_conf->def.chan;
4043 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4044 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4045 elems = ieee802_11_parse_elems(variable, len - baselen, false,
4047 ifmgd->assoc_data->bss->bssid);
4051 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4053 if (elems->dtim_period)
4054 ifmgd->dtim_period = elems->dtim_period;
4055 ifmgd->have_beacon = true;
4056 ifmgd->assoc_data->need_beacon = false;
4057 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4058 sdata->vif.bss_conf.sync_tsf =
4059 le64_to_cpu(mgmt->u.beacon.timestamp);
4060 sdata->vif.bss_conf.sync_device_ts =
4061 rx_status->device_timestamp;
4062 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4065 if (elems->mbssid_config_ie)
4066 bss_conf->profile_periodicity =
4067 elems->mbssid_config_ie->profile_periodicity;
4069 bss_conf->profile_periodicity = 0;
4071 if (elems->ext_capab_len >= 11 &&
4072 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4073 bss_conf->ema_ap = true;
4075 bss_conf->ema_ap = false;
4077 /* continue assoc process */
4078 ifmgd->assoc_data->timeout = jiffies;
4079 ifmgd->assoc_data->timeout_started = true;
4080 run_again(sdata, ifmgd->assoc_data->timeout);
4085 if (!ifmgd->associated ||
4086 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4088 bssid = ifmgd->associated->bssid;
4090 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4091 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4094 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4095 mlme_dbg_ratelimited(sdata,
4096 "cancelling AP probe due to a received beacon\n");
4097 ieee80211_reset_ap_probe(sdata);
4101 * Push the beacon loss detection into the future since
4102 * we are processing a beacon from the AP just now.
4104 ieee80211_sta_reset_beacon_monitor(sdata);
4106 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4107 * element (which carries the beacon interval). Don't forget to add a
4108 * bit to care_about_ies[] above if mac80211 is interested in a
4109 * changing S1G element.
4111 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4112 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4113 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
4114 false, care_about_ies, ncrc,
4115 mgmt->bssid, bssid);
4120 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4121 ieee80211_check_tim(elems->tim, elems->tim_len, bss_conf->aid)) {
4122 if (local->hw.conf.dynamic_ps_timeout > 0) {
4123 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4124 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4125 ieee80211_hw_config(local,
4126 IEEE80211_CONF_CHANGE_PS);
4128 ieee80211_send_nullfunc(local, sdata, false);
4129 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4130 local->pspolling = true;
4133 * Here is assumed that the driver will be
4134 * able to send ps-poll frame and receive a
4135 * response even though power save mode is
4136 * enabled, but some drivers might require
4137 * to disable power save here. This needs
4138 * to be investigated.
4140 ieee80211_send_pspoll(local, sdata);
4144 if (sdata->vif.p2p ||
4145 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4146 struct ieee80211_p2p_noa_attr noa = {};
4149 ret = cfg80211_get_p2p_attr(variable,
4151 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4152 (u8 *) &noa, sizeof(noa));
4154 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4155 /* valid noa_attr and index changed */
4156 sdata->u.mgd.p2p_noa_index = noa.index;
4157 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4158 changed |= BSS_CHANGED_P2P_PS;
4160 * make sure we update all information, the CRC
4161 * mechanism doesn't look at P2P attributes.
4163 ifmgd->beacon_crc_valid = false;
4165 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4166 /* noa_attr not found and we had valid noa_attr before */
4167 sdata->u.mgd.p2p_noa_index = -1;
4168 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4169 changed |= BSS_CHANGED_P2P_PS;
4170 ifmgd->beacon_crc_valid = false;
4174 if (ifmgd->csa_waiting_bcn)
4175 ieee80211_chswitch_post_beacon(sdata);
4178 * Update beacon timing and dtim count on every beacon appearance. This
4179 * will allow the driver to use the most updated values. Do it before
4180 * comparing this one with last received beacon.
4181 * IMPORTANT: These parameters would possibly be out of sync by the time
4182 * the driver will use them. The synchronized view is currently
4183 * guaranteed only in certain callbacks.
4185 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4186 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4187 sdata->vif.bss_conf.sync_tsf =
4188 le64_to_cpu(mgmt->u.beacon.timestamp);
4189 sdata->vif.bss_conf.sync_device_ts =
4190 rx_status->device_timestamp;
4191 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4194 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4195 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4197 ifmgd->beacon_crc = ncrc;
4198 ifmgd->beacon_crc_valid = true;
4200 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4202 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4203 rx_status->device_timestamp,
4206 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4207 ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
4208 elems->wmm_param_len,
4209 elems->mu_edca_param_set))
4210 changed |= BSS_CHANGED_QOS;
4213 * If we haven't had a beacon before, tell the driver about the
4214 * DTIM period (and beacon timing if desired) now.
4216 if (!ifmgd->have_beacon) {
4217 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4218 bss_conf->dtim_period = elems->dtim_period ?: 1;
4220 changed |= BSS_CHANGED_BEACON_INFO;
4221 ifmgd->have_beacon = true;
4223 mutex_lock(&local->iflist_mtx);
4224 ieee80211_recalc_ps(local);
4225 mutex_unlock(&local->iflist_mtx);
4227 ieee80211_recalc_ps_vif(sdata);
4230 if (elems->erp_info) {
4232 erp_value = elems->erp_info[0];
4237 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4238 changed |= ieee80211_handle_bss_capability(sdata,
4239 le16_to_cpu(mgmt->u.beacon.capab_info),
4240 erp_valid, erp_value);
4242 mutex_lock(&local->sta_mtx);
4243 sta = sta_info_get(sdata, bssid);
4245 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
4247 if (ieee80211_config_bw(sdata, sta, elems->ht_cap_elem,
4248 elems->vht_cap_elem, elems->ht_operation,
4249 elems->vht_operation, elems->he_operation,
4250 elems->s1g_oper, bssid, &changed)) {
4251 mutex_unlock(&local->sta_mtx);
4253 "failed to follow AP %pM bandwidth change, disconnect\n",
4255 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4256 WLAN_REASON_DEAUTH_LEAVING,
4258 ieee80211_report_disconnect(sdata, deauth_buf,
4259 sizeof(deauth_buf), true,
4260 WLAN_REASON_DEAUTH_LEAVING,
4265 if (sta && elems->opmode_notif)
4266 ieee80211_vht_handle_opmode(sdata, sta, *elems->opmode_notif,
4268 mutex_unlock(&local->sta_mtx);
4270 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4271 elems->country_elem,
4272 elems->country_elem_len,
4273 elems->pwr_constr_elem,
4274 elems->cisco_dtpc_elem);
4276 ieee80211_bss_info_change_notify(sdata, changed);
4281 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4282 struct sk_buff *skb)
4284 struct ieee80211_rx_status *rx_status;
4285 struct ieee80211_hdr *hdr;
4288 rx_status = (struct ieee80211_rx_status *) skb->cb;
4289 hdr = (struct ieee80211_hdr *) skb->data;
4290 fc = le16_to_cpu(hdr->frame_control);
4293 switch (fc & IEEE80211_FCTL_STYPE) {
4294 case IEEE80211_STYPE_S1G_BEACON:
4295 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4298 sdata_unlock(sdata);
4301 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4302 struct sk_buff *skb)
4304 struct ieee80211_rx_status *rx_status;
4305 struct ieee80211_mgmt *mgmt;
4309 rx_status = (struct ieee80211_rx_status *) skb->cb;
4310 mgmt = (struct ieee80211_mgmt *) skb->data;
4311 fc = le16_to_cpu(mgmt->frame_control);
4315 switch (fc & IEEE80211_FCTL_STYPE) {
4316 case IEEE80211_STYPE_BEACON:
4317 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4318 skb->len, rx_status);
4320 case IEEE80211_STYPE_PROBE_RESP:
4321 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4323 case IEEE80211_STYPE_AUTH:
4324 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4326 case IEEE80211_STYPE_DEAUTH:
4327 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4329 case IEEE80211_STYPE_DISASSOC:
4330 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4332 case IEEE80211_STYPE_ASSOC_RESP:
4333 case IEEE80211_STYPE_REASSOC_RESP:
4334 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4336 case IEEE80211_STYPE_ACTION:
4337 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4338 struct ieee802_11_elems *elems;
4340 ies_len = skb->len -
4341 offsetof(struct ieee80211_mgmt,
4342 u.action.u.chan_switch.variable);
4347 /* CSA IE cannot be overridden, no need for BSSID */
4348 elems = ieee802_11_parse_elems(
4349 mgmt->u.action.u.chan_switch.variable,
4350 ies_len, true, mgmt->bssid, NULL);
4352 if (elems && !elems->parse_error)
4353 ieee80211_sta_process_chanswitch(sdata,
4355 rx_status->device_timestamp,
4358 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4359 struct ieee802_11_elems *elems;
4361 ies_len = skb->len -
4362 offsetof(struct ieee80211_mgmt,
4363 u.action.u.ext_chan_switch.variable);
4369 * extended CSA IE can't be overridden, no need for
4372 elems = ieee802_11_parse_elems(
4373 mgmt->u.action.u.ext_chan_switch.variable,
4374 ies_len, true, mgmt->bssid, NULL);
4376 if (elems && !elems->parse_error) {
4377 /* for the handling code pretend it was an IE */
4378 elems->ext_chansw_ie =
4379 &mgmt->u.action.u.ext_chan_switch.data;
4381 ieee80211_sta_process_chanswitch(sdata,
4383 rx_status->device_timestamp,
4391 sdata_unlock(sdata);
4394 static void ieee80211_sta_timer(struct timer_list *t)
4396 struct ieee80211_sub_if_data *sdata =
4397 from_timer(sdata, t, u.mgd.timer);
4399 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4402 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4403 u8 *bssid, u8 reason, bool tx)
4405 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4407 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4410 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4414 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4416 struct ieee80211_local *local = sdata->local;
4417 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4418 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4422 struct ieee80211_prep_tx_info info = {
4423 .subtype = IEEE80211_STYPE_AUTH,
4426 sdata_assert_lock(sdata);
4428 if (WARN_ON_ONCE(!auth_data))
4433 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4434 sdata_info(sdata, "authentication with %pM timed out\n",
4435 auth_data->bss->bssid);
4438 * Most likely AP is not in the range so remove the
4439 * bss struct for that AP.
4441 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4446 if (auth_data->algorithm == WLAN_AUTH_SAE)
4447 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4449 drv_mgd_prepare_tx(local, sdata, &info);
4451 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4452 auth_data->bss->bssid, auth_data->tries,
4453 IEEE80211_AUTH_MAX_TRIES);
4455 auth_data->expected_transaction = 2;
4457 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4458 trans = auth_data->sae_trans;
4459 status = auth_data->sae_status;
4460 auth_data->expected_transaction = trans;
4463 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4464 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4465 IEEE80211_TX_INTFL_MLME_CONN_TX;
4467 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4468 auth_data->data, auth_data->data_len,
4469 auth_data->bss->bssid,
4470 auth_data->bss->bssid, NULL, 0, 0,
4473 if (tx_flags == 0) {
4474 if (auth_data->algorithm == WLAN_AUTH_SAE)
4475 auth_data->timeout = jiffies +
4476 IEEE80211_AUTH_TIMEOUT_SAE;
4478 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4480 auth_data->timeout =
4481 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4484 auth_data->timeout_started = true;
4485 run_again(sdata, auth_data->timeout);
4490 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4492 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4493 struct ieee80211_local *local = sdata->local;
4495 sdata_assert_lock(sdata);
4497 assoc_data->tries++;
4498 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4499 sdata_info(sdata, "association with %pM timed out\n",
4500 assoc_data->bss->bssid);
4503 * Most likely AP is not in the range so remove the
4504 * bss struct for that AP.
4506 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4511 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4512 assoc_data->bss->bssid, assoc_data->tries,
4513 IEEE80211_ASSOC_MAX_TRIES);
4514 ieee80211_send_assoc(sdata);
4516 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4517 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4518 assoc_data->timeout_started = true;
4519 run_again(sdata, assoc_data->timeout);
4521 assoc_data->timeout =
4522 round_jiffies_up(jiffies +
4523 IEEE80211_ASSOC_TIMEOUT_LONG);
4524 assoc_data->timeout_started = true;
4525 run_again(sdata, assoc_data->timeout);
4531 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4532 __le16 fc, bool acked)
4534 struct ieee80211_local *local = sdata->local;
4536 sdata->u.mgd.status_fc = fc;
4537 sdata->u.mgd.status_acked = acked;
4538 sdata->u.mgd.status_received = true;
4540 ieee80211_queue_work(&local->hw, &sdata->work);
4543 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4545 struct ieee80211_local *local = sdata->local;
4546 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4550 if (ifmgd->status_received) {
4551 __le16 fc = ifmgd->status_fc;
4552 bool status_acked = ifmgd->status_acked;
4554 ifmgd->status_received = false;
4555 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4557 if (ifmgd->auth_data->algorithm ==
4559 ifmgd->auth_data->timeout =
4561 IEEE80211_AUTH_TIMEOUT_SAE;
4563 ifmgd->auth_data->timeout =
4565 IEEE80211_AUTH_TIMEOUT_SHORT;
4566 run_again(sdata, ifmgd->auth_data->timeout);
4568 ifmgd->auth_data->timeout = jiffies - 1;
4570 ifmgd->auth_data->timeout_started = true;
4571 } else if (ifmgd->assoc_data &&
4572 (ieee80211_is_assoc_req(fc) ||
4573 ieee80211_is_reassoc_req(fc))) {
4575 ifmgd->assoc_data->timeout =
4576 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4577 run_again(sdata, ifmgd->assoc_data->timeout);
4579 ifmgd->assoc_data->timeout = jiffies - 1;
4581 ifmgd->assoc_data->timeout_started = true;
4585 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4586 time_after(jiffies, ifmgd->auth_data->timeout)) {
4587 if (ifmgd->auth_data->done) {
4589 * ok ... we waited for assoc but userspace didn't,
4590 * so let's just kill the auth data
4592 ieee80211_destroy_auth_data(sdata, false);
4593 } else if (ieee80211_auth(sdata)) {
4595 struct ieee80211_event event = {
4597 .u.mlme.data = AUTH_EVENT,
4598 .u.mlme.status = MLME_TIMEOUT,
4601 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4603 ieee80211_destroy_auth_data(sdata, false);
4605 cfg80211_auth_timeout(sdata->dev, bssid);
4606 drv_event_callback(sdata->local, sdata, &event);
4608 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4609 run_again(sdata, ifmgd->auth_data->timeout);
4611 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4612 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4613 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4614 ieee80211_do_assoc(sdata)) {
4615 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4616 struct ieee80211_event event = {
4618 .u.mlme.data = ASSOC_EVENT,
4619 .u.mlme.status = MLME_TIMEOUT,
4622 ieee80211_destroy_assoc_data(sdata, false, false);
4623 cfg80211_assoc_timeout(sdata->dev, bss);
4624 drv_event_callback(sdata->local, sdata, &event);
4626 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4627 run_again(sdata, ifmgd->assoc_data->timeout);
4629 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4630 ifmgd->associated) {
4634 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4636 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4637 max_tries = max_nullfunc_tries;
4639 max_tries = max_probe_tries;
4641 /* ACK received for nullfunc probing frame */
4642 if (!ifmgd->probe_send_count)
4643 ieee80211_reset_ap_probe(sdata);
4644 else if (ifmgd->nullfunc_failed) {
4645 if (ifmgd->probe_send_count < max_tries) {
4647 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4648 bssid, ifmgd->probe_send_count,
4650 ieee80211_mgd_probe_ap_send(sdata);
4653 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4655 ieee80211_sta_connection_lost(sdata, bssid,
4656 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4659 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4660 run_again(sdata, ifmgd->probe_timeout);
4661 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4663 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4664 bssid, probe_wait_ms);
4665 ieee80211_sta_connection_lost(sdata, bssid,
4666 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4667 } else if (ifmgd->probe_send_count < max_tries) {
4669 "No probe response from AP %pM after %dms, try %d/%i\n",
4670 bssid, probe_wait_ms,
4671 ifmgd->probe_send_count, max_tries);
4672 ieee80211_mgd_probe_ap_send(sdata);
4675 * We actually lost the connection ... or did we?
4679 "No probe response from AP %pM after %dms, disconnecting.\n",
4680 bssid, probe_wait_ms);
4682 ieee80211_sta_connection_lost(sdata, bssid,
4683 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4687 sdata_unlock(sdata);
4690 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4692 struct ieee80211_sub_if_data *sdata =
4693 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4694 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4696 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4699 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4702 sdata->u.mgd.connection_loss = false;
4703 ieee80211_queue_work(&sdata->local->hw,
4704 &sdata->u.mgd.beacon_connection_loss_work);
4707 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4709 struct ieee80211_sub_if_data *sdata =
4710 from_timer(sdata, t, u.mgd.conn_mon_timer);
4711 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4712 struct ieee80211_local *local = sdata->local;
4713 struct sta_info *sta;
4714 unsigned long timeout;
4716 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4719 sta = sta_info_get(sdata, ifmgd->bssid);
4723 timeout = sta->status_stats.last_ack;
4724 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4725 timeout = sta->rx_stats.last_rx;
4726 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4728 /* If timeout is after now, then update timer to fire at
4729 * the later date, but do not actually probe at this time.
4731 if (time_is_after_jiffies(timeout)) {
4732 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4736 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4739 static void ieee80211_sta_monitor_work(struct work_struct *work)
4741 struct ieee80211_sub_if_data *sdata =
4742 container_of(work, struct ieee80211_sub_if_data,
4743 u.mgd.monitor_work);
4745 ieee80211_mgd_probe_ap(sdata, false);
4748 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4750 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4751 __ieee80211_stop_poll(sdata);
4753 /* let's probe the connection once */
4754 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4755 ieee80211_queue_work(&sdata->local->hw,
4756 &sdata->u.mgd.monitor_work);
4761 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4763 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4764 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4768 if (ifmgd->auth_data || ifmgd->assoc_data) {
4769 const u8 *bssid = ifmgd->auth_data ?
4770 ifmgd->auth_data->bss->bssid :
4771 ifmgd->assoc_data->bss->bssid;
4774 * If we are trying to authenticate / associate while suspending,
4775 * cfg80211 won't know and won't actually abort those attempts,
4776 * thus we need to do that ourselves.
4778 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4779 IEEE80211_STYPE_DEAUTH,
4780 WLAN_REASON_DEAUTH_LEAVING,
4782 if (ifmgd->assoc_data)
4783 ieee80211_destroy_assoc_data(sdata, false, true);
4784 if (ifmgd->auth_data)
4785 ieee80211_destroy_auth_data(sdata, false);
4786 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4787 IEEE80211_DEAUTH_FRAME_LEN,
4791 /* This is a bit of a hack - we should find a better and more generic
4792 * solution to this. Normally when suspending, cfg80211 will in fact
4793 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4794 * auth (not so important) or assoc (this is the problem) process.
4796 * As a consequence, it can happen that we are in the process of both
4797 * associating and suspending, and receive an association response
4798 * after cfg80211 has checked if it needs to disconnect, but before
4799 * we actually set the flag to drop incoming frames. This will then
4800 * cause the workqueue flush to process the association response in
4801 * the suspend, resulting in a successful association just before it
4802 * tries to remove the interface from the driver, which now though
4803 * has a channel context assigned ... this results in issues.
4805 * To work around this (for now) simply deauth here again if we're
4808 if (ifmgd->associated && !sdata->local->wowlan) {
4810 struct cfg80211_deauth_request req = {
4811 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4815 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4816 ieee80211_mgd_deauth(sdata, &req);
4819 sdata_unlock(sdata);
4822 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4824 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4827 if (!ifmgd->associated) {
4828 sdata_unlock(sdata);
4832 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4833 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4834 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4835 ieee80211_sta_connection_lost(sdata,
4836 ifmgd->associated->bssid,
4837 WLAN_REASON_UNSPECIFIED,
4839 sdata_unlock(sdata);
4842 sdata_unlock(sdata);
4846 /* interface setup */
4847 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4849 struct ieee80211_if_managed *ifmgd;
4851 ifmgd = &sdata->u.mgd;
4852 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4853 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4854 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4855 ieee80211_beacon_connection_loss_work);
4856 INIT_WORK(&ifmgd->csa_connection_drop_work,
4857 ieee80211_csa_connection_drop_work);
4858 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4859 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4860 ieee80211_tdls_peer_del_work);
4861 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4862 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4863 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4864 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4865 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4866 ieee80211_sta_handle_tspec_ac_params_wk);
4869 ifmgd->powersave = sdata->wdev.ps;
4870 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4871 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4872 ifmgd->p2p_noa_index = -1;
4874 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4875 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4877 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4879 /* Setup TDLS data */
4880 spin_lock_init(&ifmgd->teardown_lock);
4881 ifmgd->teardown_skb = NULL;
4882 ifmgd->orig_teardown_skb = NULL;
4885 /* scan finished notification */
4886 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4888 struct ieee80211_sub_if_data *sdata;
4890 /* Restart STA timers */
4892 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4893 if (ieee80211_sdata_running(sdata))
4894 ieee80211_restart_sta_timer(sdata);
4899 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4900 struct cfg80211_bss *cbss)
4902 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4903 const u8 *ht_cap_ie, *vht_cap_ie;
4904 const struct ieee80211_ht_cap *ht_cap;
4905 const struct ieee80211_vht_cap *vht_cap;
4908 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4911 ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
4912 if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
4913 ht_cap = (void *)(ht_cap_ie + 2);
4914 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4916 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4917 * "Tx Unequal Modulation Supported" fields.
4921 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4924 vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
4925 if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
4929 vht_cap = (void *)(vht_cap_ie + 2);
4930 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4931 for (nss = 8; nss > 0; nss--) {
4932 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4933 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4936 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4937 chains = max(chains, nss);
4944 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4945 struct ieee80211_supported_band *sband,
4946 const struct ieee80211_he_operation *he_op)
4948 const struct ieee80211_sta_he_cap *sta_he_cap =
4949 ieee80211_get_he_iftype_cap(sband,
4950 ieee80211_vif_type_p2p(&sdata->vif));
4954 if (!sta_he_cap || !he_op)
4957 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4959 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4960 for (i = 0; i < 3; i++) {
4961 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4962 &sta_he_cap->he_mcs_nss_supp;
4963 u16 sta_mcs_map_rx =
4964 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4965 u16 sta_mcs_map_tx =
4966 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4968 bool verified = true;
4971 * For each band there is a maximum of 8 spatial streams
4972 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4973 * of 2 bits per NSS (1-8), with the values defined in enum
4974 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4975 * capabilities aren't less than the AP's minimum requirements
4976 * for this HE BSS per SS.
4977 * It is enough to find one such band that meets the reqs.
4979 for (nss = 8; nss > 0; nss--) {
4980 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4981 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4982 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4984 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4988 * Make sure the HE AP doesn't require MCSs that aren't
4989 * supported by the client
4991 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4992 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4993 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
5003 /* If here, STA doesn't meet AP's HE min requirements */
5007 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5008 struct cfg80211_bss *cbss)
5010 struct ieee80211_local *local = sdata->local;
5011 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5012 const struct ieee80211_ht_cap *ht_cap = NULL;
5013 const struct ieee80211_ht_operation *ht_oper = NULL;
5014 const struct ieee80211_vht_operation *vht_oper = NULL;
5015 const struct ieee80211_he_operation *he_oper = NULL;
5016 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
5017 struct ieee80211_supported_band *sband;
5018 struct cfg80211_chan_def chandef;
5019 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5020 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
5021 struct ieee80211_bss *bss = (void *)cbss->priv;
5022 struct ieee802_11_elems *elems;
5023 const struct cfg80211_bss_ies *ies;
5030 ies = rcu_dereference(cbss->ies);
5031 elems = ieee802_11_parse_elems(ies->data, ies->len, false,
5038 sband = local->hw.wiphy->bands[cbss->channel->band];
5040 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5041 IEEE80211_STA_DISABLE_80P80MHZ |
5042 IEEE80211_STA_DISABLE_160MHZ);
5044 /* disable HT/VHT/HE if we don't support them */
5045 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5046 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5047 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5048 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5051 if (!sband->vht_cap.vht_supported && is_5ghz) {
5052 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5053 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5056 if (!ieee80211_get_he_iftype_cap(sband,
5057 ieee80211_vif_type_p2p(&sdata->vif)))
5058 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5060 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5061 ht_oper = elems->ht_operation;
5062 ht_cap = elems->ht_cap_elem;
5065 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5070 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5071 vht_oper = elems->vht_operation;
5072 if (vht_oper && !ht_oper) {
5075 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5076 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5077 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5078 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5081 if (!elems->vht_cap_elem) {
5082 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5087 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5088 he_oper = elems->he_operation;
5091 struct ieee80211_bss_conf *bss_conf;
5094 bss_conf = &sdata->vif.bss_conf;
5096 if (elems->pwr_constr_elem)
5097 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
5099 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
5100 ARRAY_SIZE(elems->tx_pwr_env));
5102 for (i = 0; i < elems->tx_pwr_env_num; i++) {
5103 if (elems->tx_pwr_env_len[i] >
5104 sizeof(bss_conf->tx_pwr_env[j]))
5107 bss_conf->tx_pwr_env_num++;
5108 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
5109 elems->tx_pwr_env_len[i]);
5114 if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5115 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5118 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5120 for (i = 0; i < sband->n_channels; i++) {
5121 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5122 IEEE80211_CHAN_NO_80MHZ))
5130 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5132 if (sband->band == NL80211_BAND_S1GHZ) {
5133 s1g_oper = elems->s1g_oper;
5136 "AP missing S1G operation element?\n");
5139 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5142 ht_oper, vht_oper, he_oper,
5146 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5150 /* the element data was RCU protected so no longer valid anyway */
5154 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5155 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5159 /* will change later if needed */
5160 sdata->smps_mode = IEEE80211_SMPS_OFF;
5162 mutex_lock(&local->mtx);
5164 * If this fails (possibly due to channel context sharing
5165 * on incompatible channels, e.g. 80+80 and 160 sharing the
5166 * same control channel) try to use a smaller bandwidth.
5168 ret = ieee80211_vif_use_channel(sdata, &chandef,
5169 IEEE80211_CHANCTX_SHARED);
5171 /* don't downgrade for 5 and 10 MHz channels, though. */
5172 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5173 chandef.width == NL80211_CHAN_WIDTH_10)
5176 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5177 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5178 ret = ieee80211_vif_use_channel(sdata, &chandef,
5179 IEEE80211_CHANCTX_SHARED);
5182 mutex_unlock(&local->mtx);
5186 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5187 u8 *dtim_count, u8 *dtim_period)
5189 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5190 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5192 const struct ieee80211_tim_ie *tim = NULL;
5193 const struct ieee80211_bssid_index *idx;
5194 bool valid = tim_ie && tim_ie[1] >= 2;
5197 tim = (void *)(tim_ie + 2);
5200 *dtim_count = valid ? tim->dtim_count : 0;
5203 *dtim_period = valid ? tim->dtim_period : 0;
5205 /* Check if value is overridden by non-transmitted profile */
5206 if (!idx_ie || idx_ie[1] < 3)
5209 idx = (void *)(idx_ie + 2);
5212 *dtim_count = idx->dtim_count;
5215 *dtim_period = idx->dtim_period;
5220 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5221 struct cfg80211_bss *cbss, bool assoc,
5224 struct ieee80211_local *local = sdata->local;
5225 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5226 struct ieee80211_bss *bss = (void *)cbss->priv;
5227 struct sta_info *new_sta = NULL;
5228 struct ieee80211_supported_band *sband;
5229 bool have_sta = false;
5232 sband = local->hw.wiphy->bands[cbss->channel->band];
5234 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5237 /* If a reconfig is happening, bail out */
5238 if (local->in_reconfig)
5243 have_sta = sta_info_get(sdata, cbss->bssid);
5248 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5254 * Set up the information for the new channel before setting the
5255 * new channel. We can't - completely race-free - change the basic
5256 * rates bitmap and the channel (sband) that it refers to, but if
5257 * we set it up before we at least avoid calling into the driver's
5258 * bss_info_changed() method with invalid information (since we do
5259 * call that from changing the channel - only for IDLE and perhaps
5260 * some others, but ...).
5262 * So to avoid that, just set up all the new information before the
5263 * channel, but tell the driver to apply it only afterwards, since
5264 * it might need the new channel for that.
5267 u32 rates = 0, basic_rates = 0;
5268 bool have_higher_than_11mbit;
5269 int min_rate = INT_MAX, min_rate_index = -1;
5270 const struct cfg80211_bss_ies *ies;
5271 int shift = ieee80211_vif_get_shift(&sdata->vif);
5273 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5274 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5275 ieee80211_s1g_sta_rate_init(new_sta);
5279 ieee80211_get_rates(sband, bss->supp_rates,
5280 bss->supp_rates_len,
5281 &rates, &basic_rates,
5282 &have_higher_than_11mbit,
5283 &min_rate, &min_rate_index,
5287 * This used to be a workaround for basic rates missing
5288 * in the association response frame. Now that we no
5289 * longer use the basic rates from there, it probably
5290 * doesn't happen any more, but keep the workaround so
5291 * in case some *other* APs are buggy in different ways
5292 * we can connect -- with a warning.
5293 * Allow this workaround only in case the AP provided at least
5296 if (min_rate_index < 0) {
5298 "No legacy rates in association response\n");
5300 sta_info_free(local, new_sta);
5302 } else if (!basic_rates) {
5304 "No basic rates, using min rate instead\n");
5305 basic_rates = BIT(min_rate_index);
5309 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5312 "No rates found, keeping mandatory only\n");
5314 sdata->vif.bss_conf.basic_rates = basic_rates;
5316 /* cf. IEEE 802.11 9.2.12 */
5317 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5318 have_higher_than_11mbit)
5319 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5321 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5324 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5326 /* set timing information */
5327 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5329 ies = rcu_dereference(cbss->beacon_ies);
5331 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5332 sdata->vif.bss_conf.sync_device_ts =
5333 bss->device_ts_beacon;
5335 ieee80211_get_dtim(ies,
5336 &sdata->vif.bss_conf.sync_dtim_count,
5338 } else if (!ieee80211_hw_check(&sdata->local->hw,
5339 TIMING_BEACON_ONLY)) {
5340 ies = rcu_dereference(cbss->proberesp_ies);
5341 /* must be non-NULL since beacon IEs were NULL */
5342 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5343 sdata->vif.bss_conf.sync_device_ts =
5344 bss->device_ts_presp;
5345 sdata->vif.bss_conf.sync_dtim_count = 0;
5347 sdata->vif.bss_conf.sync_tsf = 0;
5348 sdata->vif.bss_conf.sync_device_ts = 0;
5349 sdata->vif.bss_conf.sync_dtim_count = 0;
5354 if (new_sta || override) {
5355 err = ieee80211_prep_channel(sdata, cbss);
5358 sta_info_free(local, new_sta);
5365 * tell driver about BSSID, basic rates and timing
5366 * this was set up above, before setting the channel
5368 ieee80211_bss_info_change_notify(sdata,
5369 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5370 BSS_CHANGED_BEACON_INT);
5373 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5375 err = sta_info_insert(new_sta);
5379 "failed to insert STA entry for the AP (error %d)\n",
5384 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5386 /* Cancel scan to ensure that nothing interferes with connection */
5387 if (local->scanning)
5388 ieee80211_scan_cancel(local);
5394 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5395 struct cfg80211_auth_request *req)
5397 struct ieee80211_local *local = sdata->local;
5398 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5399 struct ieee80211_mgd_auth_data *auth_data;
5404 /* prepare auth data structure */
5406 switch (req->auth_type) {
5407 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5408 auth_alg = WLAN_AUTH_OPEN;
5410 case NL80211_AUTHTYPE_SHARED_KEY:
5413 auth_alg = WLAN_AUTH_SHARED_KEY;
5415 case NL80211_AUTHTYPE_FT:
5416 auth_alg = WLAN_AUTH_FT;
5418 case NL80211_AUTHTYPE_NETWORK_EAP:
5419 auth_alg = WLAN_AUTH_LEAP;
5421 case NL80211_AUTHTYPE_SAE:
5422 auth_alg = WLAN_AUTH_SAE;
5424 case NL80211_AUTHTYPE_FILS_SK:
5425 auth_alg = WLAN_AUTH_FILS_SK;
5427 case NL80211_AUTHTYPE_FILS_SK_PFS:
5428 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5430 case NL80211_AUTHTYPE_FILS_PK:
5431 auth_alg = WLAN_AUTH_FILS_PK;
5437 if (ifmgd->assoc_data)
5440 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5441 req->ie_len, GFP_KERNEL);
5445 auth_data->bss = req->bss;
5447 if (req->auth_data_len >= 4) {
5448 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5449 __le16 *pos = (__le16 *) req->auth_data;
5451 auth_data->sae_trans = le16_to_cpu(pos[0]);
5452 auth_data->sae_status = le16_to_cpu(pos[1]);
5454 memcpy(auth_data->data, req->auth_data + 4,
5455 req->auth_data_len - 4);
5456 auth_data->data_len += req->auth_data_len - 4;
5459 /* Check if continuing authentication or trying to authenticate with the
5460 * same BSS that we were in the process of authenticating with and avoid
5461 * removal and re-addition of the STA entry in
5462 * ieee80211_prep_connection().
5464 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5466 if (req->ie && req->ie_len) {
5467 memcpy(&auth_data->data[auth_data->data_len],
5468 req->ie, req->ie_len);
5469 auth_data->data_len += req->ie_len;
5472 if (req->key && req->key_len) {
5473 auth_data->key_len = req->key_len;
5474 auth_data->key_idx = req->key_idx;
5475 memcpy(auth_data->key, req->key, req->key_len);
5478 auth_data->algorithm = auth_alg;
5480 /* try to authenticate/probe */
5482 if (ifmgd->auth_data) {
5483 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5484 auth_data->peer_confirmed =
5485 ifmgd->auth_data->peer_confirmed;
5487 ieee80211_destroy_auth_data(sdata, cont_auth);
5490 /* prep auth_data so we don't go into idle on disassoc */
5491 ifmgd->auth_data = auth_data;
5493 /* If this is continuation of an ongoing SAE authentication exchange
5494 * (i.e., request to send SAE Confirm) and the peer has already
5495 * confirmed, mark authentication completed since we are about to send
5498 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5499 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5500 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5502 if (ifmgd->associated) {
5503 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5506 "disconnect from AP %pM for new auth to %pM\n",
5507 ifmgd->associated->bssid, req->bss->bssid);
5508 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5509 WLAN_REASON_UNSPECIFIED,
5512 ieee80211_report_disconnect(sdata, frame_buf,
5513 sizeof(frame_buf), true,
5514 WLAN_REASON_UNSPECIFIED,
5518 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5520 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5524 err = ieee80211_auth(sdata);
5526 sta_info_destroy_addr(sdata, req->bss->bssid);
5530 /* hold our own reference */
5531 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5535 eth_zero_addr(ifmgd->bssid);
5536 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5537 ifmgd->auth_data = NULL;
5538 mutex_lock(&sdata->local->mtx);
5539 ieee80211_vif_release_channel(sdata);
5540 mutex_unlock(&sdata->local->mtx);
5545 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5546 struct cfg80211_assoc_request *req)
5548 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5549 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5550 struct ieee80211_local *local = sdata->local;
5551 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5552 struct ieee80211_bss *bss = (void *)req->bss->priv;
5553 struct ieee80211_mgd_assoc_data *assoc_data;
5554 const struct cfg80211_bss_ies *beacon_ies;
5555 struct ieee80211_supported_band *sband;
5556 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5557 const struct element *ssid_elem, *ht_elem, *vht_elem;
5559 bool override = false;
5561 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5566 ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID);
5567 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
5572 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
5573 assoc_data->ssid_len = ssid_elem->datalen;
5574 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5575 bss_conf->ssid_len = assoc_data->ssid_len;
5578 if (ifmgd->associated) {
5579 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5582 "disconnect from AP %pM for new assoc to %pM\n",
5583 ifmgd->associated->bssid, req->bss->bssid);
5584 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5585 WLAN_REASON_UNSPECIFIED,
5588 ieee80211_report_disconnect(sdata, frame_buf,
5589 sizeof(frame_buf), true,
5590 WLAN_REASON_UNSPECIFIED,
5594 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5599 if (ifmgd->assoc_data) {
5604 if (ifmgd->auth_data) {
5607 /* keep sta info, bssid if matching */
5608 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5609 ieee80211_destroy_auth_data(sdata, match);
5612 /* prepare assoc data */
5614 ifmgd->beacon_crc_valid = false;
5616 assoc_data->wmm = bss->wmm_used &&
5617 (local->hw.queues >= IEEE80211_NUM_ACS);
5620 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5621 * We still associate in non-HT mode (11a/b/g) if any one of these
5622 * ciphers is configured as pairwise.
5623 * We can set this to true for non-11n hardware, that'll be checked
5624 * separately along with the peer capabilities.
5626 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5627 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5628 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5629 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5630 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5631 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5632 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5633 netdev_info(sdata->dev,
5634 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5638 sband = local->hw.wiphy->bands[req->bss->channel->band];
5640 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5641 if (!bss->wmm_used) {
5642 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5643 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5644 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5645 netdev_info(sdata->dev,
5646 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5649 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5650 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5651 sizeof(ifmgd->ht_capa_mask));
5653 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5654 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5655 sizeof(ifmgd->vht_capa_mask));
5657 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5658 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5659 sizeof(ifmgd->s1g_capa_mask));
5661 if (req->ie && req->ie_len) {
5662 memcpy(assoc_data->ie, req->ie, req->ie_len);
5663 assoc_data->ie_len = req->ie_len;
5666 if (req->fils_kek) {
5667 /* should already be checked in cfg80211 - so warn */
5668 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5672 memcpy(assoc_data->fils_kek, req->fils_kek,
5674 assoc_data->fils_kek_len = req->fils_kek_len;
5677 if (req->fils_nonces)
5678 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5679 2 * FILS_NONCE_LEN);
5681 assoc_data->bss = req->bss;
5682 assoc_data->capability = req->bss->capability;
5683 assoc_data->supp_rates = bss->supp_rates;
5684 assoc_data->supp_rates_len = bss->supp_rates_len;
5687 ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION);
5688 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
5689 assoc_data->ap_ht_param =
5690 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
5692 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5693 vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY);
5694 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap))
5695 memcpy(&assoc_data->ap_vht_cap, vht_elem->data,
5696 sizeof(struct ieee80211_vht_cap));
5698 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5699 IEEE80211_STA_DISABLE_HE;
5702 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5703 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5704 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5705 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5707 if (bss->wmm_used && bss->uapsd_supported &&
5708 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5709 assoc_data->uapsd = true;
5710 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5712 assoc_data->uapsd = false;
5713 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5716 if (req->prev_bssid)
5717 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5720 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5721 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5723 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5724 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5727 if (req->flags & ASSOC_REQ_USE_RRM)
5728 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5730 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5732 if (req->crypto.control_port)
5733 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5735 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5737 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5738 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5739 sdata->control_port_over_nl80211 =
5740 req->crypto.control_port_over_nl80211;
5741 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5742 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5745 /* kick off associate process */
5747 ifmgd->assoc_data = assoc_data;
5748 ifmgd->dtim_period = 0;
5749 ifmgd->have_beacon = false;
5751 /* override HT/VHT configuration only if the AP and we support it */
5752 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5753 struct ieee80211_sta_ht_cap sta_ht_cap;
5755 if (req->flags & ASSOC_REQ_DISABLE_HT)
5758 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5759 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5761 /* check for 40 MHz disable override */
5762 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5763 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5764 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5767 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5768 req->flags & ASSOC_REQ_DISABLE_VHT)
5772 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5773 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5774 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5775 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5778 if (req->flags & ASSOC_REQ_DISABLE_VHT)
5779 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5781 if (req->flags & ASSOC_REQ_DISABLE_HE)
5782 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5784 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5788 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5789 if (ifmgd->powersave)
5790 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5792 sdata->smps_mode = IEEE80211_SMPS_OFF;
5794 sdata->smps_mode = ifmgd->req_smps;
5798 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5800 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5803 * Wait up to one beacon interval ...
5804 * should this be more if we miss one?
5806 sdata_info(sdata, "waiting for beacon from %pM\n",
5808 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5809 assoc_data->timeout_started = true;
5810 assoc_data->need_beacon = true;
5811 } else if (beacon_ies) {
5812 const struct element *elem;
5815 ieee80211_get_dtim(beacon_ies, &dtim_count,
5816 &ifmgd->dtim_period);
5818 ifmgd->have_beacon = true;
5819 assoc_data->timeout = jiffies;
5820 assoc_data->timeout_started = true;
5822 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5823 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5824 sdata->vif.bss_conf.sync_device_ts =
5825 bss->device_ts_beacon;
5826 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5829 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5830 beacon_ies->data, beacon_ies->len);
5831 if (elem && elem->datalen >= 3)
5832 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5834 sdata->vif.bss_conf.profile_periodicity = 0;
5836 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5837 beacon_ies->data, beacon_ies->len);
5838 if (elem && elem->datalen >= 11 &&
5839 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5840 sdata->vif.bss_conf.ema_ap = true;
5842 sdata->vif.bss_conf.ema_ap = false;
5844 assoc_data->timeout = jiffies;
5845 assoc_data->timeout_started = true;
5849 run_again(sdata, assoc_data->timeout);
5851 if (bss->corrupt_data) {
5852 char *corrupt_type = "data";
5853 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5854 if (bss->corrupt_data &
5855 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5856 corrupt_type = "beacon and probe response";
5858 corrupt_type = "beacon";
5859 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5860 corrupt_type = "probe response";
5861 sdata_info(sdata, "associating with AP with corrupt %s\n",
5867 eth_zero_addr(ifmgd->bssid);
5868 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5869 ifmgd->assoc_data = NULL;
5875 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5876 struct cfg80211_deauth_request *req)
5878 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5879 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5880 bool tx = !req->local_state_change;
5881 struct ieee80211_prep_tx_info info = {
5882 .subtype = IEEE80211_STYPE_DEAUTH,
5885 if (ifmgd->auth_data &&
5886 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5888 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5889 req->bssid, req->reason_code,
5890 ieee80211_get_reason_code_string(req->reason_code));
5892 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5893 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5894 IEEE80211_STYPE_DEAUTH,
5895 req->reason_code, tx,
5897 ieee80211_destroy_auth_data(sdata, false);
5898 ieee80211_report_disconnect(sdata, frame_buf,
5899 sizeof(frame_buf), true,
5900 req->reason_code, false);
5901 drv_mgd_complete_tx(sdata->local, sdata, &info);
5905 if (ifmgd->assoc_data &&
5906 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5908 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5909 req->bssid, req->reason_code,
5910 ieee80211_get_reason_code_string(req->reason_code));
5912 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5913 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5914 IEEE80211_STYPE_DEAUTH,
5915 req->reason_code, tx,
5917 ieee80211_destroy_assoc_data(sdata, false, true);
5918 ieee80211_report_disconnect(sdata, frame_buf,
5919 sizeof(frame_buf), true,
5920 req->reason_code, false);
5924 if (ifmgd->associated &&
5925 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5927 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5928 req->bssid, req->reason_code,
5929 ieee80211_get_reason_code_string(req->reason_code));
5931 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5932 req->reason_code, tx, frame_buf);
5933 ieee80211_report_disconnect(sdata, frame_buf,
5934 sizeof(frame_buf), true,
5935 req->reason_code, false);
5936 drv_mgd_complete_tx(sdata->local, sdata, &info);
5943 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5944 struct cfg80211_disassoc_request *req)
5946 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5948 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5951 * cfg80211 should catch this ... but it's racy since
5952 * we can receive a disassoc frame, process it, hand it
5953 * to cfg80211 while that's in a locked section already
5954 * trying to tell us that the user wants to disconnect.
5956 if (ifmgd->associated != req->bss)
5960 "disassociating from %pM by local choice (Reason: %u=%s)\n",
5961 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
5963 memcpy(bssid, req->bss->bssid, ETH_ALEN);
5964 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
5965 req->reason_code, !req->local_state_change,
5968 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5969 req->reason_code, false);
5974 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
5976 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5979 * Make sure some work items will not run after this,
5980 * they will not do anything but might not have been
5981 * cancelled when disconnecting.
5983 cancel_work_sync(&ifmgd->monitor_work);
5984 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
5985 cancel_work_sync(&ifmgd->request_smps_work);
5986 cancel_work_sync(&ifmgd->csa_connection_drop_work);
5987 cancel_work_sync(&ifmgd->chswitch_work);
5988 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
5991 if (ifmgd->assoc_data) {
5992 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
5993 ieee80211_destroy_assoc_data(sdata, false, false);
5994 cfg80211_assoc_timeout(sdata->dev, bss);
5996 if (ifmgd->auth_data)
5997 ieee80211_destroy_auth_data(sdata, false);
5998 spin_lock_bh(&ifmgd->teardown_lock);
5999 if (ifmgd->teardown_skb) {
6000 kfree_skb(ifmgd->teardown_skb);
6001 ifmgd->teardown_skb = NULL;
6002 ifmgd->orig_teardown_skb = NULL;
6004 kfree(ifmgd->assoc_req_ies);
6005 ifmgd->assoc_req_ies = NULL;
6006 ifmgd->assoc_req_ies_len = 0;
6007 spin_unlock_bh(&ifmgd->teardown_lock);
6008 del_timer_sync(&ifmgd->timer);
6009 sdata_unlock(sdata);
6012 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
6013 enum nl80211_cqm_rssi_threshold_event rssi_event,
6017 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6019 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
6021 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
6023 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
6025 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
6027 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6029 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
6031 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
6033 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);