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_eht_operation *eht_oper,
154 const struct ieee80211_s1g_oper_ie *s1g_oper,
155 struct cfg80211_chan_def *chandef, bool tracking)
157 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
158 struct cfg80211_chan_def vht_chandef;
159 struct ieee80211_sta_ht_cap sta_ht_cap;
162 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
163 chandef->chan = channel;
164 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
165 chandef->center_freq1 = channel->center_freq;
166 chandef->freq1_offset = channel->freq_offset;
168 if (channel->band == NL80211_BAND_6GHZ) {
169 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
172 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
173 ret = IEEE80211_STA_DISABLE_HT |
174 IEEE80211_STA_DISABLE_VHT |
175 IEEE80211_STA_DISABLE_HE |
176 IEEE80211_STA_DISABLE_EHT;
180 vht_chandef = *chandef;
182 } else if (sband->band == NL80211_BAND_S1GHZ) {
183 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
185 "Missing S1G Operation Element? Trying operating == primary\n");
186 chandef->width = ieee80211_s1g_channel_width(channel);
189 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_40MHZ |
190 IEEE80211_STA_DISABLE_VHT |
191 IEEE80211_STA_DISABLE_80P80MHZ |
192 IEEE80211_STA_DISABLE_160MHZ;
196 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
197 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
199 if (!ht_oper || !sta_ht_cap.ht_supported) {
200 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
201 ret = IEEE80211_STA_DISABLE_HT |
202 IEEE80211_STA_DISABLE_VHT |
203 IEEE80211_STA_DISABLE_HE |
204 IEEE80211_STA_DISABLE_EHT;
208 chandef->width = NL80211_CHAN_WIDTH_20;
210 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
212 /* check that channel matches the right operating channel */
213 if (!tracking && channel->center_freq != ht_cfreq) {
215 * It's possible that some APs are confused here;
216 * Netgear WNDR3700 sometimes reports 4 higher than
217 * the actual channel in association responses, but
218 * since we look at probe response/beacon data here
222 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
223 channel->center_freq, ht_cfreq,
224 ht_oper->primary_chan, channel->band);
225 ret = IEEE80211_STA_DISABLE_HT |
226 IEEE80211_STA_DISABLE_VHT |
227 IEEE80211_STA_DISABLE_HE |
228 IEEE80211_STA_DISABLE_EHT;
232 /* check 40 MHz support, if we have it */
233 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
234 ieee80211_chandef_ht_oper(ht_oper, chandef);
236 mlme_dbg(sdata, "40 MHz not supported\n");
237 /* 40 MHz (and 80 MHz) must be supported for VHT */
238 ret = IEEE80211_STA_DISABLE_VHT;
239 /* also mark 40 MHz disabled */
240 ret |= IEEE80211_STA_DISABLE_40MHZ;
244 if (!vht_oper || !sband->vht_cap.vht_supported) {
245 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
246 ret = IEEE80211_STA_DISABLE_VHT;
250 vht_chandef = *chandef;
251 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
252 (le32_to_cpu(he_oper->he_oper_params) &
253 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
254 struct ieee80211_vht_operation he_oper_vht_cap;
257 * Set only first 3 bytes (other 2 aren't used in
258 * ieee80211_chandef_vht_oper() anyway)
260 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
261 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
263 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
264 &he_oper_vht_cap, ht_oper,
266 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
268 "HE AP VHT information is invalid, disabling HE\n");
269 ret = IEEE80211_STA_DISABLE_HE | IEEE80211_STA_DISABLE_EHT;
272 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
276 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
278 "AP VHT information is invalid, disabling VHT\n");
279 ret = IEEE80211_STA_DISABLE_VHT;
283 if (!cfg80211_chandef_valid(&vht_chandef)) {
284 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
286 "AP VHT information is invalid, disabling VHT\n");
287 ret = IEEE80211_STA_DISABLE_VHT;
291 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
296 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
297 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
299 "AP VHT information doesn't match HT, disabling VHT\n");
300 ret = IEEE80211_STA_DISABLE_VHT;
304 *chandef = vht_chandef;
310 * When tracking the current AP, don't do any further checks if the
311 * new chandef is identical to the one we're currently using for the
312 * connection. This keeps us from playing ping-pong with regulatory,
313 * without it the following can happen (for example):
314 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
315 * - AP advertises regdom US
316 * - CRDA loads regdom US with 80 MHz prohibited (old database)
317 * - the code below detects an unsupported channel, downgrades, and
318 * we disconnect from the AP in the caller
319 * - disconnect causes CRDA to reload world regdomain and the game
321 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
323 * It seems possible that there are still scenarios with CSA or real
324 * bandwidth changes where a this could happen, but those cases are
325 * less common and wouldn't completely prevent using the AP.
328 cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
331 /* don't print the message below for VHT mismatch if VHT is disabled */
332 if (ret & IEEE80211_STA_DISABLE_VHT)
333 vht_chandef = *chandef;
336 * Ignore the DISABLED flag when we're already connected and only
337 * tracking the APs beacon for bandwidth changes - otherwise we
338 * might get disconnected here if we connect to an AP, update our
339 * regulatory information based on the AP's country IE and the
340 * information we have is wrong/outdated and disables the channel
341 * that we're actually using for the connection to the AP.
343 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
345 IEEE80211_CHAN_DISABLED)) {
346 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
347 ret = IEEE80211_STA_DISABLE_HT |
348 IEEE80211_STA_DISABLE_VHT |
349 IEEE80211_STA_DISABLE_HE |
350 IEEE80211_STA_DISABLE_EHT;
354 ret |= ieee80211_chandef_downgrade(chandef);
357 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
358 IEEE80211_CHAN_NO_HE))
359 ret |= IEEE80211_STA_DISABLE_HE | IEEE80211_STA_DISABLE_EHT;
361 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
362 IEEE80211_CHAN_NO_EHT))
363 ret |= IEEE80211_STA_DISABLE_EHT;
365 if (chandef->width != vht_chandef.width && !tracking)
367 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
369 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
373 static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
374 struct sta_info *sta,
375 const struct ieee80211_ht_cap *ht_cap,
376 const struct ieee80211_vht_cap *vht_cap,
377 const struct ieee80211_ht_operation *ht_oper,
378 const struct ieee80211_vht_operation *vht_oper,
379 const struct ieee80211_he_operation *he_oper,
380 const struct ieee80211_eht_operation *eht_oper,
381 const struct ieee80211_s1g_oper_ie *s1g_oper,
382 const u8 *bssid, u32 *changed)
384 struct ieee80211_local *local = sdata->local;
385 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
386 struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
387 struct ieee80211_supported_band *sband =
388 local->hw.wiphy->bands[chan->band];
389 struct cfg80211_chan_def chandef;
392 u32 vht_cap_info = 0;
395 /* if HT was/is disabled, don't track any bandwidth changes */
396 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
399 /* don't check VHT if we associated as non-VHT station */
400 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
403 /* don't check HE if we associated as non-HE station */
404 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
405 !ieee80211_get_he_iftype_cap(sband,
406 ieee80211_vif_type_p2p(&sdata->vif))) {
411 /* don't check EHT if we associated as non-EHT station */
412 if (ifmgd->flags & IEEE80211_STA_DISABLE_EHT ||
413 !ieee80211_get_eht_iftype_cap(sband,
414 ieee80211_vif_type_p2p(&sdata->vif)))
417 if (WARN_ON_ONCE(!sta))
421 * if bss configuration changed store the new one -
422 * this may be applicable even if channel is identical
424 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
425 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
426 *changed |= BSS_CHANGED_HT;
427 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
431 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
433 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
434 flags = ieee80211_determine_chantype(sdata, sband, chan, vht_cap_info,
437 s1g_oper, &chandef, true);
440 * Downgrade the new channel if we associated with restricted
441 * capabilities. For example, if we associated as a 20 MHz STA
442 * to a 40 MHz AP (due to regulatory, capabilities or config
443 * reasons) then switching to a 40 MHz channel now won't do us
444 * any good -- we couldn't use it with the AP.
446 if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
447 chandef.width == NL80211_CHAN_WIDTH_80P80)
448 flags |= ieee80211_chandef_downgrade(&chandef);
449 if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
450 chandef.width == NL80211_CHAN_WIDTH_160)
451 flags |= ieee80211_chandef_downgrade(&chandef);
452 if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
453 chandef.width > NL80211_CHAN_WIDTH_20)
454 flags |= ieee80211_chandef_downgrade(&chandef);
456 if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
460 "AP %pM changed bandwidth, new config is %d.%03d MHz, "
461 "width %d (%d.%03d/%d MHz)\n",
462 ifmgd->bssid, chandef.chan->center_freq,
463 chandef.chan->freq_offset, chandef.width,
464 chandef.center_freq1, chandef.freq1_offset,
465 chandef.center_freq2);
467 if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
468 IEEE80211_STA_DISABLE_VHT |
469 IEEE80211_STA_DISABLE_HE |
470 IEEE80211_STA_DISABLE_EHT |
471 IEEE80211_STA_DISABLE_40MHZ |
472 IEEE80211_STA_DISABLE_80P80MHZ |
473 IEEE80211_STA_DISABLE_160MHZ |
474 IEEE80211_STA_DISABLE_320MHZ)) ||
475 !cfg80211_chandef_valid(&chandef)) {
477 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
478 ifmgd->bssid, flags, ifmgd->flags);
482 ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
486 "AP %pM changed bandwidth to incompatible one - disconnect\n",
494 /* frame sending functions */
496 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
497 struct sk_buff *skb, u8 ap_ht_param,
498 struct ieee80211_supported_band *sband,
499 struct ieee80211_channel *channel,
500 enum ieee80211_smps_mode smps)
503 u32 flags = channel->flags;
505 struct ieee80211_sta_ht_cap ht_cap;
507 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
509 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
510 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
512 /* determine capability flags */
515 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
516 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
517 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
518 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
519 cap &= ~IEEE80211_HT_CAP_SGI_40;
522 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
523 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
524 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
525 cap &= ~IEEE80211_HT_CAP_SGI_40;
531 * If 40 MHz was disabled associate as though we weren't
532 * capable of 40 MHz -- some broken APs will never fall
533 * back to trying to transmit in 20 MHz.
535 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
536 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
537 cap &= ~IEEE80211_HT_CAP_SGI_40;
540 /* set SM PS mode properly */
541 cap &= ~IEEE80211_HT_CAP_SM_PS;
543 case IEEE80211_SMPS_AUTOMATIC:
544 case IEEE80211_SMPS_NUM_MODES:
547 case IEEE80211_SMPS_OFF:
548 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
549 IEEE80211_HT_CAP_SM_PS_SHIFT;
551 case IEEE80211_SMPS_STATIC:
552 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
553 IEEE80211_HT_CAP_SM_PS_SHIFT;
555 case IEEE80211_SMPS_DYNAMIC:
556 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
557 IEEE80211_HT_CAP_SM_PS_SHIFT;
561 /* reserve and fill IE */
562 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
563 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
566 /* This function determines vht capability flags for the association
568 * Note - the function may set the owner of the MU-MIMO capability
570 static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
572 struct ieee80211_supported_band *sband,
573 struct ieee80211_vht_cap *ap_vht_cap)
575 struct ieee80211_local *local = sdata->local;
578 struct ieee80211_sta_vht_cap vht_cap;
579 u32 mask, ap_bf_sts, our_bf_sts;
581 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
583 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
584 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
586 /* determine capability flags */
589 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
590 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
592 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
593 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
594 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
595 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
598 if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
599 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
600 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
604 * Some APs apparently get confused if our capabilities are better
605 * than theirs, so restrict what we advertise in the assoc request.
607 if (!(ap_vht_cap->vht_cap_info &
608 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
609 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
610 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
611 else if (!(ap_vht_cap->vht_cap_info &
612 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
613 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
616 * If some other vif is using the MU-MIMO capability we cannot associate
617 * using MU-MIMO - this will lead to contradictions in the group-id
619 * Ownership is defined since association request, in order to avoid
620 * simultaneous associations with MU-MIMO.
622 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
623 bool disable_mu_mimo = false;
624 struct ieee80211_sub_if_data *other;
626 list_for_each_entry_rcu(other, &local->interfaces, list) {
627 if (other->vif.mu_mimo_owner) {
628 disable_mu_mimo = true;
633 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
635 sdata->vif.mu_mimo_owner = true;
638 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
640 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
641 our_bf_sts = cap & mask;
643 if (ap_bf_sts < our_bf_sts) {
648 /* reserve and fill IE */
649 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
650 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
653 /* This function determines HE capability flags for the association
656 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
658 struct ieee80211_supported_band *sband)
660 u8 *pos, *pre_he_pos;
661 const struct ieee80211_sta_he_cap *he_cap = NULL;
662 struct ieee80211_chanctx_conf *chanctx_conf;
664 bool reg_cap = false;
667 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
668 if (!WARN_ON_ONCE(!chanctx_conf))
669 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
671 IEEE80211_CHAN_NO_HE);
675 he_cap = ieee80211_get_he_iftype_cap(sband,
676 ieee80211_vif_type_p2p(&sdata->vif));
677 if (!he_cap || !chanctx_conf || !reg_cap)
680 /* get a max size estimate */
682 2 + 1 + sizeof(he_cap->he_cap_elem) +
683 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
684 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
685 he_cap->he_cap_elem.phy_cap_info);
686 pos = skb_put(skb, he_cap_size);
688 pos = ieee80211_ie_build_he_cap(sdata->u.mgd.flags,
689 pos, he_cap, pos + he_cap_size);
690 /* trim excess if any */
691 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
693 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
696 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
698 struct ieee80211_supported_band *sband)
701 const struct ieee80211_sta_he_cap *he_cap;
702 const struct ieee80211_sta_eht_cap *eht_cap;
703 struct ieee80211_chanctx_conf *chanctx_conf;
705 bool reg_cap = false;
708 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
709 if (!WARN_ON_ONCE(!chanctx_conf))
710 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
712 IEEE80211_CHAN_NO_HE |
713 IEEE80211_CHAN_NO_EHT);
716 he_cap = ieee80211_get_he_iftype_cap(sband,
717 ieee80211_vif_type_p2p(&sdata->vif));
718 eht_cap = ieee80211_get_eht_iftype_cap(sband,
719 ieee80211_vif_type_p2p(&sdata->vif));
722 * EHT capabilities element is only added if the HE capabilities element
723 * was added so assume that 'he_cap' is valid and don't check it.
725 if (WARN_ON(!he_cap || !eht_cap || !reg_cap))
729 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
730 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
731 &eht_cap->eht_cap_elem) +
732 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
733 eht_cap->eht_cap_elem.phy_cap_info);
734 pos = skb_put(skb, eht_cap_size);
735 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size);
738 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
740 struct ieee80211_local *local = sdata->local;
741 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
742 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
744 struct ieee80211_mgmt *mgmt;
745 u8 *pos, qos_info, *ie_start;
746 size_t offset = 0, noffset;
747 int i, count, rates_len, supp_rates_len, shift;
749 struct ieee80211_supported_band *sband;
750 struct ieee80211_chanctx_conf *chanctx_conf;
751 struct ieee80211_channel *chan;
754 struct element *ext_capa = NULL;
755 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
756 const struct ieee80211_sband_iftype_data *iftd;
757 struct ieee80211_prep_tx_info info = {};
760 /* we know it's writable, cast away the const */
761 if (assoc_data->ie_len)
762 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
766 sdata_assert_lock(sdata);
769 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
770 if (WARN_ON(!chanctx_conf)) {
774 chan = chanctx_conf->def.chan;
776 sband = local->hw.wiphy->bands[chan->band];
777 shift = ieee80211_vif_get_shift(&sdata->vif);
779 if (assoc_data->supp_rates_len) {
781 * Get all rates supported by the device and the AP as
782 * some APs don't like getting a superset of their rates
783 * in the association request (e.g. D-Link DAP 1353 in
786 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
787 assoc_data->supp_rates,
788 assoc_data->supp_rates_len,
792 * In case AP not provide any supported rates information
793 * before association, we send information element(s) with
794 * all rates that we support.
797 for (i = 0; i < sband->n_bitrates; i++) {
803 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
805 skb = alloc_skb(local->hw.extra_tx_headroom +
806 sizeof(*mgmt) + /* bit too much but doesn't matter */
807 2 + assoc_data->ssid_len + /* SSID */
808 4 + rates_len + /* (extended) rates */
809 4 + /* power capability */
810 2 + 2 * sband->n_channels + /* supported channels */
811 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
812 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
813 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
814 sizeof(struct ieee80211_he_mcs_nss_supp) +
815 IEEE80211_HE_PPE_THRES_MAX_LEN +
816 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
817 assoc_data->ie_len + /* extra IEs */
818 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
820 (iftd ? iftd->vendor_elems.len : 0),
825 skb_reserve(skb, local->hw.extra_tx_headroom);
827 capab = WLAN_CAPABILITY_ESS;
829 if (sband->band == NL80211_BAND_2GHZ) {
830 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
831 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
834 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
835 capab |= WLAN_CAPABILITY_PRIVACY;
837 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
838 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
839 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
841 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
842 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
844 mgmt = skb_put_zero(skb, 24);
845 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
846 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
847 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
849 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
850 ieee80211_encode_usf(local->hw.conf.listen_interval) :
851 local->hw.conf.listen_interval);
852 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
854 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
855 IEEE80211_STYPE_REASSOC_REQ);
856 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
857 mgmt->u.reassoc_req.listen_interval = listen_int;
858 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
860 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
863 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
864 IEEE80211_STYPE_ASSOC_REQ);
865 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
866 mgmt->u.assoc_req.listen_interval = listen_int;
867 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
871 pos = skb_put(skb, 2 + assoc_data->ssid_len);
873 *pos++ = WLAN_EID_SSID;
874 *pos++ = assoc_data->ssid_len;
875 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
877 if (sband->band == NL80211_BAND_S1GHZ)
880 /* add all rates which were marked to be used above */
881 supp_rates_len = rates_len;
882 if (supp_rates_len > 8)
885 pos = skb_put(skb, supp_rates_len + 2);
886 *pos++ = WLAN_EID_SUPP_RATES;
887 *pos++ = supp_rates_len;
890 for (i = 0; i < sband->n_bitrates; i++) {
891 if (BIT(i) & rates) {
892 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
900 if (rates_len > count) {
901 pos = skb_put(skb, rates_len - count + 2);
902 *pos++ = WLAN_EID_EXT_SUPP_RATES;
903 *pos++ = rates_len - count;
905 for (i++; i < sband->n_bitrates; i++) {
906 if (BIT(i) & rates) {
908 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
916 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
917 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
918 pos = skb_put(skb, 4);
919 *pos++ = WLAN_EID_PWR_CAPABILITY;
921 *pos++ = 0; /* min tx power */
923 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
927 * Per spec, we shouldn't include the list of channels if we advertise
928 * support for extended channel switching, but we've always done that;
929 * (for now?) apply this restriction only on the (new) 6 GHz band.
931 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
932 (sband->band != NL80211_BAND_6GHZ ||
933 !ext_capa || ext_capa->datalen < 1 ||
934 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
935 /* TODO: get this in reg domain format */
936 pos = skb_put(skb, 2 * sband->n_channels + 2);
937 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
938 *pos++ = 2 * sband->n_channels;
939 for (i = 0; i < sband->n_channels; i++) {
940 *pos++ = ieee80211_frequency_to_channel(
941 sband->channels[i].center_freq);
942 *pos++ = 1; /* one channel in the subband*/
946 /* Set MBSSID support for HE AP if needed */
947 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
948 !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && assoc_data->ie_len &&
949 ext_capa && ext_capa->datalen >= 3)
950 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
952 /* if present, add any custom IEs that go before HT */
953 if (assoc_data->ie_len) {
954 static const u8 before_ht[] = {
957 WLAN_EID_EXT_SUPP_RATES,
958 WLAN_EID_PWR_CAPABILITY,
959 WLAN_EID_SUPPORTED_CHANNELS,
962 WLAN_EID_RRM_ENABLED_CAPABILITIES,
963 WLAN_EID_MOBILITY_DOMAIN,
964 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
965 WLAN_EID_RIC_DATA, /* reassoc only */
966 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
968 static const u8 after_ric[] = {
969 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
970 WLAN_EID_HT_CAPABILITY,
971 WLAN_EID_BSS_COEX_2040,
972 /* luckily this is almost always there */
973 WLAN_EID_EXT_CAPABILITY,
974 WLAN_EID_QOS_TRAFFIC_CAPA,
975 WLAN_EID_TIM_BCAST_REQ,
976 WLAN_EID_INTERWORKING,
977 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
978 WLAN_EID_VHT_CAPABILITY,
979 WLAN_EID_OPMODE_NOTIF,
982 noffset = ieee80211_ie_split_ric(assoc_data->ie,
985 ARRAY_SIZE(before_ht),
987 ARRAY_SIZE(after_ric),
989 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
993 if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
994 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
995 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
997 if (sband->band != NL80211_BAND_6GHZ &&
998 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
999 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
1000 sband, chan, sdata->smps_mode);
1002 /* if present, add any custom IEs that go before VHT */
1003 if (assoc_data->ie_len) {
1004 static const u8 before_vht[] = {
1006 * no need to list the ones split off before HT
1009 WLAN_EID_BSS_COEX_2040,
1010 WLAN_EID_EXT_CAPABILITY,
1011 WLAN_EID_QOS_TRAFFIC_CAPA,
1012 WLAN_EID_TIM_BCAST_REQ,
1013 WLAN_EID_INTERWORKING,
1014 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
1017 /* RIC already taken above, so no need to handle here anymore */
1018 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
1019 before_vht, ARRAY_SIZE(before_vht),
1021 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1025 /* if present, add any custom IEs that go before HE */
1026 if (assoc_data->ie_len) {
1027 static const u8 before_he[] = {
1029 * no need to list the ones split off before VHT
1032 WLAN_EID_OPMODE_NOTIF,
1033 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
1035 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
1036 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
1037 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
1038 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
1039 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
1040 /* TODO: add 11ah/11aj/11ak elements */
1043 /* RIC already taken above, so no need to handle here anymore */
1044 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
1045 before_he, ARRAY_SIZE(before_he),
1047 pos = skb_put(skb, noffset - offset);
1048 memcpy(pos, assoc_data->ie + offset, noffset - offset);
1052 if (sband->band != NL80211_BAND_6GHZ &&
1053 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
1054 ieee80211_add_vht_ie(sdata, skb, sband,
1055 &assoc_data->ap_vht_cap);
1058 * If AP doesn't support HT, mark HE and EHT as disabled.
1059 * If on the 5GHz band, make sure it supports VHT.
1061 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
1062 (sband->band == NL80211_BAND_5GHZ &&
1063 ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
1064 ifmgd->flags |= IEEE80211_STA_DISABLE_HE |
1065 IEEE80211_STA_DISABLE_EHT;
1067 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
1068 ieee80211_add_he_ie(sdata, skb, sband);
1070 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_EHT))
1071 ieee80211_add_eht_ie(sdata, skb, sband);
1074 /* if present, add any custom non-vendor IEs that go after HE */
1075 if (assoc_data->ie_len) {
1076 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1079 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1083 if (assoc_data->wmm) {
1084 if (assoc_data->uapsd) {
1085 qos_info = ifmgd->uapsd_queues;
1086 qos_info |= (ifmgd->uapsd_max_sp_len <<
1087 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1092 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1095 if (sband->band == NL80211_BAND_S1GHZ) {
1096 ieee80211_add_aid_request_ie(sdata, skb);
1097 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1100 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1101 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1103 /* add any remaining custom (i.e. vendor specific here) IEs */
1104 if (assoc_data->ie_len) {
1105 noffset = assoc_data->ie_len;
1106 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1109 if (assoc_data->fils_kek_len) {
1110 ret = fils_encrypt_assoc_req(skb, assoc_data);
1117 pos = skb_tail_pointer(skb);
1118 kfree(ifmgd->assoc_req_ies);
1119 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1120 if (!ifmgd->assoc_req_ies) {
1125 ifmgd->assoc_req_ies_len = pos - ie_start;
1127 drv_mgd_prepare_tx(local, sdata, &info);
1129 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1130 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1131 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1132 IEEE80211_TX_INTFL_MLME_CONN_TX;
1133 ieee80211_tx_skb(sdata, skb);
1138 void ieee80211_send_pspoll(struct ieee80211_local *local,
1139 struct ieee80211_sub_if_data *sdata)
1141 struct ieee80211_pspoll *pspoll;
1142 struct sk_buff *skb;
1144 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1148 pspoll = (struct ieee80211_pspoll *) skb->data;
1149 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1151 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1152 ieee80211_tx_skb(sdata, skb);
1155 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1156 struct ieee80211_sub_if_data *sdata,
1159 struct sk_buff *skb;
1160 struct ieee80211_hdr_3addr *nullfunc;
1161 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1163 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1164 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1168 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1170 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1172 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1173 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1175 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1176 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1178 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1179 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1181 ieee80211_tx_skb(sdata, skb);
1184 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1185 struct ieee80211_sub_if_data *sdata)
1187 struct sk_buff *skb;
1188 struct ieee80211_hdr *nullfunc;
1191 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1194 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1198 skb_reserve(skb, local->hw.extra_tx_headroom);
1200 nullfunc = skb_put_zero(skb, 30);
1201 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1202 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1203 nullfunc->frame_control = fc;
1204 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
1205 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1206 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
1207 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1209 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1210 ieee80211_tx_skb(sdata, skb);
1213 /* spectrum management related things */
1214 static void ieee80211_chswitch_work(struct work_struct *work)
1216 struct ieee80211_sub_if_data *sdata =
1217 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
1218 struct ieee80211_local *local = sdata->local;
1219 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1222 if (!ieee80211_sdata_running(sdata))
1226 mutex_lock(&local->mtx);
1227 mutex_lock(&local->chanctx_mtx);
1229 if (!ifmgd->associated)
1232 if (!sdata->vif.csa_active)
1236 * using reservation isn't immediate as it may be deferred until later
1237 * with multi-vif. once reservation is complete it will re-schedule the
1238 * work with no reserved_chanctx so verify chandef to check if it
1239 * completed successfully
1242 if (sdata->reserved_chanctx) {
1244 * with multi-vif csa driver may call ieee80211_csa_finish()
1245 * many times while waiting for other interfaces to use their
1248 if (sdata->reserved_ready)
1251 ret = ieee80211_vif_use_reserved_context(sdata);
1254 "failed to use reserved channel context, disconnecting (err=%d)\n",
1256 ieee80211_queue_work(&sdata->local->hw,
1257 &ifmgd->csa_connection_drop_work);
1264 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
1265 &sdata->csa_chandef)) {
1267 "failed to finalize channel switch, disconnecting\n");
1268 ieee80211_queue_work(&sdata->local->hw,
1269 &ifmgd->csa_connection_drop_work);
1273 ifmgd->csa_waiting_bcn = true;
1275 ieee80211_sta_reset_beacon_monitor(sdata);
1276 ieee80211_sta_reset_conn_monitor(sdata);
1279 mutex_unlock(&local->chanctx_mtx);
1280 mutex_unlock(&local->mtx);
1281 sdata_unlock(sdata);
1284 static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
1286 struct ieee80211_local *local = sdata->local;
1287 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1290 sdata_assert_lock(sdata);
1292 WARN_ON(!sdata->vif.csa_active);
1294 if (sdata->csa_block_tx) {
1295 ieee80211_wake_vif_queues(local, sdata,
1296 IEEE80211_QUEUE_STOP_REASON_CSA);
1297 sdata->csa_block_tx = false;
1300 sdata->vif.csa_active = false;
1301 ifmgd->csa_waiting_bcn = false;
1303 * If the CSA IE is still present on the beacon after the switch,
1304 * we need to consider it as a new CSA (possibly to self).
1306 ifmgd->beacon_crc_valid = false;
1308 ret = drv_post_channel_switch(sdata);
1311 "driver post channel switch failed, disconnecting\n");
1312 ieee80211_queue_work(&local->hw,
1313 &ifmgd->csa_connection_drop_work);
1317 cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
1320 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1322 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1323 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1325 trace_api_chswitch_done(sdata, success);
1328 "driver channel switch failed, disconnecting\n");
1329 ieee80211_queue_work(&sdata->local->hw,
1330 &ifmgd->csa_connection_drop_work);
1332 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1335 EXPORT_SYMBOL(ieee80211_chswitch_done);
1337 static void ieee80211_chswitch_timer(struct timer_list *t)
1339 struct ieee80211_sub_if_data *sdata =
1340 from_timer(sdata, t, u.mgd.chswitch_timer);
1342 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1346 ieee80211_sta_abort_chanswitch(struct ieee80211_sub_if_data *sdata)
1348 struct ieee80211_local *local = sdata->local;
1350 if (!local->ops->abort_channel_switch)
1353 mutex_lock(&local->mtx);
1355 mutex_lock(&local->chanctx_mtx);
1356 ieee80211_vif_unreserve_chanctx(sdata);
1357 mutex_unlock(&local->chanctx_mtx);
1359 if (sdata->csa_block_tx)
1360 ieee80211_wake_vif_queues(local, sdata,
1361 IEEE80211_QUEUE_STOP_REASON_CSA);
1363 sdata->csa_block_tx = false;
1364 sdata->vif.csa_active = false;
1366 mutex_unlock(&local->mtx);
1368 drv_abort_channel_switch(sdata);
1372 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1373 u64 timestamp, u32 device_timestamp,
1374 struct ieee802_11_elems *elems,
1377 struct ieee80211_local *local = sdata->local;
1378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1379 struct cfg80211_bss *cbss = ifmgd->associated;
1380 struct ieee80211_chanctx_conf *conf;
1381 struct ieee80211_chanctx *chanctx;
1382 enum nl80211_band current_band;
1383 struct ieee80211_csa_ie csa_ie;
1384 struct ieee80211_channel_switch ch_switch;
1385 struct ieee80211_bss *bss;
1388 sdata_assert_lock(sdata);
1393 if (local->scanning)
1396 current_band = cbss->channel->band;
1397 bss = (void *)cbss->priv;
1398 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1401 ifmgd->associated->bssid, &csa_ie);
1404 ch_switch.timestamp = timestamp;
1405 ch_switch.device_timestamp = device_timestamp;
1406 ch_switch.block_tx = csa_ie.mode;
1407 ch_switch.chandef = csa_ie.chandef;
1408 ch_switch.count = csa_ie.count;
1409 ch_switch.delay = csa_ie.max_switch_time;
1413 goto lock_and_drop_connection;
1415 if (beacon && sdata->vif.csa_active && !ifmgd->csa_waiting_bcn) {
1417 ieee80211_sta_abort_chanswitch(sdata);
1419 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1421 } else if (sdata->vif.csa_active || res) {
1422 /* disregard subsequent announcements if already processing */
1426 if (sdata->vif.bss_conf.chandef.chan->band !=
1427 csa_ie.chandef.chan->band) {
1429 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1430 ifmgd->associated->bssid,
1431 csa_ie.chandef.chan->center_freq,
1432 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1433 csa_ie.chandef.center_freq2);
1434 goto lock_and_drop_connection;
1437 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1438 IEEE80211_CHAN_DISABLED)) {
1440 "AP %pM switches to unsupported channel "
1441 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1443 ifmgd->associated->bssid,
1444 csa_ie.chandef.chan->center_freq,
1445 csa_ie.chandef.chan->freq_offset,
1446 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1447 csa_ie.chandef.freq1_offset,
1448 csa_ie.chandef.center_freq2);
1449 goto lock_and_drop_connection;
1452 if (cfg80211_chandef_identical(&csa_ie.chandef,
1453 &sdata->vif.bss_conf.chandef) &&
1454 (!csa_ie.mode || !beacon)) {
1455 if (ifmgd->csa_ignored_same_chan)
1458 "AP %pM tries to chanswitch to same channel, ignore\n",
1459 ifmgd->associated->bssid);
1460 ifmgd->csa_ignored_same_chan = true;
1465 * Drop all TDLS peers - either we disconnect or move to a different
1466 * channel from this point on. There's no telling what our peer will do.
1467 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1468 * have an incompatible wider chandef.
1470 ieee80211_teardown_tdls_peers(sdata);
1472 mutex_lock(&local->mtx);
1473 mutex_lock(&local->chanctx_mtx);
1474 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1475 lockdep_is_held(&local->chanctx_mtx));
1478 "no channel context assigned to vif?, disconnecting\n");
1479 goto drop_connection;
1482 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1484 if (local->use_chanctx &&
1485 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1487 "driver doesn't support chan-switch with channel contexts\n");
1488 goto drop_connection;
1491 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1493 "preparing for channel switch failed, disconnecting\n");
1494 goto drop_connection;
1497 res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
1498 chanctx->mode, false);
1501 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1503 goto drop_connection;
1505 mutex_unlock(&local->chanctx_mtx);
1507 sdata->vif.csa_active = true;
1508 sdata->csa_chandef = csa_ie.chandef;
1509 sdata->csa_block_tx = csa_ie.mode;
1510 ifmgd->csa_ignored_same_chan = false;
1511 ifmgd->beacon_crc_valid = false;
1513 if (sdata->csa_block_tx)
1514 ieee80211_stop_vif_queues(local, sdata,
1515 IEEE80211_QUEUE_STOP_REASON_CSA);
1516 mutex_unlock(&local->mtx);
1518 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1519 csa_ie.count, csa_ie.mode);
1521 if (local->ops->channel_switch) {
1522 /* use driver's channel switch callback */
1523 drv_channel_switch(local, sdata, &ch_switch);
1527 /* channel switch handled in software */
1528 if (csa_ie.count <= 1)
1529 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1531 mod_timer(&ifmgd->chswitch_timer,
1532 TU_TO_EXP_TIME((csa_ie.count - 1) *
1533 cbss->beacon_interval));
1535 lock_and_drop_connection:
1536 mutex_lock(&local->mtx);
1537 mutex_lock(&local->chanctx_mtx);
1540 * This is just so that the disconnect flow will know that
1541 * we were trying to switch channel and failed. In case the
1542 * mode is 1 (we are not allowed to Tx), we will know not to
1543 * send a deauthentication frame. Those two fields will be
1544 * reset when the disconnection worker runs.
1546 sdata->vif.csa_active = true;
1547 sdata->csa_block_tx = csa_ie.mode;
1549 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1550 mutex_unlock(&local->chanctx_mtx);
1551 mutex_unlock(&local->mtx);
1555 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1556 struct ieee80211_channel *channel,
1557 const u8 *country_ie, u8 country_ie_len,
1558 const u8 *pwr_constr_elem,
1559 int *chan_pwr, int *pwr_reduction)
1561 struct ieee80211_country_ie_triplet *triplet;
1562 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1563 int i, chan_increment;
1564 bool have_chan_pwr = false;
1567 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1570 triplet = (void *)(country_ie + 3);
1571 country_ie_len -= 3;
1573 switch (channel->band) {
1577 case NL80211_BAND_2GHZ:
1578 case NL80211_BAND_60GHZ:
1579 case NL80211_BAND_LC:
1582 case NL80211_BAND_5GHZ:
1585 case NL80211_BAND_6GHZ:
1587 * In the 6 GHz band, the "maximum transmit power level"
1588 * field in the triplets is reserved, and thus will be
1589 * zero and we shouldn't use it to control TX power.
1590 * The actual TX power will be given in the transmit
1591 * power envelope element instead.
1597 while (country_ie_len >= 3) {
1598 u8 first_channel = triplet->chans.first_channel;
1600 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1603 for (i = 0; i < triplet->chans.num_channels; i++) {
1604 if (first_channel + i * chan_increment == chan) {
1605 have_chan_pwr = true;
1606 *chan_pwr = triplet->chans.max_power;
1615 country_ie_len -= 3;
1618 if (have_chan_pwr && pwr_constr_elem)
1619 *pwr_reduction = *pwr_constr_elem;
1623 return have_chan_pwr;
1626 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1627 struct ieee80211_channel *channel,
1628 const u8 *cisco_dtpc_ie,
1631 /* From practical testing, the first data byte of the DTPC element
1632 * seems to contain the requested dBm level, and the CLI on Cisco
1633 * APs clearly state the range is -127 to 127 dBm, which indicates
1634 * a signed byte, although it seemingly never actually goes negative.
1635 * The other byte seems to always be zero.
1637 *pwr_level = (__s8)cisco_dtpc_ie[4];
1640 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1641 struct ieee80211_channel *channel,
1642 struct ieee80211_mgmt *mgmt,
1643 const u8 *country_ie, u8 country_ie_len,
1644 const u8 *pwr_constr_ie,
1645 const u8 *cisco_dtpc_ie)
1647 bool has_80211h_pwr = false, has_cisco_pwr = false;
1648 int chan_pwr = 0, pwr_reduction_80211h = 0;
1649 int pwr_level_cisco, pwr_level_80211h;
1651 __le16 capab = mgmt->u.probe_resp.capab_info;
1653 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1654 return 0; /* TODO */
1657 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1658 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1659 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1660 sdata, channel, country_ie, country_ie_len,
1661 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1663 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1666 if (cisco_dtpc_ie) {
1667 ieee80211_find_cisco_dtpc(
1668 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1669 has_cisco_pwr = true;
1672 if (!has_80211h_pwr && !has_cisco_pwr)
1675 /* If we have both 802.11h and Cisco DTPC, apply both limits
1676 * by picking the smallest of the two power levels advertised.
1678 if (has_80211h_pwr &&
1679 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1680 new_ap_level = pwr_level_80211h;
1682 if (sdata->ap_power_level == new_ap_level)
1686 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1687 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1688 sdata->u.mgd.bssid);
1689 } else { /* has_cisco_pwr is always true here. */
1690 new_ap_level = pwr_level_cisco;
1692 if (sdata->ap_power_level == new_ap_level)
1696 "Limiting TX power to %d dBm as advertised by %pM\n",
1697 pwr_level_cisco, sdata->u.mgd.bssid);
1700 sdata->ap_power_level = new_ap_level;
1701 if (__ieee80211_recalc_txpower(sdata))
1702 return BSS_CHANGED_TXPOWER;
1707 static void ieee80211_enable_ps(struct ieee80211_local *local,
1708 struct ieee80211_sub_if_data *sdata)
1710 struct ieee80211_conf *conf = &local->hw.conf;
1713 * If we are scanning right now then the parameters will
1714 * take effect when scan finishes.
1716 if (local->scanning)
1719 if (conf->dynamic_ps_timeout > 0 &&
1720 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1721 mod_timer(&local->dynamic_ps_timer, jiffies +
1722 msecs_to_jiffies(conf->dynamic_ps_timeout));
1724 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1725 ieee80211_send_nullfunc(local, sdata, true);
1727 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1728 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1731 conf->flags |= IEEE80211_CONF_PS;
1732 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1736 static void ieee80211_change_ps(struct ieee80211_local *local)
1738 struct ieee80211_conf *conf = &local->hw.conf;
1740 if (local->ps_sdata) {
1741 ieee80211_enable_ps(local, local->ps_sdata);
1742 } else if (conf->flags & IEEE80211_CONF_PS) {
1743 conf->flags &= ~IEEE80211_CONF_PS;
1744 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1745 del_timer_sync(&local->dynamic_ps_timer);
1746 cancel_work_sync(&local->dynamic_ps_enable_work);
1750 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1752 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1753 struct sta_info *sta = NULL;
1754 bool authorized = false;
1756 if (!mgd->powersave)
1762 if (!mgd->associated)
1765 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1768 if (!mgd->have_beacon)
1772 sta = sta_info_get(sdata, mgd->bssid);
1774 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1780 /* need to hold RTNL or interface lock */
1781 void ieee80211_recalc_ps(struct ieee80211_local *local)
1783 struct ieee80211_sub_if_data *sdata, *found = NULL;
1787 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
1788 local->ps_sdata = NULL;
1792 list_for_each_entry(sdata, &local->interfaces, list) {
1793 if (!ieee80211_sdata_running(sdata))
1795 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1796 /* If an AP vif is found, then disable PS
1797 * by setting the count to zero thereby setting
1803 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1809 if (count == 1 && ieee80211_powersave_allowed(found)) {
1810 u8 dtimper = found->u.mgd.dtim_period;
1812 timeout = local->dynamic_ps_forced_timeout;
1815 local->hw.conf.dynamic_ps_timeout = timeout;
1817 /* If the TIM IE is invalid, pretend the value is 1 */
1821 local->hw.conf.ps_dtim_period = dtimper;
1822 local->ps_sdata = found;
1824 local->ps_sdata = NULL;
1827 ieee80211_change_ps(local);
1830 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1832 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1834 if (sdata->vif.bss_conf.ps != ps_allowed) {
1835 sdata->vif.bss_conf.ps = ps_allowed;
1836 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
1840 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1842 struct ieee80211_local *local =
1843 container_of(work, struct ieee80211_local,
1844 dynamic_ps_disable_work);
1846 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1847 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1848 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1851 ieee80211_wake_queues_by_reason(&local->hw,
1852 IEEE80211_MAX_QUEUE_MAP,
1853 IEEE80211_QUEUE_STOP_REASON_PS,
1857 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1859 struct ieee80211_local *local =
1860 container_of(work, struct ieee80211_local,
1861 dynamic_ps_enable_work);
1862 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1863 struct ieee80211_if_managed *ifmgd;
1864 unsigned long flags;
1867 /* can only happen when PS was just disabled anyway */
1871 ifmgd = &sdata->u.mgd;
1873 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1876 if (local->hw.conf.dynamic_ps_timeout > 0) {
1877 /* don't enter PS if TX frames are pending */
1878 if (drv_tx_frames_pending(local)) {
1879 mod_timer(&local->dynamic_ps_timer, jiffies +
1881 local->hw.conf.dynamic_ps_timeout));
1886 * transmission can be stopped by others which leads to
1887 * dynamic_ps_timer expiry. Postpone the ps timer if it
1888 * is not the actual idle state.
1890 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1891 for (q = 0; q < local->hw.queues; q++) {
1892 if (local->queue_stop_reasons[q]) {
1893 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1895 mod_timer(&local->dynamic_ps_timer, jiffies +
1897 local->hw.conf.dynamic_ps_timeout));
1901 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1904 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1905 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1906 if (drv_tx_frames_pending(local)) {
1907 mod_timer(&local->dynamic_ps_timer, jiffies +
1909 local->hw.conf.dynamic_ps_timeout));
1911 ieee80211_send_nullfunc(local, sdata, true);
1912 /* Flush to get the tx status of nullfunc frame */
1913 ieee80211_flush_queues(local, sdata, false);
1917 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1918 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1919 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1920 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1921 local->hw.conf.flags |= IEEE80211_CONF_PS;
1922 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1926 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1928 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1930 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1933 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1935 struct delayed_work *delayed_work = to_delayed_work(work);
1936 struct ieee80211_sub_if_data *sdata =
1937 container_of(delayed_work, struct ieee80211_sub_if_data,
1938 dfs_cac_timer_work);
1939 struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
1941 mutex_lock(&sdata->local->mtx);
1942 if (sdata->wdev.cac_started) {
1943 ieee80211_vif_release_channel(sdata);
1944 cfg80211_cac_event(sdata->dev, &chandef,
1945 NL80211_RADAR_CAC_FINISHED,
1948 mutex_unlock(&sdata->local->mtx);
1952 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
1954 struct ieee80211_local *local = sdata->local;
1955 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1959 if (local->hw.queues < IEEE80211_NUM_ACS)
1962 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1963 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
1965 unsigned long now = jiffies;
1967 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
1968 tx_tspec->admitted_time &&
1969 time_after(now, tx_tspec->time_slice_start + HZ)) {
1970 tx_tspec->consumed_tx_time = 0;
1971 tx_tspec->time_slice_start = now;
1973 if (tx_tspec->downgraded)
1975 TX_TSPEC_ACTION_STOP_DOWNGRADE;
1978 switch (tx_tspec->action) {
1979 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
1980 /* take the original parameters */
1981 if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
1983 "failed to set TX queue parameters for queue %d\n",
1985 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1986 tx_tspec->downgraded = false;
1989 case TX_TSPEC_ACTION_DOWNGRADE:
1990 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
1991 tx_tspec->action = TX_TSPEC_ACTION_NONE;
1995 /* downgrade next lower non-ACM AC */
1996 for (non_acm_ac = ac + 1;
1997 non_acm_ac < IEEE80211_NUM_ACS;
1999 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2001 /* Usually the loop will result in using BK even if it
2002 * requires admission control, but such a configuration
2003 * makes no sense and we have to transmit somehow - the
2004 * AC selection does the same thing.
2005 * If we started out trying to downgrade from BK, then
2006 * the extra condition here might be needed.
2008 if (non_acm_ac >= IEEE80211_NUM_ACS)
2009 non_acm_ac = IEEE80211_AC_BK;
2010 if (drv_conf_tx(local, sdata, ac,
2011 &sdata->tx_conf[non_acm_ac]))
2013 "failed to set TX queue parameters for queue %d\n",
2015 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2017 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2018 tx_tspec->time_slice_start + HZ - now + 1);
2020 case TX_TSPEC_ACTION_NONE:
2029 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2031 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2032 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2035 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2037 struct ieee80211_sub_if_data *sdata;
2039 sdata = container_of(work, struct ieee80211_sub_if_data,
2040 u.mgd.tx_tspec_wk.work);
2041 ieee80211_sta_handle_tspec_ac_params(sdata);
2046 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2047 struct ieee80211_sub_if_data *sdata,
2048 const u8 *wmm_param, size_t wmm_param_len,
2049 const struct ieee80211_mu_edca_param_set *mu_edca)
2051 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2054 int count, mu_edca_count, ac;
2056 u8 uapsd_queues = 0;
2058 if (!local->ops->conf_tx)
2061 if (local->hw.queues < IEEE80211_NUM_ACS)
2067 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2070 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2071 uapsd_queues = ifmgd->uapsd_queues;
2073 count = wmm_param[6] & 0x0f;
2074 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2075 * if mu_edca was preset before and now it disappeared tell
2076 * the driver about it.
2078 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2079 if (count == ifmgd->wmm_last_param_set &&
2080 mu_edca_count == ifmgd->mu_edca_last_param_set)
2082 ifmgd->wmm_last_param_set = count;
2083 ifmgd->mu_edca_last_param_set = mu_edca_count;
2085 pos = wmm_param + 8;
2086 left = wmm_param_len - 8;
2088 memset(¶ms, 0, sizeof(params));
2091 for (; left >= 4; left -= 4, pos += 4) {
2092 int aci = (pos[0] >> 5) & 0x03;
2093 int acm = (pos[0] >> 4) & 0x01;
2098 ac = IEEE80211_AC_BK;
2100 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2101 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2103 params[ac].mu_edca = !!mu_edca;
2105 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2108 ac = IEEE80211_AC_VI;
2110 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2111 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2113 params[ac].mu_edca = !!mu_edca;
2115 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2118 ac = IEEE80211_AC_VO;
2120 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2121 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2123 params[ac].mu_edca = !!mu_edca;
2125 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2129 ac = IEEE80211_AC_BE;
2131 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2132 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2134 params[ac].mu_edca = !!mu_edca;
2136 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2140 params[ac].aifs = pos[0] & 0x0f;
2142 if (params[ac].aifs < 2) {
2144 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2145 params[ac].aifs, aci);
2146 params[ac].aifs = 2;
2148 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2149 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2150 params[ac].txop = get_unaligned_le16(pos + 2);
2151 params[ac].acm = acm;
2152 params[ac].uapsd = uapsd;
2154 if (params[ac].cw_min == 0 ||
2155 params[ac].cw_min > params[ac].cw_max) {
2157 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2158 params[ac].cw_min, params[ac].cw_max, aci);
2161 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2164 /* WMM specification requires all 4 ACIs. */
2165 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2166 if (params[ac].cw_min == 0) {
2168 "AP has invalid WMM params (missing AC %d), using defaults\n",
2174 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2176 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2178 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2179 params[ac].txop, params[ac].uapsd,
2180 ifmgd->tx_tspec[ac].downgraded);
2181 sdata->tx_conf[ac] = params[ac];
2182 if (!ifmgd->tx_tspec[ac].downgraded &&
2183 drv_conf_tx(local, sdata, ac, ¶ms[ac]))
2185 "failed to set TX queue parameters for AC %d\n",
2189 /* enable WMM or activate new settings */
2190 sdata->vif.bss_conf.qos = true;
2194 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2196 lockdep_assert_held(&sdata->local->mtx);
2198 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2199 ieee80211_run_deferred_scan(sdata->local);
2202 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2204 mutex_lock(&sdata->local->mtx);
2205 __ieee80211_stop_poll(sdata);
2206 mutex_unlock(&sdata->local->mtx);
2209 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
2210 u16 capab, bool erp_valid, u8 erp)
2212 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2213 struct ieee80211_supported_band *sband;
2215 bool use_protection;
2216 bool use_short_preamble;
2217 bool use_short_slot;
2219 sband = ieee80211_get_sband(sdata);
2224 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2225 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2227 use_protection = false;
2228 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2231 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2232 if (sband->band == NL80211_BAND_5GHZ ||
2233 sband->band == NL80211_BAND_6GHZ)
2234 use_short_slot = true;
2236 if (use_protection != bss_conf->use_cts_prot) {
2237 bss_conf->use_cts_prot = use_protection;
2238 changed |= BSS_CHANGED_ERP_CTS_PROT;
2241 if (use_short_preamble != bss_conf->use_short_preamble) {
2242 bss_conf->use_short_preamble = use_short_preamble;
2243 changed |= BSS_CHANGED_ERP_PREAMBLE;
2246 if (use_short_slot != bss_conf->use_short_slot) {
2247 bss_conf->use_short_slot = use_short_slot;
2248 changed |= BSS_CHANGED_ERP_SLOT;
2254 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2255 struct cfg80211_bss *cbss,
2256 u32 bss_info_changed)
2258 struct ieee80211_bss *bss = (void *)cbss->priv;
2259 struct ieee80211_local *local = sdata->local;
2260 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2262 bss_info_changed |= BSS_CHANGED_ASSOC;
2263 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
2264 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2266 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2267 beacon_loss_count * bss_conf->beacon_int));
2269 sdata->u.mgd.associated = cbss;
2270 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2272 ieee80211_check_rate_mask(sdata);
2274 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
2276 if (sdata->vif.p2p ||
2277 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2278 const struct cfg80211_bss_ies *ies;
2281 ies = rcu_dereference(cbss->ies);
2285 ret = cfg80211_get_p2p_attr(
2286 ies->data, ies->len,
2287 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2288 (u8 *) &bss_conf->p2p_noa_attr,
2289 sizeof(bss_conf->p2p_noa_attr));
2291 sdata->u.mgd.p2p_noa_index =
2292 bss_conf->p2p_noa_attr.index;
2293 bss_info_changed |= BSS_CHANGED_P2P_PS;
2299 /* just to be sure */
2300 ieee80211_stop_poll(sdata);
2302 ieee80211_led_assoc(local, 1);
2304 if (sdata->u.mgd.have_beacon) {
2306 * If the AP is buggy we may get here with no DTIM period
2307 * known, so assume it's 1 which is the only safe assumption
2308 * in that case, although if the TIM IE is broken powersave
2309 * probably just won't work at all.
2311 bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
2312 bss_conf->beacon_rate = bss->beacon_rate;
2313 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2315 bss_conf->beacon_rate = NULL;
2316 bss_conf->dtim_period = 0;
2319 bss_conf->assoc = 1;
2321 /* Tell the driver to monitor connection quality (if supported) */
2322 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2323 bss_conf->cqm_rssi_thold)
2324 bss_info_changed |= BSS_CHANGED_CQM;
2326 /* Enable ARP filtering */
2327 if (bss_conf->arp_addr_cnt)
2328 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2330 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2332 mutex_lock(&local->iflist_mtx);
2333 ieee80211_recalc_ps(local);
2334 mutex_unlock(&local->iflist_mtx);
2336 ieee80211_recalc_smps(sdata);
2337 ieee80211_recalc_ps_vif(sdata);
2339 netif_carrier_on(sdata->dev);
2342 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2343 u16 stype, u16 reason, bool tx,
2346 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2347 struct ieee80211_local *local = sdata->local;
2348 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2350 struct ieee80211_prep_tx_info info = {
2354 sdata_assert_lock(sdata);
2356 if (WARN_ON_ONCE(tx && !frame_buf))
2359 if (WARN_ON(!ifmgd->associated))
2362 ieee80211_stop_poll(sdata);
2364 ifmgd->associated = NULL;
2365 netif_carrier_off(sdata->dev);
2368 * if we want to get out of ps before disassoc (why?) we have
2369 * to do it before sending disassoc, as otherwise the null-packet
2372 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2373 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2374 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2376 local->ps_sdata = NULL;
2378 /* disable per-vif ps */
2379 ieee80211_recalc_ps_vif(sdata);
2381 /* make sure ongoing transmission finishes */
2385 * drop any frame before deauth/disassoc, this can be data or
2386 * management frame. Since we are disconnecting, we should not
2387 * insist sending these frames which can take time and delay
2388 * the disconnection and possible the roaming.
2391 ieee80211_flush_queues(local, sdata, true);
2393 /* deauthenticate/disassociate now */
2394 if (tx || frame_buf) {
2396 * In multi channel scenarios guarantee that the virtual
2397 * interface is granted immediate airtime to transmit the
2398 * deauthentication frame by calling mgd_prepare_tx, if the
2399 * driver requested so.
2401 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2402 !ifmgd->have_beacon) {
2403 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2406 ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid,
2407 ifmgd->bssid, stype, reason,
2411 /* flush out frame - make sure the deauth was actually sent */
2413 ieee80211_flush_queues(local, sdata, false);
2415 drv_mgd_complete_tx(sdata->local, sdata, &info);
2417 /* clear bssid only after building the needed mgmt frames */
2418 eth_zero_addr(ifmgd->bssid);
2420 sdata->vif.bss_conf.ssid_len = 0;
2422 /* remove AP and TDLS peers */
2423 sta_info_flush(sdata);
2425 /* finally reset all BSS / config parameters */
2426 changed |= ieee80211_reset_erp_info(sdata);
2428 ieee80211_led_assoc(local, 0);
2429 changed |= BSS_CHANGED_ASSOC;
2430 sdata->vif.bss_conf.assoc = false;
2432 ifmgd->p2p_noa_index = -1;
2433 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2434 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2436 /* on the next assoc, re-program HT/VHT parameters */
2437 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2438 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2439 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2440 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2442 /* reset MU-MIMO ownership and group data */
2443 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2444 sizeof(sdata->vif.bss_conf.mu_group.membership));
2445 memset(sdata->vif.bss_conf.mu_group.position, 0,
2446 sizeof(sdata->vif.bss_conf.mu_group.position));
2447 changed |= BSS_CHANGED_MU_GROUPS;
2448 sdata->vif.mu_mimo_owner = false;
2450 sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2452 del_timer_sync(&local->dynamic_ps_timer);
2453 cancel_work_sync(&local->dynamic_ps_enable_work);
2455 /* Disable ARP filtering */
2456 if (sdata->vif.bss_conf.arp_addr_cnt)
2457 changed |= BSS_CHANGED_ARP_FILTER;
2459 sdata->vif.bss_conf.qos = false;
2460 changed |= BSS_CHANGED_QOS;
2462 /* The BSSID (not really interesting) and HT changed */
2463 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2464 ieee80211_bss_info_change_notify(sdata, changed);
2466 /* disassociated - set to defaults now */
2467 ieee80211_set_wmm_default(sdata, false, false);
2469 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2470 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2471 del_timer_sync(&sdata->u.mgd.timer);
2472 del_timer_sync(&sdata->u.mgd.chswitch_timer);
2474 sdata->vif.bss_conf.dtim_period = 0;
2475 sdata->vif.bss_conf.beacon_rate = NULL;
2477 ifmgd->have_beacon = false;
2480 mutex_lock(&local->mtx);
2481 ieee80211_vif_release_channel(sdata);
2483 sdata->vif.csa_active = false;
2484 ifmgd->csa_waiting_bcn = false;
2485 ifmgd->csa_ignored_same_chan = false;
2486 if (sdata->csa_block_tx) {
2487 ieee80211_wake_vif_queues(local, sdata,
2488 IEEE80211_QUEUE_STOP_REASON_CSA);
2489 sdata->csa_block_tx = false;
2491 mutex_unlock(&local->mtx);
2493 /* existing TX TSPEC sessions no longer exist */
2494 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2495 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2497 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
2499 bss_conf->pwr_reduction = 0;
2500 bss_conf->tx_pwr_env_num = 0;
2501 memset(bss_conf->tx_pwr_env, 0, sizeof(bss_conf->tx_pwr_env));
2504 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2506 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2507 struct ieee80211_local *local = sdata->local;
2509 mutex_lock(&local->mtx);
2510 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2513 __ieee80211_stop_poll(sdata);
2515 mutex_lock(&local->iflist_mtx);
2516 ieee80211_recalc_ps(local);
2517 mutex_unlock(&local->iflist_mtx);
2519 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2523 * We've received a probe response, but are not sure whether
2524 * we have or will be receiving any beacons or data, so let's
2525 * schedule the timers again, just in case.
2527 ieee80211_sta_reset_beacon_monitor(sdata);
2529 mod_timer(&ifmgd->conn_mon_timer,
2530 round_jiffies_up(jiffies +
2531 IEEE80211_CONNECTION_IDLE_TIME));
2533 mutex_unlock(&local->mtx);
2536 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2537 struct ieee80211_hdr *hdr,
2540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2543 struct ieee80211_sta_tx_tspec *tx_tspec;
2544 unsigned long now = jiffies;
2546 if (!ieee80211_is_data_qos(hdr->frame_control))
2549 tid = ieee80211_get_tid(hdr);
2550 ac = ieee80211_ac_from_tid(tid);
2551 tx_tspec = &ifmgd->tx_tspec[ac];
2553 if (likely(!tx_tspec->admitted_time))
2556 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2557 tx_tspec->consumed_tx_time = 0;
2558 tx_tspec->time_slice_start = now;
2560 if (tx_tspec->downgraded) {
2561 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2562 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2566 if (tx_tspec->downgraded)
2569 tx_tspec->consumed_tx_time += tx_time;
2571 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2572 tx_tspec->downgraded = true;
2573 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2574 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2578 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2579 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2581 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2583 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2584 !sdata->u.mgd.probe_send_count)
2588 sdata->u.mgd.probe_send_count = 0;
2590 sdata->u.mgd.nullfunc_failed = true;
2591 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2594 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2595 const u8 *src, const u8 *dst,
2596 const u8 *ssid, size_t ssid_len,
2597 struct ieee80211_channel *channel)
2599 struct sk_buff *skb;
2601 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2602 ssid, ssid_len, NULL, 0,
2603 IEEE80211_PROBE_FLAG_DIRECTED);
2605 ieee80211_tx_skb(sdata, skb);
2608 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2610 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2611 const struct element *ssid;
2612 u8 *dst = ifmgd->associated->bssid;
2613 u8 unicast_limit = max(1, max_probe_tries - 3);
2614 struct sta_info *sta;
2617 * Try sending broadcast probe requests for the last three
2618 * probe requests after the first ones failed since some
2619 * buggy APs only support broadcast probe requests.
2621 if (ifmgd->probe_send_count >= unicast_limit)
2625 * When the hardware reports an accurate Tx ACK status, it's
2626 * better to send a nullfunc frame instead of a probe request,
2627 * as it will kick us off the AP quickly if we aren't associated
2628 * anymore. The timeout will be reset if the frame is ACKed by
2631 ifmgd->probe_send_count++;
2634 mutex_lock(&sdata->local->sta_mtx);
2635 sta = sta_info_get(sdata, dst);
2637 ieee80211_check_fast_rx(sta);
2638 mutex_unlock(&sdata->local->sta_mtx);
2641 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2642 ifmgd->nullfunc_failed = false;
2643 ieee80211_send_nullfunc(sdata->local, sdata, false);
2648 ssid = ieee80211_bss_get_elem(ifmgd->associated, WLAN_EID_SSID);
2649 if (WARN_ON_ONCE(ssid == NULL))
2652 ssid_len = ssid->datalen;
2654 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2655 ssid->data, ssid_len,
2656 ifmgd->associated->channel);
2660 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2661 run_again(sdata, ifmgd->probe_timeout);
2664 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2667 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2668 bool already = false;
2670 if (!ieee80211_sdata_running(sdata))
2675 if (!ifmgd->associated)
2678 mutex_lock(&sdata->local->mtx);
2680 if (sdata->local->tmp_channel || sdata->local->scanning) {
2681 mutex_unlock(&sdata->local->mtx);
2685 if (sdata->local->suspending) {
2686 /* reschedule after resume */
2687 mutex_unlock(&sdata->local->mtx);
2688 ieee80211_reset_ap_probe(sdata);
2693 mlme_dbg_ratelimited(sdata,
2694 "detected beacon loss from AP (missed %d beacons) - probing\n",
2697 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2701 * The driver/our work has already reported this event or the
2702 * connection monitoring has kicked in and we have already sent
2703 * a probe request. Or maybe the AP died and the driver keeps
2704 * reporting until we disassociate...
2706 * In either case we have to ignore the current call to this
2707 * function (except for setting the correct probe reason bit)
2708 * because otherwise we would reset the timer every time and
2709 * never check whether we received a probe response!
2711 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2714 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2716 mutex_unlock(&sdata->local->mtx);
2721 mutex_lock(&sdata->local->iflist_mtx);
2722 ieee80211_recalc_ps(sdata->local);
2723 mutex_unlock(&sdata->local->iflist_mtx);
2725 ifmgd->probe_send_count = 0;
2726 ieee80211_mgd_probe_ap_send(sdata);
2728 sdata_unlock(sdata);
2731 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2732 struct ieee80211_vif *vif)
2734 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2735 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2736 struct cfg80211_bss *cbss;
2737 struct sk_buff *skb;
2738 const struct element *ssid;
2741 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2744 sdata_assert_lock(sdata);
2746 if (ifmgd->associated)
2747 cbss = ifmgd->associated;
2748 else if (ifmgd->auth_data)
2749 cbss = ifmgd->auth_data->bss;
2750 else if (ifmgd->assoc_data)
2751 cbss = ifmgd->assoc_data->bss;
2756 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
2757 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
2758 "invalid SSID element (len=%d)",
2759 ssid ? ssid->datalen : -1))
2762 ssid_len = ssid->datalen;
2764 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2765 (u32) -1, cbss->channel,
2766 ssid->data, ssid_len,
2767 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2772 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2774 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2775 const u8 *buf, size_t len, bool tx,
2776 u16 reason, bool reconnect)
2778 struct ieee80211_event event = {
2780 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2781 .u.mlme.reason = reason,
2785 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2787 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2789 drv_event_callback(sdata->local, sdata, &event);
2792 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2794 struct ieee80211_local *local = sdata->local;
2795 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2796 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2800 if (!ifmgd->associated) {
2801 sdata_unlock(sdata);
2805 tx = !sdata->csa_block_tx;
2807 if (!ifmgd->driver_disconnect) {
2809 * AP is probably out of range (or not reachable for another
2810 * reason) so remove the bss struct for that AP.
2812 cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
2815 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2816 ifmgd->driver_disconnect ?
2817 WLAN_REASON_DEAUTH_LEAVING :
2818 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2820 mutex_lock(&local->mtx);
2821 sdata->vif.csa_active = false;
2822 ifmgd->csa_waiting_bcn = false;
2823 if (sdata->csa_block_tx) {
2824 ieee80211_wake_vif_queues(local, sdata,
2825 IEEE80211_QUEUE_STOP_REASON_CSA);
2826 sdata->csa_block_tx = false;
2828 mutex_unlock(&local->mtx);
2830 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2831 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2833 ifmgd->reconnect = false;
2835 sdata_unlock(sdata);
2838 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2840 struct ieee80211_sub_if_data *sdata =
2841 container_of(work, struct ieee80211_sub_if_data,
2842 u.mgd.beacon_connection_loss_work);
2843 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2845 if (ifmgd->associated)
2846 ifmgd->beacon_loss_count++;
2848 if (ifmgd->connection_loss) {
2849 sdata_info(sdata, "Connection to AP %pM lost\n",
2851 __ieee80211_disconnect(sdata);
2852 ifmgd->connection_loss = false;
2853 } else if (ifmgd->driver_disconnect) {
2855 "Driver requested disconnection from AP %pM\n",
2857 __ieee80211_disconnect(sdata);
2858 ifmgd->driver_disconnect = false;
2860 ieee80211_mgd_probe_ap(sdata, true);
2864 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2866 struct ieee80211_sub_if_data *sdata =
2867 container_of(work, struct ieee80211_sub_if_data,
2868 u.mgd.csa_connection_drop_work);
2870 __ieee80211_disconnect(sdata);
2873 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2875 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2876 struct ieee80211_hw *hw = &sdata->local->hw;
2878 trace_api_beacon_loss(sdata);
2880 sdata->u.mgd.connection_loss = false;
2881 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2883 EXPORT_SYMBOL(ieee80211_beacon_loss);
2885 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2887 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2888 struct ieee80211_hw *hw = &sdata->local->hw;
2890 trace_api_connection_loss(sdata);
2892 sdata->u.mgd.connection_loss = true;
2893 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2895 EXPORT_SYMBOL(ieee80211_connection_loss);
2897 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2899 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2900 struct ieee80211_hw *hw = &sdata->local->hw;
2902 trace_api_disconnect(sdata, reconnect);
2904 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2907 sdata->u.mgd.driver_disconnect = true;
2908 sdata->u.mgd.reconnect = reconnect;
2909 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2911 EXPORT_SYMBOL(ieee80211_disconnect);
2913 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2916 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2918 sdata_assert_lock(sdata);
2922 * we are not authenticated yet, the only timer that could be
2923 * running is the timeout for the authentication response which
2924 * which is not relevant anymore.
2926 del_timer_sync(&sdata->u.mgd.timer);
2927 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2929 eth_zero_addr(sdata->u.mgd.bssid);
2930 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2931 sdata->u.mgd.flags = 0;
2932 mutex_lock(&sdata->local->mtx);
2933 ieee80211_vif_release_channel(sdata);
2934 mutex_unlock(&sdata->local->mtx);
2937 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2939 sdata->u.mgd.auth_data = NULL;
2942 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
2943 bool assoc, bool abandon)
2945 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
2947 sdata_assert_lock(sdata);
2951 * we are not associated yet, the only timer that could be
2952 * running is the timeout for the association response which
2953 * which is not relevant anymore.
2955 del_timer_sync(&sdata->u.mgd.timer);
2956 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
2958 eth_zero_addr(sdata->u.mgd.bssid);
2959 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2960 sdata->u.mgd.flags = 0;
2961 sdata->vif.mu_mimo_owner = false;
2963 mutex_lock(&sdata->local->mtx);
2964 ieee80211_vif_release_channel(sdata);
2965 mutex_unlock(&sdata->local->mtx);
2968 cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
2972 sdata->u.mgd.assoc_data = NULL;
2975 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
2976 struct ieee80211_mgmt *mgmt, size_t len)
2978 struct ieee80211_local *local = sdata->local;
2979 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2980 const struct element *challenge;
2983 struct ieee80211_prep_tx_info info = {
2984 .subtype = IEEE80211_STYPE_AUTH,
2987 pos = mgmt->u.auth.variable;
2988 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
2989 len - (pos - (u8 *)mgmt));
2992 auth_data->expected_transaction = 4;
2993 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2994 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2995 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
2996 IEEE80211_TX_INTFL_MLME_CONN_TX;
2997 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
2999 challenge->datalen + sizeof(*challenge),
3000 auth_data->bss->bssid, auth_data->bss->bssid,
3001 auth_data->key, auth_data->key_len,
3002 auth_data->key_idx, tx_flags);
3005 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
3008 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3009 struct sta_info *sta;
3012 sdata_info(sdata, "authenticated\n");
3013 ifmgd->auth_data->done = true;
3014 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3015 ifmgd->auth_data->timeout_started = true;
3016 run_again(sdata, ifmgd->auth_data->timeout);
3018 /* move station state to auth */
3019 mutex_lock(&sdata->local->sta_mtx);
3020 sta = sta_info_get(sdata, bssid);
3022 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
3026 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3027 sdata_info(sdata, "failed moving %pM to auth\n", bssid);
3033 mutex_unlock(&sdata->local->sta_mtx);
3037 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3038 struct ieee80211_mgmt *mgmt, size_t len)
3040 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3042 u16 auth_alg, auth_transaction, status_code;
3043 struct ieee80211_event event = {
3045 .u.mlme.data = AUTH_EVENT,
3047 struct ieee80211_prep_tx_info info = {
3048 .subtype = IEEE80211_STYPE_AUTH,
3051 sdata_assert_lock(sdata);
3056 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3059 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3061 if (!ether_addr_equal(bssid, mgmt->bssid))
3064 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3065 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3066 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3068 if (auth_alg != ifmgd->auth_data->algorithm ||
3069 (auth_alg != WLAN_AUTH_SAE &&
3070 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3071 (auth_alg == WLAN_AUTH_SAE &&
3072 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3073 auth_transaction > 2))) {
3074 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3075 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3077 ifmgd->auth_data->expected_transaction);
3081 if (status_code != WLAN_STATUS_SUCCESS) {
3082 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3084 if (auth_alg == WLAN_AUTH_SAE &&
3085 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3086 (auth_transaction == 1 &&
3087 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3088 status_code == WLAN_STATUS_SAE_PK)))) {
3089 /* waiting for userspace now */
3090 ifmgd->auth_data->waiting = true;
3091 ifmgd->auth_data->timeout =
3092 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3093 ifmgd->auth_data->timeout_started = true;
3094 run_again(sdata, ifmgd->auth_data->timeout);
3098 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3099 mgmt->sa, status_code);
3100 ieee80211_destroy_auth_data(sdata, false);
3101 event.u.mlme.status = MLME_DENIED;
3102 event.u.mlme.reason = status_code;
3103 drv_event_callback(sdata->local, sdata, &event);
3107 switch (ifmgd->auth_data->algorithm) {
3108 case WLAN_AUTH_OPEN:
3109 case WLAN_AUTH_LEAP:
3112 case WLAN_AUTH_FILS_SK:
3113 case WLAN_AUTH_FILS_SK_PFS:
3114 case WLAN_AUTH_FILS_PK:
3116 case WLAN_AUTH_SHARED_KEY:
3117 if (ifmgd->auth_data->expected_transaction != 4) {
3118 ieee80211_auth_challenge(sdata, mgmt, len);
3119 /* need another frame */
3124 WARN_ONCE(1, "invalid auth alg %d",
3125 ifmgd->auth_data->algorithm);
3129 event.u.mlme.status = MLME_SUCCESS;
3131 drv_event_callback(sdata->local, sdata, &event);
3132 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3133 (auth_transaction == 2 &&
3134 ifmgd->auth_data->expected_transaction == 2)) {
3135 if (!ieee80211_mark_sta_auth(sdata, bssid))
3136 return; /* ignore frame -- wait for timeout */
3137 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3138 auth_transaction == 2) {
3139 sdata_info(sdata, "SAE peer confirmed\n");
3140 ifmgd->auth_data->peer_confirmed = true;
3143 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3145 drv_mgd_complete_tx(sdata->local, sdata, &info);
3148 #define case_WLAN(type) \
3149 case WLAN_REASON_##type: return #type
3151 const char *ieee80211_get_reason_code_string(u16 reason_code)
3153 switch (reason_code) {
3154 case_WLAN(UNSPECIFIED);
3155 case_WLAN(PREV_AUTH_NOT_VALID);
3156 case_WLAN(DEAUTH_LEAVING);
3157 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3158 case_WLAN(DISASSOC_AP_BUSY);
3159 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3160 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3161 case_WLAN(DISASSOC_STA_HAS_LEFT);
3162 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3163 case_WLAN(DISASSOC_BAD_POWER);
3164 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3165 case_WLAN(INVALID_IE);
3166 case_WLAN(MIC_FAILURE);
3167 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3168 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3169 case_WLAN(IE_DIFFERENT);
3170 case_WLAN(INVALID_GROUP_CIPHER);
3171 case_WLAN(INVALID_PAIRWISE_CIPHER);
3172 case_WLAN(INVALID_AKMP);
3173 case_WLAN(UNSUPP_RSN_VERSION);
3174 case_WLAN(INVALID_RSN_IE_CAP);
3175 case_WLAN(IEEE8021X_FAILED);
3176 case_WLAN(CIPHER_SUITE_REJECTED);
3177 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3178 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3179 case_WLAN(DISASSOC_LOW_ACK);
3180 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3181 case_WLAN(QSTA_LEAVE_QBSS);
3182 case_WLAN(QSTA_NOT_USE);
3183 case_WLAN(QSTA_REQUIRE_SETUP);
3184 case_WLAN(QSTA_TIMEOUT);
3185 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3186 case_WLAN(MESH_PEER_CANCELED);
3187 case_WLAN(MESH_MAX_PEERS);
3188 case_WLAN(MESH_CONFIG);
3189 case_WLAN(MESH_CLOSE);
3190 case_WLAN(MESH_MAX_RETRIES);
3191 case_WLAN(MESH_CONFIRM_TIMEOUT);
3192 case_WLAN(MESH_INVALID_GTK);
3193 case_WLAN(MESH_INCONSISTENT_PARAM);
3194 case_WLAN(MESH_INVALID_SECURITY);
3195 case_WLAN(MESH_PATH_ERROR);
3196 case_WLAN(MESH_PATH_NOFORWARD);
3197 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3198 case_WLAN(MAC_EXISTS_IN_MBSS);
3199 case_WLAN(MESH_CHAN_REGULATORY);
3200 case_WLAN(MESH_CHAN);
3201 default: return "<unknown>";
3205 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3206 struct ieee80211_mgmt *mgmt, size_t len)
3208 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3209 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3211 sdata_assert_lock(sdata);
3216 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3217 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3221 if (ifmgd->associated &&
3222 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
3223 const u8 *bssid = ifmgd->associated->bssid;
3225 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3227 ieee80211_get_reason_code_string(reason_code));
3229 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3231 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3232 reason_code, false);
3236 if (ifmgd->assoc_data &&
3237 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3238 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3241 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3243 ieee80211_get_reason_code_string(reason_code));
3245 ieee80211_destroy_assoc_data(sdata, false, true);
3247 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3253 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3254 struct ieee80211_mgmt *mgmt, size_t len)
3256 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3259 sdata_assert_lock(sdata);
3264 if (!ifmgd->associated ||
3265 !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3268 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3270 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3271 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3275 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3276 mgmt->sa, reason_code,
3277 ieee80211_get_reason_code_string(reason_code));
3279 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3281 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3285 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3286 u8 *supp_rates, unsigned int supp_rates_len,
3287 u32 *rates, u32 *basic_rates,
3288 bool *have_higher_than_11mbit,
3289 int *min_rate, int *min_rate_index,
3294 for (i = 0; i < supp_rates_len; i++) {
3295 int rate = supp_rates[i] & 0x7f;
3296 bool is_basic = !!(supp_rates[i] & 0x80);
3298 if ((rate * 5 * (1 << shift)) > 110)
3299 *have_higher_than_11mbit = true;
3302 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3303 * since they're not rates.
3305 * Note: Even though the membership selector and the basic
3306 * rate flag share the same bit, they are not exactly
3309 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3310 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3311 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3312 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3315 for (j = 0; j < sband->n_bitrates; j++) {
3316 struct ieee80211_rate *br;
3319 br = &sband->bitrates[j];
3321 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3322 if (brate == rate) {
3325 *basic_rates |= BIT(j);
3326 if ((rate * 5) < *min_rate) {
3327 *min_rate = rate * 5;
3328 *min_rate_index = j;
3336 static bool ieee80211_twt_req_supported(const struct sta_info *sta,
3337 const struct ieee802_11_elems *elems)
3339 if (elems->ext_capab_len < 10)
3342 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3345 return sta->sta.he_cap.he_cap_elem.mac_cap_info[0] &
3346 IEEE80211_HE_MAC_CAP0_TWT_RES;
3349 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3350 struct sta_info *sta,
3351 struct ieee802_11_elems *elems)
3353 bool twt = ieee80211_twt_req_supported(sta, elems);
3355 if (sdata->vif.bss_conf.twt_requester != twt) {
3356 sdata->vif.bss_conf.twt_requester = twt;
3357 return BSS_CHANGED_TWT;
3362 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3363 struct ieee80211_bss_conf *bss_conf,
3364 struct ieee80211_supported_band *sband,
3365 struct sta_info *sta)
3367 const struct ieee80211_sta_he_cap *own_he_cap =
3368 ieee80211_get_he_iftype_cap(sband,
3369 ieee80211_vif_type_p2p(&sdata->vif));
3371 return bss_conf->he_support &&
3372 (sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
3373 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3375 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3376 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3379 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3380 struct cfg80211_bss *cbss,
3381 struct ieee80211_mgmt *mgmt, size_t len,
3382 struct ieee802_11_elems *elems)
3384 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3385 struct ieee80211_local *local = sdata->local;
3386 struct ieee80211_supported_band *sband;
3387 struct sta_info *sta;
3388 u16 capab_info, aid;
3389 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3390 const struct cfg80211_bss_ies *bss_ies = NULL;
3391 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3392 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3393 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3399 /* AssocResp and ReassocResp have identical structure */
3401 pos = mgmt->u.assoc_resp.variable;
3402 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3404 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3407 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3408 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3409 mgmt->bssid, assoc_data->bss->bssid);
3414 if (elems->aid_resp)
3415 aid = le16_to_cpu(elems->aid_resp->aid);
3418 * The 5 MSB of the AID field are reserved
3419 * (802.11-2016 9.4.1.8 AID field)
3423 ifmgd->broken_ap = false;
3425 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3426 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3429 ifmgd->broken_ap = true;
3432 if (!is_s1g && !elems->supp_rates) {
3433 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3438 sdata->vif.bss_conf.aid = aid;
3439 ifmgd->tdls_chan_switch_prohibited =
3440 elems->ext_capab && elems->ext_capab_len >= 5 &&
3441 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3444 * Some APs are erroneously not including some information in their
3445 * (re)association response frames. Try to recover by using the data
3446 * from the beacon or probe response. This seems to afflict mobile
3447 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3448 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3451 ((assoc_data->wmm && !elems->wmm_param) ||
3452 (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3453 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3454 (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3455 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3456 const struct cfg80211_bss_ies *ies;
3457 struct ieee802_11_elems *bss_elems;
3460 ies = rcu_dereference(cbss->ies);
3462 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3470 bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3472 assoc_data->bss->bssid);
3478 if (assoc_data->wmm &&
3479 !elems->wmm_param && bss_elems->wmm_param) {
3480 elems->wmm_param = bss_elems->wmm_param;
3482 "AP bug: WMM param missing from AssocResp\n");
3486 * Also check if we requested HT/VHT, otherwise the AP doesn't
3487 * have to include the IEs in the (re)association response.
3489 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3490 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3491 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3493 "AP bug: HT capability missing from AssocResp\n");
3495 if (!elems->ht_operation && bss_elems->ht_operation &&
3496 !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
3497 elems->ht_operation = bss_elems->ht_operation;
3499 "AP bug: HT operation missing from AssocResp\n");
3501 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3502 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3503 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3505 "AP bug: VHT capa missing from AssocResp\n");
3507 if (!elems->vht_operation && bss_elems->vht_operation &&
3508 !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
3509 elems->vht_operation = bss_elems->vht_operation;
3511 "AP bug: VHT operation missing from AssocResp\n");
3518 * We previously checked these in the beacon/probe response, so
3519 * they should be present here. This is just a safety net.
3521 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
3522 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3524 "HT AP is missing WMM params or HT capability/operation\n");
3529 if (!is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
3530 (!elems->vht_cap_elem || !elems->vht_operation)) {
3532 "VHT AP is missing VHT capability/operation\n");
3537 if (is_6ghz && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3538 !elems->he_6ghz_capa) {
3540 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3545 mutex_lock(&sdata->local->sta_mtx);
3547 * station info was already allocated and inserted before
3548 * the association and should be available to us
3550 sta = sta_info_get(sdata, cbss->bssid);
3551 if (WARN_ON(!sta)) {
3552 mutex_unlock(&sdata->local->sta_mtx);
3557 sband = ieee80211_get_sband(sdata);
3559 mutex_unlock(&sdata->local->sta_mtx);
3564 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3565 (!elems->he_cap || !elems->he_operation)) {
3566 mutex_unlock(&sdata->local->sta_mtx);
3568 "HE AP is missing HE capability/operation\n");
3573 /* Set up internal HT/VHT capabilities */
3574 if (elems->ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
3575 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3576 elems->ht_cap_elem, sta);
3578 if (elems->vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
3579 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3580 elems->vht_cap_elem, sta);
3582 if (elems->he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
3584 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3587 elems->he_6ghz_capa,
3590 bss_conf->he_support = sta->sta.he_cap.has_he;
3591 if (elems->rsnx && elems->rsnx_len &&
3592 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3593 wiphy_ext_feature_isset(local->hw.wiphy,
3594 NL80211_EXT_FEATURE_PROTECTED_TWT))
3595 bss_conf->twt_protected = true;
3597 bss_conf->twt_protected = false;
3599 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
3601 if (elems->eht_operation && elems->eht_cap &&
3602 !(ifmgd->flags & IEEE80211_STA_DISABLE_EHT)) {
3603 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
3610 bss_conf->eht_support = sta->sta.eht_cap.has_eht;
3612 bss_conf->eht_support = false;
3615 bss_conf->he_support = false;
3616 bss_conf->twt_requester = false;
3617 bss_conf->twt_protected = false;
3618 bss_conf->eht_support = false;
3621 bss_conf->twt_broadcast =
3622 ieee80211_twt_bcast_support(sdata, bss_conf, sband, sta);
3624 if (bss_conf->he_support) {
3625 bss_conf->he_bss_color.color =
3626 le32_get_bits(elems->he_operation->he_oper_params,
3627 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3628 bss_conf->he_bss_color.partial =
3629 le32_get_bits(elems->he_operation->he_oper_params,
3630 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3631 bss_conf->he_bss_color.enabled =
3632 !le32_get_bits(elems->he_operation->he_oper_params,
3633 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3635 if (bss_conf->he_bss_color.enabled)
3636 changed |= BSS_CHANGED_HE_BSS_COLOR;
3638 bss_conf->htc_trig_based_pkt_ext =
3639 le32_get_bits(elems->he_operation->he_oper_params,
3640 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3641 bss_conf->frame_time_rts_th =
3642 le32_get_bits(elems->he_operation->he_oper_params,
3643 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3645 bss_conf->uora_exists = !!elems->uora_element;
3646 if (elems->uora_element)
3647 bss_conf->uora_ocw_range = elems->uora_element[0];
3649 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3650 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3651 /* TODO: OPEN: what happens if BSS color disable is set? */
3654 if (cbss->transmitted_bss) {
3655 bss_conf->nontransmitted = true;
3656 ether_addr_copy(bss_conf->transmitter_bssid,
3657 cbss->transmitted_bss->bssid);
3658 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3659 bss_conf->bssid_index = cbss->bssid_index;
3663 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3664 * in their association response, so ignore that data for our own
3665 * configuration. If it changed since the last beacon, we'll get the
3666 * next beacon and update then.
3670 * If an operating mode notification IE is present, override the
3671 * NSS calculation (that would be done in rate_control_rate_init())
3672 * and use the # of streams from that element.
3674 if (elems->opmode_notif &&
3675 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3678 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3679 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3681 sta->sta.rx_nss = nss;
3684 rate_control_rate_init(sta);
3686 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3687 set_sta_flag(sta, WLAN_STA_MFP);
3688 sta->sta.mfp = true;
3690 sta->sta.mfp = false;
3693 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3694 local->hw.queues >= IEEE80211_NUM_ACS;
3696 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3697 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3698 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3701 "failed to move station %pM to desired state\n",
3703 WARN_ON(__sta_info_destroy(sta));
3704 mutex_unlock(&sdata->local->sta_mtx);
3709 if (sdata->wdev.use_4addr)
3710 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3712 mutex_unlock(&sdata->local->sta_mtx);
3715 * Always handle WMM once after association regardless
3716 * of the first value the AP uses. Setting -1 here has
3717 * that effect because the AP values is an unsigned
3720 ifmgd->wmm_last_param_set = -1;
3721 ifmgd->mu_edca_last_param_set = -1;
3723 if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
3724 ieee80211_set_wmm_default(sdata, false, false);
3725 } else if (!ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
3726 elems->wmm_param_len,
3727 elems->mu_edca_param_set)) {
3728 /* still enable QoS since we might have HT/VHT */
3729 ieee80211_set_wmm_default(sdata, false, true);
3730 /* set the disable-WMM flag in this case to disable
3731 * tracking WMM parameter changes in the beacon if
3732 * the parameters weren't actually valid. Doing so
3733 * avoids changing parameters very strangely when
3734 * the AP is going back and forth between valid and
3735 * invalid parameters.
3737 ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
3739 changed |= BSS_CHANGED_QOS;
3741 if (elems->max_idle_period_ie) {
3742 bss_conf->max_idle_period =
3743 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3744 bss_conf->protected_keep_alive =
3745 !!(elems->max_idle_period_ie->idle_options &
3746 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3747 changed |= BSS_CHANGED_KEEP_ALIVE;
3749 bss_conf->max_idle_period = 0;
3750 bss_conf->protected_keep_alive = false;
3753 /* set assoc capability (AID was already set earlier),
3754 * ieee80211_set_associated() will tell the driver */
3755 bss_conf->assoc_capability = capab_info;
3756 ieee80211_set_associated(sdata, cbss, changed);
3759 * If we're using 4-addr mode, let the AP know that we're
3760 * doing so, so that it can create the STA VLAN on its side
3762 if (ifmgd->use_4addr)
3763 ieee80211_send_4addr_nullfunc(local, sdata);
3766 * Start timer to probe the connection to the AP now.
3767 * Also start the timer that will detect beacon loss.
3769 ieee80211_sta_reset_beacon_monitor(sdata);
3770 ieee80211_sta_reset_conn_monitor(sdata);
3779 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3780 struct ieee80211_mgmt *mgmt,
3783 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3784 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3785 u16 capab_info, status_code, aid;
3786 struct ieee802_11_elems *elems;
3787 int ac, uapsd_queues = -1;
3790 struct cfg80211_bss *cbss;
3791 struct ieee80211_event event = {
3793 .u.mlme.data = ASSOC_EVENT,
3795 struct ieee80211_prep_tx_info info = {};
3797 sdata_assert_lock(sdata);
3802 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3805 cbss = assoc_data->bss;
3808 * AssocResp and ReassocResp have identical structure, so process both
3809 * of them in this function.
3815 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3816 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3817 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3818 pos = mgmt->u.assoc_resp.variable;
3819 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3820 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3821 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3826 * Note: this may not be perfect, AP might misbehave - if
3827 * anyone needs to rely on perfect complete notification
3828 * with the exact right subtype, then we need to track what
3829 * we actually transmitted.
3831 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3832 IEEE80211_STYPE_ASSOC_REQ;
3835 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3836 reassoc ? "Rea" : "A", mgmt->sa,
3837 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3839 if (assoc_data->fils_kek_len &&
3840 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3843 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3844 mgmt->bssid, assoc_data->bss->bssid);
3848 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3849 elems->timeout_int &&
3850 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3853 cfg80211_assoc_comeback(sdata->dev, assoc_data->bss,
3854 le32_to_cpu(elems->timeout_int->value));
3856 tu = le32_to_cpu(elems->timeout_int->value);
3857 ms = tu * 1024 / 1000;
3859 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3861 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3862 assoc_data->timeout_started = true;
3863 if (ms > IEEE80211_ASSOC_TIMEOUT)
3864 run_again(sdata, assoc_data->timeout);
3868 if (status_code != WLAN_STATUS_SUCCESS) {
3869 sdata_info(sdata, "%pM denied association (code=%d)\n",
3870 mgmt->sa, status_code);
3871 ieee80211_destroy_assoc_data(sdata, false, false);
3872 event.u.mlme.status = MLME_DENIED;
3873 event.u.mlme.reason = status_code;
3874 drv_event_callback(sdata->local, sdata, &event);
3876 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) {
3877 /* oops -- internal error -- send timeout for now */
3878 ieee80211_destroy_assoc_data(sdata, false, false);
3879 cfg80211_assoc_timeout(sdata->dev, cbss);
3882 event.u.mlme.status = MLME_SUCCESS;
3883 drv_event_callback(sdata->local, sdata, &event);
3884 sdata_info(sdata, "associated\n");
3887 * destroy assoc_data afterwards, as otherwise an idle
3888 * recalc after assoc_data is NULL but before associated
3889 * is set can cause the interface to go idle
3891 ieee80211_destroy_assoc_data(sdata, true, false);
3893 /* get uapsd queues configuration */
3895 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3896 if (sdata->tx_conf[ac].uapsd)
3897 uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3902 cfg80211_rx_assoc_resp(sdata->dev, cbss, (u8 *)mgmt, len, uapsd_queues,
3903 ifmgd->assoc_req_ies, ifmgd->assoc_req_ies_len);
3905 drv_mgd_complete_tx(sdata->local, sdata, &info);
3909 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
3910 struct ieee80211_mgmt *mgmt, size_t len,
3911 struct ieee80211_rx_status *rx_status)
3913 struct ieee80211_local *local = sdata->local;
3914 struct ieee80211_bss *bss;
3915 struct ieee80211_channel *channel;
3917 sdata_assert_lock(sdata);
3919 channel = ieee80211_get_channel_khz(local->hw.wiphy,
3920 ieee80211_rx_status_to_khz(rx_status));
3924 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
3926 sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
3927 ieee80211_rx_bss_put(local, bss);
3932 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
3933 struct sk_buff *skb)
3935 struct ieee80211_mgmt *mgmt = (void *)skb->data;
3936 struct ieee80211_if_managed *ifmgd;
3937 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
3938 struct ieee80211_channel *channel;
3939 size_t baselen, len = skb->len;
3941 ifmgd = &sdata->u.mgd;
3943 sdata_assert_lock(sdata);
3946 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
3947 * "If a 6 GHz AP receives a Probe Request frame and responds with
3948 * a Probe Response frame [..], the Address 1 field of the Probe
3949 * Response frame shall be set to the broadcast address [..]"
3950 * So, on 6GHz band we should also accept broadcast responses.
3952 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
3957 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
3958 (channel->band != NL80211_BAND_6GHZ ||
3959 !is_broadcast_ether_addr(mgmt->da)))
3960 return; /* ignore ProbeResp to foreign address */
3962 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
3966 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
3968 if (ifmgd->associated &&
3969 ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
3970 ieee80211_reset_ap_probe(sdata);
3974 * This is the canonical list of information elements we care about,
3975 * the filter code also gives us all changes to the Microsoft OUI
3976 * (00:50:F2) vendor IE which is used for WMM which we need to track,
3977 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
3978 * changes to requested client power.
3980 * We implement beacon filtering in software since that means we can
3981 * avoid processing the frame here and in cfg80211, and userspace
3982 * will not be able to tell whether the hardware supports it or not.
3984 * XXX: This list needs to be dynamic -- userspace needs to be able to
3985 * add items it requires. It also needs to be able to tell us to
3986 * look out for other vendor IEs.
3988 static const u64 care_about_ies =
3989 (1ULL << WLAN_EID_COUNTRY) |
3990 (1ULL << WLAN_EID_ERP_INFO) |
3991 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
3992 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
3993 (1ULL << WLAN_EID_HT_CAPABILITY) |
3994 (1ULL << WLAN_EID_HT_OPERATION) |
3995 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
3997 static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
3998 struct ieee80211_if_managed *ifmgd,
3999 struct ieee80211_bss_conf *bss_conf,
4000 struct ieee80211_local *local,
4001 struct ieee80211_rx_status *rx_status)
4003 /* Track average RSSI from the Beacon frames of the current AP */
4005 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
4006 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
4007 ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
4008 ifmgd->last_cqm_event_signal = 0;
4009 ifmgd->count_beacon_signal = 1;
4010 ifmgd->last_ave_beacon_signal = 0;
4012 ifmgd->count_beacon_signal++;
4015 ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
4017 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
4018 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
4019 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
4020 int last_sig = ifmgd->last_ave_beacon_signal;
4021 struct ieee80211_event event = {
4026 * if signal crosses either of the boundaries, invoke callback
4027 * with appropriate parameters
4029 if (sig > ifmgd->rssi_max_thold &&
4030 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
4031 ifmgd->last_ave_beacon_signal = sig;
4032 event.u.rssi.data = RSSI_EVENT_HIGH;
4033 drv_event_callback(local, sdata, &event);
4034 } else if (sig < ifmgd->rssi_min_thold &&
4035 (last_sig >= ifmgd->rssi_max_thold ||
4037 ifmgd->last_ave_beacon_signal = sig;
4038 event.u.rssi.data = RSSI_EVENT_LOW;
4039 drv_event_callback(local, sdata, &event);
4043 if (bss_conf->cqm_rssi_thold &&
4044 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
4045 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
4046 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
4047 int last_event = ifmgd->last_cqm_event_signal;
4048 int thold = bss_conf->cqm_rssi_thold;
4049 int hyst = bss_conf->cqm_rssi_hyst;
4052 (last_event == 0 || sig < last_event - hyst)) {
4053 ifmgd->last_cqm_event_signal = sig;
4054 ieee80211_cqm_rssi_notify(
4056 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
4058 } else if (sig > thold &&
4059 (last_event == 0 || sig > last_event + hyst)) {
4060 ifmgd->last_cqm_event_signal = sig;
4061 ieee80211_cqm_rssi_notify(
4063 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
4068 if (bss_conf->cqm_rssi_low &&
4069 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
4070 int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
4071 int last_event = ifmgd->last_cqm_event_signal;
4072 int low = bss_conf->cqm_rssi_low;
4073 int high = bss_conf->cqm_rssi_high;
4076 (last_event == 0 || last_event >= low)) {
4077 ifmgd->last_cqm_event_signal = sig;
4078 ieee80211_cqm_rssi_notify(
4080 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
4082 } else if (sig > high &&
4083 (last_event == 0 || last_event <= high)) {
4084 ifmgd->last_cqm_event_signal = sig;
4085 ieee80211_cqm_rssi_notify(
4087 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
4093 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
4094 struct cfg80211_bss *bss)
4096 if (ether_addr_equal(tx_bssid, bss->bssid))
4098 if (!bss->transmitted_bss)
4100 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
4103 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
4104 struct ieee80211_hdr *hdr, size_t len,
4105 struct ieee80211_rx_status *rx_status)
4107 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4108 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
4109 struct ieee80211_mgmt *mgmt = (void *) hdr;
4111 struct ieee802_11_elems *elems;
4112 struct ieee80211_local *local = sdata->local;
4113 struct ieee80211_chanctx_conf *chanctx_conf;
4114 struct ieee80211_channel *chan;
4115 struct sta_info *sta;
4120 u8 *bssid, *variable = mgmt->u.beacon.variable;
4121 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4123 sdata_assert_lock(sdata);
4125 /* Process beacon from the current BSS */
4126 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4127 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4128 struct ieee80211_ext *ext = (void *) mgmt;
4130 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4131 variable = ext->u.s1g_short_beacon.variable;
4133 variable = ext->u.s1g_beacon.variable;
4136 baselen = (u8 *) variable - (u8 *) mgmt;
4141 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
4142 if (!chanctx_conf) {
4147 if (ieee80211_rx_status_to_khz(rx_status) !=
4148 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4152 chan = chanctx_conf->def.chan;
4155 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4156 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4157 elems = ieee802_11_parse_elems(variable, len - baselen, false,
4159 ifmgd->assoc_data->bss->bssid);
4163 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4165 if (elems->dtim_period)
4166 ifmgd->dtim_period = elems->dtim_period;
4167 ifmgd->have_beacon = true;
4168 ifmgd->assoc_data->need_beacon = false;
4169 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4170 sdata->vif.bss_conf.sync_tsf =
4171 le64_to_cpu(mgmt->u.beacon.timestamp);
4172 sdata->vif.bss_conf.sync_device_ts =
4173 rx_status->device_timestamp;
4174 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4177 if (elems->mbssid_config_ie)
4178 bss_conf->profile_periodicity =
4179 elems->mbssid_config_ie->profile_periodicity;
4181 bss_conf->profile_periodicity = 0;
4183 if (elems->ext_capab_len >= 11 &&
4184 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4185 bss_conf->ema_ap = true;
4187 bss_conf->ema_ap = false;
4189 /* continue assoc process */
4190 ifmgd->assoc_data->timeout = jiffies;
4191 ifmgd->assoc_data->timeout_started = true;
4192 run_again(sdata, ifmgd->assoc_data->timeout);
4197 if (!ifmgd->associated ||
4198 !ieee80211_rx_our_beacon(bssid, ifmgd->associated))
4200 bssid = ifmgd->associated->bssid;
4202 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4203 ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
4206 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4207 mlme_dbg_ratelimited(sdata,
4208 "cancelling AP probe due to a received beacon\n");
4209 ieee80211_reset_ap_probe(sdata);
4213 * Push the beacon loss detection into the future since
4214 * we are processing a beacon from the AP just now.
4216 ieee80211_sta_reset_beacon_monitor(sdata);
4218 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4219 * element (which carries the beacon interval). Don't forget to add a
4220 * bit to care_about_ies[] above if mac80211 is interested in a
4221 * changing S1G element.
4223 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4224 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4225 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
4226 false, care_about_ies, ncrc,
4227 mgmt->bssid, bssid);
4232 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4233 ieee80211_check_tim(elems->tim, elems->tim_len, bss_conf->aid)) {
4234 if (local->hw.conf.dynamic_ps_timeout > 0) {
4235 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4236 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4237 ieee80211_hw_config(local,
4238 IEEE80211_CONF_CHANGE_PS);
4240 ieee80211_send_nullfunc(local, sdata, false);
4241 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4242 local->pspolling = true;
4245 * Here is assumed that the driver will be
4246 * able to send ps-poll frame and receive a
4247 * response even though power save mode is
4248 * enabled, but some drivers might require
4249 * to disable power save here. This needs
4250 * to be investigated.
4252 ieee80211_send_pspoll(local, sdata);
4256 if (sdata->vif.p2p ||
4257 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4258 struct ieee80211_p2p_noa_attr noa = {};
4261 ret = cfg80211_get_p2p_attr(variable,
4263 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4264 (u8 *) &noa, sizeof(noa));
4266 if (sdata->u.mgd.p2p_noa_index != noa.index) {
4267 /* valid noa_attr and index changed */
4268 sdata->u.mgd.p2p_noa_index = noa.index;
4269 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4270 changed |= BSS_CHANGED_P2P_PS;
4272 * make sure we update all information, the CRC
4273 * mechanism doesn't look at P2P attributes.
4275 ifmgd->beacon_crc_valid = false;
4277 } else if (sdata->u.mgd.p2p_noa_index != -1) {
4278 /* noa_attr not found and we had valid noa_attr before */
4279 sdata->u.mgd.p2p_noa_index = -1;
4280 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4281 changed |= BSS_CHANGED_P2P_PS;
4282 ifmgd->beacon_crc_valid = false;
4286 if (ifmgd->csa_waiting_bcn)
4287 ieee80211_chswitch_post_beacon(sdata);
4290 * Update beacon timing and dtim count on every beacon appearance. This
4291 * will allow the driver to use the most updated values. Do it before
4292 * comparing this one with last received beacon.
4293 * IMPORTANT: These parameters would possibly be out of sync by the time
4294 * the driver will use them. The synchronized view is currently
4295 * guaranteed only in certain callbacks.
4297 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4298 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4299 sdata->vif.bss_conf.sync_tsf =
4300 le64_to_cpu(mgmt->u.beacon.timestamp);
4301 sdata->vif.bss_conf.sync_device_ts =
4302 rx_status->device_timestamp;
4303 sdata->vif.bss_conf.sync_dtim_count = elems->dtim_count;
4306 if ((ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) ||
4307 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4309 ifmgd->beacon_crc = ncrc;
4310 ifmgd->beacon_crc_valid = true;
4312 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status);
4314 ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
4315 rx_status->device_timestamp,
4318 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
4319 ieee80211_sta_wmm_params(local, sdata, elems->wmm_param,
4320 elems->wmm_param_len,
4321 elems->mu_edca_param_set))
4322 changed |= BSS_CHANGED_QOS;
4325 * If we haven't had a beacon before, tell the driver about the
4326 * DTIM period (and beacon timing if desired) now.
4328 if (!ifmgd->have_beacon) {
4329 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4330 bss_conf->dtim_period = elems->dtim_period ?: 1;
4332 changed |= BSS_CHANGED_BEACON_INFO;
4333 ifmgd->have_beacon = true;
4335 mutex_lock(&local->iflist_mtx);
4336 ieee80211_recalc_ps(local);
4337 mutex_unlock(&local->iflist_mtx);
4339 ieee80211_recalc_ps_vif(sdata);
4342 if (elems->erp_info) {
4344 erp_value = elems->erp_info[0];
4349 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4350 changed |= ieee80211_handle_bss_capability(sdata,
4351 le16_to_cpu(mgmt->u.beacon.capab_info),
4352 erp_valid, erp_value);
4354 mutex_lock(&local->sta_mtx);
4355 sta = sta_info_get(sdata, bssid);
4357 changed |= ieee80211_recalc_twt_req(sdata, sta, elems);
4359 if (ieee80211_config_bw(sdata, sta, elems->ht_cap_elem,
4360 elems->vht_cap_elem, elems->ht_operation,
4361 elems->vht_operation, elems->he_operation,
4362 elems->eht_operation,
4363 elems->s1g_oper, bssid, &changed)) {
4364 mutex_unlock(&local->sta_mtx);
4366 "failed to follow AP %pM bandwidth change, disconnect\n",
4368 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4369 WLAN_REASON_DEAUTH_LEAVING,
4371 ieee80211_report_disconnect(sdata, deauth_buf,
4372 sizeof(deauth_buf), true,
4373 WLAN_REASON_DEAUTH_LEAVING,
4378 if (sta && elems->opmode_notif)
4379 ieee80211_vht_handle_opmode(sdata, sta, *elems->opmode_notif,
4381 mutex_unlock(&local->sta_mtx);
4383 changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
4384 elems->country_elem,
4385 elems->country_elem_len,
4386 elems->pwr_constr_elem,
4387 elems->cisco_dtpc_elem);
4389 ieee80211_bss_info_change_notify(sdata, changed);
4394 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4395 struct sk_buff *skb)
4397 struct ieee80211_rx_status *rx_status;
4398 struct ieee80211_hdr *hdr;
4401 rx_status = (struct ieee80211_rx_status *) skb->cb;
4402 hdr = (struct ieee80211_hdr *) skb->data;
4403 fc = le16_to_cpu(hdr->frame_control);
4406 switch (fc & IEEE80211_FCTL_STYPE) {
4407 case IEEE80211_STYPE_S1G_BEACON:
4408 ieee80211_rx_mgmt_beacon(sdata, hdr, skb->len, rx_status);
4411 sdata_unlock(sdata);
4414 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4415 struct sk_buff *skb)
4417 struct ieee80211_rx_status *rx_status;
4418 struct ieee80211_mgmt *mgmt;
4422 rx_status = (struct ieee80211_rx_status *) skb->cb;
4423 mgmt = (struct ieee80211_mgmt *) skb->data;
4424 fc = le16_to_cpu(mgmt->frame_control);
4428 switch (fc & IEEE80211_FCTL_STYPE) {
4429 case IEEE80211_STYPE_BEACON:
4430 ieee80211_rx_mgmt_beacon(sdata, (void *)mgmt,
4431 skb->len, rx_status);
4433 case IEEE80211_STYPE_PROBE_RESP:
4434 ieee80211_rx_mgmt_probe_resp(sdata, skb);
4436 case IEEE80211_STYPE_AUTH:
4437 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4439 case IEEE80211_STYPE_DEAUTH:
4440 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4442 case IEEE80211_STYPE_DISASSOC:
4443 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4445 case IEEE80211_STYPE_ASSOC_RESP:
4446 case IEEE80211_STYPE_REASSOC_RESP:
4447 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4449 case IEEE80211_STYPE_ACTION:
4450 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4451 struct ieee802_11_elems *elems;
4453 ies_len = skb->len -
4454 offsetof(struct ieee80211_mgmt,
4455 u.action.u.chan_switch.variable);
4460 /* CSA IE cannot be overridden, no need for BSSID */
4461 elems = ieee802_11_parse_elems(
4462 mgmt->u.action.u.chan_switch.variable,
4463 ies_len, true, mgmt->bssid, NULL);
4465 if (elems && !elems->parse_error)
4466 ieee80211_sta_process_chanswitch(sdata,
4468 rx_status->device_timestamp,
4471 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4472 struct ieee802_11_elems *elems;
4474 ies_len = skb->len -
4475 offsetof(struct ieee80211_mgmt,
4476 u.action.u.ext_chan_switch.variable);
4482 * extended CSA IE can't be overridden, no need for
4485 elems = ieee802_11_parse_elems(
4486 mgmt->u.action.u.ext_chan_switch.variable,
4487 ies_len, true, mgmt->bssid, NULL);
4489 if (elems && !elems->parse_error) {
4490 /* for the handling code pretend it was an IE */
4491 elems->ext_chansw_ie =
4492 &mgmt->u.action.u.ext_chan_switch.data;
4494 ieee80211_sta_process_chanswitch(sdata,
4496 rx_status->device_timestamp,
4504 sdata_unlock(sdata);
4507 static void ieee80211_sta_timer(struct timer_list *t)
4509 struct ieee80211_sub_if_data *sdata =
4510 from_timer(sdata, t, u.mgd.timer);
4512 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4515 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4516 u8 *bssid, u8 reason, bool tx)
4518 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4520 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4523 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4527 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4529 struct ieee80211_local *local = sdata->local;
4530 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4531 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4535 struct ieee80211_prep_tx_info info = {
4536 .subtype = IEEE80211_STYPE_AUTH,
4539 sdata_assert_lock(sdata);
4541 if (WARN_ON_ONCE(!auth_data))
4546 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4547 sdata_info(sdata, "authentication with %pM timed out\n",
4548 auth_data->bss->bssid);
4551 * Most likely AP is not in the range so remove the
4552 * bss struct for that AP.
4554 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4559 if (auth_data->algorithm == WLAN_AUTH_SAE)
4560 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4562 drv_mgd_prepare_tx(local, sdata, &info);
4564 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4565 auth_data->bss->bssid, auth_data->tries,
4566 IEEE80211_AUTH_MAX_TRIES);
4568 auth_data->expected_transaction = 2;
4570 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4571 trans = auth_data->sae_trans;
4572 status = auth_data->sae_status;
4573 auth_data->expected_transaction = trans;
4576 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4577 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4578 IEEE80211_TX_INTFL_MLME_CONN_TX;
4580 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4581 auth_data->data, auth_data->data_len,
4582 auth_data->bss->bssid,
4583 auth_data->bss->bssid, NULL, 0, 0,
4586 if (tx_flags == 0) {
4587 if (auth_data->algorithm == WLAN_AUTH_SAE)
4588 auth_data->timeout = jiffies +
4589 IEEE80211_AUTH_TIMEOUT_SAE;
4591 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4593 auth_data->timeout =
4594 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4597 auth_data->timeout_started = true;
4598 run_again(sdata, auth_data->timeout);
4603 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4605 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4606 struct ieee80211_local *local = sdata->local;
4609 sdata_assert_lock(sdata);
4611 assoc_data->tries++;
4612 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4613 sdata_info(sdata, "association with %pM timed out\n",
4614 assoc_data->bss->bssid);
4617 * Most likely AP is not in the range so remove the
4618 * bss struct for that AP.
4620 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4625 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4626 assoc_data->bss->bssid, assoc_data->tries,
4627 IEEE80211_ASSOC_MAX_TRIES);
4628 ret = ieee80211_send_assoc(sdata);
4632 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4633 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4634 assoc_data->timeout_started = true;
4635 run_again(sdata, assoc_data->timeout);
4637 assoc_data->timeout =
4638 round_jiffies_up(jiffies +
4639 IEEE80211_ASSOC_TIMEOUT_LONG);
4640 assoc_data->timeout_started = true;
4641 run_again(sdata, assoc_data->timeout);
4647 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4648 __le16 fc, bool acked)
4650 struct ieee80211_local *local = sdata->local;
4652 sdata->u.mgd.status_fc = fc;
4653 sdata->u.mgd.status_acked = acked;
4654 sdata->u.mgd.status_received = true;
4656 ieee80211_queue_work(&local->hw, &sdata->work);
4659 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4661 struct ieee80211_local *local = sdata->local;
4662 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4666 if (ifmgd->status_received) {
4667 __le16 fc = ifmgd->status_fc;
4668 bool status_acked = ifmgd->status_acked;
4670 ifmgd->status_received = false;
4671 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4673 if (ifmgd->auth_data->algorithm ==
4675 ifmgd->auth_data->timeout =
4677 IEEE80211_AUTH_TIMEOUT_SAE;
4679 ifmgd->auth_data->timeout =
4681 IEEE80211_AUTH_TIMEOUT_SHORT;
4682 run_again(sdata, ifmgd->auth_data->timeout);
4684 ifmgd->auth_data->timeout = jiffies - 1;
4686 ifmgd->auth_data->timeout_started = true;
4687 } else if (ifmgd->assoc_data &&
4688 (ieee80211_is_assoc_req(fc) ||
4689 ieee80211_is_reassoc_req(fc))) {
4691 ifmgd->assoc_data->timeout =
4692 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4693 run_again(sdata, ifmgd->assoc_data->timeout);
4695 ifmgd->assoc_data->timeout = jiffies - 1;
4697 ifmgd->assoc_data->timeout_started = true;
4701 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4702 time_after(jiffies, ifmgd->auth_data->timeout)) {
4703 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
4705 * ok ... we waited for assoc or continuation but
4706 * userspace didn't do it, so kill the auth data
4708 ieee80211_destroy_auth_data(sdata, false);
4709 } else if (ieee80211_auth(sdata)) {
4711 struct ieee80211_event event = {
4713 .u.mlme.data = AUTH_EVENT,
4714 .u.mlme.status = MLME_TIMEOUT,
4717 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4719 ieee80211_destroy_auth_data(sdata, false);
4721 cfg80211_auth_timeout(sdata->dev, bssid);
4722 drv_event_callback(sdata->local, sdata, &event);
4724 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4725 run_again(sdata, ifmgd->auth_data->timeout);
4727 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4728 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4729 if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
4730 ieee80211_do_assoc(sdata)) {
4731 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
4732 struct ieee80211_event event = {
4734 .u.mlme.data = ASSOC_EVENT,
4735 .u.mlme.status = MLME_TIMEOUT,
4738 ieee80211_destroy_assoc_data(sdata, false, false);
4739 cfg80211_assoc_timeout(sdata->dev, bss);
4740 drv_event_callback(sdata->local, sdata, &event);
4742 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4743 run_again(sdata, ifmgd->assoc_data->timeout);
4745 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4746 ifmgd->associated) {
4750 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4752 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4753 max_tries = max_nullfunc_tries;
4755 max_tries = max_probe_tries;
4757 /* ACK received for nullfunc probing frame */
4758 if (!ifmgd->probe_send_count)
4759 ieee80211_reset_ap_probe(sdata);
4760 else if (ifmgd->nullfunc_failed) {
4761 if (ifmgd->probe_send_count < max_tries) {
4763 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4764 bssid, ifmgd->probe_send_count,
4766 ieee80211_mgd_probe_ap_send(sdata);
4769 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4771 ieee80211_sta_connection_lost(sdata, bssid,
4772 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4775 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4776 run_again(sdata, ifmgd->probe_timeout);
4777 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4779 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4780 bssid, probe_wait_ms);
4781 ieee80211_sta_connection_lost(sdata, bssid,
4782 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4783 } else if (ifmgd->probe_send_count < max_tries) {
4785 "No probe response from AP %pM after %dms, try %d/%i\n",
4786 bssid, probe_wait_ms,
4787 ifmgd->probe_send_count, max_tries);
4788 ieee80211_mgd_probe_ap_send(sdata);
4791 * We actually lost the connection ... or did we?
4795 "No probe response from AP %pM after %dms, disconnecting.\n",
4796 bssid, probe_wait_ms);
4798 ieee80211_sta_connection_lost(sdata, bssid,
4799 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4803 sdata_unlock(sdata);
4806 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4808 struct ieee80211_sub_if_data *sdata =
4809 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4810 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4812 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4815 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4818 sdata->u.mgd.connection_loss = false;
4819 ieee80211_queue_work(&sdata->local->hw,
4820 &sdata->u.mgd.beacon_connection_loss_work);
4823 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4825 struct ieee80211_sub_if_data *sdata =
4826 from_timer(sdata, t, u.mgd.conn_mon_timer);
4827 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4828 struct ieee80211_local *local = sdata->local;
4829 struct sta_info *sta;
4830 unsigned long timeout;
4832 if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
4835 sta = sta_info_get(sdata, ifmgd->bssid);
4839 timeout = sta->status_stats.last_ack;
4840 if (time_before(sta->status_stats.last_ack, sta->rx_stats.last_rx))
4841 timeout = sta->rx_stats.last_rx;
4842 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4844 /* If timeout is after now, then update timer to fire at
4845 * the later date, but do not actually probe at this time.
4847 if (time_is_after_jiffies(timeout)) {
4848 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4852 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4855 static void ieee80211_sta_monitor_work(struct work_struct *work)
4857 struct ieee80211_sub_if_data *sdata =
4858 container_of(work, struct ieee80211_sub_if_data,
4859 u.mgd.monitor_work);
4861 ieee80211_mgd_probe_ap(sdata, false);
4864 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4866 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4867 __ieee80211_stop_poll(sdata);
4869 /* let's probe the connection once */
4870 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4871 ieee80211_queue_work(&sdata->local->hw,
4872 &sdata->u.mgd.monitor_work);
4877 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
4879 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4880 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4884 if (ifmgd->auth_data || ifmgd->assoc_data) {
4885 const u8 *bssid = ifmgd->auth_data ?
4886 ifmgd->auth_data->bss->bssid :
4887 ifmgd->assoc_data->bss->bssid;
4890 * If we are trying to authenticate / associate while suspending,
4891 * cfg80211 won't know and won't actually abort those attempts,
4892 * thus we need to do that ourselves.
4894 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
4895 IEEE80211_STYPE_DEAUTH,
4896 WLAN_REASON_DEAUTH_LEAVING,
4898 if (ifmgd->assoc_data)
4899 ieee80211_destroy_assoc_data(sdata, false, true);
4900 if (ifmgd->auth_data)
4901 ieee80211_destroy_auth_data(sdata, false);
4902 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
4903 IEEE80211_DEAUTH_FRAME_LEN,
4907 /* This is a bit of a hack - we should find a better and more generic
4908 * solution to this. Normally when suspending, cfg80211 will in fact
4909 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
4910 * auth (not so important) or assoc (this is the problem) process.
4912 * As a consequence, it can happen that we are in the process of both
4913 * associating and suspending, and receive an association response
4914 * after cfg80211 has checked if it needs to disconnect, but before
4915 * we actually set the flag to drop incoming frames. This will then
4916 * cause the workqueue flush to process the association response in
4917 * the suspend, resulting in a successful association just before it
4918 * tries to remove the interface from the driver, which now though
4919 * has a channel context assigned ... this results in issues.
4921 * To work around this (for now) simply deauth here again if we're
4924 if (ifmgd->associated && !sdata->local->wowlan) {
4926 struct cfg80211_deauth_request req = {
4927 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
4931 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
4932 ieee80211_mgd_deauth(sdata, &req);
4935 sdata_unlock(sdata);
4939 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
4941 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4944 if (!ifmgd->associated) {
4945 sdata_unlock(sdata);
4949 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
4950 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
4951 mlme_dbg(sdata, "driver requested disconnect after resume\n");
4952 ieee80211_sta_connection_lost(sdata,
4953 ifmgd->associated->bssid,
4954 WLAN_REASON_UNSPECIFIED,
4956 sdata_unlock(sdata);
4960 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
4961 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
4962 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
4963 ieee80211_sta_connection_lost(sdata,
4964 ifmgd->associated->bssid,
4965 WLAN_REASON_UNSPECIFIED,
4967 sdata_unlock(sdata);
4971 sdata_unlock(sdata);
4974 /* interface setup */
4975 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
4977 struct ieee80211_if_managed *ifmgd;
4979 ifmgd = &sdata->u.mgd;
4980 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
4981 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
4982 INIT_WORK(&ifmgd->beacon_connection_loss_work,
4983 ieee80211_beacon_connection_loss_work);
4984 INIT_WORK(&ifmgd->csa_connection_drop_work,
4985 ieee80211_csa_connection_drop_work);
4986 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
4987 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
4988 ieee80211_tdls_peer_del_work);
4989 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
4990 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
4991 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
4992 timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
4993 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
4994 ieee80211_sta_handle_tspec_ac_params_wk);
4997 ifmgd->powersave = sdata->wdev.ps;
4998 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
4999 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
5000 ifmgd->p2p_noa_index = -1;
5002 if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
5003 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
5005 ifmgd->req_smps = IEEE80211_SMPS_OFF;
5007 /* Setup TDLS data */
5008 spin_lock_init(&ifmgd->teardown_lock);
5009 ifmgd->teardown_skb = NULL;
5010 ifmgd->orig_teardown_skb = NULL;
5013 /* scan finished notification */
5014 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
5016 struct ieee80211_sub_if_data *sdata;
5018 /* Restart STA timers */
5020 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
5021 if (ieee80211_sdata_running(sdata))
5022 ieee80211_restart_sta_timer(sdata);
5027 static u8 ieee80211_max_rx_chains(struct ieee80211_sub_if_data *sdata,
5028 struct cfg80211_bss *cbss)
5030 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
5031 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5032 const struct element *ht_cap_elem, *vht_cap_elem;
5033 const struct cfg80211_bss_ies *ies;
5034 const struct ieee80211_ht_cap *ht_cap;
5035 const struct ieee80211_vht_cap *vht_cap;
5036 const struct ieee80211_he_cap_elem *he_cap;
5037 const struct element *he_cap_elem;
5038 u16 mcs_80_map, mcs_160_map;
5039 int i, mcs_nss_size;
5043 if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
5046 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
5047 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
5048 ht_cap = (void *)ht_cap_elem->data;
5049 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
5051 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
5052 * "Tx Unequal Modulation Supported" fields.
5056 if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
5059 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
5060 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
5064 vht_cap = (void *)vht_cap_elem->data;
5065 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
5066 for (nss = 8; nss > 0; nss--) {
5067 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
5068 IEEE80211_VHT_MCS_NOT_SUPPORTED)
5071 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
5072 chains = max(chains, nss);
5075 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE)
5078 ies = rcu_dereference(cbss->ies);
5079 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
5080 ies->data, ies->len);
5082 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
5085 /* skip one byte ext_tag_id */
5086 he_cap = (void *)(he_cap_elem->data + 1);
5087 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
5090 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
5093 /* mcs_nss is right after he_cap info */
5094 he_mcs_nss_supp = (void *)(he_cap + 1);
5096 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
5098 for (i = 7; i >= 0; i--) {
5099 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
5101 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5102 chains = max_t(u8, chains, i + 1);
5107 support_160 = he_cap->phy_cap_info[0] &
5108 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
5113 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
5114 for (i = 7; i >= 0; i--) {
5115 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
5117 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5118 chains = max_t(u8, chains, i + 1);
5127 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
5128 const struct cfg80211_bss_ies *ies,
5129 const struct ieee80211_he_operation *he_op)
5131 const struct element *he_cap_elem;
5132 const struct ieee80211_he_cap_elem *he_cap;
5133 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
5134 u16 mcs_80_map_tx, mcs_80_map_rx;
5139 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
5140 ies->data, ies->len);
5143 if (!he_cap_elem || he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
5145 "Invalid HE elem, Disable HE\n");
5149 /* skip one byte ext_tag_id */
5150 he_cap = (void *)(he_cap_elem->data + 1);
5151 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
5154 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
5156 "Invalid HE elem with nss size, Disable HE\n");
5160 /* mcs_nss is right after he_cap info */
5161 he_mcs_nss_supp = (void *)(he_cap + 1);
5163 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
5164 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
5166 /* P802.11-REVme/D0.3
5167 * 27.1.1 Introduction to the HE PHY
5169 * An HE STA shall support the following features:
5171 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
5172 * supported channel widths for HE SU PPDUs
5174 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5175 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
5177 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
5178 mcs_80_map_tx, mcs_80_map_rx);
5185 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
5187 /* make sure the AP is consistent with itself
5189 * P802.11-REVme/D0.3
5190 * 26.17.1 Basic HE BSS operation
5192 * A STA that is operating in an HE BSS shall be able to receive and
5193 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
5194 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
5195 * MLME-START.request primitive and shall be able to receive at each of
5196 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
5197 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
5200 for (nss = 8; nss > 0; nss--) {
5201 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
5205 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
5208 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
5209 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
5211 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5212 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5213 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
5215 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
5216 nss, ap_rx_val, ap_rx_val, ap_op_val);
5225 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
5226 struct ieee80211_supported_band *sband,
5227 const struct ieee80211_he_operation *he_op)
5229 const struct ieee80211_sta_he_cap *sta_he_cap =
5230 ieee80211_get_he_iftype_cap(sband,
5231 ieee80211_vif_type_p2p(&sdata->vif));
5235 if (!sta_he_cap || !he_op)
5238 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
5240 /* Need to go over for 80MHz, 160MHz and for 80+80 */
5241 for (i = 0; i < 3; i++) {
5242 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
5243 &sta_he_cap->he_mcs_nss_supp;
5244 u16 sta_mcs_map_rx =
5245 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
5246 u16 sta_mcs_map_tx =
5247 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
5249 bool verified = true;
5252 * For each band there is a maximum of 8 spatial streams
5253 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
5254 * of 2 bits per NSS (1-8), with the values defined in enum
5255 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
5256 * capabilities aren't less than the AP's minimum requirements
5257 * for this HE BSS per SS.
5258 * It is enough to find one such band that meets the reqs.
5260 for (nss = 8; nss > 0; nss--) {
5261 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
5262 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
5263 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
5265 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
5269 * Make sure the HE AP doesn't require MCSs that aren't
5270 * supported by the client as required by spec
5272 * P802.11-REVme/D0.3
5273 * 26.17.1 Basic HE BSS operation
5275 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
5276 * a BSS, unless it supports (i.e., is able to both transmit and
5277 * receive using) all of the <HE-MCS, NSS> tuples in the basic
5278 * HE-MCS and NSS set.
5280 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5281 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5282 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
5292 /* If here, STA doesn't meet AP's HE min requirements */
5296 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5297 struct cfg80211_bss *cbss)
5299 struct ieee80211_local *local = sdata->local;
5300 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5301 const struct ieee80211_ht_cap *ht_cap = NULL;
5302 const struct ieee80211_ht_operation *ht_oper = NULL;
5303 const struct ieee80211_vht_operation *vht_oper = NULL;
5304 const struct ieee80211_he_operation *he_oper = NULL;
5305 const struct ieee80211_eht_operation *eht_oper = NULL;
5306 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
5307 struct ieee80211_supported_band *sband;
5308 struct cfg80211_chan_def chandef;
5309 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5310 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
5311 struct ieee80211_bss *bss = (void *)cbss->priv;
5312 struct ieee802_11_elems *elems;
5313 const struct cfg80211_bss_ies *ies;
5320 ies = rcu_dereference(cbss->ies);
5321 elems = ieee802_11_parse_elems(ies->data, ies->len, false,
5328 sband = local->hw.wiphy->bands[cbss->channel->band];
5330 ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
5331 IEEE80211_STA_DISABLE_80P80MHZ |
5332 IEEE80211_STA_DISABLE_160MHZ);
5334 /* disable HT/VHT/HE if we don't support them */
5335 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5336 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
5337 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5338 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5339 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5340 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5343 if (!sband->vht_cap.vht_supported && is_5ghz) {
5344 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
5345 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5346 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5347 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5350 if (!ieee80211_get_he_iftype_cap(sband,
5351 ieee80211_vif_type_p2p(&sdata->vif))) {
5352 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
5353 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5354 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5357 if (!ieee80211_get_eht_iftype_cap(sband,
5358 ieee80211_vif_type_p2p(&sdata->vif))) {
5359 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
5360 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5363 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && !is_6ghz) {
5364 ht_oper = elems->ht_operation;
5365 ht_cap = elems->ht_cap_elem;
5368 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5373 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && !is_6ghz) {
5374 vht_oper = elems->vht_operation;
5375 if (vht_oper && !ht_oper) {
5378 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5379 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5380 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5381 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5382 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5385 if (!elems->vht_cap_elem) {
5387 "bad VHT capabilities, disabling VHT\n");
5388 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5393 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE)) {
5394 he_oper = elems->he_operation;
5397 struct ieee80211_bss_conf *bss_conf;
5400 bss_conf = &sdata->vif.bss_conf;
5402 if (elems->pwr_constr_elem)
5403 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
5405 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
5406 ARRAY_SIZE(elems->tx_pwr_env));
5408 for (i = 0; i < elems->tx_pwr_env_num; i++) {
5409 if (elems->tx_pwr_env_len[i] >
5410 sizeof(bss_conf->tx_pwr_env[j]))
5413 bss_conf->tx_pwr_env_num++;
5414 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
5415 elems->tx_pwr_env_len[i]);
5420 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
5421 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5422 ifmgd->flags |= IEEE80211_STA_DISABLE_HE |
5423 IEEE80211_STA_DISABLE_EHT;
5427 * EHT requires HE to be supported as well. Specifically for 6 GHz
5428 * channels, the operation channel information can only be deduced from
5429 * both the 6 GHz operation information (from the HE operation IE) and
5432 if (!(ifmgd->flags & (IEEE80211_STA_DISABLE_HE |
5433 IEEE80211_STA_DISABLE_EHT)) && he_oper) {
5434 const struct cfg80211_bss_ies *ies;
5435 const u8 *eht_oper_ie;
5437 ies = rcu_dereference(cbss->ies);
5438 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
5439 ies->data, ies->len);
5440 if (eht_oper_ie && eht_oper_ie[1] >=
5441 1 + sizeof(struct ieee80211_eht_operation))
5442 eht_oper = (void *)(eht_oper_ie + 3);
5447 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5449 for (i = 0; i < sband->n_channels; i++) {
5450 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5451 IEEE80211_CHAN_NO_80MHZ))
5459 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
5460 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5463 if (sband->band == NL80211_BAND_S1GHZ) {
5464 s1g_oper = elems->s1g_oper;
5467 "AP missing S1G operation element?\n");
5470 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
5478 sdata->needed_rx_chains = min(ieee80211_max_rx_chains(sdata, cbss),
5482 /* the element data was RCU protected so no longer valid anyway */
5486 if (ifmgd->flags & IEEE80211_STA_DISABLE_HE && is_6ghz) {
5487 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5491 /* will change later if needed */
5492 sdata->smps_mode = IEEE80211_SMPS_OFF;
5494 mutex_lock(&local->mtx);
5496 * If this fails (possibly due to channel context sharing
5497 * on incompatible channels, e.g. 80+80 and 160 sharing the
5498 * same control channel) try to use a smaller bandwidth.
5500 ret = ieee80211_vif_use_channel(sdata, &chandef,
5501 IEEE80211_CHANCTX_SHARED);
5503 /* don't downgrade for 5 and 10 MHz channels, though. */
5504 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5505 chandef.width == NL80211_CHAN_WIDTH_10)
5508 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5509 ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
5510 ret = ieee80211_vif_use_channel(sdata, &chandef,
5511 IEEE80211_CHANCTX_SHARED);
5514 mutex_unlock(&local->mtx);
5518 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5519 u8 *dtim_count, u8 *dtim_period)
5521 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5522 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5524 const struct ieee80211_tim_ie *tim = NULL;
5525 const struct ieee80211_bssid_index *idx;
5526 bool valid = tim_ie && tim_ie[1] >= 2;
5529 tim = (void *)(tim_ie + 2);
5532 *dtim_count = valid ? tim->dtim_count : 0;
5535 *dtim_period = valid ? tim->dtim_period : 0;
5537 /* Check if value is overridden by non-transmitted profile */
5538 if (!idx_ie || idx_ie[1] < 3)
5541 idx = (void *)(idx_ie + 2);
5544 *dtim_count = idx->dtim_count;
5547 *dtim_period = idx->dtim_period;
5552 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5553 struct cfg80211_bss *cbss, bool assoc,
5556 struct ieee80211_local *local = sdata->local;
5557 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5558 struct ieee80211_bss *bss = (void *)cbss->priv;
5559 struct sta_info *new_sta = NULL;
5560 struct ieee80211_supported_band *sband;
5561 bool have_sta = false;
5564 sband = local->hw.wiphy->bands[cbss->channel->band];
5566 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5569 /* If a reconfig is happening, bail out */
5570 if (local->in_reconfig)
5575 have_sta = sta_info_get(sdata, cbss->bssid);
5580 new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
5586 * Set up the information for the new channel before setting the
5587 * new channel. We can't - completely race-free - change the basic
5588 * rates bitmap and the channel (sband) that it refers to, but if
5589 * we set it up before we at least avoid calling into the driver's
5590 * bss_info_changed() method with invalid information (since we do
5591 * call that from changing the channel - only for IDLE and perhaps
5592 * some others, but ...).
5594 * So to avoid that, just set up all the new information before the
5595 * channel, but tell the driver to apply it only afterwards, since
5596 * it might need the new channel for that.
5599 u32 rates = 0, basic_rates = 0;
5600 bool have_higher_than_11mbit = false;
5601 int min_rate = INT_MAX, min_rate_index = -1;
5602 const struct cfg80211_bss_ies *ies;
5603 int shift = ieee80211_vif_get_shift(&sdata->vif);
5605 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5606 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5607 ieee80211_s1g_sta_rate_init(new_sta);
5611 ieee80211_get_rates(sband, bss->supp_rates,
5612 bss->supp_rates_len,
5613 &rates, &basic_rates,
5614 &have_higher_than_11mbit,
5615 &min_rate, &min_rate_index,
5619 * This used to be a workaround for basic rates missing
5620 * in the association response frame. Now that we no
5621 * longer use the basic rates from there, it probably
5622 * doesn't happen any more, but keep the workaround so
5623 * in case some *other* APs are buggy in different ways
5624 * we can connect -- with a warning.
5625 * Allow this workaround only in case the AP provided at least
5628 if (min_rate_index < 0) {
5630 "No legacy rates in association response\n");
5632 sta_info_free(local, new_sta);
5634 } else if (!basic_rates) {
5636 "No basic rates, using min rate instead\n");
5637 basic_rates = BIT(min_rate_index);
5641 new_sta->sta.supp_rates[cbss->channel->band] = rates;
5644 "No rates found, keeping mandatory only\n");
5646 sdata->vif.bss_conf.basic_rates = basic_rates;
5648 /* cf. IEEE 802.11 9.2.12 */
5649 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5650 have_higher_than_11mbit)
5651 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5653 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5656 memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
5658 /* set timing information */
5659 sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
5661 ies = rcu_dereference(cbss->beacon_ies);
5663 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5664 sdata->vif.bss_conf.sync_device_ts =
5665 bss->device_ts_beacon;
5667 ieee80211_get_dtim(ies,
5668 &sdata->vif.bss_conf.sync_dtim_count,
5670 } else if (!ieee80211_hw_check(&sdata->local->hw,
5671 TIMING_BEACON_ONLY)) {
5672 ies = rcu_dereference(cbss->proberesp_ies);
5673 /* must be non-NULL since beacon IEs were NULL */
5674 sdata->vif.bss_conf.sync_tsf = ies->tsf;
5675 sdata->vif.bss_conf.sync_device_ts =
5676 bss->device_ts_presp;
5677 sdata->vif.bss_conf.sync_dtim_count = 0;
5679 sdata->vif.bss_conf.sync_tsf = 0;
5680 sdata->vif.bss_conf.sync_device_ts = 0;
5681 sdata->vif.bss_conf.sync_dtim_count = 0;
5686 if (new_sta || override) {
5687 err = ieee80211_prep_channel(sdata, cbss);
5690 sta_info_free(local, new_sta);
5697 * tell driver about BSSID, basic rates and timing
5698 * this was set up above, before setting the channel
5700 ieee80211_bss_info_change_notify(sdata,
5701 BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
5702 BSS_CHANGED_BEACON_INT);
5705 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5707 err = sta_info_insert(new_sta);
5711 "failed to insert STA entry for the AP (error %d)\n",
5716 WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
5718 /* Cancel scan to ensure that nothing interferes with connection */
5719 if (local->scanning)
5720 ieee80211_scan_cancel(local);
5726 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5727 struct cfg80211_auth_request *req)
5729 struct ieee80211_local *local = sdata->local;
5730 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5731 struct ieee80211_mgd_auth_data *auth_data;
5736 /* prepare auth data structure */
5738 switch (req->auth_type) {
5739 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5740 auth_alg = WLAN_AUTH_OPEN;
5742 case NL80211_AUTHTYPE_SHARED_KEY:
5745 auth_alg = WLAN_AUTH_SHARED_KEY;
5747 case NL80211_AUTHTYPE_FT:
5748 auth_alg = WLAN_AUTH_FT;
5750 case NL80211_AUTHTYPE_NETWORK_EAP:
5751 auth_alg = WLAN_AUTH_LEAP;
5753 case NL80211_AUTHTYPE_SAE:
5754 auth_alg = WLAN_AUTH_SAE;
5756 case NL80211_AUTHTYPE_FILS_SK:
5757 auth_alg = WLAN_AUTH_FILS_SK;
5759 case NL80211_AUTHTYPE_FILS_SK_PFS:
5760 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5762 case NL80211_AUTHTYPE_FILS_PK:
5763 auth_alg = WLAN_AUTH_FILS_PK;
5769 if (ifmgd->assoc_data)
5772 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5773 req->ie_len, GFP_KERNEL);
5777 auth_data->bss = req->bss;
5779 if (req->auth_data_len >= 4) {
5780 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5781 __le16 *pos = (__le16 *) req->auth_data;
5783 auth_data->sae_trans = le16_to_cpu(pos[0]);
5784 auth_data->sae_status = le16_to_cpu(pos[1]);
5786 memcpy(auth_data->data, req->auth_data + 4,
5787 req->auth_data_len - 4);
5788 auth_data->data_len += req->auth_data_len - 4;
5791 /* Check if continuing authentication or trying to authenticate with the
5792 * same BSS that we were in the process of authenticating with and avoid
5793 * removal and re-addition of the STA entry in
5794 * ieee80211_prep_connection().
5796 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5798 if (req->ie && req->ie_len) {
5799 memcpy(&auth_data->data[auth_data->data_len],
5800 req->ie, req->ie_len);
5801 auth_data->data_len += req->ie_len;
5804 if (req->key && req->key_len) {
5805 auth_data->key_len = req->key_len;
5806 auth_data->key_idx = req->key_idx;
5807 memcpy(auth_data->key, req->key, req->key_len);
5810 auth_data->algorithm = auth_alg;
5812 /* try to authenticate/probe */
5814 if (ifmgd->auth_data) {
5815 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5816 auth_data->peer_confirmed =
5817 ifmgd->auth_data->peer_confirmed;
5819 ieee80211_destroy_auth_data(sdata, cont_auth);
5822 /* prep auth_data so we don't go into idle on disassoc */
5823 ifmgd->auth_data = auth_data;
5825 /* If this is continuation of an ongoing SAE authentication exchange
5826 * (i.e., request to send SAE Confirm) and the peer has already
5827 * confirmed, mark authentication completed since we are about to send
5830 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5831 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5832 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5834 if (ifmgd->associated) {
5835 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5838 "disconnect from AP %pM for new auth to %pM\n",
5839 ifmgd->associated->bssid, req->bss->bssid);
5840 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5841 WLAN_REASON_UNSPECIFIED,
5844 ieee80211_report_disconnect(sdata, frame_buf,
5845 sizeof(frame_buf), true,
5846 WLAN_REASON_UNSPECIFIED,
5850 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
5852 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
5856 err = ieee80211_auth(sdata);
5858 sta_info_destroy_addr(sdata, req->bss->bssid);
5862 /* hold our own reference */
5863 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
5867 eth_zero_addr(ifmgd->bssid);
5868 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
5869 ifmgd->auth_data = NULL;
5870 mutex_lock(&sdata->local->mtx);
5871 ieee80211_vif_release_channel(sdata);
5872 mutex_unlock(&sdata->local->mtx);
5877 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
5878 struct cfg80211_assoc_request *req)
5880 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
5881 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
5882 struct ieee80211_local *local = sdata->local;
5883 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5884 struct ieee80211_bss *bss = (void *)req->bss->priv;
5885 struct ieee80211_mgd_assoc_data *assoc_data;
5886 const struct cfg80211_bss_ies *beacon_ies;
5887 struct ieee80211_supported_band *sband;
5888 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5889 const struct element *ssid_elem, *ht_elem, *vht_elem;
5891 bool override = false;
5893 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
5898 ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID);
5899 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
5904 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
5905 assoc_data->ssid_len = ssid_elem->datalen;
5906 memcpy(bss_conf->ssid, assoc_data->ssid, assoc_data->ssid_len);
5907 bss_conf->ssid_len = assoc_data->ssid_len;
5910 if (ifmgd->associated) {
5911 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5914 "disconnect from AP %pM for new assoc to %pM\n",
5915 ifmgd->associated->bssid, req->bss->bssid);
5916 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5917 WLAN_REASON_UNSPECIFIED,
5920 ieee80211_report_disconnect(sdata, frame_buf,
5921 sizeof(frame_buf), true,
5922 WLAN_REASON_UNSPECIFIED,
5926 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
5931 if (ifmgd->assoc_data) {
5936 if (ifmgd->auth_data) {
5939 /* keep sta info, bssid if matching */
5940 match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
5941 ieee80211_destroy_auth_data(sdata, match);
5944 /* prepare assoc data */
5946 ifmgd->beacon_crc_valid = false;
5948 assoc_data->wmm = bss->wmm_used &&
5949 (local->hw.queues >= IEEE80211_NUM_ACS);
5952 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
5953 * We still associate in non-HT mode (11a/b/g) if any one of these
5954 * ciphers is configured as pairwise.
5955 * We can set this to true for non-11n hardware, that'll be checked
5956 * separately along with the peer capabilities.
5958 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
5959 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
5960 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
5961 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
5962 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5963 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5964 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5965 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5966 netdev_info(sdata->dev,
5967 "disabling HT/VHT/HE due to WEP/TKIP use\n");
5971 sband = local->hw.wiphy->bands[req->bss->channel->band];
5973 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
5974 if (!bss->wmm_used) {
5975 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
5976 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
5977 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
5978 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
5979 netdev_info(sdata->dev,
5980 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
5983 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
5984 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
5985 sizeof(ifmgd->ht_capa_mask));
5987 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
5988 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
5989 sizeof(ifmgd->vht_capa_mask));
5991 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
5992 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
5993 sizeof(ifmgd->s1g_capa_mask));
5995 if (req->ie && req->ie_len) {
5996 memcpy(assoc_data->ie, req->ie, req->ie_len);
5997 assoc_data->ie_len = req->ie_len;
6000 if (req->fils_kek) {
6001 /* should already be checked in cfg80211 - so warn */
6002 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
6006 memcpy(assoc_data->fils_kek, req->fils_kek,
6008 assoc_data->fils_kek_len = req->fils_kek_len;
6011 if (req->fils_nonces)
6012 memcpy(assoc_data->fils_nonces, req->fils_nonces,
6013 2 * FILS_NONCE_LEN);
6015 assoc_data->bss = req->bss;
6016 assoc_data->capability = req->bss->capability;
6017 assoc_data->supp_rates = bss->supp_rates;
6018 assoc_data->supp_rates_len = bss->supp_rates_len;
6021 ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION);
6022 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
6023 assoc_data->ap_ht_param =
6024 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
6026 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
6027 vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY);
6028 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
6029 memcpy(&assoc_data->ap_vht_cap, vht_elem->data,
6030 sizeof(struct ieee80211_vht_cap));
6031 } else if (is_5ghz) {
6033 "VHT capa missing/short, disabling VHT/HE/EHT\n");
6034 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT |
6035 IEEE80211_STA_DISABLE_HE |
6036 IEEE80211_STA_DISABLE_EHT;
6040 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
6041 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
6042 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
6043 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
6045 if (bss->wmm_used && bss->uapsd_supported &&
6046 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
6047 assoc_data->uapsd = true;
6048 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
6050 assoc_data->uapsd = false;
6051 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
6054 if (req->prev_bssid)
6055 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
6058 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
6059 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
6061 ifmgd->mfp = IEEE80211_MFP_DISABLED;
6062 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
6065 if (req->flags & ASSOC_REQ_USE_RRM)
6066 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
6068 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
6070 if (req->crypto.control_port)
6071 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
6073 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
6075 sdata->control_port_protocol = req->crypto.control_port_ethertype;
6076 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
6077 sdata->control_port_over_nl80211 =
6078 req->crypto.control_port_over_nl80211;
6079 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
6080 sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
6083 /* kick off associate process */
6085 ifmgd->assoc_data = assoc_data;
6086 ifmgd->dtim_period = 0;
6087 ifmgd->have_beacon = false;
6089 /* override HT/VHT configuration only if the AP and we support it */
6090 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
6091 struct ieee80211_sta_ht_cap sta_ht_cap;
6093 if (req->flags & ASSOC_REQ_DISABLE_HT)
6096 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
6097 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
6099 /* check for 40 MHz disable override */
6100 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
6101 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
6102 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
6105 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
6106 req->flags & ASSOC_REQ_DISABLE_VHT)
6110 if (req->flags & ASSOC_REQ_DISABLE_HT) {
6111 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
6112 ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
6113 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
6114 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
6115 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
6118 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
6119 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
6120 ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
6123 if (req->flags & ASSOC_REQ_DISABLE_HE) {
6124 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
6125 ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
6126 ifmgd->flags |= IEEE80211_STA_DISABLE_EHT;
6129 err = ieee80211_prep_connection(sdata, req->bss, true, override);
6133 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
6134 if (ifmgd->powersave)
6135 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
6137 sdata->smps_mode = IEEE80211_SMPS_OFF;
6139 sdata->smps_mode = ifmgd->req_smps;
6143 beacon_ies = rcu_dereference(req->bss->beacon_ies);
6145 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
6148 * Wait up to one beacon interval ...
6149 * should this be more if we miss one?
6151 sdata_info(sdata, "waiting for beacon from %pM\n",
6153 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
6154 assoc_data->timeout_started = true;
6155 assoc_data->need_beacon = true;
6156 } else if (beacon_ies) {
6157 const struct element *elem;
6160 ieee80211_get_dtim(beacon_ies, &dtim_count,
6161 &ifmgd->dtim_period);
6163 ifmgd->have_beacon = true;
6164 assoc_data->timeout = jiffies;
6165 assoc_data->timeout_started = true;
6167 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6168 sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
6169 sdata->vif.bss_conf.sync_device_ts =
6170 bss->device_ts_beacon;
6171 sdata->vif.bss_conf.sync_dtim_count = dtim_count;
6174 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
6175 beacon_ies->data, beacon_ies->len);
6176 if (elem && elem->datalen >= 3)
6177 sdata->vif.bss_conf.profile_periodicity = elem->data[2];
6179 sdata->vif.bss_conf.profile_periodicity = 0;
6181 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
6182 beacon_ies->data, beacon_ies->len);
6183 if (elem && elem->datalen >= 11 &&
6184 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6185 sdata->vif.bss_conf.ema_ap = true;
6187 sdata->vif.bss_conf.ema_ap = false;
6189 assoc_data->timeout = jiffies;
6190 assoc_data->timeout_started = true;
6194 run_again(sdata, assoc_data->timeout);
6196 if (bss->corrupt_data) {
6197 char *corrupt_type = "data";
6198 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
6199 if (bss->corrupt_data &
6200 IEEE80211_BSS_CORRUPT_PROBE_RESP)
6201 corrupt_type = "beacon and probe response";
6203 corrupt_type = "beacon";
6204 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
6205 corrupt_type = "probe response";
6206 sdata_info(sdata, "associating with AP with corrupt %s\n",
6212 eth_zero_addr(ifmgd->bssid);
6213 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
6214 ifmgd->assoc_data = NULL;
6220 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
6221 struct cfg80211_deauth_request *req)
6223 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6224 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6225 bool tx = !req->local_state_change;
6226 struct ieee80211_prep_tx_info info = {
6227 .subtype = IEEE80211_STYPE_DEAUTH,
6230 if (ifmgd->auth_data &&
6231 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
6233 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
6234 req->bssid, req->reason_code,
6235 ieee80211_get_reason_code_string(req->reason_code));
6237 drv_mgd_prepare_tx(sdata->local, sdata, &info);
6238 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
6239 IEEE80211_STYPE_DEAUTH,
6240 req->reason_code, tx,
6242 ieee80211_destroy_auth_data(sdata, false);
6243 ieee80211_report_disconnect(sdata, frame_buf,
6244 sizeof(frame_buf), true,
6245 req->reason_code, false);
6246 drv_mgd_complete_tx(sdata->local, sdata, &info);
6250 if (ifmgd->assoc_data &&
6251 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
6253 "aborting association with %pM by local choice (Reason: %u=%s)\n",
6254 req->bssid, req->reason_code,
6255 ieee80211_get_reason_code_string(req->reason_code));
6257 drv_mgd_prepare_tx(sdata->local, sdata, &info);
6258 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
6259 IEEE80211_STYPE_DEAUTH,
6260 req->reason_code, tx,
6262 ieee80211_destroy_assoc_data(sdata, false, true);
6263 ieee80211_report_disconnect(sdata, frame_buf,
6264 sizeof(frame_buf), true,
6265 req->reason_code, false);
6269 if (ifmgd->associated &&
6270 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
6272 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
6273 req->bssid, req->reason_code,
6274 ieee80211_get_reason_code_string(req->reason_code));
6276 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6277 req->reason_code, tx, frame_buf);
6278 ieee80211_report_disconnect(sdata, frame_buf,
6279 sizeof(frame_buf), true,
6280 req->reason_code, false);
6281 drv_mgd_complete_tx(sdata->local, sdata, &info);
6288 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
6289 struct cfg80211_disassoc_request *req)
6291 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6293 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6296 * cfg80211 should catch this ... but it's racy since
6297 * we can receive a disassoc frame, process it, hand it
6298 * to cfg80211 while that's in a locked section already
6299 * trying to tell us that the user wants to disconnect.
6301 if (ifmgd->associated != req->bss)
6305 "disassociating from %pM by local choice (Reason: %u=%s)\n",
6306 req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
6308 memcpy(bssid, req->bss->bssid, ETH_ALEN);
6309 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
6310 req->reason_code, !req->local_state_change,
6313 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6314 req->reason_code, false);
6319 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
6321 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6324 * Make sure some work items will not run after this,
6325 * they will not do anything but might not have been
6326 * cancelled when disconnecting.
6328 cancel_work_sync(&ifmgd->monitor_work);
6329 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
6330 cancel_work_sync(&ifmgd->request_smps_work);
6331 cancel_work_sync(&ifmgd->csa_connection_drop_work);
6332 cancel_work_sync(&ifmgd->chswitch_work);
6333 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
6336 if (ifmgd->assoc_data) {
6337 struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
6338 ieee80211_destroy_assoc_data(sdata, false, false);
6339 cfg80211_assoc_timeout(sdata->dev, bss);
6341 if (ifmgd->auth_data)
6342 ieee80211_destroy_auth_data(sdata, false);
6343 spin_lock_bh(&ifmgd->teardown_lock);
6344 if (ifmgd->teardown_skb) {
6345 kfree_skb(ifmgd->teardown_skb);
6346 ifmgd->teardown_skb = NULL;
6347 ifmgd->orig_teardown_skb = NULL;
6349 kfree(ifmgd->assoc_req_ies);
6350 ifmgd->assoc_req_ies = NULL;
6351 ifmgd->assoc_req_ies_len = 0;
6352 spin_unlock_bh(&ifmgd->teardown_lock);
6353 del_timer_sync(&ifmgd->timer);
6354 sdata_unlock(sdata);
6357 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
6358 enum nl80211_cqm_rssi_threshold_event rssi_event,
6362 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6364 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
6366 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
6368 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
6370 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
6372 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6374 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
6376 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
6378 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);