1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2023 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 * Extract from the given disabled subchannel bitmap (raw format
93 * from the EHT Operation Element) the bits for the subchannel
94 * we're using right now.
97 ieee80211_extract_dis_subch_bmap(const struct ieee80211_eht_operation *eht_oper,
98 struct cfg80211_chan_def *chandef, u16 bitmap)
100 struct ieee80211_eht_operation_info *info = (void *)eht_oper->optional;
101 struct cfg80211_chan_def ap_chandef = *chandef;
102 u32 ap_center_freq, local_center_freq;
104 int ap_start_freq, local_start_freq;
107 if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) ||
109 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
112 /* set 160/320 supported to get the full AP definition */
113 ieee80211_chandef_eht_oper(eht_oper, true, true, &ap_chandef);
114 ap_center_freq = ap_chandef.center_freq1;
115 ap_bw = 20 * BIT(u8_get_bits(info->control,
116 IEEE80211_EHT_OPER_CHAN_WIDTH));
117 ap_start_freq = ap_center_freq - ap_bw / 2;
118 local_center_freq = chandef->center_freq1;
119 local_bw = 20 * BIT(ieee80211_chan_width_to_rx_bw(chandef->width));
120 local_start_freq = local_center_freq - local_bw / 2;
121 shift = (local_start_freq - ap_start_freq) / 20;
122 mask = BIT(local_bw / 20) - 1;
124 return (bitmap >> shift) & mask;
128 * Handle the puncturing bitmap, possibly downgrading bandwidth to get a
132 ieee80211_handle_puncturing_bitmap(struct ieee80211_link_data *link,
133 const struct ieee80211_eht_operation *eht_oper,
134 u16 bitmap, u64 *changed)
136 struct cfg80211_chan_def *chandef = &link->conf->chandef;
143 while (chandef->width > NL80211_CHAN_WIDTH_40) {
145 ieee80211_extract_dis_subch_bmap(eht_oper, chandef,
148 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
151 link->u.mgd.conn_flags |=
152 ieee80211_chandef_downgrade(chandef);
153 *changed |= BSS_CHANGED_BANDWIDTH;
156 if (chandef->width <= NL80211_CHAN_WIDTH_40)
159 if (link->conf->eht_puncturing != extracted) {
160 link->conf->eht_puncturing = extracted;
161 *changed |= BSS_CHANGED_EHT_PUNCTURING;
166 * We can have multiple work items (and connection probing)
167 * scheduling this timer, but we need to take care to only
168 * reschedule it when it should fire _earlier_ than it was
169 * asked for before, or if it's not pending right now. This
170 * function ensures that. Note that it then is required to
171 * run this function for all timeouts after the first one
172 * has happened -- the work that runs from this timer will
175 static void run_again(struct ieee80211_sub_if_data *sdata,
176 unsigned long timeout)
178 sdata_assert_lock(sdata);
180 if (!timer_pending(&sdata->u.mgd.timer) ||
181 time_before(timeout, sdata->u.mgd.timer.expires))
182 mod_timer(&sdata->u.mgd.timer, timeout);
185 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
187 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
190 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
193 mod_timer(&sdata->u.mgd.bcn_mon_timer,
194 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
197 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
199 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
201 if (unlikely(!ifmgd->associated))
204 if (ifmgd->probe_send_count)
205 ifmgd->probe_send_count = 0;
207 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
210 mod_timer(&ifmgd->conn_mon_timer,
211 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
214 static int ecw2cw(int ecw)
216 return (1 << ecw) - 1;
219 static ieee80211_conn_flags_t
220 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
221 struct ieee80211_link_data *link,
222 ieee80211_conn_flags_t conn_flags,
223 struct ieee80211_supported_band *sband,
224 struct ieee80211_channel *channel,
226 const struct ieee80211_ht_operation *ht_oper,
227 const struct ieee80211_vht_operation *vht_oper,
228 const struct ieee80211_he_operation *he_oper,
229 const struct ieee80211_eht_operation *eht_oper,
230 const struct ieee80211_s1g_oper_ie *s1g_oper,
231 struct cfg80211_chan_def *chandef, bool tracking)
233 struct cfg80211_chan_def vht_chandef;
234 struct ieee80211_sta_ht_cap sta_ht_cap;
235 ieee80211_conn_flags_t ret;
238 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
239 chandef->chan = channel;
240 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
241 chandef->center_freq1 = channel->center_freq;
242 chandef->freq1_offset = channel->freq_offset;
244 if (channel->band == NL80211_BAND_6GHZ) {
245 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
248 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
249 ret = IEEE80211_CONN_DISABLE_HT |
250 IEEE80211_CONN_DISABLE_VHT |
251 IEEE80211_CONN_DISABLE_HE |
252 IEEE80211_CONN_DISABLE_EHT;
256 vht_chandef = *chandef;
258 } else if (sband->band == NL80211_BAND_S1GHZ) {
259 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
261 "Missing S1G Operation Element? Trying operating == primary\n");
262 chandef->width = ieee80211_s1g_channel_width(channel);
265 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
266 IEEE80211_CONN_DISABLE_VHT |
267 IEEE80211_CONN_DISABLE_80P80MHZ |
268 IEEE80211_CONN_DISABLE_160MHZ;
272 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
273 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
275 if (!ht_oper || !sta_ht_cap.ht_supported) {
276 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
277 ret = IEEE80211_CONN_DISABLE_HT |
278 IEEE80211_CONN_DISABLE_VHT |
279 IEEE80211_CONN_DISABLE_HE |
280 IEEE80211_CONN_DISABLE_EHT;
284 chandef->width = NL80211_CHAN_WIDTH_20;
286 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
288 /* check that channel matches the right operating channel */
289 if (!tracking && channel->center_freq != ht_cfreq) {
291 * It's possible that some APs are confused here;
292 * Netgear WNDR3700 sometimes reports 4 higher than
293 * the actual channel in association responses, but
294 * since we look at probe response/beacon data here
298 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
299 channel->center_freq, ht_cfreq,
300 ht_oper->primary_chan, channel->band);
301 ret = IEEE80211_CONN_DISABLE_HT |
302 IEEE80211_CONN_DISABLE_VHT |
303 IEEE80211_CONN_DISABLE_HE |
304 IEEE80211_CONN_DISABLE_EHT;
308 /* check 40 MHz support, if we have it */
309 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
310 ieee80211_chandef_ht_oper(ht_oper, chandef);
312 mlme_dbg(sdata, "40 MHz not supported\n");
313 /* 40 MHz (and 80 MHz) must be supported for VHT */
314 ret = IEEE80211_CONN_DISABLE_VHT;
315 /* also mark 40 MHz disabled */
316 ret |= IEEE80211_CONN_DISABLE_40MHZ;
320 if (!vht_oper || !sband->vht_cap.vht_supported) {
321 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
322 ret = IEEE80211_CONN_DISABLE_VHT;
326 vht_chandef = *chandef;
327 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
329 (le32_to_cpu(he_oper->he_oper_params) &
330 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
331 struct ieee80211_vht_operation he_oper_vht_cap;
334 * Set only first 3 bytes (other 2 aren't used in
335 * ieee80211_chandef_vht_oper() anyway)
337 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
338 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
340 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
341 &he_oper_vht_cap, ht_oper,
343 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
345 "HE AP VHT information is invalid, disabling HE\n");
346 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
349 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
353 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
355 "AP VHT information is invalid, disabling VHT\n");
356 ret = IEEE80211_CONN_DISABLE_VHT;
360 if (!cfg80211_chandef_valid(&vht_chandef)) {
361 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
363 "AP VHT information is invalid, disabling VHT\n");
364 ret = IEEE80211_CONN_DISABLE_VHT;
368 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
373 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
374 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
376 "AP VHT information doesn't match HT, disabling VHT\n");
377 ret = IEEE80211_CONN_DISABLE_VHT;
381 *chandef = vht_chandef;
384 * handle the case that the EHT operation indicates that it holds EHT
385 * operation information (in case that the channel width differs from
386 * the channel width reported in HT/VHT/HE).
388 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
389 struct cfg80211_chan_def eht_chandef = *chandef;
391 ieee80211_chandef_eht_oper(eht_oper,
393 NL80211_CHAN_WIDTH_160,
394 false, &eht_chandef);
396 if (!cfg80211_chandef_valid(&eht_chandef)) {
397 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
399 "AP EHT information is invalid, disabling EHT\n");
400 ret = IEEE80211_CONN_DISABLE_EHT;
404 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
405 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
407 "AP EHT information is incompatible, disabling EHT\n");
408 ret = IEEE80211_CONN_DISABLE_EHT;
412 *chandef = eht_chandef;
419 * When tracking the current AP, don't do any further checks if the
420 * new chandef is identical to the one we're currently using for the
421 * connection. This keeps us from playing ping-pong with regulatory,
422 * without it the following can happen (for example):
423 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
424 * - AP advertises regdom US
425 * - CRDA loads regdom US with 80 MHz prohibited (old database)
426 * - the code below detects an unsupported channel, downgrades, and
427 * we disconnect from the AP in the caller
428 * - disconnect causes CRDA to reload world regdomain and the game
430 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
432 * It seems possible that there are still scenarios with CSA or real
433 * bandwidth changes where a this could happen, but those cases are
434 * less common and wouldn't completely prevent using the AP.
437 cfg80211_chandef_identical(chandef, &link->conf->chandef))
440 /* don't print the message below for VHT mismatch if VHT is disabled */
441 if (ret & IEEE80211_CONN_DISABLE_VHT)
442 vht_chandef = *chandef;
445 * Ignore the DISABLED flag when we're already connected and only
446 * tracking the APs beacon for bandwidth changes - otherwise we
447 * might get disconnected here if we connect to an AP, update our
448 * regulatory information based on the AP's country IE and the
449 * information we have is wrong/outdated and disables the channel
450 * that we're actually using for the connection to the AP.
452 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
454 IEEE80211_CHAN_DISABLED)) {
455 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
456 ret = IEEE80211_CONN_DISABLE_HT |
457 IEEE80211_CONN_DISABLE_VHT |
458 IEEE80211_CONN_DISABLE_HE |
459 IEEE80211_CONN_DISABLE_EHT;
463 ret |= ieee80211_chandef_downgrade(chandef);
466 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
467 IEEE80211_CHAN_NO_HE))
468 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
470 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
471 IEEE80211_CHAN_NO_EHT))
472 ret |= IEEE80211_CONN_DISABLE_EHT;
474 if (chandef->width != vht_chandef.width && !tracking)
476 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
478 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
482 static int ieee80211_config_bw(struct ieee80211_link_data *link,
483 const struct ieee80211_ht_cap *ht_cap,
484 const struct ieee80211_vht_cap *vht_cap,
485 const struct ieee80211_ht_operation *ht_oper,
486 const struct ieee80211_vht_operation *vht_oper,
487 const struct ieee80211_he_operation *he_oper,
488 const struct ieee80211_eht_operation *eht_oper,
489 const struct ieee80211_s1g_oper_ie *s1g_oper,
490 const u8 *bssid, u64 *changed)
492 struct ieee80211_sub_if_data *sdata = link->sdata;
493 struct ieee80211_local *local = sdata->local;
494 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
495 struct ieee80211_channel *chan = link->conf->chandef.chan;
496 struct ieee80211_supported_band *sband =
497 local->hw.wiphy->bands[chan->band];
498 struct cfg80211_chan_def chandef;
500 ieee80211_conn_flags_t flags;
501 u32 vht_cap_info = 0;
504 /* if HT was/is disabled, don't track any bandwidth changes */
505 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
508 /* don't check VHT if we associated as non-VHT station */
509 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
512 /* don't check HE if we associated as non-HE station */
513 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
514 !ieee80211_get_he_iftype_cap(sband,
515 ieee80211_vif_type_p2p(&sdata->vif))) {
520 /* don't check EHT if we associated as non-EHT station */
521 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
522 !ieee80211_get_eht_iftype_cap(sband,
523 ieee80211_vif_type_p2p(&sdata->vif)))
527 * if bss configuration changed store the new one -
528 * this may be applicable even if channel is identical
530 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
531 if (link->conf->ht_operation_mode != ht_opmode) {
532 *changed |= BSS_CHANGED_HT;
533 link->conf->ht_operation_mode = ht_opmode;
537 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
539 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
540 flags = ieee80211_determine_chantype(sdata, link,
541 link->u.mgd.conn_flags,
542 sband, chan, vht_cap_info,
545 s1g_oper, &chandef, true);
548 * Downgrade the new channel if we associated with restricted
549 * capabilities. For example, if we associated as a 20 MHz STA
550 * to a 40 MHz AP (due to regulatory, capabilities or config
551 * reasons) then switching to a 40 MHz channel now won't do us
552 * any good -- we couldn't use it with the AP.
554 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
555 chandef.width == NL80211_CHAN_WIDTH_80P80)
556 flags |= ieee80211_chandef_downgrade(&chandef);
557 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
558 chandef.width == NL80211_CHAN_WIDTH_160)
559 flags |= ieee80211_chandef_downgrade(&chandef);
560 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
561 chandef.width > NL80211_CHAN_WIDTH_20)
562 flags |= ieee80211_chandef_downgrade(&chandef);
564 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
568 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
569 link->u.mgd.bssid, chandef.chan->center_freq,
570 chandef.chan->freq_offset, chandef.width,
571 chandef.center_freq1, chandef.freq1_offset,
572 chandef.center_freq2);
574 if (flags != (link->u.mgd.conn_flags &
575 (IEEE80211_CONN_DISABLE_HT |
576 IEEE80211_CONN_DISABLE_VHT |
577 IEEE80211_CONN_DISABLE_HE |
578 IEEE80211_CONN_DISABLE_EHT |
579 IEEE80211_CONN_DISABLE_40MHZ |
580 IEEE80211_CONN_DISABLE_80P80MHZ |
581 IEEE80211_CONN_DISABLE_160MHZ |
582 IEEE80211_CONN_DISABLE_320MHZ)) ||
583 !cfg80211_chandef_valid(&chandef)) {
585 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
586 link->u.mgd.bssid, flags, ifmgd->flags);
590 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
594 "AP %pM changed bandwidth to incompatible one - disconnect\n",
602 /* frame sending functions */
604 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
605 struct sk_buff *skb, u8 ap_ht_param,
606 struct ieee80211_supported_band *sband,
607 struct ieee80211_channel *channel,
608 enum ieee80211_smps_mode smps,
609 ieee80211_conn_flags_t conn_flags)
612 u32 flags = channel->flags;
614 struct ieee80211_sta_ht_cap ht_cap;
616 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
618 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
619 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
621 /* determine capability flags */
624 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
625 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
626 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
627 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
628 cap &= ~IEEE80211_HT_CAP_SGI_40;
631 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
632 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
633 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
634 cap &= ~IEEE80211_HT_CAP_SGI_40;
640 * If 40 MHz was disabled associate as though we weren't
641 * capable of 40 MHz -- some broken APs will never fall
642 * back to trying to transmit in 20 MHz.
644 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
645 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
646 cap &= ~IEEE80211_HT_CAP_SGI_40;
649 /* set SM PS mode properly */
650 cap &= ~IEEE80211_HT_CAP_SM_PS;
652 case IEEE80211_SMPS_AUTOMATIC:
653 case IEEE80211_SMPS_NUM_MODES:
656 case IEEE80211_SMPS_OFF:
657 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
658 IEEE80211_HT_CAP_SM_PS_SHIFT;
660 case IEEE80211_SMPS_STATIC:
661 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
662 IEEE80211_HT_CAP_SM_PS_SHIFT;
664 case IEEE80211_SMPS_DYNAMIC:
665 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
666 IEEE80211_HT_CAP_SM_PS_SHIFT;
670 /* reserve and fill IE */
671 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
672 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
675 /* This function determines vht capability flags for the association
677 * Note - the function returns true to own the MU-MIMO capability
679 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
681 struct ieee80211_supported_band *sband,
682 struct ieee80211_vht_cap *ap_vht_cap,
683 ieee80211_conn_flags_t conn_flags)
685 struct ieee80211_local *local = sdata->local;
688 struct ieee80211_sta_vht_cap vht_cap;
689 u32 mask, ap_bf_sts, our_bf_sts;
690 bool mu_mimo_owner = false;
692 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
694 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
695 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
697 /* determine capability flags */
700 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
701 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
703 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
704 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
705 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
706 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
709 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
710 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
711 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
715 * Some APs apparently get confused if our capabilities are better
716 * than theirs, so restrict what we advertise in the assoc request.
718 if (!(ap_vht_cap->vht_cap_info &
719 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
720 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
721 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
722 else if (!(ap_vht_cap->vht_cap_info &
723 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
724 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
727 * If some other vif is using the MU-MIMO capability we cannot associate
728 * using MU-MIMO - this will lead to contradictions in the group-id
730 * Ownership is defined since association request, in order to avoid
731 * simultaneous associations with MU-MIMO.
733 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
734 bool disable_mu_mimo = false;
735 struct ieee80211_sub_if_data *other;
737 list_for_each_entry_rcu(other, &local->interfaces, list) {
738 if (other->vif.bss_conf.mu_mimo_owner) {
739 disable_mu_mimo = true;
744 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
746 mu_mimo_owner = true;
749 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
751 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
752 our_bf_sts = cap & mask;
754 if (ap_bf_sts < our_bf_sts) {
759 /* reserve and fill IE */
760 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
761 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
763 return mu_mimo_owner;
766 /* This function determines HE capability flags for the association
769 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
771 struct ieee80211_supported_band *sband,
772 enum ieee80211_smps_mode smps_mode,
773 ieee80211_conn_flags_t conn_flags)
775 u8 *pos, *pre_he_pos;
776 const struct ieee80211_sta_he_cap *he_cap;
779 he_cap = ieee80211_get_he_iftype_cap(sband,
780 ieee80211_vif_type_p2p(&sdata->vif));
781 if (WARN_ON(!he_cap))
784 /* get a max size estimate */
786 2 + 1 + sizeof(he_cap->he_cap_elem) +
787 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
788 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
789 he_cap->he_cap_elem.phy_cap_info);
790 pos = skb_put(skb, he_cap_size);
792 pos = ieee80211_ie_build_he_cap(conn_flags,
793 pos, he_cap, pos + he_cap_size);
794 /* trim excess if any */
795 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
797 ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
800 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
802 struct ieee80211_supported_band *sband)
805 const struct ieee80211_sta_he_cap *he_cap;
806 const struct ieee80211_sta_eht_cap *eht_cap;
809 he_cap = ieee80211_get_he_iftype_cap(sband,
810 ieee80211_vif_type_p2p(&sdata->vif));
811 eht_cap = ieee80211_get_eht_iftype_cap(sband,
812 ieee80211_vif_type_p2p(&sdata->vif));
815 * EHT capabilities element is only added if the HE capabilities element
816 * was added so assume that 'he_cap' is valid and don't check it.
818 if (WARN_ON(!he_cap || !eht_cap))
822 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
823 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
824 &eht_cap->eht_cap_elem,
826 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
827 eht_cap->eht_cap_elem.phy_cap_info);
828 pos = skb_put(skb, eht_cap_size);
829 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
833 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
834 enum nl80211_chan_width width,
835 struct ieee80211_supported_band *sband,
836 struct ieee80211_mgd_assoc_data *assoc_data)
838 unsigned int shift = ieee80211_chanwidth_get_shift(width);
839 unsigned int rates_len, supp_rates_len;
844 if (assoc_data->supp_rates_len) {
846 * Get all rates supported by the device and the AP as
847 * some APs don't like getting a superset of their rates
848 * in the association request (e.g. D-Link DAP 1353 in
851 rates_len = ieee80211_parse_bitrates(width, sband,
852 assoc_data->supp_rates,
853 assoc_data->supp_rates_len,
857 * In case AP not provide any supported rates information
858 * before association, we send information element(s) with
859 * all rates that we support.
861 rates_len = sband->n_bitrates;
862 for (i = 0; i < sband->n_bitrates; i++)
866 supp_rates_len = rates_len;
867 if (supp_rates_len > 8)
870 pos = skb_put(skb, supp_rates_len + 2);
871 *pos++ = WLAN_EID_SUPP_RATES;
872 *pos++ = supp_rates_len;
875 for (i = 0; i < sband->n_bitrates; i++) {
876 if (BIT(i) & rates) {
877 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
885 if (rates_len > count) {
886 pos = skb_put(skb, rates_len - count + 2);
887 *pos++ = WLAN_EID_EXT_SUPP_RATES;
888 *pos++ = rates_len - count;
890 for (i++; i < sband->n_bitrates; i++) {
891 if (BIT(i) & rates) {
894 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
902 static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
909 static const u8 before_ht[] = {
912 WLAN_EID_EXT_SUPP_RATES,
913 WLAN_EID_PWR_CAPABILITY,
914 WLAN_EID_SUPPORTED_CHANNELS,
917 WLAN_EID_RRM_ENABLED_CAPABILITIES,
918 WLAN_EID_MOBILITY_DOMAIN,
919 WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
920 WLAN_EID_RIC_DATA, /* reassoc only */
921 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
923 static const u8 after_ric[] = {
924 WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
925 WLAN_EID_HT_CAPABILITY,
926 WLAN_EID_BSS_COEX_2040,
927 /* luckily this is almost always there */
928 WLAN_EID_EXT_CAPABILITY,
929 WLAN_EID_QOS_TRAFFIC_CAPA,
930 WLAN_EID_TIM_BCAST_REQ,
931 WLAN_EID_INTERWORKING,
932 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
933 WLAN_EID_VHT_CAPABILITY,
934 WLAN_EID_OPMODE_NOTIF,
940 noffset = ieee80211_ie_split_ric(elems, elems_len,
942 ARRAY_SIZE(before_ht),
944 ARRAY_SIZE(after_ric),
946 skb_put_data(skb, elems + offset, noffset - offset);
951 static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
956 static const u8 before_vht[] = {
958 * no need to list the ones split off before HT
961 WLAN_EID_BSS_COEX_2040,
962 WLAN_EID_EXT_CAPABILITY,
963 WLAN_EID_QOS_TRAFFIC_CAPA,
964 WLAN_EID_TIM_BCAST_REQ,
965 WLAN_EID_INTERWORKING,
966 /* 60 GHz (Multi-band, DMG, MMS) can't happen */
973 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
974 noffset = ieee80211_ie_split(elems, elems_len,
975 before_vht, ARRAY_SIZE(before_vht),
977 skb_put_data(skb, elems + offset, noffset - offset);
982 static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
987 static const u8 before_he[] = {
989 * no need to list the ones split off before VHT
992 WLAN_EID_OPMODE_NOTIF,
993 WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
995 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
996 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
997 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
998 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
999 WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
1000 /* TODO: add 11ah/11aj/11ak elements */
1007 /* RIC already taken care of in ieee80211_add_before_ht_elems() */
1008 noffset = ieee80211_ie_split(elems, elems_len,
1009 before_he, ARRAY_SIZE(before_he),
1011 skb_put_data(skb, elems + offset, noffset - offset);
1016 #define PRESENT_ELEMS_MAX 8
1017 #define PRESENT_ELEM_EXT_OFFS 0x100
1019 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1020 struct sk_buff *skb, u16 capab,
1021 const struct element *ext_capa,
1022 const u16 *present_elems);
1024 static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
1025 struct sk_buff *skb, u16 *capab,
1026 const struct element *ext_capa,
1027 const u8 *extra_elems,
1028 size_t extra_elems_len,
1029 unsigned int link_id,
1030 struct ieee80211_link_data *link,
1033 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1034 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1035 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1036 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1037 struct ieee80211_channel *chan = cbss->channel;
1038 const struct ieee80211_sband_iftype_data *iftd;
1039 struct ieee80211_local *local = sdata->local;
1040 struct ieee80211_supported_band *sband;
1041 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
1042 struct ieee80211_chanctx_conf *chanctx_conf;
1043 enum ieee80211_smps_mode smps_mode;
1044 u16 orig_capab = *capab;
1046 int present_elems_len = 0;
1050 #define ADD_PRESENT_ELEM(id) do { \
1051 /* need a last for termination - we use 0 == SSID */ \
1052 if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
1053 present_elems[present_elems_len++] = (id); \
1055 #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
1058 smps_mode = link->smps_mode;
1059 else if (sdata->u.mgd.powersave)
1060 smps_mode = IEEE80211_SMPS_DYNAMIC;
1062 smps_mode = IEEE80211_SMPS_OFF;
1066 * 5/10 MHz scenarios are only viable without MLO, in which
1067 * case this pointer should be used ... All of this is a bit
1068 * unclear though, not sure this even works at all.
1071 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
1073 width = chanctx_conf->def.width;
1077 sband = local->hw.wiphy->bands[chan->band];
1078 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1080 if (sband->band == NL80211_BAND_2GHZ) {
1081 *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
1082 *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
1085 if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
1086 ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
1087 *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
1089 if (sband->band != NL80211_BAND_S1GHZ)
1090 ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
1092 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
1093 *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
1094 struct cfg80211_chan_def chandef = {
1099 pos = skb_put(skb, 4);
1100 *pos++ = WLAN_EID_PWR_CAPABILITY;
1102 *pos++ = 0; /* min tx power */
1104 *pos++ = ieee80211_chandef_max_power(&chandef);
1105 ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
1109 * Per spec, we shouldn't include the list of channels if we advertise
1110 * support for extended channel switching, but we've always done that;
1111 * (for now?) apply this restriction only on the (new) 6 GHz band.
1113 if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
1114 (sband->band != NL80211_BAND_6GHZ ||
1115 !ext_capa || ext_capa->datalen < 1 ||
1116 !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
1117 /* TODO: get this in reg domain format */
1118 pos = skb_put(skb, 2 * sband->n_channels + 2);
1119 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
1120 *pos++ = 2 * sband->n_channels;
1121 for (i = 0; i < sband->n_channels; i++) {
1122 int cf = sband->channels[i].center_freq;
1124 *pos++ = ieee80211_frequency_to_channel(cf);
1125 *pos++ = 1; /* one channel in the subband*/
1127 ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
1130 /* if present, add any custom IEs that go before HT */
1131 offset = ieee80211_add_before_ht_elems(skb, extra_elems,
1135 if (sband->band != NL80211_BAND_6GHZ &&
1136 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
1137 ieee80211_add_ht_ie(sdata, skb,
1138 assoc_data->link[link_id].ap_ht_param,
1139 sband, chan, smps_mode,
1140 assoc_data->link[link_id].conn_flags);
1141 ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
1144 /* if present, add any custom IEs that go before VHT */
1145 offset = ieee80211_add_before_vht_elems(skb, extra_elems,
1149 if (sband->band != NL80211_BAND_6GHZ &&
1150 !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
1151 bool mu_mimo_owner =
1152 ieee80211_add_vht_ie(sdata, skb, sband,
1153 &assoc_data->link[link_id].ap_vht_cap,
1154 assoc_data->link[link_id].conn_flags);
1157 link->conf->mu_mimo_owner = mu_mimo_owner;
1158 ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
1162 * If AP doesn't support HT, mark HE and EHT as disabled.
1163 * If on the 5GHz band, make sure it supports VHT.
1165 if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
1166 (sband->band == NL80211_BAND_5GHZ &&
1167 assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
1168 assoc_data->link[link_id].conn_flags |=
1169 IEEE80211_CONN_DISABLE_HE |
1170 IEEE80211_CONN_DISABLE_EHT;
1172 /* if present, add any custom IEs that go before HE */
1173 offset = ieee80211_add_before_he_elems(skb, extra_elems,
1177 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
1178 ieee80211_add_he_ie(sdata, skb, sband, smps_mode,
1179 assoc_data->link[link_id].conn_flags);
1180 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
1184 * careful - need to know about all the present elems before
1185 * calling ieee80211_assoc_add_ml_elem(), so add this one if
1186 * we're going to put it after the ML element
1188 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1189 ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
1191 if (link_id == assoc_data->assoc_link_id)
1192 ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
1195 /* crash if somebody gets it wrong */
1196 present_elems = NULL;
1198 if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
1199 ieee80211_add_eht_ie(sdata, skb, sband);
1201 if (sband->band == NL80211_BAND_S1GHZ) {
1202 ieee80211_add_aid_request_ie(sdata, skb);
1203 ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
1206 if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
1207 skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
1210 link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
1215 static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
1219 unsigned int skb_len = skb->len;
1222 u8 *len, *list_len = NULL;
1224 skb_put_u8(skb, WLAN_EID_EXTENSION);
1225 len = skb_put(skb, 1);
1226 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1228 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1229 u16 elem = outer[i];
1230 bool have_inner = false;
1231 bool at_extension = false;
1233 /* should at least be sorted in the sense of normal -> ext */
1234 WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
1236 /* switch to extension list */
1237 if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
1238 at_extension = true;
1244 for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
1245 if (elem == inner[j]) {
1255 list_len = skb_put(skb, 1);
1259 skb_put_u8(skb, (u8)elem);
1263 skb_trim(skb, skb_len);
1265 *len = skb->len - skb_len - 2;
1268 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1269 struct sk_buff *skb, u16 capab,
1270 const struct element *ext_capa,
1271 const u16 *outer_present_elems)
1273 struct ieee80211_local *local = sdata->local;
1274 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1275 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1276 struct ieee80211_multi_link_elem *ml_elem;
1277 struct ieee80211_mle_basic_common_info *common;
1278 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1279 __le16 eml_capa = 0, mld_capa_ops = 0;
1280 unsigned int link_id;
1284 if (!sdata->vif.valid_links)
1287 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1288 ieee80211_vif_type_p2p(&sdata->vif));
1290 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1291 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1294 skb_put_u8(skb, WLAN_EID_EXTENSION);
1295 ml_elem_len = skb_put(skb, 1);
1296 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1297 ml_elem = skb_put(skb, sizeof(*ml_elem));
1299 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1300 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1301 common = skb_put(skb, sizeof(*common));
1302 common->len = sizeof(*common) +
1303 2; /* MLD capa/ops */
1304 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1306 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1308 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1309 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1310 common->len += 2; /* EML capabilities */
1312 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1313 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1315 /* need indication from userspace to support this */
1316 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1317 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1319 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1320 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1321 const u8 *extra_elems;
1322 size_t extra_elems_len;
1324 u8 *subelem_len = NULL;
1327 if (!assoc_data->link[link_id].bss ||
1328 link_id == assoc_data->assoc_link_id)
1331 extra_elems = assoc_data->link[link_id].elems;
1332 extra_elems_len = assoc_data->link[link_id].elems_len;
1334 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1335 subelem_len = skb_put(skb, 1);
1337 ctrl = cpu_to_le16(link_id |
1338 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1339 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1340 skb_put_data(skb, &ctrl, sizeof(ctrl));
1341 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1342 skb_put_data(skb, assoc_data->link[link_id].addr,
1345 * Now add the contents of the (re)association request,
1346 * but the "listen interval" and "current AP address"
1347 * (if applicable) are skipped. So we only have
1348 * the capability field (remember the position and fill
1349 * later), followed by the elements added below by
1350 * calling ieee80211_assoc_link_elems().
1352 capab_pos = skb_put(skb, 2);
1354 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1359 link_present_elems);
1361 skb_put_data(skb, extra_elems + extra_used,
1362 extra_elems_len - extra_used);
1364 put_unaligned_le16(capab, capab_pos);
1366 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1367 link_present_elems);
1369 ieee80211_fragment_element(skb, subelem_len);
1372 ieee80211_fragment_element(skb, ml_elem_len);
1375 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1377 struct ieee80211_local *local = sdata->local;
1378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1379 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1380 struct ieee80211_link_data *link;
1381 struct sk_buff *skb;
1382 struct ieee80211_mgmt *mgmt;
1383 u8 *pos, qos_info, *ie_start;
1384 size_t offset, noffset;
1385 u16 capab = WLAN_CAPABILITY_ESS, link_capab;
1387 struct element *ext_capa = NULL;
1388 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1389 struct ieee80211_prep_tx_info info = {};
1390 unsigned int link_id, n_links = 0;
1391 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1396 /* we know it's writable, cast away the const */
1397 if (assoc_data->ie_len)
1398 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1400 assoc_data->ie_len);
1402 sdata_assert_lock(sdata);
1404 size = local->hw.extra_tx_headroom +
1405 sizeof(*mgmt) + /* bit too much but doesn't matter */
1406 2 + assoc_data->ssid_len + /* SSID */
1407 assoc_data->ie_len + /* extra IEs */
1408 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1411 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1412 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1413 const struct ieee80211_sband_iftype_data *iftd;
1414 struct ieee80211_supported_band *sband;
1419 sband = local->hw.wiphy->bands[cbss->channel->band];
1422 /* add STA profile elements length */
1423 size += assoc_data->link[link_id].elems_len;
1424 /* and supported rates length */
1425 size += 4 + sband->n_bitrates;
1426 /* supported channels */
1427 size += 2 + 2 * sband->n_channels;
1429 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1431 size += iftd->vendor_elems.len;
1433 /* power capability */
1436 /* HT, VHT, HE, EHT */
1437 size += 2 + sizeof(struct ieee80211_ht_cap);
1438 size += 2 + sizeof(struct ieee80211_vht_cap);
1439 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1440 sizeof(struct ieee80211_he_mcs_nss_supp) +
1441 IEEE80211_HE_PPE_THRES_MAX_LEN;
1443 if (sband->band == NL80211_BAND_6GHZ)
1444 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1446 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1447 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1448 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1450 /* non-inheritance element */
1451 size += 2 + 2 + PRESENT_ELEMS_MAX;
1453 /* should be the same across all BSSes */
1454 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1455 capab |= WLAN_CAPABILITY_PRIVACY;
1458 if (sdata->vif.valid_links) {
1459 /* consider the multi-link element with STA profile */
1460 size += sizeof(struct ieee80211_multi_link_elem);
1461 /* max common info field in basic multi-link element */
1462 size += sizeof(struct ieee80211_mle_basic_common_info) +
1467 * The capability elements were already considered above;
1468 * note this over-estimates a bit because there's no
1469 * STA profile for the assoc link.
1471 size += (n_links - 1) *
1472 (1 + 1 + /* subelement ID/length */
1473 2 + /* STA control */
1474 1 + ETH_ALEN + 2 /* STA Info field */);
1477 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1481 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1484 skb = alloc_skb(size, GFP_KERNEL);
1488 skb_reserve(skb, local->hw.extra_tx_headroom);
1490 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1491 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1493 /* Set MBSSID support for HE AP if needed */
1494 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1495 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1496 ext_capa && ext_capa->datalen >= 3)
1497 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1499 mgmt = skb_put_zero(skb, 24);
1500 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
1501 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1502 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
1504 listen_int = cpu_to_le16(assoc_data->s1g ?
1505 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1506 local->hw.conf.listen_interval);
1507 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1509 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1510 IEEE80211_STYPE_REASSOC_REQ);
1511 capab_pos = &mgmt->u.reassoc_req.capab_info;
1512 mgmt->u.reassoc_req.listen_interval = listen_int;
1513 memcpy(mgmt->u.reassoc_req.current_ap,
1514 assoc_data->prev_ap_addr, ETH_ALEN);
1515 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1518 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1519 IEEE80211_STYPE_ASSOC_REQ);
1520 capab_pos = &mgmt->u.assoc_req.capab_info;
1521 mgmt->u.assoc_req.listen_interval = listen_int;
1522 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1526 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1528 *pos++ = WLAN_EID_SSID;
1529 *pos++ = assoc_data->ssid_len;
1530 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1532 /* add the elements for the assoc (main) link */
1534 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1538 assoc_data->assoc_link_id, link,
1540 put_unaligned_le16(link_capab, capab_pos);
1542 /* if present, add any custom non-vendor IEs */
1543 if (assoc_data->ie_len) {
1544 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1547 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1551 if (assoc_data->wmm) {
1552 if (assoc_data->uapsd) {
1553 qos_info = ifmgd->uapsd_queues;
1554 qos_info |= (ifmgd->uapsd_max_sp_len <<
1555 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1560 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1563 /* add any remaining custom (i.e. vendor specific here) IEs */
1564 if (assoc_data->ie_len) {
1565 noffset = assoc_data->ie_len;
1566 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1569 if (assoc_data->fils_kek_len) {
1570 ret = fils_encrypt_assoc_req(skb, assoc_data);
1577 pos = skb_tail_pointer(skb);
1578 kfree(ifmgd->assoc_req_ies);
1579 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1580 if (!ifmgd->assoc_req_ies) {
1585 ifmgd->assoc_req_ies_len = pos - ie_start;
1587 drv_mgd_prepare_tx(local, sdata, &info);
1589 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1590 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1591 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1592 IEEE80211_TX_INTFL_MLME_CONN_TX;
1593 ieee80211_tx_skb(sdata, skb);
1598 void ieee80211_send_pspoll(struct ieee80211_local *local,
1599 struct ieee80211_sub_if_data *sdata)
1601 struct ieee80211_pspoll *pspoll;
1602 struct sk_buff *skb;
1604 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1608 pspoll = (struct ieee80211_pspoll *) skb->data;
1609 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1611 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1612 ieee80211_tx_skb(sdata, skb);
1615 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1616 struct ieee80211_sub_if_data *sdata,
1619 struct sk_buff *skb;
1620 struct ieee80211_hdr_3addr *nullfunc;
1621 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1623 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
1624 !ieee80211_hw_check(&local->hw,
1625 DOESNT_SUPPORT_QOS_NDP));
1629 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1631 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1633 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1634 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1636 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1637 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1639 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1640 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1642 ieee80211_tx_skb(sdata, skb);
1645 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1646 struct ieee80211_sub_if_data *sdata)
1648 struct sk_buff *skb;
1649 struct ieee80211_hdr *nullfunc;
1652 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1655 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1659 skb_reserve(skb, local->hw.extra_tx_headroom);
1661 nullfunc = skb_put_zero(skb, 30);
1662 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1663 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1664 nullfunc->frame_control = fc;
1665 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1666 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1667 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1668 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1670 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1671 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1672 ieee80211_tx_skb(sdata, skb);
1675 /* spectrum management related things */
1676 static void ieee80211_chswitch_work(struct work_struct *work)
1678 struct ieee80211_link_data *link =
1679 container_of(work, struct ieee80211_link_data, u.mgd.chswitch_work);
1680 struct ieee80211_sub_if_data *sdata = link->sdata;
1681 struct ieee80211_local *local = sdata->local;
1682 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1685 if (!ieee80211_sdata_running(sdata))
1689 mutex_lock(&local->mtx);
1690 mutex_lock(&local->chanctx_mtx);
1692 if (!ifmgd->associated)
1695 if (!link->conf->csa_active)
1699 * using reservation isn't immediate as it may be deferred until later
1700 * with multi-vif. once reservation is complete it will re-schedule the
1701 * work with no reserved_chanctx so verify chandef to check if it
1702 * completed successfully
1705 if (link->reserved_chanctx) {
1707 * with multi-vif csa driver may call ieee80211_csa_finish()
1708 * many times while waiting for other interfaces to use their
1711 if (link->reserved_ready)
1714 ret = ieee80211_link_use_reserved_context(link);
1717 "failed to use reserved channel context, disconnecting (err=%d)\n",
1719 ieee80211_queue_work(&sdata->local->hw,
1720 &ifmgd->csa_connection_drop_work);
1727 if (!cfg80211_chandef_identical(&link->conf->chandef,
1728 &link->csa_chandef)) {
1730 "failed to finalize channel switch, disconnecting\n");
1731 ieee80211_queue_work(&sdata->local->hw,
1732 &ifmgd->csa_connection_drop_work);
1736 link->u.mgd.csa_waiting_bcn = true;
1738 ieee80211_sta_reset_beacon_monitor(sdata);
1739 ieee80211_sta_reset_conn_monitor(sdata);
1742 mutex_unlock(&local->chanctx_mtx);
1743 mutex_unlock(&local->mtx);
1744 sdata_unlock(sdata);
1747 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1749 struct ieee80211_sub_if_data *sdata = link->sdata;
1750 struct ieee80211_local *local = sdata->local;
1751 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1754 sdata_assert_lock(sdata);
1756 WARN_ON(!link->conf->csa_active);
1758 if (link->csa_block_tx) {
1759 ieee80211_wake_vif_queues(local, sdata,
1760 IEEE80211_QUEUE_STOP_REASON_CSA);
1761 link->csa_block_tx = false;
1764 link->conf->csa_active = false;
1765 link->u.mgd.csa_waiting_bcn = false;
1767 * If the CSA IE is still present on the beacon after the switch,
1768 * we need to consider it as a new CSA (possibly to self).
1770 link->u.mgd.beacon_crc_valid = false;
1772 ret = drv_post_channel_switch(sdata);
1775 "driver post channel switch failed, disconnecting\n");
1776 ieee80211_queue_work(&local->hw,
1777 &ifmgd->csa_connection_drop_work);
1781 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0, 0);
1784 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
1786 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1787 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1789 if (WARN_ON(sdata->vif.valid_links))
1792 trace_api_chswitch_done(sdata, success);
1795 "driver channel switch failed, disconnecting\n");
1796 ieee80211_queue_work(&sdata->local->hw,
1797 &ifmgd->csa_connection_drop_work);
1799 ieee80211_queue_work(&sdata->local->hw,
1800 &sdata->deflink.u.mgd.chswitch_work);
1803 EXPORT_SYMBOL(ieee80211_chswitch_done);
1805 static void ieee80211_chswitch_timer(struct timer_list *t)
1807 struct ieee80211_link_data *link =
1808 from_timer(link, t, u.mgd.chswitch_timer);
1810 ieee80211_queue_work(&link->sdata->local->hw,
1811 &link->u.mgd.chswitch_work);
1815 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1817 struct ieee80211_sub_if_data *sdata = link->sdata;
1818 struct ieee80211_local *local = sdata->local;
1820 if (!local->ops->abort_channel_switch)
1823 mutex_lock(&local->mtx);
1825 mutex_lock(&local->chanctx_mtx);
1826 ieee80211_link_unreserve_chanctx(link);
1827 mutex_unlock(&local->chanctx_mtx);
1829 if (link->csa_block_tx)
1830 ieee80211_wake_vif_queues(local, sdata,
1831 IEEE80211_QUEUE_STOP_REASON_CSA);
1833 link->csa_block_tx = false;
1834 link->conf->csa_active = false;
1836 mutex_unlock(&local->mtx);
1838 drv_abort_channel_switch(sdata);
1842 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1843 u64 timestamp, u32 device_timestamp,
1844 struct ieee802_11_elems *elems,
1847 struct ieee80211_sub_if_data *sdata = link->sdata;
1848 struct ieee80211_local *local = sdata->local;
1849 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1850 struct cfg80211_bss *cbss = link->u.mgd.bss;
1851 struct ieee80211_chanctx_conf *conf;
1852 struct ieee80211_chanctx *chanctx;
1853 enum nl80211_band current_band;
1854 struct ieee80211_csa_ie csa_ie;
1855 struct ieee80211_channel_switch ch_switch;
1856 struct ieee80211_bss *bss;
1859 sdata_assert_lock(sdata);
1864 if (local->scanning)
1867 current_band = cbss->channel->band;
1868 bss = (void *)cbss->priv;
1869 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1871 link->u.mgd.conn_flags,
1872 link->u.mgd.bssid, &csa_ie);
1875 ch_switch.timestamp = timestamp;
1876 ch_switch.device_timestamp = device_timestamp;
1877 ch_switch.block_tx = csa_ie.mode;
1878 ch_switch.chandef = csa_ie.chandef;
1879 ch_switch.count = csa_ie.count;
1880 ch_switch.delay = csa_ie.max_switch_time;
1884 goto lock_and_drop_connection;
1886 if (beacon && link->conf->csa_active &&
1887 !link->u.mgd.csa_waiting_bcn) {
1889 ieee80211_sta_abort_chanswitch(link);
1891 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1893 } else if (link->conf->csa_active || res) {
1894 /* disregard subsequent announcements if already processing */
1898 if (link->conf->chandef.chan->band !=
1899 csa_ie.chandef.chan->band) {
1901 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1903 csa_ie.chandef.chan->center_freq,
1904 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1905 csa_ie.chandef.center_freq2);
1906 goto lock_and_drop_connection;
1909 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1910 IEEE80211_CHAN_DISABLED)) {
1912 "AP %pM switches to unsupported channel "
1913 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1916 csa_ie.chandef.chan->center_freq,
1917 csa_ie.chandef.chan->freq_offset,
1918 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1919 csa_ie.chandef.freq1_offset,
1920 csa_ie.chandef.center_freq2);
1921 goto lock_and_drop_connection;
1924 if (cfg80211_chandef_identical(&csa_ie.chandef,
1925 &link->conf->chandef) &&
1926 (!csa_ie.mode || !beacon)) {
1927 if (link->u.mgd.csa_ignored_same_chan)
1930 "AP %pM tries to chanswitch to same channel, ignore\n",
1932 link->u.mgd.csa_ignored_same_chan = true;
1937 * Drop all TDLS peers - either we disconnect or move to a different
1938 * channel from this point on. There's no telling what our peer will do.
1939 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1940 * have an incompatible wider chandef.
1942 ieee80211_teardown_tdls_peers(sdata);
1944 mutex_lock(&local->mtx);
1945 mutex_lock(&local->chanctx_mtx);
1946 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1947 lockdep_is_held(&local->chanctx_mtx));
1950 "no channel context assigned to vif?, disconnecting\n");
1951 goto drop_connection;
1954 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1956 if (local->use_chanctx &&
1957 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1959 "driver doesn't support chan-switch with channel contexts\n");
1960 goto drop_connection;
1963 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1965 "preparing for channel switch failed, disconnecting\n");
1966 goto drop_connection;
1969 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1970 chanctx->mode, false);
1973 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1975 goto drop_connection;
1977 mutex_unlock(&local->chanctx_mtx);
1979 link->conf->csa_active = true;
1980 link->csa_chandef = csa_ie.chandef;
1981 link->csa_block_tx = csa_ie.mode;
1982 link->u.mgd.csa_ignored_same_chan = false;
1983 link->u.mgd.beacon_crc_valid = false;
1985 if (link->csa_block_tx)
1986 ieee80211_stop_vif_queues(local, sdata,
1987 IEEE80211_QUEUE_STOP_REASON_CSA);
1988 mutex_unlock(&local->mtx);
1990 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, 0,
1991 csa_ie.count, csa_ie.mode, 0);
1993 if (local->ops->channel_switch) {
1994 /* use driver's channel switch callback */
1995 drv_channel_switch(local, sdata, &ch_switch);
1999 /* channel switch handled in software */
2000 if (csa_ie.count <= 1)
2001 ieee80211_queue_work(&local->hw, &link->u.mgd.chswitch_work);
2003 mod_timer(&link->u.mgd.chswitch_timer,
2004 TU_TO_EXP_TIME((csa_ie.count - 1) *
2005 cbss->beacon_interval));
2007 lock_and_drop_connection:
2008 mutex_lock(&local->mtx);
2009 mutex_lock(&local->chanctx_mtx);
2012 * This is just so that the disconnect flow will know that
2013 * we were trying to switch channel and failed. In case the
2014 * mode is 1 (we are not allowed to Tx), we will know not to
2015 * send a deauthentication frame. Those two fields will be
2016 * reset when the disconnection worker runs.
2018 link->conf->csa_active = true;
2019 link->csa_block_tx = csa_ie.mode;
2021 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
2022 mutex_unlock(&local->chanctx_mtx);
2023 mutex_unlock(&local->mtx);
2027 ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
2028 struct ieee80211_channel *channel,
2029 const u8 *country_ie, u8 country_ie_len,
2030 const u8 *pwr_constr_elem,
2031 int *chan_pwr, int *pwr_reduction)
2033 struct ieee80211_country_ie_triplet *triplet;
2034 int chan = ieee80211_frequency_to_channel(channel->center_freq);
2035 int i, chan_increment;
2036 bool have_chan_pwr = false;
2039 if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
2042 triplet = (void *)(country_ie + 3);
2043 country_ie_len -= 3;
2045 switch (channel->band) {
2049 case NL80211_BAND_2GHZ:
2050 case NL80211_BAND_60GHZ:
2051 case NL80211_BAND_LC:
2054 case NL80211_BAND_5GHZ:
2057 case NL80211_BAND_6GHZ:
2059 * In the 6 GHz band, the "maximum transmit power level"
2060 * field in the triplets is reserved, and thus will be
2061 * zero and we shouldn't use it to control TX power.
2062 * The actual TX power will be given in the transmit
2063 * power envelope element instead.
2069 while (country_ie_len >= 3) {
2070 u8 first_channel = triplet->chans.first_channel;
2072 if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
2075 for (i = 0; i < triplet->chans.num_channels; i++) {
2076 if (first_channel + i * chan_increment == chan) {
2077 have_chan_pwr = true;
2078 *chan_pwr = triplet->chans.max_power;
2087 country_ie_len -= 3;
2090 if (have_chan_pwr && pwr_constr_elem)
2091 *pwr_reduction = *pwr_constr_elem;
2095 return have_chan_pwr;
2098 static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
2099 struct ieee80211_channel *channel,
2100 const u8 *cisco_dtpc_ie,
2103 /* From practical testing, the first data byte of the DTPC element
2104 * seems to contain the requested dBm level, and the CLI on Cisco
2105 * APs clearly state the range is -127 to 127 dBm, which indicates
2106 * a signed byte, although it seemingly never actually goes negative.
2107 * The other byte seems to always be zero.
2109 *pwr_level = (__s8)cisco_dtpc_ie[4];
2112 static u32 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
2113 struct ieee80211_channel *channel,
2114 struct ieee80211_mgmt *mgmt,
2115 const u8 *country_ie, u8 country_ie_len,
2116 const u8 *pwr_constr_ie,
2117 const u8 *cisco_dtpc_ie)
2119 struct ieee80211_sub_if_data *sdata = link->sdata;
2120 bool has_80211h_pwr = false, has_cisco_pwr = false;
2121 int chan_pwr = 0, pwr_reduction_80211h = 0;
2122 int pwr_level_cisco, pwr_level_80211h;
2124 __le16 capab = mgmt->u.probe_resp.capab_info;
2126 if (ieee80211_is_s1g_beacon(mgmt->frame_control))
2127 return 0; /* TODO */
2130 (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
2131 capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
2132 has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
2133 sdata, channel, country_ie, country_ie_len,
2134 pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
2136 max_t(int, 0, chan_pwr - pwr_reduction_80211h);
2139 if (cisco_dtpc_ie) {
2140 ieee80211_find_cisco_dtpc(
2141 sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
2142 has_cisco_pwr = true;
2145 if (!has_80211h_pwr && !has_cisco_pwr)
2148 /* If we have both 802.11h and Cisco DTPC, apply both limits
2149 * by picking the smallest of the two power levels advertised.
2151 if (has_80211h_pwr &&
2152 (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
2153 new_ap_level = pwr_level_80211h;
2155 if (link->ap_power_level == new_ap_level)
2159 "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
2160 pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
2162 } else { /* has_cisco_pwr is always true here. */
2163 new_ap_level = pwr_level_cisco;
2165 if (link->ap_power_level == new_ap_level)
2169 "Limiting TX power to %d dBm as advertised by %pM\n",
2170 pwr_level_cisco, link->u.mgd.bssid);
2173 link->ap_power_level = new_ap_level;
2174 if (__ieee80211_recalc_txpower(sdata))
2175 return BSS_CHANGED_TXPOWER;
2180 static void ieee80211_enable_ps(struct ieee80211_local *local,
2181 struct ieee80211_sub_if_data *sdata)
2183 struct ieee80211_conf *conf = &local->hw.conf;
2186 * If we are scanning right now then the parameters will
2187 * take effect when scan finishes.
2189 if (local->scanning)
2192 if (conf->dynamic_ps_timeout > 0 &&
2193 !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2194 mod_timer(&local->dynamic_ps_timer, jiffies +
2195 msecs_to_jiffies(conf->dynamic_ps_timeout));
2197 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
2198 ieee80211_send_nullfunc(local, sdata, true);
2200 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2201 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
2204 conf->flags |= IEEE80211_CONF_PS;
2205 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2209 static void ieee80211_change_ps(struct ieee80211_local *local)
2211 struct ieee80211_conf *conf = &local->hw.conf;
2213 if (local->ps_sdata) {
2214 ieee80211_enable_ps(local, local->ps_sdata);
2215 } else if (conf->flags & IEEE80211_CONF_PS) {
2216 conf->flags &= ~IEEE80211_CONF_PS;
2217 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2218 del_timer_sync(&local->dynamic_ps_timer);
2219 cancel_work_sync(&local->dynamic_ps_enable_work);
2223 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2225 struct ieee80211_local *local = sdata->local;
2226 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2227 struct sta_info *sta = NULL;
2228 bool authorized = false;
2230 if (!mgd->powersave)
2236 if (!mgd->associated)
2239 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2242 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2243 !sdata->deflink.u.mgd.have_beacon)
2247 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2249 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2255 /* need to hold RTNL or interface lock */
2256 void ieee80211_recalc_ps(struct ieee80211_local *local)
2258 struct ieee80211_sub_if_data *sdata, *found = NULL;
2262 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2263 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2264 local->ps_sdata = NULL;
2268 list_for_each_entry(sdata, &local->interfaces, list) {
2269 if (!ieee80211_sdata_running(sdata))
2271 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2272 /* If an AP vif is found, then disable PS
2273 * by setting the count to zero thereby setting
2279 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2285 if (count == 1 && ieee80211_powersave_allowed(found)) {
2286 u8 dtimper = found->deflink.u.mgd.dtim_period;
2288 timeout = local->dynamic_ps_forced_timeout;
2291 local->hw.conf.dynamic_ps_timeout = timeout;
2293 /* If the TIM IE is invalid, pretend the value is 1 */
2297 local->hw.conf.ps_dtim_period = dtimper;
2298 local->ps_sdata = found;
2300 local->ps_sdata = NULL;
2303 ieee80211_change_ps(local);
2306 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2308 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2310 if (sdata->vif.cfg.ps != ps_allowed) {
2311 sdata->vif.cfg.ps = ps_allowed;
2312 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2316 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2318 struct ieee80211_local *local =
2319 container_of(work, struct ieee80211_local,
2320 dynamic_ps_disable_work);
2322 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2323 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2324 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2327 ieee80211_wake_queues_by_reason(&local->hw,
2328 IEEE80211_MAX_QUEUE_MAP,
2329 IEEE80211_QUEUE_STOP_REASON_PS,
2333 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2335 struct ieee80211_local *local =
2336 container_of(work, struct ieee80211_local,
2337 dynamic_ps_enable_work);
2338 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2339 struct ieee80211_if_managed *ifmgd;
2340 unsigned long flags;
2343 /* can only happen when PS was just disabled anyway */
2347 ifmgd = &sdata->u.mgd;
2349 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2352 if (local->hw.conf.dynamic_ps_timeout > 0) {
2353 /* don't enter PS if TX frames are pending */
2354 if (drv_tx_frames_pending(local)) {
2355 mod_timer(&local->dynamic_ps_timer, jiffies +
2357 local->hw.conf.dynamic_ps_timeout));
2362 * transmission can be stopped by others which leads to
2363 * dynamic_ps_timer expiry. Postpone the ps timer if it
2364 * is not the actual idle state.
2366 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2367 for (q = 0; q < local->hw.queues; q++) {
2368 if (local->queue_stop_reasons[q]) {
2369 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2371 mod_timer(&local->dynamic_ps_timer, jiffies +
2373 local->hw.conf.dynamic_ps_timeout));
2377 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2380 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2381 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2382 if (drv_tx_frames_pending(local)) {
2383 mod_timer(&local->dynamic_ps_timer, jiffies +
2385 local->hw.conf.dynamic_ps_timeout));
2387 ieee80211_send_nullfunc(local, sdata, true);
2388 /* Flush to get the tx status of nullfunc frame */
2389 ieee80211_flush_queues(local, sdata, false);
2393 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2394 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2395 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2396 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2397 local->hw.conf.flags |= IEEE80211_CONF_PS;
2398 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2402 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2404 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2406 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
2409 void ieee80211_dfs_cac_timer_work(struct work_struct *work)
2411 struct delayed_work *delayed_work = to_delayed_work(work);
2412 struct ieee80211_link_data *link =
2413 container_of(delayed_work, struct ieee80211_link_data,
2414 dfs_cac_timer_work);
2415 struct cfg80211_chan_def chandef = link->conf->chandef;
2416 struct ieee80211_sub_if_data *sdata = link->sdata;
2418 mutex_lock(&sdata->local->mtx);
2419 if (sdata->wdev.cac_started) {
2420 ieee80211_link_release_channel(link);
2421 cfg80211_cac_event(sdata->dev, &chandef,
2422 NL80211_RADAR_CAC_FINISHED,
2425 mutex_unlock(&sdata->local->mtx);
2429 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2431 struct ieee80211_local *local = sdata->local;
2432 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2436 if (local->hw.queues < IEEE80211_NUM_ACS)
2439 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2440 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2442 unsigned long now = jiffies;
2444 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2445 tx_tspec->admitted_time &&
2446 time_after(now, tx_tspec->time_slice_start + HZ)) {
2447 tx_tspec->consumed_tx_time = 0;
2448 tx_tspec->time_slice_start = now;
2450 if (tx_tspec->downgraded)
2452 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2455 switch (tx_tspec->action) {
2456 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2457 /* take the original parameters */
2458 if (drv_conf_tx(local, &sdata->deflink, ac,
2459 &sdata->deflink.tx_conf[ac]))
2460 link_err(&sdata->deflink,
2461 "failed to set TX queue parameters for queue %d\n",
2463 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2464 tx_tspec->downgraded = false;
2467 case TX_TSPEC_ACTION_DOWNGRADE:
2468 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2469 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2473 /* downgrade next lower non-ACM AC */
2474 for (non_acm_ac = ac + 1;
2475 non_acm_ac < IEEE80211_NUM_ACS;
2477 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2479 /* Usually the loop will result in using BK even if it
2480 * requires admission control, but such a configuration
2481 * makes no sense and we have to transmit somehow - the
2482 * AC selection does the same thing.
2483 * If we started out trying to downgrade from BK, then
2484 * the extra condition here might be needed.
2486 if (non_acm_ac >= IEEE80211_NUM_ACS)
2487 non_acm_ac = IEEE80211_AC_BK;
2488 if (drv_conf_tx(local, &sdata->deflink, ac,
2489 &sdata->deflink.tx_conf[non_acm_ac]))
2490 link_err(&sdata->deflink,
2491 "failed to set TX queue parameters for queue %d\n",
2493 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2495 schedule_delayed_work(&ifmgd->tx_tspec_wk,
2496 tx_tspec->time_slice_start + HZ - now + 1);
2498 case TX_TSPEC_ACTION_NONE:
2507 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2509 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2510 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2514 static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
2516 struct ieee80211_sub_if_data *sdata;
2518 sdata = container_of(work, struct ieee80211_sub_if_data,
2519 u.mgd.tx_tspec_wk.work);
2520 ieee80211_sta_handle_tspec_ac_params(sdata);
2523 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
2525 struct ieee80211_sub_if_data *sdata = link->sdata;
2526 struct ieee80211_local *local = sdata->local;
2527 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2528 struct ieee80211_tx_queue_params *params = link->tx_conf;
2531 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2533 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2535 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2536 params[ac].txop, params[ac].uapsd,
2537 ifmgd->tx_tspec[ac].downgraded);
2538 if (!ifmgd->tx_tspec[ac].downgraded &&
2539 drv_conf_tx(local, link, ac, ¶ms[ac]))
2541 "failed to set TX queue parameters for AC %d\n",
2548 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2549 struct ieee80211_link_data *link,
2550 const u8 *wmm_param, size_t wmm_param_len,
2551 const struct ieee80211_mu_edca_param_set *mu_edca)
2553 struct ieee80211_sub_if_data *sdata = link->sdata;
2554 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2555 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2557 int count, mu_edca_count, ac;
2559 u8 uapsd_queues = 0;
2561 if (!local->ops->conf_tx)
2564 if (local->hw.queues < IEEE80211_NUM_ACS)
2570 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2573 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2574 uapsd_queues = ifmgd->uapsd_queues;
2576 count = wmm_param[6] & 0x0f;
2577 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2578 * if mu_edca was preset before and now it disappeared tell
2579 * the driver about it.
2581 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2582 if (count == link->u.mgd.wmm_last_param_set &&
2583 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2585 link->u.mgd.wmm_last_param_set = count;
2586 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2588 pos = wmm_param + 8;
2589 left = wmm_param_len - 8;
2591 memset(¶ms, 0, sizeof(params));
2594 for (; left >= 4; left -= 4, pos += 4) {
2595 int aci = (pos[0] >> 5) & 0x03;
2596 int acm = (pos[0] >> 4) & 0x01;
2601 ac = IEEE80211_AC_BK;
2603 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2604 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2606 params[ac].mu_edca = !!mu_edca;
2608 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2611 ac = IEEE80211_AC_VI;
2613 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2614 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2616 params[ac].mu_edca = !!mu_edca;
2618 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2621 ac = IEEE80211_AC_VO;
2623 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2624 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2626 params[ac].mu_edca = !!mu_edca;
2628 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2632 ac = IEEE80211_AC_BE;
2634 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2635 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2637 params[ac].mu_edca = !!mu_edca;
2639 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2643 params[ac].aifs = pos[0] & 0x0f;
2645 if (params[ac].aifs < 2) {
2647 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2648 params[ac].aifs, aci);
2649 params[ac].aifs = 2;
2651 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2652 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2653 params[ac].txop = get_unaligned_le16(pos + 2);
2654 params[ac].acm = acm;
2655 params[ac].uapsd = uapsd;
2657 if (params[ac].cw_min == 0 ||
2658 params[ac].cw_min > params[ac].cw_max) {
2660 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2661 params[ac].cw_min, params[ac].cw_max, aci);
2664 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2667 /* WMM specification requires all 4 ACIs. */
2668 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2669 if (params[ac].cw_min == 0) {
2671 "AP has invalid WMM params (missing AC %d), using defaults\n",
2677 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2678 link->tx_conf[ac] = params[ac];
2680 ieee80211_mgd_set_link_qos_params(link);
2682 /* enable WMM or activate new settings */
2683 link->conf->qos = true;
2687 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2689 lockdep_assert_held(&sdata->local->mtx);
2691 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2692 ieee80211_run_deferred_scan(sdata->local);
2695 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2697 mutex_lock(&sdata->local->mtx);
2698 __ieee80211_stop_poll(sdata);
2699 mutex_unlock(&sdata->local->mtx);
2702 static u32 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2703 u16 capab, bool erp_valid, u8 erp)
2705 struct ieee80211_bss_conf *bss_conf = link->conf;
2706 struct ieee80211_supported_band *sband;
2708 bool use_protection;
2709 bool use_short_preamble;
2710 bool use_short_slot;
2712 sband = ieee80211_get_link_sband(link);
2717 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2718 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2720 use_protection = false;
2721 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2724 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2725 if (sband->band == NL80211_BAND_5GHZ ||
2726 sband->band == NL80211_BAND_6GHZ)
2727 use_short_slot = true;
2729 if (use_protection != bss_conf->use_cts_prot) {
2730 bss_conf->use_cts_prot = use_protection;
2731 changed |= BSS_CHANGED_ERP_CTS_PROT;
2734 if (use_short_preamble != bss_conf->use_short_preamble) {
2735 bss_conf->use_short_preamble = use_short_preamble;
2736 changed |= BSS_CHANGED_ERP_PREAMBLE;
2739 if (use_short_slot != bss_conf->use_short_slot) {
2740 bss_conf->use_short_slot = use_short_slot;
2741 changed |= BSS_CHANGED_ERP_SLOT;
2747 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2748 struct cfg80211_bss *cbss)
2750 struct ieee80211_sub_if_data *sdata = link->sdata;
2751 struct ieee80211_bss_conf *bss_conf = link->conf;
2752 struct ieee80211_bss *bss = (void *)cbss->priv;
2753 u32 changed = BSS_CHANGED_QOS;
2755 /* not really used in MLO */
2756 sdata->u.mgd.beacon_timeout =
2757 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2758 bss_conf->beacon_int));
2760 changed |= ieee80211_handle_bss_capability(link,
2761 bss_conf->assoc_capability,
2765 ieee80211_check_rate_mask(link);
2767 link->u.mgd.bss = cbss;
2768 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2770 if (sdata->vif.p2p ||
2771 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2772 const struct cfg80211_bss_ies *ies;
2775 ies = rcu_dereference(cbss->ies);
2779 ret = cfg80211_get_p2p_attr(
2780 ies->data, ies->len,
2781 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2782 (u8 *) &bss_conf->p2p_noa_attr,
2783 sizeof(bss_conf->p2p_noa_attr));
2785 link->u.mgd.p2p_noa_index =
2786 bss_conf->p2p_noa_attr.index;
2787 changed |= BSS_CHANGED_P2P_PS;
2793 if (link->u.mgd.have_beacon) {
2794 bss_conf->beacon_rate = bss->beacon_rate;
2795 changed |= BSS_CHANGED_BEACON_INFO;
2797 bss_conf->beacon_rate = NULL;
2800 /* Tell the driver to monitor connection quality (if supported) */
2801 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2802 bss_conf->cqm_rssi_thold)
2803 changed |= BSS_CHANGED_CQM;
2808 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2809 struct ieee80211_mgd_assoc_data *assoc_data,
2810 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2812 struct ieee80211_local *local = sdata->local;
2813 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2814 u64 vif_changed = BSS_CHANGED_ASSOC;
2815 unsigned int link_id;
2817 sdata->u.mgd.associated = true;
2819 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2820 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2821 struct ieee80211_link_data *link;
2824 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2827 link = sdata_dereference(sdata->link[link_id], sdata);
2831 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2834 /* just to be sure */
2835 ieee80211_stop_poll(sdata);
2837 ieee80211_led_assoc(local, 1);
2841 /* Enable ARP filtering */
2842 if (vif_cfg->arp_addr_cnt)
2843 vif_changed |= BSS_CHANGED_ARP_FILTER;
2845 if (sdata->vif.valid_links) {
2847 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2849 struct ieee80211_link_data *link;
2850 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2853 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2856 link = sdata_dereference(sdata->link[link_id], sdata);
2860 ieee80211_link_info_change_notify(sdata, link,
2863 ieee80211_recalc_smps(sdata, link);
2866 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2868 ieee80211_bss_info_change_notify(sdata,
2869 vif_changed | changed[0]);
2872 mutex_lock(&local->iflist_mtx);
2873 ieee80211_recalc_ps(local);
2874 mutex_unlock(&local->iflist_mtx);
2876 /* leave this here to not change ordering in non-MLO cases */
2877 if (!sdata->vif.valid_links)
2878 ieee80211_recalc_smps(sdata, &sdata->deflink);
2879 ieee80211_recalc_ps_vif(sdata);
2881 netif_carrier_on(sdata->dev);
2884 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2885 u16 stype, u16 reason, bool tx,
2888 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2889 struct ieee80211_local *local = sdata->local;
2890 unsigned int link_id;
2892 struct ieee80211_prep_tx_info info = {
2896 sdata_assert_lock(sdata);
2898 if (WARN_ON_ONCE(tx && !frame_buf))
2901 if (WARN_ON(!ifmgd->associated))
2904 ieee80211_stop_poll(sdata);
2906 ifmgd->associated = false;
2908 /* other links will be destroyed */
2909 sdata->deflink.u.mgd.bss = NULL;
2911 netif_carrier_off(sdata->dev);
2914 * if we want to get out of ps before disassoc (why?) we have
2915 * to do it before sending disassoc, as otherwise the null-packet
2918 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2919 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2920 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2922 local->ps_sdata = NULL;
2924 /* disable per-vif ps */
2925 ieee80211_recalc_ps_vif(sdata);
2927 /* make sure ongoing transmission finishes */
2931 * drop any frame before deauth/disassoc, this can be data or
2932 * management frame. Since we are disconnecting, we should not
2933 * insist sending these frames which can take time and delay
2934 * the disconnection and possible the roaming.
2937 ieee80211_flush_queues(local, sdata, true);
2939 /* deauthenticate/disassociate now */
2940 if (tx || frame_buf) {
2942 * In multi channel scenarios guarantee that the virtual
2943 * interface is granted immediate airtime to transmit the
2944 * deauthentication frame by calling mgd_prepare_tx, if the
2945 * driver requested so.
2947 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
2948 !sdata->deflink.u.mgd.have_beacon) {
2949 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2952 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2953 sdata->vif.cfg.ap_addr, stype,
2954 reason, tx, frame_buf);
2957 /* flush out frame - make sure the deauth was actually sent */
2959 ieee80211_flush_queues(local, sdata, false);
2961 drv_mgd_complete_tx(sdata->local, sdata, &info);
2963 /* clear AP addr only after building the needed mgmt frames */
2964 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2965 eth_zero_addr(sdata->vif.cfg.ap_addr);
2967 sdata->vif.cfg.ssid_len = 0;
2969 /* remove AP and TDLS peers */
2970 sta_info_flush(sdata);
2972 /* finally reset all BSS / config parameters */
2973 if (!sdata->vif.valid_links)
2974 changed |= ieee80211_reset_erp_info(sdata);
2976 ieee80211_led_assoc(local, 0);
2977 changed |= BSS_CHANGED_ASSOC;
2978 sdata->vif.cfg.assoc = false;
2980 sdata->deflink.u.mgd.p2p_noa_index = -1;
2981 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
2982 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
2984 /* on the next assoc, re-program HT/VHT parameters */
2985 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
2986 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
2987 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
2988 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
2991 * reset MU-MIMO ownership and group data in default link,
2992 * if used, other links are destroyed
2994 memset(sdata->vif.bss_conf.mu_group.membership, 0,
2995 sizeof(sdata->vif.bss_conf.mu_group.membership));
2996 memset(sdata->vif.bss_conf.mu_group.position, 0,
2997 sizeof(sdata->vif.bss_conf.mu_group.position));
2998 if (!sdata->vif.valid_links)
2999 changed |= BSS_CHANGED_MU_GROUPS;
3000 sdata->vif.bss_conf.mu_mimo_owner = false;
3002 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3004 del_timer_sync(&local->dynamic_ps_timer);
3005 cancel_work_sync(&local->dynamic_ps_enable_work);
3007 /* Disable ARP filtering */
3008 if (sdata->vif.cfg.arp_addr_cnt)
3009 changed |= BSS_CHANGED_ARP_FILTER;
3011 sdata->vif.bss_conf.qos = false;
3012 if (!sdata->vif.valid_links) {
3013 changed |= BSS_CHANGED_QOS;
3014 /* The BSSID (not really interesting) and HT changed */
3015 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3016 ieee80211_bss_info_change_notify(sdata, changed);
3018 ieee80211_vif_cfg_change_notify(sdata, changed);
3021 /* disassociated - set to defaults now */
3022 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3024 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3025 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3026 del_timer_sync(&sdata->u.mgd.timer);
3027 del_timer_sync(&sdata->deflink.u.mgd.chswitch_timer);
3029 sdata->vif.bss_conf.dtim_period = 0;
3030 sdata->vif.bss_conf.beacon_rate = NULL;
3032 sdata->deflink.u.mgd.have_beacon = false;
3033 sdata->deflink.u.mgd.tracking_signal_avg = false;
3034 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3037 sdata->deflink.u.mgd.conn_flags = 0;
3038 mutex_lock(&local->mtx);
3040 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3041 struct ieee80211_link_data *link;
3043 link = sdata_dereference(sdata->link[link_id], sdata);
3046 ieee80211_link_release_channel(link);
3049 sdata->vif.bss_conf.csa_active = false;
3050 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3051 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
3052 if (sdata->deflink.csa_block_tx) {
3053 ieee80211_wake_vif_queues(local, sdata,
3054 IEEE80211_QUEUE_STOP_REASON_CSA);
3055 sdata->deflink.csa_block_tx = false;
3057 mutex_unlock(&local->mtx);
3059 /* existing TX TSPEC sessions no longer exist */
3060 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3061 cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
3063 sdata->vif.bss_conf.pwr_reduction = 0;
3064 sdata->vif.bss_conf.tx_pwr_env_num = 0;
3065 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
3066 sizeof(sdata->vif.bss_conf.tx_pwr_env));
3068 ieee80211_vif_set_links(sdata, 0);
3071 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3073 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3074 struct ieee80211_local *local = sdata->local;
3076 mutex_lock(&local->mtx);
3077 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3080 __ieee80211_stop_poll(sdata);
3082 mutex_lock(&local->iflist_mtx);
3083 ieee80211_recalc_ps(local);
3084 mutex_unlock(&local->iflist_mtx);
3086 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3090 * We've received a probe response, but are not sure whether
3091 * we have or will be receiving any beacons or data, so let's
3092 * schedule the timers again, just in case.
3094 ieee80211_sta_reset_beacon_monitor(sdata);
3096 mod_timer(&ifmgd->conn_mon_timer,
3097 round_jiffies_up(jiffies +
3098 IEEE80211_CONNECTION_IDLE_TIME));
3100 mutex_unlock(&local->mtx);
3103 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3104 struct ieee80211_hdr *hdr,
3107 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3110 struct ieee80211_sta_tx_tspec *tx_tspec;
3111 unsigned long now = jiffies;
3113 if (!ieee80211_is_data_qos(hdr->frame_control))
3116 tid = ieee80211_get_tid(hdr);
3117 ac = ieee80211_ac_from_tid(tid);
3118 tx_tspec = &ifmgd->tx_tspec[ac];
3120 if (likely(!tx_tspec->admitted_time))
3123 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3124 tx_tspec->consumed_tx_time = 0;
3125 tx_tspec->time_slice_start = now;
3127 if (tx_tspec->downgraded) {
3128 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3129 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3133 if (tx_tspec->downgraded)
3136 tx_tspec->consumed_tx_time += tx_time;
3138 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3139 tx_tspec->downgraded = true;
3140 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3141 schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
3145 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3146 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3148 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3150 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3151 !sdata->u.mgd.probe_send_count)
3155 sdata->u.mgd.probe_send_count = 0;
3157 sdata->u.mgd.nullfunc_failed = true;
3158 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
3161 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3162 const u8 *src, const u8 *dst,
3163 const u8 *ssid, size_t ssid_len,
3164 struct ieee80211_channel *channel)
3166 struct sk_buff *skb;
3168 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3169 ssid, ssid_len, NULL, 0,
3170 IEEE80211_PROBE_FLAG_DIRECTED);
3172 ieee80211_tx_skb(sdata, skb);
3175 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3177 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3178 u8 *dst = sdata->vif.cfg.ap_addr;
3179 u8 unicast_limit = max(1, max_probe_tries - 3);
3180 struct sta_info *sta;
3182 if (WARN_ON(sdata->vif.valid_links))
3186 * Try sending broadcast probe requests for the last three
3187 * probe requests after the first ones failed since some
3188 * buggy APs only support broadcast probe requests.
3190 if (ifmgd->probe_send_count >= unicast_limit)
3194 * When the hardware reports an accurate Tx ACK status, it's
3195 * better to send a nullfunc frame instead of a probe request,
3196 * as it will kick us off the AP quickly if we aren't associated
3197 * anymore. The timeout will be reset if the frame is ACKed by
3200 ifmgd->probe_send_count++;
3203 mutex_lock(&sdata->local->sta_mtx);
3204 sta = sta_info_get(sdata, dst);
3206 ieee80211_check_fast_rx(sta);
3207 mutex_unlock(&sdata->local->sta_mtx);
3210 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3211 ifmgd->nullfunc_failed = false;
3212 ieee80211_send_nullfunc(sdata->local, sdata, false);
3214 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3215 sdata->vif.cfg.ssid,
3216 sdata->vif.cfg.ssid_len,
3217 sdata->deflink.u.mgd.bss->channel);
3220 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3221 run_again(sdata, ifmgd->probe_timeout);
3224 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3227 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3228 bool already = false;
3230 if (WARN_ON_ONCE(sdata->vif.valid_links))
3233 if (!ieee80211_sdata_running(sdata))
3238 if (!ifmgd->associated)
3241 mutex_lock(&sdata->local->mtx);
3243 if (sdata->local->tmp_channel || sdata->local->scanning) {
3244 mutex_unlock(&sdata->local->mtx);
3248 if (sdata->local->suspending) {
3249 /* reschedule after resume */
3250 mutex_unlock(&sdata->local->mtx);
3251 ieee80211_reset_ap_probe(sdata);
3256 mlme_dbg_ratelimited(sdata,
3257 "detected beacon loss from AP (missed %d beacons) - probing\n",
3260 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3264 * The driver/our work has already reported this event or the
3265 * connection monitoring has kicked in and we have already sent
3266 * a probe request. Or maybe the AP died and the driver keeps
3267 * reporting until we disassociate...
3269 * In either case we have to ignore the current call to this
3270 * function (except for setting the correct probe reason bit)
3271 * because otherwise we would reset the timer every time and
3272 * never check whether we received a probe response!
3274 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3277 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3279 mutex_unlock(&sdata->local->mtx);
3284 mutex_lock(&sdata->local->iflist_mtx);
3285 ieee80211_recalc_ps(sdata->local);
3286 mutex_unlock(&sdata->local->iflist_mtx);
3288 ifmgd->probe_send_count = 0;
3289 ieee80211_mgd_probe_ap_send(sdata);
3291 sdata_unlock(sdata);
3294 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3295 struct ieee80211_vif *vif)
3297 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3298 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3299 struct cfg80211_bss *cbss;
3300 struct sk_buff *skb;
3301 const struct element *ssid;
3304 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3305 sdata->vif.valid_links))
3308 sdata_assert_lock(sdata);
3310 if (ifmgd->associated)
3311 cbss = sdata->deflink.u.mgd.bss;
3312 else if (ifmgd->auth_data)
3313 cbss = ifmgd->auth_data->bss;
3314 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3315 cbss = ifmgd->assoc_data->link[0].bss;
3320 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3321 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3322 "invalid SSID element (len=%d)",
3323 ssid ? ssid->datalen : -1))
3326 ssid_len = ssid->datalen;
3328 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3329 (u32) -1, cbss->channel,
3330 ssid->data, ssid_len,
3331 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3336 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3338 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3339 const u8 *buf, size_t len, bool tx,
3340 u16 reason, bool reconnect)
3342 struct ieee80211_event event = {
3344 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3345 .u.mlme.reason = reason,
3349 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3351 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3353 drv_event_callback(sdata->local, sdata, &event);
3356 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3358 struct ieee80211_local *local = sdata->local;
3359 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3360 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3364 if (!ifmgd->associated) {
3365 sdata_unlock(sdata);
3369 /* in MLO assume we have a link where we can TX the frame */
3370 tx = sdata->vif.valid_links || !sdata->deflink.csa_block_tx;
3372 if (!ifmgd->driver_disconnect) {
3373 unsigned int link_id;
3376 * AP is probably out of range (or not reachable for another
3377 * reason) so remove the bss structs for that AP. In the case
3378 * of multi-link, it's not clear that all of them really are
3379 * out of range, but if they weren't the driver likely would
3380 * have switched to just have a single link active?
3383 link_id < ARRAY_SIZE(sdata->link);
3385 struct ieee80211_link_data *link;
3387 link = sdata_dereference(sdata->link[link_id], sdata);
3390 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3391 link->u.mgd.bss = NULL;
3395 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3396 ifmgd->driver_disconnect ?
3397 WLAN_REASON_DEAUTH_LEAVING :
3398 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3400 mutex_lock(&local->mtx);
3401 /* the other links will be destroyed */
3402 sdata->vif.bss_conf.csa_active = false;
3403 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3404 if (sdata->deflink.csa_block_tx) {
3405 ieee80211_wake_vif_queues(local, sdata,
3406 IEEE80211_QUEUE_STOP_REASON_CSA);
3407 sdata->deflink.csa_block_tx = false;
3409 mutex_unlock(&local->mtx);
3411 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3412 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3414 ifmgd->reconnect = false;
3416 sdata_unlock(sdata);
3419 static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
3421 struct ieee80211_sub_if_data *sdata =
3422 container_of(work, struct ieee80211_sub_if_data,
3423 u.mgd.beacon_connection_loss_work);
3424 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3426 if (ifmgd->connection_loss) {
3427 sdata_info(sdata, "Connection to AP %pM lost\n",
3428 sdata->vif.cfg.ap_addr);
3429 __ieee80211_disconnect(sdata);
3430 ifmgd->connection_loss = false;
3431 } else if (ifmgd->driver_disconnect) {
3433 "Driver requested disconnection from AP %pM\n",
3434 sdata->vif.cfg.ap_addr);
3435 __ieee80211_disconnect(sdata);
3436 ifmgd->driver_disconnect = false;
3438 if (ifmgd->associated)
3439 sdata->deflink.u.mgd.beacon_loss_count++;
3440 ieee80211_mgd_probe_ap(sdata, true);
3444 static void ieee80211_csa_connection_drop_work(struct work_struct *work)
3446 struct ieee80211_sub_if_data *sdata =
3447 container_of(work, struct ieee80211_sub_if_data,
3448 u.mgd.csa_connection_drop_work);
3450 __ieee80211_disconnect(sdata);
3453 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3455 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3456 struct ieee80211_hw *hw = &sdata->local->hw;
3458 trace_api_beacon_loss(sdata);
3460 sdata->u.mgd.connection_loss = false;
3461 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3463 EXPORT_SYMBOL(ieee80211_beacon_loss);
3465 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3467 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3468 struct ieee80211_hw *hw = &sdata->local->hw;
3470 trace_api_connection_loss(sdata);
3472 sdata->u.mgd.connection_loss = true;
3473 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3475 EXPORT_SYMBOL(ieee80211_connection_loss);
3477 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3479 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3480 struct ieee80211_hw *hw = &sdata->local->hw;
3482 trace_api_disconnect(sdata, reconnect);
3484 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3487 sdata->u.mgd.driver_disconnect = true;
3488 sdata->u.mgd.reconnect = reconnect;
3489 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
3491 EXPORT_SYMBOL(ieee80211_disconnect);
3493 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3496 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3498 sdata_assert_lock(sdata);
3502 * we are not authenticated yet, the only timer that could be
3503 * running is the timeout for the authentication response which
3504 * which is not relevant anymore.
3506 del_timer_sync(&sdata->u.mgd.timer);
3507 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3509 /* other links are destroyed */
3510 sdata->deflink.u.mgd.conn_flags = 0;
3511 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3512 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3514 sdata->u.mgd.flags = 0;
3516 mutex_lock(&sdata->local->mtx);
3517 ieee80211_link_release_channel(&sdata->deflink);
3518 ieee80211_vif_set_links(sdata, 0);
3519 mutex_unlock(&sdata->local->mtx);
3522 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3524 sdata->u.mgd.auth_data = NULL;
3534 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3535 enum assoc_status status)
3537 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3539 sdata_assert_lock(sdata);
3541 if (status != ASSOC_SUCCESS) {
3543 * we are not associated yet, the only timer that could be
3544 * running is the timeout for the association response which
3545 * which is not relevant anymore.
3547 del_timer_sync(&sdata->u.mgd.timer);
3548 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3550 sdata->deflink.u.mgd.conn_flags = 0;
3551 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3552 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3554 sdata->u.mgd.flags = 0;
3555 sdata->vif.bss_conf.mu_mimo_owner = false;
3557 if (status != ASSOC_REJECTED) {
3558 struct cfg80211_assoc_failure data = {
3559 .timeout = status == ASSOC_TIMEOUT,
3563 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3564 ARRAY_SIZE(assoc_data->link));
3566 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3567 data.bss[i] = assoc_data->link[i].bss;
3569 if (sdata->vif.valid_links)
3570 data.ap_mld_addr = assoc_data->ap_addr;
3572 cfg80211_assoc_failure(sdata->dev, &data);
3575 mutex_lock(&sdata->local->mtx);
3576 ieee80211_link_release_channel(&sdata->deflink);
3577 ieee80211_vif_set_links(sdata, 0);
3578 mutex_unlock(&sdata->local->mtx);
3582 sdata->u.mgd.assoc_data = NULL;
3585 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3586 struct ieee80211_mgmt *mgmt, size_t len)
3588 struct ieee80211_local *local = sdata->local;
3589 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3590 const struct element *challenge;
3593 struct ieee80211_prep_tx_info info = {
3594 .subtype = IEEE80211_STYPE_AUTH,
3597 pos = mgmt->u.auth.variable;
3598 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3599 len - (pos - (u8 *)mgmt));
3602 auth_data->expected_transaction = 4;
3603 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3604 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3605 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3606 IEEE80211_TX_INTFL_MLME_CONN_TX;
3607 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3609 challenge->datalen + sizeof(*challenge),
3610 auth_data->ap_addr, auth_data->ap_addr,
3611 auth_data->key, auth_data->key_len,
3612 auth_data->key_idx, tx_flags);
3615 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3617 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3618 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3619 struct sta_info *sta;
3622 sdata_info(sdata, "authenticated\n");
3623 ifmgd->auth_data->done = true;
3624 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3625 ifmgd->auth_data->timeout_started = true;
3626 run_again(sdata, ifmgd->auth_data->timeout);
3628 /* move station state to auth */
3629 mutex_lock(&sdata->local->sta_mtx);
3630 sta = sta_info_get(sdata, ap_addr);
3632 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3636 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3637 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3643 mutex_unlock(&sdata->local->sta_mtx);
3647 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3648 struct ieee80211_mgmt *mgmt, size_t len)
3650 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3651 u16 auth_alg, auth_transaction, status_code;
3652 struct ieee80211_event event = {
3654 .u.mlme.data = AUTH_EVENT,
3656 struct ieee80211_prep_tx_info info = {
3657 .subtype = IEEE80211_STYPE_AUTH,
3660 sdata_assert_lock(sdata);
3665 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3668 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3671 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3672 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3673 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3675 if (auth_alg != ifmgd->auth_data->algorithm ||
3676 (auth_alg != WLAN_AUTH_SAE &&
3677 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3678 (auth_alg == WLAN_AUTH_SAE &&
3679 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3680 auth_transaction > 2))) {
3681 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3682 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3684 ifmgd->auth_data->expected_transaction);
3688 if (status_code != WLAN_STATUS_SUCCESS) {
3689 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3691 if (auth_alg == WLAN_AUTH_SAE &&
3692 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3693 (auth_transaction == 1 &&
3694 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3695 status_code == WLAN_STATUS_SAE_PK)))) {
3696 /* waiting for userspace now */
3697 ifmgd->auth_data->waiting = true;
3698 ifmgd->auth_data->timeout =
3699 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3700 ifmgd->auth_data->timeout_started = true;
3701 run_again(sdata, ifmgd->auth_data->timeout);
3705 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3706 mgmt->sa, status_code);
3707 ieee80211_destroy_auth_data(sdata, false);
3708 event.u.mlme.status = MLME_DENIED;
3709 event.u.mlme.reason = status_code;
3710 drv_event_callback(sdata->local, sdata, &event);
3714 switch (ifmgd->auth_data->algorithm) {
3715 case WLAN_AUTH_OPEN:
3716 case WLAN_AUTH_LEAP:
3719 case WLAN_AUTH_FILS_SK:
3720 case WLAN_AUTH_FILS_SK_PFS:
3721 case WLAN_AUTH_FILS_PK:
3723 case WLAN_AUTH_SHARED_KEY:
3724 if (ifmgd->auth_data->expected_transaction != 4) {
3725 ieee80211_auth_challenge(sdata, mgmt, len);
3726 /* need another frame */
3731 WARN_ONCE(1, "invalid auth alg %d",
3732 ifmgd->auth_data->algorithm);
3736 event.u.mlme.status = MLME_SUCCESS;
3738 drv_event_callback(sdata->local, sdata, &event);
3739 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3740 (auth_transaction == 2 &&
3741 ifmgd->auth_data->expected_transaction == 2)) {
3742 if (!ieee80211_mark_sta_auth(sdata))
3743 return; /* ignore frame -- wait for timeout */
3744 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3745 auth_transaction == 2) {
3746 sdata_info(sdata, "SAE peer confirmed\n");
3747 ifmgd->auth_data->peer_confirmed = true;
3750 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3752 drv_mgd_complete_tx(sdata->local, sdata, &info);
3755 #define case_WLAN(type) \
3756 case WLAN_REASON_##type: return #type
3758 const char *ieee80211_get_reason_code_string(u16 reason_code)
3760 switch (reason_code) {
3761 case_WLAN(UNSPECIFIED);
3762 case_WLAN(PREV_AUTH_NOT_VALID);
3763 case_WLAN(DEAUTH_LEAVING);
3764 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3765 case_WLAN(DISASSOC_AP_BUSY);
3766 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3767 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3768 case_WLAN(DISASSOC_STA_HAS_LEFT);
3769 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3770 case_WLAN(DISASSOC_BAD_POWER);
3771 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3772 case_WLAN(INVALID_IE);
3773 case_WLAN(MIC_FAILURE);
3774 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3775 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3776 case_WLAN(IE_DIFFERENT);
3777 case_WLAN(INVALID_GROUP_CIPHER);
3778 case_WLAN(INVALID_PAIRWISE_CIPHER);
3779 case_WLAN(INVALID_AKMP);
3780 case_WLAN(UNSUPP_RSN_VERSION);
3781 case_WLAN(INVALID_RSN_IE_CAP);
3782 case_WLAN(IEEE8021X_FAILED);
3783 case_WLAN(CIPHER_SUITE_REJECTED);
3784 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3785 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3786 case_WLAN(DISASSOC_LOW_ACK);
3787 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3788 case_WLAN(QSTA_LEAVE_QBSS);
3789 case_WLAN(QSTA_NOT_USE);
3790 case_WLAN(QSTA_REQUIRE_SETUP);
3791 case_WLAN(QSTA_TIMEOUT);
3792 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3793 case_WLAN(MESH_PEER_CANCELED);
3794 case_WLAN(MESH_MAX_PEERS);
3795 case_WLAN(MESH_CONFIG);
3796 case_WLAN(MESH_CLOSE);
3797 case_WLAN(MESH_MAX_RETRIES);
3798 case_WLAN(MESH_CONFIRM_TIMEOUT);
3799 case_WLAN(MESH_INVALID_GTK);
3800 case_WLAN(MESH_INCONSISTENT_PARAM);
3801 case_WLAN(MESH_INVALID_SECURITY);
3802 case_WLAN(MESH_PATH_ERROR);
3803 case_WLAN(MESH_PATH_NOFORWARD);
3804 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3805 case_WLAN(MAC_EXISTS_IN_MBSS);
3806 case_WLAN(MESH_CHAN_REGULATORY);
3807 case_WLAN(MESH_CHAN);
3808 default: return "<unknown>";
3812 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3813 struct ieee80211_mgmt *mgmt, size_t len)
3815 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3816 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3818 sdata_assert_lock(sdata);
3823 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3824 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3828 if (ifmgd->associated &&
3829 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3830 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3831 sdata->vif.cfg.ap_addr, reason_code,
3832 ieee80211_get_reason_code_string(reason_code));
3834 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3836 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3837 reason_code, false);
3841 if (ifmgd->assoc_data &&
3842 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3844 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3845 ifmgd->assoc_data->ap_addr, reason_code,
3846 ieee80211_get_reason_code_string(reason_code));
3848 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3850 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3856 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3857 struct ieee80211_mgmt *mgmt, size_t len)
3859 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3862 sdata_assert_lock(sdata);
3867 if (!ifmgd->associated ||
3868 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3871 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3873 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3874 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3878 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3879 sdata->vif.cfg.ap_addr, reason_code,
3880 ieee80211_get_reason_code_string(reason_code));
3882 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3884 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3888 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3889 u8 *supp_rates, unsigned int supp_rates_len,
3890 u32 *rates, u32 *basic_rates,
3891 bool *have_higher_than_11mbit,
3892 int *min_rate, int *min_rate_index,
3897 for (i = 0; i < supp_rates_len; i++) {
3898 int rate = supp_rates[i] & 0x7f;
3899 bool is_basic = !!(supp_rates[i] & 0x80);
3901 if ((rate * 5 * (1 << shift)) > 110)
3902 *have_higher_than_11mbit = true;
3905 * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
3906 * since they're not rates.
3908 * Note: Even though the membership selector and the basic
3909 * rate flag share the same bit, they are not exactly
3912 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3913 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3914 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3915 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3918 for (j = 0; j < sband->n_bitrates; j++) {
3919 struct ieee80211_rate *br;
3922 br = &sband->bitrates[j];
3924 brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
3925 if (brate == rate) {
3928 *basic_rates |= BIT(j);
3929 if ((rate * 5) < *min_rate) {
3930 *min_rate = rate * 5;
3931 *min_rate_index = j;
3939 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3940 struct ieee80211_supported_band *sband,
3941 const struct link_sta_info *link_sta,
3942 const struct ieee802_11_elems *elems)
3944 const struct ieee80211_sta_he_cap *own_he_cap =
3945 ieee80211_get_he_iftype_cap(sband,
3946 ieee80211_vif_type_p2p(&sdata->vif));
3948 if (elems->ext_capab_len < 10)
3951 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3954 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3955 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3957 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3958 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3961 static int ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3962 struct ieee80211_supported_band *sband,
3963 struct ieee80211_link_data *link,
3964 struct link_sta_info *link_sta,
3965 struct ieee802_11_elems *elems)
3967 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3969 if (link->conf->twt_requester != twt) {
3970 link->conf->twt_requester = twt;
3971 return BSS_CHANGED_TWT;
3976 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3977 struct ieee80211_bss_conf *bss_conf,
3978 struct ieee80211_supported_band *sband,
3979 struct link_sta_info *link_sta)
3981 const struct ieee80211_sta_he_cap *own_he_cap =
3982 ieee80211_get_he_iftype_cap(sband,
3983 ieee80211_vif_type_p2p(&sdata->vif));
3985 return bss_conf->he_support &&
3986 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3987 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3989 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3990 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3993 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3994 struct link_sta_info *link_sta,
3995 struct cfg80211_bss *cbss,
3996 struct ieee80211_mgmt *mgmt,
3997 const u8 *elem_start,
3998 unsigned int elem_len,
4001 struct ieee80211_sub_if_data *sdata = link->sdata;
4002 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4003 struct ieee80211_bss_conf *bss_conf = link->conf;
4004 struct ieee80211_local *local = sdata->local;
4005 unsigned int link_id = link->link_id;
4006 struct ieee80211_elems_parse_params parse_params = {
4007 .start = elem_start,
4009 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
4012 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4013 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
4014 const struct cfg80211_bss_ies *bss_ies = NULL;
4015 struct ieee80211_supported_band *sband;
4016 struct ieee802_11_elems *elems;
4020 elems = ieee802_11_parse_elems_full(&parse_params);
4024 if (link_id == assoc_data->assoc_link_id) {
4025 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4028 * we should not get to this flow unless the association was
4029 * successful, so set the status directly to success
4031 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4032 } else if (!elems->prof) {
4036 const u8 *ptr = elems->prof->variable +
4037 elems->prof->sta_info_len - 1;
4040 * During parsing, we validated that these fields exist,
4041 * otherwise elems->prof would have been set to NULL.
4043 capab_info = get_unaligned_le16(ptr);
4044 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4046 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4047 link_info(link, "association response status code=%u\n",
4048 assoc_data->link[link_id].status);
4054 if (!is_s1g && !elems->supp_rates) {
4055 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4060 link->u.mgd.tdls_chan_switch_prohibited =
4061 elems->ext_capab && elems->ext_capab_len >= 5 &&
4062 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4065 * Some APs are erroneously not including some information in their
4066 * (re)association response frames. Try to recover by using the data
4067 * from the beacon or probe response. This seems to afflict mobile
4068 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4069 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4072 ((assoc_data->wmm && !elems->wmm_param) ||
4073 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4074 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4075 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4076 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4077 const struct cfg80211_bss_ies *ies;
4078 struct ieee802_11_elems *bss_elems;
4081 ies = rcu_dereference(cbss->ies);
4083 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4091 parse_params.start = bss_ies->data;
4092 parse_params.len = bss_ies->len;
4093 parse_params.bss = cbss;
4094 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4100 if (assoc_data->wmm &&
4101 !elems->wmm_param && bss_elems->wmm_param) {
4102 elems->wmm_param = bss_elems->wmm_param;
4104 "AP bug: WMM param missing from AssocResp\n");
4108 * Also check if we requested HT/VHT, otherwise the AP doesn't
4109 * have to include the IEs in the (re)association response.
4111 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4112 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4113 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4115 "AP bug: HT capability missing from AssocResp\n");
4117 if (!elems->ht_operation && bss_elems->ht_operation &&
4118 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4119 elems->ht_operation = bss_elems->ht_operation;
4121 "AP bug: HT operation missing from AssocResp\n");
4123 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4124 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4125 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4127 "AP bug: VHT capa missing from AssocResp\n");
4129 if (!elems->vht_operation && bss_elems->vht_operation &&
4130 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4131 elems->vht_operation = bss_elems->vht_operation;
4133 "AP bug: VHT operation missing from AssocResp\n");
4140 * We previously checked these in the beacon/probe response, so
4141 * they should be present here. This is just a safety net.
4143 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4144 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4146 "HT AP is missing WMM params or HT capability/operation\n");
4151 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4152 (!elems->vht_cap_elem || !elems->vht_operation)) {
4154 "VHT AP is missing VHT capability/operation\n");
4159 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4160 !elems->he_6ghz_capa) {
4162 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4167 if (WARN_ON(!link->conf->chandef.chan)) {
4171 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4173 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4174 (!elems->he_cap || !elems->he_operation)) {
4176 "HE AP is missing HE capability/operation\n");
4181 /* Set up internal HT/VHT capabilities */
4182 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4183 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4187 if (elems->vht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT))
4188 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4189 elems->vht_cap_elem,
4192 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4194 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4197 elems->he_6ghz_capa,
4200 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4201 if (elems->rsnx && elems->rsnx_len &&
4202 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4203 wiphy_ext_feature_isset(local->hw.wiphy,
4204 NL80211_EXT_FEATURE_PROTECTED_TWT))
4205 bss_conf->twt_protected = true;
4207 bss_conf->twt_protected = false;
4209 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4212 if (elems->eht_operation && elems->eht_cap &&
4213 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4214 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4221 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4222 *changed |= BSS_CHANGED_EHT_PUNCTURING;
4224 bss_conf->eht_support = false;
4227 bss_conf->he_support = false;
4228 bss_conf->twt_requester = false;
4229 bss_conf->twt_protected = false;
4230 bss_conf->eht_support = false;
4233 bss_conf->twt_broadcast =
4234 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4236 if (bss_conf->he_support) {
4237 bss_conf->he_bss_color.color =
4238 le32_get_bits(elems->he_operation->he_oper_params,
4239 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4240 bss_conf->he_bss_color.partial =
4241 le32_get_bits(elems->he_operation->he_oper_params,
4242 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4243 bss_conf->he_bss_color.enabled =
4244 !le32_get_bits(elems->he_operation->he_oper_params,
4245 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4247 if (bss_conf->he_bss_color.enabled)
4248 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4250 bss_conf->htc_trig_based_pkt_ext =
4251 le32_get_bits(elems->he_operation->he_oper_params,
4252 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4253 bss_conf->frame_time_rts_th =
4254 le32_get_bits(elems->he_operation->he_oper_params,
4255 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4257 bss_conf->uora_exists = !!elems->uora_element;
4258 if (elems->uora_element)
4259 bss_conf->uora_ocw_range = elems->uora_element[0];
4261 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4262 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4263 /* TODO: OPEN: what happens if BSS color disable is set? */
4266 if (cbss->transmitted_bss) {
4267 bss_conf->nontransmitted = true;
4268 ether_addr_copy(bss_conf->transmitter_bssid,
4269 cbss->transmitted_bss->bssid);
4270 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4271 bss_conf->bssid_index = cbss->bssid_index;
4275 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4276 * in their association response, so ignore that data for our own
4277 * configuration. If it changed since the last beacon, we'll get the
4278 * next beacon and update then.
4282 * If an operating mode notification IE is present, override the
4283 * NSS calculation (that would be done in rate_control_rate_init())
4284 * and use the # of streams from that element.
4286 if (elems->opmode_notif &&
4287 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4290 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4291 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4293 link_sta->pub->rx_nss = nss;
4297 * Always handle WMM once after association regardless
4298 * of the first value the AP uses. Setting -1 here has
4299 * that effect because the AP values is an unsigned
4302 link->u.mgd.wmm_last_param_set = -1;
4303 link->u.mgd.mu_edca_last_param_set = -1;
4305 if (link->u.mgd.disable_wmm_tracking) {
4306 ieee80211_set_wmm_default(link, false, false);
4307 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4308 elems->wmm_param_len,
4309 elems->mu_edca_param_set)) {
4310 /* still enable QoS since we might have HT/VHT */
4311 ieee80211_set_wmm_default(link, false, true);
4312 /* disable WMM tracking in this case to disable
4313 * tracking WMM parameter changes in the beacon if
4314 * the parameters weren't actually valid. Doing so
4315 * avoids changing parameters very strangely when
4316 * the AP is going back and forth between valid and
4317 * invalid parameters.
4319 link->u.mgd.disable_wmm_tracking = true;
4322 if (elems->max_idle_period_ie) {
4323 bss_conf->max_idle_period =
4324 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4325 bss_conf->protected_keep_alive =
4326 !!(elems->max_idle_period_ie->idle_options &
4327 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4328 *changed |= BSS_CHANGED_KEEP_ALIVE;
4330 bss_conf->max_idle_period = 0;
4331 bss_conf->protected_keep_alive = false;
4334 /* set assoc capability (AID was already set earlier),
4335 * ieee80211_set_associated() will tell the driver */
4336 bss_conf->assoc_capability = capab_info;
4345 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4346 struct sta_info *sta,
4347 struct link_sta_info *link_sta,
4348 struct cfg80211_bss *cbss)
4350 struct ieee80211_sub_if_data *sdata = link->sdata;
4351 struct ieee80211_local *local = sdata->local;
4352 struct ieee80211_bss *bss = (void *)cbss->priv;
4353 u32 rates = 0, basic_rates = 0;
4354 bool have_higher_than_11mbit = false;
4355 int min_rate = INT_MAX, min_rate_index = -1;
4356 /* this is clearly wrong for MLO but we'll just remove it later */
4357 int shift = ieee80211_vif_get_shift(&sdata->vif);
4358 struct ieee80211_supported_band *sband;
4360 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4361 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4363 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4364 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4365 ieee80211_s1g_sta_rate_init(sta);
4369 sband = local->hw.wiphy->bands[cbss->channel->band];
4371 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4372 &rates, &basic_rates, &have_higher_than_11mbit,
4373 &min_rate, &min_rate_index, shift);
4376 * This used to be a workaround for basic rates missing
4377 * in the association response frame. Now that we no
4378 * longer use the basic rates from there, it probably
4379 * doesn't happen any more, but keep the workaround so
4380 * in case some *other* APs are buggy in different ways
4381 * we can connect -- with a warning.
4382 * Allow this workaround only in case the AP provided at least
4385 if (min_rate_index < 0) {
4386 link_info(link, "No legacy rates in association response\n");
4388 } else if (!basic_rates) {
4389 link_info(link, "No basic rates, using min rate instead\n");
4390 basic_rates = BIT(min_rate_index);
4394 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4396 link_info(link, "No rates found, keeping mandatory only\n");
4398 link->conf->basic_rates = basic_rates;
4400 /* cf. IEEE 802.11 9.2.12 */
4401 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4402 have_higher_than_11mbit;
4407 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4408 struct cfg80211_bss *cbss)
4410 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4411 const struct element *ht_cap_elem, *vht_cap_elem;
4412 const struct cfg80211_bss_ies *ies;
4413 const struct ieee80211_ht_cap *ht_cap;
4414 const struct ieee80211_vht_cap *vht_cap;
4415 const struct ieee80211_he_cap_elem *he_cap;
4416 const struct element *he_cap_elem;
4417 u16 mcs_80_map, mcs_160_map;
4418 int i, mcs_nss_size;
4422 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4425 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4426 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4427 ht_cap = (void *)ht_cap_elem->data;
4428 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4430 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4431 * "Tx Unequal Modulation Supported" fields.
4435 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4438 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4439 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4443 vht_cap = (void *)vht_cap_elem->data;
4444 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4445 for (nss = 8; nss > 0; nss--) {
4446 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4447 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4450 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4451 chains = max(chains, nss);
4454 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4457 ies = rcu_dereference(cbss->ies);
4458 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4459 ies->data, ies->len);
4461 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4464 /* skip one byte ext_tag_id */
4465 he_cap = (void *)(he_cap_elem->data + 1);
4466 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4469 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4472 /* mcs_nss is right after he_cap info */
4473 he_mcs_nss_supp = (void *)(he_cap + 1);
4475 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4477 for (i = 7; i >= 0; i--) {
4478 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4480 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4481 chains = max_t(u8, chains, i + 1);
4486 support_160 = he_cap->phy_cap_info[0] &
4487 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4492 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4493 for (i = 7; i >= 0; i--) {
4494 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4496 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4497 chains = max_t(u8, chains, i + 1);
4506 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4507 const struct cfg80211_bss_ies *ies,
4508 const struct ieee80211_he_operation *he_op)
4510 const struct element *he_cap_elem;
4511 const struct ieee80211_he_cap_elem *he_cap;
4512 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4513 u16 mcs_80_map_tx, mcs_80_map_rx;
4518 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4519 ies->data, ies->len);
4525 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4527 "Invalid HE elem, Disable HE\n");
4531 /* skip one byte ext_tag_id */
4532 he_cap = (void *)(he_cap_elem->data + 1);
4533 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4536 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4538 "Invalid HE elem with nss size, Disable HE\n");
4542 /* mcs_nss is right after he_cap info */
4543 he_mcs_nss_supp = (void *)(he_cap + 1);
4545 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4546 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4548 /* P802.11-REVme/D0.3
4549 * 27.1.1 Introduction to the HE PHY
4551 * An HE STA shall support the following features:
4553 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4554 * supported channel widths for HE SU PPDUs
4556 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4557 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4559 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4560 mcs_80_map_tx, mcs_80_map_rx);
4567 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4570 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4571 * zeroes, which is nonsense, and completely inconsistent with itself
4572 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4574 if (!ap_min_req_set)
4577 /* make sure the AP is consistent with itself
4579 * P802.11-REVme/D0.3
4580 * 26.17.1 Basic HE BSS operation
4582 * A STA that is operating in an HE BSS shall be able to receive and
4583 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4584 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4585 * MLME-START.request primitive and shall be able to receive at each of
4586 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4587 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4590 for (nss = 8; nss > 0; nss--) {
4591 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4595 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4598 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4599 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4601 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4602 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4603 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4605 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4606 nss, ap_rx_val, ap_rx_val, ap_op_val);
4615 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4616 struct ieee80211_supported_band *sband,
4617 const struct ieee80211_he_operation *he_op)
4619 const struct ieee80211_sta_he_cap *sta_he_cap =
4620 ieee80211_get_he_iftype_cap(sband,
4621 ieee80211_vif_type_p2p(&sdata->vif));
4625 if (!sta_he_cap || !he_op)
4628 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4631 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4632 * zeroes, which is nonsense, and completely inconsistent with itself
4633 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4635 if (!ap_min_req_set)
4638 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4639 for (i = 0; i < 3; i++) {
4640 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4641 &sta_he_cap->he_mcs_nss_supp;
4642 u16 sta_mcs_map_rx =
4643 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4644 u16 sta_mcs_map_tx =
4645 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4647 bool verified = true;
4650 * For each band there is a maximum of 8 spatial streams
4651 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4652 * of 2 bits per NSS (1-8), with the values defined in enum
4653 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4654 * capabilities aren't less than the AP's minimum requirements
4655 * for this HE BSS per SS.
4656 * It is enough to find one such band that meets the reqs.
4658 for (nss = 8; nss > 0; nss--) {
4659 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4660 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4661 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4663 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4667 * Make sure the HE AP doesn't require MCSs that aren't
4668 * supported by the client as required by spec
4670 * P802.11-REVme/D0.3
4671 * 26.17.1 Basic HE BSS operation
4673 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4674 * a BSS, unless it supports (i.e., is able to both transmit and
4675 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4676 * HE-MCS and NSS set.
4678 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4679 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4680 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4690 /* If here, STA doesn't meet AP's HE min requirements */
4694 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4695 struct ieee80211_link_data *link,
4696 struct cfg80211_bss *cbss,
4697 ieee80211_conn_flags_t *conn_flags)
4699 struct ieee80211_local *local = sdata->local;
4700 const struct ieee80211_ht_cap *ht_cap = NULL;
4701 const struct ieee80211_ht_operation *ht_oper = NULL;
4702 const struct ieee80211_vht_operation *vht_oper = NULL;
4703 const struct ieee80211_he_operation *he_oper = NULL;
4704 const struct ieee80211_eht_operation *eht_oper = NULL;
4705 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4706 struct ieee80211_supported_band *sband;
4707 struct cfg80211_chan_def chandef;
4708 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4709 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4710 struct ieee80211_bss *bss = (void *)cbss->priv;
4711 struct ieee80211_elems_parse_params parse_params = {
4716 struct ieee802_11_elems *elems;
4717 const struct cfg80211_bss_ies *ies;
4724 ies = rcu_dereference(cbss->ies);
4725 parse_params.start = ies->data;
4726 parse_params.len = ies->len;
4727 elems = ieee802_11_parse_elems_full(&parse_params);
4733 sband = local->hw.wiphy->bands[cbss->channel->band];
4735 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4736 IEEE80211_CONN_DISABLE_80P80MHZ |
4737 IEEE80211_CONN_DISABLE_160MHZ);
4739 /* disable HT/VHT/HE if we don't support them */
4740 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4741 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4742 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4743 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4744 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4745 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4748 if (!sband->vht_cap.vht_supported && is_5ghz) {
4749 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4750 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4751 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4752 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4755 if (!ieee80211_get_he_iftype_cap(sband,
4756 ieee80211_vif_type_p2p(&sdata->vif))) {
4757 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4758 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4759 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4762 if (!ieee80211_get_eht_iftype_cap(sband,
4763 ieee80211_vif_type_p2p(&sdata->vif))) {
4764 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4765 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4768 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4769 ht_oper = elems->ht_operation;
4770 ht_cap = elems->ht_cap_elem;
4773 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4778 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4779 vht_oper = elems->vht_operation;
4780 if (vht_oper && !ht_oper) {
4783 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4784 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4785 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4786 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4787 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4790 if (!elems->vht_cap_elem) {
4791 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4796 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4797 he_oper = elems->he_operation;
4799 if (link && is_6ghz) {
4800 struct ieee80211_bss_conf *bss_conf;
4803 bss_conf = link->conf;
4805 if (elems->pwr_constr_elem)
4806 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4808 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4809 ARRAY_SIZE(elems->tx_pwr_env));
4811 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4812 if (elems->tx_pwr_env_len[i] >
4813 sizeof(bss_conf->tx_pwr_env[j]))
4816 bss_conf->tx_pwr_env_num++;
4817 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4818 elems->tx_pwr_env_len[i]);
4823 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4824 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4825 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4826 IEEE80211_CONN_DISABLE_EHT;
4830 * EHT requires HE to be supported as well. Specifically for 6 GHz
4831 * channels, the operation channel information can only be deduced from
4832 * both the 6 GHz operation information (from the HE operation IE) and
4836 (IEEE80211_CONN_DISABLE_HE |
4837 IEEE80211_CONN_DISABLE_EHT)) &&
4839 const struct cfg80211_bss_ies *cbss_ies;
4840 const u8 *eht_oper_ie;
4842 cbss_ies = rcu_dereference(cbss->ies);
4843 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4844 cbss_ies->data, cbss_ies->len);
4845 if (eht_oper_ie && eht_oper_ie[1] >=
4846 1 + sizeof(struct ieee80211_eht_operation))
4847 eht_oper = (void *)(eht_oper_ie + 3);
4852 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4854 for (i = 0; i < sband->n_channels; i++) {
4855 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4856 IEEE80211_CHAN_NO_80MHZ))
4864 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
4865 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4868 if (sband->band == NL80211_BAND_S1GHZ) {
4869 s1g_oper = elems->s1g_oper;
4872 "AP missing S1G operation element?\n");
4876 ieee80211_determine_chantype(sdata, link, *conn_flags,
4886 link->needed_rx_chains =
4887 min(ieee80211_max_rx_chains(link, cbss),
4891 /* the element data was RCU protected so no longer valid anyway */
4895 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
4896 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
4903 /* will change later if needed */
4904 link->smps_mode = IEEE80211_SMPS_OFF;
4906 mutex_lock(&local->mtx);
4908 * If this fails (possibly due to channel context sharing
4909 * on incompatible channels, e.g. 80+80 and 160 sharing the
4910 * same control channel) try to use a smaller bandwidth.
4912 ret = ieee80211_link_use_channel(link, &chandef,
4913 IEEE80211_CHANCTX_SHARED);
4915 /* don't downgrade for 5 and 10 MHz channels, though. */
4916 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
4917 chandef.width == NL80211_CHAN_WIDTH_10)
4920 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
4922 ieee80211_chandef_downgrade(&chandef);
4923 ret = ieee80211_link_use_channel(link, &chandef,
4924 IEEE80211_CHANCTX_SHARED);
4927 mutex_unlock(&local->mtx);
4931 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
4932 u8 *dtim_count, u8 *dtim_period)
4934 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
4935 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
4937 const struct ieee80211_tim_ie *tim = NULL;
4938 const struct ieee80211_bssid_index *idx;
4939 bool valid = tim_ie && tim_ie[1] >= 2;
4942 tim = (void *)(tim_ie + 2);
4945 *dtim_count = valid ? tim->dtim_count : 0;
4948 *dtim_period = valid ? tim->dtim_period : 0;
4950 /* Check if value is overridden by non-transmitted profile */
4951 if (!idx_ie || idx_ie[1] < 3)
4954 idx = (void *)(idx_ie + 2);
4957 *dtim_count = idx->dtim_count;
4960 *dtim_period = idx->dtim_period;
4965 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
4966 struct ieee80211_mgmt *mgmt,
4967 struct ieee802_11_elems *elems,
4968 const u8 *elem_start, unsigned int elem_len)
4970 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
4971 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
4972 struct ieee80211_local *local = sdata->local;
4973 unsigned int link_id;
4974 struct sta_info *sta;
4975 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
4976 u16 valid_links = 0;
4979 mutex_lock(&sdata->local->sta_mtx);
4981 * station info was already allocated and inserted before
4982 * the association and should be available to us
4984 sta = sta_info_get(sdata, assoc_data->ap_addr);
4988 if (sdata->vif.valid_links) {
4989 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
4990 if (!assoc_data->link[link_id].bss)
4992 valid_links |= BIT(link_id);
4994 if (link_id != assoc_data->assoc_link_id) {
4995 err = ieee80211_sta_allocate_link(sta, link_id);
5001 ieee80211_vif_set_links(sdata, valid_links);
5004 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5005 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5006 struct ieee80211_link_data *link;
5007 struct link_sta_info *link_sta;
5012 link = sdata_dereference(sdata->link[link_id], sdata);
5016 if (sdata->vif.valid_links)
5018 "local address %pM, AP link address %pM%s\n",
5020 assoc_data->link[link_id].bss->bssid,
5021 link_id == assoc_data->assoc_link_id ?
5024 link_sta = rcu_dereference_protected(sta->link[link_id],
5025 lockdep_is_held(&local->sta_mtx));
5026 if (WARN_ON(!link_sta))
5029 if (!link->u.mgd.have_beacon) {
5030 const struct cfg80211_bss_ies *ies;
5033 ies = rcu_dereference(cbss->beacon_ies);
5035 link->u.mgd.have_beacon = true;
5037 ies = rcu_dereference(cbss->ies);
5038 ieee80211_get_dtim(ies,
5039 &link->conf->sync_dtim_count,
5040 &link->u.mgd.dtim_period);
5041 link->conf->beacon_int = cbss->beacon_interval;
5045 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5047 if (link_id != assoc_data->assoc_link_id) {
5048 err = ieee80211_prep_channel(sdata, link, cbss,
5049 &link->u.mgd.conn_flags);
5051 link_info(link, "prep_channel failed\n");
5056 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5057 assoc_data->link[link_id].bss);
5061 if (!ieee80211_assoc_config_link(link, link_sta,
5062 assoc_data->link[link_id].bss,
5063 mgmt, elem_start, elem_len,
5067 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5068 valid_links &= ~BIT(link_id);
5069 ieee80211_sta_remove_link(sta, link_id);
5073 if (link_id != assoc_data->assoc_link_id) {
5074 err = ieee80211_sta_activate_link(sta, link_id);
5080 /* links might have changed due to rejected ones, set them again */
5081 ieee80211_vif_set_links(sdata, valid_links);
5083 rate_control_rate_init(sta);
5085 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5086 set_sta_flag(sta, WLAN_STA_MFP);
5087 sta->sta.mfp = true;
5089 sta->sta.mfp = false;
5092 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5093 elems->ext_capab_len);
5095 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5096 local->hw.queues >= IEEE80211_NUM_ACS;
5098 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5099 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5100 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5103 "failed to move station %pM to desired state\n",
5105 WARN_ON(__sta_info_destroy(sta));
5109 if (sdata->wdev.use_4addr)
5110 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5112 mutex_unlock(&sdata->local->sta_mtx);
5114 ieee80211_set_associated(sdata, assoc_data, changed);
5117 * If we're using 4-addr mode, let the AP know that we're
5118 * doing so, so that it can create the STA VLAN on its side
5120 if (ifmgd->use_4addr)
5121 ieee80211_send_4addr_nullfunc(local, sdata);
5124 * Start timer to probe the connection to the AP now.
5125 * Also start the timer that will detect beacon loss.
5127 ieee80211_sta_reset_beacon_monitor(sdata);
5128 ieee80211_sta_reset_conn_monitor(sdata);
5132 eth_zero_addr(sdata->vif.cfg.ap_addr);
5133 mutex_unlock(&sdata->local->sta_mtx);
5137 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5138 struct ieee80211_mgmt *mgmt,
5141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5142 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5143 u16 capab_info, status_code, aid;
5144 struct ieee80211_elems_parse_params parse_params = {
5149 struct ieee802_11_elems *elems;
5151 const u8 *elem_start;
5152 unsigned int elem_len;
5154 struct ieee80211_event event = {
5156 .u.mlme.data = ASSOC_EVENT,
5158 struct ieee80211_prep_tx_info info = {};
5159 struct cfg80211_rx_assoc_resp resp = {
5162 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5163 unsigned int link_id;
5165 sdata_assert_lock(sdata);
5170 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5171 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5175 * AssocResp and ReassocResp have identical structure, so process both
5176 * of them in this function.
5182 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5183 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5184 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5185 if (assoc_data->s1g)
5186 elem_start = mgmt->u.s1g_assoc_resp.variable;
5188 elem_start = mgmt->u.assoc_resp.variable;
5191 * Note: this may not be perfect, AP might misbehave - if
5192 * anyone needs to rely on perfect complete notification
5193 * with the exact right subtype, then we need to track what
5194 * we actually transmitted.
5196 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5197 IEEE80211_STYPE_ASSOC_REQ;
5199 if (assoc_data->fils_kek_len &&
5200 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5203 elem_len = len - (elem_start - (u8 *)mgmt);
5204 parse_params.start = elem_start;
5205 parse_params.len = elem_len;
5206 elems = ieee802_11_parse_elems_full(&parse_params);
5210 if (elems->aid_resp)
5211 aid = le16_to_cpu(elems->aid_resp->aid);
5212 else if (assoc_data->s1g)
5215 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5218 * The 5 MSB of the AID field are reserved
5219 * (802.11-2016 9.4.1.8 AID field)
5224 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5225 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5226 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5228 ifmgd->broken_ap = false;
5230 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5231 elems->timeout_int &&
5232 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5235 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5236 le32_to_cpu(elems->timeout_int->value));
5238 tu = le32_to_cpu(elems->timeout_int->value);
5239 ms = tu * 1024 / 1000;
5241 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5242 assoc_data->ap_addr, tu, ms);
5243 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5244 assoc_data->timeout_started = true;
5245 if (ms > IEEE80211_ASSOC_TIMEOUT)
5246 run_again(sdata, assoc_data->timeout);
5250 if (status_code != WLAN_STATUS_SUCCESS) {
5251 sdata_info(sdata, "%pM denied association (code=%d)\n",
5252 assoc_data->ap_addr, status_code);
5253 event.u.mlme.status = MLME_DENIED;
5254 event.u.mlme.reason = status_code;
5255 drv_event_callback(sdata->local, sdata, &event);
5257 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5259 "invalid AID value %d (out of range), turn off PS\n",
5262 ifmgd->broken_ap = true;
5265 if (sdata->vif.valid_links) {
5266 if (!elems->multi_link) {
5268 "MLO association with %pM but no multi-link element in response!\n",
5269 assoc_data->ap_addr);
5273 if (le16_get_bits(elems->multi_link->control,
5274 IEEE80211_ML_CONTROL_TYPE) !=
5275 IEEE80211_ML_CONTROL_TYPE_BASIC) {
5277 "bad multi-link element (control=0x%x)\n",
5278 le16_to_cpu(elems->multi_link->control));
5281 struct ieee80211_mle_basic_common_info *common;
5283 common = (void *)elems->multi_link->variable;
5285 if (memcmp(assoc_data->ap_addr,
5286 common->mld_mac_addr, ETH_ALEN)) {
5288 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5289 common->mld_mac_addr,
5290 assoc_data->ap_addr);
5296 sdata->vif.cfg.aid = aid;
5298 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5299 elem_start, elem_len)) {
5300 /* oops -- internal error -- send timeout for now */
5301 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5304 event.u.mlme.status = MLME_SUCCESS;
5305 drv_event_callback(sdata->local, sdata, &event);
5306 sdata_info(sdata, "associated\n");
5311 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5312 struct ieee80211_link_data *link;
5314 link = sdata_dereference(sdata->link[link_id], sdata);
5318 if (!assoc_data->link[link_id].bss)
5321 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5322 resp.links[link_id].addr = link->conf->addr;
5323 resp.links[link_id].status = assoc_data->link[link_id].status;
5325 /* get uapsd queues configuration - same for all links */
5326 resp.uapsd_queues = 0;
5327 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5328 if (link->tx_conf[ac].uapsd)
5329 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5332 if (sdata->vif.valid_links) {
5333 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5334 resp.ap_mld_addr = ap_mld_addr;
5337 ieee80211_destroy_assoc_data(sdata,
5338 status_code == WLAN_STATUS_SUCCESS ?
5342 resp.buf = (u8 *)mgmt;
5344 resp.req_ies = ifmgd->assoc_req_ies;
5345 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5346 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5348 drv_mgd_complete_tx(sdata->local, sdata, &info);
5352 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5356 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5357 struct ieee80211_mgmt *mgmt, size_t len,
5358 struct ieee80211_rx_status *rx_status)
5360 struct ieee80211_sub_if_data *sdata = link->sdata;
5361 struct ieee80211_local *local = sdata->local;
5362 struct ieee80211_bss *bss;
5363 struct ieee80211_channel *channel;
5365 sdata_assert_lock(sdata);
5367 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5368 ieee80211_rx_status_to_khz(rx_status));
5372 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5374 link->conf->beacon_rate = bss->beacon_rate;
5375 ieee80211_rx_bss_put(local, bss);
5380 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5381 struct sk_buff *skb)
5383 struct ieee80211_sub_if_data *sdata = link->sdata;
5384 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5385 struct ieee80211_if_managed *ifmgd;
5386 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5387 struct ieee80211_channel *channel;
5388 size_t baselen, len = skb->len;
5390 ifmgd = &sdata->u.mgd;
5392 sdata_assert_lock(sdata);
5395 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5396 * "If a 6 GHz AP receives a Probe Request frame and responds with
5397 * a Probe Response frame [..], the Address 1 field of the Probe
5398 * Response frame shall be set to the broadcast address [..]"
5399 * So, on 6GHz band we should also accept broadcast responses.
5401 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5406 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5407 (channel->band != NL80211_BAND_6GHZ ||
5408 !is_broadcast_ether_addr(mgmt->da)))
5409 return; /* ignore ProbeResp to foreign address */
5411 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5415 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5417 if (ifmgd->associated &&
5418 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5419 ieee80211_reset_ap_probe(sdata);
5423 * This is the canonical list of information elements we care about,
5424 * the filter code also gives us all changes to the Microsoft OUI
5425 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5426 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5427 * changes to requested client power.
5429 * We implement beacon filtering in software since that means we can
5430 * avoid processing the frame here and in cfg80211, and userspace
5431 * will not be able to tell whether the hardware supports it or not.
5433 * XXX: This list needs to be dynamic -- userspace needs to be able to
5434 * add items it requires. It also needs to be able to tell us to
5435 * look out for other vendor IEs.
5437 static const u64 care_about_ies =
5438 (1ULL << WLAN_EID_COUNTRY) |
5439 (1ULL << WLAN_EID_ERP_INFO) |
5440 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5441 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5442 (1ULL << WLAN_EID_HT_CAPABILITY) |
5443 (1ULL << WLAN_EID_HT_OPERATION) |
5444 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5446 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5447 struct ieee80211_if_managed *ifmgd,
5448 struct ieee80211_bss_conf *bss_conf,
5449 struct ieee80211_local *local,
5450 struct ieee80211_rx_status *rx_status)
5452 struct ieee80211_sub_if_data *sdata = link->sdata;
5454 /* Track average RSSI from the Beacon frames of the current AP */
5456 if (!link->u.mgd.tracking_signal_avg) {
5457 link->u.mgd.tracking_signal_avg = true;
5458 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5459 link->u.mgd.last_cqm_event_signal = 0;
5460 link->u.mgd.count_beacon_signal = 1;
5461 link->u.mgd.last_ave_beacon_signal = 0;
5463 link->u.mgd.count_beacon_signal++;
5466 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5467 -rx_status->signal);
5469 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5470 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5471 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5472 int last_sig = link->u.mgd.last_ave_beacon_signal;
5473 struct ieee80211_event event = {
5478 * if signal crosses either of the boundaries, invoke callback
5479 * with appropriate parameters
5481 if (sig > ifmgd->rssi_max_thold &&
5482 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5483 link->u.mgd.last_ave_beacon_signal = sig;
5484 event.u.rssi.data = RSSI_EVENT_HIGH;
5485 drv_event_callback(local, sdata, &event);
5486 } else if (sig < ifmgd->rssi_min_thold &&
5487 (last_sig >= ifmgd->rssi_max_thold ||
5489 link->u.mgd.last_ave_beacon_signal = sig;
5490 event.u.rssi.data = RSSI_EVENT_LOW;
5491 drv_event_callback(local, sdata, &event);
5495 if (bss_conf->cqm_rssi_thold &&
5496 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5497 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5498 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5499 int last_event = link->u.mgd.last_cqm_event_signal;
5500 int thold = bss_conf->cqm_rssi_thold;
5501 int hyst = bss_conf->cqm_rssi_hyst;
5504 (last_event == 0 || sig < last_event - hyst)) {
5505 link->u.mgd.last_cqm_event_signal = sig;
5506 ieee80211_cqm_rssi_notify(
5508 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5510 } else if (sig > thold &&
5511 (last_event == 0 || sig > last_event + hyst)) {
5512 link->u.mgd.last_cqm_event_signal = sig;
5513 ieee80211_cqm_rssi_notify(
5515 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5520 if (bss_conf->cqm_rssi_low &&
5521 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5522 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5523 int last_event = link->u.mgd.last_cqm_event_signal;
5524 int low = bss_conf->cqm_rssi_low;
5525 int high = bss_conf->cqm_rssi_high;
5528 (last_event == 0 || last_event >= low)) {
5529 link->u.mgd.last_cqm_event_signal = sig;
5530 ieee80211_cqm_rssi_notify(
5532 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5534 } else if (sig > high &&
5535 (last_event == 0 || last_event <= high)) {
5536 link->u.mgd.last_cqm_event_signal = sig;
5537 ieee80211_cqm_rssi_notify(
5539 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5545 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5546 struct cfg80211_bss *bss)
5548 if (ether_addr_equal(tx_bssid, bss->bssid))
5550 if (!bss->transmitted_bss)
5552 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5555 static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
5556 const struct ieee80211_eht_operation *eht_oper,
5559 u16 bitmap = 0, extracted;
5561 if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
5563 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
5564 const struct ieee80211_eht_operation_info *info =
5565 (void *)eht_oper->optional;
5566 const u8 *disable_subchannel_bitmap = info->optional;
5568 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
5571 extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
5572 &link->conf->chandef,
5575 /* accept if there are no changes */
5576 if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
5577 extracted == link->conf->eht_puncturing)
5580 if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
5581 &link->conf->chandef)) {
5583 "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
5586 link->conf->chandef.width);
5590 ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
5594 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
5595 struct ieee80211_hdr *hdr, size_t len,
5596 struct ieee80211_rx_status *rx_status)
5598 struct ieee80211_sub_if_data *sdata = link->sdata;
5599 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5600 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
5601 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
5602 struct ieee80211_mgmt *mgmt = (void *) hdr;
5604 struct ieee802_11_elems *elems;
5605 struct ieee80211_local *local = sdata->local;
5606 struct ieee80211_chanctx_conf *chanctx_conf;
5607 struct ieee80211_supported_band *sband;
5608 struct ieee80211_channel *chan;
5609 struct link_sta_info *link_sta;
5610 struct sta_info *sta;
5615 u8 *bssid, *variable = mgmt->u.beacon.variable;
5616 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
5617 struct ieee80211_elems_parse_params parse_params = {
5622 sdata_assert_lock(sdata);
5624 /* Process beacon from the current BSS */
5625 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
5626 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
5627 struct ieee80211_ext *ext = (void *) mgmt;
5629 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
5630 variable = ext->u.s1g_short_beacon.variable;
5632 variable = ext->u.s1g_beacon.variable;
5635 baselen = (u8 *) variable - (u8 *) mgmt;
5639 parse_params.start = variable;
5640 parse_params.len = len - baselen;
5643 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
5644 if (!chanctx_conf) {
5649 if (ieee80211_rx_status_to_khz(rx_status) !=
5650 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
5654 chan = chanctx_conf->def.chan;
5657 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
5658 !WARN_ON(sdata->vif.valid_links) &&
5659 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
5660 parse_params.bss = ifmgd->assoc_data->link[0].bss;
5661 elems = ieee802_11_parse_elems_full(&parse_params);
5665 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5667 if (elems->dtim_period)
5668 link->u.mgd.dtim_period = elems->dtim_period;
5669 link->u.mgd.have_beacon = true;
5670 ifmgd->assoc_data->need_beacon = false;
5671 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
5672 link->conf->sync_tsf =
5673 le64_to_cpu(mgmt->u.beacon.timestamp);
5674 link->conf->sync_device_ts =
5675 rx_status->device_timestamp;
5676 link->conf->sync_dtim_count = elems->dtim_count;
5679 if (elems->mbssid_config_ie)
5680 bss_conf->profile_periodicity =
5681 elems->mbssid_config_ie->profile_periodicity;
5683 bss_conf->profile_periodicity = 0;
5685 if (elems->ext_capab_len >= 11 &&
5686 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
5687 bss_conf->ema_ap = true;
5689 bss_conf->ema_ap = false;
5691 /* continue assoc process */
5692 ifmgd->assoc_data->timeout = jiffies;
5693 ifmgd->assoc_data->timeout_started = true;
5694 run_again(sdata, ifmgd->assoc_data->timeout);
5699 if (!ifmgd->associated ||
5700 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
5702 bssid = link->u.mgd.bssid;
5704 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
5705 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
5708 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
5709 mlme_dbg_ratelimited(sdata,
5710 "cancelling AP probe due to a received beacon\n");
5711 ieee80211_reset_ap_probe(sdata);
5715 * Push the beacon loss detection into the future since
5716 * we are processing a beacon from the AP just now.
5718 ieee80211_sta_reset_beacon_monitor(sdata);
5720 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
5721 * element (which carries the beacon interval). Don't forget to add a
5722 * bit to care_about_ies[] above if mac80211 is interested in a
5723 * changing S1G element.
5725 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5726 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
5727 parse_params.bss = link->u.mgd.bss;
5728 parse_params.filter = care_about_ies;
5729 parse_params.crc = ncrc;
5730 elems = ieee802_11_parse_elems_full(&parse_params);
5735 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
5736 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
5737 if (local->hw.conf.dynamic_ps_timeout > 0) {
5738 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
5739 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
5740 ieee80211_hw_config(local,
5741 IEEE80211_CONF_CHANGE_PS);
5743 ieee80211_send_nullfunc(local, sdata, false);
5744 } else if (!local->pspolling && sdata->u.mgd.powersave) {
5745 local->pspolling = true;
5748 * Here is assumed that the driver will be
5749 * able to send ps-poll frame and receive a
5750 * response even though power save mode is
5751 * enabled, but some drivers might require
5752 * to disable power save here. This needs
5753 * to be investigated.
5755 ieee80211_send_pspoll(local, sdata);
5759 if (sdata->vif.p2p ||
5760 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
5761 struct ieee80211_p2p_noa_attr noa = {};
5764 ret = cfg80211_get_p2p_attr(variable,
5766 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
5767 (u8 *) &noa, sizeof(noa));
5769 if (link->u.mgd.p2p_noa_index != noa.index) {
5770 /* valid noa_attr and index changed */
5771 link->u.mgd.p2p_noa_index = noa.index;
5772 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
5773 changed |= BSS_CHANGED_P2P_PS;
5775 * make sure we update all information, the CRC
5776 * mechanism doesn't look at P2P attributes.
5778 link->u.mgd.beacon_crc_valid = false;
5780 } else if (link->u.mgd.p2p_noa_index != -1) {
5781 /* noa_attr not found and we had valid noa_attr before */
5782 link->u.mgd.p2p_noa_index = -1;
5783 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
5784 changed |= BSS_CHANGED_P2P_PS;
5785 link->u.mgd.beacon_crc_valid = false;
5789 if (link->u.mgd.csa_waiting_bcn)
5790 ieee80211_chswitch_post_beacon(link);
5793 * Update beacon timing and dtim count on every beacon appearance. This
5794 * will allow the driver to use the most updated values. Do it before
5795 * comparing this one with last received beacon.
5796 * IMPORTANT: These parameters would possibly be out of sync by the time
5797 * the driver will use them. The synchronized view is currently
5798 * guaranteed only in certain callbacks.
5800 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
5801 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
5802 link->conf->sync_tsf =
5803 le64_to_cpu(mgmt->u.beacon.timestamp);
5804 link->conf->sync_device_ts =
5805 rx_status->device_timestamp;
5806 link->conf->sync_dtim_count = elems->dtim_count;
5809 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
5810 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
5812 link->u.mgd.beacon_crc = ncrc;
5813 link->u.mgd.beacon_crc_valid = true;
5815 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5817 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
5818 rx_status->device_timestamp,
5821 if (!link->u.mgd.disable_wmm_tracking &&
5822 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
5823 elems->wmm_param_len,
5824 elems->mu_edca_param_set))
5825 changed |= BSS_CHANGED_QOS;
5828 * If we haven't had a beacon before, tell the driver about the
5829 * DTIM period (and beacon timing if desired) now.
5831 if (!link->u.mgd.have_beacon) {
5832 /* a few bogus AP send dtim_period = 0 or no TIM IE */
5833 bss_conf->dtim_period = elems->dtim_period ?: 1;
5835 changed |= BSS_CHANGED_BEACON_INFO;
5836 link->u.mgd.have_beacon = true;
5838 mutex_lock(&local->iflist_mtx);
5839 ieee80211_recalc_ps(local);
5840 mutex_unlock(&local->iflist_mtx);
5842 ieee80211_recalc_ps_vif(sdata);
5845 if (elems->erp_info) {
5847 erp_value = elems->erp_info[0];
5852 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
5853 changed |= ieee80211_handle_bss_capability(link,
5854 le16_to_cpu(mgmt->u.beacon.capab_info),
5855 erp_valid, erp_value);
5857 mutex_lock(&local->sta_mtx);
5858 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
5859 if (WARN_ON(!sta)) {
5860 mutex_unlock(&local->sta_mtx);
5863 link_sta = rcu_dereference_protected(sta->link[link->link_id],
5864 lockdep_is_held(&local->sta_mtx));
5865 if (WARN_ON(!link_sta)) {
5866 mutex_unlock(&local->sta_mtx);
5870 if (WARN_ON(!link->conf->chandef.chan))
5873 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
5875 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
5877 if (ieee80211_config_bw(link, elems->ht_cap_elem,
5878 elems->vht_cap_elem, elems->ht_operation,
5879 elems->vht_operation, elems->he_operation,
5880 elems->eht_operation,
5881 elems->s1g_oper, bssid, &changed)) {
5882 mutex_unlock(&local->sta_mtx);
5884 "failed to follow AP %pM bandwidth change, disconnect\n",
5886 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5887 WLAN_REASON_DEAUTH_LEAVING,
5889 ieee80211_report_disconnect(sdata, deauth_buf,
5890 sizeof(deauth_buf), true,
5891 WLAN_REASON_DEAUTH_LEAVING,
5896 if (elems->opmode_notif)
5897 ieee80211_vht_handle_opmode(sdata, link_sta,
5898 *elems->opmode_notif,
5900 mutex_unlock(&local->sta_mtx);
5902 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
5903 elems->country_elem,
5904 elems->country_elem_len,
5905 elems->pwr_constr_elem,
5906 elems->cisco_dtpc_elem);
5908 if (elems->eht_operation &&
5909 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
5910 if (!ieee80211_config_puncturing(link, elems->eht_operation,
5912 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
5913 WLAN_REASON_DEAUTH_LEAVING,
5915 ieee80211_report_disconnect(sdata, deauth_buf,
5916 sizeof(deauth_buf), true,
5917 WLAN_REASON_DEAUTH_LEAVING,
5923 ieee80211_link_info_change_notify(sdata, link, changed);
5928 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
5929 struct sk_buff *skb)
5931 struct ieee80211_link_data *link = &sdata->deflink;
5932 struct ieee80211_rx_status *rx_status;
5933 struct ieee80211_hdr *hdr;
5936 rx_status = (struct ieee80211_rx_status *) skb->cb;
5937 hdr = (struct ieee80211_hdr *) skb->data;
5938 fc = le16_to_cpu(hdr->frame_control);
5941 switch (fc & IEEE80211_FCTL_STYPE) {
5942 case IEEE80211_STYPE_S1G_BEACON:
5943 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
5946 sdata_unlock(sdata);
5949 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
5950 struct sk_buff *skb)
5952 struct ieee80211_link_data *link = &sdata->deflink;
5953 struct ieee80211_rx_status *rx_status;
5954 struct ieee80211_mgmt *mgmt;
5958 rx_status = (struct ieee80211_rx_status *) skb->cb;
5959 mgmt = (struct ieee80211_mgmt *) skb->data;
5960 fc = le16_to_cpu(mgmt->frame_control);
5964 if (rx_status->link_valid) {
5965 link = sdata_dereference(sdata->link[rx_status->link_id],
5971 switch (fc & IEEE80211_FCTL_STYPE) {
5972 case IEEE80211_STYPE_BEACON:
5973 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
5974 skb->len, rx_status);
5976 case IEEE80211_STYPE_PROBE_RESP:
5977 ieee80211_rx_mgmt_probe_resp(link, skb);
5979 case IEEE80211_STYPE_AUTH:
5980 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
5982 case IEEE80211_STYPE_DEAUTH:
5983 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
5985 case IEEE80211_STYPE_DISASSOC:
5986 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
5988 case IEEE80211_STYPE_ASSOC_RESP:
5989 case IEEE80211_STYPE_REASSOC_RESP:
5990 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
5992 case IEEE80211_STYPE_ACTION:
5993 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
5994 struct ieee802_11_elems *elems;
5996 ies_len = skb->len -
5997 offsetof(struct ieee80211_mgmt,
5998 u.action.u.chan_switch.variable);
6003 /* CSA IE cannot be overridden, no need for BSSID */
6004 elems = ieee802_11_parse_elems(
6005 mgmt->u.action.u.chan_switch.variable,
6006 ies_len, true, NULL);
6008 if (elems && !elems->parse_error)
6009 ieee80211_sta_process_chanswitch(link,
6011 rx_status->device_timestamp,
6014 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
6015 struct ieee802_11_elems *elems;
6017 ies_len = skb->len -
6018 offsetof(struct ieee80211_mgmt,
6019 u.action.u.ext_chan_switch.variable);
6025 * extended CSA IE can't be overridden, no need for
6028 elems = ieee802_11_parse_elems(
6029 mgmt->u.action.u.ext_chan_switch.variable,
6030 ies_len, true, NULL);
6032 if (elems && !elems->parse_error) {
6033 /* for the handling code pretend it was an IE */
6034 elems->ext_chansw_ie =
6035 &mgmt->u.action.u.ext_chan_switch.data;
6037 ieee80211_sta_process_chanswitch(link,
6039 rx_status->device_timestamp,
6048 sdata_unlock(sdata);
6051 static void ieee80211_sta_timer(struct timer_list *t)
6053 struct ieee80211_sub_if_data *sdata =
6054 from_timer(sdata, t, u.mgd.timer);
6056 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
6059 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6062 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6064 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6067 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6071 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
6073 struct ieee80211_local *local = sdata->local;
6074 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6075 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
6079 struct ieee80211_prep_tx_info info = {
6080 .subtype = IEEE80211_STYPE_AUTH,
6083 sdata_assert_lock(sdata);
6085 if (WARN_ON_ONCE(!auth_data))
6090 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
6091 sdata_info(sdata, "authentication with %pM timed out\n",
6092 auth_data->ap_addr);
6095 * Most likely AP is not in the range so remove the
6096 * bss struct for that AP.
6098 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
6103 if (auth_data->algorithm == WLAN_AUTH_SAE)
6104 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
6106 drv_mgd_prepare_tx(local, sdata, &info);
6108 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
6109 auth_data->ap_addr, auth_data->tries,
6110 IEEE80211_AUTH_MAX_TRIES);
6112 auth_data->expected_transaction = 2;
6114 if (auth_data->algorithm == WLAN_AUTH_SAE) {
6115 trans = auth_data->sae_trans;
6116 status = auth_data->sae_status;
6117 auth_data->expected_transaction = trans;
6120 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6121 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
6122 IEEE80211_TX_INTFL_MLME_CONN_TX;
6124 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
6125 auth_data->data, auth_data->data_len,
6126 auth_data->ap_addr, auth_data->ap_addr,
6127 NULL, 0, 0, tx_flags);
6129 if (tx_flags == 0) {
6130 if (auth_data->algorithm == WLAN_AUTH_SAE)
6131 auth_data->timeout = jiffies +
6132 IEEE80211_AUTH_TIMEOUT_SAE;
6134 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6136 auth_data->timeout =
6137 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6140 auth_data->timeout_started = true;
6141 run_again(sdata, auth_data->timeout);
6146 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6148 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6149 struct ieee80211_local *local = sdata->local;
6152 sdata_assert_lock(sdata);
6154 assoc_data->tries++;
6155 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6156 sdata_info(sdata, "association with %pM timed out\n",
6157 assoc_data->ap_addr);
6160 * Most likely AP is not in the range so remove the
6161 * bss struct for that AP.
6163 cfg80211_unlink_bss(local->hw.wiphy,
6164 assoc_data->link[assoc_data->assoc_link_id].bss);
6169 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6170 assoc_data->ap_addr, assoc_data->tries,
6171 IEEE80211_ASSOC_MAX_TRIES);
6172 ret = ieee80211_send_assoc(sdata);
6176 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6177 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6178 assoc_data->timeout_started = true;
6179 run_again(sdata, assoc_data->timeout);
6181 assoc_data->timeout =
6182 round_jiffies_up(jiffies +
6183 IEEE80211_ASSOC_TIMEOUT_LONG);
6184 assoc_data->timeout_started = true;
6185 run_again(sdata, assoc_data->timeout);
6191 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6192 __le16 fc, bool acked)
6194 struct ieee80211_local *local = sdata->local;
6196 sdata->u.mgd.status_fc = fc;
6197 sdata->u.mgd.status_acked = acked;
6198 sdata->u.mgd.status_received = true;
6200 ieee80211_queue_work(&local->hw, &sdata->work);
6203 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6205 struct ieee80211_local *local = sdata->local;
6206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6210 if (ifmgd->status_received) {
6211 __le16 fc = ifmgd->status_fc;
6212 bool status_acked = ifmgd->status_acked;
6214 ifmgd->status_received = false;
6215 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6217 if (ifmgd->auth_data->algorithm ==
6219 ifmgd->auth_data->timeout =
6221 IEEE80211_AUTH_TIMEOUT_SAE;
6223 ifmgd->auth_data->timeout =
6225 IEEE80211_AUTH_TIMEOUT_SHORT;
6226 run_again(sdata, ifmgd->auth_data->timeout);
6228 ifmgd->auth_data->timeout = jiffies - 1;
6230 ifmgd->auth_data->timeout_started = true;
6231 } else if (ifmgd->assoc_data &&
6232 (ieee80211_is_assoc_req(fc) ||
6233 ieee80211_is_reassoc_req(fc))) {
6235 ifmgd->assoc_data->timeout =
6236 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6237 run_again(sdata, ifmgd->assoc_data->timeout);
6239 ifmgd->assoc_data->timeout = jiffies - 1;
6241 ifmgd->assoc_data->timeout_started = true;
6245 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6246 time_after(jiffies, ifmgd->auth_data->timeout)) {
6247 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6249 * ok ... we waited for assoc or continuation but
6250 * userspace didn't do it, so kill the auth data
6252 ieee80211_destroy_auth_data(sdata, false);
6253 } else if (ieee80211_auth(sdata)) {
6254 u8 ap_addr[ETH_ALEN];
6255 struct ieee80211_event event = {
6257 .u.mlme.data = AUTH_EVENT,
6258 .u.mlme.status = MLME_TIMEOUT,
6261 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6263 ieee80211_destroy_auth_data(sdata, false);
6265 cfg80211_auth_timeout(sdata->dev, ap_addr);
6266 drv_event_callback(sdata->local, sdata, &event);
6268 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6269 run_again(sdata, ifmgd->auth_data->timeout);
6271 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6272 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6273 if ((ifmgd->assoc_data->need_beacon &&
6274 !sdata->deflink.u.mgd.have_beacon) ||
6275 ieee80211_do_assoc(sdata)) {
6276 struct ieee80211_event event = {
6278 .u.mlme.data = ASSOC_EVENT,
6279 .u.mlme.status = MLME_TIMEOUT,
6282 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6283 drv_event_callback(sdata->local, sdata, &event);
6285 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6286 run_again(sdata, ifmgd->assoc_data->timeout);
6288 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6289 ifmgd->associated) {
6290 u8 *bssid = sdata->deflink.u.mgd.bssid;
6293 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6294 max_tries = max_nullfunc_tries;
6296 max_tries = max_probe_tries;
6298 /* ACK received for nullfunc probing frame */
6299 if (!ifmgd->probe_send_count)
6300 ieee80211_reset_ap_probe(sdata);
6301 else if (ifmgd->nullfunc_failed) {
6302 if (ifmgd->probe_send_count < max_tries) {
6304 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6305 bssid, ifmgd->probe_send_count,
6307 ieee80211_mgd_probe_ap_send(sdata);
6310 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6312 ieee80211_sta_connection_lost(sdata,
6313 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6316 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6317 run_again(sdata, ifmgd->probe_timeout);
6318 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6320 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6321 bssid, probe_wait_ms);
6322 ieee80211_sta_connection_lost(sdata,
6323 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6324 } else if (ifmgd->probe_send_count < max_tries) {
6326 "No probe response from AP %pM after %dms, try %d/%i\n",
6327 bssid, probe_wait_ms,
6328 ifmgd->probe_send_count, max_tries);
6329 ieee80211_mgd_probe_ap_send(sdata);
6332 * We actually lost the connection ... or did we?
6336 "No probe response from AP %pM after %dms, disconnecting.\n",
6337 bssid, probe_wait_ms);
6339 ieee80211_sta_connection_lost(sdata,
6340 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6344 sdata_unlock(sdata);
6347 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6349 struct ieee80211_sub_if_data *sdata =
6350 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6352 if (WARN_ON(sdata->vif.valid_links))
6355 if (sdata->vif.bss_conf.csa_active &&
6356 !sdata->deflink.u.mgd.csa_waiting_bcn)
6359 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6362 sdata->u.mgd.connection_loss = false;
6363 ieee80211_queue_work(&sdata->local->hw,
6364 &sdata->u.mgd.beacon_connection_loss_work);
6367 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6369 struct ieee80211_sub_if_data *sdata =
6370 from_timer(sdata, t, u.mgd.conn_mon_timer);
6371 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6372 struct ieee80211_local *local = sdata->local;
6373 struct sta_info *sta;
6374 unsigned long timeout;
6376 if (WARN_ON(sdata->vif.valid_links))
6379 if (sdata->vif.bss_conf.csa_active &&
6380 !sdata->deflink.u.mgd.csa_waiting_bcn)
6383 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6387 timeout = sta->deflink.status_stats.last_ack;
6388 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6389 timeout = sta->deflink.rx_stats.last_rx;
6390 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6392 /* If timeout is after now, then update timer to fire at
6393 * the later date, but do not actually probe at this time.
6395 if (time_is_after_jiffies(timeout)) {
6396 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6400 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
6403 static void ieee80211_sta_monitor_work(struct work_struct *work)
6405 struct ieee80211_sub_if_data *sdata =
6406 container_of(work, struct ieee80211_sub_if_data,
6407 u.mgd.monitor_work);
6409 ieee80211_mgd_probe_ap(sdata, false);
6412 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6414 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6415 __ieee80211_stop_poll(sdata);
6417 /* let's probe the connection once */
6418 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6419 ieee80211_queue_work(&sdata->local->hw,
6420 &sdata->u.mgd.monitor_work);
6425 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6427 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6428 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6432 if (ifmgd->auth_data || ifmgd->assoc_data) {
6433 const u8 *ap_addr = ifmgd->auth_data ?
6434 ifmgd->auth_data->ap_addr :
6435 ifmgd->assoc_data->ap_addr;
6438 * If we are trying to authenticate / associate while suspending,
6439 * cfg80211 won't know and won't actually abort those attempts,
6440 * thus we need to do that ourselves.
6442 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6443 IEEE80211_STYPE_DEAUTH,
6444 WLAN_REASON_DEAUTH_LEAVING,
6446 if (ifmgd->assoc_data)
6447 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6448 if (ifmgd->auth_data)
6449 ieee80211_destroy_auth_data(sdata, false);
6450 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6451 IEEE80211_DEAUTH_FRAME_LEN,
6455 /* This is a bit of a hack - we should find a better and more generic
6456 * solution to this. Normally when suspending, cfg80211 will in fact
6457 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6458 * auth (not so important) or assoc (this is the problem) process.
6460 * As a consequence, it can happen that we are in the process of both
6461 * associating and suspending, and receive an association response
6462 * after cfg80211 has checked if it needs to disconnect, but before
6463 * we actually set the flag to drop incoming frames. This will then
6464 * cause the workqueue flush to process the association response in
6465 * the suspend, resulting in a successful association just before it
6466 * tries to remove the interface from the driver, which now though
6467 * has a channel context assigned ... this results in issues.
6469 * To work around this (for now) simply deauth here again if we're
6472 if (ifmgd->associated && !sdata->local->wowlan) {
6474 struct cfg80211_deauth_request req = {
6475 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
6479 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
6480 ieee80211_mgd_deauth(sdata, &req);
6483 sdata_unlock(sdata);
6487 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
6489 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6492 if (!ifmgd->associated) {
6493 sdata_unlock(sdata);
6497 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
6498 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
6499 mlme_dbg(sdata, "driver requested disconnect after resume\n");
6500 ieee80211_sta_connection_lost(sdata,
6501 WLAN_REASON_UNSPECIFIED,
6503 sdata_unlock(sdata);
6507 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
6508 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
6509 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
6510 ieee80211_sta_connection_lost(sdata,
6511 WLAN_REASON_UNSPECIFIED,
6513 sdata_unlock(sdata);
6517 sdata_unlock(sdata);
6520 static void ieee80211_request_smps_mgd_work(struct work_struct *work)
6522 struct ieee80211_link_data *link =
6523 container_of(work, struct ieee80211_link_data,
6524 u.mgd.request_smps_work);
6526 sdata_lock(link->sdata);
6527 __ieee80211_request_smps_mgd(link->sdata, link,
6528 link->u.mgd.driver_smps_mode);
6529 sdata_unlock(link->sdata);
6532 /* interface setup */
6533 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
6535 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6537 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
6538 INIT_WORK(&ifmgd->beacon_connection_loss_work,
6539 ieee80211_beacon_connection_loss_work);
6540 INIT_WORK(&ifmgd->csa_connection_drop_work,
6541 ieee80211_csa_connection_drop_work);
6542 INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
6543 ieee80211_tdls_peer_del_work);
6544 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
6545 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
6546 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
6547 INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
6548 ieee80211_sta_handle_tspec_ac_params_wk);
6551 ifmgd->powersave = sdata->wdev.ps;
6552 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
6553 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
6554 /* Setup TDLS data */
6555 spin_lock_init(&ifmgd->teardown_lock);
6556 ifmgd->teardown_skb = NULL;
6557 ifmgd->orig_teardown_skb = NULL;
6560 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
6562 struct ieee80211_sub_if_data *sdata = link->sdata;
6563 struct ieee80211_local *local = sdata->local;
6564 unsigned int link_id = link->link_id;
6566 link->u.mgd.p2p_noa_index = -1;
6567 link->u.mgd.conn_flags = 0;
6568 link->conf->bssid = link->u.mgd.bssid;
6570 INIT_WORK(&link->u.mgd.request_smps_work,
6571 ieee80211_request_smps_mgd_work);
6572 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
6573 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
6575 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
6577 INIT_WORK(&link->u.mgd.chswitch_work, ieee80211_chswitch_work);
6578 timer_setup(&link->u.mgd.chswitch_timer, ieee80211_chswitch_timer, 0);
6580 if (sdata->u.mgd.assoc_data)
6581 ether_addr_copy(link->conf->addr,
6582 sdata->u.mgd.assoc_data->link[link_id].addr);
6583 else if (!is_valid_ether_addr(link->conf->addr))
6584 eth_random_addr(link->conf->addr);
6587 /* scan finished notification */
6588 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
6590 struct ieee80211_sub_if_data *sdata;
6592 /* Restart STA timers */
6594 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
6595 if (ieee80211_sdata_running(sdata))
6596 ieee80211_restart_sta_timer(sdata);
6601 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
6602 struct cfg80211_bss *cbss, s8 link_id,
6603 const u8 *ap_mld_addr, bool assoc,
6606 struct ieee80211_local *local = sdata->local;
6607 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6608 struct ieee80211_bss *bss = (void *)cbss->priv;
6609 struct sta_info *new_sta = NULL;
6610 struct ieee80211_link_data *link;
6611 bool have_sta = false;
6617 if (WARN_ON(!ap_mld_addr))
6619 err = ieee80211_vif_set_links(sdata, BIT(link_id));
6621 if (WARN_ON(ap_mld_addr))
6623 ap_mld_addr = cbss->bssid;
6624 err = ieee80211_vif_set_links(sdata, 0);
6632 link = sdata_dereference(sdata->link[link_id], sdata);
6633 if (WARN_ON(!link)) {
6638 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
6643 /* If a reconfig is happening, bail out */
6644 if (local->in_reconfig) {
6651 have_sta = sta_info_get(sdata, ap_mld_addr);
6657 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
6658 link_id, cbss->bssid,
6661 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
6668 new_sta->sta.mlo = mlo;
6672 * Set up the information for the new channel before setting the
6673 * new channel. We can't - completely race-free - change the basic
6674 * rates bitmap and the channel (sband) that it refers to, but if
6675 * we set it up before we at least avoid calling into the driver's
6676 * bss_info_changed() method with invalid information (since we do
6677 * call that from changing the channel - only for IDLE and perhaps
6678 * some others, but ...).
6680 * So to avoid that, just set up all the new information before the
6681 * channel, but tell the driver to apply it only afterwards, since
6682 * it might need the new channel for that.
6685 const struct cfg80211_bss_ies *ies;
6686 struct link_sta_info *link_sta;
6689 link_sta = rcu_dereference(new_sta->link[link_id]);
6690 if (WARN_ON(!link_sta)) {
6692 sta_info_free(local, new_sta);
6697 err = ieee80211_mgd_setup_link_sta(link, new_sta,
6701 sta_info_free(local, new_sta);
6705 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
6707 /* set timing information */
6708 link->conf->beacon_int = cbss->beacon_interval;
6709 ies = rcu_dereference(cbss->beacon_ies);
6711 link->conf->sync_tsf = ies->tsf;
6712 link->conf->sync_device_ts =
6713 bss->device_ts_beacon;
6715 ieee80211_get_dtim(ies,
6716 &link->conf->sync_dtim_count,
6718 } else if (!ieee80211_hw_check(&sdata->local->hw,
6719 TIMING_BEACON_ONLY)) {
6720 ies = rcu_dereference(cbss->proberesp_ies);
6721 /* must be non-NULL since beacon IEs were NULL */
6722 link->conf->sync_tsf = ies->tsf;
6723 link->conf->sync_device_ts =
6724 bss->device_ts_presp;
6725 link->conf->sync_dtim_count = 0;
6727 link->conf->sync_tsf = 0;
6728 link->conf->sync_device_ts = 0;
6729 link->conf->sync_dtim_count = 0;
6734 if (new_sta || override) {
6735 err = ieee80211_prep_channel(sdata, link, cbss,
6736 &link->u.mgd.conn_flags);
6739 sta_info_free(local, new_sta);
6746 * tell driver about BSSID, basic rates and timing
6747 * this was set up above, before setting the channel
6749 ieee80211_link_info_change_notify(sdata, link,
6751 BSS_CHANGED_BASIC_RATES |
6752 BSS_CHANGED_BEACON_INT);
6755 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
6757 err = sta_info_insert(new_sta);
6761 "failed to insert STA entry for the AP (error %d)\n",
6766 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
6768 /* Cancel scan to ensure that nothing interferes with connection */
6769 if (local->scanning)
6770 ieee80211_scan_cancel(local);
6775 ieee80211_link_release_channel(&sdata->deflink);
6776 ieee80211_vif_set_links(sdata, 0);
6781 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
6782 struct cfg80211_auth_request *req)
6784 struct ieee80211_local *local = sdata->local;
6785 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6786 struct ieee80211_mgd_auth_data *auth_data;
6791 /* prepare auth data structure */
6793 switch (req->auth_type) {
6794 case NL80211_AUTHTYPE_OPEN_SYSTEM:
6795 auth_alg = WLAN_AUTH_OPEN;
6797 case NL80211_AUTHTYPE_SHARED_KEY:
6800 auth_alg = WLAN_AUTH_SHARED_KEY;
6802 case NL80211_AUTHTYPE_FT:
6803 auth_alg = WLAN_AUTH_FT;
6805 case NL80211_AUTHTYPE_NETWORK_EAP:
6806 auth_alg = WLAN_AUTH_LEAP;
6808 case NL80211_AUTHTYPE_SAE:
6809 auth_alg = WLAN_AUTH_SAE;
6811 case NL80211_AUTHTYPE_FILS_SK:
6812 auth_alg = WLAN_AUTH_FILS_SK;
6814 case NL80211_AUTHTYPE_FILS_SK_PFS:
6815 auth_alg = WLAN_AUTH_FILS_SK_PFS;
6817 case NL80211_AUTHTYPE_FILS_PK:
6818 auth_alg = WLAN_AUTH_FILS_PK;
6824 if (ifmgd->assoc_data)
6827 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
6828 req->ie_len, GFP_KERNEL);
6832 memcpy(auth_data->ap_addr,
6833 req->ap_mld_addr ?: req->bss->bssid,
6835 auth_data->bss = req->bss;
6836 auth_data->link_id = req->link_id;
6838 if (req->auth_data_len >= 4) {
6839 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
6840 __le16 *pos = (__le16 *) req->auth_data;
6842 auth_data->sae_trans = le16_to_cpu(pos[0]);
6843 auth_data->sae_status = le16_to_cpu(pos[1]);
6845 memcpy(auth_data->data, req->auth_data + 4,
6846 req->auth_data_len - 4);
6847 auth_data->data_len += req->auth_data_len - 4;
6850 /* Check if continuing authentication or trying to authenticate with the
6851 * same BSS that we were in the process of authenticating with and avoid
6852 * removal and re-addition of the STA entry in
6853 * ieee80211_prep_connection().
6855 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
6856 ifmgd->auth_data->link_id == req->link_id;
6858 if (req->ie && req->ie_len) {
6859 memcpy(&auth_data->data[auth_data->data_len],
6860 req->ie, req->ie_len);
6861 auth_data->data_len += req->ie_len;
6864 if (req->key && req->key_len) {
6865 auth_data->key_len = req->key_len;
6866 auth_data->key_idx = req->key_idx;
6867 memcpy(auth_data->key, req->key, req->key_len);
6870 auth_data->algorithm = auth_alg;
6872 /* try to authenticate/probe */
6874 if (ifmgd->auth_data) {
6875 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
6876 auth_data->peer_confirmed =
6877 ifmgd->auth_data->peer_confirmed;
6879 ieee80211_destroy_auth_data(sdata, cont_auth);
6882 /* prep auth_data so we don't go into idle on disassoc */
6883 ifmgd->auth_data = auth_data;
6885 /* If this is continuation of an ongoing SAE authentication exchange
6886 * (i.e., request to send SAE Confirm) and the peer has already
6887 * confirmed, mark authentication completed since we are about to send
6890 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
6891 auth_data->peer_confirmed && auth_data->sae_trans == 2)
6892 ieee80211_mark_sta_auth(sdata);
6894 if (ifmgd->associated) {
6895 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6898 "disconnect from AP %pM for new auth to %pM\n",
6899 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
6900 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6901 WLAN_REASON_UNSPECIFIED,
6904 ieee80211_report_disconnect(sdata, frame_buf,
6905 sizeof(frame_buf), true,
6906 WLAN_REASON_UNSPECIFIED,
6910 sdata_info(sdata, "authenticate with %pM\n", auth_data->ap_addr);
6912 /* needed for transmitting the auth frame(s) properly */
6913 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
6915 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
6916 req->ap_mld_addr, cont_auth, false);
6920 err = ieee80211_auth(sdata);
6922 sta_info_destroy_addr(sdata, auth_data->ap_addr);
6926 /* hold our own reference */
6927 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
6931 if (!sdata->vif.valid_links) {
6932 eth_zero_addr(sdata->deflink.u.mgd.bssid);
6933 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
6935 mutex_lock(&sdata->local->mtx);
6936 ieee80211_link_release_channel(&sdata->deflink);
6937 mutex_unlock(&sdata->local->mtx);
6939 ifmgd->auth_data = NULL;
6944 static ieee80211_conn_flags_t
6945 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
6946 struct ieee80211_mgd_assoc_data *assoc_data,
6947 struct cfg80211_assoc_request *req,
6948 ieee80211_conn_flags_t conn_flags,
6949 unsigned int link_id)
6951 struct ieee80211_local *local = sdata->local;
6952 const struct cfg80211_bss_ies *beacon_ies;
6953 struct ieee80211_supported_band *sband;
6954 const struct element *ht_elem, *vht_elem;
6955 struct ieee80211_link_data *link;
6956 struct cfg80211_bss *cbss;
6957 struct ieee80211_bss *bss;
6958 bool is_5ghz, is_6ghz;
6960 cbss = assoc_data->link[link_id].bss;
6964 bss = (void *)cbss->priv;
6966 sband = local->hw.wiphy->bands[cbss->channel->band];
6967 if (WARN_ON(!sband))
6970 link = sdata_dereference(sdata->link[link_id], sdata);
6974 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
6975 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
6977 /* for MLO connections assume advertising all rates is OK */
6978 if (!req->ap_mld_addr) {
6979 assoc_data->supp_rates = bss->supp_rates;
6980 assoc_data->supp_rates_len = bss->supp_rates_len;
6983 /* copy and link elems for the STA profile */
6984 if (req->links[link_id].elems_len) {
6985 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
6986 req->links[link_id].elems_len);
6987 assoc_data->link[link_id].elems = assoc_data->ie_pos;
6988 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
6989 assoc_data->ie_pos += req->links[link_id].elems_len;
6993 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
6994 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
6995 assoc_data->link[link_id].ap_ht_param =
6996 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
6998 conn_flags |= IEEE80211_CONN_DISABLE_HT;
6999 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
7000 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
7001 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
7002 sizeof(struct ieee80211_vht_cap));
7003 } else if (is_5ghz) {
7005 "VHT capa missing/short, disabling VHT/HE/EHT\n");
7006 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
7007 IEEE80211_CONN_DISABLE_HE |
7008 IEEE80211_CONN_DISABLE_EHT;
7012 link->u.mgd.beacon_crc_valid = false;
7013 link->u.mgd.dtim_period = 0;
7014 link->u.mgd.have_beacon = false;
7016 /* override HT/VHT configuration only if the AP and we support it */
7017 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
7018 struct ieee80211_sta_ht_cap sta_ht_cap;
7020 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
7021 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
7024 link->conf->eht_puncturing = 0;
7027 beacon_ies = rcu_dereference(cbss->beacon_ies);
7029 const struct ieee80211_eht_operation *eht_oper;
7030 const struct element *elem;
7033 ieee80211_get_dtim(beacon_ies, &dtim_count,
7034 &link->u.mgd.dtim_period);
7036 sdata->deflink.u.mgd.have_beacon = true;
7038 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
7039 link->conf->sync_tsf = beacon_ies->tsf;
7040 link->conf->sync_device_ts = bss->device_ts_beacon;
7041 link->conf->sync_dtim_count = dtim_count;
7044 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
7045 beacon_ies->data, beacon_ies->len);
7046 if (elem && elem->datalen >= 3)
7047 link->conf->profile_periodicity = elem->data[2];
7049 link->conf->profile_periodicity = 0;
7051 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
7052 beacon_ies->data, beacon_ies->len);
7053 if (elem && elem->datalen >= 11 &&
7054 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7055 link->conf->ema_ap = true;
7057 link->conf->ema_ap = false;
7059 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
7060 beacon_ies->data, beacon_ies->len);
7061 eht_oper = (const void *)(elem->data + 1);
7064 ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
7065 elem->datalen - 1) &&
7066 (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
7067 (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
7068 const struct ieee80211_eht_operation_info *info =
7069 (void *)eht_oper->optional;
7070 const u8 *disable_subchannel_bitmap = info->optional;
7073 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
7074 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
7075 &link->conf->chandef))
7076 ieee80211_handle_puncturing_bitmap(link,
7081 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7086 if (bss->corrupt_data) {
7087 char *corrupt_type = "data";
7089 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
7090 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
7091 corrupt_type = "beacon and probe response";
7093 corrupt_type = "beacon";
7094 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
7095 corrupt_type = "probe response";
7097 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
7098 cbss->bssid, corrupt_type);
7101 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
7102 if (sdata->u.mgd.powersave)
7103 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
7105 link->smps_mode = IEEE80211_SMPS_OFF;
7107 link->smps_mode = link->u.mgd.req_smps;
7113 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
7114 struct cfg80211_assoc_request *req)
7116 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
7117 struct ieee80211_local *local = sdata->local;
7118 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7119 struct ieee80211_mgd_assoc_data *assoc_data;
7120 const struct element *ssid_elem;
7121 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
7122 ieee80211_conn_flags_t conn_flags = 0;
7123 struct ieee80211_link_data *link;
7124 struct cfg80211_bss *cbss;
7125 struct ieee80211_bss *bss;
7128 size_t size = sizeof(*assoc_data) + req->ie_len;
7130 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
7131 size += req->links[i].elems_len;
7133 /* FIXME: no support for 4-addr MLO yet */
7134 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
7137 assoc_data = kzalloc(size, GFP_KERNEL);
7141 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
7144 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
7145 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
7150 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
7151 assoc_data->ssid_len = ssid_elem->datalen;
7152 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
7153 vif_cfg->ssid_len = assoc_data->ssid_len;
7156 if (req->ap_mld_addr) {
7157 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7158 if (!req->links[i].bss)
7160 link = sdata_dereference(sdata->link[i], sdata);
7162 ether_addr_copy(assoc_data->link[i].addr,
7165 eth_random_addr(assoc_data->link[i].addr);
7168 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7171 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7173 memcpy(assoc_data->ap_addr,
7174 req->ap_mld_addr ?: req->bss->bssid,
7177 if (ifmgd->associated) {
7178 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7181 "disconnect from AP %pM for new assoc to %pM\n",
7182 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7183 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7184 WLAN_REASON_UNSPECIFIED,
7187 ieee80211_report_disconnect(sdata, frame_buf,
7188 sizeof(frame_buf), true,
7189 WLAN_REASON_UNSPECIFIED,
7193 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7198 if (ifmgd->assoc_data) {
7203 if (ifmgd->auth_data) {
7206 /* keep sta info, bssid if matching */
7207 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7208 assoc_data->ap_addr) &&
7209 ifmgd->auth_data->link_id == req->link_id;
7210 ieee80211_destroy_auth_data(sdata, match);
7213 /* prepare assoc data */
7215 bss = (void *)cbss->priv;
7216 assoc_data->wmm = bss->wmm_used &&
7217 (local->hw.queues >= IEEE80211_NUM_ACS);
7220 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7221 * We still associate in non-HT mode (11a/b/g) if any one of these
7222 * ciphers is configured as pairwise.
7223 * We can set this to true for non-11n hardware, that'll be checked
7224 * separately along with the peer capabilities.
7226 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7227 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7228 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7229 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7230 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7231 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7232 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7233 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7234 netdev_info(sdata->dev,
7235 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7239 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7240 if (!bss->wmm_used) {
7241 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7242 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7243 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7244 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7245 netdev_info(sdata->dev,
7246 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7249 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7250 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7251 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7252 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7253 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7254 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7257 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7258 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7259 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7262 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7263 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7264 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7265 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7268 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7269 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7271 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7272 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7273 sizeof(ifmgd->ht_capa_mask));
7275 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7276 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7277 sizeof(ifmgd->vht_capa_mask));
7279 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7280 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7281 sizeof(ifmgd->s1g_capa_mask));
7283 if (req->ie && req->ie_len) {
7284 memcpy(assoc_data->ie, req->ie, req->ie_len);
7285 assoc_data->ie_len = req->ie_len;
7286 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7288 assoc_data->ie_pos = assoc_data->ie;
7291 if (req->fils_kek) {
7292 /* should already be checked in cfg80211 - so warn */
7293 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7297 memcpy(assoc_data->fils_kek, req->fils_kek,
7299 assoc_data->fils_kek_len = req->fils_kek_len;
7302 if (req->fils_nonces)
7303 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7304 2 * FILS_NONCE_LEN);
7306 /* default timeout */
7307 assoc_data->timeout = jiffies;
7308 assoc_data->timeout_started = true;
7310 assoc_data->assoc_link_id = assoc_link_id;
7312 if (req->ap_mld_addr) {
7313 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7314 assoc_data->link[i].conn_flags = conn_flags;
7315 assoc_data->link[i].bss = req->links[i].bss;
7318 /* if there was no authentication, set up the link */
7319 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id));
7323 assoc_data->link[0].conn_flags = conn_flags;
7324 assoc_data->link[0].bss = cbss;
7327 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7328 if (WARN_ON(!link)) {
7333 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7334 conn_flags |= link->u.mgd.conn_flags;
7335 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7336 conn_flags, assoc_link_id);
7337 override = link->u.mgd.conn_flags != conn_flags;
7338 link->u.mgd.conn_flags |= conn_flags;
7340 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7341 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7342 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7343 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7345 if (bss->wmm_used && bss->uapsd_supported &&
7346 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7347 assoc_data->uapsd = true;
7348 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7350 assoc_data->uapsd = false;
7351 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7354 if (req->prev_bssid)
7355 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7358 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7359 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7361 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7362 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7365 if (req->flags & ASSOC_REQ_USE_RRM)
7366 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7368 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7370 if (req->crypto.control_port)
7371 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7373 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7375 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7376 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7377 sdata->control_port_over_nl80211 =
7378 req->crypto.control_port_over_nl80211;
7379 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7381 /* kick off associate process */
7382 ifmgd->assoc_data = assoc_data;
7384 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7385 if (!assoc_data->link[i].bss)
7387 if (i == assoc_data->assoc_link_id)
7389 /* only calculate the flags, hence link == NULL */
7390 err = ieee80211_prep_channel(sdata, NULL, assoc_data->link[i].bss,
7391 &assoc_data->link[i].conn_flags);
7396 /* needed for transmitting the assoc frames properly */
7397 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
7399 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7400 req->ap_mld_addr, true, override);
7404 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7405 link->u.mgd.conn_flags;
7407 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7408 const struct cfg80211_bss_ies *beacon_ies;
7411 beacon_ies = rcu_dereference(req->bss->beacon_ies);
7415 * Wait up to one beacon interval ...
7416 * should this be more if we miss one?
7418 sdata_info(sdata, "waiting for beacon from %pM\n",
7420 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
7421 assoc_data->timeout_started = true;
7422 assoc_data->need_beacon = true;
7427 run_again(sdata, assoc_data->timeout);
7431 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7432 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7434 ifmgd->assoc_data = NULL;
7440 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
7441 struct cfg80211_deauth_request *req)
7443 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7444 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7445 bool tx = !req->local_state_change;
7446 struct ieee80211_prep_tx_info info = {
7447 .subtype = IEEE80211_STYPE_DEAUTH,
7450 if (ifmgd->auth_data &&
7451 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
7453 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
7454 req->bssid, req->reason_code,
7455 ieee80211_get_reason_code_string(req->reason_code));
7457 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7458 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7459 IEEE80211_STYPE_DEAUTH,
7460 req->reason_code, tx,
7462 ieee80211_destroy_auth_data(sdata, false);
7463 ieee80211_report_disconnect(sdata, frame_buf,
7464 sizeof(frame_buf), true,
7465 req->reason_code, false);
7466 drv_mgd_complete_tx(sdata->local, sdata, &info);
7470 if (ifmgd->assoc_data &&
7471 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
7473 "aborting association with %pM by local choice (Reason: %u=%s)\n",
7474 req->bssid, req->reason_code,
7475 ieee80211_get_reason_code_string(req->reason_code));
7477 drv_mgd_prepare_tx(sdata->local, sdata, &info);
7478 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
7479 IEEE80211_STYPE_DEAUTH,
7480 req->reason_code, tx,
7482 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
7483 ieee80211_report_disconnect(sdata, frame_buf,
7484 sizeof(frame_buf), true,
7485 req->reason_code, false);
7489 if (ifmgd->associated &&
7490 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
7492 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
7493 req->bssid, req->reason_code,
7494 ieee80211_get_reason_code_string(req->reason_code));
7496 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7497 req->reason_code, tx, frame_buf);
7498 ieee80211_report_disconnect(sdata, frame_buf,
7499 sizeof(frame_buf), true,
7500 req->reason_code, false);
7501 drv_mgd_complete_tx(sdata->local, sdata, &info);
7508 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
7509 struct cfg80211_disassoc_request *req)
7511 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7513 if (!sdata->u.mgd.associated ||
7514 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
7518 "disassociating from %pM by local choice (Reason: %u=%s)\n",
7519 req->ap_addr, req->reason_code,
7520 ieee80211_get_reason_code_string(req->reason_code));
7522 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
7523 req->reason_code, !req->local_state_change,
7526 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
7527 req->reason_code, false);
7532 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
7534 cancel_work_sync(&link->u.mgd.request_smps_work);
7535 cancel_work_sync(&link->u.mgd.chswitch_work);
7538 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
7540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7543 * Make sure some work items will not run after this,
7544 * they will not do anything but might not have been
7545 * cancelled when disconnecting.
7547 cancel_work_sync(&ifmgd->monitor_work);
7548 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
7549 cancel_work_sync(&ifmgd->csa_connection_drop_work);
7550 cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
7553 if (ifmgd->assoc_data)
7554 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
7555 if (ifmgd->auth_data)
7556 ieee80211_destroy_auth_data(sdata, false);
7557 spin_lock_bh(&ifmgd->teardown_lock);
7558 if (ifmgd->teardown_skb) {
7559 kfree_skb(ifmgd->teardown_skb);
7560 ifmgd->teardown_skb = NULL;
7561 ifmgd->orig_teardown_skb = NULL;
7563 kfree(ifmgd->assoc_req_ies);
7564 ifmgd->assoc_req_ies = NULL;
7565 ifmgd->assoc_req_ies_len = 0;
7566 spin_unlock_bh(&ifmgd->teardown_lock);
7567 del_timer_sync(&ifmgd->timer);
7568 sdata_unlock(sdata);
7571 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
7572 enum nl80211_cqm_rssi_threshold_event rssi_event,
7576 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7578 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
7580 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
7582 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
7584 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
7586 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7588 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
7590 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
7592 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
7594 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
7598 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
7600 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
7604 * Scale up threshold values before storing it, as the RSSI averaging
7605 * algorithm uses a scaled up value as well. Change this scaling
7606 * factor if the RSSI averaging algorithm changes.
7608 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
7609 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
7612 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
7616 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7618 WARN_ON(rssi_min_thold == rssi_max_thold ||
7619 rssi_min_thold > rssi_max_thold);
7621 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
7624 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
7626 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
7628 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
7630 _ieee80211_enable_rssi_reports(sdata, 0, 0);
7632 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);