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 - 2022 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;
145 static ieee80211_conn_flags_t
146 ieee80211_determine_chantype(struct ieee80211_link_data *link,
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_sub_if_data *sdata = link->sdata;
158 struct cfg80211_chan_def vht_chandef;
159 struct ieee80211_sta_ht_cap sta_ht_cap;
160 ieee80211_conn_flags_t ret;
163 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
164 chandef->chan = channel;
165 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
166 chandef->center_freq1 = channel->center_freq;
167 chandef->freq1_offset = channel->freq_offset;
169 if (channel->band == NL80211_BAND_6GHZ) {
170 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
173 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
174 ret = IEEE80211_CONN_DISABLE_HT |
175 IEEE80211_CONN_DISABLE_VHT |
176 IEEE80211_CONN_DISABLE_HE |
177 IEEE80211_CONN_DISABLE_EHT;
181 vht_chandef = *chandef;
183 } else if (sband->band == NL80211_BAND_S1GHZ) {
184 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
186 "Missing S1G Operation Element? Trying operating == primary\n");
187 chandef->width = ieee80211_s1g_channel_width(channel);
190 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
191 IEEE80211_CONN_DISABLE_VHT |
192 IEEE80211_CONN_DISABLE_80P80MHZ |
193 IEEE80211_CONN_DISABLE_160MHZ;
197 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
198 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
200 if (!ht_oper || !sta_ht_cap.ht_supported) {
201 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
202 ret = IEEE80211_CONN_DISABLE_HT |
203 IEEE80211_CONN_DISABLE_VHT |
204 IEEE80211_CONN_DISABLE_HE |
205 IEEE80211_CONN_DISABLE_EHT;
209 chandef->width = NL80211_CHAN_WIDTH_20;
211 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
213 /* check that channel matches the right operating channel */
214 if (!tracking && channel->center_freq != ht_cfreq) {
216 * It's possible that some APs are confused here;
217 * Netgear WNDR3700 sometimes reports 4 higher than
218 * the actual channel in association responses, but
219 * since we look at probe response/beacon data here
223 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
224 channel->center_freq, ht_cfreq,
225 ht_oper->primary_chan, channel->band);
226 ret = IEEE80211_CONN_DISABLE_HT |
227 IEEE80211_CONN_DISABLE_VHT |
228 IEEE80211_CONN_DISABLE_HE |
229 IEEE80211_CONN_DISABLE_EHT;
233 /* check 40 MHz support, if we have it */
234 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
235 ieee80211_chandef_ht_oper(ht_oper, chandef);
237 mlme_dbg(sdata, "40 MHz not supported\n");
238 /* 40 MHz (and 80 MHz) must be supported for VHT */
239 ret = IEEE80211_CONN_DISABLE_VHT;
240 /* also mark 40 MHz disabled */
241 ret |= IEEE80211_CONN_DISABLE_40MHZ;
245 if (!vht_oper || !sband->vht_cap.vht_supported) {
246 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
247 ret = IEEE80211_CONN_DISABLE_VHT;
251 vht_chandef = *chandef;
252 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
254 (le32_to_cpu(he_oper->he_oper_params) &
255 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
256 struct ieee80211_vht_operation he_oper_vht_cap;
259 * Set only first 3 bytes (other 2 aren't used in
260 * ieee80211_chandef_vht_oper() anyway)
262 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
263 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
265 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
266 &he_oper_vht_cap, ht_oper,
268 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE))
270 "HE AP VHT information is invalid, disabling HE\n");
271 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
274 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
278 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
280 "AP VHT information is invalid, disabling VHT\n");
281 ret = IEEE80211_CONN_DISABLE_VHT;
285 if (!cfg80211_chandef_valid(&vht_chandef)) {
286 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
288 "AP VHT information is invalid, disabling VHT\n");
289 ret = IEEE80211_CONN_DISABLE_VHT;
293 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
298 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
299 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
301 "AP VHT information doesn't match HT, disabling VHT\n");
302 ret = IEEE80211_CONN_DISABLE_VHT;
306 *chandef = vht_chandef;
309 * handle the case that the EHT operation indicates that it holds EHT
310 * operation information (in case that the channel width differs from
311 * the channel width reported in HT/VHT/HE).
313 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
314 struct cfg80211_chan_def eht_chandef = *chandef;
316 ieee80211_chandef_eht_oper(sdata, eht_oper,
318 NL80211_CHAN_WIDTH_160,
319 false, &eht_chandef);
321 if (!cfg80211_chandef_valid(&eht_chandef)) {
322 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT))
324 "AP EHT information is invalid, disabling EHT\n");
325 ret = IEEE80211_CONN_DISABLE_EHT;
329 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
330 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT))
332 "AP EHT information is incompatible, disabling EHT\n");
333 ret = IEEE80211_CONN_DISABLE_EHT;
337 *chandef = eht_chandef;
344 * When tracking the current AP, don't do any further checks if the
345 * new chandef is identical to the one we're currently using for the
346 * connection. This keeps us from playing ping-pong with regulatory,
347 * without it the following can happen (for example):
348 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
349 * - AP advertises regdom US
350 * - CRDA loads regdom US with 80 MHz prohibited (old database)
351 * - the code below detects an unsupported channel, downgrades, and
352 * we disconnect from the AP in the caller
353 * - disconnect causes CRDA to reload world regdomain and the game
355 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
357 * It seems possible that there are still scenarios with CSA or real
358 * bandwidth changes where a this could happen, but those cases are
359 * less common and wouldn't completely prevent using the AP.
362 cfg80211_chandef_identical(chandef, &link->conf->chandef))
365 /* don't print the message below for VHT mismatch if VHT is disabled */
366 if (ret & IEEE80211_CONN_DISABLE_VHT)
367 vht_chandef = *chandef;
370 * Ignore the DISABLED flag when we're already connected and only
371 * tracking the APs beacon for bandwidth changes - otherwise we
372 * might get disconnected here if we connect to an AP, update our
373 * regulatory information based on the AP's country IE and the
374 * information we have is wrong/outdated and disables the channel
375 * that we're actually using for the connection to the AP.
377 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
379 IEEE80211_CHAN_DISABLED)) {
380 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
381 ret = IEEE80211_CONN_DISABLE_HT |
382 IEEE80211_CONN_DISABLE_VHT |
383 IEEE80211_CONN_DISABLE_HE |
384 IEEE80211_CONN_DISABLE_EHT;
388 ret |= ieee80211_chandef_downgrade(chandef);
391 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
392 IEEE80211_CHAN_NO_HE))
393 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
395 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
396 IEEE80211_CHAN_NO_EHT))
397 ret |= IEEE80211_CONN_DISABLE_EHT;
399 if (chandef->width != vht_chandef.width && !tracking)
401 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
403 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
407 static int ieee80211_config_bw(struct ieee80211_link_data *link,
408 const struct ieee80211_ht_cap *ht_cap,
409 const struct ieee80211_vht_cap *vht_cap,
410 const struct ieee80211_ht_operation *ht_oper,
411 const struct ieee80211_vht_operation *vht_oper,
412 const struct ieee80211_he_operation *he_oper,
413 const struct ieee80211_eht_operation *eht_oper,
414 const struct ieee80211_s1g_oper_ie *s1g_oper,
415 const u8 *bssid, u32 *changed)
417 struct ieee80211_sub_if_data *sdata = link->sdata;
418 struct ieee80211_local *local = sdata->local;
419 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
420 struct ieee80211_channel *chan = link->conf->chandef.chan;
421 struct ieee80211_supported_band *sband =
422 local->hw.wiphy->bands[chan->band];
423 struct cfg80211_chan_def chandef;
425 ieee80211_conn_flags_t flags;
426 u32 vht_cap_info = 0;
429 /* if HT was/is disabled, don't track any bandwidth changes */
430 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
433 /* don't check VHT if we associated as non-VHT station */
434 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
437 /* don't check HE if we associated as non-HE station */
438 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
439 !ieee80211_get_he_iftype_cap(sband,
440 ieee80211_vif_type_p2p(&sdata->vif))) {
445 /* don't check EHT if we associated as non-EHT station */
446 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
447 !ieee80211_get_eht_iftype_cap(sband,
448 ieee80211_vif_type_p2p(&sdata->vif)))
452 * if bss configuration changed store the new one -
453 * this may be applicable even if channel is identical
455 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
456 if (link->conf->ht_operation_mode != ht_opmode) {
457 *changed |= BSS_CHANGED_HT;
458 link->conf->ht_operation_mode = ht_opmode;
462 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
464 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
465 flags = ieee80211_determine_chantype(link, sband, chan, vht_cap_info,
468 s1g_oper, &chandef, true);
471 * Downgrade the new channel if we associated with restricted
472 * capabilities. For example, if we associated as a 20 MHz STA
473 * to a 40 MHz AP (due to regulatory, capabilities or config
474 * reasons) then switching to a 40 MHz channel now won't do us
475 * any good -- we couldn't use it with the AP.
477 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
478 chandef.width == NL80211_CHAN_WIDTH_80P80)
479 flags |= ieee80211_chandef_downgrade(&chandef);
480 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
481 chandef.width == NL80211_CHAN_WIDTH_160)
482 flags |= ieee80211_chandef_downgrade(&chandef);
483 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
484 chandef.width > NL80211_CHAN_WIDTH_20)
485 flags |= ieee80211_chandef_downgrade(&chandef);
487 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
491 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
492 link->u.mgd.bssid, chandef.chan->center_freq,
493 chandef.chan->freq_offset, chandef.width,
494 chandef.center_freq1, chandef.freq1_offset,
495 chandef.center_freq2);
497 if (flags != (link->u.mgd.conn_flags &
498 (IEEE80211_CONN_DISABLE_HT |
499 IEEE80211_CONN_DISABLE_VHT |
500 IEEE80211_CONN_DISABLE_HE |
501 IEEE80211_CONN_DISABLE_EHT |
502 IEEE80211_CONN_DISABLE_40MHZ |
503 IEEE80211_CONN_DISABLE_80P80MHZ |
504 IEEE80211_CONN_DISABLE_160MHZ |
505 IEEE80211_CONN_DISABLE_320MHZ)) ||
506 !cfg80211_chandef_valid(&chandef)) {
508 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
509 link->u.mgd.bssid, flags, ifmgd->flags);
513 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
517 "AP %pM changed bandwidth to incompatible one - disconnect\n",
525 /* frame sending functions */
527 static void ieee80211_add_ht_ie(struct ieee80211_link_data *link,
528 struct sk_buff *skb, u8 ap_ht_param,
529 struct ieee80211_supported_band *sband,
530 struct ieee80211_channel *channel,
531 enum ieee80211_smps_mode smps)
533 struct ieee80211_sub_if_data *sdata = link->sdata;
535 u32 flags = channel->flags;
537 struct ieee80211_sta_ht_cap ht_cap;
539 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
541 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
542 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
544 /* determine capability flags */
547 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
548 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
549 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
550 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
551 cap &= ~IEEE80211_HT_CAP_SGI_40;
554 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
555 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
556 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
557 cap &= ~IEEE80211_HT_CAP_SGI_40;
563 * If 40 MHz was disabled associate as though we weren't
564 * capable of 40 MHz -- some broken APs will never fall
565 * back to trying to transmit in 20 MHz.
567 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
568 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
569 cap &= ~IEEE80211_HT_CAP_SGI_40;
572 /* set SM PS mode properly */
573 cap &= ~IEEE80211_HT_CAP_SM_PS;
575 case IEEE80211_SMPS_AUTOMATIC:
576 case IEEE80211_SMPS_NUM_MODES:
579 case IEEE80211_SMPS_OFF:
580 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
581 IEEE80211_HT_CAP_SM_PS_SHIFT;
583 case IEEE80211_SMPS_STATIC:
584 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
585 IEEE80211_HT_CAP_SM_PS_SHIFT;
587 case IEEE80211_SMPS_DYNAMIC:
588 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
589 IEEE80211_HT_CAP_SM_PS_SHIFT;
593 /* reserve and fill IE */
594 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
595 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
598 /* This function determines vht capability flags for the association
600 * Note - the function may set the owner of the MU-MIMO capability
602 static void ieee80211_add_vht_ie(struct ieee80211_link_data *link,
604 struct ieee80211_supported_band *sband,
605 struct ieee80211_vht_cap *ap_vht_cap)
607 struct ieee80211_sub_if_data *sdata = link->sdata;
608 struct ieee80211_local *local = sdata->local;
611 struct ieee80211_sta_vht_cap vht_cap;
612 u32 mask, ap_bf_sts, our_bf_sts;
614 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
616 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
617 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
619 /* determine capability flags */
622 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
623 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
625 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
626 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
627 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
628 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
631 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
632 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
633 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
637 * Some APs apparently get confused if our capabilities are better
638 * than theirs, so restrict what we advertise in the assoc request.
640 if (!(ap_vht_cap->vht_cap_info &
641 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
642 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
643 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
644 else if (!(ap_vht_cap->vht_cap_info &
645 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
646 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
649 * If some other vif is using the MU-MIMO capability we cannot associate
650 * using MU-MIMO - this will lead to contradictions in the group-id
652 * Ownership is defined since association request, in order to avoid
653 * simultaneous associations with MU-MIMO.
655 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
656 bool disable_mu_mimo = false;
657 struct ieee80211_sub_if_data *other;
659 list_for_each_entry_rcu(other, &local->interfaces, list) {
660 if (other->vif.bss_conf.mu_mimo_owner) {
661 disable_mu_mimo = true;
666 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
668 link->conf->mu_mimo_owner = true;
671 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
673 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
674 our_bf_sts = cap & mask;
676 if (ap_bf_sts < our_bf_sts) {
681 /* reserve and fill IE */
682 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
683 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
686 /* This function determines HE capability flags for the association
689 static void ieee80211_add_he_ie(struct ieee80211_link_data *link,
691 struct ieee80211_supported_band *sband)
693 struct ieee80211_sub_if_data *sdata = link->sdata;
694 u8 *pos, *pre_he_pos;
695 const struct ieee80211_sta_he_cap *he_cap = NULL;
696 struct ieee80211_chanctx_conf *chanctx_conf;
698 bool reg_cap = false;
701 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
702 if (!WARN_ON_ONCE(!chanctx_conf))
703 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
705 IEEE80211_CHAN_NO_HE);
709 he_cap = ieee80211_get_he_iftype_cap(sband,
710 ieee80211_vif_type_p2p(&sdata->vif));
711 if (!he_cap || !chanctx_conf || !reg_cap)
714 /* get a max size estimate */
716 2 + 1 + sizeof(he_cap->he_cap_elem) +
717 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
718 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
719 he_cap->he_cap_elem.phy_cap_info);
720 pos = skb_put(skb, he_cap_size);
722 pos = ieee80211_ie_build_he_cap(link->u.mgd.conn_flags,
723 pos, he_cap, pos + he_cap_size);
724 /* trim excess if any */
725 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
727 ieee80211_ie_build_he_6ghz_cap(sdata, skb);
730 static void ieee80211_add_eht_ie(struct ieee80211_link_data *link,
732 struct ieee80211_supported_band *sband)
734 struct ieee80211_sub_if_data *sdata = link->sdata;
736 const struct ieee80211_sta_he_cap *he_cap;
737 const struct ieee80211_sta_eht_cap *eht_cap;
738 struct ieee80211_chanctx_conf *chanctx_conf;
740 bool reg_cap = false;
743 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
744 if (!WARN_ON_ONCE(!chanctx_conf))
745 reg_cap = cfg80211_chandef_usable(sdata->wdev.wiphy,
747 IEEE80211_CHAN_NO_HE |
748 IEEE80211_CHAN_NO_EHT);
751 he_cap = ieee80211_get_he_iftype_cap(sband,
752 ieee80211_vif_type_p2p(&sdata->vif));
753 eht_cap = ieee80211_get_eht_iftype_cap(sband,
754 ieee80211_vif_type_p2p(&sdata->vif));
757 * EHT capabilities element is only added if the HE capabilities element
758 * was added so assume that 'he_cap' is valid and don't check it.
760 if (WARN_ON(!he_cap || !eht_cap || !reg_cap))
764 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
765 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
766 &eht_cap->eht_cap_elem) +
767 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
768 eht_cap->eht_cap_elem.phy_cap_info);
769 pos = skb_put(skb, eht_cap_size);
770 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size);
773 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
775 struct ieee80211_local *local = sdata->local;
776 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
777 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
779 struct ieee80211_mgmt *mgmt;
780 u8 *pos, qos_info, *ie_start;
781 size_t offset = 0, noffset;
782 int i, count, rates_len, supp_rates_len, shift;
784 struct ieee80211_supported_band *sband;
785 struct ieee80211_chanctx_conf *chanctx_conf;
786 struct ieee80211_channel *chan;
789 struct element *ext_capa = NULL;
790 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
791 const struct ieee80211_sband_iftype_data *iftd;
792 struct ieee80211_prep_tx_info info = {};
793 struct ieee80211_link_data *link = &sdata->deflink;
796 /* we know it's writable, cast away the const */
797 if (assoc_data->ie_len)
798 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
802 sdata_assert_lock(sdata);
805 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
806 if (WARN_ON(!chanctx_conf)) {
810 chan = chanctx_conf->def.chan;
812 sband = local->hw.wiphy->bands[chan->band];
813 shift = ieee80211_vif_get_shift(&sdata->vif);
815 if (assoc_data->supp_rates_len) {
817 * Get all rates supported by the device and the AP as
818 * some APs don't like getting a superset of their rates
819 * in the association request (e.g. D-Link DAP 1353 in
822 rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
823 assoc_data->supp_rates,
824 assoc_data->supp_rates_len,
828 * In case AP not provide any supported rates information
829 * before association, we send information element(s) with
830 * all rates that we support.
833 for (i = 0; i < sband->n_bitrates; i++) {
839 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
841 skb = alloc_skb(local->hw.extra_tx_headroom +
842 sizeof(*mgmt) + /* bit too much but doesn't matter */
843 2 + assoc_data->ssid_len + /* SSID */
844 4 + rates_len + /* (extended) rates */
845 4 + /* power capability */
846 2 + 2 * sband->n_channels + /* supported channels */
847 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
848 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
849 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
850 sizeof(struct ieee80211_he_mcs_nss_supp) +
851 IEEE80211_HE_PPE_THRES_MAX_LEN +
852 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa) +
853 assoc_data->ie_len + /* extra IEs */
854 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
856 (iftd ? iftd->vendor_elems.len : 0),
861 skb_reserve(skb, local->hw.extra_tx_headroom);
863 capab = WLAN_CAPABILITY_ESS;
865 if (sband->band == NL80211_BAND_2GHZ) {
866 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
867 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
870 if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
871 capab |= WLAN_CAPABILITY_PRIVACY;
873 if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
874 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
875 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
877 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
878 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
880 mgmt = skb_put_zero(skb, 24);
881 memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
882 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
883 memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
885 listen_int = cpu_to_le16(sband->band == NL80211_BAND_S1GHZ ?
886 ieee80211_encode_usf(local->hw.conf.listen_interval) :
887 local->hw.conf.listen_interval);
888 if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
890 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
891 IEEE80211_STYPE_REASSOC_REQ);
892 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
893 mgmt->u.reassoc_req.listen_interval = listen_int;
894 memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
896 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
899 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
900 IEEE80211_STYPE_ASSOC_REQ);
901 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
902 mgmt->u.assoc_req.listen_interval = listen_int;
903 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
907 pos = skb_put(skb, 2 + assoc_data->ssid_len);
909 *pos++ = WLAN_EID_SSID;
910 *pos++ = assoc_data->ssid_len;
911 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
913 if (sband->band == NL80211_BAND_S1GHZ)
916 /* add all rates which were marked to be used above */
917 supp_rates_len = rates_len;
918 if (supp_rates_len > 8)
921 pos = skb_put(skb, supp_rates_len + 2);
922 *pos++ = WLAN_EID_SUPP_RATES;
923 *pos++ = supp_rates_len;
926 for (i = 0; i < sband->n_bitrates; i++) {
927 if (BIT(i) & rates) {
928 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
936 if (rates_len > count) {
937 pos = skb_put(skb, rates_len - count + 2);
938 *pos++ = WLAN_EID_EXT_SUPP_RATES;
939 *pos++ = rates_len - count;
941 for (i++; i < sband->n_bitrates; i++) {
942 if (BIT(i) & rates) {
944 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
952 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
953 capab & WLAN_CAPABILITY_RADIO_MEASURE) {
954 pos = skb_put(skb, 4);
955 *pos++ = WLAN_EID_PWR_CAPABILITY;
957 *pos++ = 0; /* min tx power */
959 *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
963 * Per spec, we shouldn't include the list of channels if we advertise
964 * support for extended channel switching, but we've always done that;
965 * (for now?) apply this restriction only on the (new) 6 GHz band.
967 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
968 (sband->band != NL80211_BAND_6GHZ ||
969 !ext_capa || ext_capa->datalen < 1 ||
970 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
971 /* TODO: get this in reg domain format */
972 pos = skb_put(skb, 2 * sband->n_channels + 2);
973 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
974 *pos++ = 2 * sband->n_channels;
975 for (i = 0; i < sband->n_channels; i++) {
976 *pos++ = ieee80211_frequency_to_channel(
977 sband->channels[i].center_freq);
978 *pos++ = 1; /* one channel in the subband*/
982 /* Set MBSSID support for HE AP if needed */
983 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
984 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) && assoc_data->ie_len &&
985 ext_capa && ext_capa->datalen >= 3)
986 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
988 /* if present, add any custom IEs that go before HT */
989 if (assoc_data->ie_len) {
990 static const u8 before_ht[] = {
993 WLAN_EID_EXT_SUPP_RATES,
994 WLAN_EID_PWR_CAPABILITY,
995 WLAN_EID_SUPPORTED_CHANNELS,
998 WLAN_EID_RRM_ENABLED_CAPABILITIES,
999 WLAN_EID_MOBILITY_DOMAIN,
1000 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
1001 WLAN_EID_RIC_DATA, /* reassoc only */
1002 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
1004 static const u8 after_ric[] = {
1005 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
1006 WLAN_EID_HT_CAPABILITY,
1007 WLAN_EID_BSS_COEX_2040,
1008 /* luckily this is almost always there */
1009 WLAN_EID_EXT_CAPABILITY,
1010 WLAN_EID_QOS_TRAFFIC_CAPA,
1011 WLAN_EID_TIM_BCAST_REQ,
1012 WLAN_EID_INTERWORKING,
1013 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
1014 WLAN_EID_VHT_CAPABILITY,
1015 WLAN_EID_OPMODE_NOTIF,
1018 noffset = ieee80211_ie_split_ric(assoc_data->ie,
1021 ARRAY_SIZE(before_ht),
1023 ARRAY_SIZE(after_ric),
1025 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1029 if (WARN_ON_ONCE((link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
1030 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)))
1031 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
1033 if (sband->band != NL80211_BAND_6GHZ &&
1034 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
1035 ieee80211_add_ht_ie(link, skb, assoc_data->ap_ht_param,
1036 sband, chan, link->smps_mode);
1038 /* if present, add any custom IEs that go before VHT */
1039 if (assoc_data->ie_len) {
1040 static const u8 before_vht[] = {
1042 * no need to list the ones split off before HT
1045 WLAN_EID_BSS_COEX_2040,
1046 WLAN_EID_EXT_CAPABILITY,
1047 WLAN_EID_QOS_TRAFFIC_CAPA,
1048 WLAN_EID_TIM_BCAST_REQ,
1049 WLAN_EID_INTERWORKING,
1050 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
1053 /* RIC already taken above, so no need to handle here anymore */
1054 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
1055 before_vht, ARRAY_SIZE(before_vht),
1057 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1061 /* if present, add any custom IEs that go before HE */
1062 if (assoc_data->ie_len) {
1063 static const u8 before_he[] = {
1065 * no need to list the ones split off before VHT
1068 WLAN_EID_OPMODE_NOTIF,
1069 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
1071 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
1072 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
1073 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
1074 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
1075 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
1076 /* TODO: add 11ah/11aj/11ak elements */
1079 /* RIC already taken above, so no need to handle here anymore */
1080 noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
1081 before_he, ARRAY_SIZE(before_he),
1083 pos = skb_put(skb, noffset - offset);
1084 memcpy(pos, assoc_data->ie + offset, noffset - offset);
1088 if (sband->band != NL80211_BAND_6GHZ &&
1089 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
1090 ieee80211_add_vht_ie(link, skb, sband,
1091 &assoc_data->ap_vht_cap);
1094 * If AP doesn't support HT, mark HE and EHT as disabled.
1095 * If on the 5GHz band, make sure it supports VHT.
1097 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT ||
1098 (sband->band == NL80211_BAND_5GHZ &&
1099 link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
1100 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE |
1101 IEEE80211_CONN_DISABLE_EHT;
1103 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1104 ieee80211_add_he_ie(link, skb, sband);
1106 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT))
1107 ieee80211_add_eht_ie(link, skb, sband);
1110 /* if present, add any custom non-vendor IEs that go after HE */
1111 if (assoc_data->ie_len) {
1112 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1115 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1119 if (assoc_data->wmm) {
1120 if (assoc_data->uapsd) {
1121 qos_info = ifmgd->uapsd_queues;
1122 qos_info |= (ifmgd->uapsd_max_sp_len <<
1123 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1128 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1131 if (sband->band == NL80211_BAND_S1GHZ) {
1132 ieee80211_add_aid_request_ie(sdata, skb);
1133 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1136 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1137 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1139 /* add any remaining custom (i.e. vendor specific here) IEs */
1140 if (assoc_data->ie_len) {
1141 noffset = assoc_data->ie_len;
1142 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1145 if (assoc_data->fils_kek_len) {
1146 ret = fils_encrypt_assoc_req(skb, assoc_data);
1153 pos = skb_tail_pointer(skb);
1154 kfree(ifmgd->assoc_req_ies);
1155 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1156 if (!ifmgd->assoc_req_ies) {
1161 ifmgd->assoc_req_ies_len = pos - ie_start;
1163 drv_mgd_prepare_tx(local, sdata, &info);
1165 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1166 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1167 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1168 IEEE80211_TX_INTFL_MLME_CONN_TX;
1169 ieee80211_tx_skb(sdata, skb);
1174 void ieee80211_send_pspoll(struct ieee80211_local *local,
1175 struct ieee80211_sub_if_data *sdata)
1177 struct ieee80211_pspoll *pspoll;
1178 struct sk_buff *skb;
1180 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1184 pspoll = (struct ieee80211_pspoll *) skb->data;
1185 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1187 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1188 ieee80211_tx_skb(sdata, skb);
1191 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1192 struct ieee80211_sub_if_data *sdata,
1195 struct sk_buff *skb;
1196 struct ieee80211_hdr_3addr *nullfunc;
1197 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1199 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
1200 !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
1204 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1206 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1208 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1209 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1211 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1212 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1214 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1215 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1217 ieee80211_tx_skb(sdata, skb);
1220 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1221 struct ieee80211_sub_if_data *sdata)
1223 struct sk_buff *skb;
1224 struct ieee80211_hdr *nullfunc;
1227 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1230 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1234 skb_reserve(skb, local->hw.extra_tx_headroom);
1236 nullfunc = skb_put_zero(skb, 30);
1237 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1238 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1239 nullfunc->frame_control = fc;
1240 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1241 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1242 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1243 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1245 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1246 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1247 ieee80211_tx_skb(sdata, skb);
1250 /* spectrum management related things */
1251 static void ieee80211_chswitch_work(struct work_struct *work)
1253 struct ieee80211_link_data *link =
1254 container_of(work, struct ieee80211_link_data, u.mgd.chswitch_work);
1255 struct ieee80211_sub_if_data *sdata = link->sdata;
1256 struct ieee80211_local *local = sdata->local;
1257 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1260 if (!ieee80211_sdata_running(sdata))
1264 mutex_lock(&local->mtx);
1265 mutex_lock(&local->chanctx_mtx);
1267 if (!ifmgd->associated)
1270 if (!link->conf->csa_active)
1274 * using reservation isn't immediate as it may be deferred until later
1275 * with multi-vif. once reservation is complete it will re-schedule the
1276 * work with no reserved_chanctx so verify chandef to check if it
1277 * completed successfully
1280 if (link->reserved_chanctx) {
1282 * with multi-vif csa driver may call ieee80211_csa_finish()
1283 * many times while waiting for other interfaces to use their
1286 if (link->reserved_ready)
1289 ret = ieee80211_link_use_reserved_context(link);
1292 "failed to use reserved channel context, disconnecting (err=%d)\n",
1294 ieee80211_queue_work(&sdata->local->hw,
1295 &ifmgd->csa_connection_drop_work);
1302 if (!cfg80211_chandef_identical(&link->conf->chandef,
1303 &link->csa_chandef)) {
1305 "failed to finalize channel switch, disconnecting\n");
1306 ieee80211_queue_work(&sdata->local->hw,
1307 &ifmgd->csa_connection_drop_work);
1311 link->u.mgd.csa_waiting_bcn = true;
1313 ieee80211_sta_reset_beacon_monitor(sdata);
1314 ieee80211_sta_reset_conn_monitor(sdata);
1317 mutex_unlock(&local->chanctx_mtx);
1318 mutex_unlock(&local->mtx);
1319 sdata_unlock(sdata);
1322 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1324 struct ieee80211_sub_if_data *sdata = link->sdata;
1325 struct ieee80211_local *local = sdata->local;
1326 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1329 sdata_assert_lock(sdata);
1331 WARN_ON(!link->conf->csa_active);
1333 if (link->csa_block_tx) {
1334 ieee80211_wake_vif_queues(local, sdata,
1335 IEEE80211_QUEUE_STOP_REASON_CSA);
1336 link->csa_block_tx = false;
1339 link->conf->csa_active = false;
1340 link->u.mgd.csa_waiting_bcn = false;
1342 * If the CSA IE is still present on the beacon after the switch,
1343 * we need to consider it as a new CSA (possibly to self).
1345 link->u.mgd.beacon_crc_valid = false;
1347 ret = drv_post_channel_switch(sdata);
1350 "driver post channel switch failed, disconnecting\n");
1351 ieee80211_queue_work(&local->hw,
1352 &ifmgd->csa_connection_drop_work);
1356 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0);
1359 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1361 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1362 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1364 if (WARN_ON(sdata->vif.valid_links))
1367 trace_api_chswitch_done(sdata, success);
1370 "driver channel switch failed, disconnecting\n");
1371 ieee80211_queue_work(&sdata->local->hw,
1372 &ifmgd->csa_connection_drop_work);
1374 ieee80211_queue_work(&sdata->local->hw,
1375 &sdata->deflink.u.mgd.chswitch_work);
1378 EXPORT_SYMBOL(ieee80211_chswitch_done);
1380 static void ieee80211_chswitch_timer(struct timer_list *t)
1382 struct ieee80211_link_data *link =
1383 from_timer(link, t, u.mgd.chswitch_timer);
1385 ieee80211_queue_work(&link->sdata->local->hw,
1386 &link->u.mgd.chswitch_work);
1390 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1392 struct ieee80211_sub_if_data *sdata = link->sdata;
1393 struct ieee80211_local *local = sdata->local;
1395 if (!local->ops->abort_channel_switch)
1398 mutex_lock(&local->mtx);
1400 mutex_lock(&local->chanctx_mtx);
1401 ieee80211_link_unreserve_chanctx(link);
1402 mutex_unlock(&local->chanctx_mtx);
1404 if (link->csa_block_tx)
1405 ieee80211_wake_vif_queues(local, sdata,
1406 IEEE80211_QUEUE_STOP_REASON_CSA);
1408 link->csa_block_tx = false;
1409 link->conf->csa_active = false;
1411 mutex_unlock(&local->mtx);
1413 drv_abort_channel_switch(sdata);
1417 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1418 u64 timestamp, u32 device_timestamp,
1419 struct ieee802_11_elems *elems,
1422 struct ieee80211_sub_if_data *sdata = link->sdata;
1423 struct ieee80211_local *local = sdata->local;
1424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1425 struct cfg80211_bss *cbss = link->u.mgd.bss;
1426 struct ieee80211_chanctx_conf *conf;
1427 struct ieee80211_chanctx *chanctx;
1428 enum nl80211_band current_band;
1429 struct ieee80211_csa_ie csa_ie;
1430 struct ieee80211_channel_switch ch_switch;
1431 struct ieee80211_bss *bss;
1434 sdata_assert_lock(sdata);
1439 if (local->scanning)
1442 current_band = cbss->channel->band;
1443 bss = (void *)cbss->priv;
1444 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1446 link->u.mgd.conn_flags,
1447 link->u.mgd.bssid, &csa_ie);
1450 ch_switch.timestamp = timestamp;
1451 ch_switch.device_timestamp = device_timestamp;
1452 ch_switch.block_tx = csa_ie.mode;
1453 ch_switch.chandef = csa_ie.chandef;
1454 ch_switch.count = csa_ie.count;
1455 ch_switch.delay = csa_ie.max_switch_time;
1459 goto lock_and_drop_connection;
1461 if (beacon && link->conf->csa_active &&
1462 !link->u.mgd.csa_waiting_bcn) {
1464 ieee80211_sta_abort_chanswitch(link);
1466 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1468 } else if (link->conf->csa_active || res) {
1469 /* disregard subsequent announcements if already processing */
1473 if (link->conf->chandef.chan->band !=
1474 csa_ie.chandef.chan->band) {
1476 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1478 csa_ie.chandef.chan->center_freq,
1479 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1480 csa_ie.chandef.center_freq2);
1481 goto lock_and_drop_connection;
1484 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1485 IEEE80211_CHAN_DISABLED)) {
1487 "AP %pM switches to unsupported channel "
1488 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1491 csa_ie.chandef.chan->center_freq,
1492 csa_ie.chandef.chan->freq_offset,
1493 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1494 csa_ie.chandef.freq1_offset,
1495 csa_ie.chandef.center_freq2);
1496 goto lock_and_drop_connection;
1499 if (cfg80211_chandef_identical(&csa_ie.chandef,
1500 &link->conf->chandef) &&
1501 (!csa_ie.mode || !beacon)) {
1502 if (link->u.mgd.csa_ignored_same_chan)
1505 "AP %pM tries to chanswitch to same channel, ignore\n",
1507 link->u.mgd.csa_ignored_same_chan = true;
1512 * Drop all TDLS peers - either we disconnect or move to a different
1513 * channel from this point on. There's no telling what our peer will do.
1514 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1515 * have an incompatible wider chandef.
1517 ieee80211_teardown_tdls_peers(sdata);
1519 mutex_lock(&local->mtx);
1520 mutex_lock(&local->chanctx_mtx);
1521 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1522 lockdep_is_held(&local->chanctx_mtx));
1525 "no channel context assigned to vif?, disconnecting\n");
1526 goto drop_connection;
1529 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1531 if (local->use_chanctx &&
1532 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1534 "driver doesn't support chan-switch with channel contexts\n");
1535 goto drop_connection;
1538 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1540 "preparing for channel switch failed, disconnecting\n");
1541 goto drop_connection;
1544 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1545 chanctx->mode, false);
1548 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1550 goto drop_connection;
1552 mutex_unlock(&local->chanctx_mtx);
1554 link->conf->csa_active = true;
1555 link->csa_chandef = csa_ie.chandef;
1556 link->csa_block_tx = csa_ie.mode;
1557 link->u.mgd.csa_ignored_same_chan = false;
1558 link->u.mgd.beacon_crc_valid = false;
1560 if (link->csa_block_tx)
1561 ieee80211_stop_vif_queues(local, sdata,
1562 IEEE80211_QUEUE_STOP_REASON_CSA);
1563 mutex_unlock(&local->mtx);
1565 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1566 csa_ie.count, csa_ie.mode);
1568 if (local->ops->channel_switch) {
1569 /* use driver's channel switch callback */
1570 drv_channel_switch(local, sdata, &ch_switch);
1574 /* channel switch handled in software */
1575 if (csa_ie.count <= 1)
1576 ieee80211_queue_work(&local->hw, &link->u.mgd.chswitch_work);
1578 mod_timer(&link->u.mgd.chswitch_timer,
1579 TU_TO_EXP_TIME((csa_ie.count - 1) *
1580 cbss->beacon_interval));
1582 lock_and_drop_connection:
1583 mutex_lock(&local->mtx);
1584 mutex_lock(&local->chanctx_mtx);
1587 * This is just so that the disconnect flow will know that
1588 * we were trying to switch channel and failed. In case the
1589 * mode is 1 (we are not allowed to Tx), we will know not to
1590 * send a deauthentication frame. Those two fields will be
1591 * reset when the disconnection worker runs.
1593 link->conf->csa_active = true;
1594 link->csa_block_tx = csa_ie.mode;
1596 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1597 mutex_unlock(&local->chanctx_mtx);
1598 mutex_unlock(&local->mtx);
1602 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1603 struct ieee80211_channel *channel,
1604 const u8 *country_ie, u8 country_ie_len,
1605 const u8 *pwr_constr_elem,
1606 int *chan_pwr, int *pwr_reduction)
1608 struct ieee80211_country_ie_triplet *triplet;
1609 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1610 int i, chan_increment;
1611 bool have_chan_pwr = false;
1614 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1617 triplet = (void *)(country_ie + 3);
1618 country_ie_len -= 3;
1620 switch (channel->band) {
1624 case NL80211_BAND_2GHZ:
1625 case NL80211_BAND_60GHZ:
1626 case NL80211_BAND_LC:
1629 case NL80211_BAND_5GHZ:
1632 case NL80211_BAND_6GHZ:
1634 * In the 6 GHz band, the "maximum transmit power level"
1635 * field in the triplets is reserved, and thus will be
1636 * zero and we shouldn't use it to control TX power.
1637 * The actual TX power will be given in the transmit
1638 * power envelope element instead.
1644 while (country_ie_len >= 3) {
1645 u8 first_channel = triplet->chans.first_channel;
1647 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
1650 for (i = 0; i < triplet->chans.num_channels; i++) {
1651 if (first_channel + i * chan_increment == chan) {
1652 have_chan_pwr = true;
1653 *chan_pwr = triplet->chans.max_power;
1662 country_ie_len -= 3;
1665 if (have_chan_pwr && pwr_constr_elem)
1666 *pwr_reduction = *pwr_constr_elem;
1670 return have_chan_pwr;
1673 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
1674 struct ieee80211_channel *channel,
1675 const u8 *cisco_dtpc_ie,
1678 /* From practical testing, the first data byte of the DTPC element
1679 * seems to contain the requested dBm level, and the CLI on Cisco
1680 * APs clearly state the range is -127 to 127 dBm, which indicates
1681 * a signed byte, although it seemingly never actually goes negative.
1682 * The other byte seems to always be zero.
1684 *pwr_level = (__s8)cisco_dtpc_ie[4];
1687 static u32 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
1688 struct ieee80211_channel *channel,
1689 struct ieee80211_mgmt *mgmt,
1690 const u8 *country_ie, u8 country_ie_len,
1691 const u8 *pwr_constr_ie,
1692 const u8 *cisco_dtpc_ie)
1694 struct ieee80211_sub_if_data *sdata = link->sdata;
1695 bool has_80211h_pwr = false, has_cisco_pwr = false;
1696 int chan_pwr = 0, pwr_reduction_80211h = 0;
1697 int pwr_level_cisco, pwr_level_80211h;
1699 __le16 capab = mgmt->u.probe_resp.capab_info;
1701 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
1702 return 0; /* TODO */
1705 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
1706 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
1707 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
1708 sdata, channel, country_ie, country_ie_len,
1709 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
1711 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
1714 if (cisco_dtpc_ie) {
1715 ieee80211_find_cisco_dtpc(
1716 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
1717 has_cisco_pwr = true;
1720 if (!has_80211h_pwr && !has_cisco_pwr)
1723 /* If we have both 802.11h and Cisco DTPC, apply both limits
1724 * by picking the smallest of the two power levels advertised.
1726 if (has_80211h_pwr &&
1727 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
1728 new_ap_level = pwr_level_80211h;
1730 if (link->ap_power_level == new_ap_level)
1734 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
1735 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
1737 } else { /* has_cisco_pwr is always true here. */
1738 new_ap_level = pwr_level_cisco;
1740 if (link->ap_power_level == new_ap_level)
1744 "Limiting TX power to %d dBm as advertised by %pM\n",
1745 pwr_level_cisco, link->u.mgd.bssid);
1748 link->ap_power_level = new_ap_level;
1749 if (__ieee80211_recalc_txpower(sdata))
1750 return BSS_CHANGED_TXPOWER;
1755 static void ieee80211_enable_ps(struct ieee80211_local *local,
1756 struct ieee80211_sub_if_data *sdata)
1758 struct ieee80211_conf *conf = &local->hw.conf;
1761 * If we are scanning right now then the parameters will
1762 * take effect when scan finishes.
1764 if (local->scanning)
1767 if (conf->dynamic_ps_timeout > 0 &&
1768 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1769 mod_timer(&local->dynamic_ps_timer, jiffies +
1770 msecs_to_jiffies(conf->dynamic_ps_timeout));
1772 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
1773 ieee80211_send_nullfunc(local, sdata, true);
1775 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1776 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1779 conf->flags |= IEEE80211_CONF_PS;
1780 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1784 static void ieee80211_change_ps(struct ieee80211_local *local)
1786 struct ieee80211_conf *conf = &local->hw.conf;
1788 if (local->ps_sdata) {
1789 ieee80211_enable_ps(local, local->ps_sdata);
1790 } else if (conf->flags & IEEE80211_CONF_PS) {
1791 conf->flags &= ~IEEE80211_CONF_PS;
1792 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1793 del_timer_sync(&local->dynamic_ps_timer);
1794 cancel_work_sync(&local->dynamic_ps_enable_work);
1798 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
1800 struct ieee80211_local *local = sdata->local;
1801 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
1802 struct sta_info *sta = NULL;
1803 bool authorized = false;
1805 if (!mgd->powersave)
1811 if (!mgd->associated)
1814 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
1817 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
1818 !sdata->deflink.u.mgd.have_beacon)
1822 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
1824 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
1830 /* need to hold RTNL or interface lock */
1831 void ieee80211_recalc_ps(struct ieee80211_local *local)
1833 struct ieee80211_sub_if_data *sdata, *found = NULL;
1837 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
1838 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
1839 local->ps_sdata = NULL;
1843 list_for_each_entry(sdata, &local->interfaces, list) {
1844 if (!ieee80211_sdata_running(sdata))
1846 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1847 /* If an AP vif is found, then disable PS
1848 * by setting the count to zero thereby setting
1854 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1860 if (count == 1 && ieee80211_powersave_allowed(found)) {
1861 u8 dtimper = found->deflink.u.mgd.dtim_period;
1863 timeout = local->dynamic_ps_forced_timeout;
1866 local->hw.conf.dynamic_ps_timeout = timeout;
1868 /* If the TIM IE is invalid, pretend the value is 1 */
1872 local->hw.conf.ps_dtim_period = dtimper;
1873 local->ps_sdata = found;
1875 local->ps_sdata = NULL;
1878 ieee80211_change_ps(local);
1881 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
1883 bool ps_allowed = ieee80211_powersave_allowed(sdata);
1885 if (sdata->vif.cfg.ps != ps_allowed) {
1886 sdata->vif.cfg.ps = ps_allowed;
1887 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
1891 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
1893 struct ieee80211_local *local =
1894 container_of(work, struct ieee80211_local,
1895 dynamic_ps_disable_work);
1897 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1898 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1899 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1902 ieee80211_wake_queues_by_reason(&local->hw,
1903 IEEE80211_MAX_QUEUE_MAP,
1904 IEEE80211_QUEUE_STOP_REASON_PS,
1908 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
1910 struct ieee80211_local *local =
1911 container_of(work, struct ieee80211_local,
1912 dynamic_ps_enable_work);
1913 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
1914 struct ieee80211_if_managed *ifmgd;
1915 unsigned long flags;
1918 /* can only happen when PS was just disabled anyway */
1922 ifmgd = &sdata->u.mgd;
1924 if (local->hw.conf.flags & IEEE80211_CONF_PS)
1927 if (local->hw.conf.dynamic_ps_timeout > 0) {
1928 /* don't enter PS if TX frames are pending */
1929 if (drv_tx_frames_pending(local)) {
1930 mod_timer(&local->dynamic_ps_timer, jiffies +
1932 local->hw.conf.dynamic_ps_timeout));
1937 * transmission can be stopped by others which leads to
1938 * dynamic_ps_timer expiry. Postpone the ps timer if it
1939 * is not the actual idle state.
1941 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1942 for (q = 0; q < local->hw.queues; q++) {
1943 if (local->queue_stop_reasons[q]) {
1944 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1946 mod_timer(&local->dynamic_ps_timer, jiffies +
1948 local->hw.conf.dynamic_ps_timeout));
1952 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1955 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
1956 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1957 if (drv_tx_frames_pending(local)) {
1958 mod_timer(&local->dynamic_ps_timer, jiffies +
1960 local->hw.conf.dynamic_ps_timeout));
1962 ieee80211_send_nullfunc(local, sdata, true);
1963 /* Flush to get the tx status of nullfunc frame */
1964 ieee80211_flush_queues(local, sdata, false);
1968 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
1969 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
1970 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
1971 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
1972 local->hw.conf.flags |= IEEE80211_CONF_PS;
1973 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1977 void ieee80211_dynamic_ps_timer(struct timer_list *t)
1979 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
1981 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
1984 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
1986 struct delayed_work *delayed_work = to_delayed_work(work);
1987 struct ieee80211_link_data *link =
1988 container_of(delayed_work, struct ieee80211_link_data,
1989 dfs_cac_timer_work);
1990 struct cfg80211_chan_def chandef = link->conf->chandef;
1991 struct ieee80211_sub_if_data *sdata = link->sdata;
1993 mutex_lock(&sdata->local->mtx);
1994 if (sdata->wdev.cac_started) {
1995 ieee80211_link_release_channel(link);
1996 cfg80211_cac_event(sdata->dev, &chandef,
1997 NL80211_RADAR_CAC_FINISHED,
2000 mutex_unlock(&sdata->local->mtx);
2004 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2006 struct ieee80211_local *local = sdata->local;
2007 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2011 if (local->hw.queues < IEEE80211_NUM_ACS)
2014 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2015 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2017 unsigned long now = jiffies;
2019 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2020 tx_tspec->admitted_time &&
2021 time_after(now, tx_tspec->time_slice_start + HZ)) {
2022 tx_tspec->consumed_tx_time = 0;
2023 tx_tspec->time_slice_start = now;
2025 if (tx_tspec->downgraded)
2027 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2030 switch (tx_tspec->action) {
2031 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2032 /* take the original parameters */
2033 if (drv_conf_tx(local, &sdata->deflink, ac,
2034 &sdata->deflink.tx_conf[ac]))
2035 link_err(&sdata->deflink,
2036 "failed to set TX queue parameters for queue %d\n",
2038 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2039 tx_tspec->downgraded = false;
2042 case TX_TSPEC_ACTION_DOWNGRADE:
2043 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2044 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2048 /* downgrade next lower non-ACM AC */
2049 for (non_acm_ac = ac + 1;
2050 non_acm_ac < IEEE80211_NUM_ACS;
2052 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2054 /* Usually the loop will result in using BK even if it
2055 * requires admission control, but such a configuration
2056 * makes no sense and we have to transmit somehow - the
2057 * AC selection does the same thing.
2058 * If we started out trying to downgrade from BK, then
2059 * the extra condition here might be needed.
2061 if (non_acm_ac >= IEEE80211_NUM_ACS)
2062 non_acm_ac = IEEE80211_AC_BK;
2063 if (drv_conf_tx(local, &sdata->deflink, ac,
2064 &sdata->deflink.tx_conf[non_acm_ac]))
2065 link_err(&sdata->deflink,
2066 "failed to set TX queue parameters for queue %d\n",
2068 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2070 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2071 tx_tspec->time_slice_start + HZ - now + 1);
2073 case TX_TSPEC_ACTION_NONE:
2082 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2084 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2085 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2089 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2091 struct ieee80211_sub_if_data *sdata;
2093 sdata = container_of(work, struct ieee80211_sub_if_data,
2094 u.mgd.tx_tspec_wk.work);
2095 ieee80211_sta_handle_tspec_ac_params(sdata);
2100 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2101 struct ieee80211_link_data *link,
2102 const u8 *wmm_param, size_t wmm_param_len,
2103 const struct ieee80211_mu_edca_param_set *mu_edca)
2105 struct ieee80211_sub_if_data *sdata = link->sdata;
2106 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2107 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2109 int count, mu_edca_count, ac;
2111 u8 uapsd_queues = 0;
2113 if (!local->ops->conf_tx)
2116 if (local->hw.queues < IEEE80211_NUM_ACS)
2122 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2125 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2126 uapsd_queues = ifmgd->uapsd_queues;
2128 count = wmm_param[6] & 0x0f;
2129 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2130 * if mu_edca was preset before and now it disappeared tell
2131 * the driver about it.
2133 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2134 if (count == link->u.mgd.wmm_last_param_set &&
2135 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2137 link->u.mgd.wmm_last_param_set = count;
2138 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2140 pos = wmm_param + 8;
2141 left = wmm_param_len - 8;
2143 memset(¶ms, 0, sizeof(params));
2146 for (; left >= 4; left -= 4, pos += 4) {
2147 int aci = (pos[0] >> 5) & 0x03;
2148 int acm = (pos[0] >> 4) & 0x01;
2153 ac = IEEE80211_AC_BK;
2155 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2156 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2158 params[ac].mu_edca = !!mu_edca;
2160 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2163 ac = IEEE80211_AC_VI;
2165 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2166 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2168 params[ac].mu_edca = !!mu_edca;
2170 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2173 ac = IEEE80211_AC_VO;
2175 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2176 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2178 params[ac].mu_edca = !!mu_edca;
2180 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2184 ac = IEEE80211_AC_BE;
2186 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2187 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2189 params[ac].mu_edca = !!mu_edca;
2191 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2195 params[ac].aifs = pos[0] & 0x0f;
2197 if (params[ac].aifs < 2) {
2199 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2200 params[ac].aifs, aci);
2201 params[ac].aifs = 2;
2203 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2204 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2205 params[ac].txop = get_unaligned_le16(pos + 2);
2206 params[ac].acm = acm;
2207 params[ac].uapsd = uapsd;
2209 if (params[ac].cw_min == 0 ||
2210 params[ac].cw_min > params[ac].cw_max) {
2212 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2213 params[ac].cw_min, params[ac].cw_max, aci);
2216 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2219 /* WMM specification requires all 4 ACIs. */
2220 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2221 if (params[ac].cw_min == 0) {
2223 "AP has invalid WMM params (missing AC %d), using defaults\n",
2229 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2231 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2233 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2234 params[ac].txop, params[ac].uapsd,
2235 ifmgd->tx_tspec[ac].downgraded);
2236 link->tx_conf[ac] = params[ac];
2237 if (!ifmgd->tx_tspec[ac].downgraded &&
2238 drv_conf_tx(local, link, ac, ¶ms[ac]))
2240 "failed to set TX queue parameters for AC %d\n",
2244 /* enable WMM or activate new settings */
2245 link->conf->qos = true;
2249 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2251 lockdep_assert_held(&sdata->local->mtx);
2253 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2254 ieee80211_run_deferred_scan(sdata->local);
2257 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2259 mutex_lock(&sdata->local->mtx);
2260 __ieee80211_stop_poll(sdata);
2261 mutex_unlock(&sdata->local->mtx);
2264 static u32 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2265 u16 capab, bool erp_valid, u8 erp)
2267 struct ieee80211_bss_conf *bss_conf = link->conf;
2268 struct ieee80211_supported_band *sband;
2270 bool use_protection;
2271 bool use_short_preamble;
2272 bool use_short_slot;
2274 sband = ieee80211_get_link_sband(link);
2279 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2280 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2282 use_protection = false;
2283 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2286 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2287 if (sband->band == NL80211_BAND_5GHZ ||
2288 sband->band == NL80211_BAND_6GHZ)
2289 use_short_slot = true;
2291 if (use_protection != bss_conf->use_cts_prot) {
2292 bss_conf->use_cts_prot = use_protection;
2293 changed |= BSS_CHANGED_ERP_CTS_PROT;
2296 if (use_short_preamble != bss_conf->use_short_preamble) {
2297 bss_conf->use_short_preamble = use_short_preamble;
2298 changed |= BSS_CHANGED_ERP_PREAMBLE;
2301 if (use_short_slot != bss_conf->use_short_slot) {
2302 bss_conf->use_short_slot = use_short_slot;
2303 changed |= BSS_CHANGED_ERP_SLOT;
2309 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2310 struct cfg80211_bss *cbss,
2311 u32 bss_info_changed)
2313 struct ieee80211_bss *bss = (void *)cbss->priv;
2314 struct ieee80211_local *local = sdata->local;
2315 struct ieee80211_link_data *link = &sdata->deflink;
2316 struct ieee80211_bss_conf *bss_conf = link->conf;
2317 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2319 bss_info_changed |= BSS_CHANGED_ASSOC;
2320 bss_info_changed |= ieee80211_handle_bss_capability(link,
2321 bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
2323 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
2324 beacon_loss_count * bss_conf->beacon_int));
2326 sdata->u.mgd.associated = true;
2327 link->u.mgd.bss = cbss;
2328 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2329 memcpy(sdata->vif.cfg.ap_addr, cbss->bssid, ETH_ALEN);
2331 ieee80211_check_rate_mask(sdata);
2333 if (sdata->vif.p2p ||
2334 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2335 const struct cfg80211_bss_ies *ies;
2338 ies = rcu_dereference(cbss->ies);
2342 ret = cfg80211_get_p2p_attr(
2343 ies->data, ies->len,
2344 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2345 (u8 *) &bss_conf->p2p_noa_attr,
2346 sizeof(bss_conf->p2p_noa_attr));
2348 link->u.mgd.p2p_noa_index =
2349 bss_conf->p2p_noa_attr.index;
2350 bss_info_changed |= BSS_CHANGED_P2P_PS;
2356 /* just to be sure */
2357 ieee80211_stop_poll(sdata);
2359 ieee80211_led_assoc(local, 1);
2361 if (link->u.mgd.have_beacon) {
2363 * If the AP is buggy we may get here with no DTIM period
2364 * known, so assume it's 1 which is the only safe assumption
2365 * in that case, although if the TIM IE is broken powersave
2366 * probably just won't work at all.
2368 bss_conf->dtim_period = link->u.mgd.dtim_period ?: 1;
2369 bss_conf->beacon_rate = bss->beacon_rate;
2370 bss_info_changed |= BSS_CHANGED_BEACON_INFO;
2372 bss_conf->beacon_rate = NULL;
2373 bss_conf->dtim_period = 0;
2378 /* Tell the driver to monitor connection quality (if supported) */
2379 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2380 bss_conf->cqm_rssi_thold)
2381 bss_info_changed |= BSS_CHANGED_CQM;
2383 /* Enable ARP filtering */
2384 if (vif_cfg->arp_addr_cnt)
2385 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
2387 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
2389 mutex_lock(&local->iflist_mtx);
2390 ieee80211_recalc_ps(local);
2391 mutex_unlock(&local->iflist_mtx);
2393 ieee80211_recalc_smps(sdata, &sdata->deflink);
2394 ieee80211_recalc_ps_vif(sdata);
2396 netif_carrier_on(sdata->dev);
2399 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2400 u16 stype, u16 reason, bool tx,
2403 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2404 struct ieee80211_local *local = sdata->local;
2405 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
2406 struct ieee80211_link_data *link = &sdata->deflink;
2408 struct ieee80211_prep_tx_info info = {
2412 sdata_assert_lock(sdata);
2414 if (WARN_ON_ONCE(tx && !frame_buf))
2417 if (WARN_ON(!ifmgd->associated))
2420 ieee80211_stop_poll(sdata);
2422 ifmgd->associated = false;
2423 link->u.mgd.bss = NULL;
2424 netif_carrier_off(sdata->dev);
2427 * if we want to get out of ps before disassoc (why?) we have
2428 * to do it before sending disassoc, as otherwise the null-packet
2431 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2432 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2433 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2435 local->ps_sdata = NULL;
2437 /* disable per-vif ps */
2438 ieee80211_recalc_ps_vif(sdata);
2440 /* make sure ongoing transmission finishes */
2444 * drop any frame before deauth/disassoc, this can be data or
2445 * management frame. Since we are disconnecting, we should not
2446 * insist sending these frames which can take time and delay
2447 * the disconnection and possible the roaming.
2450 ieee80211_flush_queues(local, sdata, true);
2452 /* deauthenticate/disassociate now */
2453 if (tx || frame_buf) {
2455 * In multi channel scenarios guarantee that the virtual
2456 * interface is granted immediate airtime to transmit the
2457 * deauthentication frame by calling mgd_prepare_tx, if the
2458 * driver requested so.
2460 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2461 !link->u.mgd.have_beacon) {
2462 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2465 ieee80211_send_deauth_disassoc(sdata, link->u.mgd.bssid,
2466 link->u.mgd.bssid, stype, reason,
2470 /* flush out frame - make sure the deauth was actually sent */
2472 ieee80211_flush_queues(local, sdata, false);
2474 drv_mgd_complete_tx(sdata->local, sdata, &info);
2476 /* clear bssid only after building the needed mgmt frames */
2477 eth_zero_addr(link->u.mgd.bssid);
2479 eth_zero_addr(sdata->vif.cfg.ap_addr);
2480 sdata->vif.cfg.ssid_len = 0;
2482 /* remove AP and TDLS peers */
2483 sta_info_flush(sdata);
2485 /* finally reset all BSS / config parameters */
2486 changed |= ieee80211_reset_erp_info(sdata);
2488 ieee80211_led_assoc(local, 0);
2489 changed |= BSS_CHANGED_ASSOC;
2490 sdata->vif.cfg.assoc = false;
2492 link->u.mgd.p2p_noa_index = -1;
2493 memset(&link->conf->p2p_noa_attr, 0,
2494 sizeof(link->conf->p2p_noa_attr));
2496 /* on the next assoc, re-program HT/VHT parameters */
2497 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2498 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2499 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2500 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2502 /* reset MU-MIMO ownership and group data */
2503 memset(link->conf->mu_group.membership, 0,
2504 sizeof(link->conf->mu_group.membership));
2505 memset(link->conf->mu_group.position, 0,
2506 sizeof(link->conf->mu_group.position));
2507 changed |= BSS_CHANGED_MU_GROUPS;
2508 link->conf->mu_mimo_owner = false;
2510 link->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2512 del_timer_sync(&local->dynamic_ps_timer);
2513 cancel_work_sync(&local->dynamic_ps_enable_work);
2515 /* Disable ARP filtering */
2516 if (sdata->vif.cfg.arp_addr_cnt)
2517 changed |= BSS_CHANGED_ARP_FILTER;
2519 link->conf->qos = false;
2520 changed |= BSS_CHANGED_QOS;
2522 /* The BSSID (not really interesting) and HT changed */
2523 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2524 ieee80211_bss_info_change_notify(sdata, changed);
2526 /* disassociated - set to defaults now */
2527 ieee80211_set_wmm_default(&sdata->deflink, false, false);
2529 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2530 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2531 del_timer_sync(&sdata->u.mgd.timer);
2532 del_timer_sync(&link->u.mgd.chswitch_timer);
2534 link->conf->dtim_period = 0;
2535 link->conf->beacon_rate = NULL;
2537 link->u.mgd.have_beacon = false;
2538 link->u.mgd.tracking_signal_avg = false;
2539 link->u.mgd.disable_wmm_tracking = false;
2542 link->u.mgd.conn_flags = 0;
2543 mutex_lock(&local->mtx);
2544 ieee80211_link_release_channel(link);
2546 link->conf->csa_active = false;
2547 link->u.mgd.csa_waiting_bcn = false;
2548 link->u.mgd.csa_ignored_same_chan = false;
2549 if (link->csa_block_tx) {
2550 ieee80211_wake_vif_queues(local, sdata,
2551 IEEE80211_QUEUE_STOP_REASON_CSA);
2552 link->csa_block_tx = false;
2554 mutex_unlock(&local->mtx);
2556 /* existing TX TSPEC sessions no longer exist */
2557 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2558 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2560 bss_conf->pwr_reduction = 0;
2561 bss_conf->tx_pwr_env_num = 0;
2562 memset(bss_conf->tx_pwr_env, 0, sizeof(bss_conf->tx_pwr_env));
2565 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2567 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2568 struct ieee80211_local *local = sdata->local;
2570 mutex_lock(&local->mtx);
2571 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
2574 __ieee80211_stop_poll(sdata);
2576 mutex_lock(&local->iflist_mtx);
2577 ieee80211_recalc_ps(local);
2578 mutex_unlock(&local->iflist_mtx);
2580 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
2584 * We've received a probe response, but are not sure whether
2585 * we have or will be receiving any beacons or data, so let's
2586 * schedule the timers again, just in case.
2588 ieee80211_sta_reset_beacon_monitor(sdata);
2590 mod_timer(&ifmgd->conn_mon_timer,
2591 round_jiffies_up(jiffies +
2592 IEEE80211_CONNECTION_IDLE_TIME));
2594 mutex_unlock(&local->mtx);
2597 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
2598 struct ieee80211_hdr *hdr,
2601 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2604 struct ieee80211_sta_tx_tspec *tx_tspec;
2605 unsigned long now = jiffies;
2607 if (!ieee80211_is_data_qos(hdr->frame_control))
2610 tid = ieee80211_get_tid(hdr);
2611 ac = ieee80211_ac_from_tid(tid);
2612 tx_tspec = &ifmgd->tx_tspec[ac];
2614 if (likely(!tx_tspec->admitted_time))
2617 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2618 tx_tspec->consumed_tx_time = 0;
2619 tx_tspec->time_slice_start = now;
2621 if (tx_tspec->downgraded) {
2622 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
2623 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2627 if (tx_tspec->downgraded)
2630 tx_tspec->consumed_tx_time += tx_time;
2632 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
2633 tx_tspec->downgraded = true;
2634 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
2635 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
2639 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
2640 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
2642 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
2644 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
2645 !sdata->u.mgd.probe_send_count)
2649 sdata->u.mgd.probe_send_count = 0;
2651 sdata->u.mgd.nullfunc_failed = true;
2652 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
2655 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
2656 const u8 *src, const u8 *dst,
2657 const u8 *ssid, size_t ssid_len,
2658 struct ieee80211_channel *channel)
2660 struct sk_buff *skb;
2662 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
2663 ssid, ssid_len, NULL, 0,
2664 IEEE80211_PROBE_FLAG_DIRECTED);
2666 ieee80211_tx_skb(sdata, skb);
2669 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
2671 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2672 u8 *dst = sdata->vif.cfg.ap_addr;
2673 u8 unicast_limit = max(1, max_probe_tries - 3);
2674 struct sta_info *sta;
2676 if (WARN_ON(sdata->vif.valid_links))
2680 * Try sending broadcast probe requests for the last three
2681 * probe requests after the first ones failed since some
2682 * buggy APs only support broadcast probe requests.
2684 if (ifmgd->probe_send_count >= unicast_limit)
2688 * When the hardware reports an accurate Tx ACK status, it's
2689 * better to send a nullfunc frame instead of a probe request,
2690 * as it will kick us off the AP quickly if we aren't associated
2691 * anymore. The timeout will be reset if the frame is ACKed by
2694 ifmgd->probe_send_count++;
2697 mutex_lock(&sdata->local->sta_mtx);
2698 sta = sta_info_get(sdata, dst);
2700 ieee80211_check_fast_rx(sta);
2701 mutex_unlock(&sdata->local->sta_mtx);
2704 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
2705 ifmgd->nullfunc_failed = false;
2706 ieee80211_send_nullfunc(sdata->local, sdata, false);
2708 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
2709 sdata->vif.cfg.ssid,
2710 sdata->vif.cfg.ssid_len,
2711 sdata->deflink.u.mgd.bss->channel);
2714 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
2715 run_again(sdata, ifmgd->probe_timeout);
2718 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
2721 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2722 bool already = false;
2724 if (WARN_ON(sdata->vif.valid_links))
2727 if (!ieee80211_sdata_running(sdata))
2732 if (!ifmgd->associated)
2735 mutex_lock(&sdata->local->mtx);
2737 if (sdata->local->tmp_channel || sdata->local->scanning) {
2738 mutex_unlock(&sdata->local->mtx);
2742 if (sdata->local->suspending) {
2743 /* reschedule after resume */
2744 mutex_unlock(&sdata->local->mtx);
2745 ieee80211_reset_ap_probe(sdata);
2750 mlme_dbg_ratelimited(sdata,
2751 "detected beacon loss from AP (missed %d beacons) - probing\n",
2754 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
2758 * The driver/our work has already reported this event or the
2759 * connection monitoring has kicked in and we have already sent
2760 * a probe request. Or maybe the AP died and the driver keeps
2761 * reporting until we disassociate...
2763 * In either case we have to ignore the current call to this
2764 * function (except for setting the correct probe reason bit)
2765 * because otherwise we would reset the timer every time and
2766 * never check whether we received a probe response!
2768 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
2771 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
2773 mutex_unlock(&sdata->local->mtx);
2778 mutex_lock(&sdata->local->iflist_mtx);
2779 ieee80211_recalc_ps(sdata->local);
2780 mutex_unlock(&sdata->local->iflist_mtx);
2782 ifmgd->probe_send_count = 0;
2783 ieee80211_mgd_probe_ap_send(sdata);
2785 sdata_unlock(sdata);
2788 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
2789 struct ieee80211_vif *vif)
2791 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2792 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2793 struct cfg80211_bss *cbss;
2794 struct sk_buff *skb;
2795 const struct element *ssid;
2798 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
2799 sdata->vif.valid_links))
2802 sdata_assert_lock(sdata);
2804 if (ifmgd->associated)
2805 cbss = sdata->deflink.u.mgd.bss;
2806 else if (ifmgd->auth_data)
2807 cbss = ifmgd->auth_data->bss;
2808 else if (ifmgd->assoc_data)
2809 cbss = ifmgd->assoc_data->bss;
2814 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
2815 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
2816 "invalid SSID element (len=%d)",
2817 ssid ? ssid->datalen : -1))
2820 ssid_len = ssid->datalen;
2822 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
2823 (u32) -1, cbss->channel,
2824 ssid->data, ssid_len,
2825 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
2830 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
2832 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
2833 const u8 *buf, size_t len, bool tx,
2834 u16 reason, bool reconnect)
2836 struct ieee80211_event event = {
2838 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
2839 .u.mlme.reason = reason,
2843 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
2845 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
2847 drv_event_callback(sdata->local, sdata, &event);
2850 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
2852 struct ieee80211_local *local = sdata->local;
2853 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2854 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2858 if (!ifmgd->associated) {
2859 sdata_unlock(sdata);
2863 tx = !sdata->deflink.csa_block_tx;
2865 if (!ifmgd->driver_disconnect) {
2867 * AP is probably out of range (or not reachable for another
2868 * reason) so remove the bss struct for that AP.
2870 cfg80211_unlink_bss(local->hw.wiphy, sdata->deflink.u.mgd.bss);
2873 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2874 ifmgd->driver_disconnect ?
2875 WLAN_REASON_DEAUTH_LEAVING :
2876 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2878 mutex_lock(&local->mtx);
2879 sdata->vif.bss_conf.csa_active = false;
2880 sdata->deflink.u.mgd.csa_waiting_bcn = false;
2881 if (sdata->deflink.csa_block_tx) {
2882 ieee80211_wake_vif_queues(local, sdata,
2883 IEEE80211_QUEUE_STOP_REASON_CSA);
2884 sdata->deflink.csa_block_tx = false;
2886 mutex_unlock(&local->mtx);
2888 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
2889 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2891 ifmgd->reconnect = false;
2893 sdata_unlock(sdata);
2896 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
2898 struct ieee80211_sub_if_data *sdata =
2899 container_of(work, struct ieee80211_sub_if_data,
2900 u.mgd.beacon_connection_loss_work);
2901 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2903 if (ifmgd->connection_loss) {
2904 sdata_info(sdata, "Connection to AP %pM lost\n",
2905 sdata->vif.cfg.ap_addr);
2906 __ieee80211_disconnect(sdata);
2907 ifmgd->connection_loss = false;
2908 } else if (ifmgd->driver_disconnect) {
2910 "Driver requested disconnection from AP %pM\n",
2911 sdata->vif.cfg.ap_addr);
2912 __ieee80211_disconnect(sdata);
2913 ifmgd->driver_disconnect = false;
2915 if (ifmgd->associated)
2916 sdata->deflink.u.mgd.beacon_loss_count++;
2917 ieee80211_mgd_probe_ap(sdata, true);
2921 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
2923 struct ieee80211_sub_if_data *sdata =
2924 container_of(work, struct ieee80211_sub_if_data,
2925 u.mgd.csa_connection_drop_work);
2927 __ieee80211_disconnect(sdata);
2930 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
2932 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2933 struct ieee80211_hw *hw = &sdata->local->hw;
2935 trace_api_beacon_loss(sdata);
2937 sdata->u.mgd.connection_loss = false;
2938 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2940 EXPORT_SYMBOL(ieee80211_beacon_loss);
2942 void ieee80211_connection_loss(struct ieee80211_vif *vif)
2944 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2945 struct ieee80211_hw *hw = &sdata->local->hw;
2947 trace_api_connection_loss(sdata);
2949 sdata->u.mgd.connection_loss = true;
2950 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2952 EXPORT_SYMBOL(ieee80211_connection_loss);
2954 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
2956 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2957 struct ieee80211_hw *hw = &sdata->local->hw;
2959 trace_api_disconnect(sdata, reconnect);
2961 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2964 sdata->u.mgd.driver_disconnect = true;
2965 sdata->u.mgd.reconnect = reconnect;
2966 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2968 EXPORT_SYMBOL(ieee80211_disconnect);
2970 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
2973 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
2975 sdata_assert_lock(sdata);
2979 * we are not authenticated yet, the only timer that could be
2980 * running is the timeout for the authentication response which
2981 * which is not relevant anymore.
2983 del_timer_sync(&sdata->u.mgd.timer);
2984 sta_info_destroy_addr(sdata, auth_data->bss->bssid);
2986 /* FIXME: other links are destroyed? */
2987 sdata->deflink.u.mgd.conn_flags = 0;
2988 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2989 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2991 sdata->u.mgd.flags = 0;
2992 mutex_lock(&sdata->local->mtx);
2993 ieee80211_link_release_channel(&sdata->deflink);
2994 mutex_unlock(&sdata->local->mtx);
2997 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
2999 sdata->u.mgd.auth_data = NULL;
3009 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3010 enum assoc_status status)
3012 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3014 sdata_assert_lock(sdata);
3016 if (status != ASSOC_SUCCESS) {
3018 * we are not associated yet, the only timer that could be
3019 * running is the timeout for the association response which
3020 * which is not relevant anymore.
3022 del_timer_sync(&sdata->u.mgd.timer);
3023 sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
3025 /* FIXME: other links are destroyed? */
3026 sdata->deflink.u.mgd.conn_flags = 0;
3027 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3028 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3030 sdata->u.mgd.flags = 0;
3031 sdata->vif.bss_conf.mu_mimo_owner = false;
3033 mutex_lock(&sdata->local->mtx);
3034 ieee80211_link_release_channel(&sdata->deflink);
3035 mutex_unlock(&sdata->local->mtx);
3037 if (status != ASSOC_REJECTED) {
3038 struct cfg80211_assoc_failure data = {
3039 .bss[0] = assoc_data->bss,
3040 .timeout = status == ASSOC_TIMEOUT,
3043 cfg80211_assoc_failure(sdata->dev, &data);
3048 sdata->u.mgd.assoc_data = NULL;
3051 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3052 struct ieee80211_mgmt *mgmt, size_t len)
3054 struct ieee80211_local *local = sdata->local;
3055 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3056 const struct element *challenge;
3059 struct ieee80211_prep_tx_info info = {
3060 .subtype = IEEE80211_STYPE_AUTH,
3063 pos = mgmt->u.auth.variable;
3064 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3065 len - (pos - (u8 *)mgmt));
3068 auth_data->expected_transaction = 4;
3069 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3070 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3071 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3072 IEEE80211_TX_INTFL_MLME_CONN_TX;
3073 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3075 challenge->datalen + sizeof(*challenge),
3076 auth_data->bss->bssid, auth_data->bss->bssid,
3077 auth_data->key, auth_data->key_len,
3078 auth_data->key_idx, tx_flags);
3081 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata,
3084 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3085 struct sta_info *sta;
3088 sdata_info(sdata, "authenticated\n");
3089 ifmgd->auth_data->done = true;
3090 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3091 ifmgd->auth_data->timeout_started = true;
3092 run_again(sdata, ifmgd->auth_data->timeout);
3094 /* move station state to auth */
3095 mutex_lock(&sdata->local->sta_mtx);
3096 sta = sta_info_get(sdata, ap_addr);
3098 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3102 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3103 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3109 mutex_unlock(&sdata->local->sta_mtx);
3113 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3114 struct ieee80211_mgmt *mgmt, size_t len)
3116 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3118 u16 auth_alg, auth_transaction, status_code;
3119 struct ieee80211_event event = {
3121 .u.mlme.data = AUTH_EVENT,
3123 struct ieee80211_prep_tx_info info = {
3124 .subtype = IEEE80211_STYPE_AUTH,
3127 sdata_assert_lock(sdata);
3132 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3135 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
3137 if (!ether_addr_equal(bssid, mgmt->bssid))
3140 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3141 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3142 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3144 if (auth_alg != ifmgd->auth_data->algorithm ||
3145 (auth_alg != WLAN_AUTH_SAE &&
3146 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3147 (auth_alg == WLAN_AUTH_SAE &&
3148 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3149 auth_transaction > 2))) {
3150 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3151 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3153 ifmgd->auth_data->expected_transaction);
3157 if (status_code != WLAN_STATUS_SUCCESS) {
3158 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3160 if (auth_alg == WLAN_AUTH_SAE &&
3161 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3162 (auth_transaction == 1 &&
3163 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3164 status_code == WLAN_STATUS_SAE_PK)))) {
3165 /* waiting for userspace now */
3166 ifmgd->auth_data->waiting = true;
3167 ifmgd->auth_data->timeout =
3168 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3169 ifmgd->auth_data->timeout_started = true;
3170 run_again(sdata, ifmgd->auth_data->timeout);
3174 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3175 mgmt->sa, status_code);
3176 ieee80211_destroy_auth_data(sdata, false);
3177 event.u.mlme.status = MLME_DENIED;
3178 event.u.mlme.reason = status_code;
3179 drv_event_callback(sdata->local, sdata, &event);
3183 switch (ifmgd->auth_data->algorithm) {
3184 case WLAN_AUTH_OPEN:
3185 case WLAN_AUTH_LEAP:
3188 case WLAN_AUTH_FILS_SK:
3189 case WLAN_AUTH_FILS_SK_PFS:
3190 case WLAN_AUTH_FILS_PK:
3192 case WLAN_AUTH_SHARED_KEY:
3193 if (ifmgd->auth_data->expected_transaction != 4) {
3194 ieee80211_auth_challenge(sdata, mgmt, len);
3195 /* need another frame */
3200 WARN_ONCE(1, "invalid auth alg %d",
3201 ifmgd->auth_data->algorithm);
3205 event.u.mlme.status = MLME_SUCCESS;
3207 drv_event_callback(sdata->local, sdata, &event);
3208 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3209 (auth_transaction == 2 &&
3210 ifmgd->auth_data->expected_transaction == 2)) {
3211 if (!ieee80211_mark_sta_auth(sdata, bssid))
3212 return; /* ignore frame -- wait for timeout */
3213 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3214 auth_transaction == 2) {
3215 sdata_info(sdata, "SAE peer confirmed\n");
3216 ifmgd->auth_data->peer_confirmed = true;
3219 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3221 drv_mgd_complete_tx(sdata->local, sdata, &info);
3224 #define case_WLAN(type) \
3225 case WLAN_REASON_##type: return #type
3227 const char *ieee80211_get_reason_code_string(u16 reason_code)
3229 switch (reason_code) {
3230 case_WLAN(UNSPECIFIED);
3231 case_WLAN(PREV_AUTH_NOT_VALID);
3232 case_WLAN(DEAUTH_LEAVING);
3233 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3234 case_WLAN(DISASSOC_AP_BUSY);
3235 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3236 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3237 case_WLAN(DISASSOC_STA_HAS_LEFT);
3238 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3239 case_WLAN(DISASSOC_BAD_POWER);
3240 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3241 case_WLAN(INVALID_IE);
3242 case_WLAN(MIC_FAILURE);
3243 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3244 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3245 case_WLAN(IE_DIFFERENT);
3246 case_WLAN(INVALID_GROUP_CIPHER);
3247 case_WLAN(INVALID_PAIRWISE_CIPHER);
3248 case_WLAN(INVALID_AKMP);
3249 case_WLAN(UNSUPP_RSN_VERSION);
3250 case_WLAN(INVALID_RSN_IE_CAP);
3251 case_WLAN(IEEE8021X_FAILED);
3252 case_WLAN(CIPHER_SUITE_REJECTED);
3253 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3254 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3255 case_WLAN(DISASSOC_LOW_ACK);
3256 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3257 case_WLAN(QSTA_LEAVE_QBSS);
3258 case_WLAN(QSTA_NOT_USE);
3259 case_WLAN(QSTA_REQUIRE_SETUP);
3260 case_WLAN(QSTA_TIMEOUT);
3261 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3262 case_WLAN(MESH_PEER_CANCELED);
3263 case_WLAN(MESH_MAX_PEERS);
3264 case_WLAN(MESH_CONFIG);
3265 case_WLAN(MESH_CLOSE);
3266 case_WLAN(MESH_MAX_RETRIES);
3267 case_WLAN(MESH_CONFIRM_TIMEOUT);
3268 case_WLAN(MESH_INVALID_GTK);
3269 case_WLAN(MESH_INCONSISTENT_PARAM);
3270 case_WLAN(MESH_INVALID_SECURITY);
3271 case_WLAN(MESH_PATH_ERROR);
3272 case_WLAN(MESH_PATH_NOFORWARD);
3273 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3274 case_WLAN(MAC_EXISTS_IN_MBSS);
3275 case_WLAN(MESH_CHAN_REGULATORY);
3276 case_WLAN(MESH_CHAN);
3277 default: return "<unknown>";
3281 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3282 struct ieee80211_mgmt *mgmt, size_t len)
3284 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3285 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3287 sdata_assert_lock(sdata);
3292 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3293 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3297 if (ifmgd->associated &&
3298 ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid)) {
3299 const u8 *bssid = sdata->deflink.u.mgd.bssid;
3301 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3303 ieee80211_get_reason_code_string(reason_code));
3305 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3307 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3308 reason_code, false);
3312 if (ifmgd->assoc_data &&
3313 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
3314 const u8 *bssid = ifmgd->assoc_data->bss->bssid;
3317 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3319 ieee80211_get_reason_code_string(reason_code));
3321 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3323 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3329 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3330 struct ieee80211_mgmt *mgmt, size_t len)
3332 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3335 sdata_assert_lock(sdata);
3340 if (!ifmgd->associated ||
3341 !ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
3344 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3346 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3347 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3351 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3352 mgmt->sa, reason_code,
3353 ieee80211_get_reason_code_string(reason_code));
3355 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3357 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3361 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3362 u8 *supp_rates, unsigned int supp_rates_len,
3363 u32 *rates, u32 *basic_rates,
3364 bool *have_higher_than_11mbit,
3365 int *min_rate, int *min_rate_index,
3370 for (i = 0; i < supp_rates_len; i++) {
3371 int rate = supp_rates[i] & 0x7f;
3372 bool is_basic = !!(supp_rates[i] & 0x80);
3374 if ((rate * 5 * (1 << shift)) > 110)
3375 *have_higher_than_11mbit = true;
3378 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3379 * since they're not rates.
3381 * Note: Even though the membership selector and the basic
3382 * rate flag share the same bit, they are not exactly
3385 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3386 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3387 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3388 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3391 for (j = 0; j < sband->n_bitrates; j++) {
3392 struct ieee80211_rate *br;
3395 br = &sband->bitrates[j];
3397 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3398 if (brate == rate) {
3401 *basic_rates |= BIT(j);
3402 if ((rate * 5) < *min_rate) {
3403 *min_rate = rate * 5;
3404 *min_rate_index = j;
3412 static bool ieee80211_twt_req_supported(const struct link_sta_info *link_sta,
3413 const struct ieee802_11_elems *elems)
3415 if (elems->ext_capab_len < 10)
3418 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3421 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3422 IEEE80211_HE_MAC_CAP0_TWT_RES;
3425 static int ieee80211_recalc_twt_req(struct ieee80211_link_data *link,
3426 struct link_sta_info *link_sta,
3427 struct ieee802_11_elems *elems)
3429 bool twt = ieee80211_twt_req_supported(link_sta, elems);
3431 if (link->conf->twt_requester != twt) {
3432 link->conf->twt_requester = twt;
3433 return BSS_CHANGED_TWT;
3438 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3439 struct ieee80211_bss_conf *bss_conf,
3440 struct ieee80211_supported_band *sband,
3441 struct link_sta_info *link_sta)
3443 const struct ieee80211_sta_he_cap *own_he_cap =
3444 ieee80211_get_he_iftype_cap(sband,
3445 ieee80211_vif_type_p2p(&sdata->vif));
3447 return bss_conf->he_support &&
3448 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3449 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3451 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3452 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3455 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
3456 struct cfg80211_bss *cbss,
3457 struct ieee80211_mgmt *mgmt, size_t len,
3458 struct ieee802_11_elems *elems)
3460 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3461 struct ieee80211_local *local = sdata->local;
3462 struct ieee80211_supported_band *sband;
3463 struct link_sta_info *link_sta;
3464 struct sta_info *sta;
3465 u16 capab_info, aid;
3466 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
3467 const struct cfg80211_bss_ies *bss_ies = NULL;
3468 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3469 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3470 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3471 struct ieee80211_link_data *link = &sdata->deflink;
3477 /* AssocResp and ReassocResp have identical structure */
3479 pos = mgmt->u.assoc_resp.variable;
3480 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3482 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3485 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3486 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3487 mgmt->bssid, assoc_data->bss->bssid);
3492 if (elems->aid_resp)
3493 aid = le16_to_cpu(elems->aid_resp->aid);
3496 * The 5 MSB of the AID field are reserved
3497 * (802.11-2016 9.4.1.8 AID field)
3501 ifmgd->broken_ap = false;
3503 if (aid == 0 || aid > IEEE80211_MAX_AID) {
3504 sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
3507 ifmgd->broken_ap = true;
3510 if (!is_s1g && !elems->supp_rates) {
3511 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3516 sdata->vif.cfg.aid = aid;
3517 ifmgd->tdls_chan_switch_prohibited =
3518 elems->ext_capab && elems->ext_capab_len >= 5 &&
3519 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3522 * Some APs are erroneously not including some information in their
3523 * (re)association response frames. Try to recover by using the data
3524 * from the beacon or probe response. This seems to afflict mobile
3525 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3526 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3529 ((assoc_data->wmm && !elems->wmm_param) ||
3530 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
3531 (!elems->ht_cap_elem || !elems->ht_operation)) ||
3532 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
3533 (!elems->vht_cap_elem || !elems->vht_operation)))) {
3534 const struct cfg80211_bss_ies *ies;
3535 struct ieee802_11_elems *bss_elems;
3538 ies = rcu_dereference(cbss->ies);
3540 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
3548 bss_elems = ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
3550 assoc_data->bss->bssid);
3556 if (assoc_data->wmm &&
3557 !elems->wmm_param && bss_elems->wmm_param) {
3558 elems->wmm_param = bss_elems->wmm_param;
3560 "AP bug: WMM param missing from AssocResp\n");
3564 * Also check if we requested HT/VHT, otherwise the AP doesn't
3565 * have to include the IEs in the (re)association response.
3567 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
3568 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
3569 elems->ht_cap_elem = bss_elems->ht_cap_elem;
3571 "AP bug: HT capability missing from AssocResp\n");
3573 if (!elems->ht_operation && bss_elems->ht_operation &&
3574 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
3575 elems->ht_operation = bss_elems->ht_operation;
3577 "AP bug: HT operation missing from AssocResp\n");
3579 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
3580 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
3581 elems->vht_cap_elem = bss_elems->vht_cap_elem;
3583 "AP bug: VHT capa missing from AssocResp\n");
3585 if (!elems->vht_operation && bss_elems->vht_operation &&
3586 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
3587 elems->vht_operation = bss_elems->vht_operation;
3589 "AP bug: VHT operation missing from AssocResp\n");
3596 * We previously checked these in the beacon/probe response, so
3597 * they should be present here. This is just a safety net.
3599 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
3600 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
3602 "HT AP is missing WMM params or HT capability/operation\n");
3607 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
3608 (!elems->vht_cap_elem || !elems->vht_operation)) {
3610 "VHT AP is missing VHT capability/operation\n");
3615 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
3616 !elems->he_6ghz_capa) {
3618 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
3623 mutex_lock(&sdata->local->sta_mtx);
3625 * station info was already allocated and inserted before
3626 * the association and should be available to us
3628 sta = sta_info_get(sdata, cbss->bssid);
3629 if (WARN_ON(!sta)) {
3630 mutex_unlock(&sdata->local->sta_mtx);
3635 link_sta = rcu_dereference_protected(sta->link[link->link_id],
3636 lockdep_is_held(&local->sta_mtx));
3637 if (WARN_ON(!link_sta)) {
3638 mutex_unlock(&sdata->local->sta_mtx);
3643 sband = ieee80211_get_link_sband(link);
3645 mutex_unlock(&sdata->local->sta_mtx);
3650 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
3651 (!elems->he_cap || !elems->he_operation)) {
3652 mutex_unlock(&sdata->local->sta_mtx);
3654 "HE AP is missing HE capability/operation\n");
3659 /* Set up internal HT/VHT capabilities */
3660 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
3661 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
3665 if (elems->vht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
3666 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
3667 elems->vht_cap_elem,
3670 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
3672 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
3675 elems->he_6ghz_capa,
3678 bss_conf->he_support = link_sta->pub->he_cap.has_he;
3679 if (elems->rsnx && elems->rsnx_len &&
3680 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
3681 wiphy_ext_feature_isset(local->hw.wiphy,
3682 NL80211_EXT_FEATURE_PROTECTED_TWT))
3683 bss_conf->twt_protected = true;
3685 bss_conf->twt_protected = false;
3687 changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
3689 if (elems->eht_operation && elems->eht_cap &&
3690 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
3691 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
3698 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
3700 bss_conf->eht_support = false;
3703 bss_conf->he_support = false;
3704 bss_conf->twt_requester = false;
3705 bss_conf->twt_protected = false;
3706 bss_conf->eht_support = false;
3709 bss_conf->twt_broadcast =
3710 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
3712 if (bss_conf->he_support) {
3713 bss_conf->he_bss_color.color =
3714 le32_get_bits(elems->he_operation->he_oper_params,
3715 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
3716 bss_conf->he_bss_color.partial =
3717 le32_get_bits(elems->he_operation->he_oper_params,
3718 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
3719 bss_conf->he_bss_color.enabled =
3720 !le32_get_bits(elems->he_operation->he_oper_params,
3721 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
3723 if (bss_conf->he_bss_color.enabled)
3724 changed |= BSS_CHANGED_HE_BSS_COLOR;
3726 bss_conf->htc_trig_based_pkt_ext =
3727 le32_get_bits(elems->he_operation->he_oper_params,
3728 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
3729 bss_conf->frame_time_rts_th =
3730 le32_get_bits(elems->he_operation->he_oper_params,
3731 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
3733 bss_conf->uora_exists = !!elems->uora_element;
3734 if (elems->uora_element)
3735 bss_conf->uora_ocw_range = elems->uora_element[0];
3737 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
3738 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
3739 /* TODO: OPEN: what happens if BSS color disable is set? */
3742 if (cbss->transmitted_bss) {
3743 bss_conf->nontransmitted = true;
3744 ether_addr_copy(bss_conf->transmitter_bssid,
3745 cbss->transmitted_bss->bssid);
3746 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
3747 bss_conf->bssid_index = cbss->bssid_index;
3749 bss_conf->nontransmitted = false;
3750 memset(bss_conf->transmitter_bssid, 0,
3751 sizeof(bss_conf->transmitter_bssid));
3752 bss_conf->bssid_indicator = 0;
3753 bss_conf->bssid_index = 0;
3757 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
3758 * in their association response, so ignore that data for our own
3759 * configuration. If it changed since the last beacon, we'll get the
3760 * next beacon and update then.
3764 * If an operating mode notification IE is present, override the
3765 * NSS calculation (that would be done in rate_control_rate_init())
3766 * and use the # of streams from that element.
3768 if (elems->opmode_notif &&
3769 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
3772 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
3773 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
3775 link_sta->pub->rx_nss = nss;
3778 rate_control_rate_init(sta);
3780 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
3781 set_sta_flag(sta, WLAN_STA_MFP);
3782 sta->sta.mfp = true;
3784 sta->sta.mfp = false;
3787 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
3788 local->hw.queues >= IEEE80211_NUM_ACS;
3790 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
3791 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
3792 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
3795 "failed to move station %pM to desired state\n",
3797 WARN_ON(__sta_info_destroy(sta));
3798 mutex_unlock(&sdata->local->sta_mtx);
3803 if (sdata->wdev.use_4addr)
3804 drv_sta_set_4addr(local, sdata, &sta->sta, true);
3806 mutex_unlock(&sdata->local->sta_mtx);
3809 * Always handle WMM once after association regardless
3810 * of the first value the AP uses. Setting -1 here has
3811 * that effect because the AP values is an unsigned
3814 link->u.mgd.wmm_last_param_set = -1;
3815 link->u.mgd.mu_edca_last_param_set = -1;
3817 if (link->u.mgd.disable_wmm_tracking) {
3818 ieee80211_set_wmm_default(link, false, false);
3819 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
3820 elems->wmm_param_len,
3821 elems->mu_edca_param_set)) {
3822 /* still enable QoS since we might have HT/VHT */
3823 ieee80211_set_wmm_default(link, false, true);
3824 /* disable WMM tracking in this case to disable
3825 * tracking WMM parameter changes in the beacon if
3826 * the parameters weren't actually valid. Doing so
3827 * avoids changing parameters very strangely when
3828 * the AP is going back and forth between valid and
3829 * invalid parameters.
3831 link->u.mgd.disable_wmm_tracking = true;
3833 changed |= BSS_CHANGED_QOS;
3835 if (elems->max_idle_period_ie) {
3836 bss_conf->max_idle_period =
3837 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
3838 bss_conf->protected_keep_alive =
3839 !!(elems->max_idle_period_ie->idle_options &
3840 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
3841 changed |= BSS_CHANGED_KEEP_ALIVE;
3843 bss_conf->max_idle_period = 0;
3844 bss_conf->protected_keep_alive = false;
3847 /* set assoc capability (AID was already set earlier),
3848 * ieee80211_set_associated() will tell the driver */
3849 bss_conf->assoc_capability = capab_info;
3850 ieee80211_set_associated(sdata, cbss, changed);
3853 * If we're using 4-addr mode, let the AP know that we're
3854 * doing so, so that it can create the STA VLAN on its side
3856 if (ifmgd->use_4addr)
3857 ieee80211_send_4addr_nullfunc(local, sdata);
3860 * Start timer to probe the connection to the AP now.
3861 * Also start the timer that will detect beacon loss.
3863 ieee80211_sta_reset_beacon_monitor(sdata);
3864 ieee80211_sta_reset_conn_monitor(sdata);
3873 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
3874 struct ieee80211_mgmt *mgmt,
3877 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3878 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
3879 u16 capab_info, status_code, aid;
3880 struct ieee802_11_elems *elems;
3884 struct cfg80211_bss *cbss;
3885 struct ieee80211_event event = {
3887 .u.mlme.data = ASSOC_EVENT,
3889 struct ieee80211_prep_tx_info info = {};
3890 struct cfg80211_rx_assoc_resp resp = {
3894 sdata_assert_lock(sdata);
3899 if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
3902 cbss = assoc_data->bss;
3905 * AssocResp and ReassocResp have identical structure, so process both
3906 * of them in this function.
3912 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
3913 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3914 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
3915 pos = mgmt->u.assoc_resp.variable;
3916 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
3917 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
3918 pos = (u8 *) mgmt->u.s1g_assoc_resp.variable;
3923 * Note: this may not be perfect, AP might misbehave - if
3924 * anyone needs to rely on perfect complete notification
3925 * with the exact right subtype, then we need to track what
3926 * we actually transmitted.
3928 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
3929 IEEE80211_STYPE_ASSOC_REQ;
3932 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
3933 reassoc ? "Rea" : "A", mgmt->sa,
3934 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
3936 if (assoc_data->fils_kek_len &&
3937 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
3940 elems = ieee802_11_parse_elems(pos, len - (pos - (u8 *)mgmt), false,
3941 mgmt->bssid, assoc_data->bss->bssid);
3945 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
3946 elems->timeout_int &&
3947 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
3950 cfg80211_assoc_comeback(sdata->dev, assoc_data->bss->bssid,
3951 le32_to_cpu(elems->timeout_int->value));
3953 tu = le32_to_cpu(elems->timeout_int->value);
3954 ms = tu * 1024 / 1000;
3956 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
3958 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
3959 assoc_data->timeout_started = true;
3960 if (ms > IEEE80211_ASSOC_TIMEOUT)
3961 run_again(sdata, assoc_data->timeout);
3965 if (status_code != WLAN_STATUS_SUCCESS) {
3966 sdata_info(sdata, "%pM denied association (code=%d)\n",
3967 mgmt->sa, status_code);
3968 ieee80211_destroy_assoc_data(sdata, ASSOC_REJECTED);
3969 event.u.mlme.status = MLME_DENIED;
3970 event.u.mlme.reason = status_code;
3971 drv_event_callback(sdata->local, sdata, &event);
3973 if (!ieee80211_assoc_success(sdata, cbss, mgmt, len, elems)) {
3974 /* oops -- internal error -- send timeout for now */
3975 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
3978 event.u.mlme.status = MLME_SUCCESS;
3979 drv_event_callback(sdata->local, sdata, &event);
3980 sdata_info(sdata, "associated\n");
3983 * destroy assoc_data afterwards, as otherwise an idle
3984 * recalc after assoc_data is NULL but before associated
3985 * is set can cause the interface to go idle
3987 ieee80211_destroy_assoc_data(sdata, ASSOC_SUCCESS);
3989 /* get uapsd queues configuration */
3990 resp.uapsd_queues = 0;
3991 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
3992 if (sdata->deflink.tx_conf[ac].uapsd)
3993 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
3998 resp.links[0].bss = cbss;
3999 resp.buf = (u8 *)mgmt;
4001 resp.req_ies = ifmgd->assoc_req_ies;
4002 resp.req_ies_len = ifmgd->assoc_req_ies_len;
4003 cfg80211_rx_assoc_resp(sdata->dev, &resp);
4005 drv_mgd_complete_tx(sdata->local, sdata, &info);
4009 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
4010 struct ieee80211_mgmt *mgmt, size_t len,
4011 struct ieee80211_rx_status *rx_status)
4013 struct ieee80211_sub_if_data *sdata = link->sdata;
4014 struct ieee80211_local *local = sdata->local;
4015 struct ieee80211_bss *bss;
4016 struct ieee80211_channel *channel;
4018 sdata_assert_lock(sdata);
4020 channel = ieee80211_get_channel_khz(local->hw.wiphy,
4021 ieee80211_rx_status_to_khz(rx_status));
4025 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
4027 link->conf->beacon_rate = bss->beacon_rate;
4028 ieee80211_rx_bss_put(local, bss);
4033 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
4034 struct sk_buff *skb)
4036 struct ieee80211_sub_if_data *sdata = link->sdata;
4037 struct ieee80211_mgmt *mgmt = (void *)skb->data;
4038 struct ieee80211_if_managed *ifmgd;
4039 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
4040 struct ieee80211_channel *channel;
4041 size_t baselen, len = skb->len;
4043 ifmgd = &sdata->u.mgd;
4045 sdata_assert_lock(sdata);
4048 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
4049 * "If a 6 GHz AP receives a Probe Request frame and responds with
4050 * a Probe Response frame [..], the Address 1 field of the Probe
4051 * Response frame shall be set to the broadcast address [..]"
4052 * So, on 6GHz band we should also accept broadcast responses.
4054 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
4059 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
4060 (channel->band != NL80211_BAND_6GHZ ||
4061 !is_broadcast_ether_addr(mgmt->da)))
4062 return; /* ignore ProbeResp to foreign address */
4064 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
4068 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
4070 if (ifmgd->associated &&
4071 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
4072 ieee80211_reset_ap_probe(sdata);
4076 * This is the canonical list of information elements we care about,
4077 * the filter code also gives us all changes to the Microsoft OUI
4078 * (00:50:F2) vendor IE which is used for WMM which we need to track,
4079 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
4080 * changes to requested client power.
4082 * We implement beacon filtering in software since that means we can
4083 * avoid processing the frame here and in cfg80211, and userspace
4084 * will not be able to tell whether the hardware supports it or not.
4086 * XXX: This list needs to be dynamic -- userspace needs to be able to
4087 * add items it requires. It also needs to be able to tell us to
4088 * look out for other vendor IEs.
4090 static const u64 care_about_ies =
4091 (1ULL << WLAN_EID_COUNTRY) |
4092 (1ULL << WLAN_EID_ERP_INFO) |
4093 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
4094 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
4095 (1ULL << WLAN_EID_HT_CAPABILITY) |
4096 (1ULL << WLAN_EID_HT_OPERATION) |
4097 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
4099 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
4100 struct ieee80211_if_managed *ifmgd,
4101 struct ieee80211_bss_conf *bss_conf,
4102 struct ieee80211_local *local,
4103 struct ieee80211_rx_status *rx_status)
4105 struct ieee80211_sub_if_data *sdata = link->sdata;
4107 /* Track average RSSI from the Beacon frames of the current AP */
4109 if (!link->u.mgd.tracking_signal_avg) {
4110 link->u.mgd.tracking_signal_avg = true;
4111 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
4112 link->u.mgd.last_cqm_event_signal = 0;
4113 link->u.mgd.count_beacon_signal = 1;
4114 link->u.mgd.last_ave_beacon_signal = 0;
4116 link->u.mgd.count_beacon_signal++;
4119 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
4120 -rx_status->signal);
4122 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
4123 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
4124 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
4125 int last_sig = link->u.mgd.last_ave_beacon_signal;
4126 struct ieee80211_event event = {
4131 * if signal crosses either of the boundaries, invoke callback
4132 * with appropriate parameters
4134 if (sig > ifmgd->rssi_max_thold &&
4135 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
4136 link->u.mgd.last_ave_beacon_signal = sig;
4137 event.u.rssi.data = RSSI_EVENT_HIGH;
4138 drv_event_callback(local, sdata, &event);
4139 } else if (sig < ifmgd->rssi_min_thold &&
4140 (last_sig >= ifmgd->rssi_max_thold ||
4142 link->u.mgd.last_ave_beacon_signal = sig;
4143 event.u.rssi.data = RSSI_EVENT_LOW;
4144 drv_event_callback(local, sdata, &event);
4148 if (bss_conf->cqm_rssi_thold &&
4149 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
4150 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
4151 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
4152 int last_event = link->u.mgd.last_cqm_event_signal;
4153 int thold = bss_conf->cqm_rssi_thold;
4154 int hyst = bss_conf->cqm_rssi_hyst;
4157 (last_event == 0 || sig < last_event - hyst)) {
4158 link->u.mgd.last_cqm_event_signal = sig;
4159 ieee80211_cqm_rssi_notify(
4161 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
4163 } else if (sig > thold &&
4164 (last_event == 0 || sig > last_event + hyst)) {
4165 link->u.mgd.last_cqm_event_signal = sig;
4166 ieee80211_cqm_rssi_notify(
4168 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
4173 if (bss_conf->cqm_rssi_low &&
4174 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
4175 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
4176 int last_event = link->u.mgd.last_cqm_event_signal;
4177 int low = bss_conf->cqm_rssi_low;
4178 int high = bss_conf->cqm_rssi_high;
4181 (last_event == 0 || last_event >= low)) {
4182 link->u.mgd.last_cqm_event_signal = sig;
4183 ieee80211_cqm_rssi_notify(
4185 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
4187 } else if (sig > high &&
4188 (last_event == 0 || last_event <= high)) {
4189 link->u.mgd.last_cqm_event_signal = sig;
4190 ieee80211_cqm_rssi_notify(
4192 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
4198 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
4199 struct cfg80211_bss *bss)
4201 if (ether_addr_equal(tx_bssid, bss->bssid))
4203 if (!bss->transmitted_bss)
4205 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
4208 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
4209 struct ieee80211_hdr *hdr, size_t len,
4210 struct ieee80211_rx_status *rx_status)
4212 struct ieee80211_sub_if_data *sdata = link->sdata;
4213 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4214 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
4215 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
4216 struct ieee80211_mgmt *mgmt = (void *) hdr;
4218 struct ieee802_11_elems *elems;
4219 struct ieee80211_local *local = sdata->local;
4220 struct ieee80211_chanctx_conf *chanctx_conf;
4221 struct ieee80211_channel *chan;
4222 struct link_sta_info *link_sta;
4223 struct sta_info *sta;
4228 u8 *bssid, *variable = mgmt->u.beacon.variable;
4229 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
4231 sdata_assert_lock(sdata);
4233 /* Process beacon from the current BSS */
4234 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
4235 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
4236 struct ieee80211_ext *ext = (void *) mgmt;
4238 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
4239 variable = ext->u.s1g_short_beacon.variable;
4241 variable = ext->u.s1g_beacon.variable;
4244 baselen = (u8 *) variable - (u8 *) mgmt;
4249 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
4250 if (!chanctx_conf) {
4255 if (ieee80211_rx_status_to_khz(rx_status) !=
4256 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
4260 chan = chanctx_conf->def.chan;
4263 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
4264 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->bss)) {
4265 elems = ieee802_11_parse_elems(variable, len - baselen, false,
4267 ifmgd->assoc_data->bss->bssid);
4271 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
4273 if (elems->dtim_period)
4274 link->u.mgd.dtim_period = elems->dtim_period;
4275 link->u.mgd.have_beacon = true;
4276 ifmgd->assoc_data->need_beacon = false;
4277 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
4278 link->conf->sync_tsf =
4279 le64_to_cpu(mgmt->u.beacon.timestamp);
4280 link->conf->sync_device_ts =
4281 rx_status->device_timestamp;
4282 link->conf->sync_dtim_count = elems->dtim_count;
4285 if (elems->mbssid_config_ie)
4286 bss_conf->profile_periodicity =
4287 elems->mbssid_config_ie->profile_periodicity;
4289 bss_conf->profile_periodicity = 0;
4291 if (elems->ext_capab_len >= 11 &&
4292 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
4293 bss_conf->ema_ap = true;
4295 bss_conf->ema_ap = false;
4297 /* continue assoc process */
4298 ifmgd->assoc_data->timeout = jiffies;
4299 ifmgd->assoc_data->timeout_started = true;
4300 run_again(sdata, ifmgd->assoc_data->timeout);
4305 if (!ifmgd->associated ||
4306 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
4308 bssid = link->u.mgd.bssid;
4310 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
4311 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
4314 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
4315 mlme_dbg_ratelimited(sdata,
4316 "cancelling AP probe due to a received beacon\n");
4317 ieee80211_reset_ap_probe(sdata);
4321 * Push the beacon loss detection into the future since
4322 * we are processing a beacon from the AP just now.
4324 ieee80211_sta_reset_beacon_monitor(sdata);
4326 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
4327 * element (which carries the beacon interval). Don't forget to add a
4328 * bit to care_about_ies[] above if mac80211 is interested in a
4329 * changing S1G element.
4331 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4332 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
4333 elems = ieee802_11_parse_elems_crc(variable, len - baselen,
4334 false, care_about_ies, ncrc,
4335 mgmt->bssid, bssid);
4340 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
4341 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
4342 if (local->hw.conf.dynamic_ps_timeout > 0) {
4343 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
4344 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
4345 ieee80211_hw_config(local,
4346 IEEE80211_CONF_CHANGE_PS);
4348 ieee80211_send_nullfunc(local, sdata, false);
4349 } else if (!local->pspolling && sdata->u.mgd.powersave) {
4350 local->pspolling = true;
4353 * Here is assumed that the driver will be
4354 * able to send ps-poll frame and receive a
4355 * response even though power save mode is
4356 * enabled, but some drivers might require
4357 * to disable power save here. This needs
4358 * to be investigated.
4360 ieee80211_send_pspoll(local, sdata);
4364 if (sdata->vif.p2p ||
4365 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
4366 struct ieee80211_p2p_noa_attr noa = {};
4369 ret = cfg80211_get_p2p_attr(variable,
4371 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4372 (u8 *) &noa, sizeof(noa));
4374 if (link->u.mgd.p2p_noa_index != noa.index) {
4375 /* valid noa_attr and index changed */
4376 link->u.mgd.p2p_noa_index = noa.index;
4377 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
4378 changed |= BSS_CHANGED_P2P_PS;
4380 * make sure we update all information, the CRC
4381 * mechanism doesn't look at P2P attributes.
4383 link->u.mgd.beacon_crc_valid = false;
4385 } else if (link->u.mgd.p2p_noa_index != -1) {
4386 /* noa_attr not found and we had valid noa_attr before */
4387 link->u.mgd.p2p_noa_index = -1;
4388 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
4389 changed |= BSS_CHANGED_P2P_PS;
4390 link->u.mgd.beacon_crc_valid = false;
4394 if (link->u.mgd.csa_waiting_bcn)
4395 ieee80211_chswitch_post_beacon(link);
4398 * Update beacon timing and dtim count on every beacon appearance. This
4399 * will allow the driver to use the most updated values. Do it before
4400 * comparing this one with last received beacon.
4401 * IMPORTANT: These parameters would possibly be out of sync by the time
4402 * the driver will use them. The synchronized view is currently
4403 * guaranteed only in certain callbacks.
4405 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
4406 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
4407 link->conf->sync_tsf =
4408 le64_to_cpu(mgmt->u.beacon.timestamp);
4409 link->conf->sync_device_ts =
4410 rx_status->device_timestamp;
4411 link->conf->sync_dtim_count = elems->dtim_count;
4414 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
4415 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
4417 link->u.mgd.beacon_crc = ncrc;
4418 link->u.mgd.beacon_crc_valid = true;
4420 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
4422 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
4423 rx_status->device_timestamp,
4426 if (!link->u.mgd.disable_wmm_tracking &&
4427 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4428 elems->wmm_param_len,
4429 elems->mu_edca_param_set))
4430 changed |= BSS_CHANGED_QOS;
4433 * If we haven't had a beacon before, tell the driver about the
4434 * DTIM period (and beacon timing if desired) now.
4436 if (!link->u.mgd.have_beacon) {
4437 /* a few bogus AP send dtim_period = 0 or no TIM IE */
4438 bss_conf->dtim_period = elems->dtim_period ?: 1;
4440 changed |= BSS_CHANGED_BEACON_INFO;
4441 link->u.mgd.have_beacon = true;
4443 mutex_lock(&local->iflist_mtx);
4444 ieee80211_recalc_ps(local);
4445 mutex_unlock(&local->iflist_mtx);
4447 ieee80211_recalc_ps_vif(sdata);
4450 if (elems->erp_info) {
4452 erp_value = elems->erp_info[0];
4457 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
4458 changed |= ieee80211_handle_bss_capability(link,
4459 le16_to_cpu(mgmt->u.beacon.capab_info),
4460 erp_valid, erp_value);
4462 mutex_lock(&local->sta_mtx);
4463 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
4466 link_sta = rcu_dereference_protected(sta->link[link->link_id],
4467 lockdep_is_held(&local->sta_mtx));
4468 if (WARN_ON(!link_sta))
4471 changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
4473 if (ieee80211_config_bw(link, elems->ht_cap_elem,
4474 elems->vht_cap_elem, elems->ht_operation,
4475 elems->vht_operation, elems->he_operation,
4476 elems->eht_operation,
4477 elems->s1g_oper, bssid, &changed)) {
4478 mutex_unlock(&local->sta_mtx);
4480 "failed to follow AP %pM bandwidth change, disconnect\n",
4482 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
4483 WLAN_REASON_DEAUTH_LEAVING,
4485 ieee80211_report_disconnect(sdata, deauth_buf,
4486 sizeof(deauth_buf), true,
4487 WLAN_REASON_DEAUTH_LEAVING,
4492 if (sta && elems->opmode_notif)
4493 ieee80211_vht_handle_opmode(sdata, link_sta,
4494 *elems->opmode_notif,
4496 mutex_unlock(&local->sta_mtx);
4498 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
4499 elems->country_elem,
4500 elems->country_elem_len,
4501 elems->pwr_constr_elem,
4502 elems->cisco_dtpc_elem);
4504 ieee80211_link_info_change_notify(sdata, link, changed);
4509 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
4510 struct sk_buff *skb)
4512 struct ieee80211_link_data *link = &sdata->deflink;
4513 struct ieee80211_rx_status *rx_status;
4514 struct ieee80211_hdr *hdr;
4517 rx_status = (struct ieee80211_rx_status *) skb->cb;
4518 hdr = (struct ieee80211_hdr *) skb->data;
4519 fc = le16_to_cpu(hdr->frame_control);
4522 switch (fc & IEEE80211_FCTL_STYPE) {
4523 case IEEE80211_STYPE_S1G_BEACON:
4524 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
4527 sdata_unlock(sdata);
4530 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
4531 struct sk_buff *skb)
4533 struct ieee80211_link_data *link = &sdata->deflink;
4534 struct ieee80211_rx_status *rx_status;
4535 struct ieee80211_mgmt *mgmt;
4539 rx_status = (struct ieee80211_rx_status *) skb->cb;
4540 mgmt = (struct ieee80211_mgmt *) skb->data;
4541 fc = le16_to_cpu(mgmt->frame_control);
4545 switch (fc & IEEE80211_FCTL_STYPE) {
4546 case IEEE80211_STYPE_BEACON:
4547 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
4548 skb->len, rx_status);
4550 case IEEE80211_STYPE_PROBE_RESP:
4551 ieee80211_rx_mgmt_probe_resp(link, skb);
4553 case IEEE80211_STYPE_AUTH:
4554 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
4556 case IEEE80211_STYPE_DEAUTH:
4557 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
4559 case IEEE80211_STYPE_DISASSOC:
4560 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
4562 case IEEE80211_STYPE_ASSOC_RESP:
4563 case IEEE80211_STYPE_REASSOC_RESP:
4564 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
4566 case IEEE80211_STYPE_ACTION:
4567 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
4568 struct ieee802_11_elems *elems;
4570 ies_len = skb->len -
4571 offsetof(struct ieee80211_mgmt,
4572 u.action.u.chan_switch.variable);
4577 /* CSA IE cannot be overridden, no need for BSSID */
4578 elems = ieee802_11_parse_elems(
4579 mgmt->u.action.u.chan_switch.variable,
4580 ies_len, true, mgmt->bssid, NULL);
4582 if (elems && !elems->parse_error)
4583 ieee80211_sta_process_chanswitch(link,
4585 rx_status->device_timestamp,
4588 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
4589 struct ieee802_11_elems *elems;
4591 ies_len = skb->len -
4592 offsetof(struct ieee80211_mgmt,
4593 u.action.u.ext_chan_switch.variable);
4599 * extended CSA IE can't be overridden, no need for
4602 elems = ieee802_11_parse_elems(
4603 mgmt->u.action.u.ext_chan_switch.variable,
4604 ies_len, true, mgmt->bssid, NULL);
4606 if (elems && !elems->parse_error) {
4607 /* for the handling code pretend it was an IE */
4608 elems->ext_chansw_ie =
4609 &mgmt->u.action.u.ext_chan_switch.data;
4611 ieee80211_sta_process_chanswitch(link,
4613 rx_status->device_timestamp,
4621 sdata_unlock(sdata);
4624 static void ieee80211_sta_timer(struct timer_list *t)
4626 struct ieee80211_sub_if_data *sdata =
4627 from_timer(sdata, t, u.mgd.timer);
4629 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
4632 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
4635 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
4637 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
4640 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
4644 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
4646 struct ieee80211_local *local = sdata->local;
4647 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4648 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
4652 struct ieee80211_prep_tx_info info = {
4653 .subtype = IEEE80211_STYPE_AUTH,
4656 sdata_assert_lock(sdata);
4658 if (WARN_ON_ONCE(!auth_data))
4663 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
4664 sdata_info(sdata, "authentication with %pM timed out\n",
4665 auth_data->bss->bssid);
4668 * Most likely AP is not in the range so remove the
4669 * bss struct for that AP.
4671 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
4676 if (auth_data->algorithm == WLAN_AUTH_SAE)
4677 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
4679 drv_mgd_prepare_tx(local, sdata, &info);
4681 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
4682 auth_data->bss->bssid, auth_data->tries,
4683 IEEE80211_AUTH_MAX_TRIES);
4685 auth_data->expected_transaction = 2;
4687 if (auth_data->algorithm == WLAN_AUTH_SAE) {
4688 trans = auth_data->sae_trans;
4689 status = auth_data->sae_status;
4690 auth_data->expected_transaction = trans;
4693 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4694 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
4695 IEEE80211_TX_INTFL_MLME_CONN_TX;
4697 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
4698 auth_data->data, auth_data->data_len,
4699 auth_data->bss->bssid,
4700 auth_data->bss->bssid, NULL, 0, 0,
4703 if (tx_flags == 0) {
4704 if (auth_data->algorithm == WLAN_AUTH_SAE)
4705 auth_data->timeout = jiffies +
4706 IEEE80211_AUTH_TIMEOUT_SAE;
4708 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
4710 auth_data->timeout =
4711 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
4714 auth_data->timeout_started = true;
4715 run_again(sdata, auth_data->timeout);
4720 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
4722 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4723 struct ieee80211_local *local = sdata->local;
4726 sdata_assert_lock(sdata);
4728 assoc_data->tries++;
4729 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
4730 sdata_info(sdata, "association with %pM timed out\n",
4731 assoc_data->bss->bssid);
4734 * Most likely AP is not in the range so remove the
4735 * bss struct for that AP.
4737 cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
4742 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
4743 assoc_data->bss->bssid, assoc_data->tries,
4744 IEEE80211_ASSOC_MAX_TRIES);
4745 ret = ieee80211_send_assoc(sdata);
4749 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4750 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
4751 assoc_data->timeout_started = true;
4752 run_again(sdata, assoc_data->timeout);
4754 assoc_data->timeout =
4755 round_jiffies_up(jiffies +
4756 IEEE80211_ASSOC_TIMEOUT_LONG);
4757 assoc_data->timeout_started = true;
4758 run_again(sdata, assoc_data->timeout);
4764 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
4765 __le16 fc, bool acked)
4767 struct ieee80211_local *local = sdata->local;
4769 sdata->u.mgd.status_fc = fc;
4770 sdata->u.mgd.status_acked = acked;
4771 sdata->u.mgd.status_received = true;
4773 ieee80211_queue_work(&local->hw, &sdata->work);
4776 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
4778 struct ieee80211_local *local = sdata->local;
4779 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4783 if (ifmgd->status_received) {
4784 __le16 fc = ifmgd->status_fc;
4785 bool status_acked = ifmgd->status_acked;
4787 ifmgd->status_received = false;
4788 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
4790 if (ifmgd->auth_data->algorithm ==
4792 ifmgd->auth_data->timeout =
4794 IEEE80211_AUTH_TIMEOUT_SAE;
4796 ifmgd->auth_data->timeout =
4798 IEEE80211_AUTH_TIMEOUT_SHORT;
4799 run_again(sdata, ifmgd->auth_data->timeout);
4801 ifmgd->auth_data->timeout = jiffies - 1;
4803 ifmgd->auth_data->timeout_started = true;
4804 } else if (ifmgd->assoc_data &&
4805 (ieee80211_is_assoc_req(fc) ||
4806 ieee80211_is_reassoc_req(fc))) {
4808 ifmgd->assoc_data->timeout =
4809 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
4810 run_again(sdata, ifmgd->assoc_data->timeout);
4812 ifmgd->assoc_data->timeout = jiffies - 1;
4814 ifmgd->assoc_data->timeout_started = true;
4818 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
4819 time_after(jiffies, ifmgd->auth_data->timeout)) {
4820 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
4822 * ok ... we waited for assoc or continuation but
4823 * userspace didn't do it, so kill the auth data
4825 ieee80211_destroy_auth_data(sdata, false);
4826 } else if (ieee80211_auth(sdata)) {
4828 struct ieee80211_event event = {
4830 .u.mlme.data = AUTH_EVENT,
4831 .u.mlme.status = MLME_TIMEOUT,
4834 memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
4836 ieee80211_destroy_auth_data(sdata, false);
4838 cfg80211_auth_timeout(sdata->dev, bssid);
4839 drv_event_callback(sdata->local, sdata, &event);
4841 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
4842 run_again(sdata, ifmgd->auth_data->timeout);
4844 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
4845 time_after(jiffies, ifmgd->assoc_data->timeout)) {
4846 if ((ifmgd->assoc_data->need_beacon &&
4847 !sdata->deflink.u.mgd.have_beacon) ||
4848 ieee80211_do_assoc(sdata)) {
4849 struct ieee80211_event event = {
4851 .u.mlme.data = ASSOC_EVENT,
4852 .u.mlme.status = MLME_TIMEOUT,
4855 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
4856 drv_event_callback(sdata->local, sdata, &event);
4858 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
4859 run_again(sdata, ifmgd->assoc_data->timeout);
4861 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
4862 ifmgd->associated) {
4863 u8 *bssid = sdata->deflink.u.mgd.bssid;
4866 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
4867 max_tries = max_nullfunc_tries;
4869 max_tries = max_probe_tries;
4871 /* ACK received for nullfunc probing frame */
4872 if (!ifmgd->probe_send_count)
4873 ieee80211_reset_ap_probe(sdata);
4874 else if (ifmgd->nullfunc_failed) {
4875 if (ifmgd->probe_send_count < max_tries) {
4877 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
4878 bssid, ifmgd->probe_send_count,
4880 ieee80211_mgd_probe_ap_send(sdata);
4883 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
4885 ieee80211_sta_connection_lost(sdata,
4886 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
4889 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
4890 run_again(sdata, ifmgd->probe_timeout);
4891 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
4893 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
4894 bssid, probe_wait_ms);
4895 ieee80211_sta_connection_lost(sdata,
4896 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4897 } else if (ifmgd->probe_send_count < max_tries) {
4899 "No probe response from AP %pM after %dms, try %d/%i\n",
4900 bssid, probe_wait_ms,
4901 ifmgd->probe_send_count, max_tries);
4902 ieee80211_mgd_probe_ap_send(sdata);
4905 * We actually lost the connection ... or did we?
4909 "No probe response from AP %pM after %dms, disconnecting.\n",
4910 bssid, probe_wait_ms);
4912 ieee80211_sta_connection_lost(sdata,
4913 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
4917 sdata_unlock(sdata);
4920 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
4922 struct ieee80211_sub_if_data *sdata =
4923 from_timer(sdata, t, u.mgd.bcn_mon_timer);
4925 if (WARN_ON(sdata->vif.valid_links))
4928 if (sdata->vif.bss_conf.csa_active &&
4929 !sdata->deflink.u.mgd.csa_waiting_bcn)
4932 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
4935 sdata->u.mgd.connection_loss = false;
4936 ieee80211_queue_work(&sdata->local->hw,
4937 &sdata->u.mgd.beacon_connection_loss_work);
4940 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
4942 struct ieee80211_sub_if_data *sdata =
4943 from_timer(sdata, t, u.mgd.conn_mon_timer);
4944 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4945 struct ieee80211_local *local = sdata->local;
4946 struct sta_info *sta;
4947 unsigned long timeout;
4949 if (WARN_ON(sdata->vif.valid_links))
4952 if (sdata->vif.bss_conf.csa_active &&
4953 !sdata->deflink.u.mgd.csa_waiting_bcn)
4956 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
4960 timeout = sta->deflink.status_stats.last_ack;
4961 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
4962 timeout = sta->deflink.rx_stats.last_rx;
4963 timeout += IEEE80211_CONNECTION_IDLE_TIME;
4965 /* If timeout is after now, then update timer to fire at
4966 * the later date, but do not actually probe at this time.
4968 if (time_is_after_jiffies(timeout)) {
4969 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
4973 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
4976 static void ieee80211_sta_monitor_work(struct work_struct *work)
4978 struct ieee80211_sub_if_data *sdata =
4979 container_of(work, struct ieee80211_sub_if_data,
4980 u.mgd.monitor_work);
4982 ieee80211_mgd_probe_ap(sdata, false);
4985 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
4987 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
4988 __ieee80211_stop_poll(sdata);
4990 /* let's probe the connection once */
4991 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
4992 ieee80211_queue_work(&sdata->local->hw,
4993 &sdata->u.mgd.monitor_work);
4998 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
5000 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5001 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5005 if (ifmgd->auth_data || ifmgd->assoc_data) {
5006 const u8 *bssid = ifmgd->auth_data ?
5007 ifmgd->auth_data->bss->bssid :
5008 ifmgd->assoc_data->bss->bssid;
5011 * If we are trying to authenticate / associate while suspending,
5012 * cfg80211 won't know and won't actually abort those attempts,
5013 * thus we need to do that ourselves.
5015 ieee80211_send_deauth_disassoc(sdata, bssid, bssid,
5016 IEEE80211_STYPE_DEAUTH,
5017 WLAN_REASON_DEAUTH_LEAVING,
5019 if (ifmgd->assoc_data)
5020 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5021 if (ifmgd->auth_data)
5022 ieee80211_destroy_auth_data(sdata, false);
5023 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
5024 IEEE80211_DEAUTH_FRAME_LEN,
5028 /* This is a bit of a hack - we should find a better and more generic
5029 * solution to this. Normally when suspending, cfg80211 will in fact
5030 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
5031 * auth (not so important) or assoc (this is the problem) process.
5033 * As a consequence, it can happen that we are in the process of both
5034 * associating and suspending, and receive an association response
5035 * after cfg80211 has checked if it needs to disconnect, but before
5036 * we actually set the flag to drop incoming frames. This will then
5037 * cause the workqueue flush to process the association response in
5038 * the suspend, resulting in a successful association just before it
5039 * tries to remove the interface from the driver, which now though
5040 * has a channel context assigned ... this results in issues.
5042 * To work around this (for now) simply deauth here again if we're
5045 if (ifmgd->associated && !sdata->local->wowlan) {
5047 struct cfg80211_deauth_request req = {
5048 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
5052 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
5053 ieee80211_mgd_deauth(sdata, &req);
5056 sdata_unlock(sdata);
5060 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
5062 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5065 if (!ifmgd->associated) {
5066 sdata_unlock(sdata);
5070 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
5071 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
5072 mlme_dbg(sdata, "driver requested disconnect after resume\n");
5073 ieee80211_sta_connection_lost(sdata,
5074 WLAN_REASON_UNSPECIFIED,
5076 sdata_unlock(sdata);
5080 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
5081 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
5082 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
5083 ieee80211_sta_connection_lost(sdata,
5084 WLAN_REASON_UNSPECIFIED,
5086 sdata_unlock(sdata);
5090 sdata_unlock(sdata);
5093 static void ieee80211_request_smps_mgd_work(struct work_struct *work)
5095 struct ieee80211_link_data *link =
5096 container_of(work, struct ieee80211_link_data,
5097 u.mgd.request_smps_work);
5099 sdata_lock(link->sdata);
5100 __ieee80211_request_smps_mgd(link->sdata, link,
5101 link->u.mgd.driver_smps_mode);
5102 sdata_unlock(link->sdata);
5105 /* interface setup */
5106 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
5108 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5110 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
5111 INIT_WORK(&ifmgd->beacon_connection_loss_work,
5112 ieee80211_beacon_connection_loss_work);
5113 INIT_WORK(&ifmgd->csa_connection_drop_work,
5114 ieee80211_csa_connection_drop_work);
5115 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
5116 ieee80211_tdls_peer_del_work);
5117 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
5118 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
5119 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
5120 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
5121 ieee80211_sta_handle_tspec_ac_params_wk);
5124 ifmgd->powersave = sdata->wdev.ps;
5125 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
5126 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
5127 /* Setup TDLS data */
5128 spin_lock_init(&ifmgd->teardown_lock);
5129 ifmgd->teardown_skb = NULL;
5130 ifmgd->orig_teardown_skb = NULL;
5133 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
5135 struct ieee80211_local *local = link->sdata->local;
5137 link->u.mgd.p2p_noa_index = -1;
5138 link->u.mgd.conn_flags = 0;
5139 link->conf->bssid = link->u.mgd.bssid;
5141 INIT_WORK(&link->u.mgd.request_smps_work,
5142 ieee80211_request_smps_mgd_work);
5143 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
5144 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
5146 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
5148 INIT_WORK(&link->u.mgd.chswitch_work, ieee80211_chswitch_work);
5149 timer_setup(&link->u.mgd.chswitch_timer, ieee80211_chswitch_timer, 0);
5152 /* scan finished notification */
5153 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
5155 struct ieee80211_sub_if_data *sdata;
5157 /* Restart STA timers */
5159 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
5160 if (ieee80211_sdata_running(sdata))
5161 ieee80211_restart_sta_timer(sdata);
5166 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
5167 struct cfg80211_bss *cbss)
5169 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
5170 const struct element *ht_cap_elem, *vht_cap_elem;
5171 const struct cfg80211_bss_ies *ies;
5172 const struct ieee80211_ht_cap *ht_cap;
5173 const struct ieee80211_vht_cap *vht_cap;
5174 const struct ieee80211_he_cap_elem *he_cap;
5175 const struct element *he_cap_elem;
5176 u16 mcs_80_map, mcs_160_map;
5177 int i, mcs_nss_size;
5181 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
5184 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
5185 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
5186 ht_cap = (void *)ht_cap_elem->data;
5187 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
5189 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
5190 * "Tx Unequal Modulation Supported" fields.
5194 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
5197 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
5198 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
5202 vht_cap = (void *)vht_cap_elem->data;
5203 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
5204 for (nss = 8; nss > 0; nss--) {
5205 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
5206 IEEE80211_VHT_MCS_NOT_SUPPORTED)
5209 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
5210 chains = max(chains, nss);
5213 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
5216 ies = rcu_dereference(cbss->ies);
5217 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
5218 ies->data, ies->len);
5220 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
5223 /* skip one byte ext_tag_id */
5224 he_cap = (void *)(he_cap_elem->data + 1);
5225 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
5228 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
5231 /* mcs_nss is right after he_cap info */
5232 he_mcs_nss_supp = (void *)(he_cap + 1);
5234 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
5236 for (i = 7; i >= 0; i--) {
5237 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
5239 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5240 chains = max_t(u8, chains, i + 1);
5245 support_160 = he_cap->phy_cap_info[0] &
5246 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
5251 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
5252 for (i = 7; i >= 0; i--) {
5253 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
5255 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
5256 chains = max_t(u8, chains, i + 1);
5265 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
5266 const struct cfg80211_bss_ies *ies,
5267 const struct ieee80211_he_operation *he_op)
5269 const struct element *he_cap_elem;
5270 const struct ieee80211_he_cap_elem *he_cap;
5271 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
5272 u16 mcs_80_map_tx, mcs_80_map_rx;
5277 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
5278 ies->data, ies->len);
5281 if (!he_cap_elem || he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
5283 "Invalid HE elem, Disable HE\n");
5287 /* skip one byte ext_tag_id */
5288 he_cap = (void *)(he_cap_elem->data + 1);
5289 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
5292 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
5294 "Invalid HE elem with nss size, Disable HE\n");
5298 /* mcs_nss is right after he_cap info */
5299 he_mcs_nss_supp = (void *)(he_cap + 1);
5301 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
5302 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
5304 /* P802.11-REVme/D0.3
5305 * 27.1.1 Introduction to the HE PHY
5307 * An HE STA shall support the following features:
5309 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
5310 * supported channel widths for HE SU PPDUs
5312 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5313 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
5315 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
5316 mcs_80_map_tx, mcs_80_map_rx);
5323 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
5325 /* make sure the AP is consistent with itself
5327 * P802.11-REVme/D0.3
5328 * 26.17.1 Basic HE BSS operation
5330 * A STA that is operating in an HE BSS shall be able to receive and
5331 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
5332 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
5333 * MLME-START.request primitive and shall be able to receive at each of
5334 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
5335 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
5338 for (nss = 8; nss > 0; nss--) {
5339 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
5343 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
5346 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
5347 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
5349 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5350 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5351 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
5353 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
5354 nss, ap_rx_val, ap_rx_val, ap_op_val);
5363 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
5364 struct ieee80211_supported_band *sband,
5365 const struct ieee80211_he_operation *he_op)
5367 const struct ieee80211_sta_he_cap *sta_he_cap =
5368 ieee80211_get_he_iftype_cap(sband,
5369 ieee80211_vif_type_p2p(&sdata->vif));
5373 if (!sta_he_cap || !he_op)
5376 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
5378 /* Need to go over for 80MHz, 160MHz and for 80+80 */
5379 for (i = 0; i < 3; i++) {
5380 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
5381 &sta_he_cap->he_mcs_nss_supp;
5382 u16 sta_mcs_map_rx =
5383 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
5384 u16 sta_mcs_map_tx =
5385 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
5387 bool verified = true;
5390 * For each band there is a maximum of 8 spatial streams
5391 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
5392 * of 2 bits per NSS (1-8), with the values defined in enum
5393 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
5394 * capabilities aren't less than the AP's minimum requirements
5395 * for this HE BSS per SS.
5396 * It is enough to find one such band that meets the reqs.
5398 for (nss = 8; nss > 0; nss--) {
5399 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
5400 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
5401 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
5403 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
5407 * Make sure the HE AP doesn't require MCSs that aren't
5408 * supported by the client as required by spec
5410 * P802.11-REVme/D0.3
5411 * 26.17.1 Basic HE BSS operation
5413 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
5414 * a BSS, unless it supports (i.e., is able to both transmit and
5415 * receive using) all of the <HE-MCS, NSS> tuples in the basic
5416 * HE-MCS and NSS set.
5418 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5419 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
5420 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
5430 /* If here, STA doesn't meet AP's HE min requirements */
5434 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
5435 struct ieee80211_link_data *link,
5436 struct cfg80211_bss *cbss)
5438 struct ieee80211_local *local = sdata->local;
5439 const struct ieee80211_ht_cap *ht_cap = NULL;
5440 const struct ieee80211_ht_operation *ht_oper = NULL;
5441 const struct ieee80211_vht_operation *vht_oper = NULL;
5442 const struct ieee80211_he_operation *he_oper = NULL;
5443 const struct ieee80211_eht_operation *eht_oper = NULL;
5444 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
5445 struct ieee80211_supported_band *sband;
5446 struct cfg80211_chan_def chandef;
5447 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
5448 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
5449 struct ieee80211_bss *bss = (void *)cbss->priv;
5450 struct ieee802_11_elems *elems;
5451 const struct cfg80211_bss_ies *ies;
5458 ies = rcu_dereference(cbss->ies);
5459 elems = ieee802_11_parse_elems(ies->data, ies->len, false,
5466 sband = local->hw.wiphy->bands[cbss->channel->band];
5468 link->u.mgd.conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
5469 IEEE80211_CONN_DISABLE_80P80MHZ |
5470 IEEE80211_CONN_DISABLE_160MHZ);
5472 /* disable HT/VHT/HE if we don't support them */
5473 if (!sband->ht_cap.ht_supported && !is_6ghz) {
5474 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
5475 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
5476 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5477 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
5478 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
5481 if (!sband->vht_cap.vht_supported && is_5ghz) {
5482 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
5483 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5484 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
5485 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
5488 if (!ieee80211_get_he_iftype_cap(sband,
5489 ieee80211_vif_type_p2p(&sdata->vif))) {
5490 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
5491 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
5492 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
5495 if (!ieee80211_get_eht_iftype_cap(sband,
5496 ieee80211_vif_type_p2p(&sdata->vif))) {
5497 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
5498 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
5501 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
5502 ht_oper = elems->ht_operation;
5503 ht_cap = elems->ht_cap_elem;
5506 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
5511 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
5512 vht_oper = elems->vht_operation;
5513 if (vht_oper && !ht_oper) {
5516 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
5517 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
5518 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5519 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
5520 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
5523 if (!elems->vht_cap_elem) {
5525 "bad VHT capabilities, disabling VHT\n");
5526 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5531 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)) {
5532 he_oper = elems->he_operation;
5535 struct ieee80211_bss_conf *bss_conf;
5538 bss_conf = link->conf;
5540 if (elems->pwr_constr_elem)
5541 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
5543 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
5544 ARRAY_SIZE(elems->tx_pwr_env));
5546 for (i = 0; i < elems->tx_pwr_env_num; i++) {
5547 if (elems->tx_pwr_env_len[i] >
5548 sizeof(bss_conf->tx_pwr_env[j]))
5551 bss_conf->tx_pwr_env_num++;
5552 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
5553 elems->tx_pwr_env_len[i]);
5558 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
5559 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
5560 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE |
5561 IEEE80211_CONN_DISABLE_EHT;
5565 * EHT requires HE to be supported as well. Specifically for 6 GHz
5566 * channels, the operation channel information can only be deduced from
5567 * both the 6 GHz operation information (from the HE operation IE) and
5570 if (!(link->u.mgd.conn_flags &
5571 (IEEE80211_CONN_DISABLE_HE |
5572 IEEE80211_CONN_DISABLE_EHT)) &&
5574 const struct cfg80211_bss_ies *ies;
5575 const u8 *eht_oper_ie;
5577 ies = rcu_dereference(cbss->ies);
5578 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
5579 ies->data, ies->len);
5580 if (eht_oper_ie && eht_oper_ie[1] >=
5581 1 + sizeof(struct ieee80211_eht_operation))
5582 eht_oper = (void *)(eht_oper_ie + 3);
5587 /* Allow VHT if at least one channel on the sband supports 80 MHz */
5589 for (i = 0; i < sband->n_channels; i++) {
5590 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
5591 IEEE80211_CHAN_NO_80MHZ))
5599 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
5600 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5603 if (sband->band == NL80211_BAND_S1GHZ) {
5604 s1g_oper = elems->s1g_oper;
5607 "AP missing S1G operation element?\n");
5610 link->u.mgd.conn_flags |=
5611 ieee80211_determine_chantype(link, sband,
5619 link->needed_rx_chains =
5620 min(ieee80211_max_rx_chains(link, cbss), local->rx_chains);
5623 /* the element data was RCU protected so no longer valid anyway */
5627 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
5628 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5632 /* will change later if needed */
5633 link->smps_mode = IEEE80211_SMPS_OFF;
5635 mutex_lock(&local->mtx);
5637 * If this fails (possibly due to channel context sharing
5638 * on incompatible channels, e.g. 80+80 and 160 sharing the
5639 * same control channel) try to use a smaller bandwidth.
5641 ret = ieee80211_link_use_channel(link, &chandef,
5642 IEEE80211_CHANCTX_SHARED);
5644 /* don't downgrade for 5 and 10 MHz channels, though. */
5645 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5646 chandef.width == NL80211_CHAN_WIDTH_10)
5649 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5650 link->u.mgd.conn_flags |=
5651 ieee80211_chandef_downgrade(&chandef);
5652 ret = ieee80211_link_use_channel(link, &chandef,
5653 IEEE80211_CHANCTX_SHARED);
5656 mutex_unlock(&local->mtx);
5660 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5661 u8 *dtim_count, u8 *dtim_period)
5663 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5664 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5666 const struct ieee80211_tim_ie *tim = NULL;
5667 const struct ieee80211_bssid_index *idx;
5668 bool valid = tim_ie && tim_ie[1] >= 2;
5671 tim = (void *)(tim_ie + 2);
5674 *dtim_count = valid ? tim->dtim_count : 0;
5677 *dtim_period = valid ? tim->dtim_period : 0;
5679 /* Check if value is overridden by non-transmitted profile */
5680 if (!idx_ie || idx_ie[1] < 3)
5683 idx = (void *)(idx_ie + 2);
5686 *dtim_count = idx->dtim_count;
5689 *dtim_period = idx->dtim_period;
5694 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
5695 struct cfg80211_bss *cbss, bool assoc,
5698 struct ieee80211_local *local = sdata->local;
5699 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5700 struct ieee80211_bss *bss = (void *)cbss->priv;
5701 struct sta_info *new_sta = NULL;
5702 struct ieee80211_supported_band *sband;
5703 struct ieee80211_link_data *link = &sdata->deflink;
5704 bool have_sta = false;
5707 sband = local->hw.wiphy->bands[cbss->channel->band];
5709 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
5712 /* If a reconfig is happening, bail out */
5713 if (local->in_reconfig)
5718 have_sta = sta_info_get(sdata, cbss->bssid);
5723 new_sta = sta_info_alloc(sdata, cbss->bssid, -1, GFP_KERNEL);
5729 * Set up the information for the new channel before setting the
5730 * new channel. We can't - completely race-free - change the basic
5731 * rates bitmap and the channel (sband) that it refers to, but if
5732 * we set it up before we at least avoid calling into the driver's
5733 * bss_info_changed() method with invalid information (since we do
5734 * call that from changing the channel - only for IDLE and perhaps
5735 * some others, but ...).
5737 * So to avoid that, just set up all the new information before the
5738 * channel, but tell the driver to apply it only afterwards, since
5739 * it might need the new channel for that.
5742 u32 rates = 0, basic_rates = 0;
5743 bool have_higher_than_11mbit = false;
5744 int min_rate = INT_MAX, min_rate_index = -1;
5745 const struct cfg80211_bss_ies *ies;
5746 int shift = ieee80211_vif_get_shift(&sdata->vif);
5747 struct ieee80211_link_sta *link_sta = &new_sta->sta.deflink;
5749 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
5751 /* TODO: S1G Basic Rate Set is expressed elsewhere */
5752 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
5753 ieee80211_s1g_sta_rate_init(new_sta);
5757 ieee80211_get_rates(sband, bss->supp_rates,
5758 bss->supp_rates_len,
5759 &rates, &basic_rates,
5760 &have_higher_than_11mbit,
5761 &min_rate, &min_rate_index,
5765 * This used to be a workaround for basic rates missing
5766 * in the association response frame. Now that we no
5767 * longer use the basic rates from there, it probably
5768 * doesn't happen any more, but keep the workaround so
5769 * in case some *other* APs are buggy in different ways
5770 * we can connect -- with a warning.
5771 * Allow this workaround only in case the AP provided at least
5774 if (min_rate_index < 0) {
5776 "No legacy rates in association response\n");
5778 sta_info_free(local, new_sta);
5780 } else if (!basic_rates) {
5782 "No basic rates, using min rate instead\n");
5783 basic_rates = BIT(min_rate_index);
5787 link_sta->supp_rates[cbss->channel->band] = rates;
5790 "No rates found, keeping mandatory only\n");
5792 link->conf->basic_rates = basic_rates;
5794 /* cf. IEEE 802.11 9.2.12 */
5795 if (cbss->channel->band == NL80211_BAND_2GHZ &&
5796 have_higher_than_11mbit)
5797 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
5799 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
5802 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
5804 /* set timing information */
5805 link->conf->beacon_int = cbss->beacon_interval;
5807 ies = rcu_dereference(cbss->beacon_ies);
5809 link->conf->sync_tsf = ies->tsf;
5810 link->conf->sync_device_ts =
5811 bss->device_ts_beacon;
5813 ieee80211_get_dtim(ies,
5814 &link->conf->sync_dtim_count,
5816 } else if (!ieee80211_hw_check(&sdata->local->hw,
5817 TIMING_BEACON_ONLY)) {
5818 ies = rcu_dereference(cbss->proberesp_ies);
5819 /* must be non-NULL since beacon IEs were NULL */
5820 link->conf->sync_tsf = ies->tsf;
5821 link->conf->sync_device_ts =
5822 bss->device_ts_presp;
5823 link->conf->sync_dtim_count = 0;
5825 link->conf->sync_tsf = 0;
5826 link->conf->sync_device_ts = 0;
5827 link->conf->sync_dtim_count = 0;
5832 if (new_sta || override) {
5833 err = ieee80211_prep_channel(sdata, link, cbss);
5836 sta_info_free(local, new_sta);
5843 * tell driver about BSSID, basic rates and timing
5844 * this was set up above, before setting the channel
5846 ieee80211_link_info_change_notify(sdata, link,
5848 BSS_CHANGED_BASIC_RATES |
5849 BSS_CHANGED_BEACON_INT);
5852 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
5854 err = sta_info_insert(new_sta);
5858 "failed to insert STA entry for the AP (error %d)\n",
5863 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
5865 /* Cancel scan to ensure that nothing interferes with connection */
5866 if (local->scanning)
5867 ieee80211_scan_cancel(local);
5873 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
5874 struct cfg80211_auth_request *req)
5876 struct ieee80211_link_data *link = &sdata->deflink;
5877 struct ieee80211_local *local = sdata->local;
5878 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5879 struct ieee80211_mgd_auth_data *auth_data;
5884 /* prepare auth data structure */
5886 switch (req->auth_type) {
5887 case NL80211_AUTHTYPE_OPEN_SYSTEM:
5888 auth_alg = WLAN_AUTH_OPEN;
5890 case NL80211_AUTHTYPE_SHARED_KEY:
5893 auth_alg = WLAN_AUTH_SHARED_KEY;
5895 case NL80211_AUTHTYPE_FT:
5896 auth_alg = WLAN_AUTH_FT;
5898 case NL80211_AUTHTYPE_NETWORK_EAP:
5899 auth_alg = WLAN_AUTH_LEAP;
5901 case NL80211_AUTHTYPE_SAE:
5902 auth_alg = WLAN_AUTH_SAE;
5904 case NL80211_AUTHTYPE_FILS_SK:
5905 auth_alg = WLAN_AUTH_FILS_SK;
5907 case NL80211_AUTHTYPE_FILS_SK_PFS:
5908 auth_alg = WLAN_AUTH_FILS_SK_PFS;
5910 case NL80211_AUTHTYPE_FILS_PK:
5911 auth_alg = WLAN_AUTH_FILS_PK;
5917 if (ifmgd->assoc_data)
5920 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
5921 req->ie_len, GFP_KERNEL);
5925 auth_data->bss = req->bss;
5927 if (req->auth_data_len >= 4) {
5928 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
5929 __le16 *pos = (__le16 *) req->auth_data;
5931 auth_data->sae_trans = le16_to_cpu(pos[0]);
5932 auth_data->sae_status = le16_to_cpu(pos[1]);
5934 memcpy(auth_data->data, req->auth_data + 4,
5935 req->auth_data_len - 4);
5936 auth_data->data_len += req->auth_data_len - 4;
5939 /* Check if continuing authentication or trying to authenticate with the
5940 * same BSS that we were in the process of authenticating with and avoid
5941 * removal and re-addition of the STA entry in
5942 * ieee80211_prep_connection().
5944 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
5946 if (req->ie && req->ie_len) {
5947 memcpy(&auth_data->data[auth_data->data_len],
5948 req->ie, req->ie_len);
5949 auth_data->data_len += req->ie_len;
5952 if (req->key && req->key_len) {
5953 auth_data->key_len = req->key_len;
5954 auth_data->key_idx = req->key_idx;
5955 memcpy(auth_data->key, req->key, req->key_len);
5958 auth_data->algorithm = auth_alg;
5960 /* try to authenticate/probe */
5962 if (ifmgd->auth_data) {
5963 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
5964 auth_data->peer_confirmed =
5965 ifmgd->auth_data->peer_confirmed;
5967 ieee80211_destroy_auth_data(sdata, cont_auth);
5970 /* prep auth_data so we don't go into idle on disassoc */
5971 ifmgd->auth_data = auth_data;
5973 /* If this is continuation of an ongoing SAE authentication exchange
5974 * (i.e., request to send SAE Confirm) and the peer has already
5975 * confirmed, mark authentication completed since we are about to send
5978 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
5979 auth_data->peer_confirmed && auth_data->sae_trans == 2)
5980 ieee80211_mark_sta_auth(sdata, req->bss->bssid);
5982 if (ifmgd->associated) {
5983 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5986 "disconnect from AP %pM for new auth to %pM\n",
5987 sdata->vif.cfg.ap_addr, req->bss->bssid);
5988 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5989 WLAN_REASON_UNSPECIFIED,
5992 ieee80211_report_disconnect(sdata, frame_buf,
5993 sizeof(frame_buf), true,
5994 WLAN_REASON_UNSPECIFIED,
5998 sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
6000 err = ieee80211_prep_connection(sdata, req->bss, cont_auth, false);
6004 err = ieee80211_auth(sdata);
6006 sta_info_destroy_addr(sdata, req->bss->bssid);
6010 /* hold our own reference */
6011 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
6015 eth_zero_addr(link->u.mgd.bssid);
6016 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6018 ifmgd->auth_data = NULL;
6019 mutex_lock(&sdata->local->mtx);
6020 ieee80211_link_release_channel(&sdata->deflink);
6021 mutex_unlock(&sdata->local->mtx);
6026 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
6027 struct cfg80211_assoc_request *req)
6029 bool is_6ghz = req->bss->channel->band == NL80211_BAND_6GHZ;
6030 bool is_5ghz = req->bss->channel->band == NL80211_BAND_5GHZ;
6031 struct ieee80211_local *local = sdata->local;
6032 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6033 struct ieee80211_bss *bss = (void *)req->bss->priv;
6034 struct ieee80211_mgd_assoc_data *assoc_data;
6035 const struct cfg80211_bss_ies *beacon_ies;
6036 struct ieee80211_supported_band *sband;
6037 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6038 const struct element *ssid_elem, *ht_elem, *vht_elem;
6039 struct ieee80211_link_data *link = &sdata->deflink;
6041 bool override = false;
6043 assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
6048 ssid_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_SSID);
6049 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
6054 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
6055 assoc_data->ssid_len = ssid_elem->datalen;
6056 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
6057 vif_cfg->ssid_len = assoc_data->ssid_len;
6060 if (ifmgd->associated) {
6061 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6064 "disconnect from AP %pM for new assoc to %pM\n",
6065 sdata->vif.cfg.ap_addr, req->bss->bssid);
6066 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6067 WLAN_REASON_UNSPECIFIED,
6070 ieee80211_report_disconnect(sdata, frame_buf,
6071 sizeof(frame_buf), true,
6072 WLAN_REASON_UNSPECIFIED,
6076 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
6081 if (ifmgd->assoc_data) {
6086 if (ifmgd->auth_data) {
6089 /* keep sta info, bssid if matching */
6090 match = ether_addr_equal(sdata->deflink.u.mgd.bssid,
6092 ieee80211_destroy_auth_data(sdata, match);
6095 /* prepare assoc data */
6097 link->u.mgd.beacon_crc_valid = false;
6099 assoc_data->wmm = bss->wmm_used &&
6100 (local->hw.queues >= IEEE80211_NUM_ACS);
6103 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
6104 * We still associate in non-HT mode (11a/b/g) if any one of these
6105 * ciphers is configured as pairwise.
6106 * We can set this to true for non-11n hardware, that'll be checked
6107 * separately along with the peer capabilities.
6109 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
6110 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
6111 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
6112 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
6113 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
6114 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6115 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
6116 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6117 netdev_info(sdata->dev,
6118 "disabling HT/VHT/HE due to WEP/TKIP use\n");
6122 sband = local->hw.wiphy->bands[req->bss->channel->band];
6124 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
6125 if (!bss->wmm_used) {
6126 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
6127 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6128 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
6129 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6130 netdev_info(sdata->dev,
6131 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
6134 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
6135 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
6136 sizeof(ifmgd->ht_capa_mask));
6138 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
6139 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
6140 sizeof(ifmgd->vht_capa_mask));
6142 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
6143 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
6144 sizeof(ifmgd->s1g_capa_mask));
6146 if (req->ie && req->ie_len) {
6147 memcpy(assoc_data->ie, req->ie, req->ie_len);
6148 assoc_data->ie_len = req->ie_len;
6151 if (req->fils_kek) {
6152 /* should already be checked in cfg80211 - so warn */
6153 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
6157 memcpy(assoc_data->fils_kek, req->fils_kek,
6159 assoc_data->fils_kek_len = req->fils_kek_len;
6162 if (req->fils_nonces)
6163 memcpy(assoc_data->fils_nonces, req->fils_nonces,
6164 2 * FILS_NONCE_LEN);
6166 assoc_data->bss = req->bss;
6167 assoc_data->capability = req->bss->capability;
6168 assoc_data->supp_rates = bss->supp_rates;
6169 assoc_data->supp_rates_len = bss->supp_rates_len;
6172 ht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_HT_OPERATION);
6173 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
6174 assoc_data->ap_ht_param =
6175 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
6177 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
6178 vht_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_VHT_CAPABILITY);
6179 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
6180 memcpy(&assoc_data->ap_vht_cap, vht_elem->data,
6181 sizeof(struct ieee80211_vht_cap));
6182 } else if (is_5ghz) {
6184 "VHT capa missing/short, disabling VHT/HE/EHT\n");
6185 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT |
6186 IEEE80211_CONN_DISABLE_HE |
6187 IEEE80211_CONN_DISABLE_EHT;
6191 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
6192 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
6193 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
6194 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
6196 if (bss->wmm_used && bss->uapsd_supported &&
6197 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
6198 assoc_data->uapsd = true;
6199 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
6201 assoc_data->uapsd = false;
6202 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
6205 if (req->prev_bssid)
6206 memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
6209 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
6210 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
6212 ifmgd->mfp = IEEE80211_MFP_DISABLED;
6213 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
6216 if (req->flags & ASSOC_REQ_USE_RRM)
6217 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
6219 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
6221 if (req->crypto.control_port)
6222 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
6224 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
6226 sdata->control_port_protocol = req->crypto.control_port_ethertype;
6227 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
6228 sdata->control_port_over_nl80211 =
6229 req->crypto.control_port_over_nl80211;
6230 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
6232 /* kick off associate process */
6234 ifmgd->assoc_data = assoc_data;
6235 link->u.mgd.dtim_period = 0;
6236 link->u.mgd.have_beacon = false;
6238 /* override HT/VHT configuration only if the AP and we support it */
6239 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
6240 struct ieee80211_sta_ht_cap sta_ht_cap;
6242 if (req->flags & ASSOC_REQ_DISABLE_HT)
6245 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
6246 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
6248 /* check for 40 MHz disable override */
6249 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ) &&
6250 sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
6251 !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
6254 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
6255 req->flags & ASSOC_REQ_DISABLE_VHT)
6259 if (req->flags & ASSOC_REQ_DISABLE_HT) {
6260 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
6261 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HT;
6262 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6263 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
6264 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6267 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
6268 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
6269 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_VHT;
6272 if (req->flags & ASSOC_REQ_DISABLE_HE) {
6273 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
6274 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_HE;
6275 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6278 if (req->flags & ASSOC_REQ_DISABLE_EHT)
6279 link->u.mgd.conn_flags |= IEEE80211_CONN_DISABLE_EHT;
6281 err = ieee80211_prep_connection(sdata, req->bss, true, override);
6285 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
6286 if (ifmgd->powersave)
6287 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
6289 link->smps_mode = IEEE80211_SMPS_OFF;
6291 link->smps_mode = link->u.mgd.req_smps;
6295 beacon_ies = rcu_dereference(req->bss->beacon_ies);
6297 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
6300 * Wait up to one beacon interval ...
6301 * should this be more if we miss one?
6303 sdata_info(sdata, "waiting for beacon from %pM\n",
6305 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
6306 assoc_data->timeout_started = true;
6307 assoc_data->need_beacon = true;
6308 } else if (beacon_ies) {
6309 const struct element *elem;
6312 ieee80211_get_dtim(beacon_ies, &dtim_count,
6313 &link->u.mgd.dtim_period);
6315 link->u.mgd.have_beacon = true;
6316 assoc_data->timeout = jiffies;
6317 assoc_data->timeout_started = true;
6319 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6320 link->conf->sync_tsf = beacon_ies->tsf;
6321 link->conf->sync_device_ts =
6322 bss->device_ts_beacon;
6323 link->conf->sync_dtim_count = dtim_count;
6326 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
6327 beacon_ies->data, beacon_ies->len);
6328 if (elem && elem->datalen >= 3)
6329 link->conf->profile_periodicity = elem->data[2];
6331 link->conf->profile_periodicity = 0;
6333 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
6334 beacon_ies->data, beacon_ies->len);
6335 if (elem && elem->datalen >= 11 &&
6336 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6337 link->conf->ema_ap = true;
6339 link->conf->ema_ap = false;
6341 assoc_data->timeout = jiffies;
6342 assoc_data->timeout_started = true;
6346 run_again(sdata, assoc_data->timeout);
6348 if (bss->corrupt_data) {
6349 char *corrupt_type = "data";
6350 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
6351 if (bss->corrupt_data &
6352 IEEE80211_BSS_CORRUPT_PROBE_RESP)
6353 corrupt_type = "beacon and probe response";
6355 corrupt_type = "beacon";
6356 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
6357 corrupt_type = "probe response";
6358 sdata_info(sdata, "associating with AP with corrupt %s\n",
6364 eth_zero_addr(link->u.mgd.bssid);
6365 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6367 ifmgd->assoc_data = NULL;
6373 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
6374 struct cfg80211_deauth_request *req)
6376 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6377 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6378 bool tx = !req->local_state_change;
6379 struct ieee80211_prep_tx_info info = {
6380 .subtype = IEEE80211_STYPE_DEAUTH,
6383 if (ifmgd->auth_data &&
6384 ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
6386 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
6387 req->bssid, req->reason_code,
6388 ieee80211_get_reason_code_string(req->reason_code));
6390 drv_mgd_prepare_tx(sdata->local, sdata, &info);
6391 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
6392 IEEE80211_STYPE_DEAUTH,
6393 req->reason_code, tx,
6395 ieee80211_destroy_auth_data(sdata, false);
6396 ieee80211_report_disconnect(sdata, frame_buf,
6397 sizeof(frame_buf), true,
6398 req->reason_code, false);
6399 drv_mgd_complete_tx(sdata->local, sdata, &info);
6403 if (ifmgd->assoc_data &&
6404 ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
6406 "aborting association with %pM by local choice (Reason: %u=%s)\n",
6407 req->bssid, req->reason_code,
6408 ieee80211_get_reason_code_string(req->reason_code));
6410 drv_mgd_prepare_tx(sdata->local, sdata, &info);
6411 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
6412 IEEE80211_STYPE_DEAUTH,
6413 req->reason_code, tx,
6415 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6416 ieee80211_report_disconnect(sdata, frame_buf,
6417 sizeof(frame_buf), true,
6418 req->reason_code, false);
6422 if (ifmgd->associated &&
6423 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
6425 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
6426 req->bssid, req->reason_code,
6427 ieee80211_get_reason_code_string(req->reason_code));
6429 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6430 req->reason_code, tx, frame_buf);
6431 ieee80211_report_disconnect(sdata, frame_buf,
6432 sizeof(frame_buf), true,
6433 req->reason_code, false);
6434 drv_mgd_complete_tx(sdata->local, sdata, &info);
6441 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
6442 struct cfg80211_disassoc_request *req)
6444 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6446 if (!sdata->u.mgd.associated ||
6447 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
6451 "disassociating from %pM by local choice (Reason: %u=%s)\n",
6452 req->ap_addr, req->reason_code,
6453 ieee80211_get_reason_code_string(req->reason_code));
6455 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
6456 req->reason_code, !req->local_state_change,
6459 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6460 req->reason_code, false);
6465 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
6467 cancel_work_sync(&link->u.mgd.request_smps_work);
6468 cancel_work_sync(&link->u.mgd.chswitch_work);
6471 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
6473 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6476 * Make sure some work items will not run after this,
6477 * they will not do anything but might not have been
6478 * cancelled when disconnecting.
6480 cancel_work_sync(&ifmgd->monitor_work);
6481 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
6482 cancel_work_sync(&ifmgd->csa_connection_drop_work);
6483 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
6486 if (ifmgd->assoc_data)
6487 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6488 if (ifmgd->auth_data)
6489 ieee80211_destroy_auth_data(sdata, false);
6490 spin_lock_bh(&ifmgd->teardown_lock);
6491 if (ifmgd->teardown_skb) {
6492 kfree_skb(ifmgd->teardown_skb);
6493 ifmgd->teardown_skb = NULL;
6494 ifmgd->orig_teardown_skb = NULL;
6496 kfree(ifmgd->assoc_req_ies);
6497 ifmgd->assoc_req_ies = NULL;
6498 ifmgd->assoc_req_ies_len = 0;
6499 spin_unlock_bh(&ifmgd->teardown_lock);
6500 del_timer_sync(&ifmgd->timer);
6501 sdata_unlock(sdata);
6504 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
6505 enum nl80211_cqm_rssi_threshold_event rssi_event,
6509 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6511 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
6513 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
6515 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
6517 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
6519 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6521 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
6523 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
6525 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
6527 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
6531 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
6533 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
6537 * Scale up threshold values before storing it, as the RSSI averaging
6538 * algorithm uses a scaled up value as well. Change this scaling
6539 * factor if the RSSI averaging algorithm changes.
6541 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
6542 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
6545 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
6549 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6551 WARN_ON(rssi_min_thold == rssi_max_thold ||
6552 rssi_min_thold > rssi_max_thold);
6554 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
6557 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
6559 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
6561 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
6563 _ieee80211_enable_rssi_reports(sdata, 0, 0);
6565 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);