1 // SPDX-License-Identifier: GPL-2.0-only
3 * BSS client mode implementation
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2013-2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright (C) 2018 - 2024 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;
2921 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
2923 netif_carrier_off(sdata->dev);
2926 * if we want to get out of ps before disassoc (why?) we have
2927 * to do it before sending disassoc, as otherwise the null-packet
2930 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2931 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2932 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2934 local->ps_sdata = NULL;
2936 /* disable per-vif ps */
2937 ieee80211_recalc_ps_vif(sdata);
2939 /* make sure ongoing transmission finishes */
2943 * drop any frame before deauth/disassoc, this can be data or
2944 * management frame. Since we are disconnecting, we should not
2945 * insist sending these frames which can take time and delay
2946 * the disconnection and possible the roaming.
2949 ieee80211_flush_queues(local, sdata, true);
2951 /* deauthenticate/disassociate now */
2952 if (tx || frame_buf) {
2954 * In multi channel scenarios guarantee that the virtual
2955 * interface is granted immediate airtime to transmit the
2956 * deauthentication frame by calling mgd_prepare_tx, if the
2957 * driver requested so.
2959 if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP)) {
2960 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link);
2962 struct ieee80211_link_data *link;
2964 link = sdata_dereference(sdata->link[link_id],
2968 if (link->u.mgd.have_beacon)
2971 if (link_id == IEEE80211_MLD_MAX_NUM_LINKS) {
2972 info.link_id = ffs(sdata->vif.active_links) - 1;
2973 drv_mgd_prepare_tx(sdata->local, sdata, &info);
2977 ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
2978 sdata->vif.cfg.ap_addr, stype,
2979 reason, tx, frame_buf);
2982 /* flush out frame - make sure the deauth was actually sent */
2984 ieee80211_flush_queues(local, sdata, false);
2986 drv_mgd_complete_tx(sdata->local, sdata, &info);
2988 /* clear AP addr only after building the needed mgmt frames */
2989 eth_zero_addr(sdata->deflink.u.mgd.bssid);
2990 eth_zero_addr(sdata->vif.cfg.ap_addr);
2992 sdata->vif.cfg.ssid_len = 0;
2994 /* remove AP and TDLS peers */
2995 sta_info_flush(sdata);
2997 /* finally reset all BSS / config parameters */
2998 if (!ieee80211_vif_is_mld(&sdata->vif))
2999 changed |= ieee80211_reset_erp_info(sdata);
3001 ieee80211_led_assoc(local, 0);
3002 changed |= BSS_CHANGED_ASSOC;
3003 sdata->vif.cfg.assoc = false;
3005 sdata->deflink.u.mgd.p2p_noa_index = -1;
3006 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
3007 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
3009 /* on the next assoc, re-program HT/VHT parameters */
3010 memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
3011 memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
3012 memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
3013 memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
3016 * reset MU-MIMO ownership and group data in default link,
3017 * if used, other links are destroyed
3019 memset(sdata->vif.bss_conf.mu_group.membership, 0,
3020 sizeof(sdata->vif.bss_conf.mu_group.membership));
3021 memset(sdata->vif.bss_conf.mu_group.position, 0,
3022 sizeof(sdata->vif.bss_conf.mu_group.position));
3023 if (!ieee80211_vif_is_mld(&sdata->vif))
3024 changed |= BSS_CHANGED_MU_GROUPS;
3025 sdata->vif.bss_conf.mu_mimo_owner = false;
3027 sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
3029 del_timer_sync(&local->dynamic_ps_timer);
3030 wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
3032 /* Disable ARP filtering */
3033 if (sdata->vif.cfg.arp_addr_cnt)
3034 changed |= BSS_CHANGED_ARP_FILTER;
3036 sdata->vif.bss_conf.qos = false;
3037 if (!ieee80211_vif_is_mld(&sdata->vif)) {
3038 changed |= BSS_CHANGED_QOS;
3039 /* The BSSID (not really interesting) and HT changed */
3040 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
3041 ieee80211_bss_info_change_notify(sdata, changed);
3043 ieee80211_vif_cfg_change_notify(sdata, changed);
3046 /* disassociated - set to defaults now */
3047 ieee80211_set_wmm_default(&sdata->deflink, false, false);
3049 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
3050 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
3051 del_timer_sync(&sdata->u.mgd.timer);
3053 sdata->vif.bss_conf.dtim_period = 0;
3054 sdata->vif.bss_conf.beacon_rate = NULL;
3056 sdata->deflink.u.mgd.have_beacon = false;
3057 sdata->deflink.u.mgd.tracking_signal_avg = false;
3058 sdata->deflink.u.mgd.disable_wmm_tracking = false;
3061 sdata->deflink.u.mgd.conn_flags = 0;
3063 for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
3064 struct ieee80211_link_data *link;
3066 link = sdata_dereference(sdata->link[link_id], sdata);
3069 ieee80211_link_release_channel(link);
3072 sdata->vif.bss_conf.csa_active = false;
3073 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3074 sdata->deflink.u.mgd.csa_ignored_same_chan = false;
3075 if (sdata->deflink.csa_block_tx) {
3076 ieee80211_wake_vif_queues(local, sdata,
3077 IEEE80211_QUEUE_STOP_REASON_CSA);
3078 sdata->deflink.csa_block_tx = false;
3081 /* existing TX TSPEC sessions no longer exist */
3082 memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
3083 wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk);
3085 sdata->vif.bss_conf.pwr_reduction = 0;
3086 sdata->vif.bss_conf.tx_pwr_env_num = 0;
3087 memset(sdata->vif.bss_conf.tx_pwr_env, 0,
3088 sizeof(sdata->vif.bss_conf.tx_pwr_env));
3090 memset(&sdata->u.mgd.ttlm_info, 0,
3091 sizeof(sdata->u.mgd.ttlm_info));
3092 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
3093 ieee80211_vif_set_links(sdata, 0, 0);
3096 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
3098 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3099 struct ieee80211_local *local = sdata->local;
3101 lockdep_assert_wiphy(local->hw.wiphy);
3103 if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
3106 __ieee80211_stop_poll(sdata);
3108 ieee80211_recalc_ps(local);
3110 if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
3114 * We've received a probe response, but are not sure whether
3115 * we have or will be receiving any beacons or data, so let's
3116 * schedule the timers again, just in case.
3118 ieee80211_sta_reset_beacon_monitor(sdata);
3120 mod_timer(&ifmgd->conn_mon_timer,
3121 round_jiffies_up(jiffies +
3122 IEEE80211_CONNECTION_IDLE_TIME));
3125 static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
3126 struct ieee80211_hdr *hdr,
3129 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3132 struct ieee80211_sta_tx_tspec *tx_tspec;
3133 unsigned long now = jiffies;
3135 if (!ieee80211_is_data_qos(hdr->frame_control))
3138 tid = ieee80211_get_tid(hdr);
3139 ac = ieee80211_ac_from_tid(tid);
3140 tx_tspec = &ifmgd->tx_tspec[ac];
3142 if (likely(!tx_tspec->admitted_time))
3145 if (time_after(now, tx_tspec->time_slice_start + HZ)) {
3146 tx_tspec->consumed_tx_time = 0;
3147 tx_tspec->time_slice_start = now;
3149 if (tx_tspec->downgraded) {
3150 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3151 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3152 &ifmgd->tx_tspec_wk, 0);
3156 if (tx_tspec->downgraded)
3159 tx_tspec->consumed_tx_time += tx_time;
3161 if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
3162 tx_tspec->downgraded = true;
3163 tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
3164 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
3165 &ifmgd->tx_tspec_wk, 0);
3169 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
3170 struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
3172 ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
3174 if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
3175 !sdata->u.mgd.probe_send_count)
3179 sdata->u.mgd.probe_send_count = 0;
3181 sdata->u.mgd.nullfunc_failed = true;
3182 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
3185 static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
3186 const u8 *src, const u8 *dst,
3187 const u8 *ssid, size_t ssid_len,
3188 struct ieee80211_channel *channel)
3190 struct sk_buff *skb;
3192 skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
3193 ssid, ssid_len, NULL, 0,
3194 IEEE80211_PROBE_FLAG_DIRECTED);
3196 ieee80211_tx_skb(sdata, skb);
3199 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
3201 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3202 u8 *dst = sdata->vif.cfg.ap_addr;
3203 u8 unicast_limit = max(1, max_probe_tries - 3);
3204 struct sta_info *sta;
3206 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3208 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
3212 * Try sending broadcast probe requests for the last three
3213 * probe requests after the first ones failed since some
3214 * buggy APs only support broadcast probe requests.
3216 if (ifmgd->probe_send_count >= unicast_limit)
3220 * When the hardware reports an accurate Tx ACK status, it's
3221 * better to send a nullfunc frame instead of a probe request,
3222 * as it will kick us off the AP quickly if we aren't associated
3223 * anymore. The timeout will be reset if the frame is ACKed by
3226 ifmgd->probe_send_count++;
3229 sta = sta_info_get(sdata, dst);
3231 ieee80211_check_fast_rx(sta);
3234 if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
3235 ifmgd->nullfunc_failed = false;
3236 ieee80211_send_nullfunc(sdata->local, sdata, false);
3238 ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
3239 sdata->vif.cfg.ssid,
3240 sdata->vif.cfg.ssid_len,
3241 sdata->deflink.u.mgd.bss->channel);
3244 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
3245 run_again(sdata, ifmgd->probe_timeout);
3248 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
3251 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3252 bool already = false;
3254 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3256 if (WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif)))
3259 if (!ieee80211_sdata_running(sdata))
3262 if (!ifmgd->associated)
3265 if (sdata->local->tmp_channel || sdata->local->scanning)
3268 if (sdata->local->suspending) {
3269 /* reschedule after resume */
3270 ieee80211_reset_ap_probe(sdata);
3275 mlme_dbg_ratelimited(sdata,
3276 "detected beacon loss from AP (missed %d beacons) - probing\n",
3279 ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
3283 * The driver/our work has already reported this event or the
3284 * connection monitoring has kicked in and we have already sent
3285 * a probe request. Or maybe the AP died and the driver keeps
3286 * reporting until we disassociate...
3288 * In either case we have to ignore the current call to this
3289 * function (except for setting the correct probe reason bit)
3290 * because otherwise we would reset the timer every time and
3291 * never check whether we received a probe response!
3293 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
3296 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
3301 ieee80211_recalc_ps(sdata->local);
3303 ifmgd->probe_send_count = 0;
3304 ieee80211_mgd_probe_ap_send(sdata);
3307 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
3308 struct ieee80211_vif *vif)
3310 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3311 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3312 struct cfg80211_bss *cbss;
3313 struct sk_buff *skb;
3314 const struct element *ssid;
3317 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3319 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
3320 ieee80211_vif_is_mld(&sdata->vif)))
3323 if (ifmgd->associated)
3324 cbss = sdata->deflink.u.mgd.bss;
3325 else if (ifmgd->auth_data)
3326 cbss = ifmgd->auth_data->bss;
3327 else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
3328 cbss = ifmgd->assoc_data->link[0].bss;
3333 ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
3334 if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
3335 "invalid SSID element (len=%d)",
3336 ssid ? ssid->datalen : -1))
3339 ssid_len = ssid->datalen;
3341 skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
3342 (u32) -1, cbss->channel,
3343 ssid->data, ssid_len,
3344 NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
3349 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
3351 static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
3352 const u8 *buf, size_t len, bool tx,
3353 u16 reason, bool reconnect)
3355 struct ieee80211_event event = {
3357 .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
3358 .u.mlme.reason = reason,
3362 cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
3364 cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
3366 drv_event_callback(sdata->local, sdata, &event);
3369 static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
3371 struct ieee80211_local *local = sdata->local;
3372 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3373 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
3376 lockdep_assert_wiphy(local->hw.wiphy);
3378 if (!ifmgd->associated)
3381 /* in MLO assume we have a link where we can TX the frame */
3382 tx = ieee80211_vif_is_mld(&sdata->vif) ||
3383 !sdata->deflink.csa_block_tx;
3385 if (!ifmgd->driver_disconnect) {
3386 unsigned int link_id;
3389 * AP is probably out of range (or not reachable for another
3390 * reason) so remove the bss structs for that AP. In the case
3391 * of multi-link, it's not clear that all of them really are
3392 * out of range, but if they weren't the driver likely would
3393 * have switched to just have a single link active?
3396 link_id < ARRAY_SIZE(sdata->link);
3398 struct ieee80211_link_data *link;
3400 link = sdata_dereference(sdata->link[link_id], sdata);
3403 cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
3404 link->u.mgd.bss = NULL;
3408 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
3409 ifmgd->driver_disconnect ?
3410 WLAN_REASON_DEAUTH_LEAVING :
3411 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3413 /* the other links will be destroyed */
3414 sdata->vif.bss_conf.csa_active = false;
3415 sdata->deflink.u.mgd.csa_waiting_bcn = false;
3416 if (sdata->deflink.csa_block_tx) {
3417 ieee80211_wake_vif_queues(local, sdata,
3418 IEEE80211_QUEUE_STOP_REASON_CSA);
3419 sdata->deflink.csa_block_tx = false;
3422 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
3423 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
3425 ifmgd->reconnect = false;
3428 static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
3429 struct wiphy_work *work)
3431 struct ieee80211_sub_if_data *sdata =
3432 container_of(work, struct ieee80211_sub_if_data,
3433 u.mgd.beacon_connection_loss_work);
3434 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3436 if (ifmgd->connection_loss) {
3437 sdata_info(sdata, "Connection to AP %pM lost\n",
3438 sdata->vif.cfg.ap_addr);
3439 __ieee80211_disconnect(sdata);
3440 ifmgd->connection_loss = false;
3441 } else if (ifmgd->driver_disconnect) {
3443 "Driver requested disconnection from AP %pM\n",
3444 sdata->vif.cfg.ap_addr);
3445 __ieee80211_disconnect(sdata);
3446 ifmgd->driver_disconnect = false;
3448 if (ifmgd->associated)
3449 sdata->deflink.u.mgd.beacon_loss_count++;
3450 ieee80211_mgd_probe_ap(sdata, true);
3454 static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
3455 struct wiphy_work *work)
3457 struct ieee80211_sub_if_data *sdata =
3458 container_of(work, struct ieee80211_sub_if_data,
3459 u.mgd.csa_connection_drop_work);
3461 __ieee80211_disconnect(sdata);
3464 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
3466 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3467 struct ieee80211_hw *hw = &sdata->local->hw;
3469 trace_api_beacon_loss(sdata);
3471 sdata->u.mgd.connection_loss = false;
3472 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3474 EXPORT_SYMBOL(ieee80211_beacon_loss);
3476 void ieee80211_connection_loss(struct ieee80211_vif *vif)
3478 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3479 struct ieee80211_hw *hw = &sdata->local->hw;
3481 trace_api_connection_loss(sdata);
3483 sdata->u.mgd.connection_loss = true;
3484 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3486 EXPORT_SYMBOL(ieee80211_connection_loss);
3488 void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
3490 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3491 struct ieee80211_hw *hw = &sdata->local->hw;
3493 trace_api_disconnect(sdata, reconnect);
3495 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
3498 sdata->u.mgd.driver_disconnect = true;
3499 sdata->u.mgd.reconnect = reconnect;
3500 wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
3502 EXPORT_SYMBOL(ieee80211_disconnect);
3504 static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
3507 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3509 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3513 * we are not authenticated yet, the only timer that could be
3514 * running is the timeout for the authentication response which
3515 * which is not relevant anymore.
3517 del_timer_sync(&sdata->u.mgd.timer);
3518 sta_info_destroy_addr(sdata, auth_data->ap_addr);
3520 /* other links are destroyed */
3521 sdata->deflink.u.mgd.conn_flags = 0;
3522 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3523 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3525 sdata->u.mgd.flags = 0;
3527 ieee80211_link_release_channel(&sdata->deflink);
3528 ieee80211_vif_set_links(sdata, 0, 0);
3531 cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
3533 sdata->u.mgd.auth_data = NULL;
3543 static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
3544 enum assoc_status status)
3546 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
3548 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3550 if (status != ASSOC_SUCCESS) {
3552 * we are not associated yet, the only timer that could be
3553 * running is the timeout for the association response which
3554 * which is not relevant anymore.
3556 del_timer_sync(&sdata->u.mgd.timer);
3557 sta_info_destroy_addr(sdata, assoc_data->ap_addr);
3559 sdata->deflink.u.mgd.conn_flags = 0;
3560 eth_zero_addr(sdata->deflink.u.mgd.bssid);
3561 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
3563 sdata->u.mgd.flags = 0;
3564 sdata->vif.bss_conf.mu_mimo_owner = false;
3566 if (status != ASSOC_REJECTED) {
3567 struct cfg80211_assoc_failure data = {
3568 .timeout = status == ASSOC_TIMEOUT,
3572 BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
3573 ARRAY_SIZE(assoc_data->link));
3575 for (i = 0; i < ARRAY_SIZE(data.bss); i++)
3576 data.bss[i] = assoc_data->link[i].bss;
3578 if (ieee80211_vif_is_mld(&sdata->vif))
3579 data.ap_mld_addr = assoc_data->ap_addr;
3581 cfg80211_assoc_failure(sdata->dev, &data);
3584 ieee80211_link_release_channel(&sdata->deflink);
3585 ieee80211_vif_set_links(sdata, 0, 0);
3589 sdata->u.mgd.assoc_data = NULL;
3592 static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
3593 struct ieee80211_mgmt *mgmt, size_t len)
3595 struct ieee80211_local *local = sdata->local;
3596 struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
3597 const struct element *challenge;
3600 struct ieee80211_prep_tx_info info = {
3601 .subtype = IEEE80211_STYPE_AUTH,
3602 .link_id = auth_data->link_id,
3605 pos = mgmt->u.auth.variable;
3606 challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
3607 len - (pos - (u8 *)mgmt));
3610 auth_data->expected_transaction = 4;
3611 drv_mgd_prepare_tx(sdata->local, sdata, &info);
3612 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
3613 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
3614 IEEE80211_TX_INTFL_MLME_CONN_TX;
3615 ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
3617 challenge->datalen + sizeof(*challenge),
3618 auth_data->ap_addr, auth_data->ap_addr,
3619 auth_data->key, auth_data->key_len,
3620 auth_data->key_idx, tx_flags);
3623 static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
3625 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3626 const u8 *ap_addr = ifmgd->auth_data->ap_addr;
3627 struct sta_info *sta;
3629 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3631 sdata_info(sdata, "authenticated\n");
3632 ifmgd->auth_data->done = true;
3633 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
3634 ifmgd->auth_data->timeout_started = true;
3635 run_again(sdata, ifmgd->auth_data->timeout);
3637 /* move station state to auth */
3638 sta = sta_info_get(sdata, ap_addr);
3640 WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
3643 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
3644 sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
3651 static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
3652 struct ieee80211_mgmt *mgmt, size_t len)
3654 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3655 u16 auth_alg, auth_transaction, status_code;
3656 struct ieee80211_event event = {
3658 .u.mlme.data = AUTH_EVENT,
3660 struct ieee80211_prep_tx_info info = {
3661 .subtype = IEEE80211_STYPE_AUTH,
3664 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3669 if (!ifmgd->auth_data || ifmgd->auth_data->done)
3672 if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
3675 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
3676 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
3677 status_code = le16_to_cpu(mgmt->u.auth.status_code);
3679 if (auth_alg != ifmgd->auth_data->algorithm ||
3680 (auth_alg != WLAN_AUTH_SAE &&
3681 auth_transaction != ifmgd->auth_data->expected_transaction) ||
3682 (auth_alg == WLAN_AUTH_SAE &&
3683 (auth_transaction < ifmgd->auth_data->expected_transaction ||
3684 auth_transaction > 2))) {
3685 sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
3686 mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
3688 ifmgd->auth_data->expected_transaction);
3692 if (status_code != WLAN_STATUS_SUCCESS) {
3693 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3695 if (auth_alg == WLAN_AUTH_SAE &&
3696 (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
3697 (auth_transaction == 1 &&
3698 (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
3699 status_code == WLAN_STATUS_SAE_PK)))) {
3700 /* waiting for userspace now */
3701 ifmgd->auth_data->waiting = true;
3702 ifmgd->auth_data->timeout =
3703 jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
3704 ifmgd->auth_data->timeout_started = true;
3705 run_again(sdata, ifmgd->auth_data->timeout);
3709 sdata_info(sdata, "%pM denied authentication (status %d)\n",
3710 mgmt->sa, status_code);
3711 ieee80211_destroy_auth_data(sdata, false);
3712 event.u.mlme.status = MLME_DENIED;
3713 event.u.mlme.reason = status_code;
3714 drv_event_callback(sdata->local, sdata, &event);
3718 switch (ifmgd->auth_data->algorithm) {
3719 case WLAN_AUTH_OPEN:
3720 case WLAN_AUTH_LEAP:
3723 case WLAN_AUTH_FILS_SK:
3724 case WLAN_AUTH_FILS_SK_PFS:
3725 case WLAN_AUTH_FILS_PK:
3727 case WLAN_AUTH_SHARED_KEY:
3728 if (ifmgd->auth_data->expected_transaction != 4) {
3729 ieee80211_auth_challenge(sdata, mgmt, len);
3730 /* need another frame */
3735 WARN_ONCE(1, "invalid auth alg %d",
3736 ifmgd->auth_data->algorithm);
3740 event.u.mlme.status = MLME_SUCCESS;
3742 drv_event_callback(sdata->local, sdata, &event);
3743 if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
3744 (auth_transaction == 2 &&
3745 ifmgd->auth_data->expected_transaction == 2)) {
3746 if (!ieee80211_mark_sta_auth(sdata))
3747 return; /* ignore frame -- wait for timeout */
3748 } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
3749 auth_transaction == 2) {
3750 sdata_info(sdata, "SAE peer confirmed\n");
3751 ifmgd->auth_data->peer_confirmed = true;
3754 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3756 drv_mgd_complete_tx(sdata->local, sdata, &info);
3759 #define case_WLAN(type) \
3760 case WLAN_REASON_##type: return #type
3762 const char *ieee80211_get_reason_code_string(u16 reason_code)
3764 switch (reason_code) {
3765 case_WLAN(UNSPECIFIED);
3766 case_WLAN(PREV_AUTH_NOT_VALID);
3767 case_WLAN(DEAUTH_LEAVING);
3768 case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
3769 case_WLAN(DISASSOC_AP_BUSY);
3770 case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
3771 case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
3772 case_WLAN(DISASSOC_STA_HAS_LEFT);
3773 case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
3774 case_WLAN(DISASSOC_BAD_POWER);
3775 case_WLAN(DISASSOC_BAD_SUPP_CHAN);
3776 case_WLAN(INVALID_IE);
3777 case_WLAN(MIC_FAILURE);
3778 case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
3779 case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
3780 case_WLAN(IE_DIFFERENT);
3781 case_WLAN(INVALID_GROUP_CIPHER);
3782 case_WLAN(INVALID_PAIRWISE_CIPHER);
3783 case_WLAN(INVALID_AKMP);
3784 case_WLAN(UNSUPP_RSN_VERSION);
3785 case_WLAN(INVALID_RSN_IE_CAP);
3786 case_WLAN(IEEE8021X_FAILED);
3787 case_WLAN(CIPHER_SUITE_REJECTED);
3788 case_WLAN(DISASSOC_UNSPECIFIED_QOS);
3789 case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
3790 case_WLAN(DISASSOC_LOW_ACK);
3791 case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
3792 case_WLAN(QSTA_LEAVE_QBSS);
3793 case_WLAN(QSTA_NOT_USE);
3794 case_WLAN(QSTA_REQUIRE_SETUP);
3795 case_WLAN(QSTA_TIMEOUT);
3796 case_WLAN(QSTA_CIPHER_NOT_SUPP);
3797 case_WLAN(MESH_PEER_CANCELED);
3798 case_WLAN(MESH_MAX_PEERS);
3799 case_WLAN(MESH_CONFIG);
3800 case_WLAN(MESH_CLOSE);
3801 case_WLAN(MESH_MAX_RETRIES);
3802 case_WLAN(MESH_CONFIRM_TIMEOUT);
3803 case_WLAN(MESH_INVALID_GTK);
3804 case_WLAN(MESH_INCONSISTENT_PARAM);
3805 case_WLAN(MESH_INVALID_SECURITY);
3806 case_WLAN(MESH_PATH_ERROR);
3807 case_WLAN(MESH_PATH_NOFORWARD);
3808 case_WLAN(MESH_PATH_DEST_UNREACHABLE);
3809 case_WLAN(MAC_EXISTS_IN_MBSS);
3810 case_WLAN(MESH_CHAN_REGULATORY);
3811 case_WLAN(MESH_CHAN);
3812 default: return "<unknown>";
3816 static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
3817 struct ieee80211_mgmt *mgmt, size_t len)
3819 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3820 u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
3822 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3827 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3828 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3832 if (ifmgd->associated &&
3833 ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
3834 sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
3835 sdata->vif.cfg.ap_addr, reason_code,
3836 ieee80211_get_reason_code_string(reason_code));
3838 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3840 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
3841 reason_code, false);
3845 if (ifmgd->assoc_data &&
3846 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
3848 "deauthenticated from %pM while associating (Reason: %u=%s)\n",
3849 ifmgd->assoc_data->ap_addr, reason_code,
3850 ieee80211_get_reason_code_string(reason_code));
3852 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
3854 cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
3860 static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
3861 struct ieee80211_mgmt *mgmt, size_t len)
3863 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3866 lockdep_assert_wiphy(sdata->local->hw.wiphy);
3871 if (!ifmgd->associated ||
3872 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
3875 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
3877 if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
3878 ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
3882 sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
3883 sdata->vif.cfg.ap_addr, reason_code,
3884 ieee80211_get_reason_code_string(reason_code));
3886 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3888 ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
3892 static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
3893 u8 *supp_rates, unsigned int supp_rates_len,
3894 u32 *rates, u32 *basic_rates,
3895 bool *have_higher_than_11mbit,
3896 int *min_rate, int *min_rate_index)
3900 for (i = 0; i < supp_rates_len; i++) {
3901 int rate = supp_rates[i] & 0x7f;
3902 bool is_basic = !!(supp_rates[i] & 0x80);
3904 if ((rate * 5) > 110)
3905 *have_higher_than_11mbit = true;
3908 * Skip HT, VHT, HE, EHT and SAE H2E only BSS membership
3909 * selectors since they're not rates.
3911 * Note: Even though the membership selector and the basic
3912 * rate flag share the same bit, they are not exactly
3915 if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
3916 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
3917 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
3918 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_EHT_PHY) ||
3919 supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
3922 for (j = 0; j < sband->n_bitrates; j++) {
3923 struct ieee80211_rate *br;
3926 br = &sband->bitrates[j];
3928 brate = DIV_ROUND_UP(br->bitrate, 5);
3929 if (brate == rate) {
3932 *basic_rates |= BIT(j);
3933 if ((rate * 5) < *min_rate) {
3934 *min_rate = rate * 5;
3935 *min_rate_index = j;
3943 static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
3944 struct ieee80211_supported_band *sband,
3945 const struct link_sta_info *link_sta,
3946 const struct ieee802_11_elems *elems)
3948 const struct ieee80211_sta_he_cap *own_he_cap =
3949 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3951 if (elems->ext_capab_len < 10)
3954 if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
3957 return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
3958 IEEE80211_HE_MAC_CAP0_TWT_RES &&
3960 (own_he_cap->he_cap_elem.mac_cap_info[0] &
3961 IEEE80211_HE_MAC_CAP0_TWT_REQ);
3964 static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
3965 struct ieee80211_supported_band *sband,
3966 struct ieee80211_link_data *link,
3967 struct link_sta_info *link_sta,
3968 struct ieee802_11_elems *elems)
3970 bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
3972 if (link->conf->twt_requester != twt) {
3973 link->conf->twt_requester = twt;
3974 return BSS_CHANGED_TWT;
3979 static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
3980 struct ieee80211_bss_conf *bss_conf,
3981 struct ieee80211_supported_band *sband,
3982 struct link_sta_info *link_sta)
3984 const struct ieee80211_sta_he_cap *own_he_cap =
3985 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
3987 return bss_conf->he_support &&
3988 (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
3989 IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
3991 (own_he_cap->he_cap_elem.mac_cap_info[2] &
3992 IEEE80211_HE_MAC_CAP2_BCAST_TWT);
3995 static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
3996 struct link_sta_info *link_sta,
3997 struct cfg80211_bss *cbss,
3998 struct ieee80211_mgmt *mgmt,
3999 const u8 *elem_start,
4000 unsigned int elem_len,
4003 struct ieee80211_sub_if_data *sdata = link->sdata;
4004 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
4005 struct ieee80211_bss_conf *bss_conf = link->conf;
4006 struct ieee80211_local *local = sdata->local;
4007 unsigned int link_id = link->link_id;
4008 struct ieee80211_elems_parse_params parse_params = {
4009 .start = elem_start,
4011 .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
4014 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4015 bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
4016 const struct cfg80211_bss_ies *bss_ies = NULL;
4017 struct ieee80211_supported_band *sband;
4018 struct ieee802_11_elems *elems;
4019 const __le16 prof_bss_param_ch_present =
4020 cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT);
4024 elems = ieee802_11_parse_elems_full(&parse_params);
4028 if (link_id == assoc_data->assoc_link_id) {
4029 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
4032 * we should not get to this flow unless the association was
4033 * successful, so set the status directly to success
4035 assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
4036 if (elems->ml_basic) {
4037 if (!(elems->ml_basic->control &
4038 cpu_to_le16(IEEE80211_MLC_BASIC_PRES_BSS_PARAM_CH_CNT))) {
4042 link->u.mgd.bss_param_ch_cnt =
4043 ieee80211_mle_get_bss_param_ch_cnt(elems->ml_basic);
4045 } else if (!elems->prof ||
4046 !(elems->prof->control & prof_bss_param_ch_present)) {
4050 const u8 *ptr = elems->prof->variable +
4051 elems->prof->sta_info_len - 1;
4054 * During parsing, we validated that these fields exist,
4055 * otherwise elems->prof would have been set to NULL.
4057 capab_info = get_unaligned_le16(ptr);
4058 assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
4059 link->u.mgd.bss_param_ch_cnt =
4060 ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof);
4062 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
4063 link_info(link, "association response status code=%u\n",
4064 assoc_data->link[link_id].status);
4070 if (!is_s1g && !elems->supp_rates) {
4071 sdata_info(sdata, "no SuppRates element in AssocResp\n");
4076 link->u.mgd.tdls_chan_switch_prohibited =
4077 elems->ext_capab && elems->ext_capab_len >= 5 &&
4078 (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
4081 * Some APs are erroneously not including some information in their
4082 * (re)association response frames. Try to recover by using the data
4083 * from the beacon or probe response. This seems to afflict mobile
4084 * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
4085 * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
4088 ((assoc_data->wmm && !elems->wmm_param) ||
4089 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4090 (!elems->ht_cap_elem || !elems->ht_operation)) ||
4091 (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4092 (!elems->vht_cap_elem || !elems->vht_operation)))) {
4093 const struct cfg80211_bss_ies *ies;
4094 struct ieee802_11_elems *bss_elems;
4097 ies = rcu_dereference(cbss->ies);
4099 bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
4107 parse_params.start = bss_ies->data;
4108 parse_params.len = bss_ies->len;
4109 parse_params.bss = cbss;
4110 bss_elems = ieee802_11_parse_elems_full(&parse_params);
4116 if (assoc_data->wmm &&
4117 !elems->wmm_param && bss_elems->wmm_param) {
4118 elems->wmm_param = bss_elems->wmm_param;
4120 "AP bug: WMM param missing from AssocResp\n");
4124 * Also check if we requested HT/VHT, otherwise the AP doesn't
4125 * have to include the IEs in the (re)association response.
4127 if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
4128 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4129 elems->ht_cap_elem = bss_elems->ht_cap_elem;
4131 "AP bug: HT capability missing from AssocResp\n");
4133 if (!elems->ht_operation && bss_elems->ht_operation &&
4134 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
4135 elems->ht_operation = bss_elems->ht_operation;
4137 "AP bug: HT operation missing from AssocResp\n");
4139 if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
4140 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4141 elems->vht_cap_elem = bss_elems->vht_cap_elem;
4143 "AP bug: VHT capa missing from AssocResp\n");
4145 if (!elems->vht_operation && bss_elems->vht_operation &&
4146 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4147 elems->vht_operation = bss_elems->vht_operation;
4149 "AP bug: VHT operation missing from AssocResp\n");
4156 * We previously checked these in the beacon/probe response, so
4157 * they should be present here. This is just a safety net.
4159 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
4160 (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
4162 "HT AP is missing WMM params or HT capability/operation\n");
4167 if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
4168 (!elems->vht_cap_elem || !elems->vht_operation)) {
4170 "VHT AP is missing VHT capability/operation\n");
4175 if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4176 !elems->he_6ghz_capa) {
4178 "HE 6 GHz AP is missing HE 6 GHz band capability\n");
4183 if (WARN_ON(!link->conf->chandef.chan)) {
4187 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
4189 if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4190 (!elems->he_cap || !elems->he_operation)) {
4192 "HE AP is missing HE capability/operation\n");
4197 /* Set up internal HT/VHT capabilities */
4198 if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
4199 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
4203 if (elems->vht_cap_elem &&
4204 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
4205 const struct ieee80211_vht_cap *bss_vht_cap = NULL;
4206 const struct cfg80211_bss_ies *ies;
4209 * Cisco AP module 9115 with FW 17.3 has a bug and sends a
4210 * too large maximum MPDU length in the association response
4211 * (indicating 12k) that it cannot actually process ...
4215 ies = rcu_dereference(cbss->ies);
4217 const struct element *elem;
4219 elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
4220 ies->data, ies->len);
4221 if (elem && elem->datalen >= sizeof(*bss_vht_cap))
4222 bss_vht_cap = (const void *)elem->data;
4225 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
4226 elems->vht_cap_elem,
4227 bss_vht_cap, link_sta);
4231 if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
4233 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
4236 elems->he_6ghz_capa,
4239 bss_conf->he_support = link_sta->pub->he_cap.has_he;
4240 if (elems->rsnx && elems->rsnx_len &&
4241 (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
4242 wiphy_ext_feature_isset(local->hw.wiphy,
4243 NL80211_EXT_FEATURE_PROTECTED_TWT))
4244 bss_conf->twt_protected = true;
4246 bss_conf->twt_protected = false;
4248 *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
4251 if (elems->eht_operation && elems->eht_cap &&
4252 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
4253 ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
4260 bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
4261 *changed |= BSS_CHANGED_EHT_PUNCTURING;
4263 bss_conf->eht_support = false;
4266 bss_conf->he_support = false;
4267 bss_conf->twt_requester = false;
4268 bss_conf->twt_protected = false;
4269 bss_conf->eht_support = false;
4272 bss_conf->twt_broadcast =
4273 ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
4275 if (bss_conf->he_support) {
4276 bss_conf->he_bss_color.color =
4277 le32_get_bits(elems->he_operation->he_oper_params,
4278 IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
4279 bss_conf->he_bss_color.partial =
4280 le32_get_bits(elems->he_operation->he_oper_params,
4281 IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
4282 bss_conf->he_bss_color.enabled =
4283 !le32_get_bits(elems->he_operation->he_oper_params,
4284 IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
4286 if (bss_conf->he_bss_color.enabled)
4287 *changed |= BSS_CHANGED_HE_BSS_COLOR;
4289 bss_conf->htc_trig_based_pkt_ext =
4290 le32_get_bits(elems->he_operation->he_oper_params,
4291 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
4292 bss_conf->frame_time_rts_th =
4293 le32_get_bits(elems->he_operation->he_oper_params,
4294 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
4296 bss_conf->uora_exists = !!elems->uora_element;
4297 if (elems->uora_element)
4298 bss_conf->uora_ocw_range = elems->uora_element[0];
4300 ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
4301 ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
4302 /* TODO: OPEN: what happens if BSS color disable is set? */
4305 if (cbss->transmitted_bss) {
4306 bss_conf->nontransmitted = true;
4307 ether_addr_copy(bss_conf->transmitter_bssid,
4308 cbss->transmitted_bss->bssid);
4309 bss_conf->bssid_indicator = cbss->max_bssid_indicator;
4310 bss_conf->bssid_index = cbss->bssid_index;
4314 * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
4315 * in their association response, so ignore that data for our own
4316 * configuration. If it changed since the last beacon, we'll get the
4317 * next beacon and update then.
4321 * If an operating mode notification IE is present, override the
4322 * NSS calculation (that would be done in rate_control_rate_init())
4323 * and use the # of streams from that element.
4325 if (elems->opmode_notif &&
4326 !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
4329 nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
4330 nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
4332 link_sta->pub->rx_nss = nss;
4336 * Always handle WMM once after association regardless
4337 * of the first value the AP uses. Setting -1 here has
4338 * that effect because the AP values is an unsigned
4341 link->u.mgd.wmm_last_param_set = -1;
4342 link->u.mgd.mu_edca_last_param_set = -1;
4344 if (link->u.mgd.disable_wmm_tracking) {
4345 ieee80211_set_wmm_default(link, false, false);
4346 } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
4347 elems->wmm_param_len,
4348 elems->mu_edca_param_set)) {
4349 /* still enable QoS since we might have HT/VHT */
4350 ieee80211_set_wmm_default(link, false, true);
4351 /* disable WMM tracking in this case to disable
4352 * tracking WMM parameter changes in the beacon if
4353 * the parameters weren't actually valid. Doing so
4354 * avoids changing parameters very strangely when
4355 * the AP is going back and forth between valid and
4356 * invalid parameters.
4358 link->u.mgd.disable_wmm_tracking = true;
4361 if (elems->max_idle_period_ie) {
4362 bss_conf->max_idle_period =
4363 le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
4364 bss_conf->protected_keep_alive =
4365 !!(elems->max_idle_period_ie->idle_options &
4366 WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
4367 *changed |= BSS_CHANGED_KEEP_ALIVE;
4369 bss_conf->max_idle_period = 0;
4370 bss_conf->protected_keep_alive = false;
4373 /* set assoc capability (AID was already set earlier),
4374 * ieee80211_set_associated() will tell the driver */
4375 bss_conf->assoc_capability = capab_info;
4384 static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
4385 struct sta_info *sta,
4386 struct link_sta_info *link_sta,
4387 struct cfg80211_bss *cbss)
4389 struct ieee80211_sub_if_data *sdata = link->sdata;
4390 struct ieee80211_local *local = sdata->local;
4391 struct ieee80211_bss *bss = (void *)cbss->priv;
4392 u32 rates = 0, basic_rates = 0;
4393 bool have_higher_than_11mbit = false;
4394 int min_rate = INT_MAX, min_rate_index = -1;
4395 struct ieee80211_supported_band *sband;
4397 memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
4398 memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
4400 /* TODO: S1G Basic Rate Set is expressed elsewhere */
4401 if (cbss->channel->band == NL80211_BAND_S1GHZ) {
4402 ieee80211_s1g_sta_rate_init(sta);
4406 sband = local->hw.wiphy->bands[cbss->channel->band];
4408 ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
4409 &rates, &basic_rates, &have_higher_than_11mbit,
4410 &min_rate, &min_rate_index);
4413 * This used to be a workaround for basic rates missing
4414 * in the association response frame. Now that we no
4415 * longer use the basic rates from there, it probably
4416 * doesn't happen any more, but keep the workaround so
4417 * in case some *other* APs are buggy in different ways
4418 * we can connect -- with a warning.
4419 * Allow this workaround only in case the AP provided at least
4422 if (min_rate_index < 0) {
4423 link_info(link, "No legacy rates in association response\n");
4425 } else if (!basic_rates) {
4426 link_info(link, "No basic rates, using min rate instead\n");
4427 basic_rates = BIT(min_rate_index);
4431 link_sta->pub->supp_rates[cbss->channel->band] = rates;
4433 link_info(link, "No rates found, keeping mandatory only\n");
4435 link->conf->basic_rates = basic_rates;
4437 /* cf. IEEE 802.11 9.2.12 */
4438 link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
4439 have_higher_than_11mbit;
4444 static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
4445 struct cfg80211_bss *cbss)
4447 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4448 const struct element *ht_cap_elem, *vht_cap_elem;
4449 const struct cfg80211_bss_ies *ies;
4450 const struct ieee80211_ht_cap *ht_cap;
4451 const struct ieee80211_vht_cap *vht_cap;
4452 const struct ieee80211_he_cap_elem *he_cap;
4453 const struct element *he_cap_elem;
4454 u16 mcs_80_map, mcs_160_map;
4455 int i, mcs_nss_size;
4459 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
4462 ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
4463 if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
4464 ht_cap = (void *)ht_cap_elem->data;
4465 chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
4467 * TODO: use "Tx Maximum Number Spatial Streams Supported" and
4468 * "Tx Unequal Modulation Supported" fields.
4472 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
4475 vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
4476 if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
4480 vht_cap = (void *)vht_cap_elem->data;
4481 tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
4482 for (nss = 8; nss > 0; nss--) {
4483 if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
4484 IEEE80211_VHT_MCS_NOT_SUPPORTED)
4487 /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
4488 chains = max(chains, nss);
4491 if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
4494 ies = rcu_dereference(cbss->ies);
4495 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4496 ies->data, ies->len);
4498 if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
4501 /* skip one byte ext_tag_id */
4502 he_cap = (void *)(he_cap_elem->data + 1);
4503 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4506 if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
4509 /* mcs_nss is right after he_cap info */
4510 he_mcs_nss_supp = (void *)(he_cap + 1);
4512 mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4514 for (i = 7; i >= 0; i--) {
4515 u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
4517 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4518 chains = max_t(u8, chains, i + 1);
4523 support_160 = he_cap->phy_cap_info[0] &
4524 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
4529 mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
4530 for (i = 7; i >= 0; i--) {
4531 u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
4533 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
4534 chains = max_t(u8, chains, i + 1);
4543 ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4544 const struct cfg80211_bss_ies *ies,
4545 const struct ieee80211_he_operation *he_op)
4547 const struct element *he_cap_elem;
4548 const struct ieee80211_he_cap_elem *he_cap;
4549 struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
4550 u16 mcs_80_map_tx, mcs_80_map_rx;
4555 he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
4556 ies->data, ies->len);
4562 if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
4564 "Invalid HE elem, Disable HE\n");
4568 /* skip one byte ext_tag_id */
4569 he_cap = (void *)(he_cap_elem->data + 1);
4570 mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
4573 if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
4575 "Invalid HE elem with nss size, Disable HE\n");
4579 /* mcs_nss is right after he_cap info */
4580 he_mcs_nss_supp = (void *)(he_cap + 1);
4582 mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
4583 mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
4585 /* P802.11-REVme/D0.3
4586 * 27.1.1 Introduction to the HE PHY
4588 * An HE STA shall support the following features:
4590 * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
4591 * supported channel widths for HE SU PPDUs
4593 if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4594 (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
4596 "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
4597 mcs_80_map_tx, mcs_80_map_rx);
4604 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4607 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4608 * zeroes, which is nonsense, and completely inconsistent with itself
4609 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4611 if (!ap_min_req_set)
4614 /* make sure the AP is consistent with itself
4616 * P802.11-REVme/D0.3
4617 * 26.17.1 Basic HE BSS operation
4619 * A STA that is operating in an HE BSS shall be able to receive and
4620 * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
4621 * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
4622 * MLME-START.request primitive and shall be able to receive at each of
4623 * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
4624 * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
4627 for (nss = 8; nss > 0; nss--) {
4628 u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4632 if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4635 ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
4636 ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
4638 if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4639 ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4640 ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
4642 "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
4643 nss, ap_rx_val, ap_rx_val, ap_op_val);
4652 ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
4653 struct ieee80211_supported_band *sband,
4654 const struct ieee80211_he_operation *he_op)
4656 const struct ieee80211_sta_he_cap *sta_he_cap =
4657 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4661 if (!sta_he_cap || !he_op)
4664 ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
4667 * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
4668 * zeroes, which is nonsense, and completely inconsistent with itself
4669 * (it doesn't have 8 streams). Accept the settings in this case anyway.
4671 if (!ap_min_req_set)
4674 /* Need to go over for 80MHz, 160MHz and for 80+80 */
4675 for (i = 0; i < 3; i++) {
4676 const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
4677 &sta_he_cap->he_mcs_nss_supp;
4678 u16 sta_mcs_map_rx =
4679 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
4680 u16 sta_mcs_map_tx =
4681 le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
4683 bool verified = true;
4686 * For each band there is a maximum of 8 spatial streams
4687 * possible. Each of the sta_mcs_map_* is a 16-bit struct built
4688 * of 2 bits per NSS (1-8), with the values defined in enum
4689 * ieee80211_he_mcs_support. Need to make sure STA TX and RX
4690 * capabilities aren't less than the AP's minimum requirements
4691 * for this HE BSS per SS.
4692 * It is enough to find one such band that meets the reqs.
4694 for (nss = 8; nss > 0; nss--) {
4695 u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
4696 u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
4697 u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
4699 if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
4703 * Make sure the HE AP doesn't require MCSs that aren't
4704 * supported by the client as required by spec
4706 * P802.11-REVme/D0.3
4707 * 26.17.1 Basic HE BSS operation
4709 * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
4710 * a BSS, unless it supports (i.e., is able to both transmit and
4711 * receive using) all of the <HE-MCS, NSS> tuples in the basic
4712 * HE-MCS and NSS set.
4714 if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4715 sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
4716 (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
4726 /* If here, STA doesn't meet AP's HE min requirements */
4731 ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap,
4732 const struct ieee80211_sta_eht_cap *sta_eht_cap,
4733 unsigned int idx, int bw)
4735 u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0];
4736 u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0];
4738 /* handle us being a 20 MHz-only EHT STA - with four values
4739 * for MCS 0-7, 8-9, 10-11, 12-13.
4741 if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL))
4742 return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx];
4744 /* the others have MCS 0-9 together, rather than separately from 0-7 */
4750 return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx];
4753 (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4754 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)))
4755 return 0xff; /* pass check */
4756 return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx];
4758 if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ))
4759 return 0xff; /* pass check */
4760 return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx];
4768 ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata,
4769 struct ieee80211_supported_band *sband,
4770 const struct ieee80211_eht_operation *eht_op)
4772 const struct ieee80211_sta_he_cap *sta_he_cap =
4773 ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
4774 const struct ieee80211_sta_eht_cap *sta_eht_cap =
4775 ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
4776 const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req;
4779 if (!sta_he_cap || !sta_eht_cap || !eht_op)
4782 req = &eht_op->basic_mcs_nss;
4784 for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) {
4785 u8 req_rx_nss, req_tx_nss;
4788 req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4789 IEEE80211_EHT_MCS_NSS_RX);
4790 req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i],
4791 IEEE80211_EHT_MCS_NSS_TX);
4793 for (bw = 0; bw < 3; bw++) {
4794 u8 have, have_rx_nss, have_tx_nss;
4796 have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap,
4799 have_rx_nss = u8_get_bits(have,
4800 IEEE80211_EHT_MCS_NSS_RX);
4801 have_tx_nss = u8_get_bits(have,
4802 IEEE80211_EHT_MCS_NSS_TX);
4804 if (req_rx_nss > have_rx_nss ||
4805 req_tx_nss > have_tx_nss)
4813 static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
4814 struct ieee80211_link_data *link,
4815 struct cfg80211_bss *cbss,
4817 ieee80211_conn_flags_t *conn_flags)
4819 struct ieee80211_local *local = sdata->local;
4820 const struct ieee80211_ht_cap *ht_cap = NULL;
4821 const struct ieee80211_ht_operation *ht_oper = NULL;
4822 const struct ieee80211_vht_operation *vht_oper = NULL;
4823 const struct ieee80211_he_operation *he_oper = NULL;
4824 const struct ieee80211_eht_operation *eht_oper = NULL;
4825 const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
4826 struct ieee80211_supported_band *sband;
4827 struct cfg80211_chan_def chandef;
4828 bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
4829 bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
4830 bool supports_mlo = false;
4831 struct ieee80211_bss *bss = (void *)cbss->priv;
4832 struct ieee80211_elems_parse_params parse_params = {
4836 struct ieee802_11_elems *elems;
4837 const struct cfg80211_bss_ies *ies;
4842 lockdep_assert_wiphy(local->hw.wiphy);
4846 ies = rcu_dereference(cbss->ies);
4847 parse_params.start = ies->data;
4848 parse_params.len = ies->len;
4849 elems = ieee802_11_parse_elems_full(&parse_params);
4855 sband = local->hw.wiphy->bands[cbss->channel->band];
4857 *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
4858 IEEE80211_CONN_DISABLE_80P80MHZ |
4859 IEEE80211_CONN_DISABLE_160MHZ);
4861 /* disable HT/VHT/HE if we don't support them */
4862 if (!sband->ht_cap.ht_supported && !is_6ghz) {
4863 mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
4864 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4865 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4866 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4867 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4870 if (!sband->vht_cap.vht_supported && is_5ghz) {
4871 mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
4872 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4873 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4874 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4877 if (!ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif)) {
4878 mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
4879 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4880 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4883 if (!ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif)) {
4884 mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
4885 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4888 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
4889 ht_oper = elems->ht_operation;
4890 ht_cap = elems->ht_cap_elem;
4893 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4898 if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
4899 vht_oper = elems->vht_operation;
4900 if (vht_oper && !ht_oper) {
4903 "AP advertised VHT without HT, disabling HT/VHT/HE\n");
4904 *conn_flags |= IEEE80211_CONN_DISABLE_HT;
4905 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4906 *conn_flags |= IEEE80211_CONN_DISABLE_HE;
4907 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4910 if (!elems->vht_cap_elem) {
4911 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
4916 if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
4917 he_oper = elems->he_operation;
4919 if (link && is_6ghz) {
4920 struct ieee80211_bss_conf *bss_conf;
4923 bss_conf = link->conf;
4925 if (elems->pwr_constr_elem)
4926 bss_conf->pwr_reduction = *elems->pwr_constr_elem;
4928 BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
4929 ARRAY_SIZE(elems->tx_pwr_env));
4931 for (i = 0; i < elems->tx_pwr_env_num; i++) {
4932 if (elems->tx_pwr_env_len[i] >
4933 sizeof(bss_conf->tx_pwr_env[j]))
4936 bss_conf->tx_pwr_env_num++;
4937 memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
4938 elems->tx_pwr_env_len[i]);
4943 if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
4944 !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
4945 *conn_flags |= IEEE80211_CONN_DISABLE_HE |
4946 IEEE80211_CONN_DISABLE_EHT;
4950 * EHT requires HE to be supported as well. Specifically for 6 GHz
4951 * channels, the operation channel information can only be deduced from
4952 * both the 6 GHz operation information (from the HE operation IE) and
4956 (IEEE80211_CONN_DISABLE_HE |
4957 IEEE80211_CONN_DISABLE_EHT)) &&
4959 const struct cfg80211_bss_ies *cbss_ies;
4960 const struct element *eht_ml_elem;
4961 const u8 *eht_oper_ie;
4963 cbss_ies = rcu_dereference(cbss->ies);
4964 eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
4965 cbss_ies->data, cbss_ies->len);
4966 if (eht_oper_ie && eht_oper_ie[1] >=
4967 1 + sizeof(struct ieee80211_eht_operation))
4968 eht_oper = (void *)(eht_oper_ie + 3);
4972 if (!ieee80211_verify_sta_eht_mcs_support(sdata, sband, eht_oper))
4973 *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
4975 eht_ml_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK,
4976 cbss_ies->data, cbss_ies->len);
4978 /* data + 1 / datalen - 1 since it's an extended element */
4979 if (!(*conn_flags & IEEE80211_CONN_DISABLE_EHT) &&
4981 ieee80211_mle_type_ok(eht_ml_elem->data + 1,
4982 IEEE80211_ML_CONTROL_TYPE_BASIC,
4983 eht_ml_elem->datalen - 1)) {
4984 supports_mlo = true;
4986 sdata->vif.cfg.eml_cap =
4987 ieee80211_mle_get_eml_cap(eht_ml_elem->data + 1);
4988 sdata->vif.cfg.eml_med_sync_delay =
4989 ieee80211_mle_get_eml_med_sync_delay(eht_ml_elem->data + 1);
4993 /* Allow VHT if at least one channel on the sband supports 80 MHz */
4995 for (i = 0; i < sband->n_channels; i++) {
4996 if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
4997 IEEE80211_CHAN_NO_80MHZ))
5005 sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
5006 *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
5009 if (sband->band == NL80211_BAND_S1GHZ) {
5010 s1g_oper = elems->s1g_oper;
5013 "AP missing S1G operation element?\n");
5017 ieee80211_determine_chantype(sdata, link, *conn_flags,
5027 link->needed_rx_chains =
5028 min(ieee80211_max_rx_chains(link, cbss),
5032 /* the element data was RCU protected so no longer valid anyway */
5036 if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
5037 sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
5041 if (mlo && !supports_mlo) {
5042 sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n");
5050 * If this fails (possibly due to channel context sharing
5051 * on incompatible channels, e.g. 80+80 and 160 sharing the
5052 * same control channel) try to use a smaller bandwidth.
5054 ret = ieee80211_link_use_channel(link, &chandef,
5055 IEEE80211_CHANCTX_SHARED);
5057 /* don't downgrade for 5 and 10 MHz channels, though. */
5058 if (chandef.width == NL80211_CHAN_WIDTH_5 ||
5059 chandef.width == NL80211_CHAN_WIDTH_10)
5062 while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
5064 ieee80211_chandef_downgrade(&chandef);
5065 ret = ieee80211_link_use_channel(link, &chandef,
5066 IEEE80211_CHANCTX_SHARED);
5072 static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
5073 u8 *dtim_count, u8 *dtim_period)
5075 const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
5076 const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
5078 const struct ieee80211_tim_ie *tim = NULL;
5079 const struct ieee80211_bssid_index *idx;
5080 bool valid = tim_ie && tim_ie[1] >= 2;
5083 tim = (void *)(tim_ie + 2);
5086 *dtim_count = valid ? tim->dtim_count : 0;
5089 *dtim_period = valid ? tim->dtim_period : 0;
5091 /* Check if value is overridden by non-transmitted profile */
5092 if (!idx_ie || idx_ie[1] < 3)
5095 idx = (void *)(idx_ie + 2);
5098 *dtim_count = idx->dtim_count;
5101 *dtim_period = idx->dtim_period;
5106 static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
5107 struct ieee80211_mgmt *mgmt,
5108 struct ieee802_11_elems *elems,
5109 const u8 *elem_start, unsigned int elem_len)
5111 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5112 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5113 struct ieee80211_local *local = sdata->local;
5114 unsigned int link_id;
5115 struct sta_info *sta;
5116 u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5117 u16 valid_links = 0, dormant_links = 0;
5120 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5122 * station info was already allocated and inserted before
5123 * the association and should be available to us
5125 sta = sta_info_get(sdata, assoc_data->ap_addr);
5129 if (ieee80211_vif_is_mld(&sdata->vif)) {
5130 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5131 if (!assoc_data->link[link_id].bss)
5134 valid_links |= BIT(link_id);
5135 if (assoc_data->link[link_id].disabled)
5136 dormant_links |= BIT(link_id);
5138 if (link_id != assoc_data->assoc_link_id) {
5139 err = ieee80211_sta_allocate_link(sta, link_id);
5145 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5148 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5149 struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
5150 struct ieee80211_link_data *link;
5151 struct link_sta_info *link_sta;
5156 link = sdata_dereference(sdata->link[link_id], sdata);
5160 if (ieee80211_vif_is_mld(&sdata->vif))
5162 "local address %pM, AP link address %pM%s\n",
5164 assoc_data->link[link_id].bss->bssid,
5165 link_id == assoc_data->assoc_link_id ?
5168 link_sta = rcu_dereference_protected(sta->link[link_id],
5169 lockdep_is_held(&local->hw.wiphy->mtx));
5170 if (WARN_ON(!link_sta))
5173 if (!link->u.mgd.have_beacon) {
5174 const struct cfg80211_bss_ies *ies;
5177 ies = rcu_dereference(cbss->beacon_ies);
5179 link->u.mgd.have_beacon = true;
5181 ies = rcu_dereference(cbss->ies);
5182 ieee80211_get_dtim(ies,
5183 &link->conf->sync_dtim_count,
5184 &link->u.mgd.dtim_period);
5185 link->conf->beacon_int = cbss->beacon_interval;
5189 link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
5191 if (link_id != assoc_data->assoc_link_id) {
5192 err = ieee80211_prep_channel(sdata, link, cbss, true,
5193 &link->u.mgd.conn_flags);
5195 link_info(link, "prep_channel failed\n");
5200 err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
5201 assoc_data->link[link_id].bss);
5205 if (!ieee80211_assoc_config_link(link, link_sta,
5206 assoc_data->link[link_id].bss,
5207 mgmt, elem_start, elem_len,
5211 if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
5212 valid_links &= ~BIT(link_id);
5213 ieee80211_sta_remove_link(sta, link_id);
5217 if (link_id != assoc_data->assoc_link_id) {
5218 err = ieee80211_sta_activate_link(sta, link_id);
5224 /* links might have changed due to rejected ones, set them again */
5225 ieee80211_vif_set_links(sdata, valid_links, dormant_links);
5227 rate_control_rate_init(sta);
5229 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
5230 set_sta_flag(sta, WLAN_STA_MFP);
5231 sta->sta.mfp = true;
5233 sta->sta.mfp = false;
5236 ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
5237 elems->ext_capab_len);
5239 sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
5240 local->hw.queues >= IEEE80211_NUM_ACS;
5242 err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
5243 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
5244 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
5247 "failed to move station %pM to desired state\n",
5249 WARN_ON(__sta_info_destroy(sta));
5253 if (sdata->wdev.use_4addr)
5254 drv_sta_set_4addr(local, sdata, &sta->sta, true);
5256 ieee80211_set_associated(sdata, assoc_data, changed);
5259 * If we're using 4-addr mode, let the AP know that we're
5260 * doing so, so that it can create the STA VLAN on its side
5262 if (ifmgd->use_4addr)
5263 ieee80211_send_4addr_nullfunc(local, sdata);
5266 * Start timer to probe the connection to the AP now.
5267 * Also start the timer that will detect beacon loss.
5269 ieee80211_sta_reset_beacon_monitor(sdata);
5270 ieee80211_sta_reset_conn_monitor(sdata);
5274 eth_zero_addr(sdata->vif.cfg.ap_addr);
5278 static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
5279 struct ieee80211_mgmt *mgmt,
5282 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
5283 struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
5284 u16 capab_info, status_code, aid;
5285 struct ieee80211_elems_parse_params parse_params = {
5290 struct ieee802_11_elems *elems;
5292 const u8 *elem_start;
5293 unsigned int elem_len;
5295 struct ieee80211_event event = {
5297 .u.mlme.data = ASSOC_EVENT,
5299 struct ieee80211_prep_tx_info info = {};
5300 struct cfg80211_rx_assoc_resp_data resp = {
5303 u8 ap_mld_addr[ETH_ALEN] __aligned(2);
5304 unsigned int link_id;
5306 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5311 if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
5312 !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
5316 * AssocResp and ReassocResp have identical structure, so process both
5317 * of them in this function.
5323 reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
5324 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
5325 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
5326 if (assoc_data->s1g)
5327 elem_start = mgmt->u.s1g_assoc_resp.variable;
5329 elem_start = mgmt->u.assoc_resp.variable;
5332 * Note: this may not be perfect, AP might misbehave - if
5333 * anyone needs to rely on perfect complete notification
5334 * with the exact right subtype, then we need to track what
5335 * we actually transmitted.
5337 info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
5338 IEEE80211_STYPE_ASSOC_REQ;
5340 if (assoc_data->fils_kek_len &&
5341 fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
5344 elem_len = len - (elem_start - (u8 *)mgmt);
5345 parse_params.start = elem_start;
5346 parse_params.len = elem_len;
5347 elems = ieee802_11_parse_elems_full(&parse_params);
5351 if (elems->aid_resp)
5352 aid = le16_to_cpu(elems->aid_resp->aid);
5353 else if (assoc_data->s1g)
5356 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
5359 * The 5 MSB of the AID field are reserved
5360 * (802.11-2016 9.4.1.8 AID field)
5365 "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
5366 reassoc ? "Rea" : "A", assoc_data->ap_addr,
5367 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
5369 ifmgd->broken_ap = false;
5371 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
5372 elems->timeout_int &&
5373 elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
5376 cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
5377 le32_to_cpu(elems->timeout_int->value));
5379 tu = le32_to_cpu(elems->timeout_int->value);
5380 ms = tu * 1024 / 1000;
5382 "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
5383 assoc_data->ap_addr, tu, ms);
5384 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
5385 assoc_data->timeout_started = true;
5386 assoc_data->comeback = true;
5387 if (ms > IEEE80211_ASSOC_TIMEOUT)
5388 run_again(sdata, assoc_data->timeout);
5392 if (status_code != WLAN_STATUS_SUCCESS) {
5393 sdata_info(sdata, "%pM denied association (code=%d)\n",
5394 assoc_data->ap_addr, status_code);
5395 event.u.mlme.status = MLME_DENIED;
5396 event.u.mlme.reason = status_code;
5397 drv_event_callback(sdata->local, sdata, &event);
5399 if (aid == 0 || aid > IEEE80211_MAX_AID) {
5401 "invalid AID value %d (out of range), turn off PS\n",
5404 ifmgd->broken_ap = true;
5407 if (ieee80211_vif_is_mld(&sdata->vif)) {
5408 struct ieee80211_mle_basic_common_info *common;
5410 if (!elems->ml_basic) {
5412 "MLO association with %pM but no (basic) multi-link element in response!\n",
5413 assoc_data->ap_addr);
5417 common = (void *)elems->ml_basic->variable;
5419 if (memcmp(assoc_data->ap_addr,
5420 common->mld_mac_addr, ETH_ALEN)) {
5422 "AP MLD MAC address mismatch: got %pM expected %pM\n",
5423 common->mld_mac_addr,
5424 assoc_data->ap_addr);
5429 sdata->vif.cfg.aid = aid;
5431 if (!ieee80211_assoc_success(sdata, mgmt, elems,
5432 elem_start, elem_len)) {
5433 /* oops -- internal error -- send timeout for now */
5434 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
5437 event.u.mlme.status = MLME_SUCCESS;
5438 drv_event_callback(sdata->local, sdata, &event);
5439 sdata_info(sdata, "associated\n");
5444 for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
5445 struct ieee80211_link_data *link;
5447 if (!assoc_data->link[link_id].bss)
5450 resp.links[link_id].bss = assoc_data->link[link_id].bss;
5451 ether_addr_copy(resp.links[link_id].addr,
5452 assoc_data->link[link_id].addr);
5453 resp.links[link_id].status = assoc_data->link[link_id].status;
5455 link = sdata_dereference(sdata->link[link_id], sdata);
5459 /* get uapsd queues configuration - same for all links */
5460 resp.uapsd_queues = 0;
5461 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
5462 if (link->tx_conf[ac].uapsd)
5463 resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
5466 if (ieee80211_vif_is_mld(&sdata->vif)) {
5467 ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
5468 resp.ap_mld_addr = ap_mld_addr;
5471 ieee80211_destroy_assoc_data(sdata,
5472 status_code == WLAN_STATUS_SUCCESS ?
5476 resp.buf = (u8 *)mgmt;
5478 resp.req_ies = ifmgd->assoc_req_ies;
5479 resp.req_ies_len = ifmgd->assoc_req_ies_len;
5480 cfg80211_rx_assoc_resp(sdata->dev, &resp);
5482 drv_mgd_complete_tx(sdata->local, sdata, &info);
5486 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
5490 static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
5491 struct ieee80211_mgmt *mgmt, size_t len,
5492 struct ieee80211_rx_status *rx_status)
5494 struct ieee80211_sub_if_data *sdata = link->sdata;
5495 struct ieee80211_local *local = sdata->local;
5496 struct ieee80211_bss *bss;
5497 struct ieee80211_channel *channel;
5499 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5501 channel = ieee80211_get_channel_khz(local->hw.wiphy,
5502 ieee80211_rx_status_to_khz(rx_status));
5506 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
5508 link->conf->beacon_rate = bss->beacon_rate;
5509 ieee80211_rx_bss_put(local, bss);
5514 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
5515 struct sk_buff *skb)
5517 struct ieee80211_sub_if_data *sdata = link->sdata;
5518 struct ieee80211_mgmt *mgmt = (void *)skb->data;
5519 struct ieee80211_if_managed *ifmgd;
5520 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
5521 struct ieee80211_channel *channel;
5522 size_t baselen, len = skb->len;
5524 ifmgd = &sdata->u.mgd;
5526 lockdep_assert_wiphy(sdata->local->hw.wiphy);
5529 * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
5530 * "If a 6 GHz AP receives a Probe Request frame and responds with
5531 * a Probe Response frame [..], the Address 1 field of the Probe
5532 * Response frame shall be set to the broadcast address [..]"
5533 * So, on 6GHz band we should also accept broadcast responses.
5535 channel = ieee80211_get_channel(sdata->local->hw.wiphy,
5540 if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
5541 (channel->band != NL80211_BAND_6GHZ ||
5542 !is_broadcast_ether_addr(mgmt->da)))
5543 return; /* ignore ProbeResp to foreign address */
5545 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
5549 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
5551 if (ifmgd->associated &&
5552 ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
5553 ieee80211_reset_ap_probe(sdata);
5557 * This is the canonical list of information elements we care about,
5558 * the filter code also gives us all changes to the Microsoft OUI
5559 * (00:50:F2) vendor IE which is used for WMM which we need to track,
5560 * as well as the DTPC IE (part of the Cisco OUI) used for signaling
5561 * changes to requested client power.
5563 * We implement beacon filtering in software since that means we can
5564 * avoid processing the frame here and in cfg80211, and userspace
5565 * will not be able to tell whether the hardware supports it or not.
5567 * XXX: This list needs to be dynamic -- userspace needs to be able to
5568 * add items it requires. It also needs to be able to tell us to
5569 * look out for other vendor IEs.
5571 static const u64 care_about_ies =
5572 (1ULL << WLAN_EID_COUNTRY) |
5573 (1ULL << WLAN_EID_ERP_INFO) |
5574 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
5575 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
5576 (1ULL << WLAN_EID_HT_CAPABILITY) |
5577 (1ULL << WLAN_EID_HT_OPERATION) |
5578 (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
5580 static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
5581 struct ieee80211_if_managed *ifmgd,
5582 struct ieee80211_bss_conf *bss_conf,
5583 struct ieee80211_local *local,
5584 struct ieee80211_rx_status *rx_status)
5586 struct ieee80211_sub_if_data *sdata = link->sdata;
5588 /* Track average RSSI from the Beacon frames of the current AP */
5590 if (!link->u.mgd.tracking_signal_avg) {
5591 link->u.mgd.tracking_signal_avg = true;
5592 ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
5593 link->u.mgd.last_cqm_event_signal = 0;
5594 link->u.mgd.count_beacon_signal = 1;
5595 link->u.mgd.last_ave_beacon_signal = 0;
5597 link->u.mgd.count_beacon_signal++;
5600 ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
5601 -rx_status->signal);
5603 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
5604 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5605 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5606 int last_sig = link->u.mgd.last_ave_beacon_signal;
5607 struct ieee80211_event event = {
5612 * if signal crosses either of the boundaries, invoke callback
5613 * with appropriate parameters
5615 if (sig > ifmgd->rssi_max_thold &&
5616 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
5617 link->u.mgd.last_ave_beacon_signal = sig;
5618 event.u.rssi.data = RSSI_EVENT_HIGH;
5619 drv_event_callback(local, sdata, &event);
5620 } else if (sig < ifmgd->rssi_min_thold &&
5621 (last_sig >= ifmgd->rssi_max_thold ||
5623 link->u.mgd.last_ave_beacon_signal = sig;
5624 event.u.rssi.data = RSSI_EVENT_LOW;
5625 drv_event_callback(local, sdata, &event);
5629 if (bss_conf->cqm_rssi_thold &&
5630 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
5631 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
5632 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5633 int last_event = link->u.mgd.last_cqm_event_signal;
5634 int thold = bss_conf->cqm_rssi_thold;
5635 int hyst = bss_conf->cqm_rssi_hyst;
5638 (last_event == 0 || sig < last_event - hyst)) {
5639 link->u.mgd.last_cqm_event_signal = sig;
5640 ieee80211_cqm_rssi_notify(
5642 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5644 } else if (sig > thold &&
5645 (last_event == 0 || sig > last_event + hyst)) {
5646 link->u.mgd.last_cqm_event_signal = sig;
5647 ieee80211_cqm_rssi_notify(
5649 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5654 if (bss_conf->cqm_rssi_low &&
5655 link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
5656 int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
5657 int last_event = link->u.mgd.last_cqm_event_signal;
5658 int low = bss_conf->cqm_rssi_low;
5659 int high = bss_conf->cqm_rssi_high;
5662 (last_event == 0 || last_event >= low)) {
5663 link->u.mgd.last_cqm_event_signal = sig;
5664 ieee80211_cqm_rssi_notify(
5666 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
5668 } else if (sig > high &&
5669 (last_event == 0 || last_event <= high)) {
5670 link->u.mgd.last_cqm_event_signal = sig;
5671 ieee80211_cqm_rssi_notify(
5673 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
5679 static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
5680 struct cfg80211_bss *bss)
5682 if (ether_addr_equal(tx_bssid, bss->bssid))
5684 if (!bss->transmitted_bss)
5686 return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
5689 static bool ieee80211_config_puncturing(struct ieee80211_link_data *link,
5690 const struct ieee80211_eht_operation *eht_oper,
5693 struct ieee80211_local *local = link->sdata->local;
5694 u16 bitmap = 0, extracted;
5696 if ((eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
5698 IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
5699 const struct ieee80211_eht_operation_info *info =
5700 (void *)eht_oper->optional;
5701 const u8 *disable_subchannel_bitmap = info->optional;
5703 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
5706 extracted = ieee80211_extract_dis_subch_bmap(eht_oper,
5707 &link->conf->chandef,
5710 /* accept if there are no changes */
5711 if (!(*changed & BSS_CHANGED_BANDWIDTH) &&
5712 extracted == link->conf->eht_puncturing)
5715 if (!cfg80211_valid_disable_subchannel_bitmap(&bitmap,
5716 &link->conf->chandef)) {
5718 "Got an invalid disable subchannel bitmap from AP %pM: bitmap = 0x%x, bw = 0x%x. disconnect\n",
5721 link->conf->chandef.width);
5725 if (bitmap && ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING))
5728 ieee80211_handle_puncturing_bitmap(link, eht_oper, bitmap, changed);
5732 static void ieee80211_ml_reconf_work(struct wiphy *wiphy,
5733 struct wiphy_work *work)
5735 struct ieee80211_sub_if_data *sdata =
5736 container_of(work, struct ieee80211_sub_if_data,
5737 u.mgd.ml_reconf_work.work);
5738 u16 new_valid_links, new_active_links, new_dormant_links;
5741 if (!sdata->u.mgd.removed_links)
5745 "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n",
5746 sdata->vif.valid_links, sdata->u.mgd.removed_links);
5748 new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links;
5749 if (new_valid_links == sdata->vif.valid_links)
5752 if (!new_valid_links ||
5753 !(new_valid_links & ~sdata->vif.dormant_links)) {
5754 sdata_info(sdata, "No valid links after reconfiguration\n");
5759 new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links;
5760 if (new_active_links != sdata->vif.active_links) {
5761 if (!new_active_links)
5763 BIT(ffs(new_valid_links &
5764 ~sdata->vif.dormant_links) - 1);
5766 ret = ieee80211_set_active_links(&sdata->vif, new_active_links);
5769 "Failed setting active links\n");
5774 new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links;
5776 ret = ieee80211_vif_set_links(sdata, new_valid_links,
5779 sdata_info(sdata, "Failed setting valid links\n");
5781 ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
5785 cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links);
5787 __ieee80211_disconnect(sdata);
5789 sdata->u.mgd.removed_links = 0;
5792 static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata,
5793 struct ieee802_11_elems *elems)
5795 const struct ieee80211_multi_link_elem *ml;
5796 const struct element *sub;
5798 unsigned long removed_links = 0;
5799 u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {};
5803 if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf)
5806 ml_len = cfg80211_defragment_element(elems->ml_reconf_elem,
5810 elems->scratch + elems->scratch_len -
5816 elems->ml_reconf = (const void *)elems->scratch_pos;
5817 elems->ml_reconf_len = ml_len;
5818 ml = elems->ml_reconf;
5820 /* Directly parse the sub elements as the common information doesn't
5821 * hold any useful information.
5823 for_each_mle_subelement(sub, (u8 *)ml, ml_len) {
5824 struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
5825 u8 *pos = prof->variable;
5828 if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
5831 if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data,
5835 control = le16_to_cpu(prof->control);
5836 link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID;
5838 removed_links |= BIT(link_id);
5840 /* the MAC address should not be included, but handle it */
5842 IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
5845 /* According to Draft P802.11be_D3.0, the control should
5846 * include the AP Removal Timer present. If the AP Removal Timer
5847 * is not present assume immediate removal.
5850 IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
5851 link_removal_timeout[link_id] = get_unaligned_le16(pos);
5854 removed_links &= sdata->vif.valid_links;
5855 if (!removed_links) {
5856 /* In case the removal was cancelled, abort it */
5857 if (sdata->u.mgd.removed_links) {
5858 sdata->u.mgd.removed_links = 0;
5859 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
5860 &sdata->u.mgd.ml_reconf_work);
5866 for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) {
5867 struct ieee80211_bss_conf *link_conf =
5868 sdata_dereference(sdata->vif.link_conf[link_id], sdata);
5872 removed_links &= ~BIT(link_id);
5876 if (link_removal_timeout[link_id] < 1)
5879 link_delay = link_conf->beacon_int *
5880 (link_removal_timeout[link_id] - 1);
5885 delay = min(delay, link_delay);
5888 sdata->u.mgd.removed_links = removed_links;
5889 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
5890 &sdata->u.mgd.ml_reconf_work,
5891 TU_TO_JIFFIES(delay));
5894 static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy,
5895 struct wiphy_work *work)
5897 u16 new_active_links, new_dormant_links;
5898 struct ieee80211_sub_if_data *sdata =
5899 container_of(work, struct ieee80211_sub_if_data,
5900 u.mgd.ttlm_work.work);
5903 new_active_links = sdata->u.mgd.ttlm_info.map &
5904 sdata->vif.valid_links;
5905 new_dormant_links = ~sdata->u.mgd.ttlm_info.map &
5906 sdata->vif.valid_links;
5907 if (!new_active_links) {
5908 ieee80211_disconnect(&sdata->vif, false);
5912 ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0);
5913 new_active_links = BIT(ffs(new_active_links) - 1);
5914 ieee80211_set_active_links(&sdata->vif, new_active_links);
5916 ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
5919 sdata->u.mgd.ttlm_info.active = true;
5920 sdata->u.mgd.ttlm_info.switch_time = 0;
5923 ieee80211_vif_cfg_change_notify(sdata,
5924 BSS_CHANGED_MLD_VALID_LINKS);
5927 static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data)
5932 return get_unaligned_le16(data);
5936 ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata,
5937 const struct ieee80211_ttlm_elem *ttlm,
5938 struct ieee80211_adv_ttlm_info *ttlm_info)
5940 /* The element size was already validated in
5941 * ieee80211_tid_to_link_map_size_ok()
5943 u8 control, link_map_presence, map_size, tid;
5946 memset(ttlm_info, 0, sizeof(*ttlm_info));
5947 pos = (void *)ttlm->optional;
5948 control = ttlm->control;
5950 if ((control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) ||
5951 !(control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT))
5954 if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) !=
5955 IEEE80211_TTLM_DIRECTION_BOTH) {
5956 sdata_info(sdata, "Invalid advertised T2L map direction\n");
5960 link_map_presence = *pos;
5963 ttlm_info->switch_time = get_unaligned_le16(pos);
5965 /* Since ttlm_info->switch_time == 0 means no switch time, bump it
5968 if (!ttlm_info->switch_time)
5969 ttlm_info->switch_time = 1;
5973 if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) {
5974 ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16;
5978 if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
5983 /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall
5984 * not advertise a TID-to-link mapping that does not map all TIDs to the
5985 * same link set, reject frame if not all links have mapping
5987 if (link_map_presence != 0xff) {
5989 "Invalid advertised T2L mapping presence indicator\n");
5993 ttlm_info->map = ieee80211_get_ttlm(map_size, pos);
5994 if (!ttlm_info->map) {
5996 "Invalid advertised T2L map for TID 0\n");
6002 for (tid = 1; tid < 8; tid++) {
6003 u16 map = ieee80211_get_ttlm(map_size, pos);
6005 if (map != ttlm_info->map) {
6006 sdata_info(sdata, "Invalid advertised T2L map for tid %d\n",
6016 static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata,
6017 struct ieee802_11_elems *elems,
6023 if (!ieee80211_vif_is_mld(&sdata->vif))
6026 if (!elems->ttlm_num) {
6027 if (sdata->u.mgd.ttlm_info.switch_time) {
6028 /* if a planned TID-to-link mapping was cancelled -
6031 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6032 &sdata->u.mgd.ttlm_work);
6033 } else if (sdata->u.mgd.ttlm_info.active) {
6034 /* if no TID-to-link element, set to default mapping in
6035 * which all TIDs are mapped to all setup links
6037 ret = ieee80211_vif_set_links(sdata,
6038 sdata->vif.valid_links,
6041 sdata_info(sdata, "Failed setting valid/dormant links\n");
6044 ieee80211_vif_cfg_change_notify(sdata,
6045 BSS_CHANGED_MLD_VALID_LINKS);
6047 memset(&sdata->u.mgd.ttlm_info, 0,
6048 sizeof(sdata->u.mgd.ttlm_info));
6052 for (i = 0; i < elems->ttlm_num; i++) {
6053 struct ieee80211_adv_ttlm_info ttlm_info;
6056 res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i],
6060 __ieee80211_disconnect(sdata);
6064 if (ttlm_info.switch_time) {
6065 u16 beacon_ts_tu, st_tu, delay;
6069 /* The t2l map switch time is indicated with a partial
6070 * TSF value (bits 10 to 25), get the partial beacon TS
6071 * as well, and calc the delay to the start time.
6073 mask = GENMASK_ULL(25, 10);
6074 beacon_ts_tu = (beacon_ts & mask) >> 10;
6075 st_tu = ttlm_info.switch_time;
6076 delay = st_tu - beacon_ts_tu;
6079 * If the switch time is far in the future, then it
6080 * could also be the previous switch still being
6082 * We can simply ignore it for now, if it is a future
6083 * switch the AP will continue to announce it anyway.
6085 if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW)
6088 delay_jiffies = TU_TO_JIFFIES(delay);
6090 /* Link switching can take time, so schedule it
6091 * 100ms before to be ready on time
6093 if (delay_jiffies > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS)
6095 IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS;
6099 sdata->u.mgd.ttlm_info = ttlm_info;
6100 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
6101 &sdata->u.mgd.ttlm_work);
6102 wiphy_delayed_work_queue(sdata->local->hw.wiphy,
6103 &sdata->u.mgd.ttlm_work,
6110 static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
6111 struct ieee80211_hdr *hdr, size_t len,
6112 struct ieee80211_rx_status *rx_status)
6114 struct ieee80211_sub_if_data *sdata = link->sdata;
6115 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6116 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
6117 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
6118 struct ieee80211_mgmt *mgmt = (void *) hdr;
6120 struct ieee802_11_elems *elems;
6121 struct ieee80211_local *local = sdata->local;
6122 struct ieee80211_chanctx_conf *chanctx_conf;
6123 struct ieee80211_supported_band *sband;
6124 struct ieee80211_channel *chan;
6125 struct link_sta_info *link_sta;
6126 struct sta_info *sta;
6131 u8 *bssid, *variable = mgmt->u.beacon.variable;
6132 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
6133 struct ieee80211_elems_parse_params parse_params = {
6138 lockdep_assert_wiphy(local->hw.wiphy);
6140 /* Process beacon from the current BSS */
6141 bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
6142 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
6143 struct ieee80211_ext *ext = (void *) mgmt;
6145 if (ieee80211_is_s1g_short_beacon(ext->frame_control))
6146 variable = ext->u.s1g_short_beacon.variable;
6148 variable = ext->u.s1g_beacon.variable;
6151 baselen = (u8 *) variable - (u8 *) mgmt;
6155 parse_params.start = variable;
6156 parse_params.len = len - baselen;
6159 chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
6160 if (!chanctx_conf) {
6165 if (ieee80211_rx_status_to_khz(rx_status) !=
6166 ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
6170 chan = chanctx_conf->def.chan;
6173 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
6174 !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) &&
6175 ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
6176 parse_params.bss = ifmgd->assoc_data->link[0].bss;
6177 elems = ieee802_11_parse_elems_full(&parse_params);
6181 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6183 if (elems->dtim_period)
6184 link->u.mgd.dtim_period = elems->dtim_period;
6185 link->u.mgd.have_beacon = true;
6186 ifmgd->assoc_data->need_beacon = false;
6187 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
6188 link->conf->sync_tsf =
6189 le64_to_cpu(mgmt->u.beacon.timestamp);
6190 link->conf->sync_device_ts =
6191 rx_status->device_timestamp;
6192 link->conf->sync_dtim_count = elems->dtim_count;
6195 if (elems->mbssid_config_ie)
6196 bss_conf->profile_periodicity =
6197 elems->mbssid_config_ie->profile_periodicity;
6199 bss_conf->profile_periodicity = 0;
6201 if (elems->ext_capab_len >= 11 &&
6202 (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
6203 bss_conf->ema_ap = true;
6205 bss_conf->ema_ap = false;
6207 /* continue assoc process */
6208 ifmgd->assoc_data->timeout = jiffies;
6209 ifmgd->assoc_data->timeout_started = true;
6210 run_again(sdata, ifmgd->assoc_data->timeout);
6215 if (!ifmgd->associated ||
6216 !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
6218 bssid = link->u.mgd.bssid;
6220 if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
6221 ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
6224 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
6225 mlme_dbg_ratelimited(sdata,
6226 "cancelling AP probe due to a received beacon\n");
6227 ieee80211_reset_ap_probe(sdata);
6231 * Push the beacon loss detection into the future since
6232 * we are processing a beacon from the AP just now.
6234 ieee80211_sta_reset_beacon_monitor(sdata);
6236 /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
6237 * element (which carries the beacon interval). Don't forget to add a
6238 * bit to care_about_ies[] above if mac80211 is interested in a
6239 * changing S1G element.
6241 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6242 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
6243 parse_params.bss = link->u.mgd.bss;
6244 parse_params.filter = care_about_ies;
6245 parse_params.crc = ncrc;
6246 elems = ieee802_11_parse_elems_full(&parse_params);
6251 if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
6252 ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
6253 if (local->hw.conf.dynamic_ps_timeout > 0) {
6254 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
6255 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
6256 ieee80211_hw_config(local,
6257 IEEE80211_CONF_CHANGE_PS);
6259 ieee80211_send_nullfunc(local, sdata, false);
6260 } else if (!local->pspolling && sdata->u.mgd.powersave) {
6261 local->pspolling = true;
6264 * Here is assumed that the driver will be
6265 * able to send ps-poll frame and receive a
6266 * response even though power save mode is
6267 * enabled, but some drivers might require
6268 * to disable power save here. This needs
6269 * to be investigated.
6271 ieee80211_send_pspoll(local, sdata);
6275 if (sdata->vif.p2p ||
6276 sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
6277 struct ieee80211_p2p_noa_attr noa = {};
6280 ret = cfg80211_get_p2p_attr(variable,
6282 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
6283 (u8 *) &noa, sizeof(noa));
6285 if (link->u.mgd.p2p_noa_index != noa.index) {
6286 /* valid noa_attr and index changed */
6287 link->u.mgd.p2p_noa_index = noa.index;
6288 memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
6289 changed |= BSS_CHANGED_P2P_PS;
6291 * make sure we update all information, the CRC
6292 * mechanism doesn't look at P2P attributes.
6294 link->u.mgd.beacon_crc_valid = false;
6296 } else if (link->u.mgd.p2p_noa_index != -1) {
6297 /* noa_attr not found and we had valid noa_attr before */
6298 link->u.mgd.p2p_noa_index = -1;
6299 memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
6300 changed |= BSS_CHANGED_P2P_PS;
6301 link->u.mgd.beacon_crc_valid = false;
6305 if (link->u.mgd.csa_waiting_bcn)
6306 ieee80211_chswitch_post_beacon(link);
6309 * Update beacon timing and dtim count on every beacon appearance. This
6310 * will allow the driver to use the most updated values. Do it before
6311 * comparing this one with last received beacon.
6312 * IMPORTANT: These parameters would possibly be out of sync by the time
6313 * the driver will use them. The synchronized view is currently
6314 * guaranteed only in certain callbacks.
6316 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
6317 !ieee80211_is_s1g_beacon(hdr->frame_control)) {
6318 link->conf->sync_tsf =
6319 le64_to_cpu(mgmt->u.beacon.timestamp);
6320 link->conf->sync_device_ts =
6321 rx_status->device_timestamp;
6322 link->conf->sync_dtim_count = elems->dtim_count;
6325 if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
6326 ieee80211_is_s1g_short_beacon(mgmt->frame_control))
6328 link->u.mgd.beacon_crc = ncrc;
6329 link->u.mgd.beacon_crc_valid = true;
6331 ieee80211_rx_bss_info(link, mgmt, len, rx_status);
6333 ieee80211_sta_process_chanswitch(link, rx_status->mactime,
6334 rx_status->device_timestamp,
6337 if (!link->u.mgd.disable_wmm_tracking &&
6338 ieee80211_sta_wmm_params(local, link, elems->wmm_param,
6339 elems->wmm_param_len,
6340 elems->mu_edca_param_set))
6341 changed |= BSS_CHANGED_QOS;
6344 * If we haven't had a beacon before, tell the driver about the
6345 * DTIM period (and beacon timing if desired) now.
6347 if (!link->u.mgd.have_beacon) {
6348 /* a few bogus AP send dtim_period = 0 or no TIM IE */
6349 bss_conf->dtim_period = elems->dtim_period ?: 1;
6351 changed |= BSS_CHANGED_BEACON_INFO;
6352 link->u.mgd.have_beacon = true;
6354 ieee80211_recalc_ps(local);
6356 ieee80211_recalc_ps_vif(sdata);
6359 if (elems->erp_info) {
6361 erp_value = elems->erp_info[0];
6366 if (!ieee80211_is_s1g_beacon(hdr->frame_control))
6367 changed |= ieee80211_handle_bss_capability(link,
6368 le16_to_cpu(mgmt->u.beacon.capab_info),
6369 erp_valid, erp_value);
6371 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6372 if (WARN_ON(!sta)) {
6375 link_sta = rcu_dereference_protected(sta->link[link->link_id],
6376 lockdep_is_held(&local->hw.wiphy->mtx));
6377 if (WARN_ON(!link_sta)) {
6381 if (WARN_ON(!link->conf->chandef.chan))
6384 sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
6386 changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
6388 if (ieee80211_config_bw(link, elems->ht_cap_elem,
6389 elems->vht_cap_elem, elems->ht_operation,
6390 elems->vht_operation, elems->he_operation,
6391 elems->eht_operation,
6392 elems->s1g_oper, bssid, &changed)) {
6394 "failed to follow AP %pM bandwidth change, disconnect\n",
6396 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6397 WLAN_REASON_DEAUTH_LEAVING,
6399 ieee80211_report_disconnect(sdata, deauth_buf,
6400 sizeof(deauth_buf), true,
6401 WLAN_REASON_DEAUTH_LEAVING,
6406 if (elems->opmode_notif)
6407 ieee80211_vht_handle_opmode(sdata, link_sta,
6408 *elems->opmode_notif,
6411 changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
6412 elems->country_elem,
6413 elems->country_elem_len,
6414 elems->pwr_constr_elem,
6415 elems->cisco_dtpc_elem);
6417 if (elems->eht_operation &&
6418 !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
6419 if (!ieee80211_config_puncturing(link, elems->eht_operation,
6421 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
6422 WLAN_REASON_DEAUTH_LEAVING,
6424 ieee80211_report_disconnect(sdata, deauth_buf,
6425 sizeof(deauth_buf), true,
6426 WLAN_REASON_DEAUTH_LEAVING,
6432 ieee80211_ml_reconfiguration(sdata, elems);
6433 ieee80211_process_adv_ttlm(sdata, elems,
6434 le64_to_cpu(mgmt->u.beacon.timestamp));
6436 ieee80211_link_info_change_notify(sdata, link, changed);
6441 void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
6442 struct sk_buff *skb)
6444 struct ieee80211_link_data *link = &sdata->deflink;
6445 struct ieee80211_rx_status *rx_status;
6446 struct ieee80211_hdr *hdr;
6449 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6451 rx_status = (struct ieee80211_rx_status *) skb->cb;
6452 hdr = (struct ieee80211_hdr *) skb->data;
6453 fc = le16_to_cpu(hdr->frame_control);
6455 switch (fc & IEEE80211_FCTL_STYPE) {
6456 case IEEE80211_STYPE_S1G_BEACON:
6457 ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
6462 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
6463 struct sk_buff *skb)
6465 struct ieee80211_link_data *link = &sdata->deflink;
6466 struct ieee80211_rx_status *rx_status;
6467 struct ieee80211_mgmt *mgmt;
6471 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6473 rx_status = (struct ieee80211_rx_status *) skb->cb;
6474 mgmt = (struct ieee80211_mgmt *) skb->data;
6475 fc = le16_to_cpu(mgmt->frame_control);
6477 if (rx_status->link_valid) {
6478 link = sdata_dereference(sdata->link[rx_status->link_id],
6484 switch (fc & IEEE80211_FCTL_STYPE) {
6485 case IEEE80211_STYPE_BEACON:
6486 ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
6487 skb->len, rx_status);
6489 case IEEE80211_STYPE_PROBE_RESP:
6490 ieee80211_rx_mgmt_probe_resp(link, skb);
6492 case IEEE80211_STYPE_AUTH:
6493 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
6495 case IEEE80211_STYPE_DEAUTH:
6496 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
6498 case IEEE80211_STYPE_DISASSOC:
6499 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
6501 case IEEE80211_STYPE_ASSOC_RESP:
6502 case IEEE80211_STYPE_REASSOC_RESP:
6503 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
6505 case IEEE80211_STYPE_ACTION:
6506 if (!sdata->u.mgd.associated ||
6507 !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
6510 if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
6511 struct ieee802_11_elems *elems;
6513 ies_len = skb->len -
6514 offsetof(struct ieee80211_mgmt,
6515 u.action.u.chan_switch.variable);
6520 /* CSA IE cannot be overridden, no need for BSSID */
6521 elems = ieee802_11_parse_elems(
6522 mgmt->u.action.u.chan_switch.variable,
6523 ies_len, true, NULL);
6525 if (elems && !elems->parse_error)
6526 ieee80211_sta_process_chanswitch(link,
6528 rx_status->device_timestamp,
6531 } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
6532 struct ieee802_11_elems *elems;
6534 ies_len = skb->len -
6535 offsetof(struct ieee80211_mgmt,
6536 u.action.u.ext_chan_switch.variable);
6542 * extended CSA IE can't be overridden, no need for
6545 elems = ieee802_11_parse_elems(
6546 mgmt->u.action.u.ext_chan_switch.variable,
6547 ies_len, true, NULL);
6549 if (elems && !elems->parse_error) {
6550 /* for the handling code pretend it was an IE */
6551 elems->ext_chansw_ie =
6552 &mgmt->u.action.u.ext_chan_switch.data;
6554 ieee80211_sta_process_chanswitch(link,
6556 rx_status->device_timestamp,
6566 static void ieee80211_sta_timer(struct timer_list *t)
6568 struct ieee80211_sub_if_data *sdata =
6569 from_timer(sdata, t, u.mgd.timer);
6571 wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
6574 void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
6577 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6579 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
6582 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
6586 static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
6588 struct ieee80211_local *local = sdata->local;
6589 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6590 struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
6594 struct ieee80211_prep_tx_info info = {
6595 .subtype = IEEE80211_STYPE_AUTH,
6598 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6600 if (WARN_ON_ONCE(!auth_data))
6605 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
6606 sdata_info(sdata, "authentication with %pM timed out\n",
6607 auth_data->ap_addr);
6610 * Most likely AP is not in the range so remove the
6611 * bss struct for that AP.
6613 cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
6618 if (auth_data->algorithm == WLAN_AUTH_SAE)
6619 info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
6621 info.link_id = auth_data->link_id;
6622 drv_mgd_prepare_tx(local, sdata, &info);
6624 sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
6625 auth_data->ap_addr, auth_data->tries,
6626 IEEE80211_AUTH_MAX_TRIES);
6628 auth_data->expected_transaction = 2;
6630 if (auth_data->algorithm == WLAN_AUTH_SAE) {
6631 trans = auth_data->sae_trans;
6632 status = auth_data->sae_status;
6633 auth_data->expected_transaction = trans;
6636 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6637 tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
6638 IEEE80211_TX_INTFL_MLME_CONN_TX;
6640 ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
6641 auth_data->data, auth_data->data_len,
6642 auth_data->ap_addr, auth_data->ap_addr,
6643 NULL, 0, 0, tx_flags);
6645 if (tx_flags == 0) {
6646 if (auth_data->algorithm == WLAN_AUTH_SAE)
6647 auth_data->timeout = jiffies +
6648 IEEE80211_AUTH_TIMEOUT_SAE;
6650 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
6652 auth_data->timeout =
6653 round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
6656 auth_data->timeout_started = true;
6657 run_again(sdata, auth_data->timeout);
6662 static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
6664 struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
6665 struct ieee80211_local *local = sdata->local;
6668 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6670 assoc_data->tries++;
6671 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
6672 sdata_info(sdata, "association with %pM timed out\n",
6673 assoc_data->ap_addr);
6676 * Most likely AP is not in the range so remove the
6677 * bss struct for that AP.
6679 cfg80211_unlink_bss(local->hw.wiphy,
6680 assoc_data->link[assoc_data->assoc_link_id].bss);
6685 sdata_info(sdata, "associate with %pM (try %d/%d)\n",
6686 assoc_data->ap_addr, assoc_data->tries,
6687 IEEE80211_ASSOC_MAX_TRIES);
6688 ret = ieee80211_send_assoc(sdata);
6692 if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6693 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
6694 assoc_data->timeout_started = true;
6695 run_again(sdata, assoc_data->timeout);
6697 assoc_data->timeout =
6698 round_jiffies_up(jiffies +
6699 IEEE80211_ASSOC_TIMEOUT_LONG);
6700 assoc_data->timeout_started = true;
6701 run_again(sdata, assoc_data->timeout);
6707 void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
6708 __le16 fc, bool acked)
6710 struct ieee80211_local *local = sdata->local;
6712 sdata->u.mgd.status_fc = fc;
6713 sdata->u.mgd.status_acked = acked;
6714 sdata->u.mgd.status_received = true;
6716 wiphy_work_queue(local->hw.wiphy, &sdata->work);
6719 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
6721 struct ieee80211_local *local = sdata->local;
6722 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6724 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6726 if (ifmgd->status_received) {
6727 __le16 fc = ifmgd->status_fc;
6728 bool status_acked = ifmgd->status_acked;
6730 ifmgd->status_received = false;
6731 if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
6733 if (ifmgd->auth_data->algorithm ==
6735 ifmgd->auth_data->timeout =
6737 IEEE80211_AUTH_TIMEOUT_SAE;
6739 ifmgd->auth_data->timeout =
6741 IEEE80211_AUTH_TIMEOUT_SHORT;
6742 run_again(sdata, ifmgd->auth_data->timeout);
6744 ifmgd->auth_data->timeout = jiffies - 1;
6746 ifmgd->auth_data->timeout_started = true;
6747 } else if (ifmgd->assoc_data &&
6748 !ifmgd->assoc_data->comeback &&
6749 (ieee80211_is_assoc_req(fc) ||
6750 ieee80211_is_reassoc_req(fc))) {
6752 * Update association timeout based on the TX status
6753 * for the (Re)Association Request frame. Skip this if
6754 * we have already processed a (Re)Association Response
6755 * frame that indicated need for association comeback
6756 * at a specific time in the future. This could happen
6757 * if the TX status information is delayed enough for
6758 * the response to be received and processed first.
6761 ifmgd->assoc_data->timeout =
6762 jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
6763 run_again(sdata, ifmgd->assoc_data->timeout);
6765 ifmgd->assoc_data->timeout = jiffies - 1;
6767 ifmgd->assoc_data->timeout_started = true;
6771 if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
6772 time_after(jiffies, ifmgd->auth_data->timeout)) {
6773 if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
6775 * ok ... we waited for assoc or continuation but
6776 * userspace didn't do it, so kill the auth data
6778 ieee80211_destroy_auth_data(sdata, false);
6779 } else if (ieee80211_auth(sdata)) {
6780 u8 ap_addr[ETH_ALEN];
6781 struct ieee80211_event event = {
6783 .u.mlme.data = AUTH_EVENT,
6784 .u.mlme.status = MLME_TIMEOUT,
6787 memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
6789 ieee80211_destroy_auth_data(sdata, false);
6791 cfg80211_auth_timeout(sdata->dev, ap_addr);
6792 drv_event_callback(sdata->local, sdata, &event);
6794 } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
6795 run_again(sdata, ifmgd->auth_data->timeout);
6797 if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
6798 time_after(jiffies, ifmgd->assoc_data->timeout)) {
6799 if ((ifmgd->assoc_data->need_beacon &&
6800 !sdata->deflink.u.mgd.have_beacon) ||
6801 ieee80211_do_assoc(sdata)) {
6802 struct ieee80211_event event = {
6804 .u.mlme.data = ASSOC_EVENT,
6805 .u.mlme.status = MLME_TIMEOUT,
6808 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
6809 drv_event_callback(sdata->local, sdata, &event);
6811 } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
6812 run_again(sdata, ifmgd->assoc_data->timeout);
6814 if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
6815 ifmgd->associated) {
6816 u8 *bssid = sdata->deflink.u.mgd.bssid;
6819 if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
6820 max_tries = max_nullfunc_tries;
6822 max_tries = max_probe_tries;
6824 /* ACK received for nullfunc probing frame */
6825 if (!ifmgd->probe_send_count)
6826 ieee80211_reset_ap_probe(sdata);
6827 else if (ifmgd->nullfunc_failed) {
6828 if (ifmgd->probe_send_count < max_tries) {
6830 "No ack for nullfunc frame to AP %pM, try %d/%i\n",
6831 bssid, ifmgd->probe_send_count,
6833 ieee80211_mgd_probe_ap_send(sdata);
6836 "No ack for nullfunc frame to AP %pM, disconnecting.\n",
6838 ieee80211_sta_connection_lost(sdata,
6839 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
6842 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
6843 run_again(sdata, ifmgd->probe_timeout);
6844 else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
6846 "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
6847 bssid, probe_wait_ms);
6848 ieee80211_sta_connection_lost(sdata,
6849 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6850 } else if (ifmgd->probe_send_count < max_tries) {
6852 "No probe response from AP %pM after %dms, try %d/%i\n",
6853 bssid, probe_wait_ms,
6854 ifmgd->probe_send_count, max_tries);
6855 ieee80211_mgd_probe_ap_send(sdata);
6858 * We actually lost the connection ... or did we?
6862 "No probe response from AP %pM after %dms, disconnecting.\n",
6863 bssid, probe_wait_ms);
6865 ieee80211_sta_connection_lost(sdata,
6866 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
6871 static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
6873 struct ieee80211_sub_if_data *sdata =
6874 from_timer(sdata, t, u.mgd.bcn_mon_timer);
6876 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6879 if (sdata->vif.bss_conf.csa_active &&
6880 !sdata->deflink.u.mgd.csa_waiting_bcn)
6883 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
6886 sdata->u.mgd.connection_loss = false;
6887 wiphy_work_queue(sdata->local->hw.wiphy,
6888 &sdata->u.mgd.beacon_connection_loss_work);
6891 static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
6893 struct ieee80211_sub_if_data *sdata =
6894 from_timer(sdata, t, u.mgd.conn_mon_timer);
6895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6896 struct ieee80211_local *local = sdata->local;
6897 struct sta_info *sta;
6898 unsigned long timeout;
6900 if (WARN_ON(ieee80211_vif_is_mld(&sdata->vif)))
6903 if (sdata->vif.bss_conf.csa_active &&
6904 !sdata->deflink.u.mgd.csa_waiting_bcn)
6907 sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
6911 timeout = sta->deflink.status_stats.last_ack;
6912 if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
6913 timeout = sta->deflink.rx_stats.last_rx;
6914 timeout += IEEE80211_CONNECTION_IDLE_TIME;
6916 /* If timeout is after now, then update timer to fire at
6917 * the later date, but do not actually probe at this time.
6919 if (time_is_after_jiffies(timeout)) {
6920 mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
6924 wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work);
6927 static void ieee80211_sta_monitor_work(struct wiphy *wiphy,
6928 struct wiphy_work *work)
6930 struct ieee80211_sub_if_data *sdata =
6931 container_of(work, struct ieee80211_sub_if_data,
6932 u.mgd.monitor_work);
6934 ieee80211_mgd_probe_ap(sdata, false);
6937 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
6939 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
6940 __ieee80211_stop_poll(sdata);
6942 /* let's probe the connection once */
6943 if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
6944 wiphy_work_queue(sdata->local->hw.wiphy,
6945 &sdata->u.mgd.monitor_work);
6950 void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
6952 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
6953 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
6955 lockdep_assert_wiphy(sdata->local->hw.wiphy);
6957 if (ifmgd->auth_data || ifmgd->assoc_data) {
6958 const u8 *ap_addr = ifmgd->auth_data ?
6959 ifmgd->auth_data->ap_addr :
6960 ifmgd->assoc_data->ap_addr;
6963 * If we are trying to authenticate / associate while suspending,
6964 * cfg80211 won't know and won't actually abort those attempts,
6965 * thus we need to do that ourselves.
6967 ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
6968 IEEE80211_STYPE_DEAUTH,
6969 WLAN_REASON_DEAUTH_LEAVING,
6971 if (ifmgd->assoc_data)
6972 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
6973 if (ifmgd->auth_data)
6974 ieee80211_destroy_auth_data(sdata, false);
6975 cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
6976 IEEE80211_DEAUTH_FRAME_LEN,
6980 /* This is a bit of a hack - we should find a better and more generic
6981 * solution to this. Normally when suspending, cfg80211 will in fact
6982 * deauthenticate. However, it doesn't (and cannot) stop an ongoing
6983 * auth (not so important) or assoc (this is the problem) process.
6985 * As a consequence, it can happen that we are in the process of both
6986 * associating and suspending, and receive an association response
6987 * after cfg80211 has checked if it needs to disconnect, but before
6988 * we actually set the flag to drop incoming frames. This will then
6989 * cause the workqueue flush to process the association response in
6990 * the suspend, resulting in a successful association just before it
6991 * tries to remove the interface from the driver, which now though
6992 * has a channel context assigned ... this results in issues.
6994 * To work around this (for now) simply deauth here again if we're
6997 if (ifmgd->associated && !sdata->local->wowlan) {
6999 struct cfg80211_deauth_request req = {
7000 .reason_code = WLAN_REASON_DEAUTH_LEAVING,
7004 memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
7005 ieee80211_mgd_deauth(sdata, &req);
7010 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
7012 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7014 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7016 if (!ifmgd->associated)
7019 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
7020 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
7021 mlme_dbg(sdata, "driver requested disconnect after resume\n");
7022 ieee80211_sta_connection_lost(sdata,
7023 WLAN_REASON_UNSPECIFIED,
7028 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
7029 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
7030 mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
7031 ieee80211_sta_connection_lost(sdata,
7032 WLAN_REASON_UNSPECIFIED,
7038 static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
7039 struct wiphy_work *work)
7041 struct ieee80211_link_data *link =
7042 container_of(work, struct ieee80211_link_data,
7043 u.mgd.request_smps_work);
7045 __ieee80211_request_smps_mgd(link->sdata, link,
7046 link->u.mgd.driver_smps_mode);
7049 /* interface setup */
7050 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
7052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7054 wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
7055 wiphy_work_init(&ifmgd->beacon_connection_loss_work,
7056 ieee80211_beacon_connection_loss_work);
7057 wiphy_work_init(&ifmgd->csa_connection_drop_work,
7058 ieee80211_csa_connection_drop_work);
7059 wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work,
7060 ieee80211_tdls_peer_del_work);
7061 wiphy_delayed_work_init(&ifmgd->ml_reconf_work,
7062 ieee80211_ml_reconf_work);
7063 timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
7064 timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
7065 timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
7066 wiphy_delayed_work_init(&ifmgd->tx_tspec_wk,
7067 ieee80211_sta_handle_tspec_ac_params_wk);
7068 wiphy_delayed_work_init(&ifmgd->ttlm_work,
7069 ieee80211_tid_to_link_map_work);
7072 ifmgd->powersave = sdata->wdev.ps;
7073 ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
7074 ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
7075 /* Setup TDLS data */
7076 spin_lock_init(&ifmgd->teardown_lock);
7077 ifmgd->teardown_skb = NULL;
7078 ifmgd->orig_teardown_skb = NULL;
7081 static void ieee80211_recalc_smps_work(struct wiphy *wiphy,
7082 struct wiphy_work *work)
7084 struct ieee80211_link_data *link =
7085 container_of(work, struct ieee80211_link_data,
7088 ieee80211_recalc_smps(link->sdata, link);
7091 void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
7093 struct ieee80211_sub_if_data *sdata = link->sdata;
7094 struct ieee80211_local *local = sdata->local;
7095 unsigned int link_id = link->link_id;
7097 link->u.mgd.p2p_noa_index = -1;
7098 link->u.mgd.conn_flags = 0;
7099 link->conf->bssid = link->u.mgd.bssid;
7100 link->smps_mode = IEEE80211_SMPS_OFF;
7102 wiphy_work_init(&link->u.mgd.request_smps_work,
7103 ieee80211_request_smps_mgd_work);
7104 wiphy_work_init(&link->u.mgd.recalc_smps,
7105 ieee80211_recalc_smps_work);
7106 if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
7107 link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
7109 link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
7111 wiphy_delayed_work_init(&link->u.mgd.chswitch_work,
7112 ieee80211_chswitch_work);
7114 if (sdata->u.mgd.assoc_data)
7115 ether_addr_copy(link->conf->addr,
7116 sdata->u.mgd.assoc_data->link[link_id].addr);
7117 else if (!is_valid_ether_addr(link->conf->addr))
7118 eth_random_addr(link->conf->addr);
7121 /* scan finished notification */
7122 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
7124 struct ieee80211_sub_if_data *sdata;
7126 /* Restart STA timers */
7128 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
7129 if (ieee80211_sdata_running(sdata))
7130 ieee80211_restart_sta_timer(sdata);
7135 static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
7136 struct cfg80211_bss *cbss, s8 link_id,
7137 const u8 *ap_mld_addr, bool assoc,
7140 struct ieee80211_local *local = sdata->local;
7141 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7142 struct ieee80211_bss *bss = (void *)cbss->priv;
7143 struct sta_info *new_sta = NULL;
7144 struct ieee80211_link_data *link;
7145 bool have_sta = false;
7151 if (WARN_ON(!ap_mld_addr))
7153 err = ieee80211_vif_set_links(sdata, BIT(link_id), 0);
7155 if (WARN_ON(ap_mld_addr))
7157 ap_mld_addr = cbss->bssid;
7158 err = ieee80211_vif_set_links(sdata, 0, 0);
7166 link = sdata_dereference(sdata->link[link_id], sdata);
7167 if (WARN_ON(!link)) {
7172 if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
7177 /* If a reconfig is happening, bail out */
7178 if (local->in_reconfig) {
7185 have_sta = sta_info_get(sdata, ap_mld_addr);
7191 new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
7192 link_id, cbss->bssid,
7195 new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
7202 new_sta->sta.mlo = mlo;
7206 * Set up the information for the new channel before setting the
7207 * new channel. We can't - completely race-free - change the basic
7208 * rates bitmap and the channel (sband) that it refers to, but if
7209 * we set it up before we at least avoid calling into the driver's
7210 * bss_info_changed() method with invalid information (since we do
7211 * call that from changing the channel - only for IDLE and perhaps
7212 * some others, but ...).
7214 * So to avoid that, just set up all the new information before the
7215 * channel, but tell the driver to apply it only afterwards, since
7216 * it might need the new channel for that.
7219 const struct cfg80211_bss_ies *ies;
7220 struct link_sta_info *link_sta;
7223 link_sta = rcu_dereference(new_sta->link[link_id]);
7224 if (WARN_ON(!link_sta)) {
7226 sta_info_free(local, new_sta);
7231 err = ieee80211_mgd_setup_link_sta(link, new_sta,
7235 sta_info_free(local, new_sta);
7239 memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
7241 /* set timing information */
7242 link->conf->beacon_int = cbss->beacon_interval;
7243 ies = rcu_dereference(cbss->beacon_ies);
7245 link->conf->sync_tsf = ies->tsf;
7246 link->conf->sync_device_ts =
7247 bss->device_ts_beacon;
7249 ieee80211_get_dtim(ies,
7250 &link->conf->sync_dtim_count,
7252 } else if (!ieee80211_hw_check(&sdata->local->hw,
7253 TIMING_BEACON_ONLY)) {
7254 ies = rcu_dereference(cbss->proberesp_ies);
7255 /* must be non-NULL since beacon IEs were NULL */
7256 link->conf->sync_tsf = ies->tsf;
7257 link->conf->sync_device_ts =
7258 bss->device_ts_presp;
7259 link->conf->sync_dtim_count = 0;
7261 link->conf->sync_tsf = 0;
7262 link->conf->sync_device_ts = 0;
7263 link->conf->sync_dtim_count = 0;
7268 if (new_sta || override) {
7269 err = ieee80211_prep_channel(sdata, link, cbss, mlo,
7270 &link->u.mgd.conn_flags);
7273 sta_info_free(local, new_sta);
7280 * tell driver about BSSID, basic rates and timing
7281 * this was set up above, before setting the channel
7283 ieee80211_link_info_change_notify(sdata, link,
7285 BSS_CHANGED_BASIC_RATES |
7286 BSS_CHANGED_BEACON_INT);
7289 sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
7291 err = sta_info_insert(new_sta);
7295 "failed to insert STA entry for the AP (error %d)\n",
7300 WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
7302 /* Cancel scan to ensure that nothing interferes with connection */
7303 if (local->scanning)
7304 ieee80211_scan_cancel(local);
7309 ieee80211_link_release_channel(&sdata->deflink);
7310 ieee80211_vif_set_links(sdata, 0, 0);
7314 static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata,
7315 const struct cfg80211_bss_ies *ies,
7316 u8 cur_channel, bool ignore_ecsa)
7318 const struct element *csa_elem, *ecsa_elem;
7319 struct ieee80211_channel_sw_ie *csa = NULL;
7320 struct ieee80211_ext_chansw_ie *ecsa = NULL;
7325 csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH,
7326 ies->data, ies->len);
7327 if (csa_elem && csa_elem->datalen == sizeof(*csa))
7328 csa = (void *)csa_elem->data;
7330 ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN,
7331 ies->data, ies->len);
7332 if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa))
7333 ecsa = (void *)ecsa_elem->data;
7335 if (csa && csa->count == 0)
7337 if (csa && !csa->mode && csa->new_ch_num == cur_channel)
7340 if (ecsa && ecsa->count == 0)
7342 if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel)
7345 if (ignore_ecsa && ecsa) {
7347 "Ignoring ECSA in probe response - was considered stuck!\n");
7354 static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata,
7355 struct cfg80211_bss *bss)
7360 cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq);
7363 if (ieee80211_mgd_csa_present(sdata,
7364 rcu_dereference(bss->beacon_ies),
7365 cur_channel, false)) {
7370 if (ieee80211_mgd_csa_present(sdata,
7371 rcu_dereference(bss->proberesp_ies),
7372 cur_channel, bss->proberesp_ecsa_stuck)) {
7384 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
7385 struct cfg80211_auth_request *req)
7387 struct ieee80211_local *local = sdata->local;
7388 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7389 struct ieee80211_mgd_auth_data *auth_data;
7390 struct ieee80211_link_data *link;
7395 lockdep_assert_wiphy(sdata->local->hw.wiphy);
7397 /* prepare auth data structure */
7399 switch (req->auth_type) {
7400 case NL80211_AUTHTYPE_OPEN_SYSTEM:
7401 auth_alg = WLAN_AUTH_OPEN;
7403 case NL80211_AUTHTYPE_SHARED_KEY:
7406 auth_alg = WLAN_AUTH_SHARED_KEY;
7408 case NL80211_AUTHTYPE_FT:
7409 auth_alg = WLAN_AUTH_FT;
7411 case NL80211_AUTHTYPE_NETWORK_EAP:
7412 auth_alg = WLAN_AUTH_LEAP;
7414 case NL80211_AUTHTYPE_SAE:
7415 auth_alg = WLAN_AUTH_SAE;
7417 case NL80211_AUTHTYPE_FILS_SK:
7418 auth_alg = WLAN_AUTH_FILS_SK;
7420 case NL80211_AUTHTYPE_FILS_SK_PFS:
7421 auth_alg = WLAN_AUTH_FILS_SK_PFS;
7423 case NL80211_AUTHTYPE_FILS_PK:
7424 auth_alg = WLAN_AUTH_FILS_PK;
7430 if (ifmgd->assoc_data)
7433 if (ieee80211_mgd_csa_in_process(sdata, req->bss)) {
7434 sdata_info(sdata, "AP is in CSA process, reject auth\n");
7438 auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
7439 req->ie_len, GFP_KERNEL);
7443 memcpy(auth_data->ap_addr,
7444 req->ap_mld_addr ?: req->bss->bssid,
7446 auth_data->bss = req->bss;
7447 auth_data->link_id = req->link_id;
7449 if (req->auth_data_len >= 4) {
7450 if (req->auth_type == NL80211_AUTHTYPE_SAE) {
7451 __le16 *pos = (__le16 *) req->auth_data;
7453 auth_data->sae_trans = le16_to_cpu(pos[0]);
7454 auth_data->sae_status = le16_to_cpu(pos[1]);
7456 memcpy(auth_data->data, req->auth_data + 4,
7457 req->auth_data_len - 4);
7458 auth_data->data_len += req->auth_data_len - 4;
7461 /* Check if continuing authentication or trying to authenticate with the
7462 * same BSS that we were in the process of authenticating with and avoid
7463 * removal and re-addition of the STA entry in
7464 * ieee80211_prep_connection().
7466 cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
7467 ifmgd->auth_data->link_id == req->link_id;
7469 if (req->ie && req->ie_len) {
7470 memcpy(&auth_data->data[auth_data->data_len],
7471 req->ie, req->ie_len);
7472 auth_data->data_len += req->ie_len;
7475 if (req->key && req->key_len) {
7476 auth_data->key_len = req->key_len;
7477 auth_data->key_idx = req->key_idx;
7478 memcpy(auth_data->key, req->key, req->key_len);
7481 auth_data->algorithm = auth_alg;
7483 /* try to authenticate/probe */
7485 if (ifmgd->auth_data) {
7486 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
7487 auth_data->peer_confirmed =
7488 ifmgd->auth_data->peer_confirmed;
7490 ieee80211_destroy_auth_data(sdata, cont_auth);
7493 /* prep auth_data so we don't go into idle on disassoc */
7494 ifmgd->auth_data = auth_data;
7496 /* If this is continuation of an ongoing SAE authentication exchange
7497 * (i.e., request to send SAE Confirm) and the peer has already
7498 * confirmed, mark authentication completed since we are about to send
7501 if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
7502 auth_data->peer_confirmed && auth_data->sae_trans == 2)
7503 ieee80211_mark_sta_auth(sdata);
7505 if (ifmgd->associated) {
7506 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7509 "disconnect from AP %pM for new auth to %pM\n",
7510 sdata->vif.cfg.ap_addr, auth_data->ap_addr);
7511 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7512 WLAN_REASON_UNSPECIFIED,
7515 ieee80211_report_disconnect(sdata, frame_buf,
7516 sizeof(frame_buf), true,
7517 WLAN_REASON_UNSPECIFIED,
7521 /* needed for transmitting the auth frame(s) properly */
7522 memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
7524 err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
7525 req->ap_mld_addr, cont_auth, false);
7529 if (req->link_id >= 0)
7530 link = sdata_dereference(sdata->link[req->link_id], sdata);
7532 link = &sdata->deflink;
7534 if (WARN_ON(!link)) {
7539 sdata_info(sdata, "authenticate with %pM (local address=%pM)\n",
7540 auth_data->ap_addr, link->conf->addr);
7542 err = ieee80211_auth(sdata);
7544 sta_info_destroy_addr(sdata, auth_data->ap_addr);
7548 /* hold our own reference */
7549 cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
7553 if (!ieee80211_vif_is_mld(&sdata->vif)) {
7554 eth_zero_addr(sdata->deflink.u.mgd.bssid);
7555 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
7557 ieee80211_link_release_channel(&sdata->deflink);
7559 ifmgd->auth_data = NULL;
7564 static ieee80211_conn_flags_t
7565 ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
7566 struct ieee80211_mgd_assoc_data *assoc_data,
7567 struct cfg80211_assoc_request *req,
7568 ieee80211_conn_flags_t conn_flags,
7569 unsigned int link_id)
7571 struct ieee80211_local *local = sdata->local;
7572 const struct cfg80211_bss_ies *bss_ies;
7573 struct ieee80211_supported_band *sband;
7574 const struct element *ht_elem, *vht_elem;
7575 struct ieee80211_link_data *link;
7576 struct cfg80211_bss *cbss;
7577 struct ieee80211_bss *bss;
7578 bool is_5ghz, is_6ghz;
7580 cbss = assoc_data->link[link_id].bss;
7584 bss = (void *)cbss->priv;
7586 sband = local->hw.wiphy->bands[cbss->channel->band];
7587 if (WARN_ON(!sband))
7590 link = sdata_dereference(sdata->link[link_id], sdata);
7594 is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
7595 is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
7597 /* for MLO connections assume advertising all rates is OK */
7598 if (!req->ap_mld_addr) {
7599 assoc_data->supp_rates = bss->supp_rates;
7600 assoc_data->supp_rates_len = bss->supp_rates_len;
7603 /* copy and link elems for the STA profile */
7604 if (req->links[link_id].elems_len) {
7605 memcpy(assoc_data->ie_pos, req->links[link_id].elems,
7606 req->links[link_id].elems_len);
7607 assoc_data->link[link_id].elems = assoc_data->ie_pos;
7608 assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
7609 assoc_data->ie_pos += req->links[link_id].elems_len;
7613 ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
7614 if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
7615 assoc_data->link[link_id].ap_ht_param =
7616 ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
7618 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7619 vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
7620 if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
7621 memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
7622 sizeof(struct ieee80211_vht_cap));
7623 } else if (is_5ghz) {
7625 "VHT capa missing/short, disabling VHT/HE/EHT\n");
7626 conn_flags |= IEEE80211_CONN_DISABLE_VHT |
7627 IEEE80211_CONN_DISABLE_HE |
7628 IEEE80211_CONN_DISABLE_EHT;
7632 link->u.mgd.beacon_crc_valid = false;
7633 link->u.mgd.dtim_period = 0;
7634 link->u.mgd.have_beacon = false;
7636 /* override HT/VHT configuration only if the AP and we support it */
7637 if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
7638 struct ieee80211_sta_ht_cap sta_ht_cap;
7640 memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
7641 ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
7644 link->conf->eht_puncturing = 0;
7647 bss_ies = rcu_dereference(cbss->beacon_ies);
7651 ieee80211_get_dtim(bss_ies, &dtim_count,
7652 &link->u.mgd.dtim_period);
7654 sdata->deflink.u.mgd.have_beacon = true;
7656 if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
7657 link->conf->sync_tsf = bss_ies->tsf;
7658 link->conf->sync_device_ts = bss->device_ts_beacon;
7659 link->conf->sync_dtim_count = dtim_count;
7662 bss_ies = rcu_dereference(cbss->ies);
7666 const struct ieee80211_eht_operation *eht_oper;
7667 const struct element *elem;
7669 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
7670 bss_ies->data, bss_ies->len);
7671 if (elem && elem->datalen >= 3)
7672 link->conf->profile_periodicity = elem->data[2];
7674 link->conf->profile_periodicity = 0;
7676 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
7677 bss_ies->data, bss_ies->len);
7678 if (elem && elem->datalen >= 11 &&
7679 (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
7680 link->conf->ema_ap = true;
7682 link->conf->ema_ap = false;
7684 elem = cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_OPERATION,
7685 bss_ies->data, bss_ies->len);
7686 eht_oper = (const void *)(elem->data + 1);
7689 ieee80211_eht_oper_size_ok((const void *)(elem->data + 1),
7690 elem->datalen - 1) &&
7691 (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) &&
7692 (eht_oper->params & IEEE80211_EHT_OPER_DISABLED_SUBCHANNEL_BITMAP_PRESENT)) {
7693 const struct ieee80211_eht_operation_info *info =
7694 (void *)eht_oper->optional;
7695 const u8 *disable_subchannel_bitmap = info->optional;
7698 bitmap = get_unaligned_le16(disable_subchannel_bitmap);
7699 if (cfg80211_valid_disable_subchannel_bitmap(&bitmap,
7700 &link->conf->chandef) &&
7701 !(bitmap && ieee80211_hw_check(&local->hw, DISALLOW_PUNCTURING)))
7702 ieee80211_handle_puncturing_bitmap(link,
7707 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7712 if (bss->corrupt_data) {
7713 char *corrupt_type = "data";
7715 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
7716 if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
7717 corrupt_type = "beacon and probe response";
7719 corrupt_type = "beacon";
7720 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
7721 corrupt_type = "probe response";
7723 sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
7724 cbss->bssid, corrupt_type);
7727 if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
7728 if (sdata->u.mgd.powersave)
7729 link->smps_mode = IEEE80211_SMPS_DYNAMIC;
7731 link->smps_mode = IEEE80211_SMPS_OFF;
7733 link->smps_mode = link->u.mgd.req_smps;
7739 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
7740 struct cfg80211_assoc_request *req)
7742 unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
7743 struct ieee80211_local *local = sdata->local;
7744 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
7745 struct ieee80211_mgd_assoc_data *assoc_data;
7746 const struct element *ssid_elem;
7747 struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
7748 ieee80211_conn_flags_t conn_flags = 0;
7749 struct ieee80211_link_data *link;
7750 struct cfg80211_bss *cbss;
7751 struct ieee80211_bss *bss;
7754 size_t size = sizeof(*assoc_data) + req->ie_len;
7756 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
7757 size += req->links[i].elems_len;
7759 /* FIXME: no support for 4-addr MLO yet */
7760 if (sdata->u.mgd.use_4addr && req->link_id >= 0)
7763 assoc_data = kzalloc(size, GFP_KERNEL);
7767 cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
7769 if (ieee80211_mgd_csa_in_process(sdata, cbss)) {
7770 sdata_info(sdata, "AP is in CSA process, reject assoc\n");
7776 ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
7777 if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
7783 memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
7784 assoc_data->ssid_len = ssid_elem->datalen;
7785 memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
7786 vif_cfg->ssid_len = assoc_data->ssid_len;
7789 if (req->ap_mld_addr) {
7790 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
7791 if (!req->links[i].bss)
7793 link = sdata_dereference(sdata->link[i], sdata);
7795 ether_addr_copy(assoc_data->link[i].addr,
7798 eth_random_addr(assoc_data->link[i].addr);
7801 memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
7804 assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
7806 memcpy(assoc_data->ap_addr,
7807 req->ap_mld_addr ?: req->bss->bssid,
7810 if (ifmgd->associated) {
7811 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
7814 "disconnect from AP %pM for new assoc to %pM\n",
7815 sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
7816 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
7817 WLAN_REASON_UNSPECIFIED,
7820 ieee80211_report_disconnect(sdata, frame_buf,
7821 sizeof(frame_buf), true,
7822 WLAN_REASON_UNSPECIFIED,
7826 if (ifmgd->auth_data && !ifmgd->auth_data->done) {
7831 if (ifmgd->assoc_data) {
7836 if (ifmgd->auth_data) {
7839 /* keep sta info, bssid if matching */
7840 match = ether_addr_equal(ifmgd->auth_data->ap_addr,
7841 assoc_data->ap_addr) &&
7842 ifmgd->auth_data->link_id == req->link_id;
7844 /* Cleanup is delayed if auth_data matches */
7846 ieee80211_destroy_auth_data(sdata, false);
7849 /* prepare assoc data */
7851 bss = (void *)cbss->priv;
7852 assoc_data->wmm = bss->wmm_used &&
7853 (local->hw.queues >= IEEE80211_NUM_ACS);
7856 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
7857 * We still associate in non-HT mode (11a/b/g) if any one of these
7858 * ciphers is configured as pairwise.
7859 * We can set this to true for non-11n hardware, that'll be checked
7860 * separately along with the peer capabilities.
7862 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
7863 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
7864 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
7865 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
7866 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7867 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7868 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7869 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7870 netdev_info(sdata->dev,
7871 "disabling HT/VHT/HE due to WEP/TKIP use\n");
7875 /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
7876 if (!bss->wmm_used) {
7877 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7878 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7879 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7880 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7881 netdev_info(sdata->dev,
7882 "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
7885 if (req->flags & ASSOC_REQ_DISABLE_HT) {
7886 mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
7887 conn_flags |= IEEE80211_CONN_DISABLE_HT;
7888 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7889 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7890 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7893 if (req->flags & ASSOC_REQ_DISABLE_VHT) {
7894 mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
7895 conn_flags |= IEEE80211_CONN_DISABLE_VHT;
7898 if (req->flags & ASSOC_REQ_DISABLE_HE) {
7899 mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
7900 conn_flags |= IEEE80211_CONN_DISABLE_HE;
7901 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7904 if (req->flags & ASSOC_REQ_DISABLE_EHT)
7905 conn_flags |= IEEE80211_CONN_DISABLE_EHT;
7907 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
7908 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
7909 sizeof(ifmgd->ht_capa_mask));
7911 memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
7912 memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
7913 sizeof(ifmgd->vht_capa_mask));
7915 memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
7916 memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
7917 sizeof(ifmgd->s1g_capa_mask));
7919 if (req->ie && req->ie_len) {
7920 memcpy(assoc_data->ie, req->ie, req->ie_len);
7921 assoc_data->ie_len = req->ie_len;
7922 assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
7924 assoc_data->ie_pos = assoc_data->ie;
7927 if (req->fils_kek) {
7928 /* should already be checked in cfg80211 - so warn */
7929 if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
7933 memcpy(assoc_data->fils_kek, req->fils_kek,
7935 assoc_data->fils_kek_len = req->fils_kek_len;
7938 if (req->fils_nonces)
7939 memcpy(assoc_data->fils_nonces, req->fils_nonces,
7940 2 * FILS_NONCE_LEN);
7942 /* default timeout */
7943 assoc_data->timeout = jiffies;
7944 assoc_data->timeout_started = true;
7946 assoc_data->assoc_link_id = assoc_link_id;
7948 if (req->ap_mld_addr) {
7949 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
7950 assoc_data->link[i].conn_flags = conn_flags;
7951 assoc_data->link[i].bss = req->links[i].bss;
7952 assoc_data->link[i].disabled = req->links[i].disabled;
7955 /* if there was no authentication, set up the link */
7956 err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0);
7960 assoc_data->link[0].conn_flags = conn_flags;
7961 assoc_data->link[0].bss = cbss;
7964 link = sdata_dereference(sdata->link[assoc_link_id], sdata);
7965 if (WARN_ON(!link)) {
7970 /* keep old conn_flags from ieee80211_prep_channel() from auth */
7971 conn_flags |= link->u.mgd.conn_flags;
7972 conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
7973 conn_flags, assoc_link_id);
7974 override = link->u.mgd.conn_flags != conn_flags;
7975 link->u.mgd.conn_flags |= conn_flags;
7977 if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
7978 ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
7979 "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
7980 sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
7982 if (bss->wmm_used && bss->uapsd_supported &&
7983 (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
7984 assoc_data->uapsd = true;
7985 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
7987 assoc_data->uapsd = false;
7988 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
7991 if (req->prev_bssid)
7992 memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
7995 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
7996 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
7998 ifmgd->mfp = IEEE80211_MFP_DISABLED;
7999 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
8002 if (req->flags & ASSOC_REQ_USE_RRM)
8003 ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
8005 ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
8007 if (req->crypto.control_port)
8008 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
8010 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
8012 sdata->control_port_protocol = req->crypto.control_port_ethertype;
8013 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
8014 sdata->control_port_over_nl80211 =
8015 req->crypto.control_port_over_nl80211;
8016 sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
8018 /* kick off associate process */
8019 ifmgd->assoc_data = assoc_data;
8021 for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
8022 if (!assoc_data->link[i].bss)
8024 if (i == assoc_data->assoc_link_id)
8026 /* only calculate the flags, hence link == NULL */
8027 err = ieee80211_prep_channel(sdata, NULL,
8028 assoc_data->link[i].bss, true,
8029 &assoc_data->link[i].conn_flags);
8031 req->links[i].error = err;
8036 /* needed for transmitting the assoc frames properly */
8037 memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
8039 err = ieee80211_prep_connection(sdata, cbss, req->link_id,
8040 req->ap_mld_addr, true, override);
8044 assoc_data->link[assoc_data->assoc_link_id].conn_flags =
8045 link->u.mgd.conn_flags;
8047 if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
8048 const struct cfg80211_bss_ies *beacon_ies;
8051 beacon_ies = rcu_dereference(req->bss->beacon_ies);
8054 * Wait up to one beacon interval ...
8055 * should this be more if we miss one?
8057 sdata_info(sdata, "waiting for beacon from %pM\n",
8059 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
8060 assoc_data->timeout_started = true;
8061 assoc_data->need_beacon = true;
8066 run_again(sdata, assoc_data->timeout);
8068 /* We are associating, clean up auth_data */
8069 if (ifmgd->auth_data)
8070 ieee80211_destroy_auth_data(sdata, true);
8074 if (!ifmgd->auth_data) {
8075 eth_zero_addr(sdata->deflink.u.mgd.bssid);
8076 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
8079 ifmgd->assoc_data = NULL;
8085 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
8086 struct cfg80211_deauth_request *req)
8088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8089 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8090 bool tx = !req->local_state_change;
8091 struct ieee80211_prep_tx_info info = {
8092 .subtype = IEEE80211_STYPE_DEAUTH,
8095 if (ifmgd->auth_data &&
8096 ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
8098 "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
8099 req->bssid, req->reason_code,
8100 ieee80211_get_reason_code_string(req->reason_code));
8102 info.link_id = ifmgd->auth_data->link_id;
8103 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8104 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8105 IEEE80211_STYPE_DEAUTH,
8106 req->reason_code, tx,
8108 ieee80211_destroy_auth_data(sdata, false);
8109 ieee80211_report_disconnect(sdata, frame_buf,
8110 sizeof(frame_buf), true,
8111 req->reason_code, false);
8112 drv_mgd_complete_tx(sdata->local, sdata, &info);
8116 if (ifmgd->assoc_data &&
8117 ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
8119 "aborting association with %pM by local choice (Reason: %u=%s)\n",
8120 req->bssid, req->reason_code,
8121 ieee80211_get_reason_code_string(req->reason_code));
8123 info.link_id = ifmgd->assoc_data->assoc_link_id;
8124 drv_mgd_prepare_tx(sdata->local, sdata, &info);
8125 ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
8126 IEEE80211_STYPE_DEAUTH,
8127 req->reason_code, tx,
8129 ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
8130 ieee80211_report_disconnect(sdata, frame_buf,
8131 sizeof(frame_buf), true,
8132 req->reason_code, false);
8133 drv_mgd_complete_tx(sdata->local, sdata, &info);
8137 if (ifmgd->associated &&
8138 ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
8140 "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
8141 req->bssid, req->reason_code,
8142 ieee80211_get_reason_code_string(req->reason_code));
8144 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
8145 req->reason_code, tx, frame_buf);
8146 ieee80211_report_disconnect(sdata, frame_buf,
8147 sizeof(frame_buf), true,
8148 req->reason_code, false);
8149 drv_mgd_complete_tx(sdata->local, sdata, &info);
8156 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
8157 struct cfg80211_disassoc_request *req)
8159 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
8161 if (!sdata->u.mgd.associated ||
8162 memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
8166 "disassociating from %pM by local choice (Reason: %u=%s)\n",
8167 req->ap_addr, req->reason_code,
8168 ieee80211_get_reason_code_string(req->reason_code));
8170 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
8171 req->reason_code, !req->local_state_change,
8174 ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
8175 req->reason_code, false);
8180 void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
8182 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8183 &link->u.mgd.request_smps_work);
8184 wiphy_work_cancel(link->sdata->local->hw.wiphy,
8185 &link->u.mgd.recalc_smps);
8186 wiphy_delayed_work_cancel(link->sdata->local->hw.wiphy,
8187 &link->u.mgd.chswitch_work);
8190 void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
8192 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
8195 * Make sure some work items will not run after this,
8196 * they will not do anything but might not have been
8197 * cancelled when disconnecting.
8199 wiphy_work_cancel(sdata->local->hw.wiphy,
8200 &ifmgd->monitor_work);
8201 wiphy_work_cancel(sdata->local->hw.wiphy,
8202 &ifmgd->beacon_connection_loss_work);
8203 wiphy_work_cancel(sdata->local->hw.wiphy,
8204 &ifmgd->csa_connection_drop_work);
8205 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8206 &ifmgd->tdls_peer_del_work);
8207 wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
8208 &ifmgd->ml_reconf_work);
8209 wiphy_delayed_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
8211 if (ifmgd->assoc_data)
8212 ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
8213 if (ifmgd->auth_data)
8214 ieee80211_destroy_auth_data(sdata, false);
8215 spin_lock_bh(&ifmgd->teardown_lock);
8216 if (ifmgd->teardown_skb) {
8217 kfree_skb(ifmgd->teardown_skb);
8218 ifmgd->teardown_skb = NULL;
8219 ifmgd->orig_teardown_skb = NULL;
8221 kfree(ifmgd->assoc_req_ies);
8222 ifmgd->assoc_req_ies = NULL;
8223 ifmgd->assoc_req_ies_len = 0;
8224 spin_unlock_bh(&ifmgd->teardown_lock);
8225 del_timer_sync(&ifmgd->timer);
8228 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
8229 enum nl80211_cqm_rssi_threshold_event rssi_event,
8233 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8235 trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
8237 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
8239 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
8241 void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
8243 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8245 trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
8247 cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
8249 EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
8251 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
8255 trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
8257 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
8261 * Scale up threshold values before storing it, as the RSSI averaging
8262 * algorithm uses a scaled up value as well. Change this scaling
8263 * factor if the RSSI averaging algorithm changes.
8265 sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
8266 sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
8269 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
8273 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8275 WARN_ON(rssi_min_thold == rssi_max_thold ||
8276 rssi_min_thold > rssi_max_thold);
8278 _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
8281 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
8283 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
8285 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
8287 _ieee80211_enable_rssi_reports(sdata, 0, 0);
8289 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);