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_AUTH_WAIT_SAE_RETRY (HZ * 2)
41 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
42 #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
43 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
44 #define IEEE80211_ASSOC_MAX_TRIES 3
46 static int max_nullfunc_tries = 2;
47 module_param(max_nullfunc_tries, int, 0644);
48 MODULE_PARM_DESC(max_nullfunc_tries,
49 "Maximum nullfunc tx tries before disconnecting (reason 4).");
51 static int max_probe_tries = 5;
52 module_param(max_probe_tries, int, 0644);
53 MODULE_PARM_DESC(max_probe_tries,
54 "Maximum probe tries before disconnecting (reason 4).");
57 * Beacon loss timeout is calculated as N frames times the
58 * advertised beacon interval. This may need to be somewhat
59 * higher than what hardware might detect to account for
60 * delays in the host processing frames. But since we also
61 * probe on beacon miss before declaring the connection lost
62 * default to what we want.
64 static int beacon_loss_count = 7;
65 module_param(beacon_loss_count, int, 0644);
66 MODULE_PARM_DESC(beacon_loss_count,
67 "Number of beacon intervals before we decide beacon was lost.");
70 * Time the connection can be idle before we probe
71 * it to see if we can still talk to the AP.
73 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
75 * Time we wait for a probe response after sending
76 * a probe request because of beacon loss or for
77 * checking the connection still works.
79 static int probe_wait_ms = 500;
80 module_param(probe_wait_ms, int, 0644);
81 MODULE_PARM_DESC(probe_wait_ms,
82 "Maximum time(ms) to wait for probe response"
83 " before disconnecting (reason 4).");
86 * How many Beacon frames need to have been used in average signal strength
87 * before starting to indicate signal change events.
89 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
101 static void run_again(struct ieee80211_sub_if_data *sdata,
102 unsigned long timeout)
104 sdata_assert_lock(sdata);
106 if (!timer_pending(&sdata->u.mgd.timer) ||
107 time_before(timeout, sdata->u.mgd.timer.expires))
108 mod_timer(&sdata->u.mgd.timer, timeout);
111 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
113 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
116 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
119 mod_timer(&sdata->u.mgd.bcn_mon_timer,
120 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
123 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
125 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
127 if (unlikely(!ifmgd->associated))
130 if (ifmgd->probe_send_count)
131 ifmgd->probe_send_count = 0;
133 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
136 mod_timer(&ifmgd->conn_mon_timer,
137 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
140 static int ecw2cw(int ecw)
142 return (1 << ecw) - 1;
146 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
147 struct ieee80211_supported_band *sband,
148 struct ieee80211_channel *channel,
150 const struct ieee80211_ht_operation *ht_oper,
151 const struct ieee80211_vht_operation *vht_oper,
152 const struct ieee80211_he_operation *he_oper,
153 const struct ieee80211_s1g_oper_ie *s1g_oper,
154 struct cfg80211_chan_def *chandef, bool tracking)
156 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
157 struct cfg80211_chan_def vht_chandef;
158 struct ieee80211_sta_ht_cap sta_ht_cap;
161 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
162 chandef->chan = channel;
163 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
164 chandef->center_freq1 = channel->center_freq;
165 chandef->freq1_offset = channel->freq_offset;
167 if (channel->band == NL80211_BAND_6GHZ) {
168 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, chandef)) {
170 "bad 6 GHz operation, disabling HT/VHT/HE\n");
171 ret = IEEE80211_STA_DISABLE_HT |
172 IEEE80211_STA_DISABLE_VHT |
173 IEEE80211_STA_DISABLE_HE;
177 vht_chandef = *chandef;
179 } else if (sband->band == NL80211_BAND_S1GHZ) {
180 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
182 "Missing S1G Operation Element? Trying operating == primary\n");
183 chandef->width = ieee80211_s1g_channel_width(channel);
186 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_40MHZ |
187 IEEE80211_STA_DISABLE_VHT |
188 IEEE80211_STA_DISABLE_80P80MHZ |
189 IEEE80211_STA_DISABLE_160MHZ;
193 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
194 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
196 if (!ht_oper || !sta_ht_cap.ht_supported) {
197 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
198 ret = IEEE80211_STA_DISABLE_HT |
199 IEEE80211_STA_DISABLE_VHT |
200 IEEE80211_STA_DISABLE_HE;
204 chandef->width = NL80211_CHAN_WIDTH_20;
206 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
208 /* check that channel matches the right operating channel */
209 if (!tracking && channel->center_freq != ht_cfreq) {
211 * It's possible that some APs are confused here;
212 * Netgear WNDR3700 sometimes reports 4 higher than
213 * the actual channel in association responses, but
214 * since we look at probe response/beacon data here
218 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
219 channel->center_freq, ht_cfreq,
220 ht_oper->primary_chan, channel->band);
221 ret = IEEE80211_STA_DISABLE_HT |
222 IEEE80211_STA_DISABLE_VHT |
223 IEEE80211_STA_DISABLE_HE;
227 /* check 40 MHz support, if we have it */
228 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
229 ieee80211_chandef_ht_oper(ht_oper, chandef);
231 mlme_dbg(sdata, "40 MHz not supported\n");
232 /* 40 MHz (and 80 MHz) must be supported for VHT */
233 ret = IEEE80211_STA_DISABLE_VHT;
234 /* also mark 40 MHz disabled */
235 ret |= IEEE80211_STA_DISABLE_40MHZ;
239 if (!vht_oper || !sband->vht_cap.vht_supported) {
240 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
241 ret = IEEE80211_STA_DISABLE_VHT;
245 vht_chandef = *chandef;
246 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
247 (le32_to_cpu(he_oper->he_oper_params) &
248 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
249 struct ieee80211_vht_operation he_oper_vht_cap;
252 * Set only first 3 bytes (other 2 aren't used in
253 * ieee80211_chandef_vht_oper() anyway)
255 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
256 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
258 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
259 &he_oper_vht_cap, ht_oper,
261 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
263 "HE AP VHT information is invalid, disabling HE\n");
264 ret = IEEE80211_STA_DISABLE_HE;
267 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
271 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
273 "AP VHT information is invalid, disabling VHT\n");
274 ret = IEEE80211_STA_DISABLE_VHT;
278 if (!cfg80211_chandef_valid(&vht_chandef)) {
279 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
281 "AP VHT information is invalid, disabling VHT\n");
282 ret = IEEE80211_STA_DISABLE_VHT;
286 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
291 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
292 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
294 "AP VHT information doesn't match HT, disabling VHT\n");
295 ret = IEEE80211_STA_DISABLE_VHT;
299 *chandef = vht_chandef;
305 * When tracking the current AP, don't do any further checks if the
306 * new chandef is identical to the one we're currently using for the
307 * connection. This keeps us from playing ping-pong with regulatory,
308 * without it the following can happen (for example):
309 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
310 * - AP advertises regdom US
311 * - CRDA loads regdom US with 80 MHz prohibited (old database)
312 * - the code below detects an unsupported channel, downgrades, and
313 * we disconnect from the AP in the caller
314 * - disconnect causes CRDA to reload world regdomain and the game
316 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
318 * It seems possible that there are still scenarios with CSA or real
319 * bandwidth changes where a this could happen, but those cases are
320 * less common and wouldn't completely prevent using the AP.
323 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
326 /* don't print the message below for VHT mismatch if VHT is disabled */
327 if (ret & IEEE80211_STA_DISABLE_VHT)
328 vht_chandef = *chandef;
331 * Ignore the DISABLED flag when we're already connected and only
332 * tracking the APs beacon for bandwidth changes - otherwise we
333 * might get disconnected here if we connect to an AP, update our
334 * regulatory information based on the AP's country IE and the
335 * information we have is wrong/outdated and disables the channel
336 * that we're actually using for the connection to the AP.
338 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
340 IEEE80211_CHAN_DISABLED)) {
341 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
342 ret = IEEE80211_STA_DISABLE_HT |
343 IEEE80211_STA_DISABLE_VHT |
344 IEEE80211_STA_DISABLE_HE;
348 ret |= ieee80211_chandef_downgrade(chandef);
351 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
352 IEEE80211_CHAN_NO_HE))
353 ret |= IEEE80211_STA_DISABLE_HE;
355 if (chandef->width != vht_chandef.width && !tracking)
357 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
359 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
363 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
364 struct sta_info *sta,
365 const struct ieee80211_ht_cap *ht_cap,
366 const struct ieee80211_vht_cap *vht_cap,
367 const struct ieee80211_ht_operation *ht_oper,
368 const struct ieee80211_vht_operation *vht_oper,
369 const struct ieee80211_he_operation *he_oper,
370 const struct ieee80211_s1g_oper_ie *s1g_oper,
371 const u8 *bssid, u32 *changed)
373 struct ieee80211_local *local = sdata->local;
374 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
375 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
376 struct ieee80211_supported_band *sband =
377 local->hw.wiphy->bands[chan->band];
378 struct cfg80211_chan_def chandef;
381 u32 vht_cap_info = 0;
384 /* if HT was/is disabled, don't track any bandwidth changes */
385 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
388 /* don't check VHT if we associated as non-VHT station */
389 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
392 /* don't check HE if we associated as non-HE station */
393 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
394 !ieee80211_get_he_iftype_cap(sband,
395 ieee80211_vif_type_p2p(&sdata->vif)))
399 if (WARN_ON_ONCE(!sta))
403 * if bss configuration changed store the new one -
404 * this may be applicable even if channel is identical
406 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
407 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
408 *changed |= BSS_CHANGED_HT;
409 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
413 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
415 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
416 flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info,
417 ht_oper, vht_oper, he_oper,
418 s1g_oper, &chandef, true);
421 * Downgrade the new channel if we associated with restricted
422 * capabilities. For example, if we associated as a 20 MHz STA
423 * to a 40 MHz AP (due to regulatory, capabilities or config
424 * reasons) then switching to a 40 MHz channel now won't do us
425 * any good -- we couldn't use it with the AP.
427 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
428 chandef.width == NL80211_CHAN_WIDTH_80P80)
429 flags |= ieee80211_chandef_downgrade(&chandef);
430 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
431 chandef.width == NL80211_CHAN_WIDTH_160)
432 flags |= ieee80211_chandef_downgrade(&chandef);
433 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
434 chandef.width > NL80211_CHAN_WIDTH_20)
435 flags |= ieee80211_chandef_downgrade(&chandef);
437 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
441 "AP %pM changed bandwidth, new config is %d.%03d MHz, "
442 "width %d (%d.%03d/%d MHz)\n",
443 ifmgd->bssid, chandef.chan->center_freq,
444 chandef.chan->freq_offset, chandef.width,
445 chandef.center_freq1, chandef.freq1_offset,
446 chandef.center_freq2);
448 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
449 IEEE80211_STA_DISABLE_VHT |
450 IEEE80211_STA_DISABLE_HE |
451 IEEE80211_STA_DISABLE_40MHZ |
452 IEEE80211_STA_DISABLE_80P80MHZ |
453 IEEE80211_STA_DISABLE_160MHZ)) ||
454 !cfg80211_chandef_valid(&chandef)) {
456 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
457 ifmgd->bssid, flags, ifmgd->flags);
461 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
465 "AP %pM changed bandwidth to incompatible one - disconnect\n",
473 /* frame sending functions */
475 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
476 struct sk_buff *skb, u8 ap_ht_param,
477 struct ieee80211_supported_band *sband,
478 struct ieee80211_channel *channel,
479 enum ieee80211_smps_mode smps)
482 u32 flags = channel->flags;
484 struct ieee80211_sta_ht_cap ht_cap;
486 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
488 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
489 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
491 /* determine capability flags */
494 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
495 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
496 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
497 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
498 cap &= ~IEEE80211_HT_CAP_SGI_40;
501 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
502 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
503 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
504 cap &= ~IEEE80211_HT_CAP_SGI_40;
510 * If 40 MHz was disabled associate as though we weren't
511 * capable of 40 MHz -- some broken APs will never fall
512 * back to trying to transmit in 20 MHz.
514 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
515 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
516 cap &= ~IEEE80211_HT_CAP_SGI_40;
519 /* set SM PS mode properly */
520 cap &= ~IEEE80211_HT_CAP_SM_PS;
522 case IEEE80211_SMPS_AUTOMATIC:
523 case IEEE80211_SMPS_NUM_MODES:
526 case IEEE80211_SMPS_OFF:
527 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
528 IEEE80211_HT_CAP_SM_PS_SHIFT;
530 case IEEE80211_SMPS_STATIC:
531 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
532 IEEE80211_HT_CAP_SM_PS_SHIFT;
534 case IEEE80211_SMPS_DYNAMIC:
535 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
536 IEEE80211_HT_CAP_SM_PS_SHIFT;
540 /* reserve and fill IE */
541 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
542 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
545 /* This function determines vht capability flags for the association
547 * Note - the function may set the owner of the MU-MIMO capability
549 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
551 struct ieee80211_supported_band *sband,
552 struct ieee80211_vht_cap *ap_vht_cap)
554 struct ieee80211_local *local = sdata->local;
557 struct ieee80211_sta_vht_cap vht_cap;
558 u32 mask, ap_bf_sts, our_bf_sts;
560 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
562 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
563 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
565 /* determine capability flags */
568 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
569 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
571 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
572 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
573 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
574 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
577 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
578 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
579 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
583 * Some APs apparently get confused if our capabilities are better
584 * than theirs, so restrict what we advertise in the assoc request.
586 if (!(ap_vht_cap->vht_cap_info &
587 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
588 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
589 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
590 else if (!(ap_vht_cap->vht_cap_info &
591 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
592 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
595 * If some other vif is using the MU-MIMO capability we cannot associate
596 * using MU-MIMO - this will lead to contradictions in the group-id
598 * Ownership is defined since association request, in order to avoid
599 * simultaneous associations with MU-MIMO.
601 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
602 bool disable_mu_mimo = false;
603 struct ieee80211_sub_if_data *other;
605 list_for_each_entry_rcu(other, &local->interfaces, list) {
606 if (other->vif.mu_mimo_owner) {
607 disable_mu_mimo = true;
612 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
614 sdata->vif.mu_mimo_owner = true;
617 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
619 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
620 our_bf_sts = cap & mask;
622 if (ap_bf_sts < our_bf_sts) {
627 /* reserve and fill IE */
628 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
629 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
632 /* This function determines HE capability flags for the association
635 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
637 struct ieee80211_supported_band *sband)
640 const struct ieee80211_sta_he_cap *he_cap = NULL;
641 struct ieee80211_chanctx_conf *chanctx_conf;
643 bool reg_cap = false;
646 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
647 if (!WARN_ON_ONCE(!chanctx_conf))
648 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
650 IEEE80211_CHAN_NO_HE);
654 he_cap = ieee80211_get_he_iftype_cap(sband,
655 ieee80211_vif_type_p2p(&sdata->vif));
656 if (!he_cap || !reg_cap)
660 2 + 1 + sizeof(he_cap->he_cap_elem) +
661 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
662 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
663 he_cap->he_cap_elem.phy_cap_info);
664 pos = skb_put(skb, he_cap_size);
665 ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
667 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
670 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
672 struct ieee80211_local *local = sdata->local;
673 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
674 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
676 struct ieee80211_mgmt *mgmt;
677 u8 *pos, qos_info, *ie_start;
678 size_t offset = 0, noffset;
679 int i, count, rates_len, supp_rates_len, shift;
681 struct ieee80211_supported_band *sband;
682 struct ieee80211_chanctx_conf *chanctx_conf;
683 struct ieee80211_channel *chan;
686 struct element *ext_capa = NULL;
687 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
688 const struct ieee80211_sband_iftype_data *iftd;
689 struct ieee80211_prep_tx_info info = {};
692 /* we know it's writable, cast away the const */
693 if (assoc_data->ie_len)
694 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
698 sdata_assert_lock(sdata);
701 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
702 if (WARN_ON(!chanctx_conf)) {
706 chan = chanctx_conf->def.chan;
708 sband = local->hw.wiphy->bands[chan->band];
709 shift = ieee80211_vif_get_shift(&sdata->vif);
711 if (assoc_data->supp_rates_len) {
713 * Get all rates supported by the device and the AP as
714 * some APs don't like getting a superset of their rates
715 * in the association request (e.g. D-Link DAP 1353 in
718 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
719 assoc_data->supp_rates,
720 assoc_data->supp_rates_len,
724 * In case AP not provide any supported rates information
725 * before association, we send information element(s) with
726 * all rates that we support.
729 for (i = 0; i < sband->n_bitrates; i++) {
735 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
737 skb = alloc_skb(local->hw.extra_tx_headroom +
738 sizeof(*mgmt) + /* bit too much but doesn't matter */
739 2 + assoc_data->ssid_len + /* SSID */
740 4 + rates_len + /* (extended) rates */
741 4 + /* power capability */
742 2 + 2 * sband->n_channels + /* supported channels */
743 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
744 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
745 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
746 sizeof(struct ieee80211_he_mcs_nss_supp) +
747 IEEE80211_HE_PPE_THRES_MAX_LEN +
748 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
749 assoc_data->ie_len + /* extra IEs */
750 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
752 (iftd ? iftd->vendor_elems.len : 0),
757 skb_reserve(skb, local->hw.extra_tx_headroom);
759 capab = WLAN_CAPABILITY_ESS;
761 if (sband->band == NL80211_BAND_2GHZ) {
762 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
763 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
766 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
767 capab |= WLAN_CAPABILITY_PRIVACY;
769 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
770 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
771 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
773 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
774 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
776 mgmt = skb_put_zero(skb, 24);
777 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
778 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
779 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
781 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
782 ieee80211_encode_usf(local->hw.conf.listen_interval) :
783 local->hw.conf.listen_interval);
784 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
786 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
787 IEEE80211_STYPE_REASSOC_REQ);
788 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
789 mgmt->u.reassoc_req.listen_interval = listen_int;
790 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
792 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
795 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
796 IEEE80211_STYPE_ASSOC_REQ);
797 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
798 mgmt->u.assoc_req.listen_interval = listen_int;
799 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
803 pos = skb_put(skb, 2 + assoc_data->ssid_len);
805 *pos++ = WLAN_EID_SSID;
806 *pos++ = assoc_data->ssid_len;
807 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
809 if (sband->band == NL80211_BAND_S1GHZ)
812 /* add all rates which were marked to be used above */
813 supp_rates_len = rates_len;
814 if (supp_rates_len > 8)
817 pos = skb_put(skb, supp_rates_len + 2);
818 *pos++ = WLAN_EID_SUPP_RATES;
819 *pos++ = supp_rates_len;
822 for (i = 0; i < sband->n_bitrates; i++) {
823 if (BIT(i) & rates) {
824 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
832 if (rates_len > count) {
833 pos = skb_put(skb, rates_len - count + 2);
834 *pos++ = WLAN_EID_EXT_SUPP_RATES;
835 *pos++ = rates_len - count;
837 for (i++; i < sband->n_bitrates; i++) {
838 if (BIT(i) & rates) {
840 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
848 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
849 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
850 pos = skb_put(skb, 4);
851 *pos++ = WLAN_EID_PWR_CAPABILITY;
853 *pos++ = 0; /* min tx power */
855 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
859 * Per spec, we shouldn't include the list of channels if we advertise
860 * support for extended channel switching, but we've always done that;
861 * (for now?) apply this restriction only on the (new) 6 GHz band.
863 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
864 (sband->band != NL80211_BAND_6GHZ ||
865 !ext_capa || ext_capa->datalen < 1 ||
866 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
867 /* TODO: get this in reg domain format */
868 pos = skb_put(skb, 2 * sband->n_channels + 2);
869 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
870 *pos++ = 2 * sband->n_channels;
871 for (i = 0; i < sband->n_channels; i++) {
872 *pos++ = ieee80211_frequency_to_channel(
873 sband->channels[i].center_freq);
874 *pos++ = 1; /* one channel in the subband*/
878 /* Set MBSSID support for HE AP if needed */
879 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
880 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
881 ext_capa && ext_capa->datalen >= 3)
882 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
884 /* if present, add any custom IEs that go before HT */
885 if (assoc_data->ie_len) {
886 static const u8 before_ht[] = {
889 WLAN_EID_EXT_SUPP_RATES,
890 WLAN_EID_PWR_CAPABILITY,
891 WLAN_EID_SUPPORTED_CHANNELS,
894 WLAN_EID_RRM_ENABLED_CAPABILITIES,
895 WLAN_EID_MOBILITY_DOMAIN,
896 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
897 WLAN_EID_RIC_DATA, /* reassoc only */
898 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
900 static const u8 after_ric[] = {
901 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
902 WLAN_EID_HT_CAPABILITY,
903 WLAN_EID_BSS_COEX_2040,
904 /* luckily this is almost always there */
905 WLAN_EID_EXT_CAPABILITY,
906 WLAN_EID_QOS_TRAFFIC_CAPA,
907 WLAN_EID_TIM_BCAST_REQ,
908 WLAN_EID_INTERWORKING,
909 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
910 WLAN_EID_VHT_CAPABILITY,
911 WLAN_EID_OPMODE_NOTIF,
914 noffset = ieee80211_ie_split_ric(assoc_data->ie,
917 ARRAY_SIZE(before_ht),
919 ARRAY_SIZE(after_ric),
921 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
925 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
926 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
927 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
929 if (sband->band != NL80211_BAND_6GHZ &&
930 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
931 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
932 sband, chan, sdata->smps_mode);
934 /* if present, add any custom IEs that go before VHT */
935 if (assoc_data->ie_len) {
936 static const u8 before_vht[] = {
938 * no need to list the ones split off before HT
941 WLAN_EID_BSS_COEX_2040,
942 WLAN_EID_EXT_CAPABILITY,
943 WLAN_EID_QOS_TRAFFIC_CAPA,
944 WLAN_EID_TIM_BCAST_REQ,
945 WLAN_EID_INTERWORKING,
946 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
949 /* RIC already taken above, so no need to handle here anymore */
950 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
951 before_vht, ARRAY_SIZE(before_vht),
953 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
957 /* if present, add any custom IEs that go before HE */
958 if (assoc_data->ie_len) {
959 static const u8 before_he[] = {
961 * no need to list the ones split off before VHT
964 WLAN_EID_OPMODE_NOTIF,
965 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
967 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
968 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
969 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
970 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
971 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
972 /* TODO: add 11ah/11aj/11ak elements */
975 /* RIC already taken above, so no need to handle here anymore */
976 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
977 before_he, ARRAY_SIZE(before_he),
979 pos = skb_put(skb, noffset - offset);
980 memcpy(pos, assoc_data->ie + offset, noffset - offset);
984 if (sband->band != NL80211_BAND_6GHZ &&
985 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
986 ieee80211_add_vht_ie(sdata, skb, sband,
987 &assoc_data->ap_vht_cap);
990 * If AP doesn't support HT, mark HE as disabled.
991 * If on the 5GHz band, make sure it supports VHT.
993 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
994 (sband->band == NL80211_BAND_5GHZ &&
995 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
996 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
998 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
999 ieee80211_add_he_ie(sdata, skb, sband);
1001 /* if present, add any custom non-vendor IEs that go after HE */
1002 if (assoc_data->ie_len) {
1003 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1006 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1010 if (assoc_data->wmm) {
1011 if (assoc_data->uapsd) {
1012 qos_info = ifmgd->uapsd_queues;
1013 qos_info |= (ifmgd->uapsd_max_sp_len <<
1014 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1019 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1022 if (sband->band == NL80211_BAND_S1GHZ) {
1023 ieee80211_add_aid_request_ie(sdata, skb);
1024 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1027 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1028 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1030 /* add any remaining custom (i.e. vendor specific here) IEs */
1031 if (assoc_data->ie_len) {
1032 noffset = assoc_data->ie_len;
1033 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1036 if (assoc_data->fils_kek_len) {
1037 ret = fils_encrypt_assoc_req(skb, assoc_data);
1044 pos = skb_tail_pointer(skb);
1045 kfree(ifmgd->assoc_req_ies);
1046 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1047 if (!ifmgd->assoc_req_ies) {
1052 ifmgd->assoc_req_ies_len = pos - ie_start;
1054 drv_mgd_prepare_tx(local, sdata, &info);
1056 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1057 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1058 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1059 IEEE80211_TX_INTFL_MLME_CONN_TX;
1060 ieee80211_tx_skb(sdata, skb);
1065 void ieee80211_send_pspoll(struct ieee80211_local *local,
1066 struct ieee80211_sub_if_data *sdata)
1068 struct ieee80211_pspoll *pspoll;
1069 struct sk_buff *skb;
1071 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1075 pspoll = (struct ieee80211_pspoll *) skb->data;
1076 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1078 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1079 ieee80211_tx_skb(sdata, skb);
1082 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1083 struct ieee80211_sub_if_data *sdata,
1086 struct sk_buff *skb;
1087 struct ieee80211_hdr_3addr *nullfunc;
1088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1090 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1091 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1095 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1097 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1099 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1100 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1102 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1103 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1105 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1106 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1108 ieee80211_tx_skb(sdata, skb);
1111 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1112 struct ieee80211_sub_if_data *sdata)
1114 struct sk_buff *skb;
1115 struct ieee80211_hdr *nullfunc;
1118 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1121 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1125 skb_reserve(skb, local->hw.extra_tx_headroom);
1127 nullfunc = skb_put_zero(skb, 30);
1128 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1129 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1130 nullfunc->frame_control = fc;
1131 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1132 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1133 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1134 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1136 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1137 ieee80211_tx_skb(sdata, skb);
1140 /* spectrum management related things */
1141 static void ieee80211_chswitch_work(struct work_struct *work)
1143 struct ieee80211_sub_if_data *sdata =
1144 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1145 struct ieee80211_local *local = sdata->local;
1146 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1149 if (!ieee80211_sdata_running(sdata))
1153 mutex_lock(&local->mtx);
1154 mutex_lock(&local->chanctx_mtx);
1156 if (!ifmgd->associated)
1159 if (!sdata->vif.csa_active)
1163 * using reservation isn't immediate as it may be deferred until later
1164 * with multi-vif. once reservation is complete it will re-schedule the
1165 * work with no reserved_chanctx so verify chandef to check if it
1166 * completed successfully
1169 if (sdata->reserved_chanctx) {
1171 * with multi-vif csa driver may call ieee80211_csa_finish()
1172 * many times while waiting for other interfaces to use their
1175 if (sdata->reserved_ready)
1178 ret = ieee80211_vif_use_reserved_context(sdata);
1181 "failed to use reserved channel context, disconnecting (err=%d)\n",
1183 ieee80211_queue_work(&sdata->local->hw,
1184 &ifmgd->csa_connection_drop_work);
1191 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1192 &sdata->csa_chandef)) {
1194 "failed to finalize channel switch, disconnecting\n");
1195 ieee80211_queue_work(&sdata->local->hw,
1196 &ifmgd->csa_connection_drop_work);
1200 ifmgd->csa_waiting_bcn = true;
1202 ieee80211_sta_reset_beacon_monitor(sdata);
1203 ieee80211_sta_reset_conn_monitor(sdata);
1206 mutex_unlock(&local->chanctx_mtx);
1207 mutex_unlock(&local->mtx);
1208 sdata_unlock(sdata);
1211 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1213 struct ieee80211_local *local = sdata->local;
1214 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1217 sdata_assert_lock(sdata);
1219 WARN_ON(!sdata->vif.csa_active);
1221 if (sdata->csa_block_tx) {
1222 ieee80211_wake_vif_queues(local, sdata,
1223 IEEE80211_QUEUE_STOP_REASON_CSA);
1224 sdata->csa_block_tx = false;
1227 sdata->vif.csa_active = false;
1228 ifmgd->csa_waiting_bcn = false;
1230 * If the CSA IE is still present on the beacon after the switch,
1231 * we need to consider it as a new CSA (possibly to self).
1233 ifmgd->beacon_crc_valid = false;
1235 ret = drv_post_channel_switch(sdata);
1238 "driver post channel switch failed, disconnecting\n");
1239 ieee80211_queue_work(&local->hw,
1240 &ifmgd->csa_connection_drop_work);
1244 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1247 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1249 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1250 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1252 trace_api_chswitch_done(sdata, success);
1255 "driver channel switch failed, disconnecting\n");
1256 ieee80211_queue_work(&sdata->local->hw,
1257 &ifmgd->csa_connection_drop_work);
1259 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1262 EXPORT_SYMBOL(ieee80211_chswitch_done);
1264 static void ieee80211_chswitch_timer(struct timer_list *t)
1266 struct ieee80211_sub_if_data *sdata =
1267 from_timer(sdata, t, u.mgd.chswitch_timer);
1269 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1273 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1275 struct ieee80211_local *local = sdata->local;
1277 if (!local->ops->abort_channel_switch)
1280 mutex_lock(&local->mtx);
1282 mutex_lock(&local->chanctx_mtx);
1283 ieee80211_vif_unreserve_chanctx(sdata);
1284 mutex_unlock(&local->chanctx_mtx);
1286 if (sdata->csa_block_tx)
1287 ieee80211_wake_vif_queues(local, sdata,
1288 IEEE80211_QUEUE_STOP_REASON_CSA);
1290 sdata->csa_block_tx = false;
1291 sdata->vif.csa_active = false;
1293 mutex_unlock(&local->mtx);
1295 drv_abort_channel_switch(sdata);
1299 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1300 u64 timestamp, u32 device_timestamp,
1301 struct ieee802_11_elems *elems,
1304 struct ieee80211_local *local = sdata->local;
1305 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1306 struct cfg80211_bss *cbss = ifmgd->associated;
1307 struct ieee80211_chanctx_conf *conf;
1308 struct ieee80211_chanctx *chanctx;
1309 enum nl80211_band current_band;
1310 struct ieee80211_csa_ie csa_ie;
1311 struct ieee80211_channel_switch ch_switch;
1312 struct ieee80211_bss *bss;
1315 sdata_assert_lock(sdata);
1320 if (local->scanning)
1323 current_band = cbss->channel->band;
1324 bss = (void *)cbss->priv;
1325 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1328 ifmgd->associated->bssid, &csa_ie);
1331 ch_switch.timestamp = timestamp;
1332 ch_switch.device_timestamp = device_timestamp;
1333 ch_switch.block_tx = csa_ie.mode;
1334 ch_switch.chandef = csa_ie.chandef;
1335 ch_switch.count = csa_ie.count;
1336 ch_switch.delay = csa_ie.max_switch_time;
1340 goto lock_and_drop_connection;
1342 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1344 ieee80211_sta_abort_chanswitch(sdata);
1346 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1348 } else if (sdata->vif.csa_active || res) {
1349 /* disregard subsequent announcements if already processing */
1353 if (sdata->vif.bss_conf.chandef.chan->band !=
1354 csa_ie.chandef.chan->band) {
1356 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1357 ifmgd->associated->bssid,
1358 csa_ie.chandef.chan->center_freq,
1359 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1360 csa_ie.chandef.center_freq2);
1361 goto lock_and_drop_connection;
1364 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1365 IEEE80211_CHAN_DISABLED)) {
1367 "AP %pM switches to unsupported channel "
1368 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1370 ifmgd->associated->bssid,
1371 csa_ie.chandef.chan->center_freq,
1372 csa_ie.chandef.chan->freq_offset,
1373 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1374 csa_ie.chandef.freq1_offset,
1375 csa_ie.chandef.center_freq2);
1376 goto lock_and_drop_connection;
1379 if (cfg80211_chandef_identical(&csa_ie.chandef,
1380 &sdata->vif.bss_conf.chandef) &&
1381 (!csa_ie.mode || !beacon)) {
1382 if (ifmgd->csa_ignored_same_chan)
1385 "AP %pM tries to chanswitch to same channel, ignore\n",
1386 ifmgd->associated->bssid);
1387 ifmgd->csa_ignored_same_chan = true;
1392 * Drop all TDLS peers - either we disconnect or move to a different
1393 * channel from this point on. There's no telling what our peer will do.
1394 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1395 * have an incompatible wider chandef.
1397 ieee80211_teardown_tdls_peers(sdata);
1399 mutex_lock(&local->mtx);
1400 mutex_lock(&local->chanctx_mtx);
1401 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1402 lockdep_is_held(&local->chanctx_mtx));
1405 "no channel context assigned to vif?, disconnecting\n");
1406 goto drop_connection;
1409 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1411 if (local->use_chanctx &&
1412 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1414 "driver doesn't support chan-switch with channel contexts\n");
1415 goto drop_connection;
1418 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1420 "preparing for channel switch failed, disconnecting\n");
1421 goto drop_connection;
1424 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1425 chanctx->mode, false);
1428 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1430 goto drop_connection;
1432 mutex_unlock(&local->chanctx_mtx);
1434 sdata->vif.csa_active = true;
1435 sdata->csa_chandef = csa_ie.chandef;
1436 sdata->csa_block_tx = csa_ie.mode;
1437 ifmgd->csa_ignored_same_chan = false;
1438 ifmgd->beacon_crc_valid = false;
1440 if (sdata->csa_block_tx)
1441 ieee80211_stop_vif_queues(local, sdata,
1442 IEEE80211_QUEUE_STOP_REASON_CSA);
1443 mutex_unlock(&local->mtx);
1445 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1446 csa_ie.count, csa_ie.mode);
1448 if (local->ops->channel_switch) {
1449 /* use driver's channel switch callback */
1450 drv_channel_switch(local, sdata, &ch_switch);
1454 /* channel switch handled in software */
1455 if (csa_ie.count <= 1)
1456 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1458 mod_timer(&ifmgd->chswitch_timer,
1459 TU_TO_EXP_TIME((csa_ie.count - 1) *
1460 cbss->beacon_interval));
1462 lock_and_drop_connection:
1463 mutex_lock(&local->mtx);
1464 mutex_lock(&local->chanctx_mtx);
1467 * This is just so that the disconnect flow will know that
1468 * we were trying to switch channel and failed. In case the
1469 * mode is 1 (we are not allowed to Tx), we will know not to
1470 * send a deauthentication frame. Those two fields will be
1471 * reset when the disconnection worker runs.
1473 sdata->vif.csa_active = true;
1474 sdata->csa_block_tx = csa_ie.mode;
1476 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1477 mutex_unlock(&local->chanctx_mtx);
1478 mutex_unlock(&local->mtx);
1482 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1483 struct ieee80211_channel *channel,
1484 const u8 *country_ie, u8 country_ie_len,
1485 const u8 *pwr_constr_elem,
1486 int *chan_pwr, int *pwr_reduction)
1488 struct ieee80211_country_ie_triplet *triplet;
1489 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1490 int i, chan_increment;
1491 bool have_chan_pwr = false;
1494 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1497 triplet = (void *)(country_ie + 3);
1498 country_ie_len -= 3;
1500 switch (channel->band) {
1504 case NL80211_BAND_2GHZ:
1505 case NL80211_BAND_60GHZ:
1506 case NL80211_BAND_LC:
1509 case NL80211_BAND_5GHZ:
1512 case NL80211_BAND_6GHZ:
1514 * In the 6 GHz band, the "maximum transmit power level"
1515 * field in the triplets is reserved, and thus will be
1516 * zero and we shouldn't use it to control TX power.
1517 * The actual TX power will be given in the transmit
1518 * power envelope element instead.
1524 while (country_ie_len >= 3) {
1525 u8 first_channel = triplet->chans.first_channel;
1527 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1530 for (i = 0; i < triplet->chans.num_channels; i++) {
1531 if (first_channel + i * chan_increment == chan) {
1532 have_chan_pwr = true;
1533 *chan_pwr = triplet->chans.max_power;
1542 country_ie_len -= 3;
1545 if (have_chan_pwr && pwr_constr_elem)
1546 *pwr_reduction = *pwr_constr_elem;
1550 return have_chan_pwr;
1553 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1554 struct ieee80211_channel *channel,
1555 const u8 *cisco_dtpc_ie,
1558 /* From practical testing, the first data byte of the DTPC element
1559 * seems to contain the requested dBm level, and the CLI on Cisco
1560 * APs clearly state the range is -127 to 127 dBm, which indicates
1561 * a signed byte, although it seemingly never actually goes negative.
1562 * The other byte seems to always be zero.
1564 *pwr_level = (__s8)cisco_dtpc_ie[4];
1567 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1568 struct ieee80211_channel *channel,
1569 struct ieee80211_mgmt *mgmt,
1570 const u8 *country_ie, u8 country_ie_len,
1571 const u8 *pwr_constr_ie,
1572 const u8 *cisco_dtpc_ie)
1574 bool has_80211h_pwr = false, has_cisco_pwr = false;
1575 int chan_pwr = 0, pwr_reduction_80211h = 0;
1576 int pwr_level_cisco, pwr_level_80211h;
1578 __le16 capab = mgmt->u.probe_resp.capab_info;
1580 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1581 return 0; /* TODO */
1584 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1585 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1586 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1587 sdata, channel, country_ie, country_ie_len,
1588 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1590 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1593 if (cisco_dtpc_ie) {
1594 ieee80211_find_cisco_dtpc(
1595 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1596 has_cisco_pwr = true;
1599 if (!has_80211h_pwr && !has_cisco_pwr)
1602 /* If we have both 802.11h and Cisco DTPC, apply both limits
1603 * by picking the smallest of the two power levels advertised.
1605 if (has_80211h_pwr &&
1606 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1607 new_ap_level = pwr_level_80211h;
1609 if (sdata->ap_power_level == new_ap_level)
1613 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1614 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1615 sdata->u.mgd.bssid);
1616 } else { /* has_cisco_pwr is always true here. */
1617 new_ap_level = pwr_level_cisco;
1619 if (sdata->ap_power_level == new_ap_level)
1623 "Limiting TX power to %d dBm as advertised by %pM\n",
1624 pwr_level_cisco, sdata->u.mgd.bssid);
1627 sdata->ap_power_level = new_ap_level;
1628 if (__ieee80211_recalc_txpower(sdata))
1629 return BSS_CHANGED_TXPOWER;
1634 static void ieee80211_enable_ps(struct ieee80211_local *local,
1635 struct ieee80211_sub_if_data *sdata)
1637 struct ieee80211_conf *conf = &local->hw.conf;
1640 * If we are scanning right now then the parameters will
1641 * take effect when scan finishes.
1643 if (local->scanning)
1646 if (conf->dynamic_ps_timeout > 0 &&
1647 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1648 mod_timer(&local->dynamic_ps_timer, jiffies +
1649 msecs_to_jiffies(conf->dynamic_ps_timeout));
1651 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1652 ieee80211_send_nullfunc(local, sdata, true);
1654 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1655 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1658 conf->flags |= IEEE80211_CONF_PS;
1659 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1663 static void ieee80211_change_ps(struct ieee80211_local *local)
1665 struct ieee80211_conf *conf = &local->hw.conf;
1667 if (local->ps_sdata) {
1668 ieee80211_enable_ps(local, local->ps_sdata);
1669 } else if (conf->flags & IEEE80211_CONF_PS) {
1670 conf->flags &= ~IEEE80211_CONF_PS;
1671 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1672 del_timer_sync(&local->dynamic_ps_timer);
1673 cancel_work_sync(&local->dynamic_ps_enable_work);
1677 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1679 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1680 struct sta_info *sta = NULL;
1681 bool authorized = false;
1683 if (!mgd->powersave)
1689 if (!mgd->associated)
1692 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1695 if (!mgd->have_beacon)
1699 sta = sta_info_get(sdata, mgd->bssid);
1701 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1707 /* need to hold RTNL or interface lock */
1708 void ieee80211_recalc_ps(struct ieee80211_local *local)
1710 struct ieee80211_sub_if_data *sdata, *found = NULL;
1714 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1715 local->ps_sdata = NULL;
1719 list_for_each_entry(sdata, &local->interfaces, list) {
1720 if (!ieee80211_sdata_running(sdata))
1722 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1723 /* If an AP vif is found, then disable PS
1724 * by setting the count to zero thereby setting
1730 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1736 if (count == 1 && ieee80211_powersave_allowed(found)) {
1737 u8 dtimper = found->u.mgd.dtim_period;
1739 timeout = local->dynamic_ps_forced_timeout;
1742 local->hw.conf.dynamic_ps_timeout = timeout;
1744 /* If the TIM IE is invalid, pretend the value is 1 */
1748 local->hw.conf.ps_dtim_period = dtimper;
1749 local->ps_sdata = found;
1751 local->ps_sdata = NULL;
1754 ieee80211_change_ps(local);
1757 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1759 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1761 if (sdata->vif.bss_conf.ps != ps_allowed) {
1762 sdata->vif.bss_conf.ps = ps_allowed;
1763 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1767 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1769 struct ieee80211_local *local =
1770 container_of(work, struct ieee80211_local,
1771 dynamic_ps_disable_work);
1773 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1774 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1775 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1778 ieee80211_wake_queues_by_reason(&local->hw,
1779 IEEE80211_MAX_QUEUE_MAP,
1780 IEEE80211_QUEUE_STOP_REASON_PS,
1784 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1786 struct ieee80211_local *local =
1787 container_of(work, struct ieee80211_local,
1788 dynamic_ps_enable_work);
1789 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1790 struct ieee80211_if_managed *ifmgd;
1791 unsigned long flags;
1794 /* can only happen when PS was just disabled anyway */
1798 ifmgd = &sdata->u.mgd;
1800 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1803 if (local->hw.conf.dynamic_ps_timeout > 0) {
1804 /* don't enter PS if TX frames are pending */
1805 if (drv_tx_frames_pending(local)) {
1806 mod_timer(&local->dynamic_ps_timer, jiffies +
1808 local->hw.conf.dynamic_ps_timeout));
1813 * transmission can be stopped by others which leads to
1814 * dynamic_ps_timer expiry. Postpone the ps timer if it
1815 * is not the actual idle state.
1817 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1818 for (q = 0; q < local->hw.queues; q++) {
1819 if (local->queue_stop_reasons[q]) {
1820 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1822 mod_timer(&local->dynamic_ps_timer, jiffies +
1824 local->hw.conf.dynamic_ps_timeout));
1828 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1831 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1832 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1833 if (drv_tx_frames_pending(local)) {
1834 mod_timer(&local->dynamic_ps_timer, jiffies +
1836 local->hw.conf.dynamic_ps_timeout));
1838 ieee80211_send_nullfunc(local, sdata, true);
1839 /* Flush to get the tx status of nullfunc frame */
1840 ieee80211_flush_queues(local, sdata, false);
1844 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1845 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1846 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1847 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1848 local->hw.conf.flags |= IEEE80211_CONF_PS;
1849 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1853 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1855 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1857 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1860 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1862 struct delayed_work *delayed_work = to_delayed_work(work);
1863 struct ieee80211_sub_if_data *sdata =
1864 container_of(delayed_work, struct ieee80211_sub_if_data,
1865 dfs_cac_timer_work);
1866 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1868 mutex_lock(&sdata->local->mtx);
1869 if (sdata->wdev.cac_started) {
1870 ieee80211_vif_release_channel(sdata);
1871 cfg80211_cac_event(sdata->dev, &chandef,
1872 NL80211_RADAR_CAC_FINISHED,
1875 mutex_unlock(&sdata->local->mtx);
1879 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1881 struct ieee80211_local *local = sdata->local;
1882 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1886 if (local->hw.queues < IEEE80211_NUM_ACS)
1889 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1890 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1892 unsigned long now = jiffies;
1894 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1895 tx_tspec->admitted_time &&
1896 time_after(now, tx_tspec->time_slice_start + HZ)) {
1897 tx_tspec->consumed_tx_time = 0;
1898 tx_tspec->time_slice_start = now;
1900 if (tx_tspec->downgraded)
1902 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1905 switch (tx_tspec->action) {
1906 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1907 /* take the original parameters */
1908 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1910 "failed to set TX queue parameters for queue %d\n",
1912 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1913 tx_tspec->downgraded = false;
1916 case TX_TSPEC_ACTION_DOWNGRADE:
1917 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1918 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1922 /* downgrade next lower non-ACM AC */
1923 for (non_acm_ac = ac + 1;
1924 non_acm_ac < IEEE80211_NUM_ACS;
1926 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
1928 /* Usually the loop will result in using BK even if it
1929 * requires admission control, but such a configuration
1930 * makes no sense and we have to transmit somehow - the
1931 * AC selection does the same thing.
1932 * If we started out trying to downgrade from BK, then
1933 * the extra condition here might be needed.
1935 if (non_acm_ac >= IEEE80211_NUM_ACS)
1936 non_acm_ac = IEEE80211_AC_BK;
1937 if (drv_conf_tx(local, sdata, ac,
1938 &sdata->tx_conf[non_acm_ac]))
1940 "failed to set TX queue parameters for queue %d\n",
1942 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1944 schedule_delayed_work(&ifmgd->tx_tspec_wk,
1945 tx_tspec->time_slice_start + HZ - now + 1);
1947 case TX_TSPEC_ACTION_NONE:
1956 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1958 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
1959 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1962 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
1964 struct ieee80211_sub_if_data *sdata;
1966 sdata = container_of(work, struct ieee80211_sub_if_data,
1967 u.mgd.tx_tspec_wk.work);
1968 ieee80211_sta_handle_tspec_ac_params(sdata);
1973 ieee80211_sta_wmm_params(struct ieee80211_local *local,
1974 struct ieee80211_sub_if_data *sdata,
1975 const u8 *wmm_param, size_t wmm_param_len,
1976 const struct ieee80211_mu_edca_param_set *mu_edca)
1978 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
1979 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1981 int count, mu_edca_count, ac;
1983 u8 uapsd_queues = 0;
1985 if (!local->ops->conf_tx)
1988 if (local->hw.queues < IEEE80211_NUM_ACS)
1994 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
1997 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
1998 uapsd_queues = ifmgd->uapsd_queues;
2000 count = wmm_param[6] & 0x0f;
2001 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2002 * if mu_edca was preset before and now it disappeared tell
2003 * the driver about it.
2005 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2006 if (count == ifmgd->wmm_last_param_set &&
2007 mu_edca_count == ifmgd->mu_edca_last_param_set)
2009 ifmgd->wmm_last_param_set = count;
2010 ifmgd->mu_edca_last_param_set = mu_edca_count;
2012 pos = wmm_param + 8;
2013 left = wmm_param_len - 8;
2015 memset(¶ms, 0, sizeof(params));
2018 for (; left >= 4; left -= 4, pos += 4) {
2019 int aci = (pos[0] >> 5) & 0x03;
2020 int acm = (pos[0] >> 4) & 0x01;
2025 ac = IEEE80211_AC_BK;
2027 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2028 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2030 params[ac].mu_edca = !!mu_edca;
2032 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2035 ac = IEEE80211_AC_VI;
2037 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2038 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2040 params[ac].mu_edca = !!mu_edca;
2042 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2045 ac = IEEE80211_AC_VO;
2047 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2048 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2050 params[ac].mu_edca = !!mu_edca;
2052 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2056 ac = IEEE80211_AC_BE;
2058 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2059 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2061 params[ac].mu_edca = !!mu_edca;
2063 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2067 params[ac].aifs = pos[0] & 0x0f;
2069 if (params[ac].aifs < 2) {
2071 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2072 params[ac].aifs, aci);
2073 params[ac].aifs = 2;
2075 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2076 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2077 params[ac].txop = get_unaligned_le16(pos + 2);
2078 params[ac].acm = acm;
2079 params[ac].uapsd = uapsd;
2081 if (params[ac].cw_min == 0 ||
2082 params[ac].cw_min > params[ac].cw_max) {
2084 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2085 params[ac].cw_min, params[ac].cw_max, aci);
2088 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2091 /* WMM specification requires all 4 ACIs. */
2092 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2093 if (params[ac].cw_min == 0) {
2095 "AP has invalid WMM params (missing AC %d), using defaults\n",
2101 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2103 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2105 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2106 params[ac].txop, params[ac].uapsd,
2107 ifmgd->tx_tspec[ac].downgraded);
2108 sdata->tx_conf[ac] = params[ac];
2109 if (!ifmgd->tx_tspec[ac].downgraded &&
2110 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2112 "failed to set TX queue parameters for AC %d\n",
2116 /* enable WMM or activate new settings */
2117 sdata->vif.bss_conf.qos = true;
2121 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2123 lockdep_assert_held(&sdata->local->mtx);
2125 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2126 ieee80211_run_deferred_scan(sdata->local);
2129 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2131 mutex_lock(&sdata->local->mtx);
2132 __ieee80211_stop_poll(sdata);
2133 mutex_unlock(&sdata->local->mtx);
2136 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2137 u16 capab, bool erp_valid, u8 erp)
2139 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2140 struct ieee80211_supported_band *sband;
2142 bool use_protection;
2143 bool use_short_preamble;
2144 bool use_short_slot;
2146 sband = ieee80211_get_sband(sdata);
2151 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2152 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2154 use_protection = false;
2155 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2158 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2159 if (sband->band == NL80211_BAND_5GHZ ||
2160 sband->band == NL80211_BAND_6GHZ)
2161 use_short_slot = true;
2163 if (use_protection != bss_conf->use_cts_prot) {
2164 bss_conf->use_cts_prot = use_protection;
2165 changed |= BSS_CHANGED_ERP_CTS_PROT;
2168 if (use_short_preamble != bss_conf->use_short_preamble) {
2169 bss_conf->use_short_preamble = use_short_preamble;
2170 changed |= BSS_CHANGED_ERP_PREAMBLE;
2173 if (use_short_slot != bss_conf->use_short_slot) {
2174 bss_conf->use_short_slot = use_short_slot;
2175 changed |= BSS_CHANGED_ERP_SLOT;
2181 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2182 struct cfg80211_bss *cbss,
2183 u32 bss_info_changed)
2185 struct ieee80211_bss *bss = (void *)cbss->priv;
2186 struct ieee80211_local *local = sdata->local;
2187 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2189 bss_info_changed |= BSS_CHANGED_ASSOC;
2190 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2191 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2193 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2194 beacon_loss_count * bss_conf->beacon_int));
2196 sdata->u.mgd.associated = cbss;
2197 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2199 ieee80211_check_rate_mask(sdata);
2201 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2203 if (sdata->vif.p2p ||
2204 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2205 const struct cfg80211_bss_ies *ies;
2208 ies = rcu_dereference(cbss->ies);
2212 ret = cfg80211_get_p2p_attr(
2213 ies->data, ies->len,
2214 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2215 (u8 *) &bss_conf->p2p_noa_attr,
2216 sizeof(bss_conf->p2p_noa_attr));
2218 sdata->u.mgd.p2p_noa_index =
2219 bss_conf->p2p_noa_attr.index;
2220 bss_info_changed |= BSS_CHANGED_P2P_PS;
2226 /* just to be sure */
2227 ieee80211_stop_poll(sdata);
2229 ieee80211_led_assoc(local, 1);
2231 if (sdata->u.mgd.have_beacon) {
2233 * If the AP is buggy we may get here with no DTIM period
2234 * known, so assume it's 1 which is the only safe assumption
2235 * in that case, although if the TIM IE is broken powersave
2236 * probably just won't work at all.
2238 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2239 bss_conf->beacon_rate = bss->beacon_rate;
2240 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2242 bss_conf->beacon_rate = NULL;
2243 bss_conf->dtim_period = 0;
2246 bss_conf->assoc = 1;
2248 /* Tell the driver to monitor connection quality (if supported) */
2249 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2250 bss_conf->cqm_rssi_thold)
2251 bss_info_changed |= BSS_CHANGED_CQM;
2253 /* Enable ARP filtering */
2254 if (bss_conf->arp_addr_cnt)
2255 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2257 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2259 mutex_lock(&local->iflist_mtx);
2260 ieee80211_recalc_ps(local);
2261 mutex_unlock(&local->iflist_mtx);
2263 ieee80211_recalc_smps(sdata);
2264 ieee80211_recalc_ps_vif(sdata);
2266 netif_carrier_on(sdata->dev);
2269 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2270 u16 stype, u16 reason, bool tx,
2273 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2274 struct ieee80211_local *local = sdata->local;
2275 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2277 struct ieee80211_prep_tx_info info = {
2281 sdata_assert_lock(sdata);
2283 if (WARN_ON_ONCE(tx && !frame_buf))
2286 if (WARN_ON(!ifmgd->associated))
2289 ieee80211_stop_poll(sdata);
2291 ifmgd->associated = NULL;
2292 netif_carrier_off(sdata->dev);
2295 * if we want to get out of ps before disassoc (why?) we have
2296 * to do it before sending disassoc, as otherwise the null-packet
2299 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2300 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2301 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2303 local->ps_sdata = NULL;
2305 /* disable per-vif ps */
2306 ieee80211_recalc_ps_vif(sdata);
2308 /* make sure ongoing transmission finishes */
2312 * drop any frame before deauth/disassoc, this can be data or
2313 * management frame. Since we are disconnecting, we should not
2314 * insist sending these frames which can take time and delay
2315 * the disconnection and possible the roaming.
2318 ieee80211_flush_queues(local, sdata, true);
2320 /* deauthenticate/disassociate now */
2321 if (tx || frame_buf) {
2323 * In multi channel scenarios guarantee that the virtual
2324 * interface is granted immediate airtime to transmit the
2325 * deauthentication frame by calling mgd_prepare_tx, if the
2326 * driver requested so.
2328 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2329 !ifmgd->have_beacon) {
2330 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2333 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2334 ifmgd->bssid, stype, reason,
2338 /* flush out frame - make sure the deauth was actually sent */
2340 ieee80211_flush_queues(local, sdata, false);
2342 drv_mgd_complete_tx(sdata->local, sdata, &info);
2344 /* clear bssid only after building the needed mgmt frames */
2345 eth_zero_addr(ifmgd->bssid);
2347 sdata->vif.bss_conf.ssid_len = 0;
2349 /* remove AP and TDLS peers */
2350 sta_info_flush(sdata);
2352 /* finally reset all BSS / config parameters */
2353 changed |= ieee80211_reset_erp_info(sdata);
2355 ieee80211_led_assoc(local, 0);
2356 changed |= BSS_CHANGED_ASSOC;
2357 sdata->vif.bss_conf.assoc = false;
2359 ifmgd->p2p_noa_index = -1;
2360 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2361 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2363 /* on the next assoc, re-program HT/VHT parameters */
2364 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2365 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2366 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2367 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2369 /* reset MU-MIMO ownership and group data */
2370 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2371 sizeof(sdata->vif.bss_conf.mu_group.membership));
2372 memset(sdata->vif.bss_conf.mu_group.position, 0,
2373 sizeof(sdata->vif.bss_conf.mu_group.position));
2374 changed |= BSS_CHANGED_MU_GROUPS;
2375 sdata->vif.mu_mimo_owner = false;
2377 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2379 del_timer_sync(&local->dynamic_ps_timer);
2380 cancel_work_sync(&local->dynamic_ps_enable_work);
2382 /* Disable ARP filtering */
2383 if (sdata->vif.bss_conf.arp_addr_cnt)
2384 changed |= BSS_CHANGED_ARP_FILTER;
2386 sdata->vif.bss_conf.qos = false;
2387 changed |= BSS_CHANGED_QOS;
2389 /* The BSSID (not really interesting) and HT changed */
2390 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2391 ieee80211_bss_info_change_notify(sdata, changed);
2393 /* disassociated - set to defaults now */
2394 ieee80211_set_wmm_default(sdata, false, false);
2396 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2397 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2398 del_timer_sync(&sdata->u.mgd.timer);
2399 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2401 sdata->vif.bss_conf.dtim_period = 0;
2402 sdata->vif.bss_conf.beacon_rate = NULL;
2404 ifmgd->have_beacon = false;
2407 mutex_lock(&local->mtx);
2408 ieee80211_vif_release_channel(sdata);
2410 sdata->vif.csa_active = false;
2411 ifmgd->csa_waiting_bcn = false;
2412 ifmgd->csa_ignored_same_chan = false;
2413 if (sdata->csa_block_tx) {
2414 ieee80211_wake_vif_queues(local, sdata,
2415 IEEE80211_QUEUE_STOP_REASON_CSA);
2416 sdata->csa_block_tx = false;
2418 mutex_unlock(&local->mtx);
2420 /* existing TX TSPEC sessions no longer exist */
2421 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2422 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2424 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2426 bss_conf->pwr_reduction = 0;
2427 bss_conf->tx_pwr_env_num = 0;
2428 memset(bss_conf->tx_pwr_env, 0, sizeof(bss_conf->tx_pwr_env));
2431 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2433 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2434 struct ieee80211_local *local = sdata->local;
2436 mutex_lock(&local->mtx);
2437 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2440 __ieee80211_stop_poll(sdata);
2442 mutex_lock(&local->iflist_mtx);
2443 ieee80211_recalc_ps(local);
2444 mutex_unlock(&local->iflist_mtx);
2446 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2450 * We've received a probe response, but are not sure whether
2451 * we have or will be receiving any beacons or data, so let's
2452 * schedule the timers again, just in case.
2454 ieee80211_sta_reset_beacon_monitor(sdata);
2456 mod_timer(&ifmgd->conn_mon_timer,
2457 round_jiffies_up(jiffies +
2458 IEEE80211_CONNECTION_IDLE_TIME));
2460 mutex_unlock(&local->mtx);
2463 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2464 struct ieee80211_hdr *hdr,
2467 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2470 struct ieee80211_sta_tx_tspec *tx_tspec;
2471 unsigned long now = jiffies;
2473 if (!ieee80211_is_data_qos(hdr->frame_control))
2476 tid = ieee80211_get_tid(hdr);
2477 ac = ieee80211_ac_from_tid(tid);
2478 tx_tspec = &ifmgd->tx_tspec[ac];
2480 if (likely(!tx_tspec->admitted_time))
2483 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2484 tx_tspec->consumed_tx_time = 0;
2485 tx_tspec->time_slice_start = now;
2487 if (tx_tspec->downgraded) {
2488 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2489 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2493 if (tx_tspec->downgraded)
2496 tx_tspec->consumed_tx_time += tx_time;
2498 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2499 tx_tspec->downgraded = true;
2500 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2501 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2505 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2506 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2508 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2510 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2511 !sdata->u.mgd.probe_send_count)
2515 sdata->u.mgd.probe_send_count = 0;
2517 sdata->u.mgd.nullfunc_failed = true;
2518 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2521 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2522 const u8 *src, const u8 *dst,
2523 const u8 *ssid, size_t ssid_len,
2524 struct ieee80211_channel *channel)
2526 struct sk_buff *skb;
2528 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2529 ssid, ssid_len, NULL, 0,
2530 IEEE80211_PROBE_FLAG_DIRECTED);
2532 ieee80211_tx_skb(sdata, skb);
2535 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2538 const struct element *ssid;
2539 u8 *dst = ifmgd->associated->bssid;
2540 u8 unicast_limit = max(1, max_probe_tries - 3);
2541 struct sta_info *sta;
2544 * Try sending broadcast probe requests for the last three
2545 * probe requests after the first ones failed since some
2546 * buggy APs only support broadcast probe requests.
2548 if (ifmgd->probe_send_count >= unicast_limit)
2552 * When the hardware reports an accurate Tx ACK status, it's
2553 * better to send a nullfunc frame instead of a probe request,
2554 * as it will kick us off the AP quickly if we aren't associated
2555 * anymore. The timeout will be reset if the frame is ACKed by
2558 ifmgd->probe_send_count++;
2561 mutex_lock(&sdata->local->sta_mtx);
2562 sta = sta_info_get(sdata, dst);
2564 ieee80211_check_fast_rx(sta);
2565 mutex_unlock(&sdata->local->sta_mtx);
2568 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2569 ifmgd->nullfunc_failed = false;
2570 ieee80211_send_nullfunc(sdata->local, sdata, false);
2575 ssid = ieee80211_bss_get_elem(ifmgd->associated, WLAN_EID_SSID);
2576 if (WARN_ON_ONCE(ssid == NULL))
2579 ssid_len = ssid->datalen;
2581 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2582 ssid->data, ssid_len,
2583 ifmgd->associated->channel);
2587 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2588 run_again(sdata, ifmgd->probe_timeout);
2591 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2594 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2595 bool already = false;
2597 if (!ieee80211_sdata_running(sdata))
2602 if (!ifmgd->associated)
2605 mutex_lock(&sdata->local->mtx);
2607 if (sdata->local->tmp_channel || sdata->local->scanning) {
2608 mutex_unlock(&sdata->local->mtx);
2612 if (sdata->local->suspending) {
2613 /* reschedule after resume */
2614 mutex_unlock(&sdata->local->mtx);
2615 ieee80211_reset_ap_probe(sdata);
2620 mlme_dbg_ratelimited(sdata,
2621 "detected beacon loss from AP (missed %d beacons) - probing\n",
2624 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2628 * The driver/our work has already reported this event or the
2629 * connection monitoring has kicked in and we have already sent
2630 * a probe request. Or maybe the AP died and the driver keeps
2631 * reporting until we disassociate...
2633 * In either case we have to ignore the current call to this
2634 * function (except for setting the correct probe reason bit)
2635 * because otherwise we would reset the timer every time and
2636 * never check whether we received a probe response!
2638 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2641 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2643 mutex_unlock(&sdata->local->mtx);
2648 mutex_lock(&sdata->local->iflist_mtx);
2649 ieee80211_recalc_ps(sdata->local);
2650 mutex_unlock(&sdata->local->iflist_mtx);
2652 ifmgd->probe_send_count = 0;
2653 ieee80211_mgd_probe_ap_send(sdata);
2655 sdata_unlock(sdata);
2658 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2659 struct ieee80211_vif *vif)
2661 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2662 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2663 struct cfg80211_bss *cbss;
2664 struct sk_buff *skb;
2665 const struct element *ssid;
2668 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2671 sdata_assert_lock(sdata);
2673 if (ifmgd->associated)
2674 cbss = ifmgd->associated;
2675 else if (ifmgd->auth_data)
2676 cbss = ifmgd->auth_data->bss;
2677 else if (ifmgd->assoc_data)
2678 cbss = ifmgd->assoc_data->bss;
2683 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
2684 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
2685 "invalid SSID element (len=%d)",
2686 ssid ? ssid->datalen : -1))
2689 ssid_len = ssid->datalen;
2691 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2692 (u32) -1, cbss->channel,
2693 ssid->data, ssid_len,
2694 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2699 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2701 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2702 const u8 *buf, size_t len, bool tx,
2703 u16 reason, bool reconnect)
2705 struct ieee80211_event event = {
2707 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2708 .u.mlme.reason = reason,
2712 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2714 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2716 drv_event_callback(sdata->local, sdata, &event);
2719 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2721 struct ieee80211_local *local = sdata->local;
2722 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2723 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2727 if (!ifmgd->associated) {
2728 sdata_unlock(sdata);
2732 tx = !sdata->csa_block_tx;
2734 if (!ifmgd->driver_disconnect) {
2736 * AP is probably out of range (or not reachable for another
2737 * reason) so remove the bss struct for that AP.
2739 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2742 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2743 ifmgd->driver_disconnect ?
2744 WLAN_REASON_DEAUTH_LEAVING :
2745 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2747 mutex_lock(&local->mtx);
2748 sdata->vif.csa_active = false;
2749 ifmgd->csa_waiting_bcn = false;
2750 if (sdata->csa_block_tx) {
2751 ieee80211_wake_vif_queues(local, sdata,
2752 IEEE80211_QUEUE_STOP_REASON_CSA);
2753 sdata->csa_block_tx = false;
2755 mutex_unlock(&local->mtx);
2757 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2758 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2760 ifmgd->reconnect = false;
2762 sdata_unlock(sdata);
2765 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2767 struct ieee80211_sub_if_data *sdata =
2768 container_of(work, struct ieee80211_sub_if_data,
2769 u.mgd.beacon_connection_loss_work);
2770 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2772 if (ifmgd->associated)
2773 ifmgd->beacon_loss_count++;
2775 if (ifmgd->connection_loss) {
2776 sdata_info(sdata, "Connection to AP %pM lost\n",
2778 __ieee80211_disconnect(sdata);
2779 ifmgd->connection_loss = false;
2780 } else if (ifmgd->driver_disconnect) {
2782 "Driver requested disconnection from AP %pM\n",
2784 __ieee80211_disconnect(sdata);
2785 ifmgd->driver_disconnect = false;
2787 ieee80211_mgd_probe_ap(sdata, true);
2791 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2793 struct ieee80211_sub_if_data *sdata =
2794 container_of(work, struct ieee80211_sub_if_data,
2795 u.mgd.csa_connection_drop_work);
2797 __ieee80211_disconnect(sdata);
2800 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2802 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2803 struct ieee80211_hw *hw = &sdata->local->hw;
2805 trace_api_beacon_loss(sdata);
2807 sdata->u.mgd.connection_loss = false;
2808 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2810 EXPORT_SYMBOL(ieee80211_beacon_loss);
2812 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2814 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2815 struct ieee80211_hw *hw = &sdata->local->hw;
2817 trace_api_connection_loss(sdata);
2819 sdata->u.mgd.connection_loss = true;
2820 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2822 EXPORT_SYMBOL(ieee80211_connection_loss);
2824 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2826 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2827 struct ieee80211_hw *hw = &sdata->local->hw;
2829 trace_api_disconnect(sdata, reconnect);
2831 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2834 sdata->u.mgd.driver_disconnect = true;
2835 sdata->u.mgd.reconnect = reconnect;
2836 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2838 EXPORT_SYMBOL(ieee80211_disconnect);
2840 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2843 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2845 sdata_assert_lock(sdata);
2849 * we are not authenticated yet, the only timer that could be
2850 * running is the timeout for the authentication response which
2851 * which is not relevant anymore.
2853 del_timer_sync(&sdata->u.mgd.timer);
2854 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2856 eth_zero_addr(sdata->u.mgd.bssid);
2857 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2858 sdata->u.mgd.flags = 0;
2859 mutex_lock(&sdata->local->mtx);
2860 ieee80211_vif_release_channel(sdata);
2861 mutex_unlock(&sdata->local->mtx);
2864 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2866 sdata->u.mgd.auth_data = NULL;
2869 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2870 bool assoc, bool abandon)
2872 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2874 sdata_assert_lock(sdata);
2878 * we are not associated yet, the only timer that could be
2879 * running is the timeout for the association response which
2880 * which is not relevant anymore.
2882 del_timer_sync(&sdata->u.mgd.timer);
2883 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2885 eth_zero_addr(sdata->u.mgd.bssid);
2886 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2887 sdata->u.mgd.flags = 0;
2888 sdata->vif.mu_mimo_owner = false;
2890 mutex_lock(&sdata->local->mtx);
2891 ieee80211_vif_release_channel(sdata);
2892 mutex_unlock(&sdata->local->mtx);
2895 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2899 sdata->u.mgd.assoc_data = NULL;
2902 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2903 struct ieee80211_mgmt *mgmt, size_t len)
2905 struct ieee80211_local *local = sdata->local;
2906 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2907 const struct element *challenge;
2910 struct ieee80211_prep_tx_info info = {
2911 .subtype = IEEE80211_STYPE_AUTH,
2914 pos = mgmt->u.auth.variable;
2915 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
2916 len - (pos - (u8 *)mgmt));
2919 auth_data->expected_transaction = 4;
2920 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2921 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2922 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2923 IEEE80211_TX_INTFL_MLME_CONN_TX;
2924 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2926 challenge->datalen + sizeof(*challenge),
2927 auth_data->bss->bssid, auth_data->bss->bssid,
2928 auth_data->key, auth_data->key_len,
2929 auth_data->key_idx, tx_flags);
2932 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
2935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2936 struct sta_info *sta;
2939 sdata_info(sdata, "authenticated\n");
2940 ifmgd->auth_data->done = true;
2941 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
2942 ifmgd->auth_data->timeout_started = true;
2943 run_again(sdata, ifmgd->auth_data->timeout);
2945 /* move station state to auth */
2946 mutex_lock(&sdata->local->sta_mtx);
2947 sta = sta_info_get(sdata, bssid);
2949 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
2953 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
2954 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
2960 mutex_unlock(&sdata->local->sta_mtx);
2964 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
2965 struct ieee80211_mgmt *mgmt, size_t len)
2967 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2969 u16 auth_alg, auth_transaction, status_code;
2970 struct ieee80211_event event = {
2972 .u.mlme.data = AUTH_EVENT,
2974 struct ieee80211_prep_tx_info info = {
2975 .subtype = IEEE80211_STYPE_AUTH,
2978 sdata_assert_lock(sdata);
2983 if (!ifmgd->auth_data || ifmgd->auth_data->done)
2986 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
2988 if (!ether_addr_equal(bssid, mgmt->bssid))
2991 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
2992 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
2993 status_code = le16_to_cpu(mgmt->u.auth.status_code);
2995 if (auth_alg != ifmgd->auth_data->algorithm ||
2996 (auth_alg != WLAN_AUTH_SAE &&
2997 auth_transaction != ifmgd->auth_data->expected_transaction) ||
2998 (auth_alg == WLAN_AUTH_SAE &&
2999 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3000 auth_transaction > 2))) {
3001 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3002 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3004 ifmgd->auth_data->expected_transaction);
3008 if (status_code != WLAN_STATUS_SUCCESS) {
3009 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3011 if (auth_alg == WLAN_AUTH_SAE &&
3012 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3013 (auth_transaction == 1 &&
3014 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3015 status_code == WLAN_STATUS_SAE_PK)))) {
3016 /* waiting for userspace now */
3017 ifmgd->auth_data->waiting = true;
3018 ifmgd->auth_data->timeout =
3019 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3020 ifmgd->auth_data->timeout_started = true;
3021 run_again(sdata, ifmgd->auth_data->timeout);
3025 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3026 mgmt->sa, status_code);
3027 ieee80211_destroy_auth_data(sdata, false);
3028 event.u.mlme.status = MLME_DENIED;
3029 event.u.mlme.reason = status_code;
3030 drv_event_callback(sdata->local, sdata, &event);
3034 switch (ifmgd->auth_data->algorithm) {
3035 case WLAN_AUTH_OPEN:
3036 case WLAN_AUTH_LEAP:
3039 case WLAN_AUTH_FILS_SK:
3040 case WLAN_AUTH_FILS_SK_PFS:
3041 case WLAN_AUTH_FILS_PK:
3043 case WLAN_AUTH_SHARED_KEY:
3044 if (ifmgd->auth_data->expected_transaction != 4) {
3045 ieee80211_auth_challenge(sdata, mgmt, len);
3046 /* need another frame */
3051 WARN_ONCE(1, "invalid auth alg %d",
3052 ifmgd->auth_data->algorithm);
3056 event.u.mlme.status = MLME_SUCCESS;
3058 drv_event_callback(sdata->local, sdata, &event);
3059 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3060 (auth_transaction == 2 &&
3061 ifmgd->auth_data->expected_transaction == 2)) {
3062 if (!ieee80211_mark_sta_auth(sdata, bssid))
3063 return; /* ignore frame -- wait for timeout */
3064 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3065 auth_transaction == 2) {
3066 sdata_info(sdata, "SAE peer confirmed\n");
3067 ifmgd->auth_data->peer_confirmed = true;
3070 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3072 drv_mgd_complete_tx(sdata->local, sdata, &info);
3075 #define case_WLAN(type) \
3076 case WLAN_REASON_##type: return #type
3078 const char *ieee80211_get_reason_code_string(u16 reason_code)
3080 switch (reason_code) {
3081 case_WLAN(UNSPECIFIED);
3082 case_WLAN(PREV_AUTH_NOT_VALID);
3083 case_WLAN(DEAUTH_LEAVING);
3084 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3085 case_WLAN(DISASSOC_AP_BUSY);
3086 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3087 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3088 case_WLAN(DISASSOC_STA_HAS_LEFT);
3089 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3090 case_WLAN(DISASSOC_BAD_POWER);
3091 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3092 case_WLAN(INVALID_IE);
3093 case_WLAN(MIC_FAILURE);
3094 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3095 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3096 case_WLAN(IE_DIFFERENT);
3097 case_WLAN(INVALID_GROUP_CIPHER);
3098 case_WLAN(INVALID_PAIRWISE_CIPHER);
3099 case_WLAN(INVALID_AKMP);
3100 case_WLAN(UNSUPP_RSN_VERSION);
3101 case_WLAN(INVALID_RSN_IE_CAP);
3102 case_WLAN(IEEE8021X_FAILED);
3103 case_WLAN(CIPHER_SUITE_REJECTED);
3104 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3105 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3106 case_WLAN(DISASSOC_LOW_ACK);
3107 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3108 case_WLAN(QSTA_LEAVE_QBSS);
3109 case_WLAN(QSTA_NOT_USE);
3110 case_WLAN(QSTA_REQUIRE_SETUP);
3111 case_WLAN(QSTA_TIMEOUT);
3112 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3113 case_WLAN(MESH_PEER_CANCELED);
3114 case_WLAN(MESH_MAX_PEERS);
3115 case_WLAN(MESH_CONFIG);
3116 case_WLAN(MESH_CLOSE);
3117 case_WLAN(MESH_MAX_RETRIES);
3118 case_WLAN(MESH_CONFIRM_TIMEOUT);
3119 case_WLAN(MESH_INVALID_GTK);
3120 case_WLAN(MESH_INCONSISTENT_PARAM);
3121 case_WLAN(MESH_INVALID_SECURITY);
3122 case_WLAN(MESH_PATH_ERROR);
3123 case_WLAN(MESH_PATH_NOFORWARD);
3124 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3125 case_WLAN(MAC_EXISTS_IN_MBSS);
3126 case_WLAN(MESH_CHAN_REGULATORY);
3127 case_WLAN(MESH_CHAN);
3128 default: return "<unknown>";
3132 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3133 struct ieee80211_mgmt *mgmt, size_t len)
3135 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3136 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3138 sdata_assert_lock(sdata);
3143 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3144 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3148 if (ifmgd->associated &&
3149 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3150 const u8 *bssid = ifmgd->associated->bssid;
3152 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3154 ieee80211_get_reason_code_string(reason_code));
3156 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3158 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3159 reason_code, false);
3163 if (ifmgd->assoc_data &&
3164 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3165 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3168 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3170 ieee80211_get_reason_code_string(reason_code));
3172 ieee80211_destroy_assoc_data(sdata, false, true);
3174 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3180 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3181 struct ieee80211_mgmt *mgmt, size_t len)
3183 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3186 sdata_assert_lock(sdata);
3191 if (!ifmgd->associated ||
3192 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3195 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3197 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3198 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3202 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3203 mgmt->sa, reason_code,
3204 ieee80211_get_reason_code_string(reason_code));
3206 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3208 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3212 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3213 u8 *supp_rates, unsigned int supp_rates_len,
3214 u32 *rates, u32 *basic_rates,
3215 bool *have_higher_than_11mbit,
3216 int *min_rate, int *min_rate_index,
3221 for (i = 0; i < supp_rates_len; i++) {
3222 int rate = supp_rates[i] & 0x7f;
3223 bool is_basic = !!(supp_rates[i] & 0x80);
3225 if ((rate * 5 * (1 << shift)) > 110)
3226 *have_higher_than_11mbit = true;
3229 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3230 * since they're not rates.
3232 * Note: Even though the membership selector and the basic
3233 * rate flag share the same bit, they are not exactly
3236 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3237 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3238 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3239 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3242 for (j = 0; j < sband->n_bitrates; j++) {
3243 struct ieee80211_rate *br;
3246 br = &sband->bitrates[j];
3248 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3249 if (brate == rate) {
3252 *basic_rates |= BIT(j);
3253 if ((rate * 5) < *min_rate) {
3254 *min_rate = rate * 5;
3255 *min_rate_index = j;
3263 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3264 const struct ieee802_11_elems *elems)
3266 if (elems->ext_capab_len < 10)
3269 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3272 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3273 IEEE80211_HE_MAC_CAP0_TWT_RES;
3276 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3277 struct sta_info *sta,
3278 struct ieee802_11_elems *elems)
3280 bool twt = ieee80211_twt_req_supported(sta, elems);
3282 if (sdata->vif.bss_conf.twt_requester != twt) {
3283 sdata->vif.bss_conf.twt_requester = twt;
3284 return BSS_CHANGED_TWT;
3289 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3290 struct ieee80211_bss_conf *bss_conf,
3291 struct ieee80211_supported_band *sband,
3292 struct sta_info *sta)
3294 const struct ieee80211_sta_he_cap *own_he_cap =
3295 ieee80211_get_he_iftype_cap(sband,
3296 ieee80211_vif_type_p2p(&sdata->vif));
3298 return bss_conf->he_support &&
3299 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3300 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3302 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3303 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3306 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3307 struct cfg80211_bss *cbss,
3308 struct ieee80211_mgmt *mgmt, size_t len,
3309 struct ieee802_11_elems *elems)
3311 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3312 struct ieee80211_local *local = sdata->local;
3313 struct ieee80211_supported_band *sband;
3314 struct sta_info *sta;
3315 u16 capab_info, aid;
3316 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3317 const struct cfg80211_bss_ies *bss_ies = NULL;
3318 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3319 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3320 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3326 /* AssocResp and ReassocResp have identical structure */
3328 pos = mgmt->u.assoc_resp.variable;
3329 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3331 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3334 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3335 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3336 mgmt->bssid, assoc_data->bss->bssid);
3341 if (elems->aid_resp)
3342 aid = le16_to_cpu(elems->aid_resp->aid);
3345 * The 5 MSB of the AID field are reserved
3346 * (802.11-2016 9.4.1.8 AID field)
3350 ifmgd->broken_ap = false;
3352 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3353 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3356 ifmgd->broken_ap = true;
3359 if (!is_s1g && !elems->supp_rates) {
3360 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3365 sdata->vif.bss_conf.aid = aid;
3366 ifmgd->tdls_chan_switch_prohibited =
3367 elems->ext_capab && elems->ext_capab_len >= 5 &&
3368 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3371 * Some APs are erroneously not including some information in their
3372 * (re)association response frames. Try to recover by using the data
3373 * from the beacon or probe response. This seems to afflict mobile
3374 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3375 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3378 ((assoc_data->wmm && !elems->wmm_param) ||
3379 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3380 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3381 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3382 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3383 const struct cfg80211_bss_ies *ies;
3384 struct ieee802_11_elems *bss_elems;
3387 ies = rcu_dereference(cbss->ies);
3389 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3397 bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3399 assoc_data->bss->bssid);
3405 if (assoc_data->wmm &&
3406 !elems->wmm_param && bss_elems->wmm_param) {
3407 elems->wmm_param = bss_elems->wmm_param;
3409 "AP bug: WMM param missing from AssocResp\n");
3413 * Also check if we requested HT/VHT, otherwise the AP doesn't
3414 * have to include the IEs in the (re)association response.
3416 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3417 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3418 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3420 "AP bug: HT capability missing from AssocResp\n");
3422 if (!elems->ht_operation && bss_elems->ht_operation &&
3423 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3424 elems->ht_operation = bss_elems->ht_operation;
3426 "AP bug: HT operation missing from AssocResp\n");
3428 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3429 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3430 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3432 "AP bug: VHT capa missing from AssocResp\n");
3434 if (!elems->vht_operation && bss_elems->vht_operation &&
3435 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3436 elems->vht_operation = bss_elems->vht_operation;
3438 "AP bug: VHT operation missing from AssocResp\n");
3445 * We previously checked these in the beacon/probe response, so
3446 * they should be present here. This is just a safety net.
3448 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3449 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3451 "HT AP is missing WMM params or HT capability/operation\n");
3456 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3457 (!elems->vht_cap_elem || !elems->vht_operation)) {
3459 "VHT AP is missing VHT capability/operation\n");
3464 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3465 !elems->he_6ghz_capa) {
3467 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3472 mutex_lock(&sdata->local->sta_mtx);
3474 * station info was already allocated and inserted before
3475 * the association and should be available to us
3477 sta = sta_info_get(sdata, cbss->bssid);
3478 if (WARN_ON(!sta)) {
3479 mutex_unlock(&sdata->local->sta_mtx);
3484 sband = ieee80211_get_sband(sdata);
3486 mutex_unlock(&sdata->local->sta_mtx);
3491 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3492 (!elems->he_cap || !elems->he_operation)) {
3493 mutex_unlock(&sdata->local->sta_mtx);
3495 "HE AP is missing HE capability/operation\n");
3500 /* Set up internal HT/VHT capabilities */
3501 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3502 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3503 elems->ht_cap_elem, sta);
3505 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3506 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3507 elems->vht_cap_elem, sta);
3509 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3511 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3514 elems->he_6ghz_capa,
3517 bss_conf->he_support = sta->sta.he_cap.has_he;
3518 if (elems->rsnx && elems->rsnx_len &&
3519 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3520 wiphy_ext_feature_isset(local->hw.wiphy,
3521 NL80211_EXT_FEATURE_PROTECTED_TWT))
3522 bss_conf->twt_protected = true;
3524 bss_conf->twt_protected = false;
3526 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3528 bss_conf->he_support = false;
3529 bss_conf->twt_requester = false;
3530 bss_conf->twt_protected = false;
3533 bss_conf->twt_broadcast =
3534 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3536 if (bss_conf->he_support) {
3537 bss_conf->he_bss_color.color =
3538 le32_get_bits(elems->he_operation->he_oper_params,
3539 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3540 bss_conf->he_bss_color.partial =
3541 le32_get_bits(elems->he_operation->he_oper_params,
3542 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3543 bss_conf->he_bss_color.enabled =
3544 !le32_get_bits(elems->he_operation->he_oper_params,
3545 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3547 if (bss_conf->he_bss_color.enabled)
3548 changed |= BSS_CHANGED_HE_BSS_COLOR;
3550 bss_conf->htc_trig_based_pkt_ext =
3551 le32_get_bits(elems->he_operation->he_oper_params,
3552 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3553 bss_conf->frame_time_rts_th =
3554 le32_get_bits(elems->he_operation->he_oper_params,
3555 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3557 bss_conf->uora_exists = !!elems->uora_element;
3558 if (elems->uora_element)
3559 bss_conf->uora_ocw_range = elems->uora_element[0];
3561 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3562 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3563 /* TODO: OPEN: what happens if BSS color disable is set? */
3566 if (cbss->transmitted_bss) {
3567 bss_conf->nontransmitted = true;
3568 ether_addr_copy(bss_conf->transmitter_bssid,
3569 cbss->transmitted_bss->bssid);
3570 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3571 bss_conf->bssid_index = cbss->bssid_index;
3575 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3576 * in their association response, so ignore that data for our own
3577 * configuration. If it changed since the last beacon, we'll get the
3578 * next beacon and update then.
3582 * If an operating mode notification IE is present, override the
3583 * NSS calculation (that would be done in rate_control_rate_init())
3584 * and use the # of streams from that element.
3586 if (elems->opmode_notif &&
3587 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3590 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3591 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3593 sta->sta.rx_nss = nss;
3596 rate_control_rate_init(sta);
3598 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3599 set_sta_flag(sta, WLAN_STA_MFP);
3600 sta->sta.mfp = true;
3602 sta->sta.mfp = false;
3605 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3606 local->hw.queues >= IEEE80211_NUM_ACS;
3608 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3609 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3610 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3613 "failed to move station %pM to desired state\n",
3615 WARN_ON(__sta_info_destroy(sta));
3616 mutex_unlock(&sdata->local->sta_mtx);
3621 if (sdata->wdev.use_4addr)
3622 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3624 mutex_unlock(&sdata->local->sta_mtx);
3627 * Always handle WMM once after association regardless
3628 * of the first value the AP uses. Setting -1 here has
3629 * that effect because the AP values is an unsigned
3632 ifmgd->wmm_last_param_set = -1;
3633 ifmgd->mu_edca_last_param_set = -1;
3635 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3636 ieee80211_set_wmm_default(sdata, false, false);
3637 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3638 elems->wmm_param_len,
3639 elems->mu_edca_param_set)) {
3640 /* still enable QoS since we might have HT/VHT */
3641 ieee80211_set_wmm_default(sdata, false, true);
3642 /* set the disable-WMM flag in this case to disable
3643 * tracking WMM parameter changes in the beacon if
3644 * the parameters weren't actually valid. Doing so
3645 * avoids changing parameters very strangely when
3646 * the AP is going back and forth between valid and
3647 * invalid parameters.
3649 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3651 changed |= BSS_CHANGED_QOS;
3653 if (elems->max_idle_period_ie) {
3654 bss_conf->max_idle_period =
3655 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3656 bss_conf->protected_keep_alive =
3657 !!(elems->max_idle_period_ie->idle_options &
3658 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3659 changed |= BSS_CHANGED_KEEP_ALIVE;
3661 bss_conf->max_idle_period = 0;
3662 bss_conf->protected_keep_alive = false;
3665 /* set assoc capability (AID was already set earlier),
3666 * ieee80211_set_associated() will tell the driver */
3667 bss_conf->assoc_capability = capab_info;
3668 ieee80211_set_associated(sdata, cbss, changed);
3671 * If we're using 4-addr mode, let the AP know that we're
3672 * doing so, so that it can create the STA VLAN on its side
3674 if (ifmgd->use_4addr)
3675 ieee80211_send_4addr_nullfunc(local, sdata);
3678 * Start timer to probe the connection to the AP now.
3679 * Also start the timer that will detect beacon loss.
3681 ieee80211_sta_reset_beacon_monitor(sdata);
3682 ieee80211_sta_reset_conn_monitor(sdata);
3691 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3692 struct ieee80211_mgmt *mgmt,
3695 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3696 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3697 u16 capab_info, status_code, aid;
3698 struct ieee802_11_elems *elems;
3699 int ac, uapsd_queues = -1;
3702 struct cfg80211_bss *cbss;
3703 struct ieee80211_event event = {
3705 .u.mlme.data = ASSOC_EVENT,
3707 struct ieee80211_prep_tx_info info = {};
3709 sdata_assert_lock(sdata);
3714 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3717 cbss = assoc_data->bss;
3720 * AssocResp and ReassocResp have identical structure, so process both
3721 * of them in this function.
3727 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3728 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3729 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3730 pos = mgmt->u.assoc_resp.variable;
3731 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3732 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3733 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3738 * Note: this may not be perfect, AP might misbehave - if
3739 * anyone needs to rely on perfect complete notification
3740 * with the exact right subtype, then we need to track what
3741 * we actually transmitted.
3743 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3744 IEEE80211_STYPE_ASSOC_REQ;
3747 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3748 reassoc ? "Rea" : "A", mgmt->sa,
3749 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3751 if (assoc_data->fils_kek_len &&
3752 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3755 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3756 mgmt->bssid, assoc_data->bss->bssid);
3760 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3761 elems->timeout_int &&
3762 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3765 cfg80211_assoc_comeback(sdata->dev, assoc_data->bss,
3766 le32_to_cpu(elems->timeout_int->value));
3768 tu = le32_to_cpu(elems->timeout_int->value);
3769 ms = tu * 1024 / 1000;
3771 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3773 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3774 assoc_data->timeout_started = true;
3775 if (ms > IEEE80211_ASSOC_TIMEOUT)
3776 run_again(sdata, assoc_data->timeout);
3780 if (status_code != WLAN_STATUS_SUCCESS) {
3781 sdata_info(sdata, "%pM denied association (code=%d)\n",
3782 mgmt->sa, status_code);
3783 ieee80211_destroy_assoc_data(sdata, false, false);
3784 event.u.mlme.status = MLME_DENIED;
3785 event.u.mlme.reason = status_code;
3786 drv_event_callback(sdata->local, sdata, &event);
3788 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) {
3789 /* oops -- internal error -- send timeout for now */
3790 ieee80211_destroy_assoc_data(sdata, false, false);
3791 cfg80211_assoc_timeout(sdata->dev, cbss);
3794 event.u.mlme.status = MLME_SUCCESS;
3795 drv_event_callback(sdata->local, sdata, &event);
3796 sdata_info(sdata, "associated\n");
3799 * destroy assoc_data afterwards, as otherwise an idle
3800 * recalc after assoc_data is NULL but before associated
3801 * is set can cause the interface to go idle
3803 ieee80211_destroy_assoc_data(sdata, true, false);
3805 /* get uapsd queues configuration */
3807 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3808 if (sdata->tx_conf[ac].uapsd)
3809 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3814 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3815 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3817 drv_mgd_complete_tx(sdata->local, sdata, &info);
3821 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3822 struct ieee80211_mgmt *mgmt, size_t len,
3823 struct ieee80211_rx_status *rx_status)
3825 struct ieee80211_local *local = sdata->local;
3826 struct ieee80211_bss *bss;
3827 struct ieee80211_channel *channel;
3829 sdata_assert_lock(sdata);
3831 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3832 ieee80211_rx_status_to_khz(rx_status));
3836 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3838 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3839 ieee80211_rx_bss_put(local, bss);
3844 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3845 struct sk_buff *skb)
3847 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3848 struct ieee80211_if_managed *ifmgd;
3849 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3850 struct ieee80211_channel *channel;
3851 size_t baselen, len = skb->len;
3853 ifmgd = &sdata->u.mgd;
3855 sdata_assert_lock(sdata);
3858 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3859 * "If a 6 GHz AP receives a Probe Request frame and responds with
3860 * a Probe Response frame [..], the Address 1 field of the Probe
3861 * Response frame shall be set to the broadcast address [..]"
3862 * So, on 6GHz band we should also accept broadcast responses.
3864 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3869 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3870 (channel->band != NL80211_BAND_6GHZ ||
3871 !is_broadcast_ether_addr(mgmt->da)))
3872 return; /* ignore ProbeResp to foreign address */
3874 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3878 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3880 if (ifmgd->associated &&
3881 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3882 ieee80211_reset_ap_probe(sdata);
3886 * This is the canonical list of information elements we care about,
3887 * the filter code also gives us all changes to the Microsoft OUI
3888 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3889 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3890 * changes to requested client power.
3892 * We implement beacon filtering in software since that means we can
3893 * avoid processing the frame here and in cfg80211, and userspace
3894 * will not be able to tell whether the hardware supports it or not.
3896 * XXX: This list needs to be dynamic -- userspace needs to be able to
3897 * add items it requires. It also needs to be able to tell us to
3898 * look out for other vendor IEs.
3900 static const u64 care_about_ies =
3901 (1ULL << WLAN_EID_COUNTRY) |
3902 (1ULL << WLAN_EID_ERP_INFO) |
3903 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3904 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3905 (1ULL << WLAN_EID_HT_CAPABILITY) |
3906 (1ULL << WLAN_EID_HT_OPERATION) |
3907 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3909 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3910 struct ieee80211_if_managed *ifmgd,
3911 struct ieee80211_bss_conf *bss_conf,
3912 struct ieee80211_local *local,
3913 struct ieee80211_rx_status *rx_status)
3915 /* Track average RSSI from the Beacon frames of the current AP */
3917 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
3918 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
3919 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
3920 ifmgd->last_cqm_event_signal = 0;
3921 ifmgd->count_beacon_signal = 1;
3922 ifmgd->last_ave_beacon_signal = 0;
3924 ifmgd->count_beacon_signal++;
3927 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
3929 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
3930 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3931 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3932 int last_sig = ifmgd->last_ave_beacon_signal;
3933 struct ieee80211_event event = {
3938 * if signal crosses either of the boundaries, invoke callback
3939 * with appropriate parameters
3941 if (sig > ifmgd->rssi_max_thold &&
3942 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
3943 ifmgd->last_ave_beacon_signal = sig;
3944 event.u.rssi.data = RSSI_EVENT_HIGH;
3945 drv_event_callback(local, sdata, &event);
3946 } else if (sig < ifmgd->rssi_min_thold &&
3947 (last_sig >= ifmgd->rssi_max_thold ||
3949 ifmgd->last_ave_beacon_signal = sig;
3950 event.u.rssi.data = RSSI_EVENT_LOW;
3951 drv_event_callback(local, sdata, &event);
3955 if (bss_conf->cqm_rssi_thold &&
3956 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
3957 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
3958 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3959 int last_event = ifmgd->last_cqm_event_signal;
3960 int thold = bss_conf->cqm_rssi_thold;
3961 int hyst = bss_conf->cqm_rssi_hyst;
3964 (last_event == 0 || sig < last_event - hyst)) {
3965 ifmgd->last_cqm_event_signal = sig;
3966 ieee80211_cqm_rssi_notify(
3968 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3970 } else if (sig > thold &&
3971 (last_event == 0 || sig > last_event + hyst)) {
3972 ifmgd->last_cqm_event_signal = sig;
3973 ieee80211_cqm_rssi_notify(
3975 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
3980 if (bss_conf->cqm_rssi_low &&
3981 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
3982 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
3983 int last_event = ifmgd->last_cqm_event_signal;
3984 int low = bss_conf->cqm_rssi_low;
3985 int high = bss_conf->cqm_rssi_high;
3988 (last_event == 0 || last_event >= low)) {
3989 ifmgd->last_cqm_event_signal = sig;
3990 ieee80211_cqm_rssi_notify(
3992 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
3994 } else if (sig > high &&
3995 (last_event == 0 || last_event <= high)) {
3996 ifmgd->last_cqm_event_signal = sig;
3997 ieee80211_cqm_rssi_notify(
3999 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
4005 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
4006 struct cfg80211_bss *bss)
4008 if (ether_addr_equal(tx_bssid, bss->bssid))
4010 if (!bss->transmitted_bss)
4012 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
4015 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
4016 struct ieee80211_hdr *hdr, size_t len,
4017 struct ieee80211_rx_status *rx_status)
4019 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4020 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
4021 struct ieee80211_mgmt *mgmt = (void *) hdr;
4023 struct ieee802_11_elems *elems;
4024 struct ieee80211_local *local = sdata->local;
4025 struct ieee80211_chanctx_conf *chanctx_conf;
4026 struct ieee80211_channel *chan;
4027 struct sta_info *sta;
4032 u8 *bssid, *variable = mgmt->u.beacon.variable;
4033 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4035 sdata_assert_lock(sdata);
4037 /* Process beacon from the current BSS */
4038 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4039 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4040 struct ieee80211_ext *ext = (void *) mgmt;
4042 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4043 variable = ext->u.s1g_short_beacon.variable;
4045 variable = ext->u.s1g_beacon.variable;
4048 baselen = (u8 *) variable - (u8 *) mgmt;
4053 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4054 if (!chanctx_conf) {
4059 if (ieee80211_rx_status_to_khz(rx_status) !=
4060 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4064 chan = chanctx_conf->def.chan;
4067 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4068 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4069 elems = ieee802_11_parse_elems(variable, len - baselen, false,
4071 ifmgd->assoc_data->bss->bssid);
4075 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4077 if (elems->dtim_period)
4078 ifmgd->dtim_period = elems->dtim_period;
4079 ifmgd->have_beacon = true;
4080 ifmgd->assoc_data->need_beacon = false;
4081 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4082 sdata->vif.bss_conf.sync_tsf =
4083 le64_to_cpu(mgmt->u.beacon.timestamp);
4084 sdata->vif.bss_conf.sync_device_ts =
4085 rx_status->device_timestamp;
4086 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4089 if (elems->mbssid_config_ie)
4090 bss_conf->profile_periodicity =
4091 elems->mbssid_config_ie->profile_periodicity;
4093 bss_conf->profile_periodicity = 0;
4095 if (elems->ext_capab_len >= 11 &&
4096 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4097 bss_conf->ema_ap = true;
4099 bss_conf->ema_ap = false;
4101 /* continue assoc process */
4102 ifmgd->assoc_data->timeout = jiffies;
4103 ifmgd->assoc_data->timeout_started = true;
4104 run_again(sdata, ifmgd->assoc_data->timeout);
4109 if (!ifmgd->associated ||
4110 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4112 bssid = ifmgd->associated->bssid;
4114 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4115 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4118 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4119 mlme_dbg_ratelimited(sdata,
4120 "cancelling AP probe due to a received beacon\n");
4121 ieee80211_reset_ap_probe(sdata);
4125 * Push the beacon loss detection into the future since
4126 * we are processing a beacon from the AP just now.
4128 ieee80211_sta_reset_beacon_monitor(sdata);
4130 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4131 * element (which carries the beacon interval). Don't forget to add a
4132 * bit to care_about_ies[] above if mac80211 is interested in a
4133 * changing S1G element.
4135 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4136 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4137 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
4138 false, care_about_ies, ncrc,
4139 mgmt->bssid, bssid);
4144 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4145 ieee80211_check_tim(elems->tim, elems->tim_len, bss_conf->aid)) {
4146 if (local->hw.conf.dynamic_ps_timeout > 0) {
4147 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4148 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4149 ieee80211_hw_config(local,
4150 IEEE80211_CONF_CHANGE_PS);
4152 ieee80211_send_nullfunc(local, sdata, false);
4153 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4154 local->pspolling = true;
4157 * Here is assumed that the driver will be
4158 * able to send ps-poll frame and receive a
4159 * response even though power save mode is
4160 * enabled, but some drivers might require
4161 * to disable power save here. This needs
4162 * to be investigated.
4164 ieee80211_send_pspoll(local, sdata);
4168 if (sdata->vif.p2p ||
4169 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4170 struct ieee80211_p2p_noa_attr noa = {};
4173 ret = cfg80211_get_p2p_attr(variable,
4175 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4176 (u8 *) &noa, sizeof(noa));
4178 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4179 /* valid noa_attr and index changed */
4180 sdata->u.mgd.p2p_noa_index = noa.index;
4181 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4182 changed |= BSS_CHANGED_P2P_PS;
4184 * make sure we update all information, the CRC
4185 * mechanism doesn't look at P2P attributes.
4187 ifmgd->beacon_crc_valid = false;
4189 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4190 /* noa_attr not found and we had valid noa_attr before */
4191 sdata->u.mgd.p2p_noa_index = -1;
4192 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4193 changed |= BSS_CHANGED_P2P_PS;
4194 ifmgd->beacon_crc_valid = false;
4198 if (ifmgd->csa_waiting_bcn)
4199 ieee80211_chswitch_post_beacon(sdata);
4202 * Update beacon timing and dtim count on every beacon appearance. This
4203 * will allow the driver to use the most updated values. Do it before
4204 * comparing this one with last received beacon.
4205 * IMPORTANT: These parameters would possibly be out of sync by the time
4206 * the driver will use them. The synchronized view is currently
4207 * guaranteed only in certain callbacks.
4209 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4210 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4211 sdata->vif.bss_conf.sync_tsf =
4212 le64_to_cpu(mgmt->u.beacon.timestamp);
4213 sdata->vif.bss_conf.sync_device_ts =
4214 rx_status->device_timestamp;
4215 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4218 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4219 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4221 ifmgd->beacon_crc = ncrc;
4222 ifmgd->beacon_crc_valid = true;
4224 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4226 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4227 rx_status->device_timestamp,
4230 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4231 ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
4232 elems->wmm_param_len,
4233 elems->mu_edca_param_set))
4234 changed |= BSS_CHANGED_QOS;
4237 * If we haven't had a beacon before, tell the driver about the
4238 * DTIM period (and beacon timing if desired) now.
4240 if (!ifmgd->have_beacon) {
4241 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4242 bss_conf->dtim_period = elems->dtim_period ?: 1;
4244 changed |= BSS_CHANGED_BEACON_INFO;
4245 ifmgd->have_beacon = true;
4247 mutex_lock(&local->iflist_mtx);
4248 ieee80211_recalc_ps(local);
4249 mutex_unlock(&local->iflist_mtx);
4251 ieee80211_recalc_ps_vif(sdata);
4254 if (elems->erp_info) {
4256 erp_value = elems->erp_info[0];
4261 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4262 changed |= ieee80211_handle_bss_capability(sdata,
4263 le16_to_cpu(mgmt->u.beacon.capab_info),
4264 erp_valid, erp_value);
4266 mutex_lock(&local->sta_mtx);
4267 sta = sta_info_get(sdata, bssid);
4269 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
4271 if (ieee80211_config_bw(sdata, sta, elems->ht_cap_elem,
4272 elems->vht_cap_elem, elems->ht_operation,
4273 elems->vht_operation, elems->he_operation,
4274 elems->s1g_oper, bssid, &changed)) {
4275 mutex_unlock(&local->sta_mtx);
4277 "failed to follow AP %pM bandwidth change, disconnect\n",
4279 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4280 WLAN_REASON_DEAUTH_LEAVING,
4282 ieee80211_report_disconnect(sdata, deauth_buf,
4283 sizeof(deauth_buf), true,
4284 WLAN_REASON_DEAUTH_LEAVING,
4289 if (sta && elems->opmode_notif)
4290 ieee80211_vht_handle_opmode(sdata, sta, *elems->opmode_notif,
4292 mutex_unlock(&local->sta_mtx);
4294 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4295 elems->country_elem,
4296 elems->country_elem_len,
4297 elems->pwr_constr_elem,
4298 elems->cisco_dtpc_elem);
4300 ieee80211_bss_info_change_notify(sdata, changed);
4305 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4306 struct sk_buff *skb)
4308 struct ieee80211_rx_status *rx_status;
4309 struct ieee80211_hdr *hdr;
4312 rx_status = (struct ieee80211_rx_status *) skb->cb;
4313 hdr = (struct ieee80211_hdr *) skb->data;
4314 fc = le16_to_cpu(hdr->frame_control);
4317 switch (fc & IEEE80211_FCTL_STYPE) {
4318 case IEEE80211_STYPE_S1G_BEACON:
4319 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4322 sdata_unlock(sdata);
4325 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4326 struct sk_buff *skb)
4328 struct ieee80211_rx_status *rx_status;
4329 struct ieee80211_mgmt *mgmt;
4333 rx_status = (struct ieee80211_rx_status *) skb->cb;
4334 mgmt = (struct ieee80211_mgmt *) skb->data;
4335 fc = le16_to_cpu(mgmt->frame_control);
4339 switch (fc & IEEE80211_FCTL_STYPE) {
4340 case IEEE80211_STYPE_BEACON:
4341 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4342 skb->len, rx_status);
4344 case IEEE80211_STYPE_PROBE_RESP:
4345 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4347 case IEEE80211_STYPE_AUTH:
4348 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4350 case IEEE80211_STYPE_DEAUTH:
4351 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4353 case IEEE80211_STYPE_DISASSOC:
4354 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4356 case IEEE80211_STYPE_ASSOC_RESP:
4357 case IEEE80211_STYPE_REASSOC_RESP:
4358 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4360 case IEEE80211_STYPE_ACTION:
4361 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4362 struct ieee802_11_elems *elems;
4364 ies_len = skb->len -
4365 offsetof(struct ieee80211_mgmt,
4366 u.action.u.chan_switch.variable);
4371 /* CSA IE cannot be overridden, no need for BSSID */
4372 elems = ieee802_11_parse_elems(
4373 mgmt->u.action.u.chan_switch.variable,
4374 ies_len, true, mgmt->bssid, NULL);
4376 if (elems && !elems->parse_error)
4377 ieee80211_sta_process_chanswitch(sdata,
4379 rx_status->device_timestamp,
4382 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4383 struct ieee802_11_elems *elems;
4385 ies_len = skb->len -
4386 offsetof(struct ieee80211_mgmt,
4387 u.action.u.ext_chan_switch.variable);
4393 * extended CSA IE can't be overridden, no need for
4396 elems = ieee802_11_parse_elems(
4397 mgmt->u.action.u.ext_chan_switch.variable,
4398 ies_len, true, mgmt->bssid, NULL);
4400 if (elems && !elems->parse_error) {
4401 /* for the handling code pretend it was an IE */
4402 elems->ext_chansw_ie =
4403 &mgmt->u.action.u.ext_chan_switch.data;
4405 ieee80211_sta_process_chanswitch(sdata,
4407 rx_status->device_timestamp,
4415 sdata_unlock(sdata);
4418 static void ieee80211_sta_timer(struct timer_list *t)
4420 struct ieee80211_sub_if_data *sdata =
4421 from_timer(sdata, t, u.mgd.timer);
4423 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4426 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4427 u8 *bssid, u8 reason, bool tx)
4429 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4431 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4434 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4438 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4440 struct ieee80211_local *local = sdata->local;
4441 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4442 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4446 struct ieee80211_prep_tx_info info = {
4447 .subtype = IEEE80211_STYPE_AUTH,
4450 sdata_assert_lock(sdata);
4452 if (WARN_ON_ONCE(!auth_data))
4457 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4458 sdata_info(sdata, "authentication with %pM timed out\n",
4459 auth_data->bss->bssid);
4462 * Most likely AP is not in the range so remove the
4463 * bss struct for that AP.
4465 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4470 if (auth_data->algorithm == WLAN_AUTH_SAE)
4471 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4473 drv_mgd_prepare_tx(local, sdata, &info);
4475 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4476 auth_data->bss->bssid, auth_data->tries,
4477 IEEE80211_AUTH_MAX_TRIES);
4479 auth_data->expected_transaction = 2;
4481 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4482 trans = auth_data->sae_trans;
4483 status = auth_data->sae_status;
4484 auth_data->expected_transaction = trans;
4487 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4488 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4489 IEEE80211_TX_INTFL_MLME_CONN_TX;
4491 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4492 auth_data->data, auth_data->data_len,
4493 auth_data->bss->bssid,
4494 auth_data->bss->bssid, NULL, 0, 0,
4497 if (tx_flags == 0) {
4498 if (auth_data->algorithm == WLAN_AUTH_SAE)
4499 auth_data->timeout = jiffies +
4500 IEEE80211_AUTH_TIMEOUT_SAE;
4502 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4504 auth_data->timeout =
4505 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4508 auth_data->timeout_started = true;
4509 run_again(sdata, auth_data->timeout);
4514 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4516 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4517 struct ieee80211_local *local = sdata->local;
4520 sdata_assert_lock(sdata);
4522 assoc_data->tries++;
4523 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4524 sdata_info(sdata, "association with %pM timed out\n",
4525 assoc_data->bss->bssid);
4528 * Most likely AP is not in the range so remove the
4529 * bss struct for that AP.
4531 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4536 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4537 assoc_data->bss->bssid, assoc_data->tries,
4538 IEEE80211_ASSOC_MAX_TRIES);
4539 ret = ieee80211_send_assoc(sdata);
4543 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4544 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4545 assoc_data->timeout_started = true;
4546 run_again(sdata, assoc_data->timeout);
4548 assoc_data->timeout =
4549 round_jiffies_up(jiffies +
4550 IEEE80211_ASSOC_TIMEOUT_LONG);
4551 assoc_data->timeout_started = true;
4552 run_again(sdata, assoc_data->timeout);
4558 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4559 __le16 fc, bool acked)
4561 struct ieee80211_local *local = sdata->local;
4563 sdata->u.mgd.status_fc = fc;
4564 sdata->u.mgd.status_acked = acked;
4565 sdata->u.mgd.status_received = true;
4567 ieee80211_queue_work(&local->hw, &sdata->work);
4570 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4572 struct ieee80211_local *local = sdata->local;
4573 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4577 if (ifmgd->status_received) {
4578 __le16 fc = ifmgd->status_fc;
4579 bool status_acked = ifmgd->status_acked;
4581 ifmgd->status_received = false;
4582 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4584 if (ifmgd->auth_data->algorithm ==
4586 ifmgd->auth_data->timeout =
4588 IEEE80211_AUTH_TIMEOUT_SAE;
4590 ifmgd->auth_data->timeout =
4592 IEEE80211_AUTH_TIMEOUT_SHORT;
4593 run_again(sdata, ifmgd->auth_data->timeout);
4595 ifmgd->auth_data->timeout = jiffies - 1;
4597 ifmgd->auth_data->timeout_started = true;
4598 } else if (ifmgd->assoc_data &&
4599 (ieee80211_is_assoc_req(fc) ||
4600 ieee80211_is_reassoc_req(fc))) {
4602 ifmgd->assoc_data->timeout =
4603 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4604 run_again(sdata, ifmgd->assoc_data->timeout);
4606 ifmgd->assoc_data->timeout = jiffies - 1;
4608 ifmgd->assoc_data->timeout_started = true;
4612 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4613 time_after(jiffies, ifmgd->auth_data->timeout)) {
4614 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
4616 * ok ... we waited for assoc or continuation but
4617 * userspace didn't do it, so kill the auth data
4619 ieee80211_destroy_auth_data(sdata, false);
4620 } else if (ieee80211_auth(sdata)) {
4622 struct ieee80211_event event = {
4624 .u.mlme.data = AUTH_EVENT,
4625 .u.mlme.status = MLME_TIMEOUT,
4628 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4630 ieee80211_destroy_auth_data(sdata, false);
4632 cfg80211_auth_timeout(sdata->dev, bssid);
4633 drv_event_callback(sdata->local, sdata, &event);
4635 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4636 run_again(sdata, ifmgd->auth_data->timeout);
4638 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4639 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4640 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4641 ieee80211_do_assoc(sdata)) {
4642 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4643 struct ieee80211_event event = {
4645 .u.mlme.data = ASSOC_EVENT,
4646 .u.mlme.status = MLME_TIMEOUT,
4649 ieee80211_destroy_assoc_data(sdata, false, false);
4650 cfg80211_assoc_timeout(sdata->dev, bss);
4651 drv_event_callback(sdata->local, sdata, &event);
4653 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4654 run_again(sdata, ifmgd->assoc_data->timeout);
4656 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4657 ifmgd->associated) {
4661 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4663 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4664 max_tries = max_nullfunc_tries;
4666 max_tries = max_probe_tries;
4668 /* ACK received for nullfunc probing frame */
4669 if (!ifmgd->probe_send_count)
4670 ieee80211_reset_ap_probe(sdata);
4671 else if (ifmgd->nullfunc_failed) {
4672 if (ifmgd->probe_send_count < max_tries) {
4674 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4675 bssid, ifmgd->probe_send_count,
4677 ieee80211_mgd_probe_ap_send(sdata);
4680 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4682 ieee80211_sta_connection_lost(sdata, bssid,
4683 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4686 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4687 run_again(sdata, ifmgd->probe_timeout);
4688 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4690 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4691 bssid, probe_wait_ms);
4692 ieee80211_sta_connection_lost(sdata, bssid,
4693 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4694 } else if (ifmgd->probe_send_count < max_tries) {
4696 "No probe response from AP %pM after %dms, try %d/%i\n",
4697 bssid, probe_wait_ms,
4698 ifmgd->probe_send_count, max_tries);
4699 ieee80211_mgd_probe_ap_send(sdata);
4702 * We actually lost the connection ... or did we?
4706 "No probe response from AP %pM after %dms, disconnecting.\n",
4707 bssid, probe_wait_ms);
4709 ieee80211_sta_connection_lost(sdata, bssid,
4710 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4714 sdata_unlock(sdata);
4717 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4719 struct ieee80211_sub_if_data *sdata =
4720 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4721 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4723 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4726 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4729 sdata->u.mgd.connection_loss = false;
4730 ieee80211_queue_work(&sdata->local->hw,
4731 &sdata->u.mgd.beacon_connection_loss_work);
4734 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4736 struct ieee80211_sub_if_data *sdata =
4737 from_timer(sdata, t, u.mgd.conn_mon_timer);
4738 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4739 struct ieee80211_local *local = sdata->local;
4740 struct sta_info *sta;
4741 unsigned long timeout;
4743 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4746 sta = sta_info_get(sdata, ifmgd->bssid);
4750 timeout = sta->status_stats.last_ack;
4751 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4752 timeout = sta->rx_stats.last_rx;
4753 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4755 /* If timeout is after now, then update timer to fire at
4756 * the later date, but do not actually probe at this time.
4758 if (time_is_after_jiffies(timeout)) {
4759 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4763 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4766 static void ieee80211_sta_monitor_work(struct work_struct *work)
4768 struct ieee80211_sub_if_data *sdata =
4769 container_of(work, struct ieee80211_sub_if_data,
4770 u.mgd.monitor_work);
4772 ieee80211_mgd_probe_ap(sdata, false);
4775 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4777 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4778 __ieee80211_stop_poll(sdata);
4780 /* let's probe the connection once */
4781 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4782 ieee80211_queue_work(&sdata->local->hw,
4783 &sdata->u.mgd.monitor_work);
4788 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4790 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4791 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4795 if (ifmgd->auth_data || ifmgd->assoc_data) {
4796 const u8 *bssid = ifmgd->auth_data ?
4797 ifmgd->auth_data->bss->bssid :
4798 ifmgd->assoc_data->bss->bssid;
4801 * If we are trying to authenticate / associate while suspending,
4802 * cfg80211 won't know and won't actually abort those attempts,
4803 * thus we need to do that ourselves.
4805 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4806 IEEE80211_STYPE_DEAUTH,
4807 WLAN_REASON_DEAUTH_LEAVING,
4809 if (ifmgd->assoc_data)
4810 ieee80211_destroy_assoc_data(sdata, false, true);
4811 if (ifmgd->auth_data)
4812 ieee80211_destroy_auth_data(sdata, false);
4813 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4814 IEEE80211_DEAUTH_FRAME_LEN,
4818 /* This is a bit of a hack - we should find a better and more generic
4819 * solution to this. Normally when suspending, cfg80211 will in fact
4820 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4821 * auth (not so important) or assoc (this is the problem) process.
4823 * As a consequence, it can happen that we are in the process of both
4824 * associating and suspending, and receive an association response
4825 * after cfg80211 has checked if it needs to disconnect, but before
4826 * we actually set the flag to drop incoming frames. This will then
4827 * cause the workqueue flush to process the association response in
4828 * the suspend, resulting in a successful association just before it
4829 * tries to remove the interface from the driver, which now though
4830 * has a channel context assigned ... this results in issues.
4832 * To work around this (for now) simply deauth here again if we're
4835 if (ifmgd->associated && !sdata->local->wowlan) {
4837 struct cfg80211_deauth_request req = {
4838 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4842 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4843 ieee80211_mgd_deauth(sdata, &req);
4846 sdata_unlock(sdata);
4849 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4851 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4854 if (!ifmgd->associated) {
4855 sdata_unlock(sdata);
4859 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4860 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4861 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4862 ieee80211_sta_connection_lost(sdata,
4863 ifmgd->associated->bssid,
4864 WLAN_REASON_UNSPECIFIED,
4866 sdata_unlock(sdata);
4869 sdata_unlock(sdata);
4873 /* interface setup */
4874 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4876 struct ieee80211_if_managed *ifmgd;
4878 ifmgd = &sdata->u.mgd;
4879 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4880 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4881 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4882 ieee80211_beacon_connection_loss_work);
4883 INIT_WORK(&ifmgd->csa_connection_drop_work,
4884 ieee80211_csa_connection_drop_work);
4885 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4886 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4887 ieee80211_tdls_peer_del_work);
4888 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4889 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4890 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4891 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4892 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4893 ieee80211_sta_handle_tspec_ac_params_wk);
4896 ifmgd->powersave = sdata->wdev.ps;
4897 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4898 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
4899 ifmgd->p2p_noa_index = -1;
4901 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
4902 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
4904 ifmgd->req_smps = IEEE80211_SMPS_OFF;
4906 /* Setup TDLS data */
4907 spin_lock_init(&ifmgd->teardown_lock);
4908 ifmgd->teardown_skb = NULL;
4909 ifmgd->orig_teardown_skb = NULL;
4912 /* scan finished notification */
4913 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
4915 struct ieee80211_sub_if_data *sdata;
4917 /* Restart STA timers */
4919 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
4920 if (ieee80211_sdata_running(sdata))
4921 ieee80211_restart_sta_timer(sdata);
4926 static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
4927 struct cfg80211_bss *cbss)
4929 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4930 const struct element *ht_cap_elem, *vht_cap_elem;
4931 const struct ieee80211_ht_cap *ht_cap;
4932 const struct ieee80211_vht_cap *vht_cap;
4935 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
4938 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4939 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4940 ht_cap = (void *)ht_cap_elem->data;
4941 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4943 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4944 * "Tx Unequal Modulation Supported" fields.
4948 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
4951 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4952 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4956 vht_cap = (void *)vht_cap_elem->data;
4957 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4958 for (nss = 8; nss > 0; nss--) {
4959 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4960 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4963 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4964 chains = max(chains, nss);
4971 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4972 struct ieee80211_supported_band *sband,
4973 const struct ieee80211_he_operation *he_op)
4975 const struct ieee80211_sta_he_cap *sta_he_cap =
4976 ieee80211_get_he_iftype_cap(sband,
4977 ieee80211_vif_type_p2p(&sdata->vif));
4981 if (!sta_he_cap || !he_op)
4984 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4986 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4987 for (i = 0; i < 3; i++) {
4988 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4989 &sta_he_cap->he_mcs_nss_supp;
4990 u16 sta_mcs_map_rx =
4991 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4992 u16 sta_mcs_map_tx =
4993 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4995 bool verified = true;
4998 * For each band there is a maximum of 8 spatial streams
4999 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
5000 * of 2 bits per NSS (1-8), with the values defined in enum
5001 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
5002 * capabilities aren't less than the AP's minimum requirements
5003 * for this HE BSS per SS.
5004 * It is enough to find one such band that meets the reqs.
5006 for (nss = 8; nss > 0; nss--) {
5007 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
5008 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
5009 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
5011 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
5015 * Make sure the HE AP doesn't require MCSs that aren't
5016 * supported by the client
5018 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5019 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5020 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
5030 /* If here, STA doesn't meet AP's HE min requirements */
5034 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5035 struct cfg80211_bss *cbss)
5037 struct ieee80211_local *local = sdata->local;
5038 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5039 const struct ieee80211_ht_cap *ht_cap = NULL;
5040 const struct ieee80211_ht_operation *ht_oper = NULL;
5041 const struct ieee80211_vht_operation *vht_oper = NULL;
5042 const struct ieee80211_he_operation *he_oper = NULL;
5043 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
5044 struct ieee80211_supported_band *sband;
5045 struct cfg80211_chan_def chandef;
5046 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5047 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
5048 struct ieee80211_bss *bss = (void *)cbss->priv;
5049 struct ieee802_11_elems *elems;
5050 const struct cfg80211_bss_ies *ies;
5057 ies = rcu_dereference(cbss->ies);
5058 elems = ieee802_11_parse_elems(ies->data, ies->len, false,
5065 sband = local->hw.wiphy->bands[cbss->channel->band];
5067 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5068 IEEE80211_STA_DISABLE_80P80MHZ |
5069 IEEE80211_STA_DISABLE_160MHZ);
5071 /* disable HT/VHT/HE if we don't support them */
5072 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5073 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE\n");
5074 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5075 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5076 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5079 if (!sband->vht_cap.vht_supported && is_5ghz) {
5080 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE\n");
5081 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5082 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5085 if (!ieee80211_get_he_iftype_cap(sband,
5086 ieee80211_vif_type_p2p(&sdata->vif))) {
5087 mlme_dbg(sdata, "HE not supported, disabling it\n");
5088 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5091 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5092 ht_oper = elems->ht_operation;
5093 ht_cap = elems->ht_cap_elem;
5096 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5101 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5102 vht_oper = elems->vht_operation;
5103 if (vht_oper && !ht_oper) {
5106 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5107 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5108 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5109 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5112 if (!elems->vht_cap_elem) {
5114 "bad VHT capabilities, disabling VHT\n");
5115 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5120 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5121 he_oper = elems->he_operation;
5124 struct ieee80211_bss_conf *bss_conf;
5127 bss_conf = &sdata->vif.bss_conf;
5129 if (elems->pwr_constr_elem)
5130 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
5132 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
5133 ARRAY_SIZE(elems->tx_pwr_env));
5135 for (i = 0; i < elems->tx_pwr_env_num; i++) {
5136 if (elems->tx_pwr_env_len[i] >
5137 sizeof(bss_conf->tx_pwr_env[j]))
5140 bss_conf->tx_pwr_env_num++;
5141 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
5142 elems->tx_pwr_env_len[i]);
5147 if (!ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5148 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5151 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5153 for (i = 0; i < sband->n_channels; i++) {
5154 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5155 IEEE80211_CHAN_NO_80MHZ))
5163 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
5164 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5167 if (sband->band == NL80211_BAND_S1GHZ) {
5168 s1g_oper = elems->s1g_oper;
5171 "AP missing S1G operation element?\n");
5174 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5177 ht_oper, vht_oper, he_oper,
5181 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
5185 /* the element data was RCU protected so no longer valid anyway */
5189 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5190 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5194 /* will change later if needed */
5195 sdata->smps_mode = IEEE80211_SMPS_OFF;
5197 mutex_lock(&local->mtx);
5199 * If this fails (possibly due to channel context sharing
5200 * on incompatible channels, e.g. 80+80 and 160 sharing the
5201 * same control channel) try to use a smaller bandwidth.
5203 ret = ieee80211_vif_use_channel(sdata, &chandef,
5204 IEEE80211_CHANCTX_SHARED);
5206 /* don't downgrade for 5 and 10 MHz channels, though. */
5207 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5208 chandef.width == NL80211_CHAN_WIDTH_10)
5211 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5212 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5213 ret = ieee80211_vif_use_channel(sdata, &chandef,
5214 IEEE80211_CHANCTX_SHARED);
5217 mutex_unlock(&local->mtx);
5221 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5222 u8 *dtim_count, u8 *dtim_period)
5224 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5225 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5227 const struct ieee80211_tim_ie *tim = NULL;
5228 const struct ieee80211_bssid_index *idx;
5229 bool valid = tim_ie && tim_ie[1] >= 2;
5232 tim = (void *)(tim_ie + 2);
5235 *dtim_count = valid ? tim->dtim_count : 0;
5238 *dtim_period = valid ? tim->dtim_period : 0;
5240 /* Check if value is overridden by non-transmitted profile */
5241 if (!idx_ie || idx_ie[1] < 3)
5244 idx = (void *)(idx_ie + 2);
5247 *dtim_count = idx->dtim_count;
5250 *dtim_period = idx->dtim_period;
5255 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5256 struct cfg80211_bss *cbss, bool assoc,
5259 struct ieee80211_local *local = sdata->local;
5260 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5261 struct ieee80211_bss *bss = (void *)cbss->priv;
5262 struct sta_info *new_sta = NULL;
5263 struct ieee80211_supported_band *sband;
5264 bool have_sta = false;
5267 sband = local->hw.wiphy->bands[cbss->channel->band];
5269 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5272 /* If a reconfig is happening, bail out */
5273 if (local->in_reconfig)
5278 have_sta = sta_info_get(sdata, cbss->bssid);
5283 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5289 * Set up the information for the new channel before setting the
5290 * new channel. We can't - completely race-free - change the basic
5291 * rates bitmap and the channel (sband) that it refers to, but if
5292 * we set it up before we at least avoid calling into the driver's
5293 * bss_info_changed() method with invalid information (since we do
5294 * call that from changing the channel - only for IDLE and perhaps
5295 * some others, but ...).
5297 * So to avoid that, just set up all the new information before the
5298 * channel, but tell the driver to apply it only afterwards, since
5299 * it might need the new channel for that.
5302 u32 rates = 0, basic_rates = 0;
5303 bool have_higher_than_11mbit = false;
5304 int min_rate = INT_MAX, min_rate_index = -1;
5305 const struct cfg80211_bss_ies *ies;
5306 int shift = ieee80211_vif_get_shift(&sdata->vif);
5308 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5309 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5310 ieee80211_s1g_sta_rate_init(new_sta);
5314 ieee80211_get_rates(sband, bss->supp_rates,
5315 bss->supp_rates_len,
5316 &rates, &basic_rates,
5317 &have_higher_than_11mbit,
5318 &min_rate, &min_rate_index,
5322 * This used to be a workaround for basic rates missing
5323 * in the association response frame. Now that we no
5324 * longer use the basic rates from there, it probably
5325 * doesn't happen any more, but keep the workaround so
5326 * in case some *other* APs are buggy in different ways
5327 * we can connect -- with a warning.
5328 * Allow this workaround only in case the AP provided at least
5331 if (min_rate_index < 0) {
5333 "No legacy rates in association response\n");
5335 sta_info_free(local, new_sta);
5337 } else if (!basic_rates) {
5339 "No basic rates, using min rate instead\n");
5340 basic_rates = BIT(min_rate_index);
5344 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5347 "No rates found, keeping mandatory only\n");
5349 sdata->vif.bss_conf.basic_rates = basic_rates;
5351 /* cf. IEEE 802.11 9.2.12 */
5352 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5353 have_higher_than_11mbit)
5354 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5356 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5359 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5361 /* set timing information */
5362 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5364 ies = rcu_dereference(cbss->beacon_ies);
5366 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5367 sdata->vif.bss_conf.sync_device_ts =
5368 bss->device_ts_beacon;
5370 ieee80211_get_dtim(ies,
5371 &sdata->vif.bss_conf.sync_dtim_count,
5373 } else if (!ieee80211_hw_check(&sdata->local->hw,
5374 TIMING_BEACON_ONLY)) {
5375 ies = rcu_dereference(cbss->proberesp_ies);
5376 /* must be non-NULL since beacon IEs were NULL */
5377 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5378 sdata->vif.bss_conf.sync_device_ts =
5379 bss->device_ts_presp;
5380 sdata->vif.bss_conf.sync_dtim_count = 0;
5382 sdata->vif.bss_conf.sync_tsf = 0;
5383 sdata->vif.bss_conf.sync_device_ts = 0;
5384 sdata->vif.bss_conf.sync_dtim_count = 0;
5389 if (new_sta || override) {
5390 err = ieee80211_prep_channel(sdata, cbss);
5393 sta_info_free(local, new_sta);
5400 * tell driver about BSSID, basic rates and timing
5401 * this was set up above, before setting the channel
5403 ieee80211_bss_info_change_notify(sdata,
5404 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5405 BSS_CHANGED_BEACON_INT);
5408 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5410 err = sta_info_insert(new_sta);
5414 "failed to insert STA entry for the AP (error %d)\n",
5419 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5421 /* Cancel scan to ensure that nothing interferes with connection */
5422 if (local->scanning)
5423 ieee80211_scan_cancel(local);
5429 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5430 struct cfg80211_auth_request *req)
5432 struct ieee80211_local *local = sdata->local;
5433 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5434 struct ieee80211_mgd_auth_data *auth_data;
5439 /* prepare auth data structure */
5441 switch (req->auth_type) {
5442 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5443 auth_alg = WLAN_AUTH_OPEN;
5445 case NL80211_AUTHTYPE_SHARED_KEY:
5448 auth_alg = WLAN_AUTH_SHARED_KEY;
5450 case NL80211_AUTHTYPE_FT:
5451 auth_alg = WLAN_AUTH_FT;
5453 case NL80211_AUTHTYPE_NETWORK_EAP:
5454 auth_alg = WLAN_AUTH_LEAP;
5456 case NL80211_AUTHTYPE_SAE:
5457 auth_alg = WLAN_AUTH_SAE;
5459 case NL80211_AUTHTYPE_FILS_SK:
5460 auth_alg = WLAN_AUTH_FILS_SK;
5462 case NL80211_AUTHTYPE_FILS_SK_PFS:
5463 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5465 case NL80211_AUTHTYPE_FILS_PK:
5466 auth_alg = WLAN_AUTH_FILS_PK;
5472 if (ifmgd->assoc_data)
5475 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5476 req->ie_len, GFP_KERNEL);
5480 auth_data->bss = req->bss;
5482 if (req->auth_data_len >= 4) {
5483 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5484 __le16 *pos = (__le16 *) req->auth_data;
5486 auth_data->sae_trans = le16_to_cpu(pos[0]);
5487 auth_data->sae_status = le16_to_cpu(pos[1]);
5489 memcpy(auth_data->data, req->auth_data + 4,
5490 req->auth_data_len - 4);
5491 auth_data->data_len += req->auth_data_len - 4;
5494 /* Check if continuing authentication or trying to authenticate with the
5495 * same BSS that we were in the process of authenticating with and avoid
5496 * removal and re-addition of the STA entry in
5497 * ieee80211_prep_connection().
5499 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5501 if (req->ie && req->ie_len) {
5502 memcpy(&auth_data->data[auth_data->data_len],
5503 req->ie, req->ie_len);
5504 auth_data->data_len += req->ie_len;
5507 if (req->key && req->key_len) {
5508 auth_data->key_len = req->key_len;
5509 auth_data->key_idx = req->key_idx;
5510 memcpy(auth_data->key, req->key, req->key_len);
5513 auth_data->algorithm = auth_alg;
5515 /* try to authenticate/probe */
5517 if (ifmgd->auth_data) {
5518 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5519 auth_data->peer_confirmed =
5520 ifmgd->auth_data->peer_confirmed;
5522 ieee80211_destroy_auth_data(sdata, cont_auth);
5525 /* prep auth_data so we don't go into idle on disassoc */
5526 ifmgd->auth_data = auth_data;
5528 /* If this is continuation of an ongoing SAE authentication exchange
5529 * (i.e., request to send SAE Confirm) and the peer has already
5530 * confirmed, mark authentication completed since we are about to send
5533 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5534 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5535 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5537 if (ifmgd->associated) {
5538 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5541 "disconnect from AP %pM for new auth to %pM\n",
5542 ifmgd->associated->bssid, req->bss->bssid);
5543 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5544 WLAN_REASON_UNSPECIFIED,
5547 ieee80211_report_disconnect(sdata, frame_buf,
5548 sizeof(frame_buf), true,
5549 WLAN_REASON_UNSPECIFIED,
5553 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5555 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5559 err = ieee80211_auth(sdata);
5561 sta_info_destroy_addr(sdata, req->bss->bssid);
5565 /* hold our own reference */
5566 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5570 eth_zero_addr(ifmgd->bssid);
5571 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5572 ifmgd->auth_data = NULL;
5573 mutex_lock(&sdata->local->mtx);
5574 ieee80211_vif_release_channel(sdata);
5575 mutex_unlock(&sdata->local->mtx);
5580 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5581 struct cfg80211_assoc_request *req)
5583 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5584 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5585 struct ieee80211_local *local = sdata->local;
5586 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5587 struct ieee80211_bss *bss = (void *)req->bss->priv;
5588 struct ieee80211_mgd_assoc_data *assoc_data;
5589 const struct cfg80211_bss_ies *beacon_ies;
5590 struct ieee80211_supported_band *sband;
5591 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5592 const struct element *ssid_elem, *ht_elem, *vht_elem;
5594 bool override = false;
5596 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5601 ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID);
5602 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
5607 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
5608 assoc_data->ssid_len = ssid_elem->datalen;
5609 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5610 bss_conf->ssid_len = assoc_data->ssid_len;
5613 if (ifmgd->associated) {
5614 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5617 "disconnect from AP %pM for new assoc to %pM\n",
5618 ifmgd->associated->bssid, req->bss->bssid);
5619 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5620 WLAN_REASON_UNSPECIFIED,
5623 ieee80211_report_disconnect(sdata, frame_buf,
5624 sizeof(frame_buf), true,
5625 WLAN_REASON_UNSPECIFIED,
5629 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5634 if (ifmgd->assoc_data) {
5639 if (ifmgd->auth_data) {
5642 /* keep sta info, bssid if matching */
5643 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5644 ieee80211_destroy_auth_data(sdata, match);
5647 /* prepare assoc data */
5649 ifmgd->beacon_crc_valid = false;
5651 assoc_data->wmm = bss->wmm_used &&
5652 (local->hw.queues >= IEEE80211_NUM_ACS);
5655 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5656 * We still associate in non-HT mode (11a/b/g) if any one of these
5657 * ciphers is configured as pairwise.
5658 * We can set this to true for non-11n hardware, that'll be checked
5659 * separately along with the peer capabilities.
5661 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5662 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5663 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5664 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5665 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5666 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5667 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5668 netdev_info(sdata->dev,
5669 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5673 sband = local->hw.wiphy->bands[req->bss->channel->band];
5675 /* also disable HT/VHT/HE if the AP doesn't use WMM */
5676 if (!bss->wmm_used) {
5677 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5678 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5679 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5680 netdev_info(sdata->dev,
5681 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5684 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5685 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5686 sizeof(ifmgd->ht_capa_mask));
5688 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5689 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5690 sizeof(ifmgd->vht_capa_mask));
5692 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5693 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5694 sizeof(ifmgd->s1g_capa_mask));
5696 if (req->ie && req->ie_len) {
5697 memcpy(assoc_data->ie, req->ie, req->ie_len);
5698 assoc_data->ie_len = req->ie_len;
5701 if (req->fils_kek) {
5702 /* should already be checked in cfg80211 - so warn */
5703 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
5707 memcpy(assoc_data->fils_kek, req->fils_kek,
5709 assoc_data->fils_kek_len = req->fils_kek_len;
5712 if (req->fils_nonces)
5713 memcpy(assoc_data->fils_nonces, req->fils_nonces,
5714 2 * FILS_NONCE_LEN);
5716 assoc_data->bss = req->bss;
5717 assoc_data->capability = req->bss->capability;
5718 assoc_data->supp_rates = bss->supp_rates;
5719 assoc_data->supp_rates_len = bss->supp_rates_len;
5722 ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION);
5723 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
5724 assoc_data->ap_ht_param =
5725 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
5727 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5728 vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY);
5729 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
5730 memcpy(&assoc_data->ap_vht_cap, vht_elem->data,
5731 sizeof(struct ieee80211_vht_cap));
5732 } else if (is_5ghz) {
5733 sdata_info(sdata, "VHT capa missing/short, disabling VHT/HE\n");
5734 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
5735 IEEE80211_STA_DISABLE_HE;
5739 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
5740 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
5741 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
5742 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
5744 if (bss->wmm_used && bss->uapsd_supported &&
5745 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
5746 assoc_data->uapsd = true;
5747 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
5749 assoc_data->uapsd = false;
5750 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
5753 if (req->prev_bssid)
5754 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
5757 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
5758 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
5760 ifmgd->mfp = IEEE80211_MFP_DISABLED;
5761 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
5764 if (req->flags & ASSOC_REQ_USE_RRM)
5765 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
5767 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
5769 if (req->crypto.control_port)
5770 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
5772 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
5774 sdata->control_port_protocol = req->crypto.control_port_ethertype;
5775 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
5776 sdata->control_port_over_nl80211 =
5777 req->crypto.control_port_over_nl80211;
5778 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
5779 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
5782 /* kick off associate process */
5784 ifmgd->assoc_data = assoc_data;
5785 ifmgd->dtim_period = 0;
5786 ifmgd->have_beacon = false;
5788 /* override HT/VHT configuration only if the AP and we support it */
5789 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
5790 struct ieee80211_sta_ht_cap sta_ht_cap;
5792 if (req->flags & ASSOC_REQ_DISABLE_HT)
5795 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
5796 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
5798 /* check for 40 MHz disable override */
5799 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
5800 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
5801 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
5804 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
5805 req->flags & ASSOC_REQ_DISABLE_VHT)
5809 if (req->flags & ASSOC_REQ_DISABLE_HT) {
5810 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
5811 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5812 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5813 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5816 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
5817 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
5818 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5821 if (req->flags & ASSOC_REQ_DISABLE_HE) {
5822 mlme_dbg(sdata, "HE disabled by flag, disabling VHT\n");
5823 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5826 err = ieee80211_prep_connection(sdata, req->bss, true, override);
5830 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
5831 if (ifmgd->powersave)
5832 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
5834 sdata->smps_mode = IEEE80211_SMPS_OFF;
5836 sdata->smps_mode = ifmgd->req_smps;
5840 beacon_ies = rcu_dereference(req->bss->beacon_ies);
5842 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
5845 * Wait up to one beacon interval ...
5846 * should this be more if we miss one?
5848 sdata_info(sdata, "waiting for beacon from %pM\n",
5850 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
5851 assoc_data->timeout_started = true;
5852 assoc_data->need_beacon = true;
5853 } else if (beacon_ies) {
5854 const struct element *elem;
5857 ieee80211_get_dtim(beacon_ies, &dtim_count,
5858 &ifmgd->dtim_period);
5860 ifmgd->have_beacon = true;
5861 assoc_data->timeout = jiffies;
5862 assoc_data->timeout_started = true;
5864 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5865 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
5866 sdata->vif.bss_conf.sync_device_ts =
5867 bss->device_ts_beacon;
5868 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
5871 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
5872 beacon_ies->data, beacon_ies->len);
5873 if (elem && elem->datalen >= 3)
5874 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
5876 sdata->vif.bss_conf.profile_periodicity = 0;
5878 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
5879 beacon_ies->data, beacon_ies->len);
5880 if (elem && elem->datalen >= 11 &&
5881 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5882 sdata->vif.bss_conf.ema_ap = true;
5884 sdata->vif.bss_conf.ema_ap = false;
5886 assoc_data->timeout = jiffies;
5887 assoc_data->timeout_started = true;
5891 run_again(sdata, assoc_data->timeout);
5893 if (bss->corrupt_data) {
5894 char *corrupt_type = "data";
5895 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
5896 if (bss->corrupt_data &
5897 IEEE80211_BSS_CORRUPT_PROBE_RESP)
5898 corrupt_type = "beacon and probe response";
5900 corrupt_type = "beacon";
5901 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
5902 corrupt_type = "probe response";
5903 sdata_info(sdata, "associating with AP with corrupt %s\n",
5909 eth_zero_addr(ifmgd->bssid);
5910 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5911 ifmgd->assoc_data = NULL;
5917 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
5918 struct cfg80211_deauth_request *req)
5920 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5921 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5922 bool tx = !req->local_state_change;
5923 struct ieee80211_prep_tx_info info = {
5924 .subtype = IEEE80211_STYPE_DEAUTH,
5927 if (ifmgd->auth_data &&
5928 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
5930 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
5931 req->bssid, req->reason_code,
5932 ieee80211_get_reason_code_string(req->reason_code));
5934 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5935 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5936 IEEE80211_STYPE_DEAUTH,
5937 req->reason_code, tx,
5939 ieee80211_destroy_auth_data(sdata, false);
5940 ieee80211_report_disconnect(sdata, frame_buf,
5941 sizeof(frame_buf), true,
5942 req->reason_code, false);
5943 drv_mgd_complete_tx(sdata->local, sdata, &info);
5947 if (ifmgd->assoc_data &&
5948 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
5950 "aborting association with %pM by local choice (Reason: %u=%s)\n",
5951 req->bssid, req->reason_code,
5952 ieee80211_get_reason_code_string(req->reason_code));
5954 drv_mgd_prepare_tx(sdata->local, sdata, &info);
5955 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
5956 IEEE80211_STYPE_DEAUTH,
5957 req->reason_code, tx,
5959 ieee80211_destroy_assoc_data(sdata, false, true);
5960 ieee80211_report_disconnect(sdata, frame_buf,
5961 sizeof(frame_buf), true,
5962 req->reason_code, false);
5966 if (ifmgd->associated &&
5967 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
5969 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
5970 req->bssid, req->reason_code,
5971 ieee80211_get_reason_code_string(req->reason_code));
5973 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5974 req->reason_code, tx, frame_buf);
5975 ieee80211_report_disconnect(sdata, frame_buf,
5976 sizeof(frame_buf), true,
5977 req->reason_code, false);
5978 drv_mgd_complete_tx(sdata->local, sdata, &info);
5985 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
5986 struct cfg80211_disassoc_request *req)
5988 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5990 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5993 * cfg80211 should catch this ... but it's racy since
5994 * we can receive a disassoc frame, process it, hand it
5995 * to cfg80211 while that's in a locked section already
5996 * trying to tell us that the user wants to disconnect.
5998 if (ifmgd->associated != req->bss)
6002 "disassociating from %pM by local choice (Reason: %u=%s)\n",
6003 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
6005 memcpy(bssid, req->bss->bssid, ETH_ALEN);
6006 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
6007 req->reason_code, !req->local_state_change,
6010 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6011 req->reason_code, false);
6016 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
6018 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6021 * Make sure some work items will not run after this,
6022 * they will not do anything but might not have been
6023 * cancelled when disconnecting.
6025 cancel_work_sync(&ifmgd->monitor_work);
6026 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
6027 cancel_work_sync(&ifmgd->request_smps_work);
6028 cancel_work_sync(&ifmgd->csa_connection_drop_work);
6029 cancel_work_sync(&ifmgd->chswitch_work);
6030 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
6033 if (ifmgd->assoc_data) {
6034 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
6035 ieee80211_destroy_assoc_data(sdata, false, false);
6036 cfg80211_assoc_timeout(sdata->dev, bss);
6038 if (ifmgd->auth_data)
6039 ieee80211_destroy_auth_data(sdata, false);
6040 spin_lock_bh(&ifmgd->teardown_lock);
6041 if (ifmgd->teardown_skb) {
6042 kfree_skb(ifmgd->teardown_skb);
6043 ifmgd->teardown_skb = NULL;
6044 ifmgd->orig_teardown_skb = NULL;
6046 kfree(ifmgd->assoc_req_ies);
6047 ifmgd->assoc_req_ies = NULL;
6048 ifmgd->assoc_req_ies_len = 0;
6049 spin_unlock_bh(&ifmgd->teardown_lock);
6050 del_timer_sync(&ifmgd->timer);
6051 sdata_unlock(sdata);
6054 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
6055 enum nl80211_cqm_rssi_threshold_event rssi_event,
6059 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6061 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
6063 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
6065 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
6067 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
6069 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6071 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
6073 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
6075 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);