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 #define IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS msecs_to_jiffies(100)
47 #define IEEE80211_ADV_TTLM_ST_UNDERFLOW 0xff00
49 static int max_nullfunc_tries = 2;
50 module_param(max_nullfunc_tries, int, 0644);
51 MODULE_PARM_DESC(max_nullfunc_tries,
52 "Maximum nullfunc tx tries before disconnecting (reason 4).");
54 static int max_probe_tries = 5;
55 module_param(max_probe_tries, int, 0644);
56 MODULE_PARM_DESC(max_probe_tries,
57 "Maximum probe tries before disconnecting (reason 4).");
60 * Beacon loss timeout is calculated as N frames times the
61 * advertised beacon interval. This may need to be somewhat
62 * higher than what hardware might detect to account for
63 * delays in the host processing frames. But since we also
64 * probe on beacon miss before declaring the connection lost
65 * default to what we want.
67 static int beacon_loss_count = 7;
68 module_param(beacon_loss_count, int, 0644);
69 MODULE_PARM_DESC(beacon_loss_count,
70 "Number of beacon intervals before we decide beacon was lost.");
73 * Time the connection can be idle before we probe
74 * it to see if we can still talk to the AP.
76 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
78 * Time we wait for a probe response after sending
79 * a probe request because of beacon loss or for
80 * checking the connection still works.
82 static int probe_wait_ms = 500;
83 module_param(probe_wait_ms, int, 0644);
84 MODULE_PARM_DESC(probe_wait_ms,
85 "Maximum time(ms) to wait for probe response"
86 " before disconnecting (reason 4).");
89 * How many Beacon frames need to have been used in average signal strength
90 * before starting to indicate signal change events.
92 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
95 * Extract from the given disabled subchannel bitmap (raw format
96 * from the EHT Operation Element) the bits for the subchannel
97 * we're using right now.
100 ieee80211_extract_dis_subch_bmap(const struct ieee80211_eht_operation *eht_oper,
101 struct cfg80211_chan_def *chandef, u16 bitmap)
103 struct ieee80211_eht_operation_info *info = (void *)eht_oper->optional;
104 struct cfg80211_chan_def ap_chandef = *chandef;
105 u32 ap_center_freq, local_center_freq;
107 int ap_start_freq, local_start_freq;
110 if (!(eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) ||
112 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT))
115 /* set 160/320 supported to get the full AP definition */
116 ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
117 true, true, &ap_chandef);
118 ap_center_freq = ap_chandef.center_freq1;
119 ap_bw = 20 * BIT(u8_get_bits(info->control,
120 IEEE80211_EHT_OPER_CHAN_WIDTH));
121 ap_start_freq = ap_center_freq - ap_bw / 2;
122 local_center_freq = chandef->center_freq1;
123 local_bw = 20 * BIT(ieee80211_chan_width_to_rx_bw(chandef->width));
124 local_start_freq = local_center_freq - local_bw / 2;
125 shift = (local_start_freq - ap_start_freq) / 20;
126 mask = BIT(local_bw / 20) - 1;
128 return (bitmap >> shift) & mask;
132 * Handle the puncturing bitmap, possibly downgrading bandwidth to get a
136 ieee80211_handle_puncturing_bitmap(struct ieee80211_link_data *link,
137 const struct ieee80211_eht_operation *eht_oper,
138 u16 bitmap, u64 *changed)
140 struct cfg80211_chan_def *chandef = &link->conf->chandef;
141 struct ieee80211_local *local = link->sdata->local;
148 while (chandef->width > NL80211_CHAN_WIDTH_40) {
150 ieee80211_extract_dis_subch_bmap(eht_oper, chandef,
153 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
155 !(bitmap && ieee80211_hw_check(&local->hw,
156 DISALLOW_PUNCTURING)))
158 link->u.mgd.conn_flags |=
159 ieee80211_chandef_downgrade(chandef);
160 *changed |= BSS_CHANGED_BANDWIDTH;
163 if (chandef->width <= NL80211_CHAN_WIDTH_40)
166 if (link->conf->eht_puncturing != extracted) {
167 link->conf->eht_puncturing = extracted;
168 *changed |= BSS_CHANGED_EHT_PUNCTURING;
173 * We can have multiple work items (and connection probing)
174 * scheduling this timer, but we need to take care to only
175 * reschedule it when it should fire _earlier_ than it was
176 * asked for before, or if it's not pending right now. This
177 * function ensures that. Note that it then is required to
178 * run this function for all timeouts after the first one
179 * has happened -- the work that runs from this timer will
182 static void run_again(struct ieee80211_sub_if_data *sdata,
183 unsigned long timeout)
185 lockdep_assert_wiphy(sdata->local->hw.wiphy);
187 if (!timer_pending(&sdata->u.mgd.timer) ||
188 time_before(timeout, sdata->u.mgd.timer.expires))
189 mod_timer(&sdata->u.mgd.timer, timeout);
192 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
194 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
197 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
200 mod_timer(&sdata->u.mgd.bcn_mon_timer,
201 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
204 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
208 if (unlikely(!ifmgd->associated))
211 if (ifmgd->probe_send_count)
212 ifmgd->probe_send_count = 0;
214 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
217 mod_timer(&ifmgd->conn_mon_timer,
218 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
221 static int ecw2cw(int ecw)
223 return (1 << ecw) - 1;
226 static ieee80211_conn_flags_t
227 ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
228 struct ieee80211_link_data *link,
229 ieee80211_conn_flags_t conn_flags,
230 struct ieee80211_supported_band *sband,
231 struct ieee80211_channel *channel,
233 const struct ieee80211_ht_operation *ht_oper,
234 const struct ieee80211_vht_operation *vht_oper,
235 const struct ieee80211_he_operation *he_oper,
236 const struct ieee80211_eht_operation *eht_oper,
237 const struct ieee80211_s1g_oper_ie *s1g_oper,
238 struct cfg80211_chan_def *chandef, bool tracking)
240 struct cfg80211_chan_def vht_chandef;
241 struct ieee80211_sta_ht_cap sta_ht_cap;
242 ieee80211_conn_flags_t ret;
245 memset(chandef, 0, sizeof(struct cfg80211_chan_def));
246 chandef->chan = channel;
247 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
248 chandef->center_freq1 = channel->center_freq;
249 chandef->freq1_offset = channel->freq_offset;
251 if (channel->band == NL80211_BAND_6GHZ) {
252 if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
255 "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
256 ret = IEEE80211_CONN_DISABLE_HT |
257 IEEE80211_CONN_DISABLE_VHT |
258 IEEE80211_CONN_DISABLE_HE |
259 IEEE80211_CONN_DISABLE_EHT;
263 vht_chandef = *chandef;
265 } else if (sband->band == NL80211_BAND_S1GHZ) {
266 if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
268 "Missing S1G Operation Element? Trying operating == primary\n");
269 chandef->width = ieee80211_s1g_channel_width(channel);
272 ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
273 IEEE80211_CONN_DISABLE_VHT |
274 IEEE80211_CONN_DISABLE_80P80MHZ |
275 IEEE80211_CONN_DISABLE_160MHZ;
279 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
280 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
282 if (!ht_oper || !sta_ht_cap.ht_supported) {
283 mlme_dbg(sdata, "HT operation missing / HT not supported\n");
284 ret = IEEE80211_CONN_DISABLE_HT |
285 IEEE80211_CONN_DISABLE_VHT |
286 IEEE80211_CONN_DISABLE_HE |
287 IEEE80211_CONN_DISABLE_EHT;
291 chandef->width = NL80211_CHAN_WIDTH_20;
293 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
295 /* check that channel matches the right operating channel */
296 if (!tracking && channel->center_freq != ht_cfreq) {
298 * It's possible that some APs are confused here;
299 * Netgear WNDR3700 sometimes reports 4 higher than
300 * the actual channel in association responses, but
301 * since we look at probe response/beacon data here
305 "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
306 channel->center_freq, ht_cfreq,
307 ht_oper->primary_chan, channel->band);
308 ret = IEEE80211_CONN_DISABLE_HT |
309 IEEE80211_CONN_DISABLE_VHT |
310 IEEE80211_CONN_DISABLE_HE |
311 IEEE80211_CONN_DISABLE_EHT;
315 /* check 40 MHz support, if we have it */
316 if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
317 ieee80211_chandef_ht_oper(ht_oper, chandef);
319 mlme_dbg(sdata, "40 MHz not supported\n");
320 /* 40 MHz (and 80 MHz) must be supported for VHT */
321 ret = IEEE80211_CONN_DISABLE_VHT;
322 /* also mark 40 MHz disabled */
323 ret |= IEEE80211_CONN_DISABLE_40MHZ;
327 if (!vht_oper || !sband->vht_cap.vht_supported) {
328 mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
329 ret = IEEE80211_CONN_DISABLE_VHT;
333 vht_chandef = *chandef;
334 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
336 (le32_to_cpu(he_oper->he_oper_params) &
337 IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
338 struct ieee80211_vht_operation he_oper_vht_cap;
341 * Set only first 3 bytes (other 2 aren't used in
342 * ieee80211_chandef_vht_oper() anyway)
344 memcpy(&he_oper_vht_cap, he_oper->optional, 3);
345 he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
347 if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
348 &he_oper_vht_cap, ht_oper,
350 if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
352 "HE AP VHT information is invalid, disabling HE\n");
353 ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
356 } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
360 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
362 "AP VHT information is invalid, disabling VHT\n");
363 ret = IEEE80211_CONN_DISABLE_VHT;
367 if (!cfg80211_chandef_valid(&vht_chandef)) {
368 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
370 "AP VHT information is invalid, disabling VHT\n");
371 ret = IEEE80211_CONN_DISABLE_VHT;
375 if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
380 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
381 if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
383 "AP VHT information doesn't match HT, disabling VHT\n");
384 ret = IEEE80211_CONN_DISABLE_VHT;
388 *chandef = vht_chandef;
391 * handle the case that the EHT operation indicates that it holds EHT
392 * operation information (in case that the channel width differs from
393 * the channel width reported in HT/VHT/HE).
395 if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
396 struct cfg80211_chan_def eht_chandef = *chandef;
398 ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
400 NL80211_CHAN_WIDTH_160,
401 false, &eht_chandef);
403 if (!cfg80211_chandef_valid(&eht_chandef)) {
404 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
406 "AP EHT information is invalid, disabling EHT\n");
407 ret = IEEE80211_CONN_DISABLE_EHT;
411 if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
412 if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
414 "AP EHT information is incompatible, disabling EHT\n");
415 ret = IEEE80211_CONN_DISABLE_EHT;
419 *chandef = eht_chandef;
426 * When tracking the current AP, don't do any further checks if the
427 * new chandef is identical to the one we're currently using for the
428 * connection. This keeps us from playing ping-pong with regulatory,
429 * without it the following can happen (for example):
430 * - connect to an AP with 80 MHz, world regdom allows 80 MHz
431 * - AP advertises regdom US
432 * - CRDA loads regdom US with 80 MHz prohibited (old database)
433 * - the code below detects an unsupported channel, downgrades, and
434 * we disconnect from the AP in the caller
435 * - disconnect causes CRDA to reload world regdomain and the game
437 * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
439 * It seems possible that there are still scenarios with CSA or real
440 * bandwidth changes where a this could happen, but those cases are
441 * less common and wouldn't completely prevent using the AP.
444 cfg80211_chandef_identical(chandef, &link->conf->chandef))
447 /* don't print the message below for VHT mismatch if VHT is disabled */
448 if (ret & IEEE80211_CONN_DISABLE_VHT)
449 vht_chandef = *chandef;
452 * Ignore the DISABLED flag when we're already connected and only
453 * tracking the APs beacon for bandwidth changes - otherwise we
454 * might get disconnected here if we connect to an AP, update our
455 * regulatory information based on the AP's country IE and the
456 * information we have is wrong/outdated and disables the channel
457 * that we're actually using for the connection to the AP.
459 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
461 IEEE80211_CHAN_DISABLED)) {
462 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
463 ret = IEEE80211_CONN_DISABLE_HT |
464 IEEE80211_CONN_DISABLE_VHT |
465 IEEE80211_CONN_DISABLE_HE |
466 IEEE80211_CONN_DISABLE_EHT;
470 ret |= ieee80211_chandef_downgrade(chandef);
473 if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
474 IEEE80211_CHAN_NO_HE))
475 ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
477 if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
478 IEEE80211_CHAN_NO_EHT))
479 ret |= IEEE80211_CONN_DISABLE_EHT;
481 if (chandef->width != vht_chandef.width && !tracking)
483 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
485 WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
489 static int ieee80211_config_bw(struct ieee80211_link_data *link,
490 const struct ieee80211_ht_cap *ht_cap,
491 const struct ieee80211_vht_cap *vht_cap,
492 const struct ieee80211_ht_operation *ht_oper,
493 const struct ieee80211_vht_operation *vht_oper,
494 const struct ieee80211_he_operation *he_oper,
495 const struct ieee80211_eht_operation *eht_oper,
496 const struct ieee80211_s1g_oper_ie *s1g_oper,
497 const u8 *bssid, u64 *changed)
499 struct ieee80211_sub_if_data *sdata = link->sdata;
500 struct ieee80211_local *local = sdata->local;
501 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
502 struct ieee80211_channel *chan = link->conf->chandef.chan;
503 struct ieee80211_supported_band *sband =
504 local->hw.wiphy->bands[chan->band];
505 struct cfg80211_chan_def chandef;
507 ieee80211_conn_flags_t flags;
508 u32 vht_cap_info = 0;
511 /* if HT was/is disabled, don't track any bandwidth changes */
512 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
515 /* don't check VHT if we associated as non-VHT station */
516 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
519 /* don't check HE if we associated as non-HE station */
520 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
521 !ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
526 /* don't check EHT if we associated as non-EHT station */
527 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
528 !ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif))
532 * if bss configuration changed store the new one -
533 * this may be applicable even if channel is identical
535 ht_opmode = le16_to_cpu(ht_oper->operation_mode);
536 if (link->conf->ht_operation_mode != ht_opmode) {
537 *changed |= BSS_CHANGED_HT;
538 link->conf->ht_operation_mode = ht_opmode;
542 vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
544 /* calculate new channel (type) based on HT/VHT/HE operation IEs */
545 flags = ieee80211_determine_chantype(sdata, link,
546 link->u.mgd.conn_flags,
547 sband, chan, vht_cap_info,
550 s1g_oper, &chandef, true);
553 * Downgrade the new channel if we associated with restricted
554 * capabilities. For example, if we associated as a 20 MHz STA
555 * to a 40 MHz AP (due to regulatory, capabilities or config
556 * reasons) then switching to a 40 MHz channel now won't do us
557 * any good -- we couldn't use it with the AP.
559 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
560 chandef.width == NL80211_CHAN_WIDTH_80P80)
561 flags |= ieee80211_chandef_downgrade(&chandef);
562 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
563 chandef.width == NL80211_CHAN_WIDTH_160)
564 flags |= ieee80211_chandef_downgrade(&chandef);
565 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
566 chandef.width > NL80211_CHAN_WIDTH_20)
567 flags |= ieee80211_chandef_downgrade(&chandef);
569 if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
573 "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
574 link->u.mgd.bssid, chandef.chan->center_freq,
575 chandef.chan->freq_offset, chandef.width,
576 chandef.center_freq1, chandef.freq1_offset,
577 chandef.center_freq2);
579 if (flags != (link->u.mgd.conn_flags &
580 (IEEE80211_CONN_DISABLE_HT |
581 IEEE80211_CONN_DISABLE_VHT |
582 IEEE80211_CONN_DISABLE_HE |
583 IEEE80211_CONN_DISABLE_EHT |
584 IEEE80211_CONN_DISABLE_40MHZ |
585 IEEE80211_CONN_DISABLE_80P80MHZ |
586 IEEE80211_CONN_DISABLE_160MHZ |
587 IEEE80211_CONN_DISABLE_320MHZ)) ||
588 !cfg80211_chandef_valid(&chandef)) {
590 "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
591 link->u.mgd.bssid, flags, ifmgd->flags);
595 ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
599 "AP %pM changed bandwidth to incompatible one - disconnect\n",
604 cfg80211_schedule_channels_check(&sdata->wdev);
608 /* frame sending functions */
610 static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
611 struct sk_buff *skb, u8 ap_ht_param,
612 struct ieee80211_supported_band *sband,
613 struct ieee80211_channel *channel,
614 enum ieee80211_smps_mode smps,
615 ieee80211_conn_flags_t conn_flags)
618 u32 flags = channel->flags;
620 struct ieee80211_sta_ht_cap ht_cap;
622 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
624 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
625 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
627 /* determine capability flags */
630 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
631 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
632 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
633 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
634 cap &= ~IEEE80211_HT_CAP_SGI_40;
637 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
638 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
639 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
640 cap &= ~IEEE80211_HT_CAP_SGI_40;
646 * If 40 MHz was disabled associate as though we weren't
647 * capable of 40 MHz -- some broken APs will never fall
648 * back to trying to transmit in 20 MHz.
650 if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
651 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
652 cap &= ~IEEE80211_HT_CAP_SGI_40;
655 /* set SM PS mode properly */
656 cap &= ~IEEE80211_HT_CAP_SM_PS;
658 case IEEE80211_SMPS_AUTOMATIC:
659 case IEEE80211_SMPS_NUM_MODES:
662 case IEEE80211_SMPS_OFF:
663 cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
664 IEEE80211_HT_CAP_SM_PS_SHIFT;
666 case IEEE80211_SMPS_STATIC:
667 cap |= WLAN_HT_CAP_SM_PS_STATIC <<
668 IEEE80211_HT_CAP_SM_PS_SHIFT;
670 case IEEE80211_SMPS_DYNAMIC:
671 cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
672 IEEE80211_HT_CAP_SM_PS_SHIFT;
676 /* reserve and fill IE */
677 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
678 ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
681 /* This function determines vht capability flags for the association
683 * Note - the function returns true to own the MU-MIMO capability
685 static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
687 struct ieee80211_supported_band *sband,
688 struct ieee80211_vht_cap *ap_vht_cap,
689 ieee80211_conn_flags_t conn_flags)
691 struct ieee80211_local *local = sdata->local;
694 struct ieee80211_sta_vht_cap vht_cap;
695 u32 mask, ap_bf_sts, our_bf_sts;
696 bool mu_mimo_owner = false;
698 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
700 memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
701 ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
703 /* determine capability flags */
706 if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
707 u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
709 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
710 if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
711 bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
712 cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
715 if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
716 cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
717 cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
721 * Some APs apparently get confused if our capabilities are better
722 * than theirs, so restrict what we advertise in the assoc request.
724 if (!(ap_vht_cap->vht_cap_info &
725 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
726 cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
727 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
728 else if (!(ap_vht_cap->vht_cap_info &
729 cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
730 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
733 * If some other vif is using the MU-MIMO capability we cannot associate
734 * using MU-MIMO - this will lead to contradictions in the group-id
736 * Ownership is defined since association request, in order to avoid
737 * simultaneous associations with MU-MIMO.
739 if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
740 bool disable_mu_mimo = false;
741 struct ieee80211_sub_if_data *other;
743 list_for_each_entry_rcu(other, &local->interfaces, list) {
744 if (other->vif.bss_conf.mu_mimo_owner) {
745 disable_mu_mimo = true;
750 cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
752 mu_mimo_owner = true;
755 mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
757 ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
758 our_bf_sts = cap & mask;
760 if (ap_bf_sts < our_bf_sts) {
765 /* reserve and fill IE */
766 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
767 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
769 return mu_mimo_owner;
772 /* This function determines HE capability flags for the association
775 static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
777 struct ieee80211_supported_band *sband,
778 enum ieee80211_smps_mode smps_mode,
779 ieee80211_conn_flags_t conn_flags)
781 u8 *pos, *pre_he_pos;
782 const struct ieee80211_sta_he_cap *he_cap;
785 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
786 if (WARN_ON(!he_cap))
789 /* get a max size estimate */
791 2 + 1 + sizeof(he_cap->he_cap_elem) +
792 ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
793 ieee80211_he_ppe_size(he_cap->ppe_thres[0],
794 he_cap->he_cap_elem.phy_cap_info);
795 pos = skb_put(skb, he_cap_size);
797 pos = ieee80211_ie_build_he_cap(conn_flags,
798 pos, he_cap, pos + he_cap_size);
799 /* trim excess if any */
800 skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
802 ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
805 static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
807 struct ieee80211_supported_band *sband)
810 const struct ieee80211_sta_he_cap *he_cap;
811 const struct ieee80211_sta_eht_cap *eht_cap;
814 he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
815 eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
818 * EHT capabilities element is only added if the HE capabilities element
819 * was added so assume that 'he_cap' is valid and don't check it.
821 if (WARN_ON(!he_cap || !eht_cap))
825 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
826 ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
827 &eht_cap->eht_cap_elem,
829 ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
830 eht_cap->eht_cap_elem.phy_cap_info);
831 pos = skb_put(skb, eht_cap_size);
832 ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
836 static void ieee80211_assoc_add_rates(struct sk_buff *skb,
837 enum nl80211_chan_width width,
838 struct ieee80211_supported_band *sband,
839 struct ieee80211_mgd_assoc_data *assoc_data)
841 unsigned int rates_len, supp_rates_len;
846 if (assoc_data->supp_rates_len) {
848 * Get all rates supported by the device and the AP as
849 * some APs don't like getting a superset of their rates
850 * in the association request (e.g. D-Link DAP 1353 in
853 rates_len = ieee80211_parse_bitrates(width, sband,
854 assoc_data->supp_rates,
855 assoc_data->supp_rates_len,
859 * In case AP not provide any supported rates information
860 * before association, we send information element(s) with
861 * all rates that we support.
863 rates_len = sband->n_bitrates;
864 for (i = 0; i < sband->n_bitrates; i++)
868 supp_rates_len = rates_len;
869 if (supp_rates_len > 8)
872 pos = skb_put(skb, supp_rates_len + 2);
873 *pos++ = WLAN_EID_SUPP_RATES;
874 *pos++ = supp_rates_len;
877 for (i = 0; i < sband->n_bitrates; i++) {
878 if (BIT(i) & rates) {
879 int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 5);
886 if (rates_len > count) {
887 pos = skb_put(skb, rates_len - count + 2);
888 *pos++ = WLAN_EID_EXT_SUPP_RATES;
889 *pos++ = rates_len - count;
891 for (i++; i < sband->n_bitrates; i++) {
892 if (BIT(i) & rates) {
895 rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 5);
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;
1220 bool at_extension = false;
1223 u8 *len, *list_len = NULL;
1225 skb_put_u8(skb, WLAN_EID_EXTENSION);
1226 len = skb_put(skb, 1);
1227 skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
1229 for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
1230 u16 elem = outer[i];
1231 bool have_inner = 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 /* if we added a list but no extension list, make a zero-len one */
1264 if (added && (!at_extension || !list_len))
1267 /* if nothing added remove extension element completely */
1269 skb_trim(skb, skb_len);
1271 *len = skb->len - skb_len - 2;
1274 static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
1275 struct sk_buff *skb, u16 capab,
1276 const struct element *ext_capa,
1277 const u16 *outer_present_elems)
1279 struct ieee80211_local *local = sdata->local;
1280 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1281 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1282 struct ieee80211_multi_link_elem *ml_elem;
1283 struct ieee80211_mle_basic_common_info *common;
1284 const struct wiphy_iftype_ext_capab *ift_ext_capa;
1285 __le16 eml_capa = 0, mld_capa_ops = 0;
1286 unsigned int link_id;
1290 if (!ieee80211_vif_is_mld(&sdata->vif))
1293 ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
1294 ieee80211_vif_type_p2p(&sdata->vif));
1296 eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
1297 mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
1300 skb_put_u8(skb, WLAN_EID_EXTENSION);
1301 ml_elem_len = skb_put(skb, 1);
1302 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
1303 ml_elem = skb_put(skb, sizeof(*ml_elem));
1305 cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
1306 IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
1307 common = skb_put(skb, sizeof(*common));
1308 common->len = sizeof(*common) +
1309 2; /* MLD capa/ops */
1310 memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
1312 /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
1314 cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
1315 IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
1316 common->len += 2; /* EML capabilities */
1318 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
1319 skb_put_data(skb, &eml_capa, sizeof(eml_capa));
1321 /* need indication from userspace to support this */
1322 mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
1323 skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
1325 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1326 u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
1327 const u8 *extra_elems;
1328 size_t extra_elems_len;
1330 u8 *subelem_len = NULL;
1333 if (!assoc_data->link[link_id].bss ||
1334 link_id == assoc_data->assoc_link_id)
1337 extra_elems = assoc_data->link[link_id].elems;
1338 extra_elems_len = assoc_data->link[link_id].elems_len;
1340 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
1341 subelem_len = skb_put(skb, 1);
1343 ctrl = cpu_to_le16(link_id |
1344 IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
1345 IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
1346 skb_put_data(skb, &ctrl, sizeof(ctrl));
1347 skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
1348 skb_put_data(skb, assoc_data->link[link_id].addr,
1351 * Now add the contents of the (re)association request,
1352 * but the "listen interval" and "current AP address"
1353 * (if applicable) are skipped. So we only have
1354 * the capability field (remember the position and fill
1355 * later), followed by the elements added below by
1356 * calling ieee80211_assoc_link_elems().
1358 capab_pos = skb_put(skb, 2);
1360 extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
1365 link_present_elems);
1367 skb_put_data(skb, extra_elems + extra_used,
1368 extra_elems_len - extra_used);
1370 put_unaligned_le16(capab, capab_pos);
1372 ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
1373 link_present_elems);
1375 ieee80211_fragment_element(skb, subelem_len,
1376 IEEE80211_MLE_SUBELEM_FRAGMENT);
1379 ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
1382 static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
1384 struct ieee80211_local *local = sdata->local;
1385 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1386 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
1387 struct ieee80211_link_data *link;
1388 struct sk_buff *skb;
1389 struct ieee80211_mgmt *mgmt;
1390 u8 *pos, qos_info, *ie_start;
1391 size_t offset, noffset;
1392 u16 capab = 0, link_capab;
1394 struct element *ext_capa = NULL;
1395 enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
1396 struct ieee80211_prep_tx_info info = {};
1397 unsigned int link_id, n_links = 0;
1398 u16 present_elems[PRESENT_ELEMS_MAX] = {};
1403 /* we know it's writable, cast away the const */
1404 if (assoc_data->ie_len)
1405 ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
1407 assoc_data->ie_len);
1409 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1411 size = local->hw.extra_tx_headroom +
1412 sizeof(*mgmt) + /* bit too much but doesn't matter */
1413 2 + assoc_data->ssid_len + /* SSID */
1414 assoc_data->ie_len + /* extra IEs */
1415 (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
1418 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
1419 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
1420 const struct ieee80211_sband_iftype_data *iftd;
1421 struct ieee80211_supported_band *sband;
1426 sband = local->hw.wiphy->bands[cbss->channel->band];
1429 /* add STA profile elements length */
1430 size += assoc_data->link[link_id].elems_len;
1431 /* and supported rates length */
1432 size += 4 + sband->n_bitrates;
1433 /* supported channels */
1434 size += 2 + 2 * sband->n_channels;
1436 iftd = ieee80211_get_sband_iftype_data(sband, iftype);
1438 size += iftd->vendor_elems.len;
1440 /* power capability */
1443 /* HT, VHT, HE, EHT */
1444 size += 2 + sizeof(struct ieee80211_ht_cap);
1445 size += 2 + sizeof(struct ieee80211_vht_cap);
1446 size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
1447 sizeof(struct ieee80211_he_mcs_nss_supp) +
1448 IEEE80211_HE_PPE_THRES_MAX_LEN;
1450 if (sband->band == NL80211_BAND_6GHZ)
1451 size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
1453 size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
1454 sizeof(struct ieee80211_eht_mcs_nss_supp) +
1455 IEEE80211_EHT_PPE_THRES_MAX_LEN;
1457 /* non-inheritance element */
1458 size += 2 + 2 + PRESENT_ELEMS_MAX;
1460 /* should be the same across all BSSes */
1461 if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
1462 capab |= WLAN_CAPABILITY_PRIVACY;
1465 if (ieee80211_vif_is_mld(&sdata->vif)) {
1466 /* consider the multi-link element with STA profile */
1467 size += sizeof(struct ieee80211_multi_link_elem);
1468 /* max common info field in basic multi-link element */
1469 size += sizeof(struct ieee80211_mle_basic_common_info) +
1474 * The capability elements were already considered above;
1475 * note this over-estimates a bit because there's no
1476 * STA profile for the assoc link.
1478 size += (n_links - 1) *
1479 (1 + 1 + /* subelement ID/length */
1480 2 + /* STA control */
1481 1 + ETH_ALEN + 2 /* STA Info field */);
1484 link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
1488 if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
1491 skb = alloc_skb(size, GFP_KERNEL);
1495 skb_reserve(skb, local->hw.extra_tx_headroom);
1497 if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
1498 capab |= WLAN_CAPABILITY_RADIO_MEASURE;
1500 /* Set MBSSID support for HE AP if needed */
1501 if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
1502 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
1503 ext_capa && ext_capa->datalen >= 3)
1504 ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1506 mgmt = skb_put_zero(skb, 24);
1507 memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
1508 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1509 memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
1511 listen_int = cpu_to_le16(assoc_data->s1g ?
1512 ieee80211_encode_usf(local->hw.conf.listen_interval) :
1513 local->hw.conf.listen_interval);
1514 if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
1516 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1517 IEEE80211_STYPE_REASSOC_REQ);
1518 capab_pos = &mgmt->u.reassoc_req.capab_info;
1519 mgmt->u.reassoc_req.listen_interval = listen_int;
1520 memcpy(mgmt->u.reassoc_req.current_ap,
1521 assoc_data->prev_ap_addr, ETH_ALEN);
1522 info.subtype = IEEE80211_STYPE_REASSOC_REQ;
1525 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1526 IEEE80211_STYPE_ASSOC_REQ);
1527 capab_pos = &mgmt->u.assoc_req.capab_info;
1528 mgmt->u.assoc_req.listen_interval = listen_int;
1529 info.subtype = IEEE80211_STYPE_ASSOC_REQ;
1533 pos = skb_put(skb, 2 + assoc_data->ssid_len);
1535 *pos++ = WLAN_EID_SSID;
1536 *pos++ = assoc_data->ssid_len;
1537 memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
1540 * This bit is technically reserved, so it shouldn't matter for either
1541 * the AP or us, but it also means we shouldn't set it. However, we've
1542 * always set it in the past, and apparently some EHT APs check that
1543 * we don't set it. To avoid interoperability issues with old APs that
1544 * for some reason check it and want it to be set, set the bit for all
1545 * pre-EHT connections as we used to do.
1547 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)
1548 capab |= WLAN_CAPABILITY_ESS;
1550 /* add the elements for the assoc (main) link */
1552 offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
1556 assoc_data->assoc_link_id, link,
1558 put_unaligned_le16(link_capab, capab_pos);
1560 /* if present, add any custom non-vendor IEs */
1561 if (assoc_data->ie_len) {
1562 noffset = ieee80211_ie_split_vendor(assoc_data->ie,
1565 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1569 if (assoc_data->wmm) {
1570 if (assoc_data->uapsd) {
1571 qos_info = ifmgd->uapsd_queues;
1572 qos_info |= (ifmgd->uapsd_max_sp_len <<
1573 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
1578 pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
1581 /* add any remaining custom (i.e. vendor specific here) IEs */
1582 if (assoc_data->ie_len) {
1583 noffset = assoc_data->ie_len;
1584 skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
1587 if (assoc_data->fils_kek_len) {
1588 ret = fils_encrypt_assoc_req(skb, assoc_data);
1595 pos = skb_tail_pointer(skb);
1596 kfree(ifmgd->assoc_req_ies);
1597 ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
1598 if (!ifmgd->assoc_req_ies) {
1603 ifmgd->assoc_req_ies_len = pos - ie_start;
1605 info.link_id = assoc_data->assoc_link_id;
1606 drv_mgd_prepare_tx(local, sdata, &info);
1608 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1609 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1610 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
1611 IEEE80211_TX_INTFL_MLME_CONN_TX;
1612 ieee80211_tx_skb(sdata, skb);
1617 void ieee80211_send_pspoll(struct ieee80211_local *local,
1618 struct ieee80211_sub_if_data *sdata)
1620 struct ieee80211_pspoll *pspoll;
1621 struct sk_buff *skb;
1623 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
1627 pspoll = (struct ieee80211_pspoll *) skb->data;
1628 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1630 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1631 ieee80211_tx_skb(sdata, skb);
1634 void ieee80211_send_nullfunc(struct ieee80211_local *local,
1635 struct ieee80211_sub_if_data *sdata,
1638 struct sk_buff *skb;
1639 struct ieee80211_hdr_3addr *nullfunc;
1640 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1642 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
1643 !ieee80211_hw_check(&local->hw,
1644 DOESNT_SUPPORT_QOS_NDP));
1648 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
1650 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1652 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
1653 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
1655 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
1656 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1658 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
1659 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1661 ieee80211_tx_skb(sdata, skb);
1664 void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
1665 struct ieee80211_sub_if_data *sdata)
1667 struct sk_buff *skb;
1668 struct ieee80211_hdr *nullfunc;
1671 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1674 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
1678 skb_reserve(skb, local->hw.extra_tx_headroom);
1680 nullfunc = skb_put_zero(skb, 30);
1681 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
1682 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1683 nullfunc->frame_control = fc;
1684 memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1685 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1686 memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
1687 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
1689 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
1690 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
1691 ieee80211_tx_skb(sdata, skb);
1694 /* spectrum management related things */
1695 static void ieee80211_chswitch_work(struct wiphy *wiphy,
1696 struct wiphy_work *work)
1698 struct ieee80211_link_data *link =
1699 container_of(work, struct ieee80211_link_data,
1700 u.mgd.chswitch_work.work);
1701 struct ieee80211_sub_if_data *sdata = link->sdata;
1702 struct ieee80211_local *local = sdata->local;
1703 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1706 if (!ieee80211_sdata_running(sdata))
1709 lockdep_assert_wiphy(local->hw.wiphy);
1711 if (!ifmgd->associated)
1714 if (!link->conf->csa_active)
1718 * using reservation isn't immediate as it may be deferred until later
1719 * with multi-vif. once reservation is complete it will re-schedule the
1720 * work with no reserved_chanctx so verify chandef to check if it
1721 * completed successfully
1724 if (link->reserved_chanctx) {
1726 * with multi-vif csa driver may call ieee80211_csa_finish()
1727 * many times while waiting for other interfaces to use their
1730 if (link->reserved_ready)
1733 ret = ieee80211_link_use_reserved_context(link);
1736 "failed to use reserved channel context, disconnecting (err=%d)\n",
1738 wiphy_work_queue(sdata->local->hw.wiphy,
1739 &ifmgd->csa_connection_drop_work);
1744 if (!cfg80211_chandef_identical(&link->conf->chandef,
1745 &link->csa_chandef)) {
1747 "failed to finalize channel switch, disconnecting\n");
1748 wiphy_work_queue(sdata->local->hw.wiphy,
1749 &ifmgd->csa_connection_drop_work);
1753 link->u.mgd.csa_waiting_bcn = true;
1755 ieee80211_sta_reset_beacon_monitor(sdata);
1756 ieee80211_sta_reset_conn_monitor(sdata);
1759 static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
1761 struct ieee80211_sub_if_data *sdata = link->sdata;
1762 struct ieee80211_local *local = sdata->local;
1763 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1766 lockdep_assert_wiphy(sdata->local->hw.wiphy);
1768 WARN_ON(!link->conf->csa_active);
1770 if (link->csa_block_tx) {
1771 ieee80211_wake_vif_queues(local, sdata,
1772 IEEE80211_QUEUE_STOP_REASON_CSA);
1773 link->csa_block_tx = false;
1776 link->conf->csa_active = false;
1777 link->u.mgd.csa_waiting_bcn = false;
1779 * If the CSA IE is still present on the beacon after the switch,
1780 * we need to consider it as a new CSA (possibly to self).
1782 link->u.mgd.beacon_crc_valid = false;
1784 ret = drv_post_channel_switch(link);
1787 "driver post channel switch failed, disconnecting\n");
1788 wiphy_work_queue(sdata->local->hw.wiphy,
1789 &ifmgd->csa_connection_drop_work);
1793 cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef,
1797 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success,
1798 unsigned int link_id)
1800 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1802 trace_api_chswitch_done(sdata, success, link_id);
1808 "driver channel switch failed, disconnecting\n");
1809 wiphy_work_queue(sdata->local->hw.wiphy,
1810 &sdata->u.mgd.csa_connection_drop_work);
1812 struct ieee80211_link_data *link =
1813 rcu_dereference(sdata->link[link_id]);
1815 if (WARN_ON(!link)) {
1820 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
1821 &link->u.mgd.chswitch_work, 0);
1826 EXPORT_SYMBOL(ieee80211_chswitch_done);
1829 ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
1831 struct ieee80211_sub_if_data *sdata = link->sdata;
1832 struct ieee80211_local *local = sdata->local;
1834 lockdep_assert_wiphy(local->hw.wiphy);
1836 if (!local->ops->abort_channel_switch)
1839 ieee80211_link_unreserve_chanctx(link);
1841 if (link->csa_block_tx)
1842 ieee80211_wake_vif_queues(local, sdata,
1843 IEEE80211_QUEUE_STOP_REASON_CSA);
1845 link->csa_block_tx = false;
1846 link->conf->csa_active = false;
1848 drv_abort_channel_switch(sdata);
1852 ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
1853 u64 timestamp, u32 device_timestamp,
1854 struct ieee802_11_elems *elems,
1857 struct ieee80211_sub_if_data *sdata = link->sdata;
1858 struct ieee80211_local *local = sdata->local;
1859 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1860 struct cfg80211_bss *cbss = link->u.mgd.bss;
1861 struct ieee80211_chanctx_conf *conf;
1862 struct ieee80211_chanctx *chanctx;
1863 enum nl80211_band current_band;
1864 struct ieee80211_csa_ie csa_ie;
1865 struct ieee80211_channel_switch ch_switch;
1866 struct ieee80211_bss *bss;
1867 unsigned long timeout;
1870 lockdep_assert_wiphy(local->hw.wiphy);
1875 current_band = cbss->channel->band;
1876 bss = (void *)cbss->priv;
1877 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1879 link->u.mgd.conn_flags,
1880 link->u.mgd.bssid, &csa_ie);
1883 ch_switch.timestamp = timestamp;
1884 ch_switch.device_timestamp = device_timestamp;
1885 ch_switch.block_tx = csa_ie.mode;
1886 ch_switch.chandef = csa_ie.chandef;
1887 ch_switch.count = csa_ie.count;
1888 ch_switch.delay = csa_ie.max_switch_time;
1892 goto drop_connection;
1894 if (beacon && link->conf->csa_active &&
1895 !link->u.mgd.csa_waiting_bcn) {
1897 ieee80211_sta_abort_chanswitch(link);
1899 drv_channel_switch_rx_beacon(sdata, &ch_switch);
1901 } else if (link->conf->csa_active || res) {
1902 /* disregard subsequent announcements if already processing */
1906 if (link->conf->chandef.chan->band !=
1907 csa_ie.chandef.chan->band) {
1909 "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1911 csa_ie.chandef.chan->center_freq,
1912 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1913 csa_ie.chandef.center_freq2);
1914 goto drop_connection;
1917 if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
1918 IEEE80211_CHAN_DISABLED)) {
1920 "AP %pM switches to unsupported channel "
1921 "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
1924 csa_ie.chandef.chan->center_freq,
1925 csa_ie.chandef.chan->freq_offset,
1926 csa_ie.chandef.width, csa_ie.chandef.center_freq1,
1927 csa_ie.chandef.freq1_offset,
1928 csa_ie.chandef.center_freq2);
1929 goto drop_connection;
1932 if (cfg80211_chandef_identical(&csa_ie.chandef,
1933 &link->conf->chandef) &&
1934 (!csa_ie.mode || !beacon)) {
1935 if (link->u.mgd.csa_ignored_same_chan)
1938 "AP %pM tries to chanswitch to same channel, ignore\n",
1940 link->u.mgd.csa_ignored_same_chan = true;
1945 * Drop all TDLS peers - either we disconnect or move to a different
1946 * channel from this point on. There's no telling what our peer will do.
1947 * The TDLS WIDER_BW scenario is also problematic, as peers might now
1948 * have an incompatible wider chandef.
1950 ieee80211_teardown_tdls_peers(sdata);
1952 conf = rcu_dereference_protected(link->conf->chanctx_conf,
1953 lockdep_is_held(&local->hw.wiphy->mtx));
1956 "no channel context assigned to vif?, disconnecting\n");
1957 goto drop_connection;
1960 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
1962 if (local->use_chanctx &&
1963 !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
1965 "driver doesn't support chan-switch with channel contexts\n");
1966 goto drop_connection;
1969 if (drv_pre_channel_switch(sdata, &ch_switch)) {
1971 "preparing for channel switch failed, disconnecting\n");
1972 goto drop_connection;
1975 res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
1976 chanctx->mode, false);
1979 "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
1981 goto drop_connection;
1984 link->conf->csa_active = true;
1985 link->csa_chandef = csa_ie.chandef;
1986 link->csa_block_tx = csa_ie.mode;
1987 link->u.mgd.csa_ignored_same_chan = false;
1988 link->u.mgd.beacon_crc_valid = false;
1990 if (link->csa_block_tx)
1991 ieee80211_stop_vif_queues(local, sdata,
1992 IEEE80211_QUEUE_STOP_REASON_CSA);
1994 cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
1995 link->link_id, csa_ie.count,
1998 if (local->ops->channel_switch) {
1999 /* use driver's channel switch callback */
2000 drv_channel_switch(local, sdata, &ch_switch);
2004 /* channel switch handled in software */
2005 timeout = TU_TO_JIFFIES((max_t(int, csa_ie.count, 1) - 1) *
2006 cbss->beacon_interval);
2007 wiphy_delayed_work_queue(local->hw.wiphy,
2008 &link->u.mgd.chswitch_work,
2013 * This is just so that the disconnect flow will know that
2014 * we were trying to switch channel and failed. In case the
2015 * mode is 1 (we are not allowed to Tx), we will know not to
2016 * send a deauthentication frame. Those two fields will be
2017 * reset when the disconnection worker runs.
2019 link->conf->csa_active = true;
2020 link->csa_block_tx = csa_ie.mode;
2022 wiphy_work_queue(sdata->local->hw.wiphy,
2023 &ifmgd->csa_connection_drop_work);
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 u64 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 wiphy_work_cancel(local->hw.wiphy,
2220 &local->dynamic_ps_enable_work);
2224 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
2226 struct ieee80211_local *local = sdata->local;
2227 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
2228 struct sta_info *sta = NULL;
2229 bool authorized = false;
2231 if (!mgd->powersave)
2237 if (!mgd->associated)
2240 if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
2243 if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
2244 !sdata->deflink.u.mgd.have_beacon)
2248 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
2250 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
2256 /* need to hold RTNL or interface lock */
2257 void ieee80211_recalc_ps(struct ieee80211_local *local)
2259 struct ieee80211_sub_if_data *sdata, *found = NULL;
2263 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
2264 ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
2265 local->ps_sdata = NULL;
2269 list_for_each_entry(sdata, &local->interfaces, list) {
2270 if (!ieee80211_sdata_running(sdata))
2272 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2273 /* If an AP vif is found, then disable PS
2274 * by setting the count to zero thereby setting
2280 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2286 if (count == 1 && ieee80211_powersave_allowed(found)) {
2287 u8 dtimper = found->deflink.u.mgd.dtim_period;
2289 timeout = local->dynamic_ps_forced_timeout;
2292 local->hw.conf.dynamic_ps_timeout = timeout;
2294 /* If the TIM IE is invalid, pretend the value is 1 */
2298 local->hw.conf.ps_dtim_period = dtimper;
2299 local->ps_sdata = found;
2301 local->ps_sdata = NULL;
2304 ieee80211_change_ps(local);
2307 void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
2309 bool ps_allowed = ieee80211_powersave_allowed(sdata);
2311 if (sdata->vif.cfg.ps != ps_allowed) {
2312 sdata->vif.cfg.ps = ps_allowed;
2313 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
2317 void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy,
2318 struct wiphy_work *work)
2320 struct ieee80211_local *local =
2321 container_of(work, struct ieee80211_local,
2322 dynamic_ps_disable_work);
2324 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2325 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2326 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2329 ieee80211_wake_queues_by_reason(&local->hw,
2330 IEEE80211_MAX_QUEUE_MAP,
2331 IEEE80211_QUEUE_STOP_REASON_PS,
2335 void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy,
2336 struct wiphy_work *work)
2338 struct ieee80211_local *local =
2339 container_of(work, struct ieee80211_local,
2340 dynamic_ps_enable_work);
2341 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
2342 struct ieee80211_if_managed *ifmgd;
2343 unsigned long flags;
2346 /* can only happen when PS was just disabled anyway */
2350 ifmgd = &sdata->u.mgd;
2352 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2355 if (local->hw.conf.dynamic_ps_timeout > 0) {
2356 /* don't enter PS if TX frames are pending */
2357 if (drv_tx_frames_pending(local)) {
2358 mod_timer(&local->dynamic_ps_timer, jiffies +
2360 local->hw.conf.dynamic_ps_timeout));
2365 * transmission can be stopped by others which leads to
2366 * dynamic_ps_timer expiry. Postpone the ps timer if it
2367 * is not the actual idle state.
2369 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
2370 for (q = 0; q < local->hw.queues; q++) {
2371 if (local->queue_stop_reasons[q]) {
2372 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
2374 mod_timer(&local->dynamic_ps_timer, jiffies +
2376 local->hw.conf.dynamic_ps_timeout));
2380 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
2383 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
2384 !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2385 if (drv_tx_frames_pending(local)) {
2386 mod_timer(&local->dynamic_ps_timer, jiffies +
2388 local->hw.conf.dynamic_ps_timeout));
2390 ieee80211_send_nullfunc(local, sdata, true);
2391 /* Flush to get the tx status of nullfunc frame */
2392 ieee80211_flush_queues(local, sdata, false);
2396 if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
2397 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
2398 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
2399 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2400 local->hw.conf.flags |= IEEE80211_CONF_PS;
2401 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2405 void ieee80211_dynamic_ps_timer(struct timer_list *t)
2407 struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
2409 wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work);
2412 void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work)
2414 struct ieee80211_link_data *link =
2415 container_of(work, struct ieee80211_link_data,
2416 dfs_cac_timer_work.work);
2417 struct cfg80211_chan_def chandef = link->conf->chandef;
2418 struct ieee80211_sub_if_data *sdata = link->sdata;
2420 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2422 if (sdata->wdev.cac_started) {
2423 ieee80211_link_release_channel(link);
2424 cfg80211_cac_event(sdata->dev, &chandef,
2425 NL80211_RADAR_CAC_FINISHED,
2431 __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2433 struct ieee80211_local *local = sdata->local;
2434 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2438 if (local->hw.queues < IEEE80211_NUM_ACS)
2441 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2442 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
2444 unsigned long now = jiffies;
2446 if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
2447 tx_tspec->admitted_time &&
2448 time_after(now, tx_tspec->time_slice_start + HZ)) {
2449 tx_tspec->consumed_tx_time = 0;
2450 tx_tspec->time_slice_start = now;
2452 if (tx_tspec->downgraded)
2454 TX_TSPEC_ACTION_STOP_DOWNGRADE;
2457 switch (tx_tspec->action) {
2458 case TX_TSPEC_ACTION_STOP_DOWNGRADE:
2459 /* take the original parameters */
2460 if (drv_conf_tx(local, &sdata->deflink, ac,
2461 &sdata->deflink.tx_conf[ac]))
2462 link_err(&sdata->deflink,
2463 "failed to set TX queue parameters for queue %d\n",
2465 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2466 tx_tspec->downgraded = false;
2469 case TX_TSPEC_ACTION_DOWNGRADE:
2470 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
2471 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2475 /* downgrade next lower non-ACM AC */
2476 for (non_acm_ac = ac + 1;
2477 non_acm_ac < IEEE80211_NUM_ACS;
2479 if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
2481 /* Usually the loop will result in using BK even if it
2482 * requires admission control, but such a configuration
2483 * makes no sense and we have to transmit somehow - the
2484 * AC selection does the same thing.
2485 * If we started out trying to downgrade from BK, then
2486 * the extra condition here might be needed.
2488 if (non_acm_ac >= IEEE80211_NUM_ACS)
2489 non_acm_ac = IEEE80211_AC_BK;
2490 if (drv_conf_tx(local, &sdata->deflink, ac,
2491 &sdata->deflink.tx_conf[non_acm_ac]))
2492 link_err(&sdata->deflink,
2493 "failed to set TX queue parameters for queue %d\n",
2495 tx_tspec->action = TX_TSPEC_ACTION_NONE;
2497 wiphy_delayed_work_queue(local->hw.wiphy,
2498 &ifmgd->tx_tspec_wk,
2499 tx_tspec->time_slice_start +
2502 case TX_TSPEC_ACTION_NONE:
2511 void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
2513 if (__ieee80211_sta_handle_tspec_ac_params(sdata))
2514 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
2518 static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy,
2519 struct wiphy_work *work)
2521 struct ieee80211_sub_if_data *sdata;
2523 sdata = container_of(work, struct ieee80211_sub_if_data,
2524 u.mgd.tx_tspec_wk.work);
2525 ieee80211_sta_handle_tspec_ac_params(sdata);
2528 void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
2530 struct ieee80211_sub_if_data *sdata = link->sdata;
2531 struct ieee80211_local *local = sdata->local;
2532 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2533 struct ieee80211_tx_queue_params *params = link->tx_conf;
2536 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2538 "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
2540 params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
2541 params[ac].txop, params[ac].uapsd,
2542 ifmgd->tx_tspec[ac].downgraded);
2543 if (!ifmgd->tx_tspec[ac].downgraded &&
2544 drv_conf_tx(local, link, ac, ¶ms[ac]))
2546 "failed to set TX queue parameters for AC %d\n",
2553 ieee80211_sta_wmm_params(struct ieee80211_local *local,
2554 struct ieee80211_link_data *link,
2555 const u8 *wmm_param, size_t wmm_param_len,
2556 const struct ieee80211_mu_edca_param_set *mu_edca)
2558 struct ieee80211_sub_if_data *sdata = link->sdata;
2559 struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
2560 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2562 int count, mu_edca_count, ac;
2564 u8 uapsd_queues = 0;
2566 if (!local->ops->conf_tx)
2569 if (local->hw.queues < IEEE80211_NUM_ACS)
2575 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
2578 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
2579 uapsd_queues = ifmgd->uapsd_queues;
2581 count = wmm_param[6] & 0x0f;
2582 /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
2583 * if mu_edca was preset before and now it disappeared tell
2584 * the driver about it.
2586 mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
2587 if (count == link->u.mgd.wmm_last_param_set &&
2588 mu_edca_count == link->u.mgd.mu_edca_last_param_set)
2590 link->u.mgd.wmm_last_param_set = count;
2591 link->u.mgd.mu_edca_last_param_set = mu_edca_count;
2593 pos = wmm_param + 8;
2594 left = wmm_param_len - 8;
2596 memset(¶ms, 0, sizeof(params));
2599 for (; left >= 4; left -= 4, pos += 4) {
2600 int aci = (pos[0] >> 5) & 0x03;
2601 int acm = (pos[0] >> 4) & 0x01;
2606 ac = IEEE80211_AC_BK;
2608 sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
2609 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2611 params[ac].mu_edca = !!mu_edca;
2613 params[ac].mu_edca_param_rec = mu_edca->ac_bk;
2616 ac = IEEE80211_AC_VI;
2618 sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
2619 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2621 params[ac].mu_edca = !!mu_edca;
2623 params[ac].mu_edca_param_rec = mu_edca->ac_vi;
2626 ac = IEEE80211_AC_VO;
2628 sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
2629 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2631 params[ac].mu_edca = !!mu_edca;
2633 params[ac].mu_edca_param_rec = mu_edca->ac_vo;
2637 ac = IEEE80211_AC_BE;
2639 sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
2640 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2642 params[ac].mu_edca = !!mu_edca;
2644 params[ac].mu_edca_param_rec = mu_edca->ac_be;
2648 params[ac].aifs = pos[0] & 0x0f;
2650 if (params[ac].aifs < 2) {
2652 "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
2653 params[ac].aifs, aci);
2654 params[ac].aifs = 2;
2656 params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
2657 params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
2658 params[ac].txop = get_unaligned_le16(pos + 2);
2659 params[ac].acm = acm;
2660 params[ac].uapsd = uapsd;
2662 if (params[ac].cw_min == 0 ||
2663 params[ac].cw_min > params[ac].cw_max) {
2665 "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
2666 params[ac].cw_min, params[ac].cw_max, aci);
2669 ieee80211_regulatory_limit_wmm_params(sdata, ¶ms[ac], ac);
2672 /* WMM specification requires all 4 ACIs. */
2673 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
2674 if (params[ac].cw_min == 0) {
2676 "AP has invalid WMM params (missing AC %d), using defaults\n",
2682 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2683 link->tx_conf[ac] = params[ac];
2685 ieee80211_mgd_set_link_qos_params(link);
2687 /* enable WMM or activate new settings */
2688 link->conf->qos = true;
2692 static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2694 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2696 sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
2697 ieee80211_run_deferred_scan(sdata->local);
2700 static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
2702 lockdep_assert_wiphy(sdata->local->hw.wiphy);
2704 __ieee80211_stop_poll(sdata);
2707 static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
2708 u16 capab, bool erp_valid, u8 erp)
2710 struct ieee80211_bss_conf *bss_conf = link->conf;
2711 struct ieee80211_supported_band *sband;
2713 bool use_protection;
2714 bool use_short_preamble;
2715 bool use_short_slot;
2717 sband = ieee80211_get_link_sband(link);
2722 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
2723 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
2725 use_protection = false;
2726 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
2729 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
2730 if (sband->band == NL80211_BAND_5GHZ ||
2731 sband->band == NL80211_BAND_6GHZ)
2732 use_short_slot = true;
2734 if (use_protection != bss_conf->use_cts_prot) {
2735 bss_conf->use_cts_prot = use_protection;
2736 changed |= BSS_CHANGED_ERP_CTS_PROT;
2739 if (use_short_preamble != bss_conf->use_short_preamble) {
2740 bss_conf->use_short_preamble = use_short_preamble;
2741 changed |= BSS_CHANGED_ERP_PREAMBLE;
2744 if (use_short_slot != bss_conf->use_short_slot) {
2745 bss_conf->use_short_slot = use_short_slot;
2746 changed |= BSS_CHANGED_ERP_SLOT;
2752 static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
2753 struct cfg80211_bss *cbss)
2755 struct ieee80211_sub_if_data *sdata = link->sdata;
2756 struct ieee80211_bss_conf *bss_conf = link->conf;
2757 struct ieee80211_bss *bss = (void *)cbss->priv;
2758 u64 changed = BSS_CHANGED_QOS;
2760 /* not really used in MLO */
2761 sdata->u.mgd.beacon_timeout =
2762 usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
2763 bss_conf->beacon_int));
2765 changed |= ieee80211_handle_bss_capability(link,
2766 bss_conf->assoc_capability,
2770 ieee80211_check_rate_mask(link);
2772 link->u.mgd.bss = cbss;
2773 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
2775 if (sdata->vif.p2p ||
2776 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
2777 const struct cfg80211_bss_ies *ies;
2780 ies = rcu_dereference(cbss->ies);
2784 ret = cfg80211_get_p2p_attr(
2785 ies->data, ies->len,
2786 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
2787 (u8 *) &bss_conf->p2p_noa_attr,
2788 sizeof(bss_conf->p2p_noa_attr));
2790 link->u.mgd.p2p_noa_index =
2791 bss_conf->p2p_noa_attr.index;
2792 changed |= BSS_CHANGED_P2P_PS;
2798 if (link->u.mgd.have_beacon) {
2799 bss_conf->beacon_rate = bss->beacon_rate;
2800 changed |= BSS_CHANGED_BEACON_INFO;
2802 bss_conf->beacon_rate = NULL;
2805 /* Tell the driver to monitor connection quality (if supported) */
2806 if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
2807 bss_conf->cqm_rssi_thold)
2808 changed |= BSS_CHANGED_CQM;
2813 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
2814 struct ieee80211_mgd_assoc_data *assoc_data,
2815 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
2817 struct ieee80211_local *local = sdata->local;
2818 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
2819 u64 vif_changed = BSS_CHANGED_ASSOC;
2820 unsigned int link_id;
2822 lockdep_assert_wiphy(local->hw.wiphy);
2824 sdata->u.mgd.associated = true;
2826 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
2827 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2828 struct ieee80211_link_data *link;
2831 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2834 if (ieee80211_vif_is_mld(&sdata->vif) &&
2835 !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id)))
2838 link = sdata_dereference(sdata->link[link_id], sdata);
2842 changed[link_id] |= ieee80211_link_set_associated(link, cbss);
2845 /* just to be sure */
2846 ieee80211_stop_poll(sdata);
2848 ieee80211_led_assoc(local, 1);
2852 /* Enable ARP filtering */
2853 if (vif_cfg->arp_addr_cnt)
2854 vif_changed |= BSS_CHANGED_ARP_FILTER;
2856 if (ieee80211_vif_is_mld(&sdata->vif)) {
2858 link_id < IEEE80211_MLD_MAX_NUM_LINKS;
2860 struct ieee80211_link_data *link;
2861 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
2865 ieee80211_vif_usable_links(&sdata->vif)) ||
2866 assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
2869 link = sdata_dereference(sdata->link[link_id], sdata);
2873 ieee80211_link_info_change_notify(sdata, link,
2876 ieee80211_recalc_smps(sdata, link);
2879 ieee80211_vif_cfg_change_notify(sdata, vif_changed);
2881 ieee80211_bss_info_change_notify(sdata,
2882 vif_changed | changed[0]);
2885 ieee80211_recalc_ps(local);
2887 /* leave this here to not change ordering in non-MLO cases */
2888 if (!ieee80211_vif_is_mld(&sdata->vif))
2889 ieee80211_recalc_smps(sdata, &sdata->deflink);
2890 ieee80211_recalc_ps_vif(sdata);
2892 netif_carrier_on(sdata->dev);
2895 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
2896 u16 stype, u16 reason, bool tx,
2899 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2900 struct ieee80211_local *local = sdata->local;
2901 unsigned int link_id;
2903 struct ieee80211_prep_tx_info info = {
2907 lockdep_assert_wiphy(local->hw.wiphy);
2909 if (WARN_ON_ONCE(tx && !frame_buf))
2912 if (WARN_ON(!ifmgd->associated))
2915 ieee80211_stop_poll(sdata);
2917 ifmgd->associated = false;
2919 /* other links will be destroyed */
2920 sdata->deflink.u.mgd.bss = NULL;
2922 netif_carrier_off(sdata->dev);
2925 * if we want to get out of ps before disassoc (why?) we have
2926 * to do it before sending disassoc, as otherwise the null-packet
2929 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2930 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2931 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2933 local->ps_sdata = NULL;
2935 /* disable per-vif ps */
2936 ieee80211_recalc_ps_vif(sdata);
2938 /* make sure ongoing transmission finishes */
2942 * drop any frame before deauth/disassoc, this can be data or
2943 * management frame. Since we are disconnecting, we should not
2944 * insist sending these frames which can take time and delay
2945 * the disconnection and possible the roaming.
2948 ieee80211_flush_queues(local, sdata, true);
2950 /* deauthenticate/disassociate now */
2951 if (tx || frame_buf) {
2953 * In multi channel scenarios guarantee that the virtual
2954 * interface is granted immediate airtime to transmit the
2955 * deauthentication frame by calling mgd_prepare_tx, if the
2956 * driver requested so.
2958 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP)) {
2959 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link);
2961 struct ieee80211_link_data *link;
2963 link = sdata_dereference(sdata->link[link_id],
2967 if (link->u.mgd.have_beacon)
2970 if (link_id == IEEE80211_MLD_MAX_NUM_LINKS) {
2971 info.link_id = ffs(sdata->vif.active_links) - 1;
2972 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2976 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2977 sdata->vif.cfg.ap_addr, stype,
2978 reason, tx, frame_buf);
2981 /* flush out frame - make sure the deauth was actually sent */
2983 ieee80211_flush_queues(local, sdata, false);
2985 drv_mgd_complete_tx(sdata->local, sdata, &info);
2987 /* clear AP addr only after building the needed mgmt frames */
2988 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2989 eth_zero_addr(sdata->vif.cfg.ap_addr);
2991 sdata->vif.cfg.ssid_len = 0;
2993 /* remove AP and TDLS peers */
2994 sta_info_flush(sdata);
2996 /* finally reset all BSS / config parameters */
2997 if (!ieee80211_vif_is_mld(&sdata->vif))
2998 changed |= ieee80211_reset_erp_info(sdata);
3000 ieee80211_led_assoc(local, 0);
3001 changed |= BSS_CHANGED_ASSOC;
3002 sdata->vif.cfg.assoc = false;
3004 sdata->deflink.u.mgd.p2p_noa_index = -1;
3005 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
3006 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
3008 /* on the next assoc, re-program HT/VHT parameters */
3009 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
3010 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
3011 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
3012 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
3015 * reset MU-MIMO ownership and group data in default link,
3016 * if used, other links are destroyed
3018 memset(sdata->vif.bss_conf.mu_group.membership, 0,
3019 sizeof(sdata->vif.bss_conf.mu_group.membership));
3020 memset(sdata->vif.bss_conf.mu_group.position, 0,
3021 sizeof(sdata->vif.bss_conf.mu_group.position));
3022 if (!ieee80211_vif_is_mld(&sdata->vif))
3023 changed |= BSS_CHANGED_MU_GROUPS;
3024 sdata->vif.bss_conf.mu_mimo_owner = false;
3026 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3028 del_timer_sync(&local->dynamic_ps_timer);
3029 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
3031 /* Disable ARP filtering */
3032 if (sdata->vif.cfg.arp_addr_cnt)
3033 changed |= BSS_CHANGED_ARP_FILTER;
3035 sdata->vif.bss_conf.qos = false;
3036 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3037 changed |= BSS_CHANGED_QOS;
3038 /* The BSSID (not really interesting) and HT changed */
3039 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3040 ieee80211_bss_info_change_notify(sdata, changed);
3042 ieee80211_vif_cfg_change_notify(sdata, changed);
3045 /* disassociated - set to defaults now */
3046 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3048 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3049 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3050 del_timer_sync(&sdata->u.mgd.timer);
3052 sdata->vif.bss_conf.dtim_period = 0;
3053 sdata->vif.bss_conf.beacon_rate = NULL;
3055 sdata->deflink.u.mgd.have_beacon = false;
3056 sdata->deflink.u.mgd.tracking_signal_avg = false;
3057 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3060 sdata->deflink.u.mgd.conn_flags = 0;
3062 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3063 struct ieee80211_link_data *link;
3065 link = sdata_dereference(sdata->link[link_id], sdata);
3068 ieee80211_link_release_channel(link);
3071 sdata->vif.bss_conf.csa_active = false;
3072 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3073 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
3074 if (sdata->deflink.csa_block_tx) {
3075 ieee80211_wake_vif_queues(local, sdata,
3076 IEEE80211_QUEUE_STOP_REASON_CSA);
3077 sdata->deflink.csa_block_tx = false;
3080 /* existing TX TSPEC sessions no longer exist */
3081 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3082 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk);
3084 sdata->vif.bss_conf.pwr_reduction = 0;
3085 sdata->vif.bss_conf.tx_pwr_env_num = 0;
3086 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
3087 sizeof(sdata->vif.bss_conf.tx_pwr_env));
3089 memset(&sdata->u.mgd.ttlm_info, 0,
3090 sizeof(sdata->u.mgd.ttlm_info));
3091 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
3092 ieee80211_vif_set_links(sdata, 0, 0);
3095 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3097 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3098 struct ieee80211_local *local = sdata->local;
3100 lockdep_assert_wiphy(local->hw.wiphy);
3102 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3105 __ieee80211_stop_poll(sdata);
3107 ieee80211_recalc_ps(local);
3109 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3113 * We've received a probe response, but are not sure whether
3114 * we have or will be receiving any beacons or data, so let's
3115 * schedule the timers again, just in case.
3117 ieee80211_sta_reset_beacon_monitor(sdata);
3119 mod_timer(&ifmgd->conn_mon_timer,
3120 round_jiffies_up(jiffies +
3121 IEEE80211_CONNECTION_IDLE_TIME));
3124 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3125 struct ieee80211_hdr *hdr,
3128 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3131 struct ieee80211_sta_tx_tspec *tx_tspec;
3132 unsigned long now = jiffies;
3134 if (!ieee80211_is_data_qos(hdr->frame_control))
3137 tid = ieee80211_get_tid(hdr);
3138 ac = ieee80211_ac_from_tid(tid);
3139 tx_tspec = &ifmgd->tx_tspec[ac];
3141 if (likely(!tx_tspec->admitted_time))
3144 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3145 tx_tspec->consumed_tx_time = 0;
3146 tx_tspec->time_slice_start = now;
3148 if (tx_tspec->downgraded) {
3149 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3150 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3151 &ifmgd->tx_tspec_wk, 0);
3155 if (tx_tspec->downgraded)
3158 tx_tspec->consumed_tx_time += tx_time;
3160 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3161 tx_tspec->downgraded = true;
3162 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3163 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3164 &ifmgd->tx_tspec_wk, 0);
3168 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3169 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3171 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3173 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3174 !sdata->u.mgd.probe_send_count)
3178 sdata->u.mgd.probe_send_count = 0;
3180 sdata->u.mgd.nullfunc_failed = true;
3181 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
3184 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3185 const u8 *src, const u8 *dst,
3186 const u8 *ssid, size_t ssid_len,
3187 struct ieee80211_channel *channel)
3189 struct sk_buff *skb;
3191 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3192 ssid, ssid_len, NULL, 0,
3193 IEEE80211_PROBE_FLAG_DIRECTED);
3195 ieee80211_tx_skb(sdata, skb);
3198 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3200 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3201 u8 *dst = sdata->vif.cfg.ap_addr;
3202 u8 unicast_limit = max(1, max_probe_tries - 3);
3203 struct sta_info *sta;
3205 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3207 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
3211 * Try sending broadcast probe requests for the last three
3212 * probe requests after the first ones failed since some
3213 * buggy APs only support broadcast probe requests.
3215 if (ifmgd->probe_send_count >= unicast_limit)
3219 * When the hardware reports an accurate Tx ACK status, it's
3220 * better to send a nullfunc frame instead of a probe request,
3221 * as it will kick us off the AP quickly if we aren't associated
3222 * anymore. The timeout will be reset if the frame is ACKed by
3225 ifmgd->probe_send_count++;
3228 sta = sta_info_get(sdata, dst);
3230 ieee80211_check_fast_rx(sta);
3233 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3234 ifmgd->nullfunc_failed = false;
3235 ieee80211_send_nullfunc(sdata->local, sdata, false);
3237 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3238 sdata->vif.cfg.ssid,
3239 sdata->vif.cfg.ssid_len,
3240 sdata->deflink.u.mgd.bss->channel);
3243 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3244 run_again(sdata, ifmgd->probe_timeout);
3247 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3250 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3251 bool already = false;
3253 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3255 if (WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif)))
3258 if (!ieee80211_sdata_running(sdata))
3261 if (!ifmgd->associated)
3264 if (sdata->local->tmp_channel || sdata->local->scanning)
3267 if (sdata->local->suspending) {
3268 /* reschedule after resume */
3269 ieee80211_reset_ap_probe(sdata);
3274 mlme_dbg_ratelimited(sdata,
3275 "detected beacon loss from AP (missed %d beacons) - probing\n",
3278 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3282 * The driver/our work has already reported this event or the
3283 * connection monitoring has kicked in and we have already sent
3284 * a probe request. Or maybe the AP died and the driver keeps
3285 * reporting until we disassociate...
3287 * In either case we have to ignore the current call to this
3288 * function (except for setting the correct probe reason bit)
3289 * because otherwise we would reset the timer every time and
3290 * never check whether we received a probe response!
3292 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3295 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3300 ieee80211_recalc_ps(sdata->local);
3302 ifmgd->probe_send_count = 0;
3303 ieee80211_mgd_probe_ap_send(sdata);
3306 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3307 struct ieee80211_vif *vif)
3309 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3310 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3311 struct cfg80211_bss *cbss;
3312 struct sk_buff *skb;
3313 const struct element *ssid;
3316 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3318 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3319 ieee80211_vif_is_mld(&sdata->vif)))
3322 if (ifmgd->associated)
3323 cbss = sdata->deflink.u.mgd.bss;
3324 else if (ifmgd->auth_data)
3325 cbss = ifmgd->auth_data->bss;
3326 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3327 cbss = ifmgd->assoc_data->link[0].bss;
3332 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3333 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3334 "invalid SSID element (len=%d)",
3335 ssid ? ssid->datalen : -1))
3338 ssid_len = ssid->datalen;
3340 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3341 (u32) -1, cbss->channel,
3342 ssid->data, ssid_len,
3343 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3348 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3350 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3351 const u8 *buf, size_t len, bool tx,
3352 u16 reason, bool reconnect)
3354 struct ieee80211_event event = {
3356 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3357 .u.mlme.reason = reason,
3361 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3363 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3365 drv_event_callback(sdata->local, sdata, &event);
3368 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3370 struct ieee80211_local *local = sdata->local;
3371 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3372 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3375 lockdep_assert_wiphy(local->hw.wiphy);
3377 if (!ifmgd->associated)
3380 /* in MLO assume we have a link where we can TX the frame */
3381 tx = ieee80211_vif_is_mld(&sdata->vif) ||
3382 !sdata->deflink.csa_block_tx;
3384 if (!ifmgd->driver_disconnect) {
3385 unsigned int link_id;
3388 * AP is probably out of range (or not reachable for another
3389 * reason) so remove the bss structs for that AP. In the case
3390 * of multi-link, it's not clear that all of them really are
3391 * out of range, but if they weren't the driver likely would
3392 * have switched to just have a single link active?
3395 link_id < ARRAY_SIZE(sdata->link);
3397 struct ieee80211_link_data *link;
3399 link = sdata_dereference(sdata->link[link_id], sdata);
3402 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3403 link->u.mgd.bss = NULL;
3407 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3408 ifmgd->driver_disconnect ?
3409 WLAN_REASON_DEAUTH_LEAVING :
3410 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3412 /* the other links will be destroyed */
3413 sdata->vif.bss_conf.csa_active = false;
3414 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3415 if (sdata->deflink.csa_block_tx) {
3416 ieee80211_wake_vif_queues(local, sdata,
3417 IEEE80211_QUEUE_STOP_REASON_CSA);
3418 sdata->deflink.csa_block_tx = false;
3421 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3422 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3424 ifmgd->reconnect = false;
3427 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
3428 struct wiphy_work *work)
3430 struct ieee80211_sub_if_data *sdata =
3431 container_of(work, struct ieee80211_sub_if_data,
3432 u.mgd.beacon_connection_loss_work);
3433 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3435 if (ifmgd->connection_loss) {
3436 sdata_info(sdata, "Connection to AP %pM lost\n",
3437 sdata->vif.cfg.ap_addr);
3438 __ieee80211_disconnect(sdata);
3439 ifmgd->connection_loss = false;
3440 } else if (ifmgd->driver_disconnect) {
3442 "Driver requested disconnection from AP %pM\n",
3443 sdata->vif.cfg.ap_addr);
3444 __ieee80211_disconnect(sdata);
3445 ifmgd->driver_disconnect = false;
3447 if (ifmgd->associated)
3448 sdata->deflink.u.mgd.beacon_loss_count++;
3449 ieee80211_mgd_probe_ap(sdata, true);
3453 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
3454 struct wiphy_work *work)
3456 struct ieee80211_sub_if_data *sdata =
3457 container_of(work, struct ieee80211_sub_if_data,
3458 u.mgd.csa_connection_drop_work);
3460 __ieee80211_disconnect(sdata);
3463 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3465 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3466 struct ieee80211_hw *hw = &sdata->local->hw;
3468 trace_api_beacon_loss(sdata);
3470 sdata->u.mgd.connection_loss = false;
3471 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3473 EXPORT_SYMBOL(ieee80211_beacon_loss);
3475 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3477 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3478 struct ieee80211_hw *hw = &sdata->local->hw;
3480 trace_api_connection_loss(sdata);
3482 sdata->u.mgd.connection_loss = true;
3483 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3485 EXPORT_SYMBOL(ieee80211_connection_loss);
3487 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3489 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3490 struct ieee80211_hw *hw = &sdata->local->hw;
3492 trace_api_disconnect(sdata, reconnect);
3494 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3497 sdata->u.mgd.driver_disconnect = true;
3498 sdata->u.mgd.reconnect = reconnect;
3499 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3501 EXPORT_SYMBOL(ieee80211_disconnect);
3503 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3506 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3508 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3512 * we are not authenticated yet, the only timer that could be
3513 * running is the timeout for the authentication response which
3514 * which is not relevant anymore.
3516 del_timer_sync(&sdata->u.mgd.timer);
3517 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3519 /* other links are destroyed */
3520 sdata->deflink.u.mgd.conn_flags = 0;
3521 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3522 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3524 sdata->u.mgd.flags = 0;
3526 ieee80211_link_release_channel(&sdata->deflink);
3527 ieee80211_vif_set_links(sdata, 0, 0);
3530 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3532 sdata->u.mgd.auth_data = NULL;
3542 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3543 enum assoc_status status)
3545 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3547 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3549 if (status != ASSOC_SUCCESS) {
3551 * we are not associated yet, the only timer that could be
3552 * running is the timeout for the association response which
3553 * which is not relevant anymore.
3555 del_timer_sync(&sdata->u.mgd.timer);
3556 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3558 sdata->deflink.u.mgd.conn_flags = 0;
3559 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3560 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3562 sdata->u.mgd.flags = 0;
3563 sdata->vif.bss_conf.mu_mimo_owner = false;
3565 if (status != ASSOC_REJECTED) {
3566 struct cfg80211_assoc_failure data = {
3567 .timeout = status == ASSOC_TIMEOUT,
3571 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3572 ARRAY_SIZE(assoc_data->link));
3574 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3575 data.bss[i] = assoc_data->link[i].bss;
3577 if (ieee80211_vif_is_mld(&sdata->vif))
3578 data.ap_mld_addr = assoc_data->ap_addr;
3580 cfg80211_assoc_failure(sdata->dev, &data);
3583 ieee80211_link_release_channel(&sdata->deflink);
3584 ieee80211_vif_set_links(sdata, 0, 0);
3588 sdata->u.mgd.assoc_data = NULL;
3591 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3592 struct ieee80211_mgmt *mgmt, size_t len)
3594 struct ieee80211_local *local = sdata->local;
3595 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3596 const struct element *challenge;
3599 struct ieee80211_prep_tx_info info = {
3600 .subtype = IEEE80211_STYPE_AUTH,
3601 .link_id = auth_data->link_id,
3604 pos = mgmt->u.auth.variable;
3605 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3606 len - (pos - (u8 *)mgmt));
3609 auth_data->expected_transaction = 4;
3610 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3611 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3612 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3613 IEEE80211_TX_INTFL_MLME_CONN_TX;
3614 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3616 challenge->datalen + sizeof(*challenge),
3617 auth_data->ap_addr, auth_data->ap_addr,
3618 auth_data->key, auth_data->key_len,
3619 auth_data->key_idx, tx_flags);
3622 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3624 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3625 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3626 struct sta_info *sta;
3628 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3630 sdata_info(sdata, "authenticated\n");
3631 ifmgd->auth_data->done = true;
3632 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3633 ifmgd->auth_data->timeout_started = true;
3634 run_again(sdata, ifmgd->auth_data->timeout);
3636 /* move station state to auth */
3637 sta = sta_info_get(sdata, ap_addr);
3639 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3642 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3643 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3650 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3651 struct ieee80211_mgmt *mgmt, size_t len)
3653 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3654 u16 auth_alg, auth_transaction, status_code;
3655 struct ieee80211_event event = {
3657 .u.mlme.data = AUTH_EVENT,
3659 struct ieee80211_prep_tx_info info = {
3660 .subtype = IEEE80211_STYPE_AUTH,
3663 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3668 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3671 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3674 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3675 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3676 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3678 if (auth_alg != ifmgd->auth_data->algorithm ||
3679 (auth_alg != WLAN_AUTH_SAE &&
3680 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3681 (auth_alg == WLAN_AUTH_SAE &&
3682 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3683 auth_transaction > 2))) {
3684 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3685 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3687 ifmgd->auth_data->expected_transaction);
3691 if (status_code != WLAN_STATUS_SUCCESS) {
3692 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3694 if (auth_alg == WLAN_AUTH_SAE &&
3695 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3696 (auth_transaction == 1 &&
3697 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3698 status_code == WLAN_STATUS_SAE_PK)))) {
3699 /* waiting for userspace now */
3700 ifmgd->auth_data->waiting = true;
3701 ifmgd->auth_data->timeout =
3702 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3703 ifmgd->auth_data->timeout_started = true;
3704 run_again(sdata, ifmgd->auth_data->timeout);
3708 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3709 mgmt->sa, status_code);
3710 ieee80211_destroy_auth_data(sdata, false);
3711 event.u.mlme.status = MLME_DENIED;
3712 event.u.mlme.reason = status_code;
3713 drv_event_callback(sdata->local, sdata, &event);
3717 switch (ifmgd->auth_data->algorithm) {
3718 case WLAN_AUTH_OPEN:
3719 case WLAN_AUTH_LEAP:
3722 case WLAN_AUTH_FILS_SK:
3723 case WLAN_AUTH_FILS_SK_PFS:
3724 case WLAN_AUTH_FILS_PK:
3726 case WLAN_AUTH_SHARED_KEY:
3727 if (ifmgd->auth_data->expected_transaction != 4) {
3728 ieee80211_auth_challenge(sdata, mgmt, len);
3729 /* need another frame */
3734 WARN_ONCE(1, "invalid auth alg %d",
3735 ifmgd->auth_data->algorithm);
3739 event.u.mlme.status = MLME_SUCCESS;
3741 drv_event_callback(sdata->local, sdata, &event);
3742 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3743 (auth_transaction == 2 &&
3744 ifmgd->auth_data->expected_transaction == 2)) {
3745 if (!ieee80211_mark_sta_auth(sdata))
3746 return; /* ignore frame -- wait for timeout */
3747 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3748 auth_transaction == 2) {
3749 sdata_info(sdata, "SAE peer confirmed\n");
3750 ifmgd->auth_data->peer_confirmed = true;
3753 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3755 drv_mgd_complete_tx(sdata->local, sdata, &info);
3758 #define case_WLAN(type) \
3759 case WLAN_REASON_##type: return #type
3761 const char *ieee80211_get_reason_code_string(u16 reason_code)
3763 switch (reason_code) {
3764 case_WLAN(UNSPECIFIED);
3765 case_WLAN(PREV_AUTH_NOT_VALID);
3766 case_WLAN(DEAUTH_LEAVING);
3767 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3768 case_WLAN(DISASSOC_AP_BUSY);
3769 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3770 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3771 case_WLAN(DISASSOC_STA_HAS_LEFT);
3772 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3773 case_WLAN(DISASSOC_BAD_POWER);
3774 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3775 case_WLAN(INVALID_IE);
3776 case_WLAN(MIC_FAILURE);
3777 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3778 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3779 case_WLAN(IE_DIFFERENT);
3780 case_WLAN(INVALID_GROUP_CIPHER);
3781 case_WLAN(INVALID_PAIRWISE_CIPHER);
3782 case_WLAN(INVALID_AKMP);
3783 case_WLAN(UNSUPP_RSN_VERSION);
3784 case_WLAN(INVALID_RSN_IE_CAP);
3785 case_WLAN(IEEE8021X_FAILED);
3786 case_WLAN(CIPHER_SUITE_REJECTED);
3787 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3788 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3789 case_WLAN(DISASSOC_LOW_ACK);
3790 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3791 case_WLAN(QSTA_LEAVE_QBSS);
3792 case_WLAN(QSTA_NOT_USE);
3793 case_WLAN(QSTA_REQUIRE_SETUP);
3794 case_WLAN(QSTA_TIMEOUT);
3795 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3796 case_WLAN(MESH_PEER_CANCELED);
3797 case_WLAN(MESH_MAX_PEERS);
3798 case_WLAN(MESH_CONFIG);
3799 case_WLAN(MESH_CLOSE);
3800 case_WLAN(MESH_MAX_RETRIES);
3801 case_WLAN(MESH_CONFIRM_TIMEOUT);
3802 case_WLAN(MESH_INVALID_GTK);
3803 case_WLAN(MESH_INCONSISTENT_PARAM);
3804 case_WLAN(MESH_INVALID_SECURITY);
3805 case_WLAN(MESH_PATH_ERROR);
3806 case_WLAN(MESH_PATH_NOFORWARD);
3807 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3808 case_WLAN(MAC_EXISTS_IN_MBSS);
3809 case_WLAN(MESH_CHAN_REGULATORY);
3810 case_WLAN(MESH_CHAN);
3811 default: return "<unknown>";
3815 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3816 struct ieee80211_mgmt *mgmt, size_t len)
3818 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3819 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3821 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3826 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3827 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3831 if (ifmgd->associated &&
3832 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3833 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3834 sdata->vif.cfg.ap_addr, reason_code,
3835 ieee80211_get_reason_code_string(reason_code));
3837 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3839 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3840 reason_code, false);
3844 if (ifmgd->assoc_data &&
3845 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3847 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3848 ifmgd->assoc_data->ap_addr, reason_code,
3849 ieee80211_get_reason_code_string(reason_code));
3851 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3853 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3859 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3860 struct ieee80211_mgmt *mgmt, size_t len)
3862 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3865 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3870 if (!ifmgd->associated ||
3871 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3874 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3876 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3877 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3881 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3882 sdata->vif.cfg.ap_addr, reason_code,
3883 ieee80211_get_reason_code_string(reason_code));
3885 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3887 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3891 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3892 u8 *supp_rates, unsigned int supp_rates_len,
3893 u32 *rates, u32 *basic_rates,
3894 bool *have_higher_than_11mbit,
3895 int *min_rate, int *min_rate_index)
3899 for (i = 0; i < supp_rates_len; i++) {
3900 int rate = supp_rates[i] & 0x7f;
3901 bool is_basic = !!(supp_rates[i] & 0x80);
3903 if ((rate * 5) > 110)
3904 *have_higher_than_11mbit = true;
3907 * Skip HT, VHT, HE, EHT and SAE H2E only BSS membership
3908 * selectors since they're not rates.
3910 * Note: Even though the membership selector and the basic
3911 * rate flag share the same bit, they are not exactly
3914 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3915 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3916 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3917 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_EHT_PHY) ||
3918 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3921 for (j = 0; j < sband->n_bitrates; j++) {
3922 struct ieee80211_rate *br;
3925 br = &sband->bitrates[j];
3927 brate = DIV_ROUND_UP(br->bitrate, 5);
3928 if (brate == rate) {
3931 *basic_rates |= BIT(j);
3932 if ((rate * 5) < *min_rate) {
3933 *min_rate = rate * 5;
3934 *min_rate_index = j;
3942 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3943 struct ieee80211_supported_band *sband,
3944 const struct link_sta_info *link_sta,
3945 const struct ieee802_11_elems *elems)
3947 const struct ieee80211_sta_he_cap *own_he_cap =
3948 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3950 if (elems->ext_capab_len < 10)
3953 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3956 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3957 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3959 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3960 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3963 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3964 struct ieee80211_supported_band *sband,
3965 struct ieee80211_link_data *link,
3966 struct link_sta_info *link_sta,
3967 struct ieee802_11_elems *elems)
3969 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3971 if (link->conf->twt_requester != twt) {
3972 link->conf->twt_requester = twt;
3973 return BSS_CHANGED_TWT;
3978 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3979 struct ieee80211_bss_conf *bss_conf,
3980 struct ieee80211_supported_band *sband,
3981 struct link_sta_info *link_sta)
3983 const struct ieee80211_sta_he_cap *own_he_cap =
3984 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3986 return bss_conf->he_support &&
3987 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3988 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3990 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3991 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3994 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3995 struct link_sta_info *link_sta,
3996 struct cfg80211_bss *cbss,
3997 struct ieee80211_mgmt *mgmt,
3998 const u8 *elem_start,
3999 unsigned int elem_len,
4002 struct ieee80211_sub_if_data *sdata = link->sdata;
4003 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4004 struct ieee80211_bss_conf *bss_conf = link->conf;
4005 struct ieee80211_local *local = sdata->local;
4006 unsigned int link_id = link->link_id;
4007 struct ieee80211_elems_parse_params parse_params = {
4008 .start = elem_start,
4010 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
4013 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4014 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
4015 const struct cfg80211_bss_ies *bss_ies = NULL;
4016 struct ieee80211_supported_band *sband;
4017 struct ieee802_11_elems *elems;
4018 const __le16 prof_bss_param_ch_present =
4019 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT);
4023 elems = ieee802_11_parse_elems_full(&parse_params);
4027 if (link_id == assoc_data->assoc_link_id) {
4028 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4031 * we should not get to this flow unless the association was
4032 * successful, so set the status directly to success
4034 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4035 if (elems->ml_basic) {
4036 if (!(elems->ml_basic->control &
4037 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT))) {
4041 link->u.mgd.bss_param_ch_cnt =
4042 ieee80211_mle_get_bss_param_ch_cnt(elems->ml_basic);
4044 } else if (!elems->prof ||
4045 !(elems->prof->control & prof_bss_param_ch_present)) {
4049 const u8 *ptr = elems->prof->variable +
4050 elems->prof->sta_info_len - 1;
4053 * During parsing, we validated that these fields exist,
4054 * otherwise elems->prof would have been set to NULL.
4056 capab_info = get_unaligned_le16(ptr);
4057 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4058 link->u.mgd.bss_param_ch_cnt =
4059 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof);
4061 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4062 link_info(link, "association response status code=%u\n",
4063 assoc_data->link[link_id].status);
4069 if (!is_s1g && !elems->supp_rates) {
4070 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4075 link->u.mgd.tdls_chan_switch_prohibited =
4076 elems->ext_capab && elems->ext_capab_len >= 5 &&
4077 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4080 * Some APs are erroneously not including some information in their
4081 * (re)association response frames. Try to recover by using the data
4082 * from the beacon or probe response. This seems to afflict mobile
4083 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4084 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4087 ((assoc_data->wmm && !elems->wmm_param) ||
4088 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4089 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4090 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4091 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4092 const struct cfg80211_bss_ies *ies;
4093 struct ieee802_11_elems *bss_elems;
4096 ies = rcu_dereference(cbss->ies);
4098 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4106 parse_params.start = bss_ies->data;
4107 parse_params.len = bss_ies->len;
4108 parse_params.bss = cbss;
4109 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4115 if (assoc_data->wmm &&
4116 !elems->wmm_param && bss_elems->wmm_param) {
4117 elems->wmm_param = bss_elems->wmm_param;
4119 "AP bug: WMM param missing from AssocResp\n");
4123 * Also check if we requested HT/VHT, otherwise the AP doesn't
4124 * have to include the IEs in the (re)association response.
4126 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4127 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4128 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4130 "AP bug: HT capability missing from AssocResp\n");
4132 if (!elems->ht_operation && bss_elems->ht_operation &&
4133 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4134 elems->ht_operation = bss_elems->ht_operation;
4136 "AP bug: HT operation missing from AssocResp\n");
4138 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4139 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4140 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4142 "AP bug: VHT capa missing from AssocResp\n");
4144 if (!elems->vht_operation && bss_elems->vht_operation &&
4145 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4146 elems->vht_operation = bss_elems->vht_operation;
4148 "AP bug: VHT operation missing from AssocResp\n");
4155 * We previously checked these in the beacon/probe response, so
4156 * they should be present here. This is just a safety net.
4158 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4159 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4161 "HT AP is missing WMM params or HT capability/operation\n");
4166 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4167 (!elems->vht_cap_elem || !elems->vht_operation)) {
4169 "VHT AP is missing VHT capability/operation\n");
4174 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4175 !elems->he_6ghz_capa) {
4177 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4182 if (WARN_ON(!link->conf->chandef.chan)) {
4186 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4188 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4189 (!elems->he_cap || !elems->he_operation)) {
4191 "HE AP is missing HE capability/operation\n");
4196 /* Set up internal HT/VHT capabilities */
4197 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4198 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4202 if (elems->vht_cap_elem &&
4203 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4204 const struct ieee80211_vht_cap *bss_vht_cap = NULL;
4205 const struct cfg80211_bss_ies *ies;
4208 * Cisco AP module 9115 with FW 17.3 has a bug and sends a
4209 * too large maximum MPDU length in the association response
4210 * (indicating 12k) that it cannot actually process ...
4214 ies = rcu_dereference(cbss->ies);
4216 const struct element *elem;
4218 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
4219 ies->data, ies->len);
4220 if (elem && elem->datalen >= sizeof(*bss_vht_cap))
4221 bss_vht_cap = (const void *)elem->data;
4224 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4225 elems->vht_cap_elem,
4226 bss_vht_cap, link_sta);
4230 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4232 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4235 elems->he_6ghz_capa,
4238 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4239 if (elems->rsnx && elems->rsnx_len &&
4240 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4241 wiphy_ext_feature_isset(local->hw.wiphy,
4242 NL80211_EXT_FEATURE_PROTECTED_TWT))
4243 bss_conf->twt_protected = true;
4245 bss_conf->twt_protected = false;
4247 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4250 if (elems->eht_operation && elems->eht_cap &&
4251 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4252 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4259 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4260 *changed |= BSS_CHANGED_EHT_PUNCTURING;
4262 bss_conf->eht_support = false;
4265 bss_conf->he_support = false;
4266 bss_conf->twt_requester = false;
4267 bss_conf->twt_protected = false;
4268 bss_conf->eht_support = false;
4271 bss_conf->twt_broadcast =
4272 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4274 if (bss_conf->he_support) {
4275 bss_conf->he_bss_color.color =
4276 le32_get_bits(elems->he_operation->he_oper_params,
4277 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4278 bss_conf->he_bss_color.partial =
4279 le32_get_bits(elems->he_operation->he_oper_params,
4280 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4281 bss_conf->he_bss_color.enabled =
4282 !le32_get_bits(elems->he_operation->he_oper_params,
4283 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4285 if (bss_conf->he_bss_color.enabled)
4286 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4288 bss_conf->htc_trig_based_pkt_ext =
4289 le32_get_bits(elems->he_operation->he_oper_params,
4290 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4291 bss_conf->frame_time_rts_th =
4292 le32_get_bits(elems->he_operation->he_oper_params,
4293 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4295 bss_conf->uora_exists = !!elems->uora_element;
4296 if (elems->uora_element)
4297 bss_conf->uora_ocw_range = elems->uora_element[0];
4299 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4300 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4301 /* TODO: OPEN: what happens if BSS color disable is set? */
4304 if (cbss->transmitted_bss) {
4305 bss_conf->nontransmitted = true;
4306 ether_addr_copy(bss_conf->transmitter_bssid,
4307 cbss->transmitted_bss->bssid);
4308 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4309 bss_conf->bssid_index = cbss->bssid_index;
4313 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4314 * in their association response, so ignore that data for our own
4315 * configuration. If it changed since the last beacon, we'll get the
4316 * next beacon and update then.
4320 * If an operating mode notification IE is present, override the
4321 * NSS calculation (that would be done in rate_control_rate_init())
4322 * and use the # of streams from that element.
4324 if (elems->opmode_notif &&
4325 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4328 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4329 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4331 link_sta->pub->rx_nss = nss;
4335 * Always handle WMM once after association regardless
4336 * of the first value the AP uses. Setting -1 here has
4337 * that effect because the AP values is an unsigned
4340 link->u.mgd.wmm_last_param_set = -1;
4341 link->u.mgd.mu_edca_last_param_set = -1;
4343 if (link->u.mgd.disable_wmm_tracking) {
4344 ieee80211_set_wmm_default(link, false, false);
4345 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4346 elems->wmm_param_len,
4347 elems->mu_edca_param_set)) {
4348 /* still enable QoS since we might have HT/VHT */
4349 ieee80211_set_wmm_default(link, false, true);
4350 /* disable WMM tracking in this case to disable
4351 * tracking WMM parameter changes in the beacon if
4352 * the parameters weren't actually valid. Doing so
4353 * avoids changing parameters very strangely when
4354 * the AP is going back and forth between valid and
4355 * invalid parameters.
4357 link->u.mgd.disable_wmm_tracking = true;
4360 if (elems->max_idle_period_ie) {
4361 bss_conf->max_idle_period =
4362 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4363 bss_conf->protected_keep_alive =
4364 !!(elems->max_idle_period_ie->idle_options &
4365 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4366 *changed |= BSS_CHANGED_KEEP_ALIVE;
4368 bss_conf->max_idle_period = 0;
4369 bss_conf->protected_keep_alive = false;
4372 /* set assoc capability (AID was already set earlier),
4373 * ieee80211_set_associated() will tell the driver */
4374 bss_conf->assoc_capability = capab_info;
4383 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4384 struct sta_info *sta,
4385 struct link_sta_info *link_sta,
4386 struct cfg80211_bss *cbss)
4388 struct ieee80211_sub_if_data *sdata = link->sdata;
4389 struct ieee80211_local *local = sdata->local;
4390 struct ieee80211_bss *bss = (void *)cbss->priv;
4391 u32 rates = 0, basic_rates = 0;
4392 bool have_higher_than_11mbit = false;
4393 int min_rate = INT_MAX, min_rate_index = -1;
4394 struct ieee80211_supported_band *sband;
4396 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4397 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4399 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4400 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4401 ieee80211_s1g_sta_rate_init(sta);
4405 sband = local->hw.wiphy->bands[cbss->channel->band];
4407 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4408 &rates, &basic_rates, &have_higher_than_11mbit,
4409 &min_rate, &min_rate_index);
4412 * This used to be a workaround for basic rates missing
4413 * in the association response frame. Now that we no
4414 * longer use the basic rates from there, it probably
4415 * doesn't happen any more, but keep the workaround so
4416 * in case some *other* APs are buggy in different ways
4417 * we can connect -- with a warning.
4418 * Allow this workaround only in case the AP provided at least
4421 if (min_rate_index < 0) {
4422 link_info(link, "No legacy rates in association response\n");
4424 } else if (!basic_rates) {
4425 link_info(link, "No basic rates, using min rate instead\n");
4426 basic_rates = BIT(min_rate_index);
4430 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4432 link_info(link, "No rates found, keeping mandatory only\n");
4434 link->conf->basic_rates = basic_rates;
4436 /* cf. IEEE 802.11 9.2.12 */
4437 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4438 have_higher_than_11mbit;
4443 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4444 struct cfg80211_bss *cbss)
4446 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4447 const struct element *ht_cap_elem, *vht_cap_elem;
4448 const struct cfg80211_bss_ies *ies;
4449 const struct ieee80211_ht_cap *ht_cap;
4450 const struct ieee80211_vht_cap *vht_cap;
4451 const struct ieee80211_he_cap_elem *he_cap;
4452 const struct element *he_cap_elem;
4453 u16 mcs_80_map, mcs_160_map;
4454 int i, mcs_nss_size;
4458 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4461 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4462 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4463 ht_cap = (void *)ht_cap_elem->data;
4464 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4466 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4467 * "Tx Unequal Modulation Supported" fields.
4471 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4474 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4475 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4479 vht_cap = (void *)vht_cap_elem->data;
4480 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4481 for (nss = 8; nss > 0; nss--) {
4482 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4483 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4486 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4487 chains = max(chains, nss);
4490 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4493 ies = rcu_dereference(cbss->ies);
4494 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4495 ies->data, ies->len);
4497 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4500 /* skip one byte ext_tag_id */
4501 he_cap = (void *)(he_cap_elem->data + 1);
4502 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4505 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4508 /* mcs_nss is right after he_cap info */
4509 he_mcs_nss_supp = (void *)(he_cap + 1);
4511 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4513 for (i = 7; i >= 0; i--) {
4514 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4516 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4517 chains = max_t(u8, chains, i + 1);
4522 support_160 = he_cap->phy_cap_info[0] &
4523 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4528 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4529 for (i = 7; i >= 0; i--) {
4530 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4532 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4533 chains = max_t(u8, chains, i + 1);
4542 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4543 const struct cfg80211_bss_ies *ies,
4544 const struct ieee80211_he_operation *he_op)
4546 const struct element *he_cap_elem;
4547 const struct ieee80211_he_cap_elem *he_cap;
4548 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4549 u16 mcs_80_map_tx, mcs_80_map_rx;
4554 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4555 ies->data, ies->len);
4561 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4563 "Invalid HE elem, Disable HE\n");
4567 /* skip one byte ext_tag_id */
4568 he_cap = (void *)(he_cap_elem->data + 1);
4569 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4572 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4574 "Invalid HE elem with nss size, Disable HE\n");
4578 /* mcs_nss is right after he_cap info */
4579 he_mcs_nss_supp = (void *)(he_cap + 1);
4581 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4582 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4584 /* P802.11-REVme/D0.3
4585 * 27.1.1 Introduction to the HE PHY
4587 * An HE STA shall support the following features:
4589 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4590 * supported channel widths for HE SU PPDUs
4592 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4593 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4595 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4596 mcs_80_map_tx, mcs_80_map_rx);
4603 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4606 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4607 * zeroes, which is nonsense, and completely inconsistent with itself
4608 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4610 if (!ap_min_req_set)
4613 /* make sure the AP is consistent with itself
4615 * P802.11-REVme/D0.3
4616 * 26.17.1 Basic HE BSS operation
4618 * A STA that is operating in an HE BSS shall be able to receive and
4619 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4620 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4621 * MLME-START.request primitive and shall be able to receive at each of
4622 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4623 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4626 for (nss = 8; nss > 0; nss--) {
4627 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4631 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4634 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4635 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4637 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4638 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4639 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4641 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4642 nss, ap_rx_val, ap_rx_val, ap_op_val);
4651 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4652 struct ieee80211_supported_band *sband,
4653 const struct ieee80211_he_operation *he_op)
4655 const struct ieee80211_sta_he_cap *sta_he_cap =
4656 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4660 if (!sta_he_cap || !he_op)
4663 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4666 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4667 * zeroes, which is nonsense, and completely inconsistent with itself
4668 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4670 if (!ap_min_req_set)
4673 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4674 for (i = 0; i < 3; i++) {
4675 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4676 &sta_he_cap->he_mcs_nss_supp;
4677 u16 sta_mcs_map_rx =
4678 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4679 u16 sta_mcs_map_tx =
4680 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4682 bool verified = true;
4685 * For each band there is a maximum of 8 spatial streams
4686 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4687 * of 2 bits per NSS (1-8), with the values defined in enum
4688 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4689 * capabilities aren't less than the AP's minimum requirements
4690 * for this HE BSS per SS.
4691 * It is enough to find one such band that meets the reqs.
4693 for (nss = 8; nss > 0; nss--) {
4694 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4695 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4696 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4698 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4702 * Make sure the HE AP doesn't require MCSs that aren't
4703 * supported by the client as required by spec
4705 * P802.11-REVme/D0.3
4706 * 26.17.1 Basic HE BSS operation
4708 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4709 * a BSS, unless it supports (i.e., is able to both transmit and
4710 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4711 * HE-MCS and NSS set.
4713 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4714 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4715 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4725 /* If here, STA doesn't meet AP's HE min requirements */
4730 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap,
4731 const struct ieee80211_sta_eht_cap *sta_eht_cap,
4732 unsigned int idx, int bw)
4734 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0];
4735 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0];
4737 /* handle us being a 20 MHz-only EHT STA - with four values
4738 * for MCS 0-7, 8-9, 10-11, 12-13.
4740 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL))
4741 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx];
4743 /* the others have MCS 0-9 together, rather than separately from 0-7 */
4749 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx];
4752 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4753 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)))
4754 return 0xff; /* pass check */
4755 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx];
4757 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ))
4758 return 0xff; /* pass check */
4759 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx];
4767 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata,
4768 struct ieee80211_supported_band *sband,
4769 const struct ieee80211_eht_operation *eht_op)
4771 const struct ieee80211_sta_he_cap *sta_he_cap =
4772 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4773 const struct ieee80211_sta_eht_cap *sta_eht_cap =
4774 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
4775 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req;
4778 if (!sta_he_cap || !sta_eht_cap || !eht_op)
4781 req = &eht_op->basic_mcs_nss;
4783 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) {
4784 u8 req_rx_nss, req_tx_nss;
4787 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4788 IEEE80211_EHT_MCS_NSS_RX);
4789 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4790 IEEE80211_EHT_MCS_NSS_TX);
4792 for (bw = 0; bw < 3; bw++) {
4793 u8 have, have_rx_nss, have_tx_nss;
4795 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap,
4798 have_rx_nss = u8_get_bits(have,
4799 IEEE80211_EHT_MCS_NSS_RX);
4800 have_tx_nss = u8_get_bits(have,
4801 IEEE80211_EHT_MCS_NSS_TX);
4803 if (req_rx_nss > have_rx_nss ||
4804 req_tx_nss > have_tx_nss)
4812 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4813 struct ieee80211_link_data *link,
4814 struct cfg80211_bss *cbss,
4816 ieee80211_conn_flags_t *conn_flags)
4818 struct ieee80211_local *local = sdata->local;
4819 const struct ieee80211_ht_cap *ht_cap = NULL;
4820 const struct ieee80211_ht_operation *ht_oper = NULL;
4821 const struct ieee80211_vht_operation *vht_oper = NULL;
4822 const struct ieee80211_he_operation *he_oper = NULL;
4823 const struct ieee80211_eht_operation *eht_oper = NULL;
4824 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4825 struct ieee80211_supported_band *sband;
4826 struct cfg80211_chan_def chandef;
4827 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4828 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4829 bool supports_mlo = false;
4830 struct ieee80211_bss *bss = (void *)cbss->priv;
4831 struct ieee80211_elems_parse_params parse_params = {
4835 struct ieee802_11_elems *elems;
4836 const struct cfg80211_bss_ies *ies;
4841 lockdep_assert_wiphy(local->hw.wiphy);
4845 ies = rcu_dereference(cbss->ies);
4846 parse_params.start = ies->data;
4847 parse_params.len = ies->len;
4848 elems = ieee802_11_parse_elems_full(&parse_params);
4854 sband = local->hw.wiphy->bands[cbss->channel->band];
4856 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4857 IEEE80211_CONN_DISABLE_80P80MHZ |
4858 IEEE80211_CONN_DISABLE_160MHZ);
4860 /* disable HT/VHT/HE if we don't support them */
4861 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4862 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4863 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4864 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4865 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4866 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4869 if (!sband->vht_cap.vht_supported && is_5ghz) {
4870 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4871 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4872 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4873 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4876 if (!ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
4877 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4878 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4879 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4882 if (!ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif)) {
4883 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4884 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4887 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4888 ht_oper = elems->ht_operation;
4889 ht_cap = elems->ht_cap_elem;
4892 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4897 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4898 vht_oper = elems->vht_operation;
4899 if (vht_oper && !ht_oper) {
4902 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4903 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4904 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4905 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4906 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4909 if (!elems->vht_cap_elem) {
4910 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4915 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4916 he_oper = elems->he_operation;
4918 if (link && is_6ghz) {
4919 struct ieee80211_bss_conf *bss_conf;
4922 bss_conf = link->conf;
4924 if (elems->pwr_constr_elem)
4925 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4927 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4928 ARRAY_SIZE(elems->tx_pwr_env));
4930 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4931 if (elems->tx_pwr_env_len[i] >
4932 sizeof(bss_conf->tx_pwr_env[j]))
4935 bss_conf->tx_pwr_env_num++;
4936 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4937 elems->tx_pwr_env_len[i]);
4942 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4943 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4944 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4945 IEEE80211_CONN_DISABLE_EHT;
4949 * EHT requires HE to be supported as well. Specifically for 6 GHz
4950 * channels, the operation channel information can only be deduced from
4951 * both the 6 GHz operation information (from the HE operation IE) and
4955 (IEEE80211_CONN_DISABLE_HE |
4956 IEEE80211_CONN_DISABLE_EHT)) &&
4958 const struct cfg80211_bss_ies *cbss_ies;
4959 const struct element *eht_ml_elem;
4960 const u8 *eht_oper_ie;
4962 cbss_ies = rcu_dereference(cbss->ies);
4963 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4964 cbss_ies->data, cbss_ies->len);
4965 if (eht_oper_ie && eht_oper_ie[1] >=
4966 1 + sizeof(struct ieee80211_eht_operation))
4967 eht_oper = (void *)(eht_oper_ie + 3);
4971 if (!ieee80211_verify_sta_eht_mcs_support(sdata, sband, eht_oper))
4972 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4974 eht_ml_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK,
4975 cbss_ies->data, cbss_ies->len);
4977 /* data + 1 / datalen - 1 since it's an extended element */
4978 if (!(*conn_flags & IEEE80211_CONN_DISABLE_EHT) &&
4980 ieee80211_mle_type_ok(eht_ml_elem->data + 1,
4981 IEEE80211_ML_CONTROL_TYPE_BASIC,
4982 eht_ml_elem->datalen - 1)) {
4983 supports_mlo = true;
4985 sdata->vif.cfg.eml_cap =
4986 ieee80211_mle_get_eml_cap(eht_ml_elem->data + 1);
4987 sdata->vif.cfg.eml_med_sync_delay =
4988 ieee80211_mle_get_eml_med_sync_delay(eht_ml_elem->data + 1);
4992 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4994 for (i = 0; i < sband->n_channels; i++) {
4995 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4996 IEEE80211_CHAN_NO_80MHZ))
5004 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
5005 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5008 if (sband->band == NL80211_BAND_S1GHZ) {
5009 s1g_oper = elems->s1g_oper;
5012 "AP missing S1G operation element?\n");
5016 ieee80211_determine_chantype(sdata, link, *conn_flags,
5026 link->needed_rx_chains =
5027 min(ieee80211_max_rx_chains(link, cbss),
5031 /* the element data was RCU protected so no longer valid anyway */
5035 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
5036 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5040 if (mlo && !supports_mlo) {
5041 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n");
5048 /* will change later if needed */
5049 link->smps_mode = IEEE80211_SMPS_OFF;
5052 * If this fails (possibly due to channel context sharing
5053 * on incompatible channels, e.g. 80+80 and 160 sharing the
5054 * same control channel) try to use a smaller bandwidth.
5056 ret = ieee80211_link_use_channel(link, &chandef,
5057 IEEE80211_CHANCTX_SHARED);
5059 /* don't downgrade for 5 and 10 MHz channels, though. */
5060 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5061 chandef.width == NL80211_CHAN_WIDTH_10)
5064 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5066 ieee80211_chandef_downgrade(&chandef);
5067 ret = ieee80211_link_use_channel(link, &chandef,
5068 IEEE80211_CHANCTX_SHARED);
5074 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5075 u8 *dtim_count, u8 *dtim_period)
5077 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5078 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5080 const struct ieee80211_tim_ie *tim = NULL;
5081 const struct ieee80211_bssid_index *idx;
5082 bool valid = tim_ie && tim_ie[1] >= 2;
5085 tim = (void *)(tim_ie + 2);
5088 *dtim_count = valid ? tim->dtim_count : 0;
5091 *dtim_period = valid ? tim->dtim_period : 0;
5093 /* Check if value is overridden by non-transmitted profile */
5094 if (!idx_ie || idx_ie[1] < 3)
5097 idx = (void *)(idx_ie + 2);
5100 *dtim_count = idx->dtim_count;
5103 *dtim_period = idx->dtim_period;
5108 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
5109 struct ieee80211_mgmt *mgmt,
5110 struct ieee802_11_elems *elems,
5111 const u8 *elem_start, unsigned int elem_len)
5113 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5114 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5115 struct ieee80211_local *local = sdata->local;
5116 unsigned int link_id;
5117 struct sta_info *sta;
5118 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5119 u16 valid_links = 0, dormant_links = 0;
5122 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5124 * station info was already allocated and inserted before
5125 * the association and should be available to us
5127 sta = sta_info_get(sdata, assoc_data->ap_addr);
5131 if (ieee80211_vif_is_mld(&sdata->vif)) {
5132 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5133 if (!assoc_data->link[link_id].bss)
5136 valid_links |= BIT(link_id);
5137 if (assoc_data->link[link_id].disabled)
5138 dormant_links |= BIT(link_id);
5140 if (link_id != assoc_data->assoc_link_id) {
5141 err = ieee80211_sta_allocate_link(sta, link_id);
5147 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5150 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5151 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5152 struct ieee80211_link_data *link;
5153 struct link_sta_info *link_sta;
5158 link = sdata_dereference(sdata->link[link_id], sdata);
5162 if (ieee80211_vif_is_mld(&sdata->vif))
5164 "local address %pM, AP link address %pM%s\n",
5166 assoc_data->link[link_id].bss->bssid,
5167 link_id == assoc_data->assoc_link_id ?
5170 link_sta = rcu_dereference_protected(sta->link[link_id],
5171 lockdep_is_held(&local->hw.wiphy->mtx));
5172 if (WARN_ON(!link_sta))
5175 if (!link->u.mgd.have_beacon) {
5176 const struct cfg80211_bss_ies *ies;
5179 ies = rcu_dereference(cbss->beacon_ies);
5181 link->u.mgd.have_beacon = true;
5183 ies = rcu_dereference(cbss->ies);
5184 ieee80211_get_dtim(ies,
5185 &link->conf->sync_dtim_count,
5186 &link->u.mgd.dtim_period);
5187 link->conf->beacon_int = cbss->beacon_interval;
5191 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5193 if (link_id != assoc_data->assoc_link_id) {
5194 err = ieee80211_prep_channel(sdata, link, cbss, true,
5195 &link->u.mgd.conn_flags);
5197 link_info(link, "prep_channel failed\n");
5202 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5203 assoc_data->link[link_id].bss);
5207 if (!ieee80211_assoc_config_link(link, link_sta,
5208 assoc_data->link[link_id].bss,
5209 mgmt, elem_start, elem_len,
5213 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5214 valid_links &= ~BIT(link_id);
5215 ieee80211_sta_remove_link(sta, link_id);
5219 if (link_id != assoc_data->assoc_link_id) {
5220 err = ieee80211_sta_activate_link(sta, link_id);
5226 /* links might have changed due to rejected ones, set them again */
5227 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5229 rate_control_rate_init(sta);
5231 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5232 set_sta_flag(sta, WLAN_STA_MFP);
5233 sta->sta.mfp = true;
5235 sta->sta.mfp = false;
5238 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5239 elems->ext_capab_len);
5241 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5242 local->hw.queues >= IEEE80211_NUM_ACS;
5244 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5245 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5246 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5249 "failed to move station %pM to desired state\n",
5251 WARN_ON(__sta_info_destroy(sta));
5255 if (sdata->wdev.use_4addr)
5256 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5258 ieee80211_set_associated(sdata, assoc_data, changed);
5261 * If we're using 4-addr mode, let the AP know that we're
5262 * doing so, so that it can create the STA VLAN on its side
5264 if (ifmgd->use_4addr)
5265 ieee80211_send_4addr_nullfunc(local, sdata);
5268 * Start timer to probe the connection to the AP now.
5269 * Also start the timer that will detect beacon loss.
5271 ieee80211_sta_reset_beacon_monitor(sdata);
5272 ieee80211_sta_reset_conn_monitor(sdata);
5276 eth_zero_addr(sdata->vif.cfg.ap_addr);
5280 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5281 struct ieee80211_mgmt *mgmt,
5284 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5285 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5286 u16 capab_info, status_code, aid;
5287 struct ieee80211_elems_parse_params parse_params = {
5292 struct ieee802_11_elems *elems;
5294 const u8 *elem_start;
5295 unsigned int elem_len;
5297 struct ieee80211_event event = {
5299 .u.mlme.data = ASSOC_EVENT,
5301 struct ieee80211_prep_tx_info info = {};
5302 struct cfg80211_rx_assoc_resp_data resp = {
5305 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5306 unsigned int link_id;
5308 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5313 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5314 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5318 * AssocResp and ReassocResp have identical structure, so process both
5319 * of them in this function.
5325 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5326 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5327 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5328 if (assoc_data->s1g)
5329 elem_start = mgmt->u.s1g_assoc_resp.variable;
5331 elem_start = mgmt->u.assoc_resp.variable;
5334 * Note: this may not be perfect, AP might misbehave - if
5335 * anyone needs to rely on perfect complete notification
5336 * with the exact right subtype, then we need to track what
5337 * we actually transmitted.
5339 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5340 IEEE80211_STYPE_ASSOC_REQ;
5342 if (assoc_data->fils_kek_len &&
5343 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5346 elem_len = len - (elem_start - (u8 *)mgmt);
5347 parse_params.start = elem_start;
5348 parse_params.len = elem_len;
5349 elems = ieee802_11_parse_elems_full(&parse_params);
5353 if (elems->aid_resp)
5354 aid = le16_to_cpu(elems->aid_resp->aid);
5355 else if (assoc_data->s1g)
5358 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5361 * The 5 MSB of the AID field are reserved
5362 * (802.11-2016 9.4.1.8 AID field)
5367 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5368 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5369 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5371 ifmgd->broken_ap = false;
5373 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5374 elems->timeout_int &&
5375 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5378 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5379 le32_to_cpu(elems->timeout_int->value));
5381 tu = le32_to_cpu(elems->timeout_int->value);
5382 ms = tu * 1024 / 1000;
5384 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5385 assoc_data->ap_addr, tu, ms);
5386 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5387 assoc_data->timeout_started = true;
5388 assoc_data->comeback = true;
5389 if (ms > IEEE80211_ASSOC_TIMEOUT)
5390 run_again(sdata, assoc_data->timeout);
5394 if (status_code != WLAN_STATUS_SUCCESS) {
5395 sdata_info(sdata, "%pM denied association (code=%d)\n",
5396 assoc_data->ap_addr, status_code);
5397 event.u.mlme.status = MLME_DENIED;
5398 event.u.mlme.reason = status_code;
5399 drv_event_callback(sdata->local, sdata, &event);
5401 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5403 "invalid AID value %d (out of range), turn off PS\n",
5406 ifmgd->broken_ap = true;
5409 if (ieee80211_vif_is_mld(&sdata->vif)) {
5410 struct ieee80211_mle_basic_common_info *common;
5412 if (!elems->ml_basic) {
5414 "MLO association with %pM but no (basic) multi-link element in response!\n",
5415 assoc_data->ap_addr);
5419 common = (void *)elems->ml_basic->variable;
5421 if (memcmp(assoc_data->ap_addr,
5422 common->mld_mac_addr, ETH_ALEN)) {
5424 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5425 common->mld_mac_addr,
5426 assoc_data->ap_addr);
5431 sdata->vif.cfg.aid = aid;
5433 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5434 elem_start, elem_len)) {
5435 /* oops -- internal error -- send timeout for now */
5436 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5439 event.u.mlme.status = MLME_SUCCESS;
5440 drv_event_callback(sdata->local, sdata, &event);
5441 sdata_info(sdata, "associated\n");
5446 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5447 struct ieee80211_link_data *link;
5449 if (!assoc_data->link[link_id].bss)
5452 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5453 ether_addr_copy(resp.links[link_id].addr,
5454 assoc_data->link[link_id].addr);
5455 resp.links[link_id].status = assoc_data->link[link_id].status;
5457 link = sdata_dereference(sdata->link[link_id], sdata);
5461 /* get uapsd queues configuration - same for all links */
5462 resp.uapsd_queues = 0;
5463 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5464 if (link->tx_conf[ac].uapsd)
5465 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5468 if (ieee80211_vif_is_mld(&sdata->vif)) {
5469 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5470 resp.ap_mld_addr = ap_mld_addr;
5473 ieee80211_destroy_assoc_data(sdata,
5474 status_code == WLAN_STATUS_SUCCESS ?
5478 resp.buf = (u8 *)mgmt;
5480 resp.req_ies = ifmgd->assoc_req_ies;
5481 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5482 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5484 drv_mgd_complete_tx(sdata->local, sdata, &info);
5488 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5492 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5493 struct ieee80211_mgmt *mgmt, size_t len,
5494 struct ieee80211_rx_status *rx_status)
5496 struct ieee80211_sub_if_data *sdata = link->sdata;
5497 struct ieee80211_local *local = sdata->local;
5498 struct ieee80211_bss *bss;
5499 struct ieee80211_channel *channel;
5501 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5503 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5504 ieee80211_rx_status_to_khz(rx_status));
5508 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5510 link->conf->beacon_rate = bss->beacon_rate;
5511 ieee80211_rx_bss_put(local, bss);
5516 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5517 struct sk_buff *skb)
5519 struct ieee80211_sub_if_data *sdata = link->sdata;
5520 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5521 struct ieee80211_if_managed *ifmgd;
5522 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5523 struct ieee80211_channel *channel;
5524 size_t baselen, len = skb->len;
5526 ifmgd = &sdata->u.mgd;
5528 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5531 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5532 * "If a 6 GHz AP receives a Probe Request frame and responds with
5533 * a Probe Response frame [..], the Address 1 field of the Probe
5534 * Response frame shall be set to the broadcast address [..]"
5535 * So, on 6GHz band we should also accept broadcast responses.
5537 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5542 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5543 (channel->band != NL80211_BAND_6GHZ ||
5544 !is_broadcast_ether_addr(mgmt->da)))
5545 return; /* ignore ProbeResp to foreign address */
5547 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5551 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5553 if (ifmgd->associated &&
5554 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5555 ieee80211_reset_ap_probe(sdata);
5559 * This is the canonical list of information elements we care about,
5560 * the filter code also gives us all changes to the Microsoft OUI
5561 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5562 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5563 * changes to requested client power.
5565 * We implement beacon filtering in software since that means we can
5566 * avoid processing the frame here and in cfg80211, and userspace
5567 * will not be able to tell whether the hardware supports it or not.
5569 * XXX: This list needs to be dynamic -- userspace needs to be able to
5570 * add items it requires. It also needs to be able to tell us to
5571 * look out for other vendor IEs.
5573 static const u64 care_about_ies =
5574 (1ULL << WLAN_EID_COUNTRY) |
5575 (1ULL << WLAN_EID_ERP_INFO) |
5576 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5577 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5578 (1ULL << WLAN_EID_HT_CAPABILITY) |
5579 (1ULL << WLAN_EID_HT_OPERATION) |
5580 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5582 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5583 struct ieee80211_if_managed *ifmgd,
5584 struct ieee80211_bss_conf *bss_conf,
5585 struct ieee80211_local *local,
5586 struct ieee80211_rx_status *rx_status)
5588 struct ieee80211_sub_if_data *sdata = link->sdata;
5590 /* Track average RSSI from the Beacon frames of the current AP */
5592 if (!link->u.mgd.tracking_signal_avg) {
5593 link->u.mgd.tracking_signal_avg = true;
5594 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5595 link->u.mgd.last_cqm_event_signal = 0;
5596 link->u.mgd.count_beacon_signal = 1;
5597 link->u.mgd.last_ave_beacon_signal = 0;
5599 link->u.mgd.count_beacon_signal++;
5602 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5603 -rx_status->signal);
5605 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5606 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5607 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5608 int last_sig = link->u.mgd.last_ave_beacon_signal;
5609 struct ieee80211_event event = {
5614 * if signal crosses either of the boundaries, invoke callback
5615 * with appropriate parameters
5617 if (sig > ifmgd->rssi_max_thold &&
5618 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5619 link->u.mgd.last_ave_beacon_signal = sig;
5620 event.u.rssi.data = RSSI_EVENT_HIGH;
5621 drv_event_callback(local, sdata, &event);
5622 } else if (sig < ifmgd->rssi_min_thold &&
5623 (last_sig >= ifmgd->rssi_max_thold ||
5625 link->u.mgd.last_ave_beacon_signal = sig;
5626 event.u.rssi.data = RSSI_EVENT_LOW;
5627 drv_event_callback(local, sdata, &event);
5631 if (bss_conf->cqm_rssi_thold &&
5632 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5633 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5634 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5635 int last_event = link->u.mgd.last_cqm_event_signal;
5636 int thold = bss_conf->cqm_rssi_thold;
5637 int hyst = bss_conf->cqm_rssi_hyst;
5640 (last_event == 0 || sig < last_event - hyst)) {
5641 link->u.mgd.last_cqm_event_signal = sig;
5642 ieee80211_cqm_rssi_notify(
5644 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5646 } else if (sig > thold &&
5647 (last_event == 0 || sig > last_event + hyst)) {
5648 link->u.mgd.last_cqm_event_signal = sig;
5649 ieee80211_cqm_rssi_notify(
5651 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5656 if (bss_conf->cqm_rssi_low &&
5657 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5658 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5659 int last_event = link->u.mgd.last_cqm_event_signal;
5660 int low = bss_conf->cqm_rssi_low;
5661 int high = bss_conf->cqm_rssi_high;
5664 (last_event == 0 || last_event >= low)) {
5665 link->u.mgd.last_cqm_event_signal = sig;
5666 ieee80211_cqm_rssi_notify(
5668 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5670 } else if (sig > high &&
5671 (last_event == 0 || last_event <= high)) {
5672 link->u.mgd.last_cqm_event_signal = sig;
5673 ieee80211_cqm_rssi_notify(
5675 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5681 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5682 struct cfg80211_bss *bss)
5684 if (ether_addr_equal(tx_bssid, bss->bssid))
5686 if (!bss->transmitted_bss)
5688 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5691 static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
5692 const struct ieee80211_eht_operation *eht_oper,
5695 struct ieee80211_local *local = link->sdata->local;
5696 u16 bitmap = 0, extracted;
5698 if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
5700 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
5701 const struct ieee80211_eht_operation_info *info =
5702 (void *)eht_oper->optional;
5703 const u8 *disable_subchannel_bitmap = info->optional;
5705 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
5708 extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
5709 &link->conf->chandef,
5712 /* accept if there are no changes */
5713 if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
5714 extracted == link->conf->eht_puncturing)
5717 if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
5718 &link->conf->chandef)) {
5720 "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
5723 link->conf->chandef.width);
5727 if (bitmap && ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING))
5730 ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
5734 static void ieee80211_ml_reconf_work(struct wiphy *wiphy,
5735 struct wiphy_work *work)
5737 struct ieee80211_sub_if_data *sdata =
5738 container_of(work, struct ieee80211_sub_if_data,
5739 u.mgd.ml_reconf_work.work);
5740 u16 new_valid_links, new_active_links, new_dormant_links;
5743 if (!sdata->u.mgd.removed_links)
5747 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n",
5748 sdata->vif.valid_links, sdata->u.mgd.removed_links);
5750 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links;
5751 if (new_valid_links == sdata->vif.valid_links)
5754 if (!new_valid_links ||
5755 !(new_valid_links & ~sdata->vif.dormant_links)) {
5756 sdata_info(sdata, "No valid links after reconfiguration\n");
5761 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links;
5762 if (new_active_links != sdata->vif.active_links) {
5763 if (!new_active_links)
5765 BIT(ffs(new_valid_links &
5766 ~sdata->vif.dormant_links) - 1);
5768 ret = ieee80211_set_active_links(&sdata->vif, new_active_links);
5771 "Failed setting active links\n");
5776 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links;
5778 ret = ieee80211_vif_set_links(sdata, new_valid_links,
5781 sdata_info(sdata, "Failed setting valid links\n");
5783 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
5787 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links);
5789 __ieee80211_disconnect(sdata);
5791 sdata->u.mgd.removed_links = 0;
5794 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata,
5795 struct ieee802_11_elems *elems)
5797 const struct ieee80211_multi_link_elem *ml;
5798 const struct element *sub;
5800 unsigned long removed_links = 0;
5801 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5805 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf)
5808 ml_len = cfg80211_defragment_element(elems->ml_reconf_elem,
5812 elems->scratch + elems->scratch_len -
5818 elems->ml_reconf = (const void *)elems->scratch_pos;
5819 elems->ml_reconf_len = ml_len;
5820 ml = elems->ml_reconf;
5822 /* Directly parse the sub elements as the common information doesn't
5823 * hold any useful information.
5825 for_each_mle_subelement(sub, (u8 *)ml, ml_len) {
5826 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
5827 u8 *pos = prof->variable;
5830 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
5833 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data,
5837 control = le16_to_cpu(prof->control);
5838 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID;
5840 removed_links |= BIT(link_id);
5842 /* the MAC address should not be included, but handle it */
5844 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
5847 /* According to Draft P802.11be_D3.0, the control should
5848 * include the AP Removal Timer present. If the AP Removal Timer
5849 * is not present assume immediate removal.
5852 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
5853 link_removal_timeout[link_id] = le16_to_cpu(*(__le16 *)pos);
5856 removed_links &= sdata->vif.valid_links;
5857 if (!removed_links) {
5858 /* In case the removal was cancelled, abort it */
5859 if (sdata->u.mgd.removed_links) {
5860 sdata->u.mgd.removed_links = 0;
5861 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
5862 &sdata->u.mgd.ml_reconf_work);
5868 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) {
5869 struct ieee80211_bss_conf *link_conf =
5870 sdata_dereference(sdata->vif.link_conf[link_id], sdata);
5874 removed_links &= ~BIT(link_id);
5878 link_delay = link_conf->beacon_int *
5879 link_removal_timeout[link_id];
5884 delay = min(delay, link_delay);
5887 sdata->u.mgd.removed_links = removed_links;
5888 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
5889 &sdata->u.mgd.ml_reconf_work,
5890 TU_TO_JIFFIES(delay));
5893 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy,
5894 struct wiphy_work *work)
5896 u16 new_active_links, new_dormant_links;
5897 struct ieee80211_sub_if_data *sdata =
5898 container_of(work, struct ieee80211_sub_if_data,
5899 u.mgd.ttlm_work.work);
5902 new_active_links = sdata->u.mgd.ttlm_info.map &
5903 sdata->vif.valid_links;
5904 new_dormant_links = ~sdata->u.mgd.ttlm_info.map &
5905 sdata->vif.valid_links;
5906 if (!new_active_links) {
5907 ieee80211_disconnect(&sdata->vif, false);
5911 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0);
5912 new_active_links = BIT(ffs(new_active_links) - 1);
5913 ieee80211_set_active_links(&sdata->vif, new_active_links);
5915 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
5918 sdata->u.mgd.ttlm_info.active = true;
5919 sdata->u.mgd.ttlm_info.switch_time = 0;
5922 ieee80211_vif_cfg_change_notify(sdata,
5923 BSS_CHANGED_MLD_VALID_LINKS);
5926 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data)
5931 return get_unaligned_le16(data);
5935 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata,
5936 const struct ieee80211_ttlm_elem *ttlm,
5937 struct ieee80211_adv_ttlm_info *ttlm_info)
5939 /* The element size was already validated in
5940 * ieee80211_tid_to_link_map_size_ok()
5942 u8 control, link_map_presence, map_size, tid;
5945 memset(ttlm_info, 0, sizeof(*ttlm_info));
5946 pos = (void *)ttlm->optional;
5947 control = ttlm->control;
5949 if ((control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) ||
5950 !(control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT))
5953 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) !=
5954 IEEE80211_TTLM_DIRECTION_BOTH) {
5955 sdata_info(sdata, "Invalid advertised T2L map direction\n");
5959 link_map_presence = *pos;
5962 ttlm_info->switch_time = get_unaligned_le16(pos);
5964 /* Since ttlm_info->switch_time == 0 means no switch time, bump it
5967 if (!ttlm_info->switch_time)
5968 ttlm_info->switch_time = 1;
5972 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) {
5973 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16;
5977 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
5982 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall
5983 * not advertise a TID-to-link mapping that does not map all TIDs to the
5984 * same link set, reject frame if not all links have mapping
5986 if (link_map_presence != 0xff) {
5988 "Invalid advertised T2L mapping presence indicator\n");
5992 ttlm_info->map = ieee80211_get_ttlm(map_size, pos);
5993 if (!ttlm_info->map) {
5995 "Invalid advertised T2L map for TID 0\n");
6001 for (tid = 1; tid < 8; tid++) {
6002 u16 map = ieee80211_get_ttlm(map_size, pos);
6004 if (map != ttlm_info->map) {
6005 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n",
6015 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata,
6016 struct ieee802_11_elems *elems,
6022 if (!ieee80211_vif_is_mld(&sdata->vif))
6025 if (!elems->ttlm_num) {
6026 if (sdata->u.mgd.ttlm_info.switch_time) {
6027 /* if a planned TID-to-link mapping was cancelled -
6030 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6031 &sdata->u.mgd.ttlm_work);
6032 } else if (sdata->u.mgd.ttlm_info.active) {
6033 /* if no TID-to-link element, set to default mapping in
6034 * which all TIDs are mapped to all setup links
6036 ret = ieee80211_vif_set_links(sdata,
6037 sdata->vif.valid_links,
6040 sdata_info(sdata, "Failed setting valid/dormant links\n");
6043 ieee80211_vif_cfg_change_notify(sdata,
6044 BSS_CHANGED_MLD_VALID_LINKS);
6046 memset(&sdata->u.mgd.ttlm_info, 0,
6047 sizeof(sdata->u.mgd.ttlm_info));
6051 for (i = 0; i < elems->ttlm_num; i++) {
6052 struct ieee80211_adv_ttlm_info ttlm_info;
6055 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i],
6059 __ieee80211_disconnect(sdata);
6063 if (ttlm_info.switch_time) {
6064 u16 beacon_ts_tu, st_tu, delay;
6068 /* The t2l map switch time is indicated with a partial
6069 * TSF value (bits 10 to 25), get the partial beacon TS
6070 * as well, and calc the delay to the start time.
6072 mask = GENMASK_ULL(25, 10);
6073 beacon_ts_tu = (beacon_ts & mask) >> 10;
6074 st_tu = ttlm_info.switch_time;
6075 delay = st_tu - beacon_ts_tu;
6078 * If the switch time is far in the future, then it
6079 * could also be the previous switch still being
6081 * We can simply ignore it for now, if it is a future
6082 * switch the AP will continue to announce it anyway.
6084 if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW)
6087 delay_jiffies = TU_TO_JIFFIES(delay);
6089 /* Link switching can take time, so schedule it
6090 * 100ms before to be ready on time
6092 if (delay_jiffies > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS)
6094 IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS;
6098 sdata->u.mgd.ttlm_info = ttlm_info;
6099 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6100 &sdata->u.mgd.ttlm_work);
6101 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
6102 &sdata->u.mgd.ttlm_work,
6109 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
6110 struct ieee80211_hdr *hdr, size_t len,
6111 struct ieee80211_rx_status *rx_status)
6113 struct ieee80211_sub_if_data *sdata = link->sdata;
6114 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6115 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
6116 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6117 struct ieee80211_mgmt *mgmt = (void *) hdr;
6119 struct ieee802_11_elems *elems;
6120 struct ieee80211_local *local = sdata->local;
6121 struct ieee80211_chanctx_conf *chanctx_conf;
6122 struct ieee80211_supported_band *sband;
6123 struct ieee80211_channel *chan;
6124 struct link_sta_info *link_sta;
6125 struct sta_info *sta;
6130 u8 *bssid, *variable = mgmt->u.beacon.variable;
6131 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
6132 struct ieee80211_elems_parse_params parse_params = {
6137 lockdep_assert_wiphy(local->hw.wiphy);
6139 /* Process beacon from the current BSS */
6140 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
6141 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
6142 struct ieee80211_ext *ext = (void *) mgmt;
6144 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
6145 variable = ext->u.s1g_short_beacon.variable;
6147 variable = ext->u.s1g_beacon.variable;
6150 baselen = (u8 *) variable - (u8 *) mgmt;
6154 parse_params.start = variable;
6155 parse_params.len = len - baselen;
6158 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
6159 if (!chanctx_conf) {
6164 if (ieee80211_rx_status_to_khz(rx_status) !=
6165 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
6169 chan = chanctx_conf->def.chan;
6172 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
6173 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) &&
6174 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
6175 parse_params.bss = ifmgd->assoc_data->link[0].bss;
6176 elems = ieee802_11_parse_elems_full(&parse_params);
6180 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6182 if (elems->dtim_period)
6183 link->u.mgd.dtim_period = elems->dtim_period;
6184 link->u.mgd.have_beacon = true;
6185 ifmgd->assoc_data->need_beacon = false;
6186 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6187 link->conf->sync_tsf =
6188 le64_to_cpu(mgmt->u.beacon.timestamp);
6189 link->conf->sync_device_ts =
6190 rx_status->device_timestamp;
6191 link->conf->sync_dtim_count = elems->dtim_count;
6194 if (elems->mbssid_config_ie)
6195 bss_conf->profile_periodicity =
6196 elems->mbssid_config_ie->profile_periodicity;
6198 bss_conf->profile_periodicity = 0;
6200 if (elems->ext_capab_len >= 11 &&
6201 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6202 bss_conf->ema_ap = true;
6204 bss_conf->ema_ap = false;
6206 /* continue assoc process */
6207 ifmgd->assoc_data->timeout = jiffies;
6208 ifmgd->assoc_data->timeout_started = true;
6209 run_again(sdata, ifmgd->assoc_data->timeout);
6214 if (!ifmgd->associated ||
6215 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
6217 bssid = link->u.mgd.bssid;
6219 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
6220 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
6223 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
6224 mlme_dbg_ratelimited(sdata,
6225 "cancelling AP probe due to a received beacon\n");
6226 ieee80211_reset_ap_probe(sdata);
6230 * Push the beacon loss detection into the future since
6231 * we are processing a beacon from the AP just now.
6233 ieee80211_sta_reset_beacon_monitor(sdata);
6235 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
6236 * element (which carries the beacon interval). Don't forget to add a
6237 * bit to care_about_ies[] above if mac80211 is interested in a
6238 * changing S1G element.
6240 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6241 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
6242 parse_params.bss = link->u.mgd.bss;
6243 parse_params.filter = care_about_ies;
6244 parse_params.crc = ncrc;
6245 elems = ieee802_11_parse_elems_full(&parse_params);
6250 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
6251 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
6252 if (local->hw.conf.dynamic_ps_timeout > 0) {
6253 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
6254 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
6255 ieee80211_hw_config(local,
6256 IEEE80211_CONF_CHANGE_PS);
6258 ieee80211_send_nullfunc(local, sdata, false);
6259 } else if (!local->pspolling && sdata->u.mgd.powersave) {
6260 local->pspolling = true;
6263 * Here is assumed that the driver will be
6264 * able to send ps-poll frame and receive a
6265 * response even though power save mode is
6266 * enabled, but some drivers might require
6267 * to disable power save here. This needs
6268 * to be investigated.
6270 ieee80211_send_pspoll(local, sdata);
6274 if (sdata->vif.p2p ||
6275 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
6276 struct ieee80211_p2p_noa_attr noa = {};
6279 ret = cfg80211_get_p2p_attr(variable,
6281 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
6282 (u8 *) &noa, sizeof(noa));
6284 if (link->u.mgd.p2p_noa_index != noa.index) {
6285 /* valid noa_attr and index changed */
6286 link->u.mgd.p2p_noa_index = noa.index;
6287 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
6288 changed |= BSS_CHANGED_P2P_PS;
6290 * make sure we update all information, the CRC
6291 * mechanism doesn't look at P2P attributes.
6293 link->u.mgd.beacon_crc_valid = false;
6295 } else if (link->u.mgd.p2p_noa_index != -1) {
6296 /* noa_attr not found and we had valid noa_attr before */
6297 link->u.mgd.p2p_noa_index = -1;
6298 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
6299 changed |= BSS_CHANGED_P2P_PS;
6300 link->u.mgd.beacon_crc_valid = false;
6304 if (link->u.mgd.csa_waiting_bcn)
6305 ieee80211_chswitch_post_beacon(link);
6308 * Update beacon timing and dtim count on every beacon appearance. This
6309 * will allow the driver to use the most updated values. Do it before
6310 * comparing this one with last received beacon.
6311 * IMPORTANT: These parameters would possibly be out of sync by the time
6312 * the driver will use them. The synchronized view is currently
6313 * guaranteed only in certain callbacks.
6315 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
6316 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
6317 link->conf->sync_tsf =
6318 le64_to_cpu(mgmt->u.beacon.timestamp);
6319 link->conf->sync_device_ts =
6320 rx_status->device_timestamp;
6321 link->conf->sync_dtim_count = elems->dtim_count;
6324 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
6325 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
6327 link->u.mgd.beacon_crc = ncrc;
6328 link->u.mgd.beacon_crc_valid = true;
6330 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6332 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
6333 rx_status->device_timestamp,
6336 if (!link->u.mgd.disable_wmm_tracking &&
6337 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
6338 elems->wmm_param_len,
6339 elems->mu_edca_param_set))
6340 changed |= BSS_CHANGED_QOS;
6343 * If we haven't had a beacon before, tell the driver about the
6344 * DTIM period (and beacon timing if desired) now.
6346 if (!link->u.mgd.have_beacon) {
6347 /* a few bogus AP send dtim_period = 0 or no TIM IE */
6348 bss_conf->dtim_period = elems->dtim_period ?: 1;
6350 changed |= BSS_CHANGED_BEACON_INFO;
6351 link->u.mgd.have_beacon = true;
6353 ieee80211_recalc_ps(local);
6355 ieee80211_recalc_ps_vif(sdata);
6358 if (elems->erp_info) {
6360 erp_value = elems->erp_info[0];
6365 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6366 changed |= ieee80211_handle_bss_capability(link,
6367 le16_to_cpu(mgmt->u.beacon.capab_info),
6368 erp_valid, erp_value);
6370 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6371 if (WARN_ON(!sta)) {
6374 link_sta = rcu_dereference_protected(sta->link[link->link_id],
6375 lockdep_is_held(&local->hw.wiphy->mtx));
6376 if (WARN_ON(!link_sta)) {
6380 if (WARN_ON(!link->conf->chandef.chan))
6383 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
6385 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
6387 if (ieee80211_config_bw(link, elems->ht_cap_elem,
6388 elems->vht_cap_elem, elems->ht_operation,
6389 elems->vht_operation, elems->he_operation,
6390 elems->eht_operation,
6391 elems->s1g_oper, bssid, &changed)) {
6393 "failed to follow AP %pM bandwidth change, disconnect\n",
6395 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6396 WLAN_REASON_DEAUTH_LEAVING,
6398 ieee80211_report_disconnect(sdata, deauth_buf,
6399 sizeof(deauth_buf), true,
6400 WLAN_REASON_DEAUTH_LEAVING,
6405 if (elems->opmode_notif)
6406 ieee80211_vht_handle_opmode(sdata, link_sta,
6407 *elems->opmode_notif,
6410 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
6411 elems->country_elem,
6412 elems->country_elem_len,
6413 elems->pwr_constr_elem,
6414 elems->cisco_dtpc_elem);
6416 if (elems->eht_operation &&
6417 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
6418 if (!ieee80211_config_puncturing(link, elems->eht_operation,
6420 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6421 WLAN_REASON_DEAUTH_LEAVING,
6423 ieee80211_report_disconnect(sdata, deauth_buf,
6424 sizeof(deauth_buf), true,
6425 WLAN_REASON_DEAUTH_LEAVING,
6431 ieee80211_ml_reconfiguration(sdata, elems);
6432 ieee80211_process_adv_ttlm(sdata, elems,
6433 le64_to_cpu(mgmt->u.beacon.timestamp));
6435 ieee80211_link_info_change_notify(sdata, link, changed);
6440 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
6441 struct sk_buff *skb)
6443 struct ieee80211_link_data *link = &sdata->deflink;
6444 struct ieee80211_rx_status *rx_status;
6445 struct ieee80211_hdr *hdr;
6448 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6450 rx_status = (struct ieee80211_rx_status *) skb->cb;
6451 hdr = (struct ieee80211_hdr *) skb->data;
6452 fc = le16_to_cpu(hdr->frame_control);
6454 switch (fc & IEEE80211_FCTL_STYPE) {
6455 case IEEE80211_STYPE_S1G_BEACON:
6456 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
6461 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
6462 struct sk_buff *skb)
6464 struct ieee80211_link_data *link = &sdata->deflink;
6465 struct ieee80211_rx_status *rx_status;
6466 struct ieee80211_mgmt *mgmt;
6470 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6472 rx_status = (struct ieee80211_rx_status *) skb->cb;
6473 mgmt = (struct ieee80211_mgmt *) skb->data;
6474 fc = le16_to_cpu(mgmt->frame_control);
6476 if (rx_status->link_valid) {
6477 link = sdata_dereference(sdata->link[rx_status->link_id],
6483 switch (fc & IEEE80211_FCTL_STYPE) {
6484 case IEEE80211_STYPE_BEACON:
6485 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
6486 skb->len, rx_status);
6488 case IEEE80211_STYPE_PROBE_RESP:
6489 ieee80211_rx_mgmt_probe_resp(link, skb);
6491 case IEEE80211_STYPE_AUTH:
6492 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
6494 case IEEE80211_STYPE_DEAUTH:
6495 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
6497 case IEEE80211_STYPE_DISASSOC:
6498 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
6500 case IEEE80211_STYPE_ASSOC_RESP:
6501 case IEEE80211_STYPE_REASSOC_RESP:
6502 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
6504 case IEEE80211_STYPE_ACTION:
6505 if (!sdata->u.mgd.associated ||
6506 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
6509 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
6510 struct ieee802_11_elems *elems;
6512 ies_len = skb->len -
6513 offsetof(struct ieee80211_mgmt,
6514 u.action.u.chan_switch.variable);
6519 /* CSA IE cannot be overridden, no need for BSSID */
6520 elems = ieee802_11_parse_elems(
6521 mgmt->u.action.u.chan_switch.variable,
6522 ies_len, true, NULL);
6524 if (elems && !elems->parse_error)
6525 ieee80211_sta_process_chanswitch(link,
6527 rx_status->device_timestamp,
6530 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
6531 struct ieee802_11_elems *elems;
6533 ies_len = skb->len -
6534 offsetof(struct ieee80211_mgmt,
6535 u.action.u.ext_chan_switch.variable);
6541 * extended CSA IE can't be overridden, no need for
6544 elems = ieee802_11_parse_elems(
6545 mgmt->u.action.u.ext_chan_switch.variable,
6546 ies_len, true, NULL);
6548 if (elems && !elems->parse_error) {
6549 /* for the handling code pretend it was an IE */
6550 elems->ext_chansw_ie =
6551 &mgmt->u.action.u.ext_chan_switch.data;
6553 ieee80211_sta_process_chanswitch(link,
6555 rx_status->device_timestamp,
6565 static void ieee80211_sta_timer(struct timer_list *t)
6567 struct ieee80211_sub_if_data *sdata =
6568 from_timer(sdata, t, u.mgd.timer);
6570 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
6573 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6576 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6578 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6581 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6585 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
6587 struct ieee80211_local *local = sdata->local;
6588 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6589 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
6593 struct ieee80211_prep_tx_info info = {
6594 .subtype = IEEE80211_STYPE_AUTH,
6597 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6599 if (WARN_ON_ONCE(!auth_data))
6604 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
6605 sdata_info(sdata, "authentication with %pM timed out\n",
6606 auth_data->ap_addr);
6609 * Most likely AP is not in the range so remove the
6610 * bss struct for that AP.
6612 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
6617 if (auth_data->algorithm == WLAN_AUTH_SAE)
6618 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
6620 info.link_id = auth_data->link_id;
6621 drv_mgd_prepare_tx(local, sdata, &info);
6623 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
6624 auth_data->ap_addr, auth_data->tries,
6625 IEEE80211_AUTH_MAX_TRIES);
6627 auth_data->expected_transaction = 2;
6629 if (auth_data->algorithm == WLAN_AUTH_SAE) {
6630 trans = auth_data->sae_trans;
6631 status = auth_data->sae_status;
6632 auth_data->expected_transaction = trans;
6635 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6636 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
6637 IEEE80211_TX_INTFL_MLME_CONN_TX;
6639 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
6640 auth_data->data, auth_data->data_len,
6641 auth_data->ap_addr, auth_data->ap_addr,
6642 NULL, 0, 0, tx_flags);
6644 if (tx_flags == 0) {
6645 if (auth_data->algorithm == WLAN_AUTH_SAE)
6646 auth_data->timeout = jiffies +
6647 IEEE80211_AUTH_TIMEOUT_SAE;
6649 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6651 auth_data->timeout =
6652 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6655 auth_data->timeout_started = true;
6656 run_again(sdata, auth_data->timeout);
6661 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6663 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6664 struct ieee80211_local *local = sdata->local;
6667 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6669 assoc_data->tries++;
6670 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6671 sdata_info(sdata, "association with %pM timed out\n",
6672 assoc_data->ap_addr);
6675 * Most likely AP is not in the range so remove the
6676 * bss struct for that AP.
6678 cfg80211_unlink_bss(local->hw.wiphy,
6679 assoc_data->link[assoc_data->assoc_link_id].bss);
6684 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6685 assoc_data->ap_addr, assoc_data->tries,
6686 IEEE80211_ASSOC_MAX_TRIES);
6687 ret = ieee80211_send_assoc(sdata);
6691 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6692 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6693 assoc_data->timeout_started = true;
6694 run_again(sdata, assoc_data->timeout);
6696 assoc_data->timeout =
6697 round_jiffies_up(jiffies +
6698 IEEE80211_ASSOC_TIMEOUT_LONG);
6699 assoc_data->timeout_started = true;
6700 run_again(sdata, assoc_data->timeout);
6706 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6707 __le16 fc, bool acked)
6709 struct ieee80211_local *local = sdata->local;
6711 sdata->u.mgd.status_fc = fc;
6712 sdata->u.mgd.status_acked = acked;
6713 sdata->u.mgd.status_received = true;
6715 wiphy_work_queue(local->hw.wiphy, &sdata->work);
6718 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6720 struct ieee80211_local *local = sdata->local;
6721 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6723 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6725 if (ifmgd->status_received) {
6726 __le16 fc = ifmgd->status_fc;
6727 bool status_acked = ifmgd->status_acked;
6729 ifmgd->status_received = false;
6730 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6732 if (ifmgd->auth_data->algorithm ==
6734 ifmgd->auth_data->timeout =
6736 IEEE80211_AUTH_TIMEOUT_SAE;
6738 ifmgd->auth_data->timeout =
6740 IEEE80211_AUTH_TIMEOUT_SHORT;
6741 run_again(sdata, ifmgd->auth_data->timeout);
6743 ifmgd->auth_data->timeout = jiffies - 1;
6745 ifmgd->auth_data->timeout_started = true;
6746 } else if (ifmgd->assoc_data &&
6747 !ifmgd->assoc_data->comeback &&
6748 (ieee80211_is_assoc_req(fc) ||
6749 ieee80211_is_reassoc_req(fc))) {
6751 * Update association timeout based on the TX status
6752 * for the (Re)Association Request frame. Skip this if
6753 * we have already processed a (Re)Association Response
6754 * frame that indicated need for association comeback
6755 * at a specific time in the future. This could happen
6756 * if the TX status information is delayed enough for
6757 * the response to be received and processed first.
6760 ifmgd->assoc_data->timeout =
6761 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6762 run_again(sdata, ifmgd->assoc_data->timeout);
6764 ifmgd->assoc_data->timeout = jiffies - 1;
6766 ifmgd->assoc_data->timeout_started = true;
6770 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6771 time_after(jiffies, ifmgd->auth_data->timeout)) {
6772 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6774 * ok ... we waited for assoc or continuation but
6775 * userspace didn't do it, so kill the auth data
6777 ieee80211_destroy_auth_data(sdata, false);
6778 } else if (ieee80211_auth(sdata)) {
6779 u8 ap_addr[ETH_ALEN];
6780 struct ieee80211_event event = {
6782 .u.mlme.data = AUTH_EVENT,
6783 .u.mlme.status = MLME_TIMEOUT,
6786 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6788 ieee80211_destroy_auth_data(sdata, false);
6790 cfg80211_auth_timeout(sdata->dev, ap_addr);
6791 drv_event_callback(sdata->local, sdata, &event);
6793 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6794 run_again(sdata, ifmgd->auth_data->timeout);
6796 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6797 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6798 if ((ifmgd->assoc_data->need_beacon &&
6799 !sdata->deflink.u.mgd.have_beacon) ||
6800 ieee80211_do_assoc(sdata)) {
6801 struct ieee80211_event event = {
6803 .u.mlme.data = ASSOC_EVENT,
6804 .u.mlme.status = MLME_TIMEOUT,
6807 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6808 drv_event_callback(sdata->local, sdata, &event);
6810 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6811 run_again(sdata, ifmgd->assoc_data->timeout);
6813 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6814 ifmgd->associated) {
6815 u8 *bssid = sdata->deflink.u.mgd.bssid;
6818 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6819 max_tries = max_nullfunc_tries;
6821 max_tries = max_probe_tries;
6823 /* ACK received for nullfunc probing frame */
6824 if (!ifmgd->probe_send_count)
6825 ieee80211_reset_ap_probe(sdata);
6826 else if (ifmgd->nullfunc_failed) {
6827 if (ifmgd->probe_send_count < max_tries) {
6829 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6830 bssid, ifmgd->probe_send_count,
6832 ieee80211_mgd_probe_ap_send(sdata);
6835 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6837 ieee80211_sta_connection_lost(sdata,
6838 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6841 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6842 run_again(sdata, ifmgd->probe_timeout);
6843 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6845 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6846 bssid, probe_wait_ms);
6847 ieee80211_sta_connection_lost(sdata,
6848 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6849 } else if (ifmgd->probe_send_count < max_tries) {
6851 "No probe response from AP %pM after %dms, try %d/%i\n",
6852 bssid, probe_wait_ms,
6853 ifmgd->probe_send_count, max_tries);
6854 ieee80211_mgd_probe_ap_send(sdata);
6857 * We actually lost the connection ... or did we?
6861 "No probe response from AP %pM after %dms, disconnecting.\n",
6862 bssid, probe_wait_ms);
6864 ieee80211_sta_connection_lost(sdata,
6865 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6870 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6872 struct ieee80211_sub_if_data *sdata =
6873 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6875 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6878 if (sdata->vif.bss_conf.csa_active &&
6879 !sdata->deflink.u.mgd.csa_waiting_bcn)
6882 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6885 sdata->u.mgd.connection_loss = false;
6886 wiphy_work_queue(sdata->local->hw.wiphy,
6887 &sdata->u.mgd.beacon_connection_loss_work);
6890 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6892 struct ieee80211_sub_if_data *sdata =
6893 from_timer(sdata, t, u.mgd.conn_mon_timer);
6894 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6895 struct ieee80211_local *local = sdata->local;
6896 struct sta_info *sta;
6897 unsigned long timeout;
6899 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6902 if (sdata->vif.bss_conf.csa_active &&
6903 !sdata->deflink.u.mgd.csa_waiting_bcn)
6906 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6910 timeout = sta->deflink.status_stats.last_ack;
6911 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6912 timeout = sta->deflink.rx_stats.last_rx;
6913 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6915 /* If timeout is after now, then update timer to fire at
6916 * the later date, but do not actually probe at this time.
6918 if (time_is_after_jiffies(timeout)) {
6919 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6923 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work);
6926 static void ieee80211_sta_monitor_work(struct wiphy *wiphy,
6927 struct wiphy_work *work)
6929 struct ieee80211_sub_if_data *sdata =
6930 container_of(work, struct ieee80211_sub_if_data,
6931 u.mgd.monitor_work);
6933 ieee80211_mgd_probe_ap(sdata, false);
6936 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6938 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6939 __ieee80211_stop_poll(sdata);
6941 /* let's probe the connection once */
6942 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6943 wiphy_work_queue(sdata->local->hw.wiphy,
6944 &sdata->u.mgd.monitor_work);
6949 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6951 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6952 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6954 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6956 if (ifmgd->auth_data || ifmgd->assoc_data) {
6957 const u8 *ap_addr = ifmgd->auth_data ?
6958 ifmgd->auth_data->ap_addr :
6959 ifmgd->assoc_data->ap_addr;
6962 * If we are trying to authenticate / associate while suspending,
6963 * cfg80211 won't know and won't actually abort those attempts,
6964 * thus we need to do that ourselves.
6966 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6967 IEEE80211_STYPE_DEAUTH,
6968 WLAN_REASON_DEAUTH_LEAVING,
6970 if (ifmgd->assoc_data)
6971 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6972 if (ifmgd->auth_data)
6973 ieee80211_destroy_auth_data(sdata, false);
6974 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6975 IEEE80211_DEAUTH_FRAME_LEN,
6979 /* This is a bit of a hack - we should find a better and more generic
6980 * solution to this. Normally when suspending, cfg80211 will in fact
6981 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6982 * auth (not so important) or assoc (this is the problem) process.
6984 * As a consequence, it can happen that we are in the process of both
6985 * associating and suspending, and receive an association response
6986 * after cfg80211 has checked if it needs to disconnect, but before
6987 * we actually set the flag to drop incoming frames. This will then
6988 * cause the workqueue flush to process the association response in
6989 * the suspend, resulting in a successful association just before it
6990 * tries to remove the interface from the driver, which now though
6991 * has a channel context assigned ... this results in issues.
6993 * To work around this (for now) simply deauth here again if we're
6996 if (ifmgd->associated && !sdata->local->wowlan) {
6998 struct cfg80211_deauth_request req = {
6999 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
7003 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
7004 ieee80211_mgd_deauth(sdata, &req);
7009 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
7011 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7013 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7015 if (!ifmgd->associated)
7018 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
7019 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
7020 mlme_dbg(sdata, "driver requested disconnect after resume\n");
7021 ieee80211_sta_connection_lost(sdata,
7022 WLAN_REASON_UNSPECIFIED,
7027 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
7028 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
7029 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
7030 ieee80211_sta_connection_lost(sdata,
7031 WLAN_REASON_UNSPECIFIED,
7037 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
7038 struct wiphy_work *work)
7040 struct ieee80211_link_data *link =
7041 container_of(work, struct ieee80211_link_data,
7042 u.mgd.request_smps_work);
7044 __ieee80211_request_smps_mgd(link->sdata, link,
7045 link->u.mgd.driver_smps_mode);
7048 /* interface setup */
7049 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
7051 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7053 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
7054 wiphy_work_init(&ifmgd->beacon_connection_loss_work,
7055 ieee80211_beacon_connection_loss_work);
7056 wiphy_work_init(&ifmgd->csa_connection_drop_work,
7057 ieee80211_csa_connection_drop_work);
7058 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work,
7059 ieee80211_tdls_peer_del_work);
7060 wiphy_delayed_work_init(&ifmgd->ml_reconf_work,
7061 ieee80211_ml_reconf_work);
7062 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
7063 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
7064 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
7065 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk,
7066 ieee80211_sta_handle_tspec_ac_params_wk);
7067 wiphy_delayed_work_init(&ifmgd->ttlm_work,
7068 ieee80211_tid_to_link_map_work);
7071 ifmgd->powersave = sdata->wdev.ps;
7072 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
7073 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
7074 /* Setup TDLS data */
7075 spin_lock_init(&ifmgd->teardown_lock);
7076 ifmgd->teardown_skb = NULL;
7077 ifmgd->orig_teardown_skb = NULL;
7080 static void ieee80211_recalc_smps_work(struct wiphy *wiphy,
7081 struct wiphy_work *work)
7083 struct ieee80211_link_data *link =
7084 container_of(work, struct ieee80211_link_data,
7087 ieee80211_recalc_smps(link->sdata, link);
7090 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
7092 struct ieee80211_sub_if_data *sdata = link->sdata;
7093 struct ieee80211_local *local = sdata->local;
7094 unsigned int link_id = link->link_id;
7096 link->u.mgd.p2p_noa_index = -1;
7097 link->u.mgd.conn_flags = 0;
7098 link->conf->bssid = link->u.mgd.bssid;
7100 wiphy_work_init(&link->u.mgd.request_smps_work,
7101 ieee80211_request_smps_mgd_work);
7102 wiphy_work_init(&link->u.mgd.recalc_smps,
7103 ieee80211_recalc_smps_work);
7104 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
7105 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
7107 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
7109 wiphy_delayed_work_init(&link->u.mgd.chswitch_work,
7110 ieee80211_chswitch_work);
7112 if (sdata->u.mgd.assoc_data)
7113 ether_addr_copy(link->conf->addr,
7114 sdata->u.mgd.assoc_data->link[link_id].addr);
7115 else if (!is_valid_ether_addr(link->conf->addr))
7116 eth_random_addr(link->conf->addr);
7119 /* scan finished notification */
7120 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
7122 struct ieee80211_sub_if_data *sdata;
7124 /* Restart STA timers */
7126 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
7127 if (ieee80211_sdata_running(sdata))
7128 ieee80211_restart_sta_timer(sdata);
7133 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
7134 struct cfg80211_bss *cbss, s8 link_id,
7135 const u8 *ap_mld_addr, bool assoc,
7138 struct ieee80211_local *local = sdata->local;
7139 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7140 struct ieee80211_bss *bss = (void *)cbss->priv;
7141 struct sta_info *new_sta = NULL;
7142 struct ieee80211_link_data *link;
7143 bool have_sta = false;
7149 if (WARN_ON(!ap_mld_addr))
7151 err = ieee80211_vif_set_links(sdata, BIT(link_id), 0);
7153 if (WARN_ON(ap_mld_addr))
7155 ap_mld_addr = cbss->bssid;
7156 err = ieee80211_vif_set_links(sdata, 0, 0);
7164 link = sdata_dereference(sdata->link[link_id], sdata);
7165 if (WARN_ON(!link)) {
7170 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
7175 /* If a reconfig is happening, bail out */
7176 if (local->in_reconfig) {
7183 have_sta = sta_info_get(sdata, ap_mld_addr);
7189 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
7190 link_id, cbss->bssid,
7193 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
7200 new_sta->sta.mlo = mlo;
7204 * Set up the information for the new channel before setting the
7205 * new channel. We can't - completely race-free - change the basic
7206 * rates bitmap and the channel (sband) that it refers to, but if
7207 * we set it up before we at least avoid calling into the driver's
7208 * bss_info_changed() method with invalid information (since we do
7209 * call that from changing the channel - only for IDLE and perhaps
7210 * some others, but ...).
7212 * So to avoid that, just set up all the new information before the
7213 * channel, but tell the driver to apply it only afterwards, since
7214 * it might need the new channel for that.
7217 const struct cfg80211_bss_ies *ies;
7218 struct link_sta_info *link_sta;
7221 link_sta = rcu_dereference(new_sta->link[link_id]);
7222 if (WARN_ON(!link_sta)) {
7224 sta_info_free(local, new_sta);
7229 err = ieee80211_mgd_setup_link_sta(link, new_sta,
7233 sta_info_free(local, new_sta);
7237 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
7239 /* set timing information */
7240 link->conf->beacon_int = cbss->beacon_interval;
7241 ies = rcu_dereference(cbss->beacon_ies);
7243 link->conf->sync_tsf = ies->tsf;
7244 link->conf->sync_device_ts =
7245 bss->device_ts_beacon;
7247 ieee80211_get_dtim(ies,
7248 &link->conf->sync_dtim_count,
7250 } else if (!ieee80211_hw_check(&sdata->local->hw,
7251 TIMING_BEACON_ONLY)) {
7252 ies = rcu_dereference(cbss->proberesp_ies);
7253 /* must be non-NULL since beacon IEs were NULL */
7254 link->conf->sync_tsf = ies->tsf;
7255 link->conf->sync_device_ts =
7256 bss->device_ts_presp;
7257 link->conf->sync_dtim_count = 0;
7259 link->conf->sync_tsf = 0;
7260 link->conf->sync_device_ts = 0;
7261 link->conf->sync_dtim_count = 0;
7266 if (new_sta || override) {
7267 err = ieee80211_prep_channel(sdata, link, cbss, mlo,
7268 &link->u.mgd.conn_flags);
7271 sta_info_free(local, new_sta);
7278 * tell driver about BSSID, basic rates and timing
7279 * this was set up above, before setting the channel
7281 ieee80211_link_info_change_notify(sdata, link,
7283 BSS_CHANGED_BASIC_RATES |
7284 BSS_CHANGED_BEACON_INT);
7287 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
7289 err = sta_info_insert(new_sta);
7293 "failed to insert STA entry for the AP (error %d)\n",
7298 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
7300 /* Cancel scan to ensure that nothing interferes with connection */
7301 if (local->scanning)
7302 ieee80211_scan_cancel(local);
7307 ieee80211_link_release_channel(&sdata->deflink);
7308 ieee80211_vif_set_links(sdata, 0, 0);
7313 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
7314 struct cfg80211_auth_request *req)
7316 struct ieee80211_local *local = sdata->local;
7317 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7318 struct ieee80211_mgd_auth_data *auth_data;
7319 struct ieee80211_link_data *link;
7320 const struct element *csa_elem, *ecsa_elem;
7325 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7327 /* prepare auth data structure */
7329 switch (req->auth_type) {
7330 case NL80211_AUTHTYPE_OPEN_SYSTEM:
7331 auth_alg = WLAN_AUTH_OPEN;
7333 case NL80211_AUTHTYPE_SHARED_KEY:
7336 auth_alg = WLAN_AUTH_SHARED_KEY;
7338 case NL80211_AUTHTYPE_FT:
7339 auth_alg = WLAN_AUTH_FT;
7341 case NL80211_AUTHTYPE_NETWORK_EAP:
7342 auth_alg = WLAN_AUTH_LEAP;
7344 case NL80211_AUTHTYPE_SAE:
7345 auth_alg = WLAN_AUTH_SAE;
7347 case NL80211_AUTHTYPE_FILS_SK:
7348 auth_alg = WLAN_AUTH_FILS_SK;
7350 case NL80211_AUTHTYPE_FILS_SK_PFS:
7351 auth_alg = WLAN_AUTH_FILS_SK_PFS;
7353 case NL80211_AUTHTYPE_FILS_PK:
7354 auth_alg = WLAN_AUTH_FILS_PK;
7360 if (ifmgd->assoc_data)
7364 csa_elem = ieee80211_bss_get_elem(req->bss, WLAN_EID_CHANNEL_SWITCH);
7365 ecsa_elem = ieee80211_bss_get_elem(req->bss,
7366 WLAN_EID_EXT_CHANSWITCH_ANN);
7368 csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) &&
7369 ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) ||
7371 ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) &&
7372 ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) {
7374 sdata_info(sdata, "AP is in CSA process, reject auth\n");
7379 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
7380 req->ie_len, GFP_KERNEL);
7384 memcpy(auth_data->ap_addr,
7385 req->ap_mld_addr ?: req->bss->bssid,
7387 auth_data->bss = req->bss;
7388 auth_data->link_id = req->link_id;
7390 if (req->auth_data_len >= 4) {
7391 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
7392 __le16 *pos = (__le16 *) req->auth_data;
7394 auth_data->sae_trans = le16_to_cpu(pos[0]);
7395 auth_data->sae_status = le16_to_cpu(pos[1]);
7397 memcpy(auth_data->data, req->auth_data + 4,
7398 req->auth_data_len - 4);
7399 auth_data->data_len += req->auth_data_len - 4;
7402 /* Check if continuing authentication or trying to authenticate with the
7403 * same BSS that we were in the process of authenticating with and avoid
7404 * removal and re-addition of the STA entry in
7405 * ieee80211_prep_connection().
7407 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
7408 ifmgd->auth_data->link_id == req->link_id;
7410 if (req->ie && req->ie_len) {
7411 memcpy(&auth_data->data[auth_data->data_len],
7412 req->ie, req->ie_len);
7413 auth_data->data_len += req->ie_len;
7416 if (req->key && req->key_len) {
7417 auth_data->key_len = req->key_len;
7418 auth_data->key_idx = req->key_idx;
7419 memcpy(auth_data->key, req->key, req->key_len);
7422 auth_data->algorithm = auth_alg;
7424 /* try to authenticate/probe */
7426 if (ifmgd->auth_data) {
7427 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
7428 auth_data->peer_confirmed =
7429 ifmgd->auth_data->peer_confirmed;
7431 ieee80211_destroy_auth_data(sdata, cont_auth);
7434 /* prep auth_data so we don't go into idle on disassoc */
7435 ifmgd->auth_data = auth_data;
7437 /* If this is continuation of an ongoing SAE authentication exchange
7438 * (i.e., request to send SAE Confirm) and the peer has already
7439 * confirmed, mark authentication completed since we are about to send
7442 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
7443 auth_data->peer_confirmed && auth_data->sae_trans == 2)
7444 ieee80211_mark_sta_auth(sdata);
7446 if (ifmgd->associated) {
7447 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7450 "disconnect from AP %pM for new auth to %pM\n",
7451 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
7452 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7453 WLAN_REASON_UNSPECIFIED,
7456 ieee80211_report_disconnect(sdata, frame_buf,
7457 sizeof(frame_buf), true,
7458 WLAN_REASON_UNSPECIFIED,
7462 /* needed for transmitting the auth frame(s) properly */
7463 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
7465 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
7466 req->ap_mld_addr, cont_auth, false);
7470 if (req->link_id > 0)
7471 link = sdata_dereference(sdata->link[req->link_id], sdata);
7473 link = sdata_dereference(sdata->link[0], sdata);
7475 if (WARN_ON(!link)) {
7480 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n",
7481 auth_data->ap_addr, link->conf->addr);
7483 err = ieee80211_auth(sdata);
7485 sta_info_destroy_addr(sdata, auth_data->ap_addr);
7489 /* hold our own reference */
7490 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
7494 if (!ieee80211_vif_is_mld(&sdata->vif)) {
7495 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7496 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7498 ieee80211_link_release_channel(&sdata->deflink);
7500 ifmgd->auth_data = NULL;
7505 static ieee80211_conn_flags_t
7506 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
7507 struct ieee80211_mgd_assoc_data *assoc_data,
7508 struct cfg80211_assoc_request *req,
7509 ieee80211_conn_flags_t conn_flags,
7510 unsigned int link_id)
7512 struct ieee80211_local *local = sdata->local;
7513 const struct cfg80211_bss_ies *bss_ies;
7514 struct ieee80211_supported_band *sband;
7515 const struct element *ht_elem, *vht_elem;
7516 struct ieee80211_link_data *link;
7517 struct cfg80211_bss *cbss;
7518 struct ieee80211_bss *bss;
7519 bool is_5ghz, is_6ghz;
7521 cbss = assoc_data->link[link_id].bss;
7525 bss = (void *)cbss->priv;
7527 sband = local->hw.wiphy->bands[cbss->channel->band];
7528 if (WARN_ON(!sband))
7531 link = sdata_dereference(sdata->link[link_id], sdata);
7535 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
7536 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
7538 /* for MLO connections assume advertising all rates is OK */
7539 if (!req->ap_mld_addr) {
7540 assoc_data->supp_rates = bss->supp_rates;
7541 assoc_data->supp_rates_len = bss->supp_rates_len;
7544 /* copy and link elems for the STA profile */
7545 if (req->links[link_id].elems_len) {
7546 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
7547 req->links[link_id].elems_len);
7548 assoc_data->link[link_id].elems = assoc_data->ie_pos;
7549 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
7550 assoc_data->ie_pos += req->links[link_id].elems_len;
7554 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
7555 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
7556 assoc_data->link[link_id].ap_ht_param =
7557 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
7559 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7560 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
7561 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
7562 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
7563 sizeof(struct ieee80211_vht_cap));
7564 } else if (is_5ghz) {
7566 "VHT capa missing/short, disabling VHT/HE/EHT\n");
7567 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
7568 IEEE80211_CONN_DISABLE_HE |
7569 IEEE80211_CONN_DISABLE_EHT;
7573 link->u.mgd.beacon_crc_valid = false;
7574 link->u.mgd.dtim_period = 0;
7575 link->u.mgd.have_beacon = false;
7577 /* override HT/VHT configuration only if the AP and we support it */
7578 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
7579 struct ieee80211_sta_ht_cap sta_ht_cap;
7581 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
7582 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
7585 link->conf->eht_puncturing = 0;
7588 bss_ies = rcu_dereference(cbss->beacon_ies);
7592 ieee80211_get_dtim(bss_ies, &dtim_count,
7593 &link->u.mgd.dtim_period);
7595 sdata->deflink.u.mgd.have_beacon = true;
7597 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
7598 link->conf->sync_tsf = bss_ies->tsf;
7599 link->conf->sync_device_ts = bss->device_ts_beacon;
7600 link->conf->sync_dtim_count = dtim_count;
7603 bss_ies = rcu_dereference(cbss->ies);
7607 const struct ieee80211_eht_operation *eht_oper;
7608 const struct element *elem;
7610 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
7611 bss_ies->data, bss_ies->len);
7612 if (elem && elem->datalen >= 3)
7613 link->conf->profile_periodicity = elem->data[2];
7615 link->conf->profile_periodicity = 0;
7617 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
7618 bss_ies->data, bss_ies->len);
7619 if (elem && elem->datalen >= 11 &&
7620 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7621 link->conf->ema_ap = true;
7623 link->conf->ema_ap = false;
7625 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
7626 bss_ies->data, bss_ies->len);
7627 eht_oper = (const void *)(elem->data + 1);
7630 ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
7631 elem->datalen - 1) &&
7632 (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
7633 (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
7634 const struct ieee80211_eht_operation_info *info =
7635 (void *)eht_oper->optional;
7636 const u8 *disable_subchannel_bitmap = info->optional;
7639 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
7640 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
7641 &link->conf->chandef) &&
7642 !(bitmap && ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING)))
7643 ieee80211_handle_puncturing_bitmap(link,
7648 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7653 if (bss->corrupt_data) {
7654 char *corrupt_type = "data";
7656 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
7657 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
7658 corrupt_type = "beacon and probe response";
7660 corrupt_type = "beacon";
7661 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
7662 corrupt_type = "probe response";
7664 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
7665 cbss->bssid, corrupt_type);
7668 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
7669 if (sdata->u.mgd.powersave)
7670 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
7672 link->smps_mode = IEEE80211_SMPS_OFF;
7674 link->smps_mode = link->u.mgd.req_smps;
7680 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
7681 struct cfg80211_assoc_request *req)
7683 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
7684 struct ieee80211_local *local = sdata->local;
7685 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7686 struct ieee80211_mgd_assoc_data *assoc_data;
7687 const struct element *ssid_elem, *csa_elem, *ecsa_elem;
7688 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
7689 ieee80211_conn_flags_t conn_flags = 0;
7690 struct ieee80211_link_data *link;
7691 struct cfg80211_bss *cbss;
7692 struct ieee80211_bss *bss;
7695 size_t size = sizeof(*assoc_data) + req->ie_len;
7697 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
7698 size += req->links[i].elems_len;
7700 /* FIXME: no support for 4-addr MLO yet */
7701 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
7704 assoc_data = kzalloc(size, GFP_KERNEL);
7708 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
7711 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
7712 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
7718 csa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_CHANNEL_SWITCH);
7719 ecsa_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_EXT_CHANSWITCH_ANN);
7721 csa_elem->datalen == sizeof(struct ieee80211_channel_sw_ie) &&
7722 ((struct ieee80211_channel_sw_ie *)csa_elem->data)->count != 0) ||
7724 ecsa_elem->datalen == sizeof(struct ieee80211_ext_chansw_ie) &&
7725 ((struct ieee80211_ext_chansw_ie *)ecsa_elem->data)->count != 0)) {
7726 sdata_info(sdata, "AP is in CSA process, reject assoc\n");
7732 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
7733 assoc_data->ssid_len = ssid_elem->datalen;
7734 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
7735 vif_cfg->ssid_len = assoc_data->ssid_len;
7738 if (req->ap_mld_addr) {
7739 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7740 if (!req->links[i].bss)
7742 link = sdata_dereference(sdata->link[i], sdata);
7744 ether_addr_copy(assoc_data->link[i].addr,
7747 eth_random_addr(assoc_data->link[i].addr);
7750 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7753 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7755 memcpy(assoc_data->ap_addr,
7756 req->ap_mld_addr ?: req->bss->bssid,
7759 if (ifmgd->associated) {
7760 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7763 "disconnect from AP %pM for new assoc to %pM\n",
7764 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7765 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7766 WLAN_REASON_UNSPECIFIED,
7769 ieee80211_report_disconnect(sdata, frame_buf,
7770 sizeof(frame_buf), true,
7771 WLAN_REASON_UNSPECIFIED,
7775 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7780 if (ifmgd->assoc_data) {
7785 if (ifmgd->auth_data) {
7788 /* keep sta info, bssid if matching */
7789 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7790 assoc_data->ap_addr) &&
7791 ifmgd->auth_data->link_id == req->link_id;
7793 /* Cleanup is delayed if auth_data matches */
7795 ieee80211_destroy_auth_data(sdata, false);
7798 /* prepare assoc data */
7800 bss = (void *)cbss->priv;
7801 assoc_data->wmm = bss->wmm_used &&
7802 (local->hw.queues >= IEEE80211_NUM_ACS);
7805 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7806 * We still associate in non-HT mode (11a/b/g) if any one of these
7807 * ciphers is configured as pairwise.
7808 * We can set this to true for non-11n hardware, that'll be checked
7809 * separately along with the peer capabilities.
7811 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7812 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7813 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7814 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7815 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7816 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7817 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7818 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7819 netdev_info(sdata->dev,
7820 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7824 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7825 if (!bss->wmm_used) {
7826 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7827 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7828 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7829 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7830 netdev_info(sdata->dev,
7831 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7834 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7835 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7836 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7837 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7838 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7839 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7842 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7843 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7844 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7847 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7848 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7849 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7850 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7853 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7854 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7856 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7857 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7858 sizeof(ifmgd->ht_capa_mask));
7860 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7861 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7862 sizeof(ifmgd->vht_capa_mask));
7864 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7865 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7866 sizeof(ifmgd->s1g_capa_mask));
7868 if (req->ie && req->ie_len) {
7869 memcpy(assoc_data->ie, req->ie, req->ie_len);
7870 assoc_data->ie_len = req->ie_len;
7871 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7873 assoc_data->ie_pos = assoc_data->ie;
7876 if (req->fils_kek) {
7877 /* should already be checked in cfg80211 - so warn */
7878 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7882 memcpy(assoc_data->fils_kek, req->fils_kek,
7884 assoc_data->fils_kek_len = req->fils_kek_len;
7887 if (req->fils_nonces)
7888 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7889 2 * FILS_NONCE_LEN);
7891 /* default timeout */
7892 assoc_data->timeout = jiffies;
7893 assoc_data->timeout_started = true;
7895 assoc_data->assoc_link_id = assoc_link_id;
7897 if (req->ap_mld_addr) {
7898 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7899 assoc_data->link[i].conn_flags = conn_flags;
7900 assoc_data->link[i].bss = req->links[i].bss;
7901 assoc_data->link[i].disabled = req->links[i].disabled;
7904 /* if there was no authentication, set up the link */
7905 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0);
7909 assoc_data->link[0].conn_flags = conn_flags;
7910 assoc_data->link[0].bss = cbss;
7913 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7914 if (WARN_ON(!link)) {
7919 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7920 conn_flags |= link->u.mgd.conn_flags;
7921 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7922 conn_flags, assoc_link_id);
7923 override = link->u.mgd.conn_flags != conn_flags;
7924 link->u.mgd.conn_flags |= conn_flags;
7926 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7927 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7928 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7929 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7931 if (bss->wmm_used && bss->uapsd_supported &&
7932 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7933 assoc_data->uapsd = true;
7934 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7936 assoc_data->uapsd = false;
7937 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7940 if (req->prev_bssid)
7941 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7944 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7945 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7947 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7948 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
7951 if (req->flags & ASSOC_REQ_USE_RRM)
7952 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
7954 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
7956 if (req->crypto.control_port)
7957 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
7959 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
7961 sdata->control_port_protocol = req->crypto.control_port_ethertype;
7962 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
7963 sdata->control_port_over_nl80211 =
7964 req->crypto.control_port_over_nl80211;
7965 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
7967 /* kick off associate process */
7968 ifmgd->assoc_data = assoc_data;
7970 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7971 if (!assoc_data->link[i].bss)
7973 if (i == assoc_data->assoc_link_id)
7975 /* only calculate the flags, hence link == NULL */
7976 err = ieee80211_prep_channel(sdata, NULL,
7977 assoc_data->link[i].bss, true,
7978 &assoc_data->link[i].conn_flags);
7980 req->links[i].error = err;
7985 /* needed for transmitting the assoc frames properly */
7986 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
7988 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
7989 req->ap_mld_addr, true, override);
7993 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
7994 link->u.mgd.conn_flags;
7996 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
7997 const struct cfg80211_bss_ies *beacon_ies;
8000 beacon_ies = rcu_dereference(req->bss->beacon_ies);
8004 * Wait up to one beacon interval ...
8005 * should this be more if we miss one?
8007 sdata_info(sdata, "waiting for beacon from %pM\n",
8009 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
8010 assoc_data->timeout_started = true;
8011 assoc_data->need_beacon = true;
8016 run_again(sdata, assoc_data->timeout);
8018 /* We are associating, clean up auth_data */
8019 if (ifmgd->auth_data)
8020 ieee80211_destroy_auth_data(sdata, true);
8024 if (!ifmgd->auth_data) {
8025 eth_zero_addr(sdata->deflink.u.mgd.bssid);
8026 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
8029 ifmgd->assoc_data = NULL;
8035 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
8036 struct cfg80211_deauth_request *req)
8038 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8039 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8040 bool tx = !req->local_state_change;
8041 struct ieee80211_prep_tx_info info = {
8042 .subtype = IEEE80211_STYPE_DEAUTH,
8045 if (ifmgd->auth_data &&
8046 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
8048 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
8049 req->bssid, req->reason_code,
8050 ieee80211_get_reason_code_string(req->reason_code));
8052 info.link_id = ifmgd->auth_data->link_id;
8053 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8054 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8055 IEEE80211_STYPE_DEAUTH,
8056 req->reason_code, tx,
8058 ieee80211_destroy_auth_data(sdata, false);
8059 ieee80211_report_disconnect(sdata, frame_buf,
8060 sizeof(frame_buf), true,
8061 req->reason_code, false);
8062 drv_mgd_complete_tx(sdata->local, sdata, &info);
8066 if (ifmgd->assoc_data &&
8067 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
8069 "aborting association with %pM by local choice (Reason: %u=%s)\n",
8070 req->bssid, req->reason_code,
8071 ieee80211_get_reason_code_string(req->reason_code));
8073 info.link_id = ifmgd->assoc_data->assoc_link_id;
8074 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8075 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8076 IEEE80211_STYPE_DEAUTH,
8077 req->reason_code, tx,
8079 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
8080 ieee80211_report_disconnect(sdata, frame_buf,
8081 sizeof(frame_buf), true,
8082 req->reason_code, false);
8086 if (ifmgd->associated &&
8087 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
8089 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
8090 req->bssid, req->reason_code,
8091 ieee80211_get_reason_code_string(req->reason_code));
8093 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
8094 req->reason_code, tx, frame_buf);
8095 ieee80211_report_disconnect(sdata, frame_buf,
8096 sizeof(frame_buf), true,
8097 req->reason_code, false);
8098 drv_mgd_complete_tx(sdata->local, sdata, &info);
8105 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
8106 struct cfg80211_disassoc_request *req)
8108 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8110 if (!sdata->u.mgd.associated ||
8111 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
8115 "disassociating from %pM by local choice (Reason: %u=%s)\n",
8116 req->ap_addr, req->reason_code,
8117 ieee80211_get_reason_code_string(req->reason_code));
8119 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
8120 req->reason_code, !req->local_state_change,
8123 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
8124 req->reason_code, false);
8129 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
8131 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8132 &link->u.mgd.request_smps_work);
8133 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8134 &link->u.mgd.recalc_smps);
8135 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
8136 &link->u.mgd.chswitch_work);
8139 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
8141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8144 * Make sure some work items will not run after this,
8145 * they will not do anything but might not have been
8146 * cancelled when disconnecting.
8148 wiphy_work_cancel(sdata->local->hw.wiphy,
8149 &ifmgd->monitor_work);
8150 wiphy_work_cancel(sdata->local->hw.wiphy,
8151 &ifmgd->beacon_connection_loss_work);
8152 wiphy_work_cancel(sdata->local->hw.wiphy,
8153 &ifmgd->csa_connection_drop_work);
8154 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8155 &ifmgd->tdls_peer_del_work);
8156 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8157 &ifmgd->ml_reconf_work);
8158 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
8160 if (ifmgd->assoc_data)
8161 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
8162 if (ifmgd->auth_data)
8163 ieee80211_destroy_auth_data(sdata, false);
8164 spin_lock_bh(&ifmgd->teardown_lock);
8165 if (ifmgd->teardown_skb) {
8166 kfree_skb(ifmgd->teardown_skb);
8167 ifmgd->teardown_skb = NULL;
8168 ifmgd->orig_teardown_skb = NULL;
8170 kfree(ifmgd->assoc_req_ies);
8171 ifmgd->assoc_req_ies = NULL;
8172 ifmgd->assoc_req_ies_len = 0;
8173 spin_unlock_bh(&ifmgd->teardown_lock);
8174 del_timer_sync(&ifmgd->timer);
8177 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
8178 enum nl80211_cqm_rssi_threshold_event rssi_event,
8182 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8184 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
8186 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
8188 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
8190 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
8192 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8194 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
8196 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
8198 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
8200 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
8204 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
8206 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
8210 * Scale up threshold values before storing it, as the RSSI averaging
8211 * algorithm uses a scaled up value as well. Change this scaling
8212 * factor if the RSSI averaging algorithm changes.
8214 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
8215 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
8218 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
8222 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8224 WARN_ON(rssi_min_thold == rssi_max_thold ||
8225 rssi_min_thold > rssi_max_thold);
8227 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
8230 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
8232 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
8234 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8236 _ieee80211_enable_rssi_reports(sdata, 0, 0);
8238 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);