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_sub_if_data *sdata,
147 struct ieee80211_link_data *link,
148 ieee80211_conn_flags_t conn_flags,
149 struct ieee80211_supported_band *sband,
150 struct ieee80211_channel *channel,
152 const struct ieee80211_ht_operation *ht_oper,
153 const struct ieee80211_vht_operation *vht_oper,
154 const struct ieee80211_he_operation *he_oper,
155 const struct ieee80211_eht_operation *eht_oper,
156 const struct ieee80211_s1g_oper_ie *s1g_oper,
157 struct cfg80211_chan_def *chandef, bool tracking)
159 struct cfg80211_chan_def vht_chandef;
160 struct ieee80211_sta_ht_cap sta_ht_cap;
161 ieee80211_conn_flags_t ret;
164 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
165 chandef->chan = channel;
166 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
167 chandef->center_freq1 = channel->center_freq;
168 chandef->freq1_offset = channel->freq_offset;
170 if (channel->band == NL80211_BAND_6GHZ) {
171 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
174 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
175 ret = IEEE80211_CONN_DISABLE_HT |
176 IEEE80211_CONN_DISABLE_VHT |
177 IEEE80211_CONN_DISABLE_HE |
178 IEEE80211_CONN_DISABLE_EHT;
182 vht_chandef = *chandef;
184 } else if (sband->band == NL80211_BAND_S1GHZ) {
185 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
187 "Missing S1G Operation Element? Trying operating == primary\n");
188 chandef->width = ieee80211_s1g_channel_width(channel);
191 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
192 IEEE80211_CONN_DISABLE_VHT |
193 IEEE80211_CONN_DISABLE_80P80MHZ |
194 IEEE80211_CONN_DISABLE_160MHZ;
198 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
199 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
201 if (!ht_oper || !sta_ht_cap.ht_supported) {
202 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
203 ret = IEEE80211_CONN_DISABLE_HT |
204 IEEE80211_CONN_DISABLE_VHT |
205 IEEE80211_CONN_DISABLE_HE |
206 IEEE80211_CONN_DISABLE_EHT;
210 chandef->width = NL80211_CHAN_WIDTH_20;
212 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
214 /* check that channel matches the right operating channel */
215 if (!tracking && channel->center_freq != ht_cfreq) {
217 * It's possible that some APs are confused here;
218 * Netgear WNDR3700 sometimes reports 4 higher than
219 * the actual channel in association responses, but
220 * since we look at probe response/beacon data here
224 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
225 channel->center_freq, ht_cfreq,
226 ht_oper->primary_chan, channel->band);
227 ret = IEEE80211_CONN_DISABLE_HT |
228 IEEE80211_CONN_DISABLE_VHT |
229 IEEE80211_CONN_DISABLE_HE |
230 IEEE80211_CONN_DISABLE_EHT;
234 /* check 40 MHz support, if we have it */
235 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
236 ieee80211_chandef_ht_oper(ht_oper, chandef);
238 mlme_dbg(sdata, "40 MHz not supported\n");
239 /* 40 MHz (and 80 MHz) must be supported for VHT */
240 ret = IEEE80211_CONN_DISABLE_VHT;
241 /* also mark 40 MHz disabled */
242 ret |= IEEE80211_CONN_DISABLE_40MHZ;
246 if (!vht_oper || !sband->vht_cap.vht_supported) {
247 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
248 ret = IEEE80211_CONN_DISABLE_VHT;
252 vht_chandef = *chandef;
253 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
255 (le32_to_cpu(he_oper->he_oper_params) &
256 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
257 struct ieee80211_vht_operation he_oper_vht_cap;
260 * Set only first 3 bytes (other 2 aren't used in
261 * ieee80211_chandef_vht_oper() anyway)
263 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
264 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
266 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
267 &he_oper_vht_cap, ht_oper,
269 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
271 "HE AP VHT information is invalid, disabling HE\n");
272 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
275 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
279 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
281 "AP VHT information is invalid, disabling VHT\n");
282 ret = IEEE80211_CONN_DISABLE_VHT;
286 if (!cfg80211_chandef_valid(&vht_chandef)) {
287 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
289 "AP VHT information is invalid, disabling VHT\n");
290 ret = IEEE80211_CONN_DISABLE_VHT;
294 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
299 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
300 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
302 "AP VHT information doesn't match HT, disabling VHT\n");
303 ret = IEEE80211_CONN_DISABLE_VHT;
307 *chandef = vht_chandef;
310 * handle the case that the EHT operation indicates that it holds EHT
311 * operation information (in case that the channel width differs from
312 * the channel width reported in HT/VHT/HE).
314 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
315 struct cfg80211_chan_def eht_chandef = *chandef;
317 ieee80211_chandef_eht_oper(eht_oper,
319 NL80211_CHAN_WIDTH_160,
320 false, &eht_chandef);
322 if (!cfg80211_chandef_valid(&eht_chandef)) {
323 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
325 "AP EHT information is invalid, disabling EHT\n");
326 ret = IEEE80211_CONN_DISABLE_EHT;
330 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
331 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
333 "AP EHT information is incompatible, disabling EHT\n");
334 ret = IEEE80211_CONN_DISABLE_EHT;
338 *chandef = eht_chandef;
345 * When tracking the current AP, don't do any further checks if the
346 * new chandef is identical to the one we're currently using for the
347 * connection. This keeps us from playing ping-pong with regulatory,
348 * without it the following can happen (for example):
349 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
350 * - AP advertises regdom US
351 * - CRDA loads regdom US with 80 MHz prohibited (old database)
352 * - the code below detects an unsupported channel, downgrades, and
353 * we disconnect from the AP in the caller
354 * - disconnect causes CRDA to reload world regdomain and the game
356 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
358 * It seems possible that there are still scenarios with CSA or real
359 * bandwidth changes where a this could happen, but those cases are
360 * less common and wouldn't completely prevent using the AP.
363 cfg80211_chandef_identical(chandef, &link->conf->chandef))
366 /* don't print the message below for VHT mismatch if VHT is disabled */
367 if (ret & IEEE80211_CONN_DISABLE_VHT)
368 vht_chandef = *chandef;
371 * Ignore the DISABLED flag when we're already connected and only
372 * tracking the APs beacon for bandwidth changes - otherwise we
373 * might get disconnected here if we connect to an AP, update our
374 * regulatory information based on the AP's country IE and the
375 * information we have is wrong/outdated and disables the channel
376 * that we're actually using for the connection to the AP.
378 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
380 IEEE80211_CHAN_DISABLED)) {
381 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
382 ret = IEEE80211_CONN_DISABLE_HT |
383 IEEE80211_CONN_DISABLE_VHT |
384 IEEE80211_CONN_DISABLE_HE |
385 IEEE80211_CONN_DISABLE_EHT;
389 ret |= ieee80211_chandef_downgrade(chandef);
392 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
393 IEEE80211_CHAN_NO_HE))
394 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
396 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
397 IEEE80211_CHAN_NO_EHT))
398 ret |= IEEE80211_CONN_DISABLE_EHT;
400 if (chandef->width != vht_chandef.width && !tracking)
402 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
404 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
408 static int ieee80211_config_bw(struct ieee80211_link_data *link,
409 const struct ieee80211_ht_cap *ht_cap,
410 const struct ieee80211_vht_cap *vht_cap,
411 const struct ieee80211_ht_operation *ht_oper,
412 const struct ieee80211_vht_operation *vht_oper,
413 const struct ieee80211_he_operation *he_oper,
414 const struct ieee80211_eht_operation *eht_oper,
415 const struct ieee80211_s1g_oper_ie *s1g_oper,
416 const u8 *bssid, u32 *changed)
418 struct ieee80211_sub_if_data *sdata = link->sdata;
419 struct ieee80211_local *local = sdata->local;
420 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
421 struct ieee80211_channel *chan = link->conf->chandef.chan;
422 struct ieee80211_supported_band *sband =
423 local->hw.wiphy->bands[chan->band];
424 struct cfg80211_chan_def chandef;
426 ieee80211_conn_flags_t flags;
427 u32 vht_cap_info = 0;
430 /* if HT was/is disabled, don't track any bandwidth changes */
431 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
434 /* don't check VHT if we associated as non-VHT station */
435 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
438 /* don't check HE if we associated as non-HE station */
439 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
440 !ieee80211_get_he_iftype_cap(sband,
441 ieee80211_vif_type_p2p(&sdata->vif))) {
446 /* don't check EHT if we associated as non-EHT station */
447 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
448 !ieee80211_get_eht_iftype_cap(sband,
449 ieee80211_vif_type_p2p(&sdata->vif)))
453 * if bss configuration changed store the new one -
454 * this may be applicable even if channel is identical
456 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
457 if (link->conf->ht_operation_mode != ht_opmode) {
458 *changed |= BSS_CHANGED_HT;
459 link->conf->ht_operation_mode = ht_opmode;
463 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
465 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
466 flags = ieee80211_determine_chantype(sdata, link,
467 link->u.mgd.conn_flags,
468 sband, chan, vht_cap_info,
471 s1g_oper, &chandef, true);
474 * Downgrade the new channel if we associated with restricted
475 * capabilities. For example, if we associated as a 20 MHz STA
476 * to a 40 MHz AP (due to regulatory, capabilities or config
477 * reasons) then switching to a 40 MHz channel now won't do us
478 * any good -- we couldn't use it with the AP.
480 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
481 chandef.width == NL80211_CHAN_WIDTH_80P80)
482 flags |= ieee80211_chandef_downgrade(&chandef);
483 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
484 chandef.width == NL80211_CHAN_WIDTH_160)
485 flags |= ieee80211_chandef_downgrade(&chandef);
486 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
487 chandef.width > NL80211_CHAN_WIDTH_20)
488 flags |= ieee80211_chandef_downgrade(&chandef);
490 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
494 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
495 link->u.mgd.bssid, chandef.chan->center_freq,
496 chandef.chan->freq_offset, chandef.width,
497 chandef.center_freq1, chandef.freq1_offset,
498 chandef.center_freq2);
500 if (flags != (link->u.mgd.conn_flags &
501 (IEEE80211_CONN_DISABLE_HT |
502 IEEE80211_CONN_DISABLE_VHT |
503 IEEE80211_CONN_DISABLE_HE |
504 IEEE80211_CONN_DISABLE_EHT |
505 IEEE80211_CONN_DISABLE_40MHZ |
506 IEEE80211_CONN_DISABLE_80P80MHZ |
507 IEEE80211_CONN_DISABLE_160MHZ |
508 IEEE80211_CONN_DISABLE_320MHZ)) ||
509 !cfg80211_chandef_valid(&chandef)) {
511 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
512 link->u.mgd.bssid, flags, ifmgd->flags);
516 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
520 "AP %pM changed bandwidth to incompatible one - disconnect\n",
528 /* frame sending functions */
530 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
531 struct sk_buff *skb, u8 ap_ht_param,
532 struct ieee80211_supported_band *sband,
533 struct ieee80211_channel *channel,
534 enum ieee80211_smps_mode smps,
535 ieee80211_conn_flags_t conn_flags)
538 u32 flags = channel->flags;
540 struct ieee80211_sta_ht_cap ht_cap;
542 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
544 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
545 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
547 /* determine capability flags */
550 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
551 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
552 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
553 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
554 cap &= ~IEEE80211_HT_CAP_SGI_40;
557 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
558 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
559 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
560 cap &= ~IEEE80211_HT_CAP_SGI_40;
566 * If 40 MHz was disabled associate as though we weren't
567 * capable of 40 MHz -- some broken APs will never fall
568 * back to trying to transmit in 20 MHz.
570 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
571 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
572 cap &= ~IEEE80211_HT_CAP_SGI_40;
575 /* set SM PS mode properly */
576 cap &= ~IEEE80211_HT_CAP_SM_PS;
578 case IEEE80211_SMPS_AUTOMATIC:
579 case IEEE80211_SMPS_NUM_MODES:
582 case IEEE80211_SMPS_OFF:
583 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
584 IEEE80211_HT_CAP_SM_PS_SHIFT;
586 case IEEE80211_SMPS_STATIC:
587 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
588 IEEE80211_HT_CAP_SM_PS_SHIFT;
590 case IEEE80211_SMPS_DYNAMIC:
591 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
592 IEEE80211_HT_CAP_SM_PS_SHIFT;
596 /* reserve and fill IE */
597 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
598 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
601 /* This function determines vht capability flags for the association
603 * Note - the function returns true to own the MU-MIMO capability
605 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
607 struct ieee80211_supported_band *sband,
608 struct ieee80211_vht_cap *ap_vht_cap,
609 ieee80211_conn_flags_t conn_flags)
611 struct ieee80211_local *local = sdata->local;
614 struct ieee80211_sta_vht_cap vht_cap;
615 u32 mask, ap_bf_sts, our_bf_sts;
616 bool mu_mimo_owner = false;
618 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
620 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
621 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
623 /* determine capability flags */
626 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
627 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
629 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
630 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
631 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
632 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
635 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
636 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
637 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
641 * Some APs apparently get confused if our capabilities are better
642 * than theirs, so restrict what we advertise in the assoc request.
644 if (!(ap_vht_cap->vht_cap_info &
645 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
646 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
647 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
648 else if (!(ap_vht_cap->vht_cap_info &
649 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
650 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
653 * If some other vif is using the MU-MIMO capability we cannot associate
654 * using MU-MIMO - this will lead to contradictions in the group-id
656 * Ownership is defined since association request, in order to avoid
657 * simultaneous associations with MU-MIMO.
659 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
660 bool disable_mu_mimo = false;
661 struct ieee80211_sub_if_data *other;
663 list_for_each_entry_rcu(other, &local->interfaces, list) {
664 if (other->vif.bss_conf.mu_mimo_owner) {
665 disable_mu_mimo = true;
670 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
672 mu_mimo_owner = true;
675 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
677 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
678 our_bf_sts = cap & mask;
680 if (ap_bf_sts < our_bf_sts) {
685 /* reserve and fill IE */
686 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
687 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
689 return mu_mimo_owner;
692 /* This function determines HE capability flags for the association
695 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
697 struct ieee80211_supported_band *sband,
698 enum ieee80211_smps_mode smps_mode,
699 ieee80211_conn_flags_t conn_flags)
701 u8 *pos, *pre_he_pos;
702 const struct ieee80211_sta_he_cap *he_cap;
705 he_cap = ieee80211_get_he_iftype_cap(sband,
706 ieee80211_vif_type_p2p(&sdata->vif));
707 if (WARN_ON(!he_cap))
710 /* get a max size estimate */
712 2 + 1 + sizeof(he_cap->he_cap_elem) +
713 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
714 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
715 he_cap->he_cap_elem.phy_cap_info);
716 pos = skb_put(skb, he_cap_size);
718 pos = ieee80211_ie_build_he_cap(conn_flags,
719 pos, he_cap, pos + he_cap_size);
720 /* trim excess if any */
721 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
723 ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
726 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
728 struct ieee80211_supported_band *sband)
731 const struct ieee80211_sta_he_cap *he_cap;
732 const struct ieee80211_sta_eht_cap *eht_cap;
735 he_cap = ieee80211_get_he_iftype_cap(sband,
736 ieee80211_vif_type_p2p(&sdata->vif));
737 eht_cap = ieee80211_get_eht_iftype_cap(sband,
738 ieee80211_vif_type_p2p(&sdata->vif));
741 * EHT capabilities element is only added if the HE capabilities element
742 * was added so assume that 'he_cap' is valid and don't check it.
744 if (WARN_ON(!he_cap || !eht_cap))
748 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
749 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
750 &eht_cap->eht_cap_elem,
752 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
753 eht_cap->eht_cap_elem.phy_cap_info);
754 pos = skb_put(skb, eht_cap_size);
755 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
759 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
760 enum nl80211_chan_width width,
761 struct ieee80211_supported_band *sband,
762 struct ieee80211_mgd_assoc_data *assoc_data)
764 unsigned int shift = ieee80211_chanwidth_get_shift(width);
765 unsigned int rates_len, supp_rates_len;
770 if (assoc_data->supp_rates_len) {
772 * Get all rates supported by the device and the AP as
773 * some APs don't like getting a superset of their rates
774 * in the association request (e.g. D-Link DAP 1353 in
777 rates_len = ieee80211_parse_bitrates(width, sband,
778 assoc_data->supp_rates,
779 assoc_data->supp_rates_len,
783 * In case AP not provide any supported rates information
784 * before association, we send information element(s) with
785 * all rates that we support.
787 rates_len = sband->n_bitrates;
788 for (i = 0; i < sband->n_bitrates; i++)
792 supp_rates_len = rates_len;
793 if (supp_rates_len > 8)
796 pos = skb_put(skb, supp_rates_len + 2);
797 *pos++ = WLAN_EID_SUPP_RATES;
798 *pos++ = supp_rates_len;
801 for (i = 0; i < sband->n_bitrates; i++) {
802 if (BIT(i) & rates) {
803 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
811 if (rates_len > count) {
812 pos = skb_put(skb, rates_len - count + 2);
813 *pos++ = WLAN_EID_EXT_SUPP_RATES;
814 *pos++ = rates_len - count;
816 for (i++; i < sband->n_bitrates; i++) {
817 if (BIT(i) & rates) {
820 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
828 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
835 static const u8 before_ht[] = {
838 WLAN_EID_EXT_SUPP_RATES,
839 WLAN_EID_PWR_CAPABILITY,
840 WLAN_EID_SUPPORTED_CHANNELS,
843 WLAN_EID_RRM_ENABLED_CAPABILITIES,
844 WLAN_EID_MOBILITY_DOMAIN,
845 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
846 WLAN_EID_RIC_DATA, /* reassoc only */
847 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
849 static const u8 after_ric[] = {
850 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
851 WLAN_EID_HT_CAPABILITY,
852 WLAN_EID_BSS_COEX_2040,
853 /* luckily this is almost always there */
854 WLAN_EID_EXT_CAPABILITY,
855 WLAN_EID_QOS_TRAFFIC_CAPA,
856 WLAN_EID_TIM_BCAST_REQ,
857 WLAN_EID_INTERWORKING,
858 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
859 WLAN_EID_VHT_CAPABILITY,
860 WLAN_EID_OPMODE_NOTIF,
866 noffset = ieee80211_ie_split_ric(elems, elems_len,
868 ARRAY_SIZE(before_ht),
870 ARRAY_SIZE(after_ric),
872 skb_put_data(skb, elems + offset, noffset - offset);
877 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
882 static const u8 before_vht[] = {
884 * no need to list the ones split off before HT
887 WLAN_EID_BSS_COEX_2040,
888 WLAN_EID_EXT_CAPABILITY,
889 WLAN_EID_QOS_TRAFFIC_CAPA,
890 WLAN_EID_TIM_BCAST_REQ,
891 WLAN_EID_INTERWORKING,
892 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
899 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
900 noffset = ieee80211_ie_split(elems, elems_len,
901 before_vht, ARRAY_SIZE(before_vht),
903 skb_put_data(skb, elems + offset, noffset - offset);
908 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
913 static const u8 before_he[] = {
915 * no need to list the ones split off before VHT
918 WLAN_EID_OPMODE_NOTIF,
919 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
921 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
922 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
923 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
924 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
925 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
926 /* TODO: add 11ah/11aj/11ak elements */
933 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
934 noffset = ieee80211_ie_split(elems, elems_len,
935 before_he, ARRAY_SIZE(before_he),
937 skb_put_data(skb, elems + offset, noffset - offset);
942 #define PRESENT_ELEMS_MAX 8
943 #define PRESENT_ELEM_EXT_OFFS 0x100
945 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
946 struct sk_buff *skb, u16 capab,
947 const struct element *ext_capa,
948 const u16 *present_elems);
950 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
951 struct sk_buff *skb, u16 *capab,
952 const struct element *ext_capa,
953 const u8 *extra_elems,
954 size_t extra_elems_len,
955 unsigned int link_id,
956 struct ieee80211_link_data *link,
959 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
960 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
961 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
962 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
963 struct ieee80211_channel *chan = cbss->channel;
964 const struct ieee80211_sband_iftype_data *iftd;
965 struct ieee80211_local *local = sdata->local;
966 struct ieee80211_supported_band *sband;
967 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
968 struct ieee80211_chanctx_conf *chanctx_conf;
969 enum ieee80211_smps_mode smps_mode;
970 u16 orig_capab = *capab;
972 int present_elems_len = 0;
976 #define ADD_PRESENT_ELEM(id) do { \
977 /* need a last for termination - we use 0 == SSID */ \
978 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
979 present_elems[present_elems_len++] = (id); \
981 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
984 smps_mode = link->smps_mode;
985 else if (sdata->u.mgd.powersave)
986 smps_mode = IEEE80211_SMPS_DYNAMIC;
988 smps_mode = IEEE80211_SMPS_OFF;
992 * 5/10 MHz scenarios are only viable without MLO, in which
993 * case this pointer should be used ... All of this is a bit
994 * unclear though, not sure this even works at all.
997 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
999 width = chanctx_conf->def.width;
1003 sband = local->hw.wiphy->bands[chan->band];
1004 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1006 if (sband->band == NL80211_BAND_2GHZ) {
1007 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1008 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1011 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1012 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1013 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1015 if (sband->band != NL80211_BAND_S1GHZ)
1016 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1018 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1019 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1020 struct cfg80211_chan_def chandef = {
1025 pos = skb_put(skb, 4);
1026 *pos++ = WLAN_EID_PWR_CAPABILITY;
1028 *pos++ = 0; /* min tx power */
1030 *pos++ = ieee80211_chandef_max_power(&chandef);
1031 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1035 * Per spec, we shouldn't include the list of channels if we advertise
1036 * support for extended channel switching, but we've always done that;
1037 * (for now?) apply this restriction only on the (new) 6 GHz band.
1039 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1040 (sband->band != NL80211_BAND_6GHZ ||
1041 !ext_capa || ext_capa->datalen < 1 ||
1042 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1043 /* TODO: get this in reg domain format */
1044 pos = skb_put(skb, 2 * sband->n_channels + 2);
1045 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1046 *pos++ = 2 * sband->n_channels;
1047 for (i = 0; i < sband->n_channels; i++) {
1048 int cf = sband->channels[i].center_freq;
1050 *pos++ = ieee80211_frequency_to_channel(cf);
1051 *pos++ = 1; /* one channel in the subband*/
1053 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1056 /* if present, add any custom IEs that go before HT */
1057 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1061 if (sband->band != NL80211_BAND_6GHZ &&
1062 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
1063 ieee80211_add_ht_ie(sdata, skb,
1064 assoc_data->link[link_id].ap_ht_param,
1065 sband, chan, smps_mode,
1066 assoc_data->link[link_id].conn_flags);
1067 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1070 /* if present, add any custom IEs that go before VHT */
1071 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1075 if (sband->band != NL80211_BAND_6GHZ &&
1076 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
1077 bool mu_mimo_owner =
1078 ieee80211_add_vht_ie(sdata, skb, sband,
1079 &assoc_data->link[link_id].ap_vht_cap,
1080 assoc_data->link[link_id].conn_flags);
1083 link->conf->mu_mimo_owner = mu_mimo_owner;
1084 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1088 * If AP doesn't support HT, mark HE and EHT as disabled.
1089 * If on the 5GHz band, make sure it supports VHT.
1091 if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
1092 (sband->band == NL80211_BAND_5GHZ &&
1093 assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
1094 assoc_data->link[link_id].conn_flags |=
1095 IEEE80211_CONN_DISABLE_HE |
1096 IEEE80211_CONN_DISABLE_EHT;
1098 /* if present, add any custom IEs that go before HE */
1099 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1103 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1104 ieee80211_add_he_ie(sdata, skb, sband, smps_mode,
1105 assoc_data->link[link_id].conn_flags);
1106 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1110 * careful - need to know about all the present elems before
1111 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1112 * we're going to put it after the ML element
1114 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1115 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1117 if (link_id == assoc_data->assoc_link_id)
1118 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1121 /* crash if somebody gets it wrong */
1122 present_elems = NULL;
1124 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1125 ieee80211_add_eht_ie(sdata, skb, sband);
1127 if (sband->band == NL80211_BAND_S1GHZ) {
1128 ieee80211_add_aid_request_ie(sdata, skb);
1129 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1132 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1133 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1136 link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
1141 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1145 unsigned int skb_len = skb->len;
1148 u8 *len, *list_len = NULL;
1150 skb_put_u8(skb, WLAN_EID_EXTENSION);
1151 len = skb_put(skb, 1);
1152 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1154 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1155 u16 elem = outer[i];
1156 bool have_inner = false;
1157 bool at_extension = false;
1159 /* should at least be sorted in the sense of normal -> ext */
1160 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1162 /* switch to extension list */
1163 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1164 at_extension = true;
1170 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1171 if (elem == inner[j]) {
1181 list_len = skb_put(skb, 1);
1185 skb_put_u8(skb, (u8)elem);
1189 skb_trim(skb, skb_len);
1191 *len = skb->len - skb_len - 2;
1194 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1195 struct sk_buff *skb, u16 capab,
1196 const struct element *ext_capa,
1197 const u16 *outer_present_elems)
1199 struct ieee80211_local *local = sdata->local;
1200 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1201 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1202 struct ieee80211_multi_link_elem *ml_elem;
1203 struct ieee80211_mle_basic_common_info *common;
1204 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1205 __le16 eml_capa = 0, mld_capa_ops = 0;
1206 unsigned int link_id;
1210 if (!sdata->vif.valid_links)
1213 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1214 ieee80211_vif_type_p2p(&sdata->vif));
1216 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1217 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1220 skb_put_u8(skb, WLAN_EID_EXTENSION);
1221 ml_elem_len = skb_put(skb, 1);
1222 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1223 ml_elem = skb_put(skb, sizeof(*ml_elem));
1225 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1226 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1227 common = skb_put(skb, sizeof(*common));
1228 common->len = sizeof(*common) +
1229 2; /* MLD capa/ops */
1230 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1232 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1234 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1235 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1236 common->len += 2; /* EML capabilities */
1238 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1239 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1241 /* need indication from userspace to support this */
1242 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1243 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1245 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1246 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1247 const u8 *extra_elems;
1248 size_t extra_elems_len;
1250 u8 *subelem_len = NULL;
1253 if (!assoc_data->link[link_id].bss ||
1254 link_id == assoc_data->assoc_link_id)
1257 extra_elems = assoc_data->link[link_id].elems;
1258 extra_elems_len = assoc_data->link[link_id].elems_len;
1260 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1261 subelem_len = skb_put(skb, 1);
1263 ctrl = cpu_to_le16(link_id |
1264 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1265 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1266 skb_put_data(skb, &ctrl, sizeof(ctrl));
1267 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1268 skb_put_data(skb, assoc_data->link[link_id].addr,
1271 * Now add the contents of the (re)association request,
1272 * but the "listen interval" and "current AP address"
1273 * (if applicable) are skipped. So we only have
1274 * the capability field (remember the position and fill
1275 * later), followed by the elements added below by
1276 * calling ieee80211_assoc_link_elems().
1278 capab_pos = skb_put(skb, 2);
1280 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1285 link_present_elems);
1287 skb_put_data(skb, extra_elems + extra_used,
1288 extra_elems_len - extra_used);
1290 put_unaligned_le16(capab, capab_pos);
1292 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1293 link_present_elems);
1295 ieee80211_fragment_element(skb, subelem_len);
1298 ieee80211_fragment_element(skb, ml_elem_len);
1301 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1303 struct ieee80211_local *local = sdata->local;
1304 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1305 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1306 struct ieee80211_link_data *link;
1307 struct sk_buff *skb;
1308 struct ieee80211_mgmt *mgmt;
1309 u8 *pos, qos_info, *ie_start;
1310 size_t offset, noffset;
1311 u16 capab = WLAN_CAPABILITY_ESS, link_capab;
1313 struct element *ext_capa = NULL;
1314 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1315 struct ieee80211_prep_tx_info info = {};
1316 unsigned int link_id, n_links = 0;
1317 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1322 /* we know it's writable, cast away the const */
1323 if (assoc_data->ie_len)
1324 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1326 assoc_data->ie_len);
1328 sdata_assert_lock(sdata);
1330 size = local->hw.extra_tx_headroom +
1331 sizeof(*mgmt) + /* bit too much but doesn't matter */
1332 2 + assoc_data->ssid_len + /* SSID */
1333 assoc_data->ie_len + /* extra IEs */
1334 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1337 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1338 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1339 const struct ieee80211_sband_iftype_data *iftd;
1340 struct ieee80211_supported_band *sband;
1345 sband = local->hw.wiphy->bands[cbss->channel->band];
1348 /* add STA profile elements length */
1349 size += assoc_data->link[link_id].elems_len;
1350 /* and supported rates length */
1351 size += 4 + sband->n_bitrates;
1352 /* supported channels */
1353 size += 2 + 2 * sband->n_channels;
1355 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1357 size += iftd->vendor_elems.len;
1359 /* power capability */
1362 /* HT, VHT, HE, EHT */
1363 size += 2 + sizeof(struct ieee80211_ht_cap);
1364 size += 2 + sizeof(struct ieee80211_vht_cap);
1365 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1366 sizeof(struct ieee80211_he_mcs_nss_supp) +
1367 IEEE80211_HE_PPE_THRES_MAX_LEN;
1369 if (sband->band == NL80211_BAND_6GHZ)
1370 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1372 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1373 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1374 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1376 /* non-inheritance element */
1377 size += 2 + 2 + PRESENT_ELEMS_MAX;
1379 /* should be the same across all BSSes */
1380 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1381 capab |= WLAN_CAPABILITY_PRIVACY;
1384 if (sdata->vif.valid_links) {
1385 /* consider the multi-link element with STA profile */
1386 size += sizeof(struct ieee80211_multi_link_elem);
1387 /* max common info field in basic multi-link element */
1388 size += sizeof(struct ieee80211_mle_basic_common_info) +
1393 * The capability elements were already considered above;
1394 * note this over-estimates a bit because there's no
1395 * STA profile for the assoc link.
1397 size += (n_links - 1) *
1398 (1 + 1 + /* subelement ID/length */
1399 2 + /* STA control */
1400 1 + ETH_ALEN + 2 /* STA Info field */);
1403 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1407 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1410 skb = alloc_skb(size, GFP_KERNEL);
1414 skb_reserve(skb, local->hw.extra_tx_headroom);
1416 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1417 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1419 /* Set MBSSID support for HE AP if needed */
1420 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1421 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1422 ext_capa && ext_capa->datalen >= 3)
1423 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1425 mgmt = skb_put_zero(skb, 24);
1426 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
1427 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1428 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
1430 listen_int = cpu_to_le16(assoc_data->s1g ?
1431 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1432 local->hw.conf.listen_interval);
1433 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1435 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1436 IEEE80211_STYPE_REASSOC_REQ);
1437 capab_pos = &mgmt->u.reassoc_req.capab_info;
1438 mgmt->u.reassoc_req.listen_interval = listen_int;
1439 memcpy(mgmt->u.reassoc_req.current_ap,
1440 assoc_data->prev_ap_addr, ETH_ALEN);
1441 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1444 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1445 IEEE80211_STYPE_ASSOC_REQ);
1446 capab_pos = &mgmt->u.assoc_req.capab_info;
1447 mgmt->u.assoc_req.listen_interval = listen_int;
1448 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1452 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1454 *pos++ = WLAN_EID_SSID;
1455 *pos++ = assoc_data->ssid_len;
1456 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1458 /* add the elements for the assoc (main) link */
1460 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1464 assoc_data->assoc_link_id, link,
1466 put_unaligned_le16(link_capab, capab_pos);
1468 /* if present, add any custom non-vendor IEs */
1469 if (assoc_data->ie_len) {
1470 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1473 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1477 if (assoc_data->wmm) {
1478 if (assoc_data->uapsd) {
1479 qos_info = ifmgd->uapsd_queues;
1480 qos_info |= (ifmgd->uapsd_max_sp_len <<
1481 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1486 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1489 /* add any remaining custom (i.e. vendor specific here) IEs */
1490 if (assoc_data->ie_len) {
1491 noffset = assoc_data->ie_len;
1492 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1495 if (assoc_data->fils_kek_len) {
1496 ret = fils_encrypt_assoc_req(skb, assoc_data);
1503 pos = skb_tail_pointer(skb);
1504 kfree(ifmgd->assoc_req_ies);
1505 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1506 if (!ifmgd->assoc_req_ies) {
1511 ifmgd->assoc_req_ies_len = pos - ie_start;
1513 drv_mgd_prepare_tx(local, sdata, &info);
1515 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1516 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1517 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1518 IEEE80211_TX_INTFL_MLME_CONN_TX;
1519 ieee80211_tx_skb(sdata, skb);
1524 void ieee80211_send_pspoll(struct ieee80211_local *local,
1525 struct ieee80211_sub_if_data *sdata)
1527 struct ieee80211_pspoll *pspoll;
1528 struct sk_buff *skb;
1530 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1534 pspoll = (struct ieee80211_pspoll *) skb->data;
1535 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1537 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1538 ieee80211_tx_skb(sdata, skb);
1541 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1542 struct ieee80211_sub_if_data *sdata,
1545 struct sk_buff *skb;
1546 struct ieee80211_hdr_3addr *nullfunc;
1547 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1549 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
1550 !ieee80211_hw_check(&local->hw,
1551 DOESNT_SUPPORT_QOS_NDP));
1555 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1557 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1559 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1560 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1562 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1563 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1565 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1566 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1568 ieee80211_tx_skb(sdata, skb);
1571 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1572 struct ieee80211_sub_if_data *sdata)
1574 struct sk_buff *skb;
1575 struct ieee80211_hdr *nullfunc;
1578 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1581 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1585 skb_reserve(skb, local->hw.extra_tx_headroom);
1587 nullfunc = skb_put_zero(skb, 30);
1588 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1589 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1590 nullfunc->frame_control = fc;
1591 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1592 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1593 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1594 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1596 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1597 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1598 ieee80211_tx_skb(sdata, skb);
1601 /* spectrum management related things */
1602 static void ieee80211_chswitch_work(struct work_struct *work)
1604 struct ieee80211_link_data *link =
1605 container_of(work, struct ieee80211_link_data, u.mgd.chswitch_work);
1606 struct ieee80211_sub_if_data *sdata = link->sdata;
1607 struct ieee80211_local *local = sdata->local;
1608 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1611 if (!ieee80211_sdata_running(sdata))
1615 mutex_lock(&local->mtx);
1616 mutex_lock(&local->chanctx_mtx);
1618 if (!ifmgd->associated)
1621 if (!link->conf->csa_active)
1625 * using reservation isn't immediate as it may be deferred until later
1626 * with multi-vif. once reservation is complete it will re-schedule the
1627 * work with no reserved_chanctx so verify chandef to check if it
1628 * completed successfully
1631 if (link->reserved_chanctx) {
1633 * with multi-vif csa driver may call ieee80211_csa_finish()
1634 * many times while waiting for other interfaces to use their
1637 if (link->reserved_ready)
1640 ret = ieee80211_link_use_reserved_context(link);
1643 "failed to use reserved channel context, disconnecting (err=%d)\n",
1645 ieee80211_queue_work(&sdata->local->hw,
1646 &ifmgd->csa_connection_drop_work);
1653 if (!cfg80211_chandef_identical(&link->conf->chandef,
1654 &link->csa_chandef)) {
1656 "failed to finalize channel switch, disconnecting\n");
1657 ieee80211_queue_work(&sdata->local->hw,
1658 &ifmgd->csa_connection_drop_work);
1662 link->u.mgd.csa_waiting_bcn = true;
1664 ieee80211_sta_reset_beacon_monitor(sdata);
1665 ieee80211_sta_reset_conn_monitor(sdata);
1668 mutex_unlock(&local->chanctx_mtx);
1669 mutex_unlock(&local->mtx);
1670 sdata_unlock(sdata);
1673 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1675 struct ieee80211_sub_if_data *sdata = link->sdata;
1676 struct ieee80211_local *local = sdata->local;
1677 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1680 sdata_assert_lock(sdata);
1682 WARN_ON(!link->conf->csa_active);
1684 if (link->csa_block_tx) {
1685 ieee80211_wake_vif_queues(local, sdata,
1686 IEEE80211_QUEUE_STOP_REASON_CSA);
1687 link->csa_block_tx = false;
1690 link->conf->csa_active = false;
1691 link->u.mgd.csa_waiting_bcn = false;
1693 * If the CSA IE is still present on the beacon after the switch,
1694 * we need to consider it as a new CSA (possibly to self).
1696 link->u.mgd.beacon_crc_valid = false;
1698 ret = drv_post_channel_switch(sdata);
1701 "driver post channel switch failed, disconnecting\n");
1702 ieee80211_queue_work(&local->hw,
1703 &ifmgd->csa_connection_drop_work);
1707 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0);
1710 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1712 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1713 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1715 if (WARN_ON(sdata->vif.valid_links))
1718 trace_api_chswitch_done(sdata, success);
1721 "driver channel switch failed, disconnecting\n");
1722 ieee80211_queue_work(&sdata->local->hw,
1723 &ifmgd->csa_connection_drop_work);
1725 ieee80211_queue_work(&sdata->local->hw,
1726 &sdata->deflink.u.mgd.chswitch_work);
1729 EXPORT_SYMBOL(ieee80211_chswitch_done);
1731 static void ieee80211_chswitch_timer(struct timer_list *t)
1733 struct ieee80211_link_data *link =
1734 from_timer(link, t, u.mgd.chswitch_timer);
1736 ieee80211_queue_work(&link->sdata->local->hw,
1737 &link->u.mgd.chswitch_work);
1741 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1743 struct ieee80211_sub_if_data *sdata = link->sdata;
1744 struct ieee80211_local *local = sdata->local;
1746 if (!local->ops->abort_channel_switch)
1749 mutex_lock(&local->mtx);
1751 mutex_lock(&local->chanctx_mtx);
1752 ieee80211_link_unreserve_chanctx(link);
1753 mutex_unlock(&local->chanctx_mtx);
1755 if (link->csa_block_tx)
1756 ieee80211_wake_vif_queues(local, sdata,
1757 IEEE80211_QUEUE_STOP_REASON_CSA);
1759 link->csa_block_tx = false;
1760 link->conf->csa_active = false;
1762 mutex_unlock(&local->mtx);
1764 drv_abort_channel_switch(sdata);
1768 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1769 u64 timestamp, u32 device_timestamp,
1770 struct ieee802_11_elems *elems,
1773 struct ieee80211_sub_if_data *sdata = link->sdata;
1774 struct ieee80211_local *local = sdata->local;
1775 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1776 struct cfg80211_bss *cbss = link->u.mgd.bss;
1777 struct ieee80211_chanctx_conf *conf;
1778 struct ieee80211_chanctx *chanctx;
1779 enum nl80211_band current_band;
1780 struct ieee80211_csa_ie csa_ie;
1781 struct ieee80211_channel_switch ch_switch;
1782 struct ieee80211_bss *bss;
1785 sdata_assert_lock(sdata);
1790 if (local->scanning)
1793 current_band = cbss->channel->band;
1794 bss = (void *)cbss->priv;
1795 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1797 link->u.mgd.conn_flags,
1798 link->u.mgd.bssid, &csa_ie);
1801 ch_switch.timestamp = timestamp;
1802 ch_switch.device_timestamp = device_timestamp;
1803 ch_switch.block_tx = csa_ie.mode;
1804 ch_switch.chandef = csa_ie.chandef;
1805 ch_switch.count = csa_ie.count;
1806 ch_switch.delay = csa_ie.max_switch_time;
1810 goto lock_and_drop_connection;
1812 if (beacon && link->conf->csa_active &&
1813 !link->u.mgd.csa_waiting_bcn) {
1815 ieee80211_sta_abort_chanswitch(link);
1817 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1819 } else if (link->conf->csa_active || res) {
1820 /* disregard subsequent announcements if already processing */
1824 if (link->conf->chandef.chan->band !=
1825 csa_ie.chandef.chan->band) {
1827 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1829 csa_ie.chandef.chan->center_freq,
1830 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1831 csa_ie.chandef.center_freq2);
1832 goto lock_and_drop_connection;
1835 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1836 IEEE80211_CHAN_DISABLED)) {
1838 "AP %pM switches to unsupported channel "
1839 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1842 csa_ie.chandef.chan->center_freq,
1843 csa_ie.chandef.chan->freq_offset,
1844 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1845 csa_ie.chandef.freq1_offset,
1846 csa_ie.chandef.center_freq2);
1847 goto lock_and_drop_connection;
1850 if (cfg80211_chandef_identical(&csa_ie.chandef,
1851 &link->conf->chandef) &&
1852 (!csa_ie.mode || !beacon)) {
1853 if (link->u.mgd.csa_ignored_same_chan)
1856 "AP %pM tries to chanswitch to same channel, ignore\n",
1858 link->u.mgd.csa_ignored_same_chan = true;
1863 * Drop all TDLS peers - either we disconnect or move to a different
1864 * channel from this point on. There's no telling what our peer will do.
1865 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1866 * have an incompatible wider chandef.
1868 ieee80211_teardown_tdls_peers(sdata);
1870 mutex_lock(&local->mtx);
1871 mutex_lock(&local->chanctx_mtx);
1872 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1873 lockdep_is_held(&local->chanctx_mtx));
1876 "no channel context assigned to vif?, disconnecting\n");
1877 goto drop_connection;
1880 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1882 if (local->use_chanctx &&
1883 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1885 "driver doesn't support chan-switch with channel contexts\n");
1886 goto drop_connection;
1889 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1891 "preparing for channel switch failed, disconnecting\n");
1892 goto drop_connection;
1895 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1896 chanctx->mode, false);
1899 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1901 goto drop_connection;
1903 mutex_unlock(&local->chanctx_mtx);
1905 link->conf->csa_active = true;
1906 link->csa_chandef = csa_ie.chandef;
1907 link->csa_block_tx = csa_ie.mode;
1908 link->u.mgd.csa_ignored_same_chan = false;
1909 link->u.mgd.beacon_crc_valid = false;
1911 if (link->csa_block_tx)
1912 ieee80211_stop_vif_queues(local, sdata,
1913 IEEE80211_QUEUE_STOP_REASON_CSA);
1914 mutex_unlock(&local->mtx);
1916 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, 0,
1917 csa_ie.count, csa_ie.mode);
1919 if (local->ops->channel_switch) {
1920 /* use driver's channel switch callback */
1921 drv_channel_switch(local, sdata, &ch_switch);
1925 /* channel switch handled in software */
1926 if (csa_ie.count <= 1)
1927 ieee80211_queue_work(&local->hw, &link->u.mgd.chswitch_work);
1929 mod_timer(&link->u.mgd.chswitch_timer,
1930 TU_TO_EXP_TIME((csa_ie.count - 1) *
1931 cbss->beacon_interval));
1933 lock_and_drop_connection:
1934 mutex_lock(&local->mtx);
1935 mutex_lock(&local->chanctx_mtx);
1938 * This is just so that the disconnect flow will know that
1939 * we were trying to switch channel and failed. In case the
1940 * mode is 1 (we are not allowed to Tx), we will know not to
1941 * send a deauthentication frame. Those two fields will be
1942 * reset when the disconnection worker runs.
1944 link->conf->csa_active = true;
1945 link->csa_block_tx = csa_ie.mode;
1947 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
1948 mutex_unlock(&local->chanctx_mtx);
1949 mutex_unlock(&local->mtx);
1953 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
1954 struct ieee80211_channel *channel,
1955 const u8 *country_ie, u8 country_ie_len,
1956 const u8 *pwr_constr_elem,
1957 int *chan_pwr, int *pwr_reduction)
1959 struct ieee80211_country_ie_triplet *triplet;
1960 int chan = ieee80211_frequency_to_channel(channel->center_freq);
1961 int i, chan_increment;
1962 bool have_chan_pwr = false;
1965 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
1968 triplet = (void *)(country_ie + 3);
1969 country_ie_len -= 3;
1971 switch (channel->band) {
1975 case NL80211_BAND_2GHZ:
1976 case NL80211_BAND_60GHZ:
1977 case NL80211_BAND_LC:
1980 case NL80211_BAND_5GHZ:
1983 case NL80211_BAND_6GHZ:
1985 * In the 6 GHz band, the "maximum transmit power level"
1986 * field in the triplets is reserved, and thus will be
1987 * zero and we shouldn't use it to control TX power.
1988 * The actual TX power will be given in the transmit
1989 * power envelope element instead.
1995 while (country_ie_len >= 3) {
1996 u8 first_channel = triplet->chans.first_channel;
1998 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
2001 for (i = 0; i < triplet->chans.num_channels; i++) {
2002 if (first_channel + i * chan_increment == chan) {
2003 have_chan_pwr = true;
2004 *chan_pwr = triplet->chans.max_power;
2013 country_ie_len -= 3;
2016 if (have_chan_pwr && pwr_constr_elem)
2017 *pwr_reduction = *pwr_constr_elem;
2021 return have_chan_pwr;
2024 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
2025 struct ieee80211_channel *channel,
2026 const u8 *cisco_dtpc_ie,
2029 /* From practical testing, the first data byte of the DTPC element
2030 * seems to contain the requested dBm level, and the CLI on Cisco
2031 * APs clearly state the range is -127 to 127 dBm, which indicates
2032 * a signed byte, although it seemingly never actually goes negative.
2033 * The other byte seems to always be zero.
2035 *pwr_level = (__s8)cisco_dtpc_ie[4];
2038 static u32 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2039 struct ieee80211_channel *channel,
2040 struct ieee80211_mgmt *mgmt,
2041 const u8 *country_ie, u8 country_ie_len,
2042 const u8 *pwr_constr_ie,
2043 const u8 *cisco_dtpc_ie)
2045 struct ieee80211_sub_if_data *sdata = link->sdata;
2046 bool has_80211h_pwr = false, has_cisco_pwr = false;
2047 int chan_pwr = 0, pwr_reduction_80211h = 0;
2048 int pwr_level_cisco, pwr_level_80211h;
2050 __le16 capab = mgmt->u.probe_resp.capab_info;
2052 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2053 return 0; /* TODO */
2056 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2057 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2058 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2059 sdata, channel, country_ie, country_ie_len,
2060 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2062 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2065 if (cisco_dtpc_ie) {
2066 ieee80211_find_cisco_dtpc(
2067 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
2068 has_cisco_pwr = true;
2071 if (!has_80211h_pwr && !has_cisco_pwr)
2074 /* If we have both 802.11h and Cisco DTPC, apply both limits
2075 * by picking the smallest of the two power levels advertised.
2077 if (has_80211h_pwr &&
2078 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2079 new_ap_level = pwr_level_80211h;
2081 if (link->ap_power_level == new_ap_level)
2085 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2086 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2088 } else { /* has_cisco_pwr is always true here. */
2089 new_ap_level = pwr_level_cisco;
2091 if (link->ap_power_level == new_ap_level)
2095 "Limiting TX power to %d dBm as advertised by %pM\n",
2096 pwr_level_cisco, link->u.mgd.bssid);
2099 link->ap_power_level = new_ap_level;
2100 if (__ieee80211_recalc_txpower(sdata))
2101 return BSS_CHANGED_TXPOWER;
2106 static void ieee80211_enable_ps(struct ieee80211_local *local,
2107 struct ieee80211_sub_if_data *sdata)
2109 struct ieee80211_conf *conf = &local->hw.conf;
2112 * If we are scanning right now then the parameters will
2113 * take effect when scan finishes.
2115 if (local->scanning)
2118 if (conf->dynamic_ps_timeout > 0 &&
2119 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2120 mod_timer(&local->dynamic_ps_timer, jiffies +
2121 msecs_to_jiffies(conf->dynamic_ps_timeout));
2123 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
2124 ieee80211_send_nullfunc(local, sdata, true);
2126 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2127 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2130 conf->flags |= IEEE80211_CONF_PS;
2131 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2135 static void ieee80211_change_ps(struct ieee80211_local *local)
2137 struct ieee80211_conf *conf = &local->hw.conf;
2139 if (local->ps_sdata) {
2140 ieee80211_enable_ps(local, local->ps_sdata);
2141 } else if (conf->flags & IEEE80211_CONF_PS) {
2142 conf->flags &= ~IEEE80211_CONF_PS;
2143 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2144 del_timer_sync(&local->dynamic_ps_timer);
2145 cancel_work_sync(&local->dynamic_ps_enable_work);
2149 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2151 struct ieee80211_local *local = sdata->local;
2152 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2153 struct sta_info *sta = NULL;
2154 bool authorized = false;
2156 if (!mgd->powersave)
2162 if (!mgd->associated)
2165 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2168 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2169 !sdata->deflink.u.mgd.have_beacon)
2173 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2175 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2181 /* need to hold RTNL or interface lock */
2182 void ieee80211_recalc_ps(struct ieee80211_local *local)
2184 struct ieee80211_sub_if_data *sdata, *found = NULL;
2188 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2189 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2190 local->ps_sdata = NULL;
2194 list_for_each_entry(sdata, &local->interfaces, list) {
2195 if (!ieee80211_sdata_running(sdata))
2197 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2198 /* If an AP vif is found, then disable PS
2199 * by setting the count to zero thereby setting
2205 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2211 if (count == 1 && ieee80211_powersave_allowed(found)) {
2212 u8 dtimper = found->deflink.u.mgd.dtim_period;
2214 timeout = local->dynamic_ps_forced_timeout;
2217 local->hw.conf.dynamic_ps_timeout = timeout;
2219 /* If the TIM IE is invalid, pretend the value is 1 */
2223 local->hw.conf.ps_dtim_period = dtimper;
2224 local->ps_sdata = found;
2226 local->ps_sdata = NULL;
2229 ieee80211_change_ps(local);
2232 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2234 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2236 if (sdata->vif.cfg.ps != ps_allowed) {
2237 sdata->vif.cfg.ps = ps_allowed;
2238 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2242 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2244 struct ieee80211_local *local =
2245 container_of(work, struct ieee80211_local,
2246 dynamic_ps_disable_work);
2248 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2249 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2250 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2253 ieee80211_wake_queues_by_reason(&local->hw,
2254 IEEE80211_MAX_QUEUE_MAP,
2255 IEEE80211_QUEUE_STOP_REASON_PS,
2259 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2261 struct ieee80211_local *local =
2262 container_of(work, struct ieee80211_local,
2263 dynamic_ps_enable_work);
2264 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2265 struct ieee80211_if_managed *ifmgd;
2266 unsigned long flags;
2269 /* can only happen when PS was just disabled anyway */
2273 ifmgd = &sdata->u.mgd;
2275 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2278 if (local->hw.conf.dynamic_ps_timeout > 0) {
2279 /* don't enter PS if TX frames are pending */
2280 if (drv_tx_frames_pending(local)) {
2281 mod_timer(&local->dynamic_ps_timer, jiffies +
2283 local->hw.conf.dynamic_ps_timeout));
2288 * transmission can be stopped by others which leads to
2289 * dynamic_ps_timer expiry. Postpone the ps timer if it
2290 * is not the actual idle state.
2292 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2293 for (q = 0; q < local->hw.queues; q++) {
2294 if (local->queue_stop_reasons[q]) {
2295 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2297 mod_timer(&local->dynamic_ps_timer, jiffies +
2299 local->hw.conf.dynamic_ps_timeout));
2303 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2306 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2307 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2308 if (drv_tx_frames_pending(local)) {
2309 mod_timer(&local->dynamic_ps_timer, jiffies +
2311 local->hw.conf.dynamic_ps_timeout));
2313 ieee80211_send_nullfunc(local, sdata, true);
2314 /* Flush to get the tx status of nullfunc frame */
2315 ieee80211_flush_queues(local, sdata, false);
2319 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2320 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2321 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2322 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2323 local->hw.conf.flags |= IEEE80211_CONF_PS;
2324 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2328 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2330 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2332 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
2335 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
2337 struct delayed_work *delayed_work = to_delayed_work(work);
2338 struct ieee80211_link_data *link =
2339 container_of(delayed_work, struct ieee80211_link_data,
2340 dfs_cac_timer_work);
2341 struct cfg80211_chan_def chandef = link->conf->chandef;
2342 struct ieee80211_sub_if_data *sdata = link->sdata;
2344 mutex_lock(&sdata->local->mtx);
2345 if (sdata->wdev.cac_started) {
2346 ieee80211_link_release_channel(link);
2347 cfg80211_cac_event(sdata->dev, &chandef,
2348 NL80211_RADAR_CAC_FINISHED,
2351 mutex_unlock(&sdata->local->mtx);
2355 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2357 struct ieee80211_local *local = sdata->local;
2358 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2362 if (local->hw.queues < IEEE80211_NUM_ACS)
2365 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2366 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2368 unsigned long now = jiffies;
2370 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2371 tx_tspec->admitted_time &&
2372 time_after(now, tx_tspec->time_slice_start + HZ)) {
2373 tx_tspec->consumed_tx_time = 0;
2374 tx_tspec->time_slice_start = now;
2376 if (tx_tspec->downgraded)
2378 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2381 switch (tx_tspec->action) {
2382 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2383 /* take the original parameters */
2384 if (drv_conf_tx(local, &sdata->deflink, ac,
2385 &sdata->deflink.tx_conf[ac]))
2386 link_err(&sdata->deflink,
2387 "failed to set TX queue parameters for queue %d\n",
2389 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2390 tx_tspec->downgraded = false;
2393 case TX_TSPEC_ACTION_DOWNGRADE:
2394 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2395 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2399 /* downgrade next lower non-ACM AC */
2400 for (non_acm_ac = ac + 1;
2401 non_acm_ac < IEEE80211_NUM_ACS;
2403 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2405 /* Usually the loop will result in using BK even if it
2406 * requires admission control, but such a configuration
2407 * makes no sense and we have to transmit somehow - the
2408 * AC selection does the same thing.
2409 * If we started out trying to downgrade from BK, then
2410 * the extra condition here might be needed.
2412 if (non_acm_ac >= IEEE80211_NUM_ACS)
2413 non_acm_ac = IEEE80211_AC_BK;
2414 if (drv_conf_tx(local, &sdata->deflink, ac,
2415 &sdata->deflink.tx_conf[non_acm_ac]))
2416 link_err(&sdata->deflink,
2417 "failed to set TX queue parameters for queue %d\n",
2419 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2421 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2422 tx_tspec->time_slice_start + HZ - now + 1);
2424 case TX_TSPEC_ACTION_NONE:
2433 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2435 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2436 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2440 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2442 struct ieee80211_sub_if_data *sdata;
2444 sdata = container_of(work, struct ieee80211_sub_if_data,
2445 u.mgd.tx_tspec_wk.work);
2446 ieee80211_sta_handle_tspec_ac_params(sdata);
2449 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
2451 struct ieee80211_sub_if_data *sdata = link->sdata;
2452 struct ieee80211_local *local = sdata->local;
2453 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2454 struct ieee80211_tx_queue_params *params = link->tx_conf;
2457 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2459 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2461 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2462 params[ac].txop, params[ac].uapsd,
2463 ifmgd->tx_tspec[ac].downgraded);
2464 if (!ifmgd->tx_tspec[ac].downgraded &&
2465 drv_conf_tx(local, link, ac, ¶ms[ac]))
2467 "failed to set TX queue parameters for AC %d\n",
2474 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2475 struct ieee80211_link_data *link,
2476 const u8 *wmm_param, size_t wmm_param_len,
2477 const struct ieee80211_mu_edca_param_set *mu_edca)
2479 struct ieee80211_sub_if_data *sdata = link->sdata;
2480 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2481 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2483 int count, mu_edca_count, ac;
2485 u8 uapsd_queues = 0;
2487 if (!local->ops->conf_tx)
2490 if (local->hw.queues < IEEE80211_NUM_ACS)
2496 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2499 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2500 uapsd_queues = ifmgd->uapsd_queues;
2502 count = wmm_param[6] & 0x0f;
2503 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2504 * if mu_edca was preset before and now it disappeared tell
2505 * the driver about it.
2507 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2508 if (count == link->u.mgd.wmm_last_param_set &&
2509 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2511 link->u.mgd.wmm_last_param_set = count;
2512 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2514 pos = wmm_param + 8;
2515 left = wmm_param_len - 8;
2517 memset(¶ms, 0, sizeof(params));
2520 for (; left >= 4; left -= 4, pos += 4) {
2521 int aci = (pos[0] >> 5) & 0x03;
2522 int acm = (pos[0] >> 4) & 0x01;
2527 ac = IEEE80211_AC_BK;
2529 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2530 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2532 params[ac].mu_edca = !!mu_edca;
2534 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2537 ac = IEEE80211_AC_VI;
2539 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2540 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2542 params[ac].mu_edca = !!mu_edca;
2544 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2547 ac = IEEE80211_AC_VO;
2549 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2550 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2552 params[ac].mu_edca = !!mu_edca;
2554 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2558 ac = IEEE80211_AC_BE;
2560 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2561 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2563 params[ac].mu_edca = !!mu_edca;
2565 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2569 params[ac].aifs = pos[0] & 0x0f;
2571 if (params[ac].aifs < 2) {
2573 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2574 params[ac].aifs, aci);
2575 params[ac].aifs = 2;
2577 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2578 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2579 params[ac].txop = get_unaligned_le16(pos + 2);
2580 params[ac].acm = acm;
2581 params[ac].uapsd = uapsd;
2583 if (params[ac].cw_min == 0 ||
2584 params[ac].cw_min > params[ac].cw_max) {
2586 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2587 params[ac].cw_min, params[ac].cw_max, aci);
2590 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2593 /* WMM specification requires all 4 ACIs. */
2594 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2595 if (params[ac].cw_min == 0) {
2597 "AP has invalid WMM params (missing AC %d), using defaults\n",
2603 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2604 link->tx_conf[ac] = params[ac];
2606 ieee80211_mgd_set_link_qos_params(link);
2608 /* enable WMM or activate new settings */
2609 link->conf->qos = true;
2613 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2615 lockdep_assert_held(&sdata->local->mtx);
2617 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2618 ieee80211_run_deferred_scan(sdata->local);
2621 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2623 mutex_lock(&sdata->local->mtx);
2624 __ieee80211_stop_poll(sdata);
2625 mutex_unlock(&sdata->local->mtx);
2628 static u32 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2629 u16 capab, bool erp_valid, u8 erp)
2631 struct ieee80211_bss_conf *bss_conf = link->conf;
2632 struct ieee80211_supported_band *sband;
2634 bool use_protection;
2635 bool use_short_preamble;
2636 bool use_short_slot;
2638 sband = ieee80211_get_link_sband(link);
2643 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2644 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2646 use_protection = false;
2647 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2650 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2651 if (sband->band == NL80211_BAND_5GHZ ||
2652 sband->band == NL80211_BAND_6GHZ)
2653 use_short_slot = true;
2655 if (use_protection != bss_conf->use_cts_prot) {
2656 bss_conf->use_cts_prot = use_protection;
2657 changed |= BSS_CHANGED_ERP_CTS_PROT;
2660 if (use_short_preamble != bss_conf->use_short_preamble) {
2661 bss_conf->use_short_preamble = use_short_preamble;
2662 changed |= BSS_CHANGED_ERP_PREAMBLE;
2665 if (use_short_slot != bss_conf->use_short_slot) {
2666 bss_conf->use_short_slot = use_short_slot;
2667 changed |= BSS_CHANGED_ERP_SLOT;
2673 static u32 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2674 struct cfg80211_bss *cbss)
2676 struct ieee80211_sub_if_data *sdata = link->sdata;
2677 struct ieee80211_bss_conf *bss_conf = link->conf;
2678 struct ieee80211_bss *bss = (void *)cbss->priv;
2679 u32 changed = BSS_CHANGED_QOS;
2681 /* not really used in MLO */
2682 sdata->u.mgd.beacon_timeout =
2683 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2684 bss_conf->beacon_int));
2686 changed |= ieee80211_handle_bss_capability(link,
2687 bss_conf->assoc_capability,
2691 ieee80211_check_rate_mask(link);
2693 link->u.mgd.bss = cbss;
2694 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2696 if (sdata->vif.p2p ||
2697 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2698 const struct cfg80211_bss_ies *ies;
2701 ies = rcu_dereference(cbss->ies);
2705 ret = cfg80211_get_p2p_attr(
2706 ies->data, ies->len,
2707 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2708 (u8 *) &bss_conf->p2p_noa_attr,
2709 sizeof(bss_conf->p2p_noa_attr));
2711 link->u.mgd.p2p_noa_index =
2712 bss_conf->p2p_noa_attr.index;
2713 changed |= BSS_CHANGED_P2P_PS;
2719 if (link->u.mgd.have_beacon) {
2720 bss_conf->beacon_rate = bss->beacon_rate;
2721 changed |= BSS_CHANGED_BEACON_INFO;
2723 bss_conf->beacon_rate = NULL;
2726 /* Tell the driver to monitor connection quality (if supported) */
2727 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2728 bss_conf->cqm_rssi_thold)
2729 changed |= BSS_CHANGED_CQM;
2734 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2735 struct ieee80211_mgd_assoc_data *assoc_data,
2736 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2738 struct ieee80211_local *local = sdata->local;
2739 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2740 u64 vif_changed = BSS_CHANGED_ASSOC;
2741 unsigned int link_id;
2743 sdata->u.mgd.associated = true;
2745 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2746 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2747 struct ieee80211_link_data *link;
2750 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2753 link = sdata_dereference(sdata->link[link_id], sdata);
2757 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2760 /* just to be sure */
2761 ieee80211_stop_poll(sdata);
2763 ieee80211_led_assoc(local, 1);
2767 /* Enable ARP filtering */
2768 if (vif_cfg->arp_addr_cnt)
2769 vif_changed |= BSS_CHANGED_ARP_FILTER;
2771 if (sdata->vif.valid_links) {
2773 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2775 struct ieee80211_link_data *link;
2776 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2779 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2782 link = sdata_dereference(sdata->link[link_id], sdata);
2786 ieee80211_link_info_change_notify(sdata, link,
2789 ieee80211_recalc_smps(sdata, link);
2792 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2794 ieee80211_bss_info_change_notify(sdata,
2795 vif_changed | changed[0]);
2798 mutex_lock(&local->iflist_mtx);
2799 ieee80211_recalc_ps(local);
2800 mutex_unlock(&local->iflist_mtx);
2802 /* leave this here to not change ordering in non-MLO cases */
2803 if (!sdata->vif.valid_links)
2804 ieee80211_recalc_smps(sdata, &sdata->deflink);
2805 ieee80211_recalc_ps_vif(sdata);
2807 netif_carrier_on(sdata->dev);
2810 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2811 u16 stype, u16 reason, bool tx,
2814 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2815 struct ieee80211_local *local = sdata->local;
2816 unsigned int link_id;
2818 struct ieee80211_prep_tx_info info = {
2822 sdata_assert_lock(sdata);
2824 if (WARN_ON_ONCE(tx && !frame_buf))
2827 if (WARN_ON(!ifmgd->associated))
2830 ieee80211_stop_poll(sdata);
2832 ifmgd->associated = false;
2834 /* other links will be destroyed */
2835 sdata->deflink.u.mgd.bss = NULL;
2837 netif_carrier_off(sdata->dev);
2840 * if we want to get out of ps before disassoc (why?) we have
2841 * to do it before sending disassoc, as otherwise the null-packet
2844 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2845 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2846 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2848 local->ps_sdata = NULL;
2850 /* disable per-vif ps */
2851 ieee80211_recalc_ps_vif(sdata);
2853 /* make sure ongoing transmission finishes */
2857 * drop any frame before deauth/disassoc, this can be data or
2858 * management frame. Since we are disconnecting, we should not
2859 * insist sending these frames which can take time and delay
2860 * the disconnection and possible the roaming.
2863 ieee80211_flush_queues(local, sdata, true);
2865 /* deauthenticate/disassociate now */
2866 if (tx || frame_buf) {
2868 * In multi channel scenarios guarantee that the virtual
2869 * interface is granted immediate airtime to transmit the
2870 * deauthentication frame by calling mgd_prepare_tx, if the
2871 * driver requested so.
2873 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2874 !sdata->deflink.u.mgd.have_beacon) {
2875 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2878 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2879 sdata->vif.cfg.ap_addr, stype,
2880 reason, tx, frame_buf);
2883 /* flush out frame - make sure the deauth was actually sent */
2885 ieee80211_flush_queues(local, sdata, false);
2887 drv_mgd_complete_tx(sdata->local, sdata, &info);
2889 /* clear AP addr only after building the needed mgmt frames */
2890 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2891 eth_zero_addr(sdata->vif.cfg.ap_addr);
2893 sdata->vif.cfg.ssid_len = 0;
2895 /* remove AP and TDLS peers */
2896 sta_info_flush(sdata);
2898 /* finally reset all BSS / config parameters */
2899 if (!sdata->vif.valid_links)
2900 changed |= ieee80211_reset_erp_info(sdata);
2902 ieee80211_led_assoc(local, 0);
2903 changed |= BSS_CHANGED_ASSOC;
2904 sdata->vif.cfg.assoc = false;
2906 sdata->deflink.u.mgd.p2p_noa_index = -1;
2907 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2908 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2910 /* on the next assoc, re-program HT/VHT parameters */
2911 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2912 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2913 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2914 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2917 * reset MU-MIMO ownership and group data in default link,
2918 * if used, other links are destroyed
2920 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2921 sizeof(sdata->vif.bss_conf.mu_group.membership));
2922 memset(sdata->vif.bss_conf.mu_group.position, 0,
2923 sizeof(sdata->vif.bss_conf.mu_group.position));
2924 if (!sdata->vif.valid_links)
2925 changed |= BSS_CHANGED_MU_GROUPS;
2926 sdata->vif.bss_conf.mu_mimo_owner = false;
2928 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
2930 del_timer_sync(&local->dynamic_ps_timer);
2931 cancel_work_sync(&local->dynamic_ps_enable_work);
2933 /* Disable ARP filtering */
2934 if (sdata->vif.cfg.arp_addr_cnt)
2935 changed |= BSS_CHANGED_ARP_FILTER;
2937 sdata->vif.bss_conf.qos = false;
2938 if (!sdata->vif.valid_links) {
2939 changed |= BSS_CHANGED_QOS;
2940 /* The BSSID (not really interesting) and HT changed */
2941 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
2942 ieee80211_bss_info_change_notify(sdata, changed);
2944 ieee80211_vif_cfg_change_notify(sdata, changed);
2947 /* disassociated - set to defaults now */
2948 ieee80211_set_wmm_default(&sdata->deflink, false, false);
2950 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
2951 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
2952 del_timer_sync(&sdata->u.mgd.timer);
2953 del_timer_sync(&sdata->deflink.u.mgd.chswitch_timer);
2955 sdata->vif.bss_conf.dtim_period = 0;
2956 sdata->vif.bss_conf.beacon_rate = NULL;
2958 sdata->deflink.u.mgd.have_beacon = false;
2959 sdata->deflink.u.mgd.tracking_signal_avg = false;
2960 sdata->deflink.u.mgd.disable_wmm_tracking = false;
2963 sdata->deflink.u.mgd.conn_flags = 0;
2964 mutex_lock(&local->mtx);
2966 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
2967 struct ieee80211_link_data *link;
2969 link = sdata_dereference(sdata->link[link_id], sdata);
2972 ieee80211_link_release_channel(link);
2975 sdata->vif.bss_conf.csa_active = false;
2976 sdata->deflink.u.mgd.csa_waiting_bcn = false;
2977 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
2978 if (sdata->deflink.csa_block_tx) {
2979 ieee80211_wake_vif_queues(local, sdata,
2980 IEEE80211_QUEUE_STOP_REASON_CSA);
2981 sdata->deflink.csa_block_tx = false;
2983 mutex_unlock(&local->mtx);
2985 /* existing TX TSPEC sessions no longer exist */
2986 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
2987 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
2989 sdata->vif.bss_conf.pwr_reduction = 0;
2990 sdata->vif.bss_conf.tx_pwr_env_num = 0;
2991 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
2992 sizeof(sdata->vif.bss_conf.tx_pwr_env));
2994 ieee80211_vif_set_links(sdata, 0);
2997 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
2999 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3000 struct ieee80211_local *local = sdata->local;
3002 mutex_lock(&local->mtx);
3003 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3006 __ieee80211_stop_poll(sdata);
3008 mutex_lock(&local->iflist_mtx);
3009 ieee80211_recalc_ps(local);
3010 mutex_unlock(&local->iflist_mtx);
3012 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3016 * We've received a probe response, but are not sure whether
3017 * we have or will be receiving any beacons or data, so let's
3018 * schedule the timers again, just in case.
3020 ieee80211_sta_reset_beacon_monitor(sdata);
3022 mod_timer(&ifmgd->conn_mon_timer,
3023 round_jiffies_up(jiffies +
3024 IEEE80211_CONNECTION_IDLE_TIME));
3026 mutex_unlock(&local->mtx);
3029 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3030 struct ieee80211_hdr *hdr,
3033 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3036 struct ieee80211_sta_tx_tspec *tx_tspec;
3037 unsigned long now = jiffies;
3039 if (!ieee80211_is_data_qos(hdr->frame_control))
3042 tid = ieee80211_get_tid(hdr);
3043 ac = ieee80211_ac_from_tid(tid);
3044 tx_tspec = &ifmgd->tx_tspec[ac];
3046 if (likely(!tx_tspec->admitted_time))
3049 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3050 tx_tspec->consumed_tx_time = 0;
3051 tx_tspec->time_slice_start = now;
3053 if (tx_tspec->downgraded) {
3054 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3055 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3059 if (tx_tspec->downgraded)
3062 tx_tspec->consumed_tx_time += tx_time;
3064 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3065 tx_tspec->downgraded = true;
3066 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3067 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3071 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3072 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3074 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3076 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3077 !sdata->u.mgd.probe_send_count)
3081 sdata->u.mgd.probe_send_count = 0;
3083 sdata->u.mgd.nullfunc_failed = true;
3084 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3087 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3088 const u8 *src, const u8 *dst,
3089 const u8 *ssid, size_t ssid_len,
3090 struct ieee80211_channel *channel)
3092 struct sk_buff *skb;
3094 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3095 ssid, ssid_len, NULL, 0,
3096 IEEE80211_PROBE_FLAG_DIRECTED);
3098 ieee80211_tx_skb(sdata, skb);
3101 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3103 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3104 u8 *dst = sdata->vif.cfg.ap_addr;
3105 u8 unicast_limit = max(1, max_probe_tries - 3);
3106 struct sta_info *sta;
3108 if (WARN_ON(sdata->vif.valid_links))
3112 * Try sending broadcast probe requests for the last three
3113 * probe requests after the first ones failed since some
3114 * buggy APs only support broadcast probe requests.
3116 if (ifmgd->probe_send_count >= unicast_limit)
3120 * When the hardware reports an accurate Tx ACK status, it's
3121 * better to send a nullfunc frame instead of a probe request,
3122 * as it will kick us off the AP quickly if we aren't associated
3123 * anymore. The timeout will be reset if the frame is ACKed by
3126 ifmgd->probe_send_count++;
3129 mutex_lock(&sdata->local->sta_mtx);
3130 sta = sta_info_get(sdata, dst);
3132 ieee80211_check_fast_rx(sta);
3133 mutex_unlock(&sdata->local->sta_mtx);
3136 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3137 ifmgd->nullfunc_failed = false;
3138 ieee80211_send_nullfunc(sdata->local, sdata, false);
3140 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3141 sdata->vif.cfg.ssid,
3142 sdata->vif.cfg.ssid_len,
3143 sdata->deflink.u.mgd.bss->channel);
3146 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3147 run_again(sdata, ifmgd->probe_timeout);
3150 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3153 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3154 bool already = false;
3156 if (WARN_ON(sdata->vif.valid_links))
3159 if (!ieee80211_sdata_running(sdata))
3164 if (!ifmgd->associated)
3167 mutex_lock(&sdata->local->mtx);
3169 if (sdata->local->tmp_channel || sdata->local->scanning) {
3170 mutex_unlock(&sdata->local->mtx);
3174 if (sdata->local->suspending) {
3175 /* reschedule after resume */
3176 mutex_unlock(&sdata->local->mtx);
3177 ieee80211_reset_ap_probe(sdata);
3182 mlme_dbg_ratelimited(sdata,
3183 "detected beacon loss from AP (missed %d beacons) - probing\n",
3186 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3190 * The driver/our work has already reported this event or the
3191 * connection monitoring has kicked in and we have already sent
3192 * a probe request. Or maybe the AP died and the driver keeps
3193 * reporting until we disassociate...
3195 * In either case we have to ignore the current call to this
3196 * function (except for setting the correct probe reason bit)
3197 * because otherwise we would reset the timer every time and
3198 * never check whether we received a probe response!
3200 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3203 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3205 mutex_unlock(&sdata->local->mtx);
3210 mutex_lock(&sdata->local->iflist_mtx);
3211 ieee80211_recalc_ps(sdata->local);
3212 mutex_unlock(&sdata->local->iflist_mtx);
3214 ifmgd->probe_send_count = 0;
3215 ieee80211_mgd_probe_ap_send(sdata);
3217 sdata_unlock(sdata);
3220 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3221 struct ieee80211_vif *vif)
3223 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3224 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3225 struct cfg80211_bss *cbss;
3226 struct sk_buff *skb;
3227 const struct element *ssid;
3230 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3231 sdata->vif.valid_links))
3234 sdata_assert_lock(sdata);
3236 if (ifmgd->associated)
3237 cbss = sdata->deflink.u.mgd.bss;
3238 else if (ifmgd->auth_data)
3239 cbss = ifmgd->auth_data->bss;
3240 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3241 cbss = ifmgd->assoc_data->link[0].bss;
3246 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3247 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3248 "invalid SSID element (len=%d)",
3249 ssid ? ssid->datalen : -1))
3252 ssid_len = ssid->datalen;
3254 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3255 (u32) -1, cbss->channel,
3256 ssid->data, ssid_len,
3257 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3262 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3264 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3265 const u8 *buf, size_t len, bool tx,
3266 u16 reason, bool reconnect)
3268 struct ieee80211_event event = {
3270 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3271 .u.mlme.reason = reason,
3275 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3277 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3279 drv_event_callback(sdata->local, sdata, &event);
3282 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3284 struct ieee80211_local *local = sdata->local;
3285 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3286 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3290 if (!ifmgd->associated) {
3291 sdata_unlock(sdata);
3295 /* in MLO assume we have a link where we can TX the frame */
3296 tx = sdata->vif.valid_links || !sdata->deflink.csa_block_tx;
3298 if (!ifmgd->driver_disconnect) {
3299 unsigned int link_id;
3302 * AP is probably out of range (or not reachable for another
3303 * reason) so remove the bss structs for that AP. In the case
3304 * of multi-link, it's not clear that all of them really are
3305 * out of range, but if they weren't the driver likely would
3306 * have switched to just have a single link active?
3309 link_id < ARRAY_SIZE(sdata->link);
3311 struct ieee80211_link_data *link;
3313 link = sdata_dereference(sdata->link[link_id], sdata);
3316 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3317 link->u.mgd.bss = NULL;
3321 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3322 ifmgd->driver_disconnect ?
3323 WLAN_REASON_DEAUTH_LEAVING :
3324 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3326 mutex_lock(&local->mtx);
3327 /* the other links will be destroyed */
3328 sdata->vif.bss_conf.csa_active = false;
3329 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3330 if (sdata->deflink.csa_block_tx) {
3331 ieee80211_wake_vif_queues(local, sdata,
3332 IEEE80211_QUEUE_STOP_REASON_CSA);
3333 sdata->deflink.csa_block_tx = false;
3335 mutex_unlock(&local->mtx);
3337 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3338 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3340 ifmgd->reconnect = false;
3342 sdata_unlock(sdata);
3345 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
3347 struct ieee80211_sub_if_data *sdata =
3348 container_of(work, struct ieee80211_sub_if_data,
3349 u.mgd.beacon_connection_loss_work);
3350 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3352 if (ifmgd->connection_loss) {
3353 sdata_info(sdata, "Connection to AP %pM lost\n",
3354 sdata->vif.cfg.ap_addr);
3355 __ieee80211_disconnect(sdata);
3356 ifmgd->connection_loss = false;
3357 } else if (ifmgd->driver_disconnect) {
3359 "Driver requested disconnection from AP %pM\n",
3360 sdata->vif.cfg.ap_addr);
3361 __ieee80211_disconnect(sdata);
3362 ifmgd->driver_disconnect = false;
3364 if (ifmgd->associated)
3365 sdata->deflink.u.mgd.beacon_loss_count++;
3366 ieee80211_mgd_probe_ap(sdata, true);
3370 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
3372 struct ieee80211_sub_if_data *sdata =
3373 container_of(work, struct ieee80211_sub_if_data,
3374 u.mgd.csa_connection_drop_work);
3376 __ieee80211_disconnect(sdata);
3379 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3381 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3382 struct ieee80211_hw *hw = &sdata->local->hw;
3384 trace_api_beacon_loss(sdata);
3386 sdata->u.mgd.connection_loss = false;
3387 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3389 EXPORT_SYMBOL(ieee80211_beacon_loss);
3391 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3393 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3394 struct ieee80211_hw *hw = &sdata->local->hw;
3396 trace_api_connection_loss(sdata);
3398 sdata->u.mgd.connection_loss = true;
3399 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3401 EXPORT_SYMBOL(ieee80211_connection_loss);
3403 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3405 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3406 struct ieee80211_hw *hw = &sdata->local->hw;
3408 trace_api_disconnect(sdata, reconnect);
3410 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3413 sdata->u.mgd.driver_disconnect = true;
3414 sdata->u.mgd.reconnect = reconnect;
3415 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3417 EXPORT_SYMBOL(ieee80211_disconnect);
3419 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3422 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3424 sdata_assert_lock(sdata);
3428 * we are not authenticated yet, the only timer that could be
3429 * running is the timeout for the authentication response which
3430 * which is not relevant anymore.
3432 del_timer_sync(&sdata->u.mgd.timer);
3433 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3435 /* other links are destroyed */
3436 sdata->deflink.u.mgd.conn_flags = 0;
3437 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3438 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3440 sdata->u.mgd.flags = 0;
3442 mutex_lock(&sdata->local->mtx);
3443 ieee80211_link_release_channel(&sdata->deflink);
3444 ieee80211_vif_set_links(sdata, 0);
3445 mutex_unlock(&sdata->local->mtx);
3448 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3450 sdata->u.mgd.auth_data = NULL;
3460 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3461 enum assoc_status status)
3463 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3465 sdata_assert_lock(sdata);
3467 if (status != ASSOC_SUCCESS) {
3469 * we are not associated yet, the only timer that could be
3470 * running is the timeout for the association response which
3471 * which is not relevant anymore.
3473 del_timer_sync(&sdata->u.mgd.timer);
3474 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3476 sdata->deflink.u.mgd.conn_flags = 0;
3477 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3478 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3480 sdata->u.mgd.flags = 0;
3481 sdata->vif.bss_conf.mu_mimo_owner = false;
3483 if (status != ASSOC_REJECTED) {
3484 struct cfg80211_assoc_failure data = {
3485 .timeout = status == ASSOC_TIMEOUT,
3489 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3490 ARRAY_SIZE(assoc_data->link));
3492 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3493 data.bss[i] = assoc_data->link[i].bss;
3495 if (sdata->vif.valid_links)
3496 data.ap_mld_addr = assoc_data->ap_addr;
3498 cfg80211_assoc_failure(sdata->dev, &data);
3501 mutex_lock(&sdata->local->mtx);
3502 ieee80211_link_release_channel(&sdata->deflink);
3503 ieee80211_vif_set_links(sdata, 0);
3504 mutex_unlock(&sdata->local->mtx);
3508 sdata->u.mgd.assoc_data = NULL;
3511 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3512 struct ieee80211_mgmt *mgmt, size_t len)
3514 struct ieee80211_local *local = sdata->local;
3515 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3516 const struct element *challenge;
3519 struct ieee80211_prep_tx_info info = {
3520 .subtype = IEEE80211_STYPE_AUTH,
3523 pos = mgmt->u.auth.variable;
3524 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3525 len - (pos - (u8 *)mgmt));
3528 auth_data->expected_transaction = 4;
3529 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3530 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3531 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3532 IEEE80211_TX_INTFL_MLME_CONN_TX;
3533 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3535 challenge->datalen + sizeof(*challenge),
3536 auth_data->ap_addr, auth_data->ap_addr,
3537 auth_data->key, auth_data->key_len,
3538 auth_data->key_idx, tx_flags);
3541 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3543 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3544 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3545 struct sta_info *sta;
3548 sdata_info(sdata, "authenticated\n");
3549 ifmgd->auth_data->done = true;
3550 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3551 ifmgd->auth_data->timeout_started = true;
3552 run_again(sdata, ifmgd->auth_data->timeout);
3554 /* move station state to auth */
3555 mutex_lock(&sdata->local->sta_mtx);
3556 sta = sta_info_get(sdata, ap_addr);
3558 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3562 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3563 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3569 mutex_unlock(&sdata->local->sta_mtx);
3573 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3574 struct ieee80211_mgmt *mgmt, size_t len)
3576 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3577 u16 auth_alg, auth_transaction, status_code;
3578 struct ieee80211_event event = {
3580 .u.mlme.data = AUTH_EVENT,
3582 struct ieee80211_prep_tx_info info = {
3583 .subtype = IEEE80211_STYPE_AUTH,
3586 sdata_assert_lock(sdata);
3591 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3594 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3597 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3598 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3599 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3601 if (auth_alg != ifmgd->auth_data->algorithm ||
3602 (auth_alg != WLAN_AUTH_SAE &&
3603 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3604 (auth_alg == WLAN_AUTH_SAE &&
3605 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3606 auth_transaction > 2))) {
3607 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3608 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3610 ifmgd->auth_data->expected_transaction);
3614 if (status_code != WLAN_STATUS_SUCCESS) {
3615 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3617 if (auth_alg == WLAN_AUTH_SAE &&
3618 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3619 (auth_transaction == 1 &&
3620 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3621 status_code == WLAN_STATUS_SAE_PK)))) {
3622 /* waiting for userspace now */
3623 ifmgd->auth_data->waiting = true;
3624 ifmgd->auth_data->timeout =
3625 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3626 ifmgd->auth_data->timeout_started = true;
3627 run_again(sdata, ifmgd->auth_data->timeout);
3631 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3632 mgmt->sa, status_code);
3633 ieee80211_destroy_auth_data(sdata, false);
3634 event.u.mlme.status = MLME_DENIED;
3635 event.u.mlme.reason = status_code;
3636 drv_event_callback(sdata->local, sdata, &event);
3640 switch (ifmgd->auth_data->algorithm) {
3641 case WLAN_AUTH_OPEN:
3642 case WLAN_AUTH_LEAP:
3645 case WLAN_AUTH_FILS_SK:
3646 case WLAN_AUTH_FILS_SK_PFS:
3647 case WLAN_AUTH_FILS_PK:
3649 case WLAN_AUTH_SHARED_KEY:
3650 if (ifmgd->auth_data->expected_transaction != 4) {
3651 ieee80211_auth_challenge(sdata, mgmt, len);
3652 /* need another frame */
3657 WARN_ONCE(1, "invalid auth alg %d",
3658 ifmgd->auth_data->algorithm);
3662 event.u.mlme.status = MLME_SUCCESS;
3664 drv_event_callback(sdata->local, sdata, &event);
3665 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3666 (auth_transaction == 2 &&
3667 ifmgd->auth_data->expected_transaction == 2)) {
3668 if (!ieee80211_mark_sta_auth(sdata))
3669 return; /* ignore frame -- wait for timeout */
3670 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3671 auth_transaction == 2) {
3672 sdata_info(sdata, "SAE peer confirmed\n");
3673 ifmgd->auth_data->peer_confirmed = true;
3676 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3678 drv_mgd_complete_tx(sdata->local, sdata, &info);
3681 #define case_WLAN(type) \
3682 case WLAN_REASON_##type: return #type
3684 const char *ieee80211_get_reason_code_string(u16 reason_code)
3686 switch (reason_code) {
3687 case_WLAN(UNSPECIFIED);
3688 case_WLAN(PREV_AUTH_NOT_VALID);
3689 case_WLAN(DEAUTH_LEAVING);
3690 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3691 case_WLAN(DISASSOC_AP_BUSY);
3692 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3693 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3694 case_WLAN(DISASSOC_STA_HAS_LEFT);
3695 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3696 case_WLAN(DISASSOC_BAD_POWER);
3697 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3698 case_WLAN(INVALID_IE);
3699 case_WLAN(MIC_FAILURE);
3700 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3701 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3702 case_WLAN(IE_DIFFERENT);
3703 case_WLAN(INVALID_GROUP_CIPHER);
3704 case_WLAN(INVALID_PAIRWISE_CIPHER);
3705 case_WLAN(INVALID_AKMP);
3706 case_WLAN(UNSUPP_RSN_VERSION);
3707 case_WLAN(INVALID_RSN_IE_CAP);
3708 case_WLAN(IEEE8021X_FAILED);
3709 case_WLAN(CIPHER_SUITE_REJECTED);
3710 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3711 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3712 case_WLAN(DISASSOC_LOW_ACK);
3713 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3714 case_WLAN(QSTA_LEAVE_QBSS);
3715 case_WLAN(QSTA_NOT_USE);
3716 case_WLAN(QSTA_REQUIRE_SETUP);
3717 case_WLAN(QSTA_TIMEOUT);
3718 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3719 case_WLAN(MESH_PEER_CANCELED);
3720 case_WLAN(MESH_MAX_PEERS);
3721 case_WLAN(MESH_CONFIG);
3722 case_WLAN(MESH_CLOSE);
3723 case_WLAN(MESH_MAX_RETRIES);
3724 case_WLAN(MESH_CONFIRM_TIMEOUT);
3725 case_WLAN(MESH_INVALID_GTK);
3726 case_WLAN(MESH_INCONSISTENT_PARAM);
3727 case_WLAN(MESH_INVALID_SECURITY);
3728 case_WLAN(MESH_PATH_ERROR);
3729 case_WLAN(MESH_PATH_NOFORWARD);
3730 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3731 case_WLAN(MAC_EXISTS_IN_MBSS);
3732 case_WLAN(MESH_CHAN_REGULATORY);
3733 case_WLAN(MESH_CHAN);
3734 default: return "<unknown>";
3738 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3739 struct ieee80211_mgmt *mgmt, size_t len)
3741 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3742 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3744 sdata_assert_lock(sdata);
3749 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3750 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3754 if (ifmgd->associated &&
3755 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3756 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3757 sdata->vif.cfg.ap_addr, reason_code,
3758 ieee80211_get_reason_code_string(reason_code));
3760 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3762 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3763 reason_code, false);
3767 if (ifmgd->assoc_data &&
3768 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3770 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3771 ifmgd->assoc_data->ap_addr, reason_code,
3772 ieee80211_get_reason_code_string(reason_code));
3774 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3776 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3782 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3783 struct ieee80211_mgmt *mgmt, size_t len)
3785 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3788 sdata_assert_lock(sdata);
3793 if (!ifmgd->associated ||
3794 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3797 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3799 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3800 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3804 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3805 sdata->vif.cfg.ap_addr, reason_code,
3806 ieee80211_get_reason_code_string(reason_code));
3808 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3810 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3814 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3815 u8 *supp_rates, unsigned int supp_rates_len,
3816 u32 *rates, u32 *basic_rates,
3817 bool *have_higher_than_11mbit,
3818 int *min_rate, int *min_rate_index,
3823 for (i = 0; i < supp_rates_len; i++) {
3824 int rate = supp_rates[i] & 0x7f;
3825 bool is_basic = !!(supp_rates[i] & 0x80);
3827 if ((rate * 5 * (1 << shift)) > 110)
3828 *have_higher_than_11mbit = true;
3831 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3832 * since they're not rates.
3834 * Note: Even though the membership selector and the basic
3835 * rate flag share the same bit, they are not exactly
3838 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3839 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3840 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3841 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3844 for (j = 0; j < sband->n_bitrates; j++) {
3845 struct ieee80211_rate *br;
3848 br = &sband->bitrates[j];
3850 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3851 if (brate == rate) {
3854 *basic_rates |= BIT(j);
3855 if ((rate * 5) < *min_rate) {
3856 *min_rate = rate * 5;
3857 *min_rate_index = j;
3865 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3866 struct ieee80211_supported_band *sband,
3867 const struct link_sta_info *link_sta,
3868 const struct ieee802_11_elems *elems)
3870 const struct ieee80211_sta_he_cap *own_he_cap =
3871 ieee80211_get_he_iftype_cap(sband,
3872 ieee80211_vif_type_p2p(&sdata->vif));
3874 if (elems->ext_capab_len < 10)
3877 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3880 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3881 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3883 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3884 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3887 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3888 struct ieee80211_supported_band *sband,
3889 struct ieee80211_link_data *link,
3890 struct link_sta_info *link_sta,
3891 struct ieee802_11_elems *elems)
3893 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3895 if (link->conf->twt_requester != twt) {
3896 link->conf->twt_requester = twt;
3897 return BSS_CHANGED_TWT;
3902 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3903 struct ieee80211_bss_conf *bss_conf,
3904 struct ieee80211_supported_band *sband,
3905 struct link_sta_info *link_sta)
3907 const struct ieee80211_sta_he_cap *own_he_cap =
3908 ieee80211_get_he_iftype_cap(sband,
3909 ieee80211_vif_type_p2p(&sdata->vif));
3911 return bss_conf->he_support &&
3912 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3913 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3915 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3916 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3919 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3920 struct link_sta_info *link_sta,
3921 struct cfg80211_bss *cbss,
3922 struct ieee80211_mgmt *mgmt,
3923 const u8 *elem_start,
3924 unsigned int elem_len,
3927 struct ieee80211_sub_if_data *sdata = link->sdata;
3928 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3929 struct ieee80211_bss_conf *bss_conf = link->conf;
3930 struct ieee80211_local *local = sdata->local;
3931 unsigned int link_id = link->link_id;
3932 struct ieee80211_elems_parse_params parse_params = {
3933 .start = elem_start,
3935 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
3938 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
3939 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
3940 const struct cfg80211_bss_ies *bss_ies = NULL;
3941 struct ieee80211_supported_band *sband;
3942 struct ieee802_11_elems *elems;
3946 elems = ieee802_11_parse_elems_full(&parse_params);
3950 if (link_id == assoc_data->assoc_link_id) {
3951 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
3954 * we should not get to this flow unless the association was
3955 * successful, so set the status directly to success
3957 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
3958 } else if (!elems->prof) {
3962 const u8 *ptr = elems->prof->variable +
3963 elems->prof->sta_info_len - 1;
3966 * During parsing, we validated that these fields exist,
3967 * otherwise elems->prof would have been set to NULL.
3969 capab_info = get_unaligned_le16(ptr);
3970 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
3972 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
3973 link_info(link, "association response status code=%u\n",
3974 assoc_data->link[link_id].status);
3980 if (!is_s1g && !elems->supp_rates) {
3981 sdata_info(sdata, "no SuppRates element in AssocResp\n");
3986 link->u.mgd.tdls_chan_switch_prohibited =
3987 elems->ext_capab && elems->ext_capab_len >= 5 &&
3988 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
3991 * Some APs are erroneously not including some information in their
3992 * (re)association response frames. Try to recover by using the data
3993 * from the beacon or probe response. This seems to afflict mobile
3994 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
3995 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
3998 ((assoc_data->wmm && !elems->wmm_param) ||
3999 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4000 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4001 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4002 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4003 const struct cfg80211_bss_ies *ies;
4004 struct ieee802_11_elems *bss_elems;
4007 ies = rcu_dereference(cbss->ies);
4009 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4017 parse_params.start = bss_ies->data;
4018 parse_params.len = bss_ies->len;
4019 parse_params.bss = cbss;
4020 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4026 if (assoc_data->wmm &&
4027 !elems->wmm_param && bss_elems->wmm_param) {
4028 elems->wmm_param = bss_elems->wmm_param;
4030 "AP bug: WMM param missing from AssocResp\n");
4034 * Also check if we requested HT/VHT, otherwise the AP doesn't
4035 * have to include the IEs in the (re)association response.
4037 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4038 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4039 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4041 "AP bug: HT capability missing from AssocResp\n");
4043 if (!elems->ht_operation && bss_elems->ht_operation &&
4044 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4045 elems->ht_operation = bss_elems->ht_operation;
4047 "AP bug: HT operation missing from AssocResp\n");
4049 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4050 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4051 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4053 "AP bug: VHT capa missing from AssocResp\n");
4055 if (!elems->vht_operation && bss_elems->vht_operation &&
4056 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4057 elems->vht_operation = bss_elems->vht_operation;
4059 "AP bug: VHT operation missing from AssocResp\n");
4066 * We previously checked these in the beacon/probe response, so
4067 * they should be present here. This is just a safety net.
4069 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4070 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4072 "HT AP is missing WMM params or HT capability/operation\n");
4077 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4078 (!elems->vht_cap_elem || !elems->vht_operation)) {
4080 "VHT AP is missing VHT capability/operation\n");
4085 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4086 !elems->he_6ghz_capa) {
4088 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4093 if (WARN_ON(!link->conf->chandef.chan)) {
4097 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4099 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4100 (!elems->he_cap || !elems->he_operation)) {
4102 "HE AP is missing HE capability/operation\n");
4107 /* Set up internal HT/VHT capabilities */
4108 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4109 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4113 if (elems->vht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
4114 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4115 elems->vht_cap_elem,
4118 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4120 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4123 elems->he_6ghz_capa,
4126 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4127 if (elems->rsnx && elems->rsnx_len &&
4128 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4129 wiphy_ext_feature_isset(local->hw.wiphy,
4130 NL80211_EXT_FEATURE_PROTECTED_TWT))
4131 bss_conf->twt_protected = true;
4133 bss_conf->twt_protected = false;
4135 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4138 if (elems->eht_operation && elems->eht_cap &&
4139 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4140 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4147 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4149 bss_conf->eht_support = false;
4152 bss_conf->he_support = false;
4153 bss_conf->twt_requester = false;
4154 bss_conf->twt_protected = false;
4155 bss_conf->eht_support = false;
4158 bss_conf->twt_broadcast =
4159 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4161 if (bss_conf->he_support) {
4162 bss_conf->he_bss_color.color =
4163 le32_get_bits(elems->he_operation->he_oper_params,
4164 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4165 bss_conf->he_bss_color.partial =
4166 le32_get_bits(elems->he_operation->he_oper_params,
4167 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4168 bss_conf->he_bss_color.enabled =
4169 !le32_get_bits(elems->he_operation->he_oper_params,
4170 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4172 if (bss_conf->he_bss_color.enabled)
4173 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4175 bss_conf->htc_trig_based_pkt_ext =
4176 le32_get_bits(elems->he_operation->he_oper_params,
4177 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4178 bss_conf->frame_time_rts_th =
4179 le32_get_bits(elems->he_operation->he_oper_params,
4180 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4182 bss_conf->uora_exists = !!elems->uora_element;
4183 if (elems->uora_element)
4184 bss_conf->uora_ocw_range = elems->uora_element[0];
4186 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4187 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4188 /* TODO: OPEN: what happens if BSS color disable is set? */
4191 if (cbss->transmitted_bss) {
4192 bss_conf->nontransmitted = true;
4193 ether_addr_copy(bss_conf->transmitter_bssid,
4194 cbss->transmitted_bss->bssid);
4195 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4196 bss_conf->bssid_index = cbss->bssid_index;
4200 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4201 * in their association response, so ignore that data for our own
4202 * configuration. If it changed since the last beacon, we'll get the
4203 * next beacon and update then.
4207 * If an operating mode notification IE is present, override the
4208 * NSS calculation (that would be done in rate_control_rate_init())
4209 * and use the # of streams from that element.
4211 if (elems->opmode_notif &&
4212 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4215 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4216 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4218 link_sta->pub->rx_nss = nss;
4222 * Always handle WMM once after association regardless
4223 * of the first value the AP uses. Setting -1 here has
4224 * that effect because the AP values is an unsigned
4227 link->u.mgd.wmm_last_param_set = -1;
4228 link->u.mgd.mu_edca_last_param_set = -1;
4230 if (link->u.mgd.disable_wmm_tracking) {
4231 ieee80211_set_wmm_default(link, false, false);
4232 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4233 elems->wmm_param_len,
4234 elems->mu_edca_param_set)) {
4235 /* still enable QoS since we might have HT/VHT */
4236 ieee80211_set_wmm_default(link, false, true);
4237 /* disable WMM tracking in this case to disable
4238 * tracking WMM parameter changes in the beacon if
4239 * the parameters weren't actually valid. Doing so
4240 * avoids changing parameters very strangely when
4241 * the AP is going back and forth between valid and
4242 * invalid parameters.
4244 link->u.mgd.disable_wmm_tracking = true;
4247 if (elems->max_idle_period_ie) {
4248 bss_conf->max_idle_period =
4249 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4250 bss_conf->protected_keep_alive =
4251 !!(elems->max_idle_period_ie->idle_options &
4252 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4253 *changed |= BSS_CHANGED_KEEP_ALIVE;
4255 bss_conf->max_idle_period = 0;
4256 bss_conf->protected_keep_alive = false;
4259 /* set assoc capability (AID was already set earlier),
4260 * ieee80211_set_associated() will tell the driver */
4261 bss_conf->assoc_capability = capab_info;
4270 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4271 struct sta_info *sta,
4272 struct link_sta_info *link_sta,
4273 struct cfg80211_bss *cbss)
4275 struct ieee80211_sub_if_data *sdata = link->sdata;
4276 struct ieee80211_local *local = sdata->local;
4277 struct ieee80211_bss *bss = (void *)cbss->priv;
4278 u32 rates = 0, basic_rates = 0;
4279 bool have_higher_than_11mbit = false;
4280 int min_rate = INT_MAX, min_rate_index = -1;
4281 /* this is clearly wrong for MLO but we'll just remove it later */
4282 int shift = ieee80211_vif_get_shift(&sdata->vif);
4283 struct ieee80211_supported_band *sband;
4285 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4286 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4288 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4289 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4290 ieee80211_s1g_sta_rate_init(sta);
4294 sband = local->hw.wiphy->bands[cbss->channel->band];
4296 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4297 &rates, &basic_rates, &have_higher_than_11mbit,
4298 &min_rate, &min_rate_index, shift);
4301 * This used to be a workaround for basic rates missing
4302 * in the association response frame. Now that we no
4303 * longer use the basic rates from there, it probably
4304 * doesn't happen any more, but keep the workaround so
4305 * in case some *other* APs are buggy in different ways
4306 * we can connect -- with a warning.
4307 * Allow this workaround only in case the AP provided at least
4310 if (min_rate_index < 0) {
4311 link_info(link, "No legacy rates in association response\n");
4313 } else if (!basic_rates) {
4314 link_info(link, "No basic rates, using min rate instead\n");
4315 basic_rates = BIT(min_rate_index);
4319 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4321 link_info(link, "No rates found, keeping mandatory only\n");
4323 link->conf->basic_rates = basic_rates;
4325 /* cf. IEEE 802.11 9.2.12 */
4326 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4327 have_higher_than_11mbit;
4332 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4333 struct cfg80211_bss *cbss)
4335 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4336 const struct element *ht_cap_elem, *vht_cap_elem;
4337 const struct cfg80211_bss_ies *ies;
4338 const struct ieee80211_ht_cap *ht_cap;
4339 const struct ieee80211_vht_cap *vht_cap;
4340 const struct ieee80211_he_cap_elem *he_cap;
4341 const struct element *he_cap_elem;
4342 u16 mcs_80_map, mcs_160_map;
4343 int i, mcs_nss_size;
4347 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4350 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4351 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4352 ht_cap = (void *)ht_cap_elem->data;
4353 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4355 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4356 * "Tx Unequal Modulation Supported" fields.
4360 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4363 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4364 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4368 vht_cap = (void *)vht_cap_elem->data;
4369 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4370 for (nss = 8; nss > 0; nss--) {
4371 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4372 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4375 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4376 chains = max(chains, nss);
4379 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4382 ies = rcu_dereference(cbss->ies);
4383 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4384 ies->data, ies->len);
4386 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4389 /* skip one byte ext_tag_id */
4390 he_cap = (void *)(he_cap_elem->data + 1);
4391 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4394 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4397 /* mcs_nss is right after he_cap info */
4398 he_mcs_nss_supp = (void *)(he_cap + 1);
4400 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4402 for (i = 7; i >= 0; i--) {
4403 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4405 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4406 chains = max_t(u8, chains, i + 1);
4411 support_160 = he_cap->phy_cap_info[0] &
4412 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4417 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4418 for (i = 7; i >= 0; i--) {
4419 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4421 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4422 chains = max_t(u8, chains, i + 1);
4431 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4432 const struct cfg80211_bss_ies *ies,
4433 const struct ieee80211_he_operation *he_op)
4435 const struct element *he_cap_elem;
4436 const struct ieee80211_he_cap_elem *he_cap;
4437 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4438 u16 mcs_80_map_tx, mcs_80_map_rx;
4443 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4444 ies->data, ies->len);
4450 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4452 "Invalid HE elem, Disable HE\n");
4456 /* skip one byte ext_tag_id */
4457 he_cap = (void *)(he_cap_elem->data + 1);
4458 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4461 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4463 "Invalid HE elem with nss size, Disable HE\n");
4467 /* mcs_nss is right after he_cap info */
4468 he_mcs_nss_supp = (void *)(he_cap + 1);
4470 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4471 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4473 /* P802.11-REVme/D0.3
4474 * 27.1.1 Introduction to the HE PHY
4476 * An HE STA shall support the following features:
4478 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4479 * supported channel widths for HE SU PPDUs
4481 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4482 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4484 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4485 mcs_80_map_tx, mcs_80_map_rx);
4492 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4495 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4496 * zeroes, which is nonsense, and completely inconsistent with itself
4497 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4499 if (!ap_min_req_set)
4502 /* make sure the AP is consistent with itself
4504 * P802.11-REVme/D0.3
4505 * 26.17.1 Basic HE BSS operation
4507 * A STA that is operating in an HE BSS shall be able to receive and
4508 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4509 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4510 * MLME-START.request primitive and shall be able to receive at each of
4511 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4512 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4515 for (nss = 8; nss > 0; nss--) {
4516 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4520 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4523 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4524 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4526 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4527 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4528 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4530 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4531 nss, ap_rx_val, ap_rx_val, ap_op_val);
4540 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4541 struct ieee80211_supported_band *sband,
4542 const struct ieee80211_he_operation *he_op)
4544 const struct ieee80211_sta_he_cap *sta_he_cap =
4545 ieee80211_get_he_iftype_cap(sband,
4546 ieee80211_vif_type_p2p(&sdata->vif));
4550 if (!sta_he_cap || !he_op)
4553 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4556 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4557 * zeroes, which is nonsense, and completely inconsistent with itself
4558 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4560 if (!ap_min_req_set)
4563 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4564 for (i = 0; i < 3; i++) {
4565 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4566 &sta_he_cap->he_mcs_nss_supp;
4567 u16 sta_mcs_map_rx =
4568 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4569 u16 sta_mcs_map_tx =
4570 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4572 bool verified = true;
4575 * For each band there is a maximum of 8 spatial streams
4576 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4577 * of 2 bits per NSS (1-8), with the values defined in enum
4578 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4579 * capabilities aren't less than the AP's minimum requirements
4580 * for this HE BSS per SS.
4581 * It is enough to find one such band that meets the reqs.
4583 for (nss = 8; nss > 0; nss--) {
4584 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4585 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4586 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4588 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4592 * Make sure the HE AP doesn't require MCSs that aren't
4593 * supported by the client as required by spec
4595 * P802.11-REVme/D0.3
4596 * 26.17.1 Basic HE BSS operation
4598 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4599 * a BSS, unless it supports (i.e., is able to both transmit and
4600 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4601 * HE-MCS and NSS set.
4603 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4604 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4605 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4615 /* If here, STA doesn't meet AP's HE min requirements */
4619 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4620 struct ieee80211_link_data *link,
4621 struct cfg80211_bss *cbss,
4622 ieee80211_conn_flags_t *conn_flags)
4624 struct ieee80211_local *local = sdata->local;
4625 const struct ieee80211_ht_cap *ht_cap = NULL;
4626 const struct ieee80211_ht_operation *ht_oper = NULL;
4627 const struct ieee80211_vht_operation *vht_oper = NULL;
4628 const struct ieee80211_he_operation *he_oper = NULL;
4629 const struct ieee80211_eht_operation *eht_oper = NULL;
4630 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4631 struct ieee80211_supported_band *sband;
4632 struct cfg80211_chan_def chandef;
4633 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4634 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4635 struct ieee80211_bss *bss = (void *)cbss->priv;
4636 struct ieee80211_elems_parse_params parse_params = {
4641 struct ieee802_11_elems *elems;
4642 const struct cfg80211_bss_ies *ies;
4649 ies = rcu_dereference(cbss->ies);
4650 parse_params.start = ies->data;
4651 parse_params.len = ies->len;
4652 elems = ieee802_11_parse_elems_full(&parse_params);
4658 sband = local->hw.wiphy->bands[cbss->channel->band];
4660 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4661 IEEE80211_CONN_DISABLE_80P80MHZ |
4662 IEEE80211_CONN_DISABLE_160MHZ);
4664 /* disable HT/VHT/HE if we don't support them */
4665 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4666 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4667 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4668 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4669 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4670 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4673 if (!sband->vht_cap.vht_supported && is_5ghz) {
4674 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4675 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4676 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4677 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4680 if (!ieee80211_get_he_iftype_cap(sband,
4681 ieee80211_vif_type_p2p(&sdata->vif))) {
4682 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4683 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4684 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4687 if (!ieee80211_get_eht_iftype_cap(sband,
4688 ieee80211_vif_type_p2p(&sdata->vif))) {
4689 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4690 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4693 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4694 ht_oper = elems->ht_operation;
4695 ht_cap = elems->ht_cap_elem;
4698 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4703 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4704 vht_oper = elems->vht_operation;
4705 if (vht_oper && !ht_oper) {
4708 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4709 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4710 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4711 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4712 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4715 if (!elems->vht_cap_elem) {
4716 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4721 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4722 he_oper = elems->he_operation;
4724 if (link && is_6ghz) {
4725 struct ieee80211_bss_conf *bss_conf;
4728 bss_conf = link->conf;
4730 if (elems->pwr_constr_elem)
4731 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4733 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4734 ARRAY_SIZE(elems->tx_pwr_env));
4736 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4737 if (elems->tx_pwr_env_len[i] >
4738 sizeof(bss_conf->tx_pwr_env[j]))
4741 bss_conf->tx_pwr_env_num++;
4742 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4743 elems->tx_pwr_env_len[i]);
4748 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4749 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4750 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4751 IEEE80211_CONN_DISABLE_EHT;
4755 * EHT requires HE to be supported as well. Specifically for 6 GHz
4756 * channels, the operation channel information can only be deduced from
4757 * both the 6 GHz operation information (from the HE operation IE) and
4761 (IEEE80211_CONN_DISABLE_HE |
4762 IEEE80211_CONN_DISABLE_EHT)) &&
4764 const struct cfg80211_bss_ies *cbss_ies;
4765 const u8 *eht_oper_ie;
4767 cbss_ies = rcu_dereference(cbss->ies);
4768 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4769 cbss_ies->data, cbss_ies->len);
4770 if (eht_oper_ie && eht_oper_ie[1] >=
4771 1 + sizeof(struct ieee80211_eht_operation))
4772 eht_oper = (void *)(eht_oper_ie + 3);
4777 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4779 for (i = 0; i < sband->n_channels; i++) {
4780 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4781 IEEE80211_CHAN_NO_80MHZ))
4789 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
4790 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4793 if (sband->band == NL80211_BAND_S1GHZ) {
4794 s1g_oper = elems->s1g_oper;
4797 "AP missing S1G operation element?\n");
4801 ieee80211_determine_chantype(sdata, link, *conn_flags,
4811 link->needed_rx_chains =
4812 min(ieee80211_max_rx_chains(link, cbss),
4816 /* the element data was RCU protected so no longer valid anyway */
4820 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
4821 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
4828 /* will change later if needed */
4829 link->smps_mode = IEEE80211_SMPS_OFF;
4831 mutex_lock(&local->mtx);
4833 * If this fails (possibly due to channel context sharing
4834 * on incompatible channels, e.g. 80+80 and 160 sharing the
4835 * same control channel) try to use a smaller bandwidth.
4837 ret = ieee80211_link_use_channel(link, &chandef,
4838 IEEE80211_CHANCTX_SHARED);
4840 /* don't downgrade for 5 and 10 MHz channels, though. */
4841 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4842 chandef.width == NL80211_CHAN_WIDTH_10)
4845 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4847 ieee80211_chandef_downgrade(&chandef);
4848 ret = ieee80211_link_use_channel(link, &chandef,
4849 IEEE80211_CHANCTX_SHARED);
4852 mutex_unlock(&local->mtx);
4856 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4857 u8 *dtim_count, u8 *dtim_period)
4859 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4860 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4862 const struct ieee80211_tim_ie *tim = NULL;
4863 const struct ieee80211_bssid_index *idx;
4864 bool valid = tim_ie && tim_ie[1] >= 2;
4867 tim = (void *)(tim_ie + 2);
4870 *dtim_count = valid ? tim->dtim_count : 0;
4873 *dtim_period = valid ? tim->dtim_period : 0;
4875 /* Check if value is overridden by non-transmitted profile */
4876 if (!idx_ie || idx_ie[1] < 3)
4879 idx = (void *)(idx_ie + 2);
4882 *dtim_count = idx->dtim_count;
4885 *dtim_period = idx->dtim_period;
4890 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
4891 struct ieee80211_mgmt *mgmt,
4892 struct ieee802_11_elems *elems,
4893 const u8 *elem_start, unsigned int elem_len)
4895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4896 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
4897 struct ieee80211_local *local = sdata->local;
4898 unsigned int link_id;
4899 struct sta_info *sta;
4900 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
4901 u16 valid_links = 0;
4904 mutex_lock(&sdata->local->sta_mtx);
4906 * station info was already allocated and inserted before
4907 * the association and should be available to us
4909 sta = sta_info_get(sdata, assoc_data->ap_addr);
4913 if (sdata->vif.valid_links) {
4914 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4915 if (!assoc_data->link[link_id].bss)
4917 valid_links |= BIT(link_id);
4919 if (link_id != assoc_data->assoc_link_id) {
4920 err = ieee80211_sta_allocate_link(sta, link_id);
4926 ieee80211_vif_set_links(sdata, valid_links);
4929 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4930 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
4931 struct ieee80211_link_data *link;
4932 struct link_sta_info *link_sta;
4937 link = sdata_dereference(sdata->link[link_id], sdata);
4941 if (sdata->vif.valid_links)
4943 "local address %pM, AP link address %pM%s\n",
4945 assoc_data->link[link_id].bss->bssid,
4946 link_id == assoc_data->assoc_link_id ?
4949 link_sta = rcu_dereference_protected(sta->link[link_id],
4950 lockdep_is_held(&local->sta_mtx));
4951 if (WARN_ON(!link_sta))
4954 if (!link->u.mgd.have_beacon) {
4955 const struct cfg80211_bss_ies *ies;
4958 ies = rcu_dereference(cbss->beacon_ies);
4960 link->u.mgd.have_beacon = true;
4962 ies = rcu_dereference(cbss->ies);
4963 ieee80211_get_dtim(ies,
4964 &link->conf->sync_dtim_count,
4965 &link->u.mgd.dtim_period);
4966 link->conf->beacon_int = cbss->beacon_interval;
4970 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
4972 if (link_id != assoc_data->assoc_link_id) {
4973 err = ieee80211_prep_channel(sdata, link, cbss,
4974 &link->u.mgd.conn_flags);
4976 link_info(link, "prep_channel failed\n");
4981 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
4982 assoc_data->link[link_id].bss);
4986 if (!ieee80211_assoc_config_link(link, link_sta,
4987 assoc_data->link[link_id].bss,
4988 mgmt, elem_start, elem_len,
4992 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4993 valid_links &= ~BIT(link_id);
4994 ieee80211_sta_remove_link(sta, link_id);
4998 if (link_id != assoc_data->assoc_link_id) {
4999 err = ieee80211_sta_activate_link(sta, link_id);
5005 /* links might have changed due to rejected ones, set them again */
5006 ieee80211_vif_set_links(sdata, valid_links);
5008 rate_control_rate_init(sta);
5010 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5011 set_sta_flag(sta, WLAN_STA_MFP);
5012 sta->sta.mfp = true;
5014 sta->sta.mfp = false;
5017 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5018 elems->ext_capab_len);
5020 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5021 local->hw.queues >= IEEE80211_NUM_ACS;
5023 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5024 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5025 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5028 "failed to move station %pM to desired state\n",
5030 WARN_ON(__sta_info_destroy(sta));
5034 if (sdata->wdev.use_4addr)
5035 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5037 mutex_unlock(&sdata->local->sta_mtx);
5039 ieee80211_set_associated(sdata, assoc_data, changed);
5042 * If we're using 4-addr mode, let the AP know that we're
5043 * doing so, so that it can create the STA VLAN on its side
5045 if (ifmgd->use_4addr)
5046 ieee80211_send_4addr_nullfunc(local, sdata);
5049 * Start timer to probe the connection to the AP now.
5050 * Also start the timer that will detect beacon loss.
5052 ieee80211_sta_reset_beacon_monitor(sdata);
5053 ieee80211_sta_reset_conn_monitor(sdata);
5057 eth_zero_addr(sdata->vif.cfg.ap_addr);
5058 mutex_unlock(&sdata->local->sta_mtx);
5062 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5063 struct ieee80211_mgmt *mgmt,
5066 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5067 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5068 u16 capab_info, status_code, aid;
5069 struct ieee80211_elems_parse_params parse_params = {
5074 struct ieee802_11_elems *elems;
5076 const u8 *elem_start;
5077 unsigned int elem_len;
5079 struct ieee80211_event event = {
5081 .u.mlme.data = ASSOC_EVENT,
5083 struct ieee80211_prep_tx_info info = {};
5084 struct cfg80211_rx_assoc_resp resp = {
5087 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5088 unsigned int link_id;
5090 sdata_assert_lock(sdata);
5095 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5096 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5100 * AssocResp and ReassocResp have identical structure, so process both
5101 * of them in this function.
5107 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5108 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5109 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5110 if (assoc_data->s1g)
5111 elem_start = mgmt->u.s1g_assoc_resp.variable;
5113 elem_start = mgmt->u.assoc_resp.variable;
5116 * Note: this may not be perfect, AP might misbehave - if
5117 * anyone needs to rely on perfect complete notification
5118 * with the exact right subtype, then we need to track what
5119 * we actually transmitted.
5121 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5122 IEEE80211_STYPE_ASSOC_REQ;
5124 if (assoc_data->fils_kek_len &&
5125 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5128 elem_len = len - (elem_start - (u8 *)mgmt);
5129 parse_params.start = elem_start;
5130 parse_params.len = elem_len;
5131 elems = ieee802_11_parse_elems_full(&parse_params);
5135 if (elems->aid_resp)
5136 aid = le16_to_cpu(elems->aid_resp->aid);
5137 else if (assoc_data->s1g)
5140 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5143 * The 5 MSB of the AID field are reserved
5144 * (802.11-2016 9.4.1.8 AID field)
5149 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5150 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5151 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5153 ifmgd->broken_ap = false;
5155 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5156 elems->timeout_int &&
5157 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5160 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5161 le32_to_cpu(elems->timeout_int->value));
5163 tu = le32_to_cpu(elems->timeout_int->value);
5164 ms = tu * 1024 / 1000;
5166 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5167 assoc_data->ap_addr, tu, ms);
5168 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5169 assoc_data->timeout_started = true;
5170 if (ms > IEEE80211_ASSOC_TIMEOUT)
5171 run_again(sdata, assoc_data->timeout);
5175 if (status_code != WLAN_STATUS_SUCCESS) {
5176 sdata_info(sdata, "%pM denied association (code=%d)\n",
5177 assoc_data->ap_addr, status_code);
5178 event.u.mlme.status = MLME_DENIED;
5179 event.u.mlme.reason = status_code;
5180 drv_event_callback(sdata->local, sdata, &event);
5182 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5184 "invalid AID value %d (out of range), turn off PS\n",
5187 ifmgd->broken_ap = true;
5190 if (sdata->vif.valid_links) {
5191 if (!elems->multi_link) {
5193 "MLO association with %pM but no multi-link element in response!\n",
5194 assoc_data->ap_addr);
5198 if (le16_get_bits(elems->multi_link->control,
5199 IEEE80211_ML_CONTROL_TYPE) !=
5200 IEEE80211_ML_CONTROL_TYPE_BASIC) {
5202 "bad multi-link element (control=0x%x)\n",
5203 le16_to_cpu(elems->multi_link->control));
5206 struct ieee80211_mle_basic_common_info *common;
5208 common = (void *)elems->multi_link->variable;
5210 if (memcmp(assoc_data->ap_addr,
5211 common->mld_mac_addr, ETH_ALEN)) {
5213 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5214 common->mld_mac_addr,
5215 assoc_data->ap_addr);
5221 sdata->vif.cfg.aid = aid;
5223 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5224 elem_start, elem_len)) {
5225 /* oops -- internal error -- send timeout for now */
5226 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5229 event.u.mlme.status = MLME_SUCCESS;
5230 drv_event_callback(sdata->local, sdata, &event);
5231 sdata_info(sdata, "associated\n");
5236 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5237 struct ieee80211_link_data *link;
5239 link = sdata_dereference(sdata->link[link_id], sdata);
5243 if (!assoc_data->link[link_id].bss)
5246 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5247 resp.links[link_id].addr = link->conf->addr;
5248 resp.links[link_id].status = assoc_data->link[link_id].status;
5250 /* get uapsd queues configuration - same for all links */
5251 resp.uapsd_queues = 0;
5252 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5253 if (link->tx_conf[ac].uapsd)
5254 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5257 if (sdata->vif.valid_links) {
5258 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5259 resp.ap_mld_addr = ap_mld_addr;
5262 ieee80211_destroy_assoc_data(sdata,
5263 status_code == WLAN_STATUS_SUCCESS ?
5267 resp.buf = (u8 *)mgmt;
5269 resp.req_ies = ifmgd->assoc_req_ies;
5270 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5271 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5273 drv_mgd_complete_tx(sdata->local, sdata, &info);
5277 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5281 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5282 struct ieee80211_mgmt *mgmt, size_t len,
5283 struct ieee80211_rx_status *rx_status)
5285 struct ieee80211_sub_if_data *sdata = link->sdata;
5286 struct ieee80211_local *local = sdata->local;
5287 struct ieee80211_bss *bss;
5288 struct ieee80211_channel *channel;
5290 sdata_assert_lock(sdata);
5292 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5293 ieee80211_rx_status_to_khz(rx_status));
5297 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5299 link->conf->beacon_rate = bss->beacon_rate;
5300 ieee80211_rx_bss_put(local, bss);
5305 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5306 struct sk_buff *skb)
5308 struct ieee80211_sub_if_data *sdata = link->sdata;
5309 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5310 struct ieee80211_if_managed *ifmgd;
5311 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5312 struct ieee80211_channel *channel;
5313 size_t baselen, len = skb->len;
5315 ifmgd = &sdata->u.mgd;
5317 sdata_assert_lock(sdata);
5320 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5321 * "If a 6 GHz AP receives a Probe Request frame and responds with
5322 * a Probe Response frame [..], the Address 1 field of the Probe
5323 * Response frame shall be set to the broadcast address [..]"
5324 * So, on 6GHz band we should also accept broadcast responses.
5326 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5331 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5332 (channel->band != NL80211_BAND_6GHZ ||
5333 !is_broadcast_ether_addr(mgmt->da)))
5334 return; /* ignore ProbeResp to foreign address */
5336 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5340 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5342 if (ifmgd->associated &&
5343 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5344 ieee80211_reset_ap_probe(sdata);
5348 * This is the canonical list of information elements we care about,
5349 * the filter code also gives us all changes to the Microsoft OUI
5350 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5351 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5352 * changes to requested client power.
5354 * We implement beacon filtering in software since that means we can
5355 * avoid processing the frame here and in cfg80211, and userspace
5356 * will not be able to tell whether the hardware supports it or not.
5358 * XXX: This list needs to be dynamic -- userspace needs to be able to
5359 * add items it requires. It also needs to be able to tell us to
5360 * look out for other vendor IEs.
5362 static const u64 care_about_ies =
5363 (1ULL << WLAN_EID_COUNTRY) |
5364 (1ULL << WLAN_EID_ERP_INFO) |
5365 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5366 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5367 (1ULL << WLAN_EID_HT_CAPABILITY) |
5368 (1ULL << WLAN_EID_HT_OPERATION) |
5369 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5371 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5372 struct ieee80211_if_managed *ifmgd,
5373 struct ieee80211_bss_conf *bss_conf,
5374 struct ieee80211_local *local,
5375 struct ieee80211_rx_status *rx_status)
5377 struct ieee80211_sub_if_data *sdata = link->sdata;
5379 /* Track average RSSI from the Beacon frames of the current AP */
5381 if (!link->u.mgd.tracking_signal_avg) {
5382 link->u.mgd.tracking_signal_avg = true;
5383 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5384 link->u.mgd.last_cqm_event_signal = 0;
5385 link->u.mgd.count_beacon_signal = 1;
5386 link->u.mgd.last_ave_beacon_signal = 0;
5388 link->u.mgd.count_beacon_signal++;
5391 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5392 -rx_status->signal);
5394 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5395 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5396 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5397 int last_sig = link->u.mgd.last_ave_beacon_signal;
5398 struct ieee80211_event event = {
5403 * if signal crosses either of the boundaries, invoke callback
5404 * with appropriate parameters
5406 if (sig > ifmgd->rssi_max_thold &&
5407 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5408 link->u.mgd.last_ave_beacon_signal = sig;
5409 event.u.rssi.data = RSSI_EVENT_HIGH;
5410 drv_event_callback(local, sdata, &event);
5411 } else if (sig < ifmgd->rssi_min_thold &&
5412 (last_sig >= ifmgd->rssi_max_thold ||
5414 link->u.mgd.last_ave_beacon_signal = sig;
5415 event.u.rssi.data = RSSI_EVENT_LOW;
5416 drv_event_callback(local, sdata, &event);
5420 if (bss_conf->cqm_rssi_thold &&
5421 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5422 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5423 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5424 int last_event = link->u.mgd.last_cqm_event_signal;
5425 int thold = bss_conf->cqm_rssi_thold;
5426 int hyst = bss_conf->cqm_rssi_hyst;
5429 (last_event == 0 || sig < last_event - hyst)) {
5430 link->u.mgd.last_cqm_event_signal = sig;
5431 ieee80211_cqm_rssi_notify(
5433 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5435 } else if (sig > thold &&
5436 (last_event == 0 || sig > last_event + hyst)) {
5437 link->u.mgd.last_cqm_event_signal = sig;
5438 ieee80211_cqm_rssi_notify(
5440 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5445 if (bss_conf->cqm_rssi_low &&
5446 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5447 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5448 int last_event = link->u.mgd.last_cqm_event_signal;
5449 int low = bss_conf->cqm_rssi_low;
5450 int high = bss_conf->cqm_rssi_high;
5453 (last_event == 0 || last_event >= low)) {
5454 link->u.mgd.last_cqm_event_signal = sig;
5455 ieee80211_cqm_rssi_notify(
5457 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5459 } else if (sig > high &&
5460 (last_event == 0 || last_event <= high)) {
5461 link->u.mgd.last_cqm_event_signal = sig;
5462 ieee80211_cqm_rssi_notify(
5464 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5470 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5471 struct cfg80211_bss *bss)
5473 if (ether_addr_equal(tx_bssid, bss->bssid))
5475 if (!bss->transmitted_bss)
5477 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5480 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
5481 struct ieee80211_hdr *hdr, size_t len,
5482 struct ieee80211_rx_status *rx_status)
5484 struct ieee80211_sub_if_data *sdata = link->sdata;
5485 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5486 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5487 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
5488 struct ieee80211_mgmt *mgmt = (void *) hdr;
5490 struct ieee802_11_elems *elems;
5491 struct ieee80211_local *local = sdata->local;
5492 struct ieee80211_chanctx_conf *chanctx_conf;
5493 struct ieee80211_supported_band *sband;
5494 struct ieee80211_channel *chan;
5495 struct link_sta_info *link_sta;
5496 struct sta_info *sta;
5501 u8 *bssid, *variable = mgmt->u.beacon.variable;
5502 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
5503 struct ieee80211_elems_parse_params parse_params = {
5508 sdata_assert_lock(sdata);
5510 /* Process beacon from the current BSS */
5511 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
5512 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
5513 struct ieee80211_ext *ext = (void *) mgmt;
5515 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
5516 variable = ext->u.s1g_short_beacon.variable;
5518 variable = ext->u.s1g_beacon.variable;
5521 baselen = (u8 *) variable - (u8 *) mgmt;
5525 parse_params.start = variable;
5526 parse_params.len = len - baselen;
5529 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
5530 if (!chanctx_conf) {
5535 if (ieee80211_rx_status_to_khz(rx_status) !=
5536 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
5540 chan = chanctx_conf->def.chan;
5543 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
5544 !WARN_ON(sdata->vif.valid_links) &&
5545 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
5546 parse_params.bss = ifmgd->assoc_data->link[0].bss;
5547 elems = ieee802_11_parse_elems_full(&parse_params);
5551 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5553 if (elems->dtim_period)
5554 link->u.mgd.dtim_period = elems->dtim_period;
5555 link->u.mgd.have_beacon = true;
5556 ifmgd->assoc_data->need_beacon = false;
5557 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5558 link->conf->sync_tsf =
5559 le64_to_cpu(mgmt->u.beacon.timestamp);
5560 link->conf->sync_device_ts =
5561 rx_status->device_timestamp;
5562 link->conf->sync_dtim_count = elems->dtim_count;
5565 if (elems->mbssid_config_ie)
5566 bss_conf->profile_periodicity =
5567 elems->mbssid_config_ie->profile_periodicity;
5569 bss_conf->profile_periodicity = 0;
5571 if (elems->ext_capab_len >= 11 &&
5572 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5573 bss_conf->ema_ap = true;
5575 bss_conf->ema_ap = false;
5577 /* continue assoc process */
5578 ifmgd->assoc_data->timeout = jiffies;
5579 ifmgd->assoc_data->timeout_started = true;
5580 run_again(sdata, ifmgd->assoc_data->timeout);
5585 if (!ifmgd->associated ||
5586 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
5588 bssid = link->u.mgd.bssid;
5590 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
5591 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
5594 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
5595 mlme_dbg_ratelimited(sdata,
5596 "cancelling AP probe due to a received beacon\n");
5597 ieee80211_reset_ap_probe(sdata);
5601 * Push the beacon loss detection into the future since
5602 * we are processing a beacon from the AP just now.
5604 ieee80211_sta_reset_beacon_monitor(sdata);
5606 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
5607 * element (which carries the beacon interval). Don't forget to add a
5608 * bit to care_about_ies[] above if mac80211 is interested in a
5609 * changing S1G element.
5611 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5612 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
5613 parse_params.bss = link->u.mgd.bss;
5614 parse_params.filter = care_about_ies;
5615 parse_params.crc = ncrc;
5616 elems = ieee802_11_parse_elems_full(&parse_params);
5621 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
5622 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
5623 if (local->hw.conf.dynamic_ps_timeout > 0) {
5624 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
5625 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
5626 ieee80211_hw_config(local,
5627 IEEE80211_CONF_CHANGE_PS);
5629 ieee80211_send_nullfunc(local, sdata, false);
5630 } else if (!local->pspolling && sdata->u.mgd.powersave) {
5631 local->pspolling = true;
5634 * Here is assumed that the driver will be
5635 * able to send ps-poll frame and receive a
5636 * response even though power save mode is
5637 * enabled, but some drivers might require
5638 * to disable power save here. This needs
5639 * to be investigated.
5641 ieee80211_send_pspoll(local, sdata);
5645 if (sdata->vif.p2p ||
5646 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
5647 struct ieee80211_p2p_noa_attr noa = {};
5650 ret = cfg80211_get_p2p_attr(variable,
5652 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
5653 (u8 *) &noa, sizeof(noa));
5655 if (link->u.mgd.p2p_noa_index != noa.index) {
5656 /* valid noa_attr and index changed */
5657 link->u.mgd.p2p_noa_index = noa.index;
5658 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
5659 changed |= BSS_CHANGED_P2P_PS;
5661 * make sure we update all information, the CRC
5662 * mechanism doesn't look at P2P attributes.
5664 link->u.mgd.beacon_crc_valid = false;
5666 } else if (link->u.mgd.p2p_noa_index != -1) {
5667 /* noa_attr not found and we had valid noa_attr before */
5668 link->u.mgd.p2p_noa_index = -1;
5669 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
5670 changed |= BSS_CHANGED_P2P_PS;
5671 link->u.mgd.beacon_crc_valid = false;
5675 if (link->u.mgd.csa_waiting_bcn)
5676 ieee80211_chswitch_post_beacon(link);
5679 * Update beacon timing and dtim count on every beacon appearance. This
5680 * will allow the driver to use the most updated values. Do it before
5681 * comparing this one with last received beacon.
5682 * IMPORTANT: These parameters would possibly be out of sync by the time
5683 * the driver will use them. The synchronized view is currently
5684 * guaranteed only in certain callbacks.
5686 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
5687 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
5688 link->conf->sync_tsf =
5689 le64_to_cpu(mgmt->u.beacon.timestamp);
5690 link->conf->sync_device_ts =
5691 rx_status->device_timestamp;
5692 link->conf->sync_dtim_count = elems->dtim_count;
5695 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
5696 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
5698 link->u.mgd.beacon_crc = ncrc;
5699 link->u.mgd.beacon_crc_valid = true;
5701 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5703 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
5704 rx_status->device_timestamp,
5707 if (!link->u.mgd.disable_wmm_tracking &&
5708 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
5709 elems->wmm_param_len,
5710 elems->mu_edca_param_set))
5711 changed |= BSS_CHANGED_QOS;
5714 * If we haven't had a beacon before, tell the driver about the
5715 * DTIM period (and beacon timing if desired) now.
5717 if (!link->u.mgd.have_beacon) {
5718 /* a few bogus AP send dtim_period = 0 or no TIM IE */
5719 bss_conf->dtim_period = elems->dtim_period ?: 1;
5721 changed |= BSS_CHANGED_BEACON_INFO;
5722 link->u.mgd.have_beacon = true;
5724 mutex_lock(&local->iflist_mtx);
5725 ieee80211_recalc_ps(local);
5726 mutex_unlock(&local->iflist_mtx);
5728 ieee80211_recalc_ps_vif(sdata);
5731 if (elems->erp_info) {
5733 erp_value = elems->erp_info[0];
5738 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5739 changed |= ieee80211_handle_bss_capability(link,
5740 le16_to_cpu(mgmt->u.beacon.capab_info),
5741 erp_valid, erp_value);
5743 mutex_lock(&local->sta_mtx);
5744 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
5745 if (WARN_ON(!sta)) {
5746 mutex_unlock(&local->sta_mtx);
5749 link_sta = rcu_dereference_protected(sta->link[link->link_id],
5750 lockdep_is_held(&local->sta_mtx));
5751 if (WARN_ON(!link_sta)) {
5752 mutex_unlock(&local->sta_mtx);
5756 if (WARN_ON(!link->conf->chandef.chan))
5759 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
5761 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
5763 if (ieee80211_config_bw(link, elems->ht_cap_elem,
5764 elems->vht_cap_elem, elems->ht_operation,
5765 elems->vht_operation, elems->he_operation,
5766 elems->eht_operation,
5767 elems->s1g_oper, bssid, &changed)) {
5768 mutex_unlock(&local->sta_mtx);
5770 "failed to follow AP %pM bandwidth change, disconnect\n",
5772 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5773 WLAN_REASON_DEAUTH_LEAVING,
5775 ieee80211_report_disconnect(sdata, deauth_buf,
5776 sizeof(deauth_buf), true,
5777 WLAN_REASON_DEAUTH_LEAVING,
5782 if (sta && elems->opmode_notif)
5783 ieee80211_vht_handle_opmode(sdata, link_sta,
5784 *elems->opmode_notif,
5786 mutex_unlock(&local->sta_mtx);
5788 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
5789 elems->country_elem,
5790 elems->country_elem_len,
5791 elems->pwr_constr_elem,
5792 elems->cisco_dtpc_elem);
5794 ieee80211_link_info_change_notify(sdata, link, changed);
5799 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
5800 struct sk_buff *skb)
5802 struct ieee80211_link_data *link = &sdata->deflink;
5803 struct ieee80211_rx_status *rx_status;
5804 struct ieee80211_hdr *hdr;
5807 rx_status = (struct ieee80211_rx_status *) skb->cb;
5808 hdr = (struct ieee80211_hdr *) skb->data;
5809 fc = le16_to_cpu(hdr->frame_control);
5812 switch (fc & IEEE80211_FCTL_STYPE) {
5813 case IEEE80211_STYPE_S1G_BEACON:
5814 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
5817 sdata_unlock(sdata);
5820 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
5821 struct sk_buff *skb)
5823 struct ieee80211_link_data *link = &sdata->deflink;
5824 struct ieee80211_rx_status *rx_status;
5825 struct ieee80211_mgmt *mgmt;
5829 rx_status = (struct ieee80211_rx_status *) skb->cb;
5830 mgmt = (struct ieee80211_mgmt *) skb->data;
5831 fc = le16_to_cpu(mgmt->frame_control);
5835 if (rx_status->link_valid) {
5836 link = sdata_dereference(sdata->link[rx_status->link_id],
5842 switch (fc & IEEE80211_FCTL_STYPE) {
5843 case IEEE80211_STYPE_BEACON:
5844 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
5845 skb->len, rx_status);
5847 case IEEE80211_STYPE_PROBE_RESP:
5848 ieee80211_rx_mgmt_probe_resp(link, skb);
5850 case IEEE80211_STYPE_AUTH:
5851 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
5853 case IEEE80211_STYPE_DEAUTH:
5854 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
5856 case IEEE80211_STYPE_DISASSOC:
5857 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
5859 case IEEE80211_STYPE_ASSOC_RESP:
5860 case IEEE80211_STYPE_REASSOC_RESP:
5861 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
5863 case IEEE80211_STYPE_ACTION:
5864 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
5865 struct ieee802_11_elems *elems;
5867 ies_len = skb->len -
5868 offsetof(struct ieee80211_mgmt,
5869 u.action.u.chan_switch.variable);
5874 /* CSA IE cannot be overridden, no need for BSSID */
5875 elems = ieee802_11_parse_elems(
5876 mgmt->u.action.u.chan_switch.variable,
5877 ies_len, true, NULL);
5879 if (elems && !elems->parse_error)
5880 ieee80211_sta_process_chanswitch(link,
5882 rx_status->device_timestamp,
5885 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
5886 struct ieee802_11_elems *elems;
5888 ies_len = skb->len -
5889 offsetof(struct ieee80211_mgmt,
5890 u.action.u.ext_chan_switch.variable);
5896 * extended CSA IE can't be overridden, no need for
5899 elems = ieee802_11_parse_elems(
5900 mgmt->u.action.u.ext_chan_switch.variable,
5901 ies_len, true, NULL);
5903 if (elems && !elems->parse_error) {
5904 /* for the handling code pretend it was an IE */
5905 elems->ext_chansw_ie =
5906 &mgmt->u.action.u.ext_chan_switch.data;
5908 ieee80211_sta_process_chanswitch(link,
5910 rx_status->device_timestamp,
5919 sdata_unlock(sdata);
5922 static void ieee80211_sta_timer(struct timer_list *t)
5924 struct ieee80211_sub_if_data *sdata =
5925 from_timer(sdata, t, u.mgd.timer);
5927 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
5930 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
5933 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
5935 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
5938 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
5942 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
5944 struct ieee80211_local *local = sdata->local;
5945 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5946 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
5950 struct ieee80211_prep_tx_info info = {
5951 .subtype = IEEE80211_STYPE_AUTH,
5954 sdata_assert_lock(sdata);
5956 if (WARN_ON_ONCE(!auth_data))
5961 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
5962 sdata_info(sdata, "authentication with %pM timed out\n",
5963 auth_data->ap_addr);
5966 * Most likely AP is not in the range so remove the
5967 * bss struct for that AP.
5969 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
5974 if (auth_data->algorithm == WLAN_AUTH_SAE)
5975 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
5977 drv_mgd_prepare_tx(local, sdata, &info);
5979 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
5980 auth_data->ap_addr, auth_data->tries,
5981 IEEE80211_AUTH_MAX_TRIES);
5983 auth_data->expected_transaction = 2;
5985 if (auth_data->algorithm == WLAN_AUTH_SAE) {
5986 trans = auth_data->sae_trans;
5987 status = auth_data->sae_status;
5988 auth_data->expected_transaction = trans;
5991 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
5992 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
5993 IEEE80211_TX_INTFL_MLME_CONN_TX;
5995 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
5996 auth_data->data, auth_data->data_len,
5997 auth_data->ap_addr, auth_data->ap_addr,
5998 NULL, 0, 0, tx_flags);
6000 if (tx_flags == 0) {
6001 if (auth_data->algorithm == WLAN_AUTH_SAE)
6002 auth_data->timeout = jiffies +
6003 IEEE80211_AUTH_TIMEOUT_SAE;
6005 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6007 auth_data->timeout =
6008 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6011 auth_data->timeout_started = true;
6012 run_again(sdata, auth_data->timeout);
6017 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6019 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6020 struct ieee80211_local *local = sdata->local;
6023 sdata_assert_lock(sdata);
6025 assoc_data->tries++;
6026 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6027 sdata_info(sdata, "association with %pM timed out\n",
6028 assoc_data->ap_addr);
6031 * Most likely AP is not in the range so remove the
6032 * bss struct for that AP.
6034 cfg80211_unlink_bss(local->hw.wiphy,
6035 assoc_data->link[assoc_data->assoc_link_id].bss);
6040 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6041 assoc_data->ap_addr, assoc_data->tries,
6042 IEEE80211_ASSOC_MAX_TRIES);
6043 ret = ieee80211_send_assoc(sdata);
6047 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6048 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6049 assoc_data->timeout_started = true;
6050 run_again(sdata, assoc_data->timeout);
6052 assoc_data->timeout =
6053 round_jiffies_up(jiffies +
6054 IEEE80211_ASSOC_TIMEOUT_LONG);
6055 assoc_data->timeout_started = true;
6056 run_again(sdata, assoc_data->timeout);
6062 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6063 __le16 fc, bool acked)
6065 struct ieee80211_local *local = sdata->local;
6067 sdata->u.mgd.status_fc = fc;
6068 sdata->u.mgd.status_acked = acked;
6069 sdata->u.mgd.status_received = true;
6071 ieee80211_queue_work(&local->hw, &sdata->work);
6074 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6076 struct ieee80211_local *local = sdata->local;
6077 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6081 if (ifmgd->status_received) {
6082 __le16 fc = ifmgd->status_fc;
6083 bool status_acked = ifmgd->status_acked;
6085 ifmgd->status_received = false;
6086 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6088 if (ifmgd->auth_data->algorithm ==
6090 ifmgd->auth_data->timeout =
6092 IEEE80211_AUTH_TIMEOUT_SAE;
6094 ifmgd->auth_data->timeout =
6096 IEEE80211_AUTH_TIMEOUT_SHORT;
6097 run_again(sdata, ifmgd->auth_data->timeout);
6099 ifmgd->auth_data->timeout = jiffies - 1;
6101 ifmgd->auth_data->timeout_started = true;
6102 } else if (ifmgd->assoc_data &&
6103 (ieee80211_is_assoc_req(fc) ||
6104 ieee80211_is_reassoc_req(fc))) {
6106 ifmgd->assoc_data->timeout =
6107 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6108 run_again(sdata, ifmgd->assoc_data->timeout);
6110 ifmgd->assoc_data->timeout = jiffies - 1;
6112 ifmgd->assoc_data->timeout_started = true;
6116 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6117 time_after(jiffies, ifmgd->auth_data->timeout)) {
6118 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6120 * ok ... we waited for assoc or continuation but
6121 * userspace didn't do it, so kill the auth data
6123 ieee80211_destroy_auth_data(sdata, false);
6124 } else if (ieee80211_auth(sdata)) {
6125 u8 ap_addr[ETH_ALEN];
6126 struct ieee80211_event event = {
6128 .u.mlme.data = AUTH_EVENT,
6129 .u.mlme.status = MLME_TIMEOUT,
6132 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6134 ieee80211_destroy_auth_data(sdata, false);
6136 cfg80211_auth_timeout(sdata->dev, ap_addr);
6137 drv_event_callback(sdata->local, sdata, &event);
6139 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6140 run_again(sdata, ifmgd->auth_data->timeout);
6142 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6143 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6144 if ((ifmgd->assoc_data->need_beacon &&
6145 !sdata->deflink.u.mgd.have_beacon) ||
6146 ieee80211_do_assoc(sdata)) {
6147 struct ieee80211_event event = {
6149 .u.mlme.data = ASSOC_EVENT,
6150 .u.mlme.status = MLME_TIMEOUT,
6153 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6154 drv_event_callback(sdata->local, sdata, &event);
6156 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6157 run_again(sdata, ifmgd->assoc_data->timeout);
6159 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6160 ifmgd->associated) {
6161 u8 *bssid = sdata->deflink.u.mgd.bssid;
6164 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6165 max_tries = max_nullfunc_tries;
6167 max_tries = max_probe_tries;
6169 /* ACK received for nullfunc probing frame */
6170 if (!ifmgd->probe_send_count)
6171 ieee80211_reset_ap_probe(sdata);
6172 else if (ifmgd->nullfunc_failed) {
6173 if (ifmgd->probe_send_count < max_tries) {
6175 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6176 bssid, ifmgd->probe_send_count,
6178 ieee80211_mgd_probe_ap_send(sdata);
6181 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6183 ieee80211_sta_connection_lost(sdata,
6184 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6187 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6188 run_again(sdata, ifmgd->probe_timeout);
6189 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6191 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6192 bssid, probe_wait_ms);
6193 ieee80211_sta_connection_lost(sdata,
6194 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6195 } else if (ifmgd->probe_send_count < max_tries) {
6197 "No probe response from AP %pM after %dms, try %d/%i\n",
6198 bssid, probe_wait_ms,
6199 ifmgd->probe_send_count, max_tries);
6200 ieee80211_mgd_probe_ap_send(sdata);
6203 * We actually lost the connection ... or did we?
6207 "No probe response from AP %pM after %dms, disconnecting.\n",
6208 bssid, probe_wait_ms);
6210 ieee80211_sta_connection_lost(sdata,
6211 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6215 sdata_unlock(sdata);
6218 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6220 struct ieee80211_sub_if_data *sdata =
6221 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6223 if (WARN_ON(sdata->vif.valid_links))
6226 if (sdata->vif.bss_conf.csa_active &&
6227 !sdata->deflink.u.mgd.csa_waiting_bcn)
6230 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6233 sdata->u.mgd.connection_loss = false;
6234 ieee80211_queue_work(&sdata->local->hw,
6235 &sdata->u.mgd.beacon_connection_loss_work);
6238 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6240 struct ieee80211_sub_if_data *sdata =
6241 from_timer(sdata, t, u.mgd.conn_mon_timer);
6242 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6243 struct ieee80211_local *local = sdata->local;
6244 struct sta_info *sta;
6245 unsigned long timeout;
6247 if (WARN_ON(sdata->vif.valid_links))
6250 if (sdata->vif.bss_conf.csa_active &&
6251 !sdata->deflink.u.mgd.csa_waiting_bcn)
6254 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6258 timeout = sta->deflink.status_stats.last_ack;
6259 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6260 timeout = sta->deflink.rx_stats.last_rx;
6261 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6263 /* If timeout is after now, then update timer to fire at
6264 * the later date, but do not actually probe at this time.
6266 if (time_is_after_jiffies(timeout)) {
6267 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6271 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
6274 static void ieee80211_sta_monitor_work(struct work_struct *work)
6276 struct ieee80211_sub_if_data *sdata =
6277 container_of(work, struct ieee80211_sub_if_data,
6278 u.mgd.monitor_work);
6280 ieee80211_mgd_probe_ap(sdata, false);
6283 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6285 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6286 __ieee80211_stop_poll(sdata);
6288 /* let's probe the connection once */
6289 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6290 ieee80211_queue_work(&sdata->local->hw,
6291 &sdata->u.mgd.monitor_work);
6296 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6298 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6299 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6303 if (ifmgd->auth_data || ifmgd->assoc_data) {
6304 const u8 *ap_addr = ifmgd->auth_data ?
6305 ifmgd->auth_data->ap_addr :
6306 ifmgd->assoc_data->ap_addr;
6309 * If we are trying to authenticate / associate while suspending,
6310 * cfg80211 won't know and won't actually abort those attempts,
6311 * thus we need to do that ourselves.
6313 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6314 IEEE80211_STYPE_DEAUTH,
6315 WLAN_REASON_DEAUTH_LEAVING,
6317 if (ifmgd->assoc_data)
6318 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6319 if (ifmgd->auth_data)
6320 ieee80211_destroy_auth_data(sdata, false);
6321 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6322 IEEE80211_DEAUTH_FRAME_LEN,
6326 /* This is a bit of a hack - we should find a better and more generic
6327 * solution to this. Normally when suspending, cfg80211 will in fact
6328 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6329 * auth (not so important) or assoc (this is the problem) process.
6331 * As a consequence, it can happen that we are in the process of both
6332 * associating and suspending, and receive an association response
6333 * after cfg80211 has checked if it needs to disconnect, but before
6334 * we actually set the flag to drop incoming frames. This will then
6335 * cause the workqueue flush to process the association response in
6336 * the suspend, resulting in a successful association just before it
6337 * tries to remove the interface from the driver, which now though
6338 * has a channel context assigned ... this results in issues.
6340 * To work around this (for now) simply deauth here again if we're
6343 if (ifmgd->associated && !sdata->local->wowlan) {
6345 struct cfg80211_deauth_request req = {
6346 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
6350 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
6351 ieee80211_mgd_deauth(sdata, &req);
6354 sdata_unlock(sdata);
6358 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
6360 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6363 if (!ifmgd->associated) {
6364 sdata_unlock(sdata);
6368 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
6369 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
6370 mlme_dbg(sdata, "driver requested disconnect after resume\n");
6371 ieee80211_sta_connection_lost(sdata,
6372 WLAN_REASON_UNSPECIFIED,
6374 sdata_unlock(sdata);
6378 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
6379 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
6380 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
6381 ieee80211_sta_connection_lost(sdata,
6382 WLAN_REASON_UNSPECIFIED,
6384 sdata_unlock(sdata);
6388 sdata_unlock(sdata);
6391 static void ieee80211_request_smps_mgd_work(struct work_struct *work)
6393 struct ieee80211_link_data *link =
6394 container_of(work, struct ieee80211_link_data,
6395 u.mgd.request_smps_work);
6397 sdata_lock(link->sdata);
6398 __ieee80211_request_smps_mgd(link->sdata, link,
6399 link->u.mgd.driver_smps_mode);
6400 sdata_unlock(link->sdata);
6403 /* interface setup */
6404 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
6406 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6408 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
6409 INIT_WORK(&ifmgd->beacon_connection_loss_work,
6410 ieee80211_beacon_connection_loss_work);
6411 INIT_WORK(&ifmgd->csa_connection_drop_work,
6412 ieee80211_csa_connection_drop_work);
6413 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
6414 ieee80211_tdls_peer_del_work);
6415 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
6416 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
6417 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
6418 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
6419 ieee80211_sta_handle_tspec_ac_params_wk);
6422 ifmgd->powersave = sdata->wdev.ps;
6423 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
6424 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
6425 /* Setup TDLS data */
6426 spin_lock_init(&ifmgd->teardown_lock);
6427 ifmgd->teardown_skb = NULL;
6428 ifmgd->orig_teardown_skb = NULL;
6431 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
6433 struct ieee80211_sub_if_data *sdata = link->sdata;
6434 struct ieee80211_local *local = sdata->local;
6435 unsigned int link_id = link->link_id;
6437 link->u.mgd.p2p_noa_index = -1;
6438 link->u.mgd.conn_flags = 0;
6439 link->conf->bssid = link->u.mgd.bssid;
6441 INIT_WORK(&link->u.mgd.request_smps_work,
6442 ieee80211_request_smps_mgd_work);
6443 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
6444 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
6446 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
6448 INIT_WORK(&link->u.mgd.chswitch_work, ieee80211_chswitch_work);
6449 timer_setup(&link->u.mgd.chswitch_timer, ieee80211_chswitch_timer, 0);
6451 if (sdata->u.mgd.assoc_data)
6452 ether_addr_copy(link->conf->addr,
6453 sdata->u.mgd.assoc_data->link[link_id].addr);
6454 else if (!is_valid_ether_addr(link->conf->addr))
6455 eth_random_addr(link->conf->addr);
6458 /* scan finished notification */
6459 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
6461 struct ieee80211_sub_if_data *sdata;
6463 /* Restart STA timers */
6465 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
6466 if (ieee80211_sdata_running(sdata))
6467 ieee80211_restart_sta_timer(sdata);
6472 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
6473 struct cfg80211_bss *cbss, s8 link_id,
6474 const u8 *ap_mld_addr, bool assoc,
6477 struct ieee80211_local *local = sdata->local;
6478 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6479 struct ieee80211_bss *bss = (void *)cbss->priv;
6480 struct sta_info *new_sta = NULL;
6481 struct ieee80211_link_data *link;
6482 bool have_sta = false;
6488 if (WARN_ON(!ap_mld_addr))
6490 err = ieee80211_vif_set_links(sdata, BIT(link_id));
6492 if (WARN_ON(ap_mld_addr))
6494 ap_mld_addr = cbss->bssid;
6495 err = ieee80211_vif_set_links(sdata, 0);
6503 link = sdata_dereference(sdata->link[link_id], sdata);
6504 if (WARN_ON(!link)) {
6509 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
6514 /* If a reconfig is happening, bail out */
6515 if (local->in_reconfig) {
6522 have_sta = sta_info_get(sdata, ap_mld_addr);
6528 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
6529 link_id, cbss->bssid,
6532 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
6539 new_sta->sta.mlo = mlo;
6543 * Set up the information for the new channel before setting the
6544 * new channel. We can't - completely race-free - change the basic
6545 * rates bitmap and the channel (sband) that it refers to, but if
6546 * we set it up before we at least avoid calling into the driver's
6547 * bss_info_changed() method with invalid information (since we do
6548 * call that from changing the channel - only for IDLE and perhaps
6549 * some others, but ...).
6551 * So to avoid that, just set up all the new information before the
6552 * channel, but tell the driver to apply it only afterwards, since
6553 * it might need the new channel for that.
6556 const struct cfg80211_bss_ies *ies;
6557 struct link_sta_info *link_sta;
6560 link_sta = rcu_dereference(new_sta->link[link_id]);
6561 if (WARN_ON(!link_sta)) {
6563 sta_info_free(local, new_sta);
6568 err = ieee80211_mgd_setup_link_sta(link, new_sta,
6572 sta_info_free(local, new_sta);
6576 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
6578 /* set timing information */
6579 link->conf->beacon_int = cbss->beacon_interval;
6580 ies = rcu_dereference(cbss->beacon_ies);
6582 link->conf->sync_tsf = ies->tsf;
6583 link->conf->sync_device_ts =
6584 bss->device_ts_beacon;
6586 ieee80211_get_dtim(ies,
6587 &link->conf->sync_dtim_count,
6589 } else if (!ieee80211_hw_check(&sdata->local->hw,
6590 TIMING_BEACON_ONLY)) {
6591 ies = rcu_dereference(cbss->proberesp_ies);
6592 /* must be non-NULL since beacon IEs were NULL */
6593 link->conf->sync_tsf = ies->tsf;
6594 link->conf->sync_device_ts =
6595 bss->device_ts_presp;
6596 link->conf->sync_dtim_count = 0;
6598 link->conf->sync_tsf = 0;
6599 link->conf->sync_device_ts = 0;
6600 link->conf->sync_dtim_count = 0;
6605 if (new_sta || override) {
6606 err = ieee80211_prep_channel(sdata, link, cbss,
6607 &link->u.mgd.conn_flags);
6610 sta_info_free(local, new_sta);
6617 * tell driver about BSSID, basic rates and timing
6618 * this was set up above, before setting the channel
6620 ieee80211_link_info_change_notify(sdata, link,
6622 BSS_CHANGED_BASIC_RATES |
6623 BSS_CHANGED_BEACON_INT);
6626 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
6628 err = sta_info_insert(new_sta);
6632 "failed to insert STA entry for the AP (error %d)\n",
6637 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
6639 /* Cancel scan to ensure that nothing interferes with connection */
6640 if (local->scanning)
6641 ieee80211_scan_cancel(local);
6646 ieee80211_link_release_channel(&sdata->deflink);
6647 ieee80211_vif_set_links(sdata, 0);
6652 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
6653 struct cfg80211_auth_request *req)
6655 struct ieee80211_local *local = sdata->local;
6656 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6657 struct ieee80211_mgd_auth_data *auth_data;
6662 /* prepare auth data structure */
6664 switch (req->auth_type) {
6665 case NL80211_AUTHTYPE_OPEN_SYSTEM:
6666 auth_alg = WLAN_AUTH_OPEN;
6668 case NL80211_AUTHTYPE_SHARED_KEY:
6671 auth_alg = WLAN_AUTH_SHARED_KEY;
6673 case NL80211_AUTHTYPE_FT:
6674 auth_alg = WLAN_AUTH_FT;
6676 case NL80211_AUTHTYPE_NETWORK_EAP:
6677 auth_alg = WLAN_AUTH_LEAP;
6679 case NL80211_AUTHTYPE_SAE:
6680 auth_alg = WLAN_AUTH_SAE;
6682 case NL80211_AUTHTYPE_FILS_SK:
6683 auth_alg = WLAN_AUTH_FILS_SK;
6685 case NL80211_AUTHTYPE_FILS_SK_PFS:
6686 auth_alg = WLAN_AUTH_FILS_SK_PFS;
6688 case NL80211_AUTHTYPE_FILS_PK:
6689 auth_alg = WLAN_AUTH_FILS_PK;
6695 if (ifmgd->assoc_data)
6698 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
6699 req->ie_len, GFP_KERNEL);
6703 memcpy(auth_data->ap_addr,
6704 req->ap_mld_addr ?: req->bss->bssid,
6706 auth_data->bss = req->bss;
6707 auth_data->link_id = req->link_id;
6709 if (req->auth_data_len >= 4) {
6710 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
6711 __le16 *pos = (__le16 *) req->auth_data;
6713 auth_data->sae_trans = le16_to_cpu(pos[0]);
6714 auth_data->sae_status = le16_to_cpu(pos[1]);
6716 memcpy(auth_data->data, req->auth_data + 4,
6717 req->auth_data_len - 4);
6718 auth_data->data_len += req->auth_data_len - 4;
6721 /* Check if continuing authentication or trying to authenticate with the
6722 * same BSS that we were in the process of authenticating with and avoid
6723 * removal and re-addition of the STA entry in
6724 * ieee80211_prep_connection().
6726 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
6727 ifmgd->auth_data->link_id == req->link_id;
6729 if (req->ie && req->ie_len) {
6730 memcpy(&auth_data->data[auth_data->data_len],
6731 req->ie, req->ie_len);
6732 auth_data->data_len += req->ie_len;
6735 if (req->key && req->key_len) {
6736 auth_data->key_len = req->key_len;
6737 auth_data->key_idx = req->key_idx;
6738 memcpy(auth_data->key, req->key, req->key_len);
6741 auth_data->algorithm = auth_alg;
6743 /* try to authenticate/probe */
6745 if (ifmgd->auth_data) {
6746 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
6747 auth_data->peer_confirmed =
6748 ifmgd->auth_data->peer_confirmed;
6750 ieee80211_destroy_auth_data(sdata, cont_auth);
6753 /* prep auth_data so we don't go into idle on disassoc */
6754 ifmgd->auth_data = auth_data;
6756 /* If this is continuation of an ongoing SAE authentication exchange
6757 * (i.e., request to send SAE Confirm) and the peer has already
6758 * confirmed, mark authentication completed since we are about to send
6761 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
6762 auth_data->peer_confirmed && auth_data->sae_trans == 2)
6763 ieee80211_mark_sta_auth(sdata);
6765 if (ifmgd->associated) {
6766 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6769 "disconnect from AP %pM for new auth to %pM\n",
6770 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
6771 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6772 WLAN_REASON_UNSPECIFIED,
6775 ieee80211_report_disconnect(sdata, frame_buf,
6776 sizeof(frame_buf), true,
6777 WLAN_REASON_UNSPECIFIED,
6781 sdata_info(sdata, "authenticate with %pM\n", auth_data->ap_addr);
6783 /* needed for transmitting the auth frame(s) properly */
6784 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
6786 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
6787 req->ap_mld_addr, cont_auth, false);
6791 err = ieee80211_auth(sdata);
6793 sta_info_destroy_addr(sdata, auth_data->ap_addr);
6797 /* hold our own reference */
6798 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
6802 if (!sdata->vif.valid_links) {
6803 eth_zero_addr(sdata->deflink.u.mgd.bssid);
6804 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6806 mutex_lock(&sdata->local->mtx);
6807 ieee80211_link_release_channel(&sdata->deflink);
6808 mutex_unlock(&sdata->local->mtx);
6810 ifmgd->auth_data = NULL;
6815 static ieee80211_conn_flags_t
6816 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
6817 struct ieee80211_mgd_assoc_data *assoc_data,
6818 struct cfg80211_assoc_request *req,
6819 ieee80211_conn_flags_t conn_flags,
6820 unsigned int link_id)
6822 struct ieee80211_local *local = sdata->local;
6823 const struct cfg80211_bss_ies *beacon_ies;
6824 struct ieee80211_supported_band *sband;
6825 const struct element *ht_elem, *vht_elem;
6826 struct ieee80211_link_data *link;
6827 struct cfg80211_bss *cbss;
6828 struct ieee80211_bss *bss;
6829 bool is_5ghz, is_6ghz;
6831 cbss = assoc_data->link[link_id].bss;
6835 bss = (void *)cbss->priv;
6837 sband = local->hw.wiphy->bands[cbss->channel->band];
6838 if (WARN_ON(!sband))
6841 link = sdata_dereference(sdata->link[link_id], sdata);
6845 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
6846 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
6848 /* for MLO connections assume advertising all rates is OK */
6849 if (!req->ap_mld_addr) {
6850 assoc_data->supp_rates = bss->supp_rates;
6851 assoc_data->supp_rates_len = bss->supp_rates_len;
6854 /* copy and link elems for the STA profile */
6855 if (req->links[link_id].elems_len) {
6856 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
6857 req->links[link_id].elems_len);
6858 assoc_data->link[link_id].elems = assoc_data->ie_pos;
6859 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
6860 assoc_data->ie_pos += req->links[link_id].elems_len;
6864 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
6865 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
6866 assoc_data->link[link_id].ap_ht_param =
6867 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
6869 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6870 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
6871 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
6872 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
6873 sizeof(struct ieee80211_vht_cap));
6874 } else if (is_5ghz) {
6876 "VHT capa missing/short, disabling VHT/HE/EHT\n");
6877 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
6878 IEEE80211_CONN_DISABLE_HE |
6879 IEEE80211_CONN_DISABLE_EHT;
6883 link->u.mgd.beacon_crc_valid = false;
6884 link->u.mgd.dtim_period = 0;
6885 link->u.mgd.have_beacon = false;
6887 /* override HT/VHT configuration only if the AP and we support it */
6888 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
6889 struct ieee80211_sta_ht_cap sta_ht_cap;
6891 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
6892 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
6896 beacon_ies = rcu_dereference(cbss->beacon_ies);
6898 const struct element *elem;
6901 ieee80211_get_dtim(beacon_ies, &dtim_count,
6902 &link->u.mgd.dtim_period);
6904 sdata->deflink.u.mgd.have_beacon = true;
6906 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6907 link->conf->sync_tsf = beacon_ies->tsf;
6908 link->conf->sync_device_ts = bss->device_ts_beacon;
6909 link->conf->sync_dtim_count = dtim_count;
6912 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
6913 beacon_ies->data, beacon_ies->len);
6914 if (elem && elem->datalen >= 3)
6915 link->conf->profile_periodicity = elem->data[2];
6917 link->conf->profile_periodicity = 0;
6919 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
6920 beacon_ies->data, beacon_ies->len);
6921 if (elem && elem->datalen >= 11 &&
6922 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6923 link->conf->ema_ap = true;
6925 link->conf->ema_ap = false;
6929 if (bss->corrupt_data) {
6930 char *corrupt_type = "data";
6932 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
6933 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
6934 corrupt_type = "beacon and probe response";
6936 corrupt_type = "beacon";
6937 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
6938 corrupt_type = "probe response";
6940 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
6941 cbss->bssid, corrupt_type);
6944 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
6945 if (sdata->u.mgd.powersave)
6946 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
6948 link->smps_mode = IEEE80211_SMPS_OFF;
6950 link->smps_mode = link->u.mgd.req_smps;
6956 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
6957 struct cfg80211_assoc_request *req)
6959 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
6960 struct ieee80211_local *local = sdata->local;
6961 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6962 struct ieee80211_mgd_assoc_data *assoc_data;
6963 const struct element *ssid_elem;
6964 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6965 ieee80211_conn_flags_t conn_flags = 0;
6966 struct ieee80211_link_data *link;
6967 struct cfg80211_bss *cbss;
6968 struct ieee80211_bss *bss;
6971 size_t size = sizeof(*assoc_data) + req->ie_len;
6973 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
6974 size += req->links[i].elems_len;
6976 /* FIXME: no support for 4-addr MLO yet */
6977 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
6980 assoc_data = kzalloc(size, GFP_KERNEL);
6984 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
6987 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
6988 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
6993 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
6994 assoc_data->ssid_len = ssid_elem->datalen;
6995 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
6996 vif_cfg->ssid_len = assoc_data->ssid_len;
6999 if (req->ap_mld_addr) {
7000 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7001 if (!req->links[i].bss)
7003 link = sdata_dereference(sdata->link[i], sdata);
7005 ether_addr_copy(assoc_data->link[i].addr,
7008 eth_random_addr(assoc_data->link[i].addr);
7011 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7014 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7016 memcpy(assoc_data->ap_addr,
7017 req->ap_mld_addr ?: req->bss->bssid,
7020 if (ifmgd->associated) {
7021 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7024 "disconnect from AP %pM for new assoc to %pM\n",
7025 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7026 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7027 WLAN_REASON_UNSPECIFIED,
7030 ieee80211_report_disconnect(sdata, frame_buf,
7031 sizeof(frame_buf), true,
7032 WLAN_REASON_UNSPECIFIED,
7036 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7041 if (ifmgd->assoc_data) {
7046 if (ifmgd->auth_data) {
7049 /* keep sta info, bssid if matching */
7050 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7051 assoc_data->ap_addr) &&
7052 ifmgd->auth_data->link_id == req->link_id;
7053 ieee80211_destroy_auth_data(sdata, match);
7056 /* prepare assoc data */
7058 bss = (void *)cbss->priv;
7059 assoc_data->wmm = bss->wmm_used &&
7060 (local->hw.queues >= IEEE80211_NUM_ACS);
7063 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7064 * We still associate in non-HT mode (11a/b/g) if any one of these
7065 * ciphers is configured as pairwise.
7066 * We can set this to true for non-11n hardware, that'll be checked
7067 * separately along with the peer capabilities.
7069 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7070 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7071 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7072 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7073 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7074 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7075 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7076 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7077 netdev_info(sdata->dev,
7078 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7082 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7083 if (!bss->wmm_used) {
7084 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7085 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7086 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7087 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7088 netdev_info(sdata->dev,
7089 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7092 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7093 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7094 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7095 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7096 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7097 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7100 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7101 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7102 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7105 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7106 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7107 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7108 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7111 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7112 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7114 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7115 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7116 sizeof(ifmgd->ht_capa_mask));
7118 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7119 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7120 sizeof(ifmgd->vht_capa_mask));
7122 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7123 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7124 sizeof(ifmgd->s1g_capa_mask));
7126 if (req->ie && req->ie_len) {
7127 memcpy(assoc_data->ie, req->ie, req->ie_len);
7128 assoc_data->ie_len = req->ie_len;
7129 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7131 assoc_data->ie_pos = assoc_data->ie;
7134 if (req->fils_kek) {
7135 /* should already be checked in cfg80211 - so warn */
7136 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7140 memcpy(assoc_data->fils_kek, req->fils_kek,
7142 assoc_data->fils_kek_len = req->fils_kek_len;
7145 if (req->fils_nonces)
7146 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7147 2 * FILS_NONCE_LEN);
7149 /* default timeout */
7150 assoc_data->timeout = jiffies;
7151 assoc_data->timeout_started = true;
7153 assoc_data->assoc_link_id = assoc_link_id;
7155 if (req->ap_mld_addr) {
7156 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7157 assoc_data->link[i].conn_flags = conn_flags;
7158 assoc_data->link[i].bss = req->links[i].bss;
7161 /* if there was no authentication, set up the link */
7162 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id));
7166 assoc_data->link[0].conn_flags = conn_flags;
7167 assoc_data->link[0].bss = cbss;
7170 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7171 if (WARN_ON(!link)) {
7176 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7177 conn_flags |= link->u.mgd.conn_flags;
7178 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7179 conn_flags, assoc_link_id);
7180 override = link->u.mgd.conn_flags != conn_flags;
7181 link->u.mgd.conn_flags |= conn_flags;
7183 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7184 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7185 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7186 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7188 if (bss->wmm_used && bss->uapsd_supported &&
7189 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7190 assoc_data->uapsd = true;
7191 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7193 assoc_data->uapsd = false;
7194 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7197 if (req->prev_bssid)
7198 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7201 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7202 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7204 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7205 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7208 if (req->flags & ASSOC_REQ_USE_RRM)
7209 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7211 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7213 if (req->crypto.control_port)
7214 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7216 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7218 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7219 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7220 sdata->control_port_over_nl80211 =
7221 req->crypto.control_port_over_nl80211;
7222 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7224 /* kick off associate process */
7225 ifmgd->assoc_data = assoc_data;
7227 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7228 if (!assoc_data->link[i].bss)
7230 if (i == assoc_data->assoc_link_id)
7232 /* only calculate the flags, hence link == NULL */
7233 err = ieee80211_prep_channel(sdata, NULL, assoc_data->link[i].bss,
7234 &assoc_data->link[i].conn_flags);
7239 /* needed for transmitting the assoc frames properly */
7240 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
7242 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7243 req->ap_mld_addr, true, override);
7247 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7248 link->u.mgd.conn_flags;
7250 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7251 const struct cfg80211_bss_ies *beacon_ies;
7254 beacon_ies = rcu_dereference(req->bss->beacon_ies);
7258 * Wait up to one beacon interval ...
7259 * should this be more if we miss one?
7261 sdata_info(sdata, "waiting for beacon from %pM\n",
7263 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
7264 assoc_data->timeout_started = true;
7265 assoc_data->need_beacon = true;
7270 run_again(sdata, assoc_data->timeout);
7274 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7275 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7277 ifmgd->assoc_data = NULL;
7283 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
7284 struct cfg80211_deauth_request *req)
7286 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7287 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7288 bool tx = !req->local_state_change;
7289 struct ieee80211_prep_tx_info info = {
7290 .subtype = IEEE80211_STYPE_DEAUTH,
7293 if (ifmgd->auth_data &&
7294 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
7296 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
7297 req->bssid, req->reason_code,
7298 ieee80211_get_reason_code_string(req->reason_code));
7300 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7301 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7302 IEEE80211_STYPE_DEAUTH,
7303 req->reason_code, tx,
7305 ieee80211_destroy_auth_data(sdata, false);
7306 ieee80211_report_disconnect(sdata, frame_buf,
7307 sizeof(frame_buf), true,
7308 req->reason_code, false);
7309 drv_mgd_complete_tx(sdata->local, sdata, &info);
7313 if (ifmgd->assoc_data &&
7314 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
7316 "aborting association with %pM by local choice (Reason: %u=%s)\n",
7317 req->bssid, req->reason_code,
7318 ieee80211_get_reason_code_string(req->reason_code));
7320 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7321 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7322 IEEE80211_STYPE_DEAUTH,
7323 req->reason_code, tx,
7325 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
7326 ieee80211_report_disconnect(sdata, frame_buf,
7327 sizeof(frame_buf), true,
7328 req->reason_code, false);
7332 if (ifmgd->associated &&
7333 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
7335 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
7336 req->bssid, req->reason_code,
7337 ieee80211_get_reason_code_string(req->reason_code));
7339 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7340 req->reason_code, tx, frame_buf);
7341 ieee80211_report_disconnect(sdata, frame_buf,
7342 sizeof(frame_buf), true,
7343 req->reason_code, false);
7344 drv_mgd_complete_tx(sdata->local, sdata, &info);
7351 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
7352 struct cfg80211_disassoc_request *req)
7354 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7356 if (!sdata->u.mgd.associated ||
7357 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
7361 "disassociating from %pM by local choice (Reason: %u=%s)\n",
7362 req->ap_addr, req->reason_code,
7363 ieee80211_get_reason_code_string(req->reason_code));
7365 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
7366 req->reason_code, !req->local_state_change,
7369 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
7370 req->reason_code, false);
7375 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
7377 cancel_work_sync(&link->u.mgd.request_smps_work);
7378 cancel_work_sync(&link->u.mgd.chswitch_work);
7381 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
7383 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7386 * Make sure some work items will not run after this,
7387 * they will not do anything but might not have been
7388 * cancelled when disconnecting.
7390 cancel_work_sync(&ifmgd->monitor_work);
7391 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
7392 cancel_work_sync(&ifmgd->csa_connection_drop_work);
7393 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
7396 if (ifmgd->assoc_data)
7397 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
7398 if (ifmgd->auth_data)
7399 ieee80211_destroy_auth_data(sdata, false);
7400 spin_lock_bh(&ifmgd->teardown_lock);
7401 if (ifmgd->teardown_skb) {
7402 kfree_skb(ifmgd->teardown_skb);
7403 ifmgd->teardown_skb = NULL;
7404 ifmgd->orig_teardown_skb = NULL;
7406 kfree(ifmgd->assoc_req_ies);
7407 ifmgd->assoc_req_ies = NULL;
7408 ifmgd->assoc_req_ies_len = 0;
7409 spin_unlock_bh(&ifmgd->teardown_lock);
7410 del_timer_sync(&ifmgd->timer);
7411 sdata_unlock(sdata);
7414 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
7415 enum nl80211_cqm_rssi_threshold_event rssi_event,
7419 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7421 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
7423 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
7425 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
7427 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
7429 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7431 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
7433 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
7435 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
7437 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
7441 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
7443 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
7447 * Scale up threshold values before storing it, as the RSSI averaging
7448 * algorithm uses a scaled up value as well. Change this scaling
7449 * factor if the RSSI averaging algorithm changes.
7451 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
7452 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
7455 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
7459 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7461 WARN_ON(rssi_min_thold == rssi_max_thold ||
7462 rssi_min_thold > rssi_max_thold);
7464 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
7467 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
7469 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
7471 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7473 _ieee80211_enable_rssi_reports(sdata, 0, 0);
7475 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);